Why does the accuracy of my longitude latitude translate appear to diminish below the equator?

StackOverflow https://stackoverflow.com/questions/16835987

Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top