This example uses d3.geo.bounds to draw a diagonal line for the bounding box for each county.
forked from mbostock's block: Fuzzy Counties
license: gpl-3.0 |
This example uses d3.geo.bounds to draw a diagonal line for the bounding box for each county.
forked from mbostock's block: Fuzzy Counties
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
path { | |
fill: none; | |
stroke: steelblue; | |
} | |
</style> | |
<body> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://d3js.org/topojson.v2.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var projection = d3.geoAlbersUsa() | |
.scale(1000) | |
.translate([width / 2, height / 2]); | |
var path = d3.geoPath() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
d3.json("https://gist.githubusercontent.com/mbostock/4090846/raw/d534aba169207548a8a3d670c9c2cc719ff05c47/us.json", function(error, us) { | |
if (error) throw error; | |
svg.append("path") | |
.attr("d", path({ | |
type: "MultiLineString", | |
coordinates: topojson.feature(us, us.objects.counties).features | |
.filter(function(d) { return d.geometry && d.geometry.coordinates.length; }) | |
.map(d3.geoBounds) | |
})); | |
}); | |
</script> |