似乎我有一个简单的要求,但我对OpenLayer的知识似乎有限。
我需要在地图中放置1个特征,放置后,将该特征拖到正确的位置,然后获得经度/长坐标。这将是很好的,我可以删除功能重新开始…
但首先:我已经设法放置了一个功能,但无法从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);
谢谢马可
你需要添加dragFeature控件到你的地图:
map.addControl(drawFeature);
在添加drawFeature控件的地方执行此操作,然后activate()将按原样工作