Created
April 26, 2013 10:35
-
-
Save tomstove/5466369 to your computer and use it in GitHub Desktop.
Auckland with D3
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> | |
<head> | |
<style> | |
.buildings { | |
fill: steelblue; | |
} | |
.roads { | |
fill: none; | |
stroke: orange; | |
stroke-width: 0.3px; | |
} | |
.trees { | |
fill: red; | |
fill-opacity: 0.1; | |
} | |
.landuse { | |
fill: #ccc; | |
fill-opacity: 0.1; | |
} | |
</style> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/d3.geo.projection.v0.min.js"></script> | |
<script src="http://d3js.org/topojson.v0.min.js"></script> | |
</head> | |
<body> | |
<script> | |
/* Longitude and latitude data for 'clipdst': | |
174.7236442566 -36.879620605 174.8223495483 -36.8189047565 */ | |
var width = 960, | |
height = 500; | |
var projection = d3.geo.mercator() | |
.translate([width/2, height/2]) | |
.center([174.77299690245002, -36.84926268075]) | |
.scale(600000); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
var buildings = svg.append("g"); | |
var roads = svg.append("g"); | |
var trees = svg.append("g"); | |
var landuse = svg.append("g"); | |
d3.json('buildings.json', function(err, data) { | |
buildings.selectAll("path") | |
.data(data.features) | |
.enter().append("path") | |
.attr("class", "buildings") | |
.attr("d", path); | |
}); | |
d3.json('roads.json', function(err, data) { | |
roads.selectAll("path") | |
.data(data.features) | |
.enter().append("path") | |
.attr("class", "roads") | |
.attr("d", path); | |
}); | |
d3.json('trees.json', function(err, data) { | |
trees.selectAll("path") | |
.data(data.features) | |
.enter().append("path") | |
.attr("class", "trees") | |
.attr("d", path); | |
}); | |
d3.json('landuse.json', function(err, data) { | |
landuse.selectAll("path") | |
.data(data.features) | |
.enter().append("path") | |
.attr("class", "landuse") | |
.attr("d", path); | |
}); | |
</script> | |
</body> | |
</html> |
View raw
(Sorry about that, but we can’t show files that are this big right now.)
View raw
(Sorry about that, but we can’t show files that are this big right now.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment