1
我試圖使用ol.interaction.Draw
將多邊形添加到openlayers地圖。我也有一個快照交互,並設置關閉,而我在按住Shift鍵。在ol.interaction.Draw中按住shift-click事件打開圖層
const
snapInteraction = new ol.interaction.Snap({
source: drawLayer.getSource()
}),
turnOnSnap = (evt) => {
if (!isShiftKey(evt)) {
return;
}
console.log('shift key is down, turning off snap');
snapInteraction.setActive(false);
},
turnOffSnap = (evt) => {
if (!isShiftKey(evt)) {
return;
}
console.log('shift key is up, turning on snap');
snapInteraction.setActive(true);
};
document.addEventListener('keydown', turnOnSnap);
document.addEventListener('keyup', turnOffSnap);
這可以禁用捕捉。但是,當我按住Shift鍵時,我的Draw互動功能不起作用。我知道condition
參數默認爲ol.events.condition.noModifierKeys
,但是當我自定義condition
時,它甚至不會被擊中!
const drawInteraction = new ol.interaction.Draw({
source: drawLayer.getSource(),
type: 'Polygon',
condition: function (evt) {
console.log("yo, why isn't this hit when I hold down shift?", evt);
return (ol.events.condition.noModifierKeys(evt) ||
ol.events.condition.shiftKeyOnly(evt));
}
});
爲什麼drawInteraction忽略shift + click事件?