View / add a method to compute a valid zoom level
The `getValidZoomLevel` apply the current resolution constraint to return a value that is guaranteed valid. This is used for interactions & controls which need a target value to work: the +/- buttons, the zoom clider, the dragbox zoom and the mouse wheel zoom.
This commit is contained in:
@@ -114,20 +114,20 @@ class Zoom extends Control {
|
||||
// upon it
|
||||
return;
|
||||
}
|
||||
const currentResolution = view.getResolution();
|
||||
if (currentResolution) {
|
||||
const newResolution = view.constrainResolution(currentResolution, delta);
|
||||
const currentZoom = view.getZoom();
|
||||
if (currentZoom !== undefined) {
|
||||
const newZoom = view.getValidZoomLevel(currentZoom + delta);
|
||||
if (this.duration_ > 0) {
|
||||
if (view.getAnimating()) {
|
||||
view.cancelAnimations();
|
||||
}
|
||||
view.animate({
|
||||
resolution: newResolution,
|
||||
zoom: newZoom,
|
||||
duration: this.duration_,
|
||||
easing: easeOut
|
||||
});
|
||||
} else {
|
||||
view.setResolution(newResolution);
|
||||
view.setZoom(newZoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,9 +218,10 @@ class ZoomSlider extends Control {
|
||||
event.offsetY - this.thumbSize_[1] / 2);
|
||||
|
||||
const resolution = this.getResolutionForPosition_(relativePosition);
|
||||
const zoom = view.getValidZoomLevel(view.getZoomForResolution(resolution));
|
||||
|
||||
view.animate({
|
||||
resolution: view.constrainResolution(resolution),
|
||||
zoom: zoom,
|
||||
duration: this.duration_,
|
||||
easing: easeOut
|
||||
});
|
||||
@@ -281,8 +282,11 @@ class ZoomSlider extends Control {
|
||||
const view = this.getMap().getView();
|
||||
view.endInteraction();
|
||||
|
||||
const zoom = view.getValidZoomLevel(
|
||||
view.getZoomForResolution(this.currentResolution_));
|
||||
|
||||
view.animate({
|
||||
resolution: view.constrainResolution(this.currentResolution_),
|
||||
zoom: zoom,
|
||||
duration: this.duration_,
|
||||
easing: easeOut
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user