1

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

Jakarta - SFMap.zoomTo([106.7500, 6.1333], 1300); Jakarta

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.

Community
  • 1
  • 1
Check12
  • 352
  • 1
  • 5
  • 11
  • 1
    Are you returning the group to the projection scale between the transformations? When you apply a projection, you are using the scale of the projection as a starting point, not the current scale of the figure. Are the errors consistent? If you go from A, B and then to C, you have the same error than going from B, A and then C? – Pablo Navarro May 30 '13 at 14:34
  • @PabloNavarro, you have an interesting point. I am not passing scale adjustments back to `SFMap.projection()` because I figured I didn't need to if I was calculating the affect scale had on the translate within my transform method, `zoomTo()` - shown above. I will explore passing `scale` to the projection, before using its values, when I get home from work. I will respond accordingly. :) Many thanks. – Check12 May 30 '13 at 15:16

1 Answers1

1

Embarrassingly, I discovered a silly mistake with my use of longitude and latitude coordinates.

Although I was passing coordinates to projection([106.7500, 6.1333]) on the inverse after retrieving them from Google, I had not noticed the significance of the orientation (or cardinal direction) that Google was also giving.

6.1333° S, 106.7500° E means Jakarta is 6.1333 degrees South of the equator.

So, my problem occurred because I wasn't passing projection() a negative value for the Southern coordinate - meaning, my projection was always going to be 6.1333 degrees above the equator, when it should have been below.

Check12
  • 352
  • 1
  • 5
  • 11