Map of US Airports

forked from mbostock's block.

In [1]:
let d3 = require('d3'),
    topojson = require('topojson'),
    projection = d3.geoAlbersUsa(),
    path = d3.geoPath().projection(projection),
    topohref = "https://gist.githubusercontent.com/mbostock/4090846/raw/d534aba169207548a8a3d670c9c2cc719ff05c47/us.json",
    airportshref = "http://bl.ocks.org/mbostock/raw/4408297/airports.json",
    topo,
    airports;
Out[1]:
undefined
In [2]:
d3.json(topohref, (err, data) => (topo = data, console.log(err || data ? "OK" : "error")));
"loading topojson… "
Out[2]:
'loading topojson… '
OK
In [3]:
d3.json(airportshref, (err, data) => (airports = data, console.log(err || data ? "OK" : "error")));
"loading airports… "
Out[3]:
'loading airports… '
OK
In [4]:
svg1 = '<svg width=960 height=500>'
    + '<path fill="#ddd" d="'
    + path(topojson.feature(topo, topo.objects.land))
    + '"/>';
$$.svg(svg1);
Out[4]:
In [5]:
svg2 = svg1
    + '<path fill="none" stroke="white" d="'
    + path(topojson.mesh(topo, topo.objects.states), function(a, b) { return a !== b; })
    + '"/>';
$$.svg(svg2);
Out[5]:
In [6]:
path.pointRadius(1.5);
svg3 = svg2
    + '<path d="'
    + path(topojson.feature(airports, airports.objects.airports))
    + '"/>';
$$.svg(svg3);
Out[6]: