Reputation: 41
Iam trying to create a map over my country but it is always zoomed out.
I have seen a lot of maps where they manage to zoom into country with projection, but where do they get the numbers for the projection? Im so confused..
examples: http://bl.ocks.org/mbostock/9265674 http://bl.ocks.org/mbostock/5413933
Current code:
var width = 960,
height = 500;
// 11°E 64.4°N - latitude and
var projection = d3.geo.mercator();
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("topojson/fylker.json", function(error, norge) {
norge = norge;
for(var i = 0; i < norge.objects.fylker.geometries.length; i++) {
svg.append("path")
.datum(topojson.feature(norge, norge.objects.fylker.geometries[i]))
.attr("d", path)
.attr("class", function(d) { return "county-" + d.id; });
}
});
Upvotes: 4
Views: 1864
Reputation: 16069
If your map doesn't change (no transform for example) you can get those numbers by trial and error, like it was done in the examples you provided. Just enter some numbers and see if the result fits your needs. It is better though to calculate the center of the map and pass this to the projection. Lars Kotthoff gave you in the comment of your question a very good link to see how this works (Center a map in d3 given a geoJSON object).
Upvotes: 1