2

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 でこれを実現する方法を知っている人はいますか?

4

3 に答える 3

2

OpenLayers 3 には、「ドラッグ機能」の相互作用を実装する方法を示す例が含まれるようになりました。http://openlayers.org/en/master/examples/drag-features.htmlを参照してください。

そのため、OpenLayers 3 ライブラリはまだ「ドラッグ機能」の相互作用を提供していませんが、アプリケーション レベルでそのような相互作用を実装できるようにする拡張ポイントを提供しています。

例のように、独自の「ドラッグ機能」インタラクションを実装するには、OpenLayers 3 の「マスター」ブランチを使用する必要があることに注意してください。もう 1 つのオプションは、3.1.0 を待つことです。これは間もなくリリースされるはずです。

于 2014-12-20T23:19:19.727 に答える
1

誰かがこの質問への回答にまだ興味がある場合は、次のコードで要求された要件を満たす必要があります (この種の問題にしばらく苦労したため)。


// 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」のように動作します)。

于 2016-03-10T13:49:19.300 に答える