[OSM-dev] Mercator coordinates mismatch (informationfreeway.org and Freemap)

Tom Hughes tom at compton.nu
Sat Jan 5 10:37:27 GMT 2008


In message <200801051004.45653.nick at hogweed.org>
          Nick Whitelegg <nick at hogweed.org> wrote:

> Freemap has been Mercator for a while now, but has used its own zoom levels
> rather than the standard Google zoom levels. By using code from
> informationfreeway.org, I have now converted Freemap to use the Google zoom
> levels and tiling scheme, but I'm now getting a mismatch in the Mercator
> coordinates used compared to previously.
> 
> Previously, the mercator coordinates (-85000, 6595000) corresponded to
> Fernhurst, West sussex, UK but (as you can see at http://www.free-map.org.uk)
> they now correspond to Lavant, some 15 miles south.
> 
> The code I previously used to convert from latlon to mercator is a standard
> algorithm found on the web and is at
> 
> http://www.free-map.org.uk/freemap/javascript/lib/converter.js
> (look in the Mercator section)

That code looks like it is assuming a non-sperical earth (which is
correct but not what the Google-like tiling scheme assumes). The
values for a and b look like the diameter of the earth along each
axis and are different.

You will need to use a spherical mercator calculation I suspect
which assumes the earth has the same diameter in all directions.

The code we use on the main OSM site can be seen at:

http://trac.openstreetmap.org/browser/sites/rails_port/public/javascripts/map.js

Tom

-- 
Tom Hughes (tom at compton.nu)
http://www.compton.nu/




More information about the dev mailing list