簡體   English   中英

OpenLayers 如何停止在 OpenLayers 6 中傳播指針

[英]OpenLayers how do I stop propagation of pointer in OpenLayers 6

我正在升級到 OpenLayers 6 和以前工作的代碼

  import { MapBrowserPointerEvent as olMapBrowserPointerEvent } from 'ol/events/Event';

  const simpleLineInteraction: PointerInteraction = new PointerInteraction({
  handleDownEvent: handleDownEventHandler,
  handleDragEvent: handleDragEventHandler,
  handleUpEvent: handleUpEventHandler,
  stopDown: stopDownHandler
  });
  function stopDownHandler(evt: olMapBrowserPointerEvent) {
  return false;
  }

已停止為 stopDownHandler 工作

我試圖實現的代碼是

import  MapBrowserEvent  from 'ol/MapBrowserEvent';
const simpleLineInteraction: PointerInteraction = new PointerInteraction({
handleDownEvent: handleDownEventHandler,
handleDragEvent: handleDragEventHandler,      
handleUpEvent: handleUpEventHandler,
stopDown: stopDownHandler
});
function stopDownHandler(evt: MapBrowserEvent<MouseEvent>) {
return false;
}

我還嘗試在 stopDownHandler 中使用類型“UIEvent”並嘗試將其設置為 false...OpenLayers 文檔說它需要一個函數並且新模式不會為任何其他處理程序拋出錯誤,但“stopDownHandler”即(

function handleDownEventHandler(evt: MapBrowserEvent<MouseEvent>) {
if (evt.originalEvent.buttons !== 2) {
downClick = evt.coordinate;
return true;
} else { return false; }
}

) 作品

我收到錯誤

類型 '(evt: MapBrowserEvent) => boolean' 不能分配給類型 '(arg0: boolean) => boolean'。 參數“evt”和“arg0”的類型不兼容。 類型 'boolean' 不可分配給類型 'MapBrowserEvent'.ts(2322)

使用類型 UIEvent 和錯誤時

類型 '(evt: MapBrowserEvent) => boolean' 不能分配給類型 '(arg0: boolean) => boolean'。 參數“evt”和“arg0”的類型不兼容。 類型 'boolean' 不可分配給類型 'MapBrowserEvent'.ts(2322)

使用類型 MouseEvent 時...即使類型鼠標事件適用於其他處理程序。

OpenLayers 文檔沒有給出如何使用它的一個很好的例子,我在任何“升級”文檔中都找不到一個很好的解釋如何改變它以便它可以工作。

任何幫助是極大的贊賞

將 evt: MapBrowserEvent 更改為 arg0: boolean 使錯誤消失,但這似乎不是一個好的解決方案......它實際上似乎是一個錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM