Javascript 捕捉ol.interaction.Draw打开图层中的shift单击事件

Javascript 捕捉ol.interaction.Draw打开图层中的shift单击事件,javascript,openlayers,Javascript,Openlayers,我正在尝试使用ol.interaction.Draw向openlayers地图添加多边形。我也有一个快速的互动,并设置为关闭,而我按住shift键 const snapInteraction = new ol.interaction.Snap({ source: drawLayer.getSource() }), turnOnSnap = (evt) => { if (!isShiftKey(evt)) { return; } con

我正在尝试使用
ol.interaction.Draw
向openlayers地图添加多边形。我也有一个快速的互动,并设置为关闭,而我按住shift键

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键时,我的绘图交互不起作用。我知道
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事件?

freehandCondition的默认设置是捕获shift+click事件,因此不会对其进行计算。将其更改为其他内容,shift+click事件将命中自定义条件函数

const drawInteraction = new ol.interaction.Draw({
  source: drawLayer.getSource(),
  type: 'Polygon',
  condition: function (evt) {
    return (ol.events.condition.noModifierKeys(evt) ||
      ol.events.condition.shiftKeyOnly(evt));
  },
  freehandCondition: ol.events.condition.never, // <-- add this line
});
const drawInteraction=new ol.interaction.Draw({
来源:drawLayer.getSource(),
键入:“多边形”,
条件:功能(evt){
返回(ol.events.condition.noModifierKeys(evt)||
ol.events.condition.shiftKeyOnly(evt));
},
freehandCondition:ol.events.condition.never//