如何仅在班次点击中制作翻译事件

时间:2017-12-01 01:59:08

标签: openlayers-3

有没有办法让ol.interaction.Translate只在转移时点击+点击它当你一起翻译和修改时很难编辑图层。

var selectInteraction = new ol.interaction.Select({
    condition: ol.events.condition.singleClick,
    //toggleCondition: ol.events.condition.shiftKeyOnly,
    layers: function (layer) {
        return layer.get('id') == 'redline';
    }
});

var modify = new ol.interaction.Modify({
    features: selectInteraction.getFeatures()
});

var Translate = new ol.interaction.Translate({
    features: selectInteraction.getFeatures()
});

map.getInteractions().extend([selectInteraction, modify, Translate]);

selected_features = selectInteraction.getFeatures();

1 个答案:

答案 0 :(得分:0)

翻译扩展ol.interaction.Pointer,所以according to the doc,您可以为多个事件提供处理程序方法。如果处理程序返回false,则会丢弃偶数(至少从翻译的角度来看)。

您还可能希望提供handleEvent,以便事件不会首先冒充其他事件:

  

该函数可能返回false以防止事件的传播   到地图互动链中的其他互动。

所以你可能想引入一个全局状态来跟踪一些迭代是否已经在运行,如果是,则取消所有其他交互。

let isInteractionRunning=false;

const Translate = new ol.interaction.Translate({
    features: selectInteraction.getFeatures(),
    handleDownEvent: (evt) => {
        const shiftKeyPressed = evt.originalEvent.shiftKey;

        if (shiftKeyPressed && !isInteractionRunning) {
            isInteractionRunning = true;
            return true;
        }
        return false;
    },
    handleUpEvent: function() {
        // set back global state
        isInteractionRunning = false;
        return true;
    }
});

const modify = new ol.interaction.Modify({
    features: selectInteraction.getFeatures(),
    handleDownEvent: () => {
        if (!isInteractionRunning) {
            isInteractionRunning = true;
            return true;
        }
        return false;
    },
    handleUpEvent: function() {
        // set back global state
        isInteractionRunning = false;
        return true;
    }
});
相关问题