Openlayers 3中的拖放功能

Openlayers 3中的拖放功能,openlayers,openlayers-3,Openlayers,Openlayers 3,OpenLayers 2“OpenLayers.Control.DragFeature”功能的等效功能是什么。我需要在地图上添加一个图标,可以用鼠标移动。当我下车的时候,我需要赶上比赛。 在OpenLayers 2中,描述的功能是: new OpenLayers.Control.DragFeature(this.MarkersLayer, { onComplete: function(feature, pixel) { /* here comes the action afte

OpenLayers 2“OpenLayers.Control.DragFeature”功能的等效功能是什么。我需要在地图上添加一个图标,可以用鼠标移动。当我下车的时候,我需要赶上比赛。 在OpenLayers 2中,描述的功能是:

new OpenLayers.Control.DragFeature(this.MarkersLayer, {     
    onComplete: function(feature, pixel) { /* here comes the action after dropping the marker */ }}

有人知道如何使用OpenLayers 3实现这一点吗?

没有人知道。你也不能画圆和圆。viva la OL2

OpenLayers 3现在包含一个示例,演示如何实现“拖动功能”交互。看

因此,OpenLayers 3库仍然没有提供“拖动功能”交互,但它提供了扩展点,使得在应用程序级别实现这种交互成为可能


请注意,您必须使用OpenLayers 3的“主”分支来实现您自己的“拖动功能”交互,如示例所示。另一种选择是等待3.1.0,它很快就会推出。

如果有人仍然对这个问题的答案感兴趣,下面的代码应该达到要求的要求(因为我在这类问题上挣扎了一段时间):


// Create the icon feature
var iconFeature = new ol.Feature({
    geometry: new ol.geom.Point([lng, lat])
});

// Set the style for the icon feature 
iconFeature.setStyle(new ol.style.Style({
    image: new ol.style.Icon(({
        anchor: [0.5, 35],
        anchorXUnits: 'fraction',
        anchorYUnits: 'pixels',
        opacity: 1,
        src: markerGraphics
    }))
}));

// Create the vector layer with it's source
var vectorLayer = new ol.layer.Vector({
    source: new ol.source.Vector({
        features: [iconFeature]
    })
});

// Drag and drop feature
var dragInteraction = new ol.interaction.Modify({
    features: new ol.Collection([iconFeature]),
    style: null,
    pixelTolerance: 20
});

// Add the event to the drag and drop feature
dragInteraction.on('modifyend',function(){
    callYourFunction();
},iconFeature);

// Add the vector layer and the refering drag and drop interaction
map.addLayer(vectorLayer);
map.addInteraction(dragInteraction);

// Create the icon feature
var iconFeature = new ol.Feature({
    geometry: new ol.geom.Point([lng, lat])
});

// Set the style for the icon feature 
iconFeature.setStyle(new ol.style.Style({
    image: new ol.style.Icon(({
        anchor: [0.5, 35],
        anchorXUnits: 'fraction',
        anchorYUnits: 'pixels',
        opacity: 1,
        src: markerGraphics
    }))
}));

// Create the vector layer with it's source
var vectorLayer = new ol.layer.Vector({
    source: new ol.source.Vector({
        features: [iconFeature]
    })
});

// Drag and drop feature
var dragInteraction = new ol.interaction.Modify({
    features: new ol.Collection([iconFeature]),
    style: null,
    pixelTolerance: 20
});

// Add the event to the drag and drop feature
dragInteraction.on('modifyend',function(){
    callYourFunction();
},iconFeature);

// Add the vector layer and the refering drag and drop interaction
map.addLayer(vectorLayer);
map.addInteraction(dragInteraction);

基于,可以将侦听器附加到而不是。使用此解决方案,可以在停止拖动层/图标后执行函数(类似于OpenLayers 2中的“dragend”)

ol3中目前还没有拖动功能组件。我已经开始了一个拖动功能的交互工作,但这是未完成的工作。看,死链接。请在您的答案中添加新链接。