I'm upgrading to OpenLayers 6 and the code that previously worked
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;
}
has stopped working for the stopDownHandler
The code I'm trying to implement is
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;
}
I've also tried using the type "UIEvent" in stopDownHandler and tried just setting it to false...the OpenLayers docs say it needs a function and the new pattern doesn't throw errors for any other handlers but 'stopDownHandler' i.e (
function handleDownEventHandler(evt: MapBrowserEvent<MouseEvent>) {
if (evt.originalEvent.buttons !== 2) {
downClick = evt.coordinate;
return true;
} else { return false; }
}
) works
I receive the error
Type '(evt: MapBrowserEvent) => boolean' is not assignable to type '(arg0: boolean) => boolean'. Types of parameters 'evt' and 'arg0' are incompatible. Type 'boolean' is not assignable to type 'MapBrowserEvent'.ts(2322)
when using type UIEvent and error
Type '(evt: MapBrowserEvent) => boolean' is not assignable to type '(arg0: boolean) => boolean'. Types of parameters 'evt' and 'arg0' are incompatible. Type 'boolean' is not assignable to type 'MapBrowserEvent'.ts(2322)
when using type MouseEvent...even though type mouse event works for the other handlers.
The OpenLayers documentation doesn't give a good example of how to use this and I can't find a good explanation in any of the "Upgrade" documentation how to change this so it will work.
Any help is greatly appreciated