On Sep 13, 4:48 am, Paul Kulchenko <paulclin...@gmail.com> wrote: > To answer my own question. The solution was easy: my offset > calculations were incorrect (probably misinterpreted bratliff's > explanations); should be this: > > var x = div.x - abs.x; > var y = div.y - abs.y; > > var offx = (X0 << 8) + x; > var offy = (Y0 << 8) + y; > > It all works now and I don't see any issue with the International Date > line. Thanks all! > > Paul.
Hi Paul, If you are slightly east of the International Data Line, X0 may be a negative number. If you are slightly west of the International Date Line, X1 may a positive number greater than the number of tiles available at the given zoom level. An easy way to solve it is with the mod function. The number of tiles available at a given zoom level is: 1<<z The number of pixels available at a given zoom level is: 256<<z Thus, if you use: x = (x+(256<<z)) % (256<<z) your pixel number will always be in range. If x is negative, you have to add the circumference of the Earth to make the mod function return a positive number. If x is positive, adding the circumference of the Earth does not impact the mod function. In the old days, remainder division was slow compared to shifting for exact powers of two. For an interpreter like JavaScript, the difference is insignificant. I guess old habits are just hard to break. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to google-maps-api@googlegroups.com To unsubscribe from this group, send email to google-maps-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en -~----------~----~----~----~------~----~------~--~---