Last active
November 10, 2015 21:30
-
-
Save robroc/422d8de2cbfb3a48f735 to your computer and use it in GitHub Desktop.
D3 map of census tracts on the Island of Montreal
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> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Census tracts on Montreal island</title> | |
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script> | |
<style type="text/css"> | |
body { | |
background-color: gray; | |
} | |
svg { | |
background-color: white; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
//Width and height | |
var w = 700; | |
var h = 600; | |
//Define map projection | |
var projection = d3.geo.mercator() | |
.center([ -73.6, 45.56 ]) | |
//.translate([ w/2, h/2 ]) | |
.scale([ w*90 ]); | |
//Define path generator | |
var path = d3.geo.path() | |
.projection(projection); | |
//Create SVG | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("width", w) | |
.attr("height", h); | |
//Load in GeoJSON data | |
d3.json("tracts_mtl.json", function(json) { | |
//Bind data and create one path per GeoJSON feature | |
svg.selectAll("path") | |
.data(json.geometries) | |
.enter() | |
.append("path") | |
.attr("d", path) | |
.style("fill", "white") | |
.style("stroke", "black"); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment