This file shows how to use the albersUsa projection from d3-composite-projections. In this case, the example (and projection) is copied directly from the d3 projection, but adding the borders a the composed zones.
Last active
March 1, 2016 10:59
-
-
Save rveciana/170a76b8dc1f9cfd8b2d to your computer and use it in GitHub Desktop.
d3-composite-projections albersUsa
This file contains 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> | |
.land { | |
fill: #222; | |
} | |
.county-boundary { | |
fill: none; | |
stroke: #fff; | |
stroke-width: .5px; | |
} | |
.state-boundary { | |
fill: none; | |
stroke: #fff; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-composite-projections/0.3.5/albersUsa-proj.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("/d/4090846/us.json", function(error, us) { | |
svg.insert("path", ".graticule") | |
.datum(topojson.feature(us, us.objects.land)) | |
.attr("class", "land") | |
.attr("d", path); | |
svg.insert("path", ".graticule") | |
.datum(topojson.mesh(us, us.objects.counties, function(a, b) { return a !== b && !(a.id / 1000 ^ b.id / 1000); })) | |
.attr("class", "county-boundary") | |
.attr("d", path); | |
svg.insert("path", ".graticule") | |
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; })) | |
.attr("class", "state-boundary") | |
.attr("d", path); | |
svg | |
.append("path") | |
.style("fill","none") | |
.style("stroke","#000") | |
.attr("d", projection.getCompositionBorders()); | |
}); | |
d3.select(self.frameElement).style("height", height + "px"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment