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?

superlazy
  • 101
  • 1
  • 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: https://gis.stackexchange.com/questions/309387/detecting-zoom-change-in-openlayers – Son of a Beach May 19 '23 at 04:07
  • Many thanks! This does the trick and greatly simplifies our code! – superlazy May 19 '23 at 19:59
  • good to hear it worked! I've added it as an answer now I know it works. – Son of a Beach May 24 '23 at 04:05

2 Answers2

1

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

Detecting zoom change in OpenLayers

Son of a Beach
  • 8,182
  • 1
  • 17
  • 33
0

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

Ninja
  • 1