Openlayers 3 OL交互-鼠标向下

Openlayers 3 OL交互-鼠标向下,openlayers-3,Openlayers 3,我看到有一个ol交互可以在单击、单击或指针移动时完成,但是,有一个可以通过mousedown/mouseup完成吗?简言之,我们希望用户能够编辑一个功能,只要点击鼠标按钮,但在释放鼠标按钮时保存/停止 featureRotateDown = new ol.interaction.Select({ condition: ol.events.condition.pointerdown }); featureRotateUp = new ol.interaction.

我看到有一个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');
        });
    });

换句话说,想象一个放置在地图上的箭头标记。我希望能够在光标位于标记上并按下鼠标按钮时,尽可能多地旋转它。

尝试
指针向下
指针向下

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...
})
在函数中,您可以使用
forEachFeatureAtPixel
getClosestFeatureToCoordinate
访问功能。
也看看这个

我试过了。向上的指针工作正常,但向下的指针失败。我需要它处理向量层中的单个特征,而不是总体地图上的。请参阅我发布的代码。您可以使用
forEachFeatureAtPixel
来实现这一点。这似乎大部分都是有效的。我的问题是,如果一个人没有准确地点击箭头,该功能就不会启动。我们如何解决这个问题?因此,无论他们在何处单击箭头,函数都会在
地图内激发。在
函数上,您还可以在
ol.source vector上使用
getClosestFeatureToCoordinate
来选择一个特征以增加公差。()看看ol.interaction.Pointer及其handleDownEvent和handleUpEvent函数。要在鼠标按下时获得该功能,必须使用forEachFeatureAtPixel方法。