currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView to present a map which is provided by my own tileserver.
I`m using OpenLayers to show this map and now I want to use a Text Layer to show some custom POI`s.
Unfortunately, the map uses 90013 projection:
map = new OpenLayers.Map ("map", {
controls:[
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.Permalink(),
new OpenLayers.Control.ScaleLine({geodesic: true}),
new OpenLayers.Control.Permalink('permalink'),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.Attribution()],
//maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
maxResolution: 156543.0339,
numZoomLevels: 19,
units: 'm',
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:900913")
} );
So when I want to display the Markes provided by the TextLayer, I have to use coordinates in the right format. To center the map is easy:
var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
map.setCenter (lonLat, zoom);
But how can I do this transformation automatically for the TextLayer? I want to have the lat lon values according to the well-known EPSG4326 into the Text Layer data file (columns lat long) and not the values according to 900913 (what I`m doing at the moment to have it work).
Is there a way to let OpenLayers transform the Text Layer`s coordinates automatically to the format used in the map? Maybe a callback function to override like onShow?
Thanks for your help!
Otherwise I would have to translate the lat lon values myself and put the calculated value in the text file which will make performance to suffer…
Finally, I found the answer myself and I must say I`m very impressed! OpenLayers is quite powerful!
Here is my solution:
In the options of the map-object you have to set displayOptions to the projection of your layer, in my case it`s the following to support EPSG:4326:
Then you only have to take care that the layer uses this projection (if it`s not the default value already). In my case, Text Layer didn`t work correctly on Android (in a WebView): I couldn`t open a popup when clicking on the image of a marker from the textfile. Instead, I`m using a Vector-Layer according to the sundials-Example:
In the text-file I can now use the LatLon-values of the EPSG-4326 format. It`s so easy 😉