How to create a simple drag-and-drop marker in OpenLayers

A very simple question is how can I create a draggable marker in an OpenLayers map and get latlon when dragging it. From Google it seems that you can drag vectors, but not drag markers.

I saw some links to OpenLayers.Control.DragMarker , but this does not seem to be in the "main" library. It was used in this example, but it looks like it is using a custom JS OpenLayers file, so I have no idea how to include this in my code.

Code so far (to add a simple token):

 var layer = new OpenLayers.Layer.TMS( "TMS The Layer","", { url: '', serviceVersion: '.', layername: '.', alpha: true, type: 'png', getURL: overlay_getTileURL }); map.addLayers([layer]); var markers = new OpenLayers.Layer.Markers( "Markers" ); map.addLayer(markers); var lonLat = new OpenLayers.LonLat( -100 ,100 ); markers.addMarker(new OpenLayers.Marker(lonLat)); 
+1
source share
2 answers

I did this, but now I can not find this code. Take a look at this OpenLayers example:

Drag and drop function

+4
source

Can you change markers with functions? look at the link

+1
source

All Articles