[OpenLayers-Users] Need some help with Mercator projection

Richard Vong rvong at digitalglobe.com
Wed Apr 18 12:45:01 EDT 2007


Hi,

I am using a tile system similar to that used by Google Map or MS 
Virtual Earth, in which the tiles are pre-built (i.e. sliced into 
256x256 pixels tiles by a GIS software from a set of large images that 
were projected into the Mercator-Spheroid projection). Each tile is then 
identified by a column, row, and zoom value. So I built a Layer that 
draws these tiles on the map and it inherits the OpenLayers.Layer.Grid 
and OpenLayers.Layer.FixedZoomLevel classes. In my Layer class, I have 
implemented the getLonLatFromViewPortPx() and getViewPortPxFromLonLat() 
functions that basically translate a Point to a LonLat under the 
Mercator projection. The Mercator projection transform is more than a 
simple scaling function which involves a cosine correction for the 
latitude.
The Layer works very well as expected; calling setCenter() for a desired 
LonLat moves the map to the correct location without problems. However, 
now I encounter a issue when I want to draw SVG polygons on top of this 
Mercator projected layer. The polygons diverge from the correct location 
around the edge of the map. I have located the source of the problem in 
the OpenLayers.Renderer.SVG class. This class simply scales the list of 
LonLat points (the vertices of the Feature, vector polygon) by the 
resolution or scale of the map to obtain the viewport point to which to 
draw the polygon. This operation resembles to a re-projection 
transformation, but the wrong one for Mercator. I have included two 
links to screenshots that show this problem:
1- Vector layer working correctly using OpenLayers' default projection 
EPSG4326. Link:
http://12.25.176.42:8080/openlayers/vector4326.jpg
2- Vector layer not working over aerial imagery using Mercator 
projection. Link:
http://12.25.176.42:8080/openlayers/vectorMercator.jpg

So my question is: would it be better for OpenLayers to implement a 
Projection class that can abstract the conversion from viewport-px to 
LonLat (and vice versa) in a more general way other the default 
scaling/resolution approach integrated into the OpenLayers.Layer class? 
Hence, this class can be used by the other OpenLayers tools and features 
to correctly display information on the map.
Or is there any other approach to solve this problem?

Many thanks in advanced.

Richard



More information about the Users mailing list