0

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

Funn_Bobby
  • 647
  • 1
  • 20
  • 57
  • If it is working for mouse but not pointer do you need a polyfill? https://github.com/openlayers/openlayers/releases/tag/v6.4.0 – Mike Jul 23 '21 at 13:12
  • It's not really about if it works or not...it doesn't build. I'll update the question with this info – Funn_Bobby Jul 23 '21 at 13:18

1 Answers1

0

Changing evt: MapBrowserEvent to arg0: boolean made the error go away but this does not seem like a good solution...it actually seems like a bug.

Funn_Bobby
  • 647
  • 1
  • 20
  • 57