Created
November 5, 2012 15:56
-
-
Save Flave/4017956 to your computer and use it in GitHub Desktop.
D3 hack to display geoJSON correctly
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
d3.json( | |
"http://localhost:8888/data/geo.json", | |
function (json) { | |
//dimensions | |
var w = 2000; | |
var h = 2000; | |
var svg = d3.select("#chart").append("svg") | |
.attr("width", w) | |
.attr("height", h); | |
//create geo.path object, set the projection to merator bring it to the svg-viewport | |
var path = d3.geo.path() | |
.projection(d3.geo.mercator() | |
.scale(20000) | |
.translate([0, 3800])); | |
//draw svg lines of the boundries | |
svg.append("g") | |
.attr("class", "black") | |
.selectAll("path") | |
.data(json.features) | |
.enter() | |
.append("path") | |
.attr("d", path); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment