Openlayers 如果用户单击“如何防止打开图层DrawInteraction绘制线条字符串”;“错误”;地区

Openlayers 如果用户单击“如何防止打开图层DrawInteraction绘制线条字符串”;“错误”;地区,openlayers,Openlayers,单击鼠标开始绘制多段线时,将触发“drawstart”事件。如果有条件阻止抽签,我可以取消/阻止抽签吗 const draw = new DrawInteraction({ type: geometryType }); draw.on('drawstart', (evt) => { // if some condition abort/prevent/cancel the whole thing } 这可能不是唯一的解决方案,但从地图中删除交互将取消正在进行的任何图形,然后再将其添加

单击鼠标开始绘制多段线时,将触发“drawstart”事件。如果有条件阻止抽签,我可以取消/阻止抽签吗

const draw = new DrawInteraction({ type: geometryType });
draw.on('drawstart', (evt) => {
  // if some condition abort/prevent/cancel the whole thing
}

这可能不是唯一的解决方案,但从地图中删除交互将取消正在进行的任何图形,然后再将其添加回地图

draw.on('drawstart', function(e) {
  if (cancelcondition) {
    map.removeInteraction(draw);
    map.addInteraction(draw);
  }
});
最好通过在绘图的“条件”选项中进行测试来停止绘图启动(这也可用于防止有效启动的绘图扩展到禁止区域)


这可能不是唯一的解决方案,但从地图中删除交互将取消正在进行的任何图形,然后再将其添加回地图

draw.on('drawstart', function(e) {
  if (cancelcondition) {
    map.removeInteraction(draw);
    map.addInteraction(draw);
  }
});
最好通过在绘图的“条件”选项中进行测试来停止绘图启动(这也可用于防止有效启动的绘图扩展到禁止区域)