0

In an OpenLayers 4 application, I want to refresh the view of a layer when the user crosses a particular zoom level, either zooming in or zooming out (the tile rendering changes at that point from less to more complex or vice versa).

I can capture change:resolution, and get the new value, but is there a way of getting the old value?

1

One solution is in the answer :)

If you look the View API for change resolution, you will see that it's emit an event The description states the following

oldValue{*}

The old value. To get the new value use e.target.get(e.key) where e is the event object.

Just applied the recipe to get what you want.

I've also considered another approach using movestart, movend map events. Both provided solutions are not the "silver bullet" as you will see in this demo

To better understand, in the demo, open the browser debugger (I use some console.log) and look at source comments. I explained here the issues I got with both approaches. There is maybe a better way but I did not found it at the moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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