This example uses d3.geo.bounds to draw the lat-lon bounding box for each county. Compare to the projected bounding box using path.bounds.
-
-
Save mbostock/4206857 to your computer and use it in GitHub Desktop.
Blocky Counties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
path { | |
fill: none; | |
stroke: steelblue; | |
} | |
</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 projection = d3.geo.albersUsa() | |
.scale(1000) | |
.translate([width / 2, height / 2]); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
d3.json("/mbostock/raw/4090846/us.json", function(error, us) { | |
if (error) throw error; | |
svg.append("path") | |
.attr("d", path({ | |
type: "MultiPolygon", | |
coordinates: topojson.feature(us, us.objects.counties).features | |
.filter(function(d) { return d.geometry && d.geometry.coordinates.length; }) | |
.map(function(d) { var b = d3.geo.bounds(d); return [[b[0], [b[0][0], b[1][1]], b[1], [b[1][0], b[0][1]], b[0]]]; }) | |
})); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment