Skip to content

Instantly share code, notes, and snippets.

@tomstove
Created April 26, 2013 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomstove/5466369 to your computer and use it in GitHub Desktop.
Save tomstove/5466369 to your computer and use it in GitHub Desktop.
Auckland with D3
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!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>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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