[Tilesathome] Lowzoom Place Labels displaced

Matthias Julius lists at julius-net.net
Fri Sep 19 17:48:40 BST 2008


Knut Arne Bjørndal <bob+osm at cakebox.net> writes:

> The projection algorithm somebody threw in somewhere else in this
> thread seemed quite different from what is currently in osma, which is
> roughly like this:
> lat_rad = middleLatitude * pi / 180
> projection = 1/cos(lat_rad)
>
> x = $width - (($topRightLongitude - @lon) * 10000 * $scale)
> y = $height + (($bottomLeftLatitude - @lat) * 10000 * $scale * $projection)
>
> Could this be the difference between proper mercator and spherical
> mercator or something? (I'm guessing wildly here, feel free to
> disregard if I'm writing nonsense)
>
> If the entire projection algorithm is plain wrong and we can find some
> way of doing a better one in xslt that's bound to help...

Mercator projection is actually quite simple:

x = Scale * Longitude
y = Scale * Latitude / sin(Latitude)

or, if we want strictly positive coordinates:

x = Scale * (Longitude + 180 deg)
y = Scale * (Latitude / sin(Latitude) + 180 deg)
                                        ^^^^^^^
                                        this is because we use a
                                        square map

This should be applied to the raw OSM data before anything else is
done.  The renderers then just need to translate mercator coordinates
into SVG coordinates which is just scale + offset.

The only places the client should need to worry about projections is
where it has to figure out the bounding box to download and in a
projection pre-processor.  Everything else is just dealing with
cartesian map coordinates.  

The pre-processor could also be made to return the bounding box for a
set of tile coordinates.  Then, one would just need to switch the
pre-processor to create a map in a different projection.

Matthias




More information about the Tilesathome mailing list