mor*_*ell 6 drag-and-drop openlayers openlayers-3
在OL3示例中,我可以拖动对象并放在地图上,但我想移动/调整大小/旋转已经在地图上的东西,如ol.geom.Point和其他ol.geom对象.什么是OL3方式呢?
OL2中的示例:
OpenLayers.Control.DragFeature(layer)
Run Code Online (Sandbox Code Playgroud)
不知道为什么OL3网站上的例子如此复杂.使用可以轻松实现拖动矢量对象new ol.interaction.Modify.
这是一个更简单的工作示例:jsFiddle
简而言之,如果你的标记是:
var pointFeature = new ol.Feature(new ol.geom.Point([0, 0]));
Run Code Online (Sandbox Code Playgroud)
您可以将修改交互定义为:
var dragInteraction = new ol.interaction.Modify({
features: new ol.Collection([pointFeature]),
style: null
});
map.addInteraction(dragInteraction);
Run Code Online (Sandbox Code Playgroud)
然后,您可以获得一个事件,以便在拖动后获取标记的新位置,如下所示:
pointFeature.on('change',function(){
console.log('Feature Moved To:' + this.getGeometry().getCoordinates());
},pointFeature);
Run Code Online (Sandbox Code Playgroud)