simplegeo / polymaps

Polymaps is a free JavaScript library for making dynamic, interactive maps in modern web browsers.
http://polymaps.org/
Other
1.6k stars 213 forks source link

Latitudes at and above 90º cause NaNs, break map #108

Open eagereyes opened 12 years ago

eagereyes commented 12 years ago

So I'm using Polymaps for an interactive version of my ZIPScribble map, and for some reason Canada is causing lots of issues. The map doesn't display, the hash shows NaNs, and things can't be fixed by switching to another country until the page is reloaded (and the entire map rebuilt).

It turns out that some joker added Santa Claus's place at (90, 0) to Quebec, which causes the bounding box to extend past 90º (because of padding), and that point being part of some geoJSON I'm loading. I realize that the pole is a special place, but the code should not crash and destroy the map (especially when the value is above 90º, which I figured would just wrap around, just like longitude).

Two things in particular are happening: Calling extent() with a latitude at or above 90º causes NaNs in the calculations and a white rectangle as the display. Something inside the map is set to null, so subsequent calls to extent() can't fix things. If a point has a latitude of 90º, it is projected to some place very, very high above the northernmost map tiles. Since that point does actually exist, that should probably be fixed.

mbostock commented 12 years ago

The spherical mercator projection is not defined outside of [-85.05112877980659º, +85.05112877980659º] latitude. A point at ±90º would be at Infinity. The simplest fix is to clamp the geometry to this range; perhaps the GeoJSON layer should do this automatically?