Jon Garrido Martin GIS Developer

GIS Developer Freelance

Zoomend event in openlayers 3

By jongarrido | September 30, 2015 | 0 Comment

Hi,
It’s not performed a zooend event on map object in openlayers 3, by the moment….
Here it’s a simple way to perform this event

We will need a global variable to alocate map’s view zoom level. I’ve named it as currentZoomLevel.

There is available a moveend event. Let’s use it, and add a zoom level check function..

In case of there’s a new zoom level, we trigger a zoomend event to DOM’s document.

Finally we will need to add zoomend listener to the document element.


var = currentZoomLevel;

map.on('moveend', checknewzoom);

function checknewzoom(evt)
{
var newZoomLevel = map.getView().getZoom();
if (newZoomLevel != currentZoomLevel)
{
currentZoomLevel = newZoomLevel;
$(document).trigger("zoomend", zoomend_event);
}
}

$(document).on('zoomend', function () {
console.log("Zoom");
//Your code here
});

I hope you find this code useful!!

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *