SubClosure

{ Don't Repeat Yourself ! }

Browsing Posts in openlayers

Probably one of the first things you would want to do with an openlayers map is adding some interaction.
Amazingly it is difficult to find an easy and quick example on how to do it.

Here is an example on how to move an Openlayer.Marker to the point where a user clicked on the map.

 

var markers = new OpenLayers.Layer.Markers( "Markers" );
marker = new OpenLayers.Marker(lonLat) ;
markers.addMarker(marker);
map.addLayer(markers);

map.events.register("click", map , function(e){
var opx = map.getLayerPxFromViewPortPx(e.xy) ;
marker.map = map ;
marker.moveTo(opx) ;
});


Another example can be found on the openlayers examples page.
I found it a bit overkill though and more difficult to use.

This error occurs on line 915 in Openlayers.js.

If you get this error when using the moveTo method of an OpenLayers.Marker object  set the map on the marker first.

e.g.

mymarker.map = map ;
mymarker.moveTo(opx ) ;

 

 

Get Adobe Flash player