[OpenLayers-Dev] Problem with getting latitude nad longitude(mapnik
layer)
sniipe
sniipe at gmail.com
Tue Feb 17 15:46:43 EST 2009
Hi!
I am a beginner in GIS and maps programming. I try to do a certain
project but I have some problems. Here is my code:
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'click': this.trigger
}, this.handlerOptions
);
},
trigger: function(e) {
var lonlat = map.getLonLatFromViewPortPx(e.xy);
document.getElementById('lat').value =
lonlat.lat.toString();
document.getElementById('lng').value =
lonlat.lon.toString();
}
});
var map;
function init(){
map = new OpenLayers.Map('map');
var layerMapnik = new
OpenLayers.Layer.OSM.Mapnik("Mapnik");
var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers
WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers:
'basic'} );
map.addLayers([layerMapnik, ol_wms]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
// map.setCenter(new OpenLayers.LonLat(0, 0), 0);
map.zoomToMaxExtent();
var click = new OpenLayers.Control.Click();
map.addControl(click);
click.activate();
}
On click event(only on Mapnik layer) I received some data, but it is
not longitude and latitude. And my question is how to convert it to
get properly values(lat, lon)?
With kind regards
snipe
More information about the Dev
mailing list