0

I have an application using OpenLayers 6 where I am listening to map.getView().on('change:resolution', ...).

When the user zooms with the scroll wheel on the mouse, my handler gets blasted with dozens of events with intermediate zoom levels (between start and end zoom values).

My handler function is compute intensive, and I only want to receive the event with the last and final zoom level.

As a work-around, I have some code that stores the latest event, and then calls the real handler after 500ms. The code is ugly and becoming complex to maintain. Is there a better way to handle this in OpenLayers?

3
  • 2
    Haven't tried it, but does the moveend event get called for each iteration of the scroll-wheel events? See the accepted answer for a method using the moveend event at: gis.stackexchange.com/questions/309387/… Commented May 19, 2023 at 4:07
  • Many thanks! This does the trick and greatly simplifies our code!
    – superlazy
    Commented May 19, 2023 at 19:59
  • good to hear it worked! I've added it as an answer now I know it works. Commented May 24, 2023 at 4:05

2 Answers 2

1

Try using the moveend event instead. See the accepted answer for a method using the moveend event at:

Detecting zoom change in OpenLayers

0

Try it. map.on('zoomend', function);

Not the answer you're looking for? Browse other questions tagged or ask your own question.