Skip to content

Instantly share code, notes, and snippets.

@caged
Last active January 16, 2020 14:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save caged/5779481 to your computer and use it in GitHub Desktop.
Save caged/5779481 to your computer and use it in GitHub Desktop.
TopoJSON via MapBox & Leaflet
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<div id="map"></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://api.tiles.mapbox.com/mapbox.js/v1.0.3/mapbox.js"></script>
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.0.3/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
<script>
var map = L.mapbox.map('map', 'caged.map-qa2i17ab').setView([44, -100], 2),
layer = L.geoJson(null, { style: { color: '#333', weight: 1 }})
map.addLayer(layer)
d3.json('/mbostock/raw/4090846/us.json', function(error, data) {
var neighborhoods = topojson.feature(data, data.objects.counties)
layer.addData(neighborhoods);
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment