Skip to content

Instantly share code, notes, and snippets.

@Flave
Created November 5, 2012 15:56
Show Gist options
  • Save Flave/4017956 to your computer and use it in GitHub Desktop.
Save Flave/4017956 to your computer and use it in GitHub Desktop.
D3 hack to display geoJSON correctly
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);
});
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