Skip to content

Instantly share code, notes, and snippets.

@robroc
Last active November 10, 2015 21:30
Show Gist options
  • Save robroc/422d8de2cbfb3a48f735 to your computer and use it in GitHub Desktop.
Save robroc/422d8de2cbfb3a48f735 to your computer and use it in GitHub Desktop.
D3 map of census tracts on the Island of Montreal
<!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>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment