2014-03-28 44 views
2

我使用的是OpenLayers,我已经找到拖动标记的实现,但没有关于如何返回拖动位置的文档。我已经试过这样:我怎样才能拖动一个标记,并得到lon/lat

drag = new OpenLayers.Control.DragFeature(vectors, { 
    autoActivate: true, 
    onComplete: function() { 
    alert('hello') 
    } 
}); 

不退还其标记被拖所以我不能拖后得到其经度或纬度。

回答

2

实际上the official documentation明确指出onComplete回调的第一个参数是受影响的功能。您可以轻松地检查处理程序中的功能。

举一个例子去http://dev.openlayers.org/examples/drag-feature.html,打开浏览器的JS控制台,并执行这个片段:

map.addControl(new OpenLayers.Control.DragFeature(vectors, { 
    autoActivate: true, 
    onComplete: function (feature) { 
    alert('x=' + feature.geometry.x + ', y=' + feature.geometry.x); 
    } 
})); 

然后添加一个点,并尝试拖动。