OL互动 - mousedown

时间:2016-12-12 18:09:11

标签: openlayers-3

我看到可以通过点击或单击或指针移动来完成ol交互 - 但是,是否可以使用mousedown / mouseup完成?简而言之,我们希望用户只要单击鼠标按钮就可以编辑功能,但在鼠标按钮释放时保存/停止。

featureRotateDown = new ol.interaction.Select({
        condition: ol.events.condition.pointerdown
    });

    featureRotateUp = new ol.interaction.Select({
        condition: ol.events.condition.pointerup
    });

    map.addInteraction(featureRotateDown);
    map.addInteraction(featureRotateUp);

featureRotateDown.on('select', function(event) {
        $.each(event.selected, function (index, feature) {
            console.log(feature);
            console.log('1');
        });
    });

    featureRotateUp.on('select', function(event) {
        $.each(event.selected, function (index, feature) {
            console.log(feature);
            console.log('3');
        });
    });

换句话说,想象一下放置在地图上的标记是箭头。当光标在标记上并按下鼠标按钮时,我希望能够根据需要旋转它。

1 个答案:

答案 0 :(得分:1)

尝试pointerdownpointerup

map.on('pointerdown', function (event) {
  // doStuff...
  // ALTERNATIVE 1: get a feature at click position (with very small tolerance)
  map.forEachFeatureAtPixel(event.pixel, function(feature, layer){
    // doStuff with your feature at click position
  });

  // ALTERNATIVE 2: get the closest feature
  closestFeature = yourVectorSource.getClosestFeatureToCoordinate(event.coordinate);
})

map.on('pointerup', function (event) {
  // doStuff...
})

在这些功能中,您可以使用forEachFeatureAtPixelgetClosestFeatureToCoordinate来访问这些功能。 另请参阅此JSFiddle