Answering my own question (again).

Berry, there was indeed an error in our calculations. I haven't
figured out why exactly it's always off by one pixel in v3, but I know
why it's occasionally off in v2. Which probably means that your
drawings may be off by one pixel (not that anybody would notice; I
only noticed because there was occasional one pixel gap in my canvas
drawings; I don't like gaps that I can't explain).

It seems like the current logic does rounding too early:

  var OFFSET = 268435456;
  var LngToX = function (lng) { return ~~(0.5 + OFFSET + lng*OFFSET/
180); }
  var x = LngToX(center.lng()) >> (21 - zoom);

For -111.90884 this generates 198329 even though the correct value is
198330. If I re-arrange thing a bit and only do round *after* shifting
value, I get the correct result:

  var LngToX = function (lng) { return (1 + lng/180); }
  var x = ~~(0.5 + LngToX(center.lng()) * (2 << (zoom + 6)));

Also, while I was looking at this I figured out why my implementation
was 5 times faster than the original fromLatLngToPixel. The short
answer is because I was comparing apples to oranges. It turned out
that google is using very similar logic to the one that we've been
using; they even do some optimization to use zoom-based table lookup
instead of calculating 2<<(zoom+6) at run time.

The reason why it was much faster was simple: I calculate LngToX
values for all points on the map once and these calculations take the
most time (because of log, sin, and multiplications). For every zoom
level I just multiply those values by 2^(zoom+6) and this is very fast
(much faster than fully re-calculating mapping from LL to pixel
coordinates). If you use google's fromLatLngToPixel you's stuck with
doing all the calculations again and again for every zoom level. Hence
the difference in speed.

Paul (http://notebook.kulchenko.com/maps/)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to