Skip to content

Instantly share code, notes, and snippets.

@enjalot
Last active June 21, 2016 06:07
Show Gist options
  • Save enjalot/4a449bee40e7b74108de89e303a2a284 to your computer and use it in GitHub Desktop.
Save enjalot/4a449bee40e7b74108de89e303a2a284 to your computer and use it in GitHub Desktop.
WWSD #12: d3 + TopoJSON
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
fill: #ccc;
stroke: #fff;
stroke-width: .5px;
}
path:hover {
fill: red;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var path = d3.geo.path();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var url = "https://gist.githubusercontent.com/mbostock/4090846/raw/d534aba169207548a8a3d670c9c2cc719ff05c47/us.json"
d3.json(url, function(error, topology) {
if (error) throw error;
console.log("topojson", topology)
var geojson = topojson.feature(topology, topology.objects.counties);
console.log("geojson", geojson)
svg.selectAll("path")
.data(geojson.features)
.enter().append("path")
.attr("d", path);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment