Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

d3.geo.bounds returns incorrect bounds #1595

Closed
larskotthoff opened this Issue Oct 22, 2013 · 7 comments

Comments

3 participants
Contributor

larskotthoff commented Oct 22, 2013

For negative longitudes, d3.geo.bounds() seems to be returning incorrect bounds. See the jsfiddle here. The latitude values are correct, but the longitudes aren't.

Collaborator

jasondavies commented Oct 22, 2013

Actually, d3.geo.bounds attempts to return the smallest bounding box in spherical coordinates, which can sometimes cross the antimeridian (you can detect this case by seeing if λ0 > λ1).

Owner

mbostock commented Oct 22, 2013

Jason has a nice illustration of the problem here: https://www.jasondavies.com/maps/bounds/

Looks like the right behavior to me. Closing, but reply if we missed something.

@mbostock mbostock closed this Oct 22, 2013

Contributor

larskotthoff commented Oct 22, 2013

I take your point, but in this case the lower left longitude is bigger than the upper right longitude. This causes problems when calculating the dimensions of the map. The specific case where this came up is here (sorry should have included that in the initial report).

Owner

mbostock commented Oct 22, 2013

It’s still the correct behavior for this method; that code should use path.bounds rather than d3.geo.bounds:

var bounds = path.bounds(collection),
    bottomLeft = bounds[0],
    topRight = bounds[1];
Owner

mbostock commented Oct 22, 2013

I suppose it might need to change slightly because of the inverted y-dimension in screen space, but same basic idea:

var bounds = path.bounds(collection),
    topLeft = bounds[0],
    bottomRight = bounds[1];
Contributor

larskotthoff commented Oct 22, 2013

Ok, thanks!

Owner

mbostock commented Oct 22, 2013

I’ve updated my tutorial to use the D3 V3 API: http://bost.ocks.org/mike/leaflet/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment