For each zoom change, my map makes about 56 requests for map tiles (depending on the map/screen size). If the user rapidly zooms in or out, all these map tile requests get queued up
You can avoid requests for each zoom level that the user passes through as suggested by janb (their code does not work in the latest release anymore).
By default, MouseWheelZoom waits 80 milliseconds after the first scroll event before doing anything (timeout:80
) and does not allow zooming more than one click at a time (maxDelta:1
) (the documentation doesn't say why these speed bumps are in place). While it waits for the timeout, no zooming happens and so no intermediate zoom levels are loaded. By setting maxDelta
to a greater value, the user can skip over zoom levels if they scroll more than one click within the timeout period.
You could make the application more responsive by reducing the 80 milliseconds, but eventually you forego the chance of zooming fast enough to skip loading zoom levels.
Another setting I found relevant is the animation duration. It stacks animations instead of waiting for them to complete, so this (thankfully) does not limit the user (so many applications make the user wait for an animation before interaction is enabled). Try setting it to 2500 ms and then scroll at different points on the map while the animation is still going :). The default is 250 ms but I find a slightly lower value to feel more responsive.
From some testing, 6 zoom levels is about the most precise I can do without ending up in a place I didn't intend to. This may not be a good default for everyone, but maxDelta:6
seems to be a good value for me. Setting a timeout
of 30 ms resulted in it not accumulating all the zooming I tried to do at once, so 40 ms strikes a good balance for me between doing what the user asked and no unnecessary waiting.
let map = new ol.Map({
interactions: ol.interaction.defaults.defaults({
mouseWheelZoom: false,
}).extend([
new ol.interaction.MouseWheelZoom({
maxDelta: 6,
timeout: 40,
duration: 150,
}),
]),
});
The code seems a bit unwieldy but this is how an example overrides the default MouseWheelZoom options.