North America d3.js
I went through Mike Bostock's Let's make a map tutorial again and after that decided to try to modify it slightly using North America data. I'm a bit of a homer I guess.
data/* | |
*.zip | |
*.gzip | |
*.bu | |
*.paul | |
*.*~ |
North America d3.js
I went through Mike Bostock's Let's make a map tutorial again and after that decided to try to modify it slightly using North America data. I'm a bit of a homer I guess.
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
body { | |
background-color: #e0f3f8; | |
} | |
.subunit.USB { fill: #d73027; } | |
.subunit.USK { fill: #fc8d59; } | |
.subunit.USH { fill: #ffffbf; } | |
.subunit.CAN { fill: #4575b4; } | |
.subunit.MEX { fill: #fee090; } | |
.subunit-boundary { | |
fill: none; | |
stroke: white; | |
stroke-width: 3; | |
stroke-linejoin: round; | |
} | |
.subunit-label { | |
fill: #404040; | |
fill-opacity: 1; | |
font-size: 20px; | |
font-weight: 600; | |
text-anchor: middle; | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<script> | |
var width = 960, | |
height = 1160; | |
var projection = d3.geo.mercator() | |
.center([100, 50]) | |
.scale(240) | |
.rotate([-180,0]); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
d3.json("nam.json", function(error, nam) { | |
var subunits = topojson.feature(nam, nam.objects.subunits) | |
/* ,places = topojson.feature(nam, nam.objects.places) */ | |
; | |
svg.selectAll(".subunit") | |
.data(subunits.features) | |
.enter().append("path") | |
.attr("class", function(d) { return "subunit " + d.id; }) | |
.attr("d", path); | |
svg.append("path") | |
.datum(topojson.mesh(nam, nam.objects.subunits, function(a, b) { return a !== b; })) | |
.attr("d", path) | |
.attr("class", "subunit-boundary"); | |
svg.selectAll(".subunit-label") | |
.data(subunits.features) | |
.enter().append("text") | |
.attr("class", function(d) { return "subunit-label " + d.id; }) | |
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; }) | |
.attr("dy", ".35em") | |
.text(function(d) { return d.properties.name; }); | |
svg.append("path") | |
.datum(places) | |
.attr("d", path) | |
.attr("class", "place"); | |
/* | |
svg.selectAll(".place-label") | |
.data(places.features) | |
.enter().append("text") | |
.attr("class", "place-label") | |
.attr("transform", function(d) { return "translate(" + projection(d.geometry.coordinates) + ")"; }) | |
.attr("x", function(d) { return d.geometry.coordinates[0] > -1 ? 6 : -6; }) | |
.attr("dy", ".35em") | |
.style("text-anchor", function(d) { return d.geometry.coordinates[0] > -1 ? "start" : "end"; }) | |
.text(function(d) { return d.properties.name; }); | |
*/ | |
}); | |
</script> |