Skip to content

Instantly share code, notes, and snippets.

@Andrew-Reid
Created January 24, 2018 00:25
Show Gist options
  • Save Andrew-Reid/b40c1f11fbc49998e67c493fd473c075 to your computer and use it in GitHub Desktop.
Save Andrew-Reid/b40c1f11fbc49998e67c493fd473c075 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<svg width="960" height="600"></svg>
<script>
var width = 960;
var height = 600;
var svg = d3.select("svg");
var projection = d3.geoMercator();
var path = d3.geoPath().projection(projection);
d3.json("topo.topojson", function(error, aisp) {
if (error) throw error;
projection.fitSize([width,height], topojson.feature(aisp, aisp.objects.convert));
svg.append("g")
.attr("class", "states")
.selectAll("path")
.data(topojson.feature(aisp, aisp.objects.convert).features)
.enter().append("path")
.attr("d", path);
svg.append("path")
.attr("class", "state-borders")
.attr("d", path(topojson.mesh(aisp, aisp.objects.convert, function(a, b) { return a !== b; })));
});
</script>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment