<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Thomas Thoren</title>
    <description>Software engineer based in Chicago.</description>
    <link>https://thomasthoren.com/</link>
    <atom:link href="https://thomasthoren.com/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Fri, 01 Dec 2023 20:46:37 +0000</pubDate>
    <lastBuildDate>Fri, 01 Dec 2023 20:46:37 +0000</lastBuildDate>
    <generator>Jekyll v3.9.3</generator>
    
      <item>
        <title>Making a New York Times map</title>
        <description>&lt;p&gt;Of the many things the New York Times does well, their way of explaining the news through maps such as &lt;a href=&quot;http://www.nytimes.com/interactive/2014/06/12/world/middleeast/the-iraq-isis-conflict-in-maps-photos-and-video.html&quot;&gt;these&lt;/a&gt; is one of the best. The maps are always informative and enlightening, and often have an artistic element as well.&lt;/p&gt;

&lt;p&gt;Their graphics team’s ability to quickly develop such detailed maps has always made me wonder how they’re able to do it. So I set out to recreate one of their maps, and make it in a reproducible way that allows for rapid development on future projects.&lt;/p&gt;

&lt;p&gt;This guide will cover how to find the raw map data sources, use command line tools to process the data and display it all in a web browser using &lt;a href=&quot;https://d3js.org/&quot;&gt;D3.js&lt;/a&gt;. An optional final step will go over using Adobe Illustrator to clean it up.&lt;/p&gt;

&lt;p&gt;The code and files used for the map are &lt;a href=&quot;https://gist.github.com/ThomasThoren/5e676d0de41bac8a0e96&quot;&gt;available in this Gist&lt;/a&gt;, so you can skip past any parts that you aren’t yet familiar with.&lt;/p&gt;

&lt;p&gt;For this exercise, we’ll focus on &lt;a href=&quot;http://www.nytimes.com/interactive/2015/09/29/world/asia/afghanistan-taliban-maps.html&quot;&gt;this map of Afghanistan&lt;/a&gt;. Once we’re finished, &lt;a href=&quot;https://blocks.roadtolarissa.com/thomasthoren/5e676d0de41bac8a0e96&quot;&gt;you will have this map&lt;/a&gt; to show for your work.&lt;/p&gt;

&lt;div class=&quot;blog-image image-center image-full&quot;&gt;
&lt;img src=&quot;/images/thumbnails/nyt-afghanistan-map.png&quot; alt=&quot;New York Times map&quot; /&gt;
&lt;/div&gt;

&lt;h2 id=&quot;setup&quot;&gt;Setup&lt;/h2&gt;

&lt;p&gt;Assuming you’re working on a Mac, you’ll want to start by installing &lt;a href=&quot;http://brew.sh/&quot;&gt;Homebrew&lt;/a&gt;. This is a software package manager that helps you install programs and keep them organized. A lot of other programs are available through Homebrew, so you’ll probably use it again on future projects.&lt;/p&gt;

&lt;p&gt;Open your Terminal app and run the following:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;/usr/bin/ruby &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;curl &lt;span class=&quot;nt&quot;&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/Homebrew/install/master/install&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;You’ll then want to use Homebrew to install &lt;a href=&quot;http://www.gdal.org/&quot;&gt;GDAL&lt;/a&gt; (for geographic data processing), &lt;a href=&quot;http://www.imagemagick.org/script/index.php&quot;&gt;ImageMagick&lt;/a&gt; (for image processing) and &lt;a href=&quot;https://nodejs.org/en/&quot;&gt;Node&lt;/a&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;brew &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;gdal imagemagick node&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Install &lt;a href=&quot;https://github.com/mbostock/topojson&quot;&gt;TopoJSON&lt;/a&gt; (for working with map files) via &lt;a href=&quot;https://www.npmjs.com/&quot;&gt;npm&lt;/a&gt;, a Node package manager.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;npm &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-g&lt;/span&gt; topojson&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;That’s it for writing code directly to the terminal. The rest of the code is stored in files that are then called on from the command line.&lt;/p&gt;

&lt;h2 id=&quot;getting-the-data&quot;&gt;Getting the data&lt;/h2&gt;

&lt;p&gt;The New York Times’ map displays Afghanistan’s cities and districts. You might not be able to tell immediately, but it also shows provinces with slightly darker borders. The provinces consist of districts, similar to how states are made up of counties. We only need to get the districts in order to have both geographic regions.&lt;/p&gt;

&lt;p&gt;We can download district map files from Princeton University’s &lt;a href=&quot;https://esoc.princeton.edu/files/administrative-boundaries-398-districts&quot;&gt;Empirical Studies of Conflict Project&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For the cities, we can use a file found on &lt;a href=&quot;http://www.naturalearthdata.com/&quot;&gt;Natural Earth&lt;/a&gt;. This site is often useful for international and national-level geographic files. The file includes &lt;a href=&quot;http://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-populated-places/&quot;&gt;cities around the globe&lt;/a&gt;, but we will filter it down to only those in Afghanistan in the next step.&lt;/p&gt;

&lt;p&gt;You might also notice the subtle terrain texture shown most-prominently in the northeast corner of the map. You can clearly see the &lt;a href=&quot;https://gist.github.com/ThomasThoren/5e676d0de41bac8a0e96#file-afghanistan-png&quot;&gt;underlying image here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This is called &lt;a href=&quot;https://en.wikipedia.org/wiki/Terrain_cartography#Shaded_relief&quot;&gt;shaded relief&lt;/a&gt;. While not necessary in order to create this map, it’s a nice addition that reveals the topography of the region.&lt;/p&gt;

&lt;div class=&quot;blog-image image-right image-small&quot;&gt;
&lt;img src=&quot;/images/thumbnails/srtm-tile-grabber.png&quot; alt=&quot;&quot; /&gt;
&lt;p class=&quot;image-description&quot;&gt;The tiles covering Afghanistan.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The shaded relief imagery we will use is from NASA’s &lt;a href=&quot;http://www2.jpl.nasa.gov/srtm/&quot;&gt;Shuttle Radar Topography Mission&lt;/a&gt;. &lt;a href=&quot;https://twitter.com/dwtkns&quot;&gt;Derek Watkins&lt;/a&gt; has made a tool called the &lt;a href=&quot;http://dwtkns.com/srtm/&quot;&gt;SRTM Tile Grabber&lt;/a&gt; that makes it easy to determine which topographic map tiles we need. These files are fairly large, but you’ll be able to delete the intermediate files after the image processing is finished.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vector data vs. raster data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we have geographic boundaries and cities (lines and dots on a map) and satellite imagery, we have all the data we need. These two types of map data are referred to as “vector” data and “raster” data, respectively.&lt;/p&gt;

&lt;p&gt;Vector data can be zoomed in on as much as you’d like without any loss of accuracy or image integrity, while a raster image cannot. Think of the difference between when you pinch and zoom on a smartphone. Text usually scales up and remains crisp, while photos often become pixelated.&lt;/p&gt;

&lt;p&gt;Compare this &lt;a href=&quot;https://upload.wikimedia.org/wikipedia/commons/c/c0/Antarctica.svg&quot;&gt;vector image (SVG)&lt;/a&gt; to this &lt;a href=&quot;/images/thumbnails/Antarctica.png&quot;&gt;raster image (PNG)&lt;/a&gt; to see the difference. The SVG file stays crisp and the PNG file becomes pixelated. We will have to be aware of this limitation while working with the topographic images.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Make&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The full process of downloading, converting and exporting both types of data is scripted in a &lt;a href=&quot;https://gist.github.com/ThomasThoren/5e676d0de41bac8a0e96#file-makefile&quot;&gt;Makefile&lt;/a&gt;. This means the entire process is repeatable and can be run with a single command, such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make all&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Makefile&quot;&gt;Make&lt;/a&gt; is structured so you define how each file’s creation depends on other files. Here is the format:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;target_file: prequisite_file
    @# Code to create target_file.&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;In the example below, running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make File_B.json&lt;/code&gt; would first run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;touch File_A.shp&lt;/code&gt; because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File_B.json&lt;/code&gt; requires that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File_A.shp&lt;/code&gt; exist. Once &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File_A.shp&lt;/code&gt; is created, Make would then run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp File_A.shp File_B.json&lt;/code&gt; to create &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File_B.json&lt;/code&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;File_A.shp:
    @# File_A.shp is the target file.
    @# It has no prequisite files.
    @touch File_A.shp
File_B.json: File_A.shp
    @# File_B.json is the target file.
    @# File_A.shp is a prequisite file.
    @cp File_A.shp File_B.json&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;All of the programming in a Makefile is for the command line. This project uses standard bash commands and the command-line interfaces for GDAL, TopoJSON and ImageMagick, but you can always call on files written in other languages, such as Python, Ruby or JavaScript. This would be perfectly valid for a Makefile:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;target.shp:
    @python script_to_create_target.py&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Make is helpful for two big reasons, the first of which is that it clearly documents how you’ve created new files and how they depend on each other. When you revisit this project in the future, you will be able to clearly see how you created the output files. You can then quickly edit a step in the process and rerun the command.&lt;/p&gt;

&lt;p&gt;The other main reason for using Make is because it monitors the modification time for each of your files, which results in you spending less time waiting around for your output files. If you’ve already run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make all&lt;/code&gt;, and then run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make all&lt;/code&gt; again, it won’t trigger any processes because Make knows that there is nothing new to create. The file dependencies have not changed. If you delete or alter a file, only then would &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make all&lt;/code&gt; run some or all of your processes once again.&lt;/p&gt;

&lt;p&gt;If you aren’t using Make or a similar program for documenting your data conversion, now is a &lt;a href=&quot;https://bost.ocks.org/mike/make/&quot;&gt;good time to start&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scripting downloads&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is how you can download a .zip file using bash’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl&lt;/code&gt; command.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; zip
curl &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; zip/ne_10m_populated_places.zip &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;http://naciscdn.org/naturalearth/10m/cultural/ne_10m_populated_places.zip&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;And here is how you can unzip that file.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; shp
&lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-rf&lt;/span&gt; tmp &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;mkdir &lt;/span&gt;tmp
unzip &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; tmp &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    zip/ne_10m_populated_places.zip
&lt;span class=&quot;nb&quot;&gt;cp &lt;/span&gt;tmp/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; shp&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;converting-data&quot;&gt;Converting data&lt;/h2&gt;

&lt;div class=&quot;blog-image image-right image-small&quot;&gt;
&lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/GDALLogoColor.svg/1000px-GDALLogoColor.svg.png&quot; alt=&quot;GDAL logo&quot; /&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Vector data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The outline for converting and exporting the vector data is to filter out any unnecessary information (e.g. cities outside of Afghanistan), convert to a different file format for use by a web browser and simplify the map to reduce the file size.&lt;/p&gt;

&lt;p&gt;To remove extraneous information, we will exclude small cities and those outside of Afghanistan. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SCALERANK&lt;/code&gt; field ranks cities based on their size, so we only include those that have a rank of 7 or higher. This will reduce the file size and therefore speed up load times in your browser.&lt;/p&gt;

&lt;p&gt;This uses GDAL’s ogr2ogr command, which allows you to manipulate geographic files. See Derek Watkins’ &lt;a href=&quot;https://github.com/dwtkns/gdal-cheat-sheet&quot;&gt;GDAL cheat sheet&lt;/a&gt; for a long list of other commands that you might find useful. We will also use GDAL commands for manipulating raster images in the next section.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;ogr2ogr &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;ESRI Shapefile&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    shp/cities.shp &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    shp/ne_10m_populated_places.shp &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-dialect&lt;/span&gt; sqlite &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-sql&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;SELECT Geometry, NAME &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
        FROM 'ne_10m_populated_places' &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
        WHERE ADM0NAME = 'Afghanistan' AND &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
              SCALERANK &amp;lt;= 7&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Convert that new Shapefile to GeoJSON, which is an open-source format usable by D3 and most other mapping programs.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; geojson
ogr2ogr &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;GeoJSON&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    geojson/afghanistan-cities.json &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    shp/cities.shp&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Convert GeoJSON to TopoJSON. This reduces the file size even more while maintaining its accuracy. The TopoJSON format is also usable by D3 (both of which were created by &lt;a href=&quot;https://bost.ocks.org/mike/&quot;&gt;Mike Bostock&lt;/a&gt;).&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; topojson
topojson &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;--no-quantization&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;--properties&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; topojson/afghanistan-districts-fullsize.json &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt; geojson/afghanistan-districts.json&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;For the district and province TopoJSON files, you’ll want to simplify the geometry in order to reduce the file size. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-s&lt;/code&gt; flag determines the &lt;a href=&quot;https://github.com/mbostock/topojson/wiki/Command-Line-Reference#simplification&quot;&gt;degree of simplification&lt;/a&gt;, while the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-q&lt;/code&gt; flag determines the &lt;a href=&quot;https://github.com/mbostock/topojson/wiki/Command-Line-Reference#quantization&quot;&gt;degree of quantization&lt;/a&gt;. The two are different, though similar in that they can both reduce the complexity of the map and therefore reduce the file size.&lt;/p&gt;

&lt;p&gt;The number &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-9&lt;/code&gt; is shorthand for scientific notation (1 x 10&lt;sup&gt;-9&lt;/sup&gt;), both of which are equivalent to 0.000000001. Similarly, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e4&lt;/code&gt; is short for 1 x 10&lt;sup&gt;4&lt;/sup&gt;, or 10,000.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;topojson &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;--spherical&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;--properties&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; 1e-9 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-q&lt;/span&gt; 1e4 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; afghanistan-districts.json &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt; topojson/afghanistan-districts-fullsize.json&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;strong&gt;Raster data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The plan for the raster data is to merge the individual downloaded files into one large tile, convert the new image into the correct map projection, crop the image to the outline of Afghanistan’s border, perform some color correction and hillshading techniques, and then convert to a smaller PNG file for use by a web browser.&lt;/p&gt;

&lt;p&gt;Merge topographic tiles into a single file. The smaller tiles were downloaded in the same way as the cities ZIP file.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;# Makefile code to loop over tiles and merge into single TIF file.&lt;/span&gt;
tif/afghanistan-merged-90m.tif: &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_48_07.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_49_07.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_50_07.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_51_07.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_52_07.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_48_06.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_49_06.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_50_06.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_51_06.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_52_06.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_48_05.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_49_05.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_50_05.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_51_05.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/srtm_52_05.tif

    @mkdir &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dir&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$@&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
    @gdal_merge.py &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$@&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;-init&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;255&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
        tif/srtm_&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;.tif&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Convert the TIF file to the Mercator projection (EPSG:3857) for use by D3. It comes in the WGS 84 (EPSG:4326) projection.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;gdalwarp &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-co&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;TFW=YES&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-s_srs&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;EPSG:4326&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-t_srs&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;EPSG:3857&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/afghanistan-merged-90m.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/afghanistan-reprojected.tif&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Crop the image to the outline of Afghanistan. We’ll use one of the vector files from earlier to define the country’s outline.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;gdalwarp &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-cutline&lt;/span&gt; shp/district398.shp &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-crop_to_cutline&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-dstalpha&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/afghanistan-reprojected.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/afghanistan-cropped.tif&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Shade and color the image to arrive at the final TIF file. &lt;a href=&quot;https://gis.stackexchange.com/a/144700&quot;&gt;This post on Stack Exchange&lt;/a&gt; is helpful for understanding the options available when creating hillshade images.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-rf&lt;/span&gt; tmp &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; tmp
gdaldem &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    hillshade &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/afghanistan-cropped.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tmp/hillshade.tmp.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-z&lt;/span&gt; 5 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-az&lt;/span&gt; 315 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-alt&lt;/span&gt; 60 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-compute_edges&lt;/span&gt;
gdal_calc.py &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-A&lt;/span&gt; tmp/hillshade.tmp.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;--outfile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;tif/afghanistan-color-crop.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;--calc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;255*(A&amp;gt;220) + A*(A&amp;lt;=220)&quot;&lt;/span&gt;
gdal_calc.py &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-A&lt;/span&gt; tmp/hillshade.tmp.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;--outfile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;tmp/opacity_crop.tmp.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;--calc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;1*(A&amp;gt;220) + (256-A)*(A&amp;lt;=220)&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Convert the TIF file to a PNG file and resize it in order to reduce the file size.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;convert &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-resize&lt;/span&gt; x670 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    tif/afghanistan-color-crop.tif &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    afghanistan.png&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;displaying-map-on-a-web-page&quot;&gt;Displaying map on a web page&lt;/h2&gt;

&lt;div class=&quot;blog-image image-right image-small&quot;&gt;
&lt;img src=&quot;https://upload.wikimedia.org/wikipedia/en/thumb/1/15/Logo_D3.svg/1079px-Logo_D3.svg.png&quot; alt=&quot;D3 logo&quot; /&gt;
&lt;/div&gt;

&lt;p&gt;At this point, you are finished processing data. You now have all of the files you’ll need for the map. You can see them all on &lt;a href=&quot;https://gist.github.com/ThomasThoren/5e676d0de41bac8a0e96&quot;&gt;this Gist page&lt;/a&gt;. Now it is time to display those results on a web page.&lt;/p&gt;

&lt;p&gt;During development, you’ll want to load your HTML pages through a local server. Open your terminal and navigate to your project directory, then run the following to create a server at port &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;8888&lt;/code&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;python &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; SimpleHTTPServer 8888
&lt;span class=&quot;c&quot;&gt;# Press CONTROL + C when finished.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Open your web browser and go to &lt;a href=&quot;http://localhost:8888&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://localhost:8888&lt;/code&gt;&lt;/a&gt; to see your page.&lt;/p&gt;

&lt;p&gt;I won’t go over the basics of making maps in D3 and instead only focus on the unique parts of this project. If you’re completely new to making maps with D3, try following some of Mike Bostock’s tutorials to get started. &lt;a href=&quot;https://bost.ocks.org/mike/map/&quot;&gt;This guide&lt;/a&gt; is a good starting point. I have other maps on &lt;a href=&quot;https://blocks.roadtolarissa.com/thomasthoren&quot;&gt;bl.ocks.org&lt;/a&gt; that might help too, such as &lt;a href=&quot;https://blocks.roadtolarissa.com/thomasthoren/7e9970f025c301e8c2f8&quot;&gt;this one focusing on labels&lt;/a&gt; and &lt;a href=&quot;https://blocks.roadtolarissa.com/thomasthoren/6a543c4d804f35a240f9&quot;&gt;this other map&lt;/a&gt; that explains how to calculate a distance scale.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syncing raster images with vector outlines&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An important part of this map is making sure that the raster imagery is scaled at the same level as the vector data, and that they are aligned on the page. &lt;a href=&quot;https://stackoverflow.com/a/14691788/2574244&quot;&gt;This post by Mike Bostock&lt;/a&gt; helps explain one approach.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// Define map dimensions.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;map_width&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;850&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;map_height&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;750&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Create a unit projection.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;map_projection&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;geo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;mercator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;map_path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;geo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;projection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map_projection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now that we have an unscaled projection, we will use our page’s parameters to create a scale. This will determine the relationship between the map’s actual dimensions (e.g. 5 decimal degrees) and its displayed dimensions (e.g. 500 pixels).&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span class=&quot;nx&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;districts.json&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;districts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;warn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;map_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;topojson&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;feature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;districts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;districts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;objects&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;afghanistan-districts&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]));&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Calculate the pixels per map-path-degree.&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;scale&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;map_width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;map_height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Find how to translate map into view based on the calculated scale.&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;translation&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map_width&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;scale&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map_height&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;scale&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Scale and center vector using new scale and translation.&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;map_projection&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;translation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;This same scale will then be used to scale the raster image. By using the same scale, we can be sure that the vector and raster data will align.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// In d3.json function&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Scale and position shaded relief raster image.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// This assumes it has been cropped to the vector outline shape.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;raster_width&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;raster_height&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;rtranslate_x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map_width&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;raster_width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;rtranslate_y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map_height&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;raster_height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Shaded relief&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;svg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Raster&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;clip-path&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;url(#afghanistan_clip)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;xlink:href&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;afghanistan.png&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;raster_width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;raster_height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
          &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;translate(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;rtranslate_x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;rtranslate_y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The rest of the D3 code places city markers, writes city labels, draws label lines and colors certain districts.&lt;/p&gt;

&lt;p&gt;You might notice little differences between &lt;a href=&quot;https://blocks.roadtolarissa.com/thomasthoren/5e676d0de41bac8a0e96&quot;&gt;our map&lt;/a&gt; and the &lt;a href=&quot;http://www.nytimes.com/interactive/2015/09/29/world/asia/afghanistan-taliban-maps.html&quot;&gt;New York Times map&lt;/a&gt;, but this get us pretty close. For an optional final step, use Adobe Illustrator to clean things up.&lt;/p&gt;

&lt;h2 id=&quot;adobe-illustrator-and-ai2html&quot;&gt;Adobe Illustrator and ai2html&lt;/h2&gt;

&lt;div class=&quot;blog-image image-right image-small&quot;&gt;
&lt;img src=&quot;/images/thumbnails/ai.jpg&quot; alt=&quot;Adobe Illustrator logo&quot; /&gt;
&lt;/div&gt;

&lt;p&gt;For additional fine-tuning, it is easiest to use Adobe Illustrator for working with vector graphics. The New York Times has a helpful open-source project called &lt;a href=&quot;http://ai2html.org/&quot;&gt;ai2html&lt;/a&gt; that makes it easy to export Illustrator files into HTML and PNG files, including different sizes and styels for different devices (phones, tablets, laptops, large monitors).&lt;/p&gt;

&lt;p&gt;This is how the New York Times appears to have created the presentation for their Afghanistan map. You can tell because, whereas our map creates an SVG graphic in the browser, their map is simply a static PNG image with HTML laid on top.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://gist.github.com/ThomasThoren/8116135710c53794c425&quot;&gt;This Gist&lt;/a&gt; shows how we can take the SVG made with D3 and convert it to static HTML and PNG files, like how the New York Times map was done.&lt;/p&gt;

&lt;p&gt;Install &lt;a href=&quot;SVGCrowbar&quot;&gt;SVG Crowbar&lt;/a&gt; (yet another New York Times project) so you can save our SVG as a local file. Follow ai2html’s installation instructions and then open your SVG file in Illustrator. You can find my final &lt;a href=&quot;https://gist.github.com/ThomasThoren/8116135710c53794c425#file-index-ai&quot;&gt;Illustrator file here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You’ll probably find that some elements are miscolored or aligned wrong, but you can fix that in Illustrator. Some of the text labels in D3 were hacked together to imitate a cohesive text block. Fix that by combining the text into a single entity.&lt;/p&gt;

&lt;div class=&quot;blog-image image-right image-small&quot;&gt;
&lt;img src=&quot;/images/thumbnails/illustrator-artboards.png&quot; alt=&quot;Illustrator artboards&quot; /&gt;
&lt;p class=&quot;image-description&quot;&gt;The different artboards.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Copy the artboard for each width that you’d like to create, possibly one for small, medium and large. Name them according to the format &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;large:min_width&lt;/code&gt;, such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;large:480&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Size the artboard and its contents according to the minimum width desired. Make sure the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;responsiveness&lt;/code&gt; field is set in your settings block, either as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;responsiveness: fixed&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;responsiveness: dynamic&lt;/code&gt;. Fixed makes it a little bit easier to predict how your graphics will be displayed at different screen sizes.&lt;/p&gt;

&lt;p&gt;In D3, we added all of the content that will be needed for the largest width. We will remove some elements for smaller widths so the map won’t be so crowded.&lt;/p&gt;

&lt;p&gt;For smaller artboards, be aware that font sizes will need to be increased. Text will wrap between breakpoints if dynamic, so you’ll also want to allow for extra padding.&lt;/p&gt;

&lt;div class=&quot;blog-image image-center image-large&quot;&gt;
&lt;img src=&quot;/images/thumbnails/illustrator-workspace.png&quot; alt=&quot;Illustrator artboards&quot; /&gt;
&lt;p class=&quot;image-description&quot;&gt;The different artboards with the settings text block to the left. Notice how the smaller artboards include fewer labels and cities.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Here is a sample config text block:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;ai2html-settings
settings_version: 0.59
image_format: png
responsiveness: fixed
output: one-file
html_output_path: /
html_output_extension: .html
image_output_path: ./
local_preview_template: index-template.html
png_number_of_colors: 128
jpg_quality: 60
create_config_file: yes
config_file_path: ./config.yml
include_resizer_classes: yes
headline: 14 Years After U.S. Invasion, the Taliban Are Back in Control of Large Parts of Afghanistan
leadin: The Taliban have a significant footprint in Afghanistan, according to Bill Roggio, the editor of The Long War Journal, an online publication that is tracking Taliban control. Mr. Roggio has confirmed that about one-fifth of the country is controlled or contested by the Taliban, but based on his understanding of how the Taliban operate, he said, “they probably either control or heavily influence about a half of the country.”
notes: Here is some note text.
sources: Source: New York Times.
credit: By Thomas Thoren
job_title: Open data reporter&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Export the artboards using ai2html by running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File &amp;gt; Scripts &amp;gt; ai2html&lt;/code&gt; in Illustrator. This will output HTML and PNG files’. Load &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.preview.html&lt;/code&gt; in your browser to see the results.&lt;/p&gt;

&lt;p&gt;You’ll need to add either the &lt;a href=&quot;https://gist.githubusercontent.com/ThomasThoren/8116135710c53794c425/raw/164f0045013db87805f544d48cf4195045dfca4f/resizer-script.js&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resizer-script.js&lt;/code&gt;&lt;/a&gt; block into the preview HTML page or have the file in the same directory so you can import it. This file makes your page readjust according to the page width size.&lt;/p&gt;

&lt;p&gt;Make sure breakpoints are working by adjusting the width of your page. You should see the elements scale up and down, and disappear and reappear. Edit the HTML file to include any font styles that may have been lost in the export step, such as bold and italics. Also add in any font styles for your text, if you’d like.&lt;/p&gt;

&lt;p&gt;That’s it! I hope you were able to learn a lot and will be able to apply this information to your future projects. Please let me know if you found this useful and show me what you went on to create.&lt;/p&gt;

</description>
        <pubDate>Sun, 28 Feb 2016 00:00:00 +0000</pubDate>
        <link>https://thomasthoren.com/2016/02/28/making-a-new-york-times-map.html</link>
        <guid isPermaLink="true">https://thomasthoren.com/2016/02/28/making-a-new-york-times-map.html</guid>
        
        
      </item>
    
  </channel>
</rss>
