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

Point geometries don't project properly? #101

Closed shawnbot closed 12 years ago

shawnbot commented 12 years ago

I ran into a bit of a problem while putting together a quick map of some dots on dotspotting today: they're in the wrong place. Here's a gist to check out. That cluster of red dots on the left should be on top of the US. It's hard to say without digging deeper, but it looks like the whole layer's x translation is off by about the size of the map.

Could be a problem with spanning the international date line?

mbostock commented 12 years ago

I believe the problem is your point coordinates are strings rather than numbers. If you change them to numbers and then you still see this problem, please let me know!

shawnbot commented 12 years ago

I don't think that's the problem. There should be some implicit numeric coercion going on locationCoordinate(), right? And if that were the issue, how would the y coordinates be correct?

mbostock commented 12 years ago

Fixed by coercing to numbers: http://bl.ocks.org/1335475

mbostock commented 12 years ago

The problem is that there is no explicit coercion. By coincidence, the latitude does get coerced to a number because of the multiply here:

function lat2y(lat) {
  return 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360));
}

In contrast, the longitude uses the plus operator:

return {
  column: (l.lon + 180) * k,
  …
};

If the longitude is a string such as "-42", you end up with "-42180" rather than the expected 138.

shawnbot commented 12 years ago

Ah, right. So, you probably already know what I'm going to ask, then...

Can we get a coercion of the longitude value, too? :)

Or would an explicit coercion here hurt projection performance?

mbostock commented 12 years ago

Sure, I'd be pro-coercion. Just change l.lon to +l.lon. OTOH then you wouldn't realize your geojson is invalid. ;) not sure about performance, but it should be minor.