4

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; });        
    }
});

1 Answers1

1

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).

Community
  • 1
  • 1
ssc-hrep3
  • 15,024
  • 7
  • 48
  • 87
  • This is what I ended up doing. Found a worldmap with topojson and used the data from UK as shown here: http://bost.ocks.org/mike/map/. Then edited numbers to fit for Norway. – Einar Gangsø Aug 23 '14 at 18:08