How to create a simple draggable marker in OpenLayers

泪湿孤枕 提交于 2019-12-23 02:35:03

问题


Very simple question, how can I create a draggable marker in an OpenLayers map, and get the latlon when its been dragged. From google, it seems that you can have draggable vectors, but not draggable markers.

I've seen some references to OpenLayers.Control.DragMarker, but this doesn't seem to be in the "core" library. It's used in this example but that seems to be using a custom OpenLayers JS file, so I have no idea how to go about including that in my code.

Code thus far (to add a simple marker):

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:


I've done that, but I can't find that code now. Take a look at this OpenLayers Example:

Drag Feature




回答2:


Can you change the markers with features? look this link



来源:https://stackoverflow.com/questions/4376360/how-to-create-a-simple-draggable-marker-in-openlayers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!