{"id":127,"date":"2015-09-30T10:02:09","date_gmt":"2015-09-30T10:02:09","guid":{"rendered":"https:\/\/jongarrido.es\/?p=127"},"modified":"2015-09-30T10:02:09","modified_gmt":"2015-09-30T10:02:09","slug":"zoomend-event-in-openlayers-3","status":"publish","type":"post","link":"https:\/\/jongarrido.es\/?p=127","title":{"rendered":"Zoomend event in openlayers 3"},"content":{"rendered":"<p>Hi,<br \/>\nIt&#8217;s not performed a zooend event on map object in openlayers 3, by the moment&#8230;.<br \/>\nHere it&#8217;s a simple way to perform this event<\/p>\n<p><!--more--><\/p>\n<p>We will need a global variable to alocate map&#8217;s view zoom level. I&#8217;ve named it as currentZoomLevel.<\/p>\n<p>There is available a moveend event. Let&#8217;s use it, and add a zoom level check function..<\/p>\n<p>In case of there&#8217;s a new zoom level, we trigger a zoomend event to DOM&#8217;s document.<\/p>\n<p>Finally we will need to add zoomend listener to the document element.<\/p>\n<p><code><\/p>\n<p>var = currentZoomLevel;<\/p>\n<p>map.on('moveend', checknewzoom);<\/p>\n<p>function checknewzoom(evt)<br \/>\n{<br \/>\n    var newZoomLevel = map.getView().getZoom();<br \/>\n    if (newZoomLevel != currentZoomLevel)<br \/>\n    {<br \/>\n        currentZoomLevel = newZoomLevel;<br \/>\n        $(document).trigger(\"zoomend\", zoomend_event);<br \/>\n    }<br \/>\n}<\/p>\n<p>$(document).on('zoomend', function () {<br \/>\n    console.log(\"Zoom\");<br \/>\n    \/\/Your code here<br \/>\n });<\/p>\n<p><\/code><\/p>\n<p>I hope you find this code useful!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, It&#8217;s not performed a zooend event on map object in openlayers 3, by the moment&#8230;. Here it&#8217;s a simple way to perform this event<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11,18,19,29],"class_list":["post-127","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-javascript","tag-openlayers","tag-openlayers-3","tag-zoomend"],"_links":{"self":[{"href":"https:\/\/jongarrido.es\/index.php?rest_route=\/wp\/v2\/posts\/127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jongarrido.es\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jongarrido.es\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jongarrido.es\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jongarrido.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=127"}],"version-history":[{"count":0,"href":"https:\/\/jongarrido.es\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions"}],"wp:attachment":[{"href":"https:\/\/jongarrido.es\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jongarrido.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jongarrido.es\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}