Created
May 13, 2013 10:56
-
-
Save tomstove/5567540 to your computer and use it in GitHub Desktop.
London with D3
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> | |
<head> | |
<style> | |
.landuse { | |
fill: #efefef; | |
} | |
.roads { | |
fill: none; | |
stroke: #777; | |
stroke-width: 0.3px; | |
} | |
.roads_residential { | |
fill: none; | |
stroke: #fff; | |
stroke-width: 0.3px; | |
} | |
.roads_primary { | |
fill: none; | |
stroke: #555; | |
stroke-width: 0.35px; | |
} | |
.roads_trunk { | |
fill: none; | |
stroke: #3b3b3b; | |
stroke-width: 0.4px; | |
} | |
.water { | |
fill: steelblue; | |
fill-opacity: 0.3; | |
} | |
</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> | |
var width = 960, | |
height = 500; | |
var projection = d3.geo.mercator() | |
.translate([600, height/2]) | |
.center([0.0, 51.4971]) | |
.scale(150000); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
var landuse = svg.append("g"); | |
var roads = svg.append("g"); | |
var roads_residential = svg.append("g"); | |
var roads_primary = svg.append("g"); | |
var roads_trunk = svg.append("g"); | |
var water = svg.append("g"); | |
d3.json('london.topo.json', function(err, data) { | |
landuse.append("path") | |
.datum(topojson.object(data, data.objects.landuse)) | |
.attr("class", "landuse") | |
.attr("d", path); | |
roads.append("path") | |
.datum(topojson.object(data, data.objects.roads)) | |
.attr("class", "roads") | |
.attr("d", path); | |
roads_residential.append("path") | |
.datum(topojson.object(data, data.objects.roads_residential)) | |
.attr("class", "roads_residential") | |
.attr("d", path); | |
roads_primary.append("path") | |
.datum(topojson.object(data, data.objects.roads_primary)) | |
.attr("class", "roads_primary") | |
.attr("d", path); | |
roads_trunk.append("path") | |
.datum(topojson.object(data, data.objects.roads_trunk)) | |
.attr("class", "roads_trunk") | |
.attr("d", path); | |
water.append("path") | |
.datum(topojson.object(data, data.objects.waterway)) | |
.attr("class", "water") | |
.attr("d", path); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment