似乎我有一个简单的要求,但我对OpenLayer的了解似乎有限。
我需要在地图中放置1个要素,放置后,将此要素拖到正确的位置,然后得到Lat / Long坐标。我可以删除该功能以便重新开始...
但首先: 我已设法放置一个功能,但无法从drawfeature切换到dragfeature。 如果有更好的方法来实现我的目标,我更乐于学习!
// create the map variable
map = new OpenLayers.Map("map");
// create layers
var mapLayer = new OpenLayers.Layer.OSM(); // openstreetmap
var vectorLayer = new OpenLayers.Layer.Vector("Vector", {styleMap: styleMap}); // vector
// add the layers to the map
map.addLayer(mapLayer);
map.addLayer(vectorLayer);
map.addControl(new OpenLayers.Control.MousePosition());
var drawFeature = new OpenLayers.Control.DrawFeature(vectorLayer, OpenLayers.Handler.Point);
var dragFeature = new OpenLayers.Control.DragFeature(vectorLayer);
map.addControl(drawFeature);
drawFeature.activate();
vectorLayer.onFeatureInsert = function () {
drawFeature.deactivate();
// how to switch to drag feature???
// dragFeature.activate(); does not seem to work
}
...
map.setCenter (lonLat, zoom);
由于 马可
答案 0 :(得分:2)
您需要将dragFeature控件添加到地图中:
map.addControl(drawFeature);
在添加drawFeature控件的位置执行此操作,然后activate()将按原样运行。