I received some help with a previous question on how to go about translating my map to given longitude and latitude values, here: How can I use SVG translate to center a d3.js projection to given latitude and longitude values? I wrote a method which pans to the given location at the given scale:
zoomTo: function(point, scale) {
var lat = -SFMap.projection(point)[0] * scale;
var lon = -SFMap.projection(point)[1] * scale;
var x = (SFMap.config.width / 2) + lat;
var y = (SFMap.config.height / 2) + lon;
SFMap.g
.transition()
.duration(500)
.attr("transform", "translate("+ x +","+ y +") scale("+ scale +")");
}
I can 'zoom' around Europe just fine, but when I move to Jakarta, Indonesia, the center-point lays clearly over the ocean.
London - SFMap.zoomTo([0.1062, 51.5171], 1300)
Jakarta - SFMap.zoomTo([106.7500, 6.1333], 1300);
And, this problem is emphasised if I try Australia - I can't even see it.
I should note that I am using d3 to render a Mercator projection and retrieving longitude and latitude values from Google Search.
Please could someone suggest why this is happening? I am aware that there is a lot of math behind the scenes, but I'd hoped d3 would take care of this.
Edit:
After reading Pablo's comment, I decided to remove my zoomTo()
method from the equation and simply test whether d3 could center([106.7500, 6.1333])
correctly on Jarkata at a fixed scale(1000)
, but it did not; it still dumps you in the ocean.