Search code examples
azure-maps

Azure Maps - detect zoom direction


When zoomed, the map invokes zoomstart, zoom and zoomend events. Is there a way to tell if the map is zooming in our out? Really at zoomend, I need to understand if the map was zoomed in our out.


Solution

  • The following code accomplishes this...

    var currentZoomLevel;
    
    map.events.add('zoomstart', layer, function (e) { currentZoomLevel = map.getCamera().zoom; })
    map.events.add('zoomend', layer, function (e) {
        if (currentZoomLevel > map.getCamera().zoom) {
            // zoomed out
        }
    })