There is no appropriate zoom event listener in OpenLayers v5.3 yet, but there is a workaround suggested in this ticket:
You can use
this.view.instance.on('change:zoom', evt => console.log(this.view.zoom));
whereview
is aviewChild : @ViewChild(ViewComponent) view: ViewComponent;
to detect zoom changes.
Can anyone please explain to newbies how to utilize this? How to use that code with an instance of a map view which is usually got by calling map.getView()
?
Best Answer
To hook on zoom end event is fairly simple: listen to
moveend
event and compare old and new zoom:If you want to catch zoom start, it's more complicated. I found a way but I don't like it, it's not how it should be done. I noticed that exposed method
view.animate
is called before any animated map event. I replaced it with my own, where I check for zoom, and then call original method: