I've got a map in OpenLayers with 12 possible zoom levels given by a resolution array as defined in view:
var map = new Map({
//...
view: new View({
resolutions: [8, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625, 0.0078125, 0.00390625],
zoom: 2,
constrainResolution: true
}),
});
The maximum zoom seems to be given implicitly by the resolutions array and is set to 12.
In my use case, users should be able to select detail or overview layers for which I want to constrain the zoom temporarily:
map.getView().setMaxZoom(7);
I would expect the zoom now to stop at zoom level 7 (i. e. restrict the zoom to resolutions of
[8, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625]
).
Unfortunately, it doesn't work for me as intended. Visually, zoom will stop at zoom level 7 but internally, on zoom interactions, zoom is being incremented until the original maximum zoom 12 is reached. Not only is this notable by calling map.getView().getZoom()
in these stages, but also by user interaction. When “invisibly” having zoomed out to zoom level 12 (the original max zoom), users have to undo 5 zoom interactions (e. g. mouse wheel) before again reaching the state where zooming out results in a visible change.
Is there any way to achieve the behavior I am aiming for?
view.setConstrainResolution(true);
and remove the constraint withview.setConstrainResolution(false);
. openlayers.org/en/latest/apidoc/… – Mike Jan 18 at 10:51