diff --git a/src/ol/View.js b/src/ol/View.js index 6a73338a3d..c5ae377bcd 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -622,7 +622,7 @@ class View extends BaseObject { } this.targetRotation_ = rotation; } - this.applyParameters_(true); + this.applyTargetState_(true); more = true; if (!animation.complete) { break; @@ -1070,7 +1070,7 @@ class View extends BaseObject { [size[0] - padding[1] - padding[3], size[1] - padding[0] - padding[2]]); resolution = isNaN(resolution) ? minResolution : Math.max(resolution, minResolution); - resolution = this.getValidResolution(resolution, nearest ? 0 : 1); + resolution = this.getConstrainedResolution(resolution, nearest ? 0 : 1); // calculate center sinAngle = -sinAngle; // go back to original rotation @@ -1086,14 +1086,14 @@ class View extends BaseObject { if (options.duration !== undefined) { this.animate({ resolution: resolution, - center: this.getValidCenter(center, resolution), + center: this.getConstrainedCenter(center, resolution), duration: options.duration, easing: options.easing }, callback); } else { this.targetResolution_ = resolution; this.targetCenter_ = center; - this.applyParameters_(false, true); + this.applyTargetState_(false, true); animationCallback(callback, true); } } @@ -1159,7 +1159,7 @@ class View extends BaseObject { } this.targetResolution_ *= ratio; - this.applyParameters_(); + this.applyTargetState_(); } /** @@ -1188,7 +1188,7 @@ class View extends BaseObject { this.targetCenter_ = this.calculateCenterRotate(newRotation, opt_anchor); } this.targetRotation_ += delta; - this.applyParameters_(); + this.applyTargetState_(); } /** @@ -1199,7 +1199,7 @@ class View extends BaseObject { */ setCenter(center) { this.targetCenter_ = center; - this.applyParameters_(); + this.applyTargetState_(); } /** @@ -1221,7 +1221,7 @@ class View extends BaseObject { */ setResolution(resolution) { this.targetResolution_ = resolution; - this.applyParameters_(); + this.applyTargetState_(); } /** @@ -1232,7 +1232,7 @@ class View extends BaseObject { */ setRotation(rotation) { this.targetRotation_ = rotation; - this.applyParameters_(); + this.applyTargetState_(); } /** @@ -1252,7 +1252,7 @@ class View extends BaseObject { * @param {boolean=} opt_forceMoving Apply constraints as if the view is moving. * @private */ - applyParameters_(opt_doNotCancelAnims, opt_forceMoving) { + applyTargetState_(opt_doNotCancelAnims, opt_forceMoving) { const isMoving = this.getAnimating() || this.getInteracting() || opt_forceMoving; // compute rotation @@ -1338,9 +1338,8 @@ class View extends BaseObject { * @param {number=} opt_targetResolution Target resolution. If not supplied, the current one will be used. * This is useful to guess a valid center position at a different zoom level. * @return {import("./coordinate.js").Coordinate|undefined} Valid center position. - * @api */ - getValidCenter(targetCenter, opt_targetResolution) { + getConstrainedCenter(targetCenter, opt_targetResolution) { const size = this.getSizeFromViewport_(this.getRotation()); return this.constraints_.center(targetCenter, opt_targetResolution || this.getResolution(), size); } @@ -1352,11 +1351,10 @@ class View extends BaseObject { * the available value respectively lower or greater than the target one. Leaving `0` will simply choose * the nearest available value. * @return {number|undefined} Valid zoom level. - * @api */ - getValidZoomLevel(targetZoom, opt_direction) { + getConstrainedZoom(targetZoom, opt_direction) { const targetRes = this.getResolutionForZoom(targetZoom); - return this.getZoomForResolution(this.getValidResolution(targetRes)); + return this.getZoomForResolution(this.getConstrainedResolution(targetRes)); } /** @@ -1366,9 +1364,8 @@ class View extends BaseObject { * the available value respectively lower or greater than the target one. Leaving `0` will simply choose * the nearest available value. * @return {number|undefined} Valid resolution. - * @api */ - getValidResolution(targetResolution, opt_direction) { + getConstrainedResolution(targetResolution, opt_direction) { const direction = opt_direction || 0; const size = this.getSizeFromViewport_(this.getRotation()); diff --git a/src/ol/control/Zoom.js b/src/ol/control/Zoom.js index f84254f904..379e703fc4 100644 --- a/src/ol/control/Zoom.js +++ b/src/ol/control/Zoom.js @@ -116,7 +116,7 @@ class Zoom extends Control { } const currentZoom = view.getZoom(); if (currentZoom !== undefined) { - const newZoom = view.getValidZoomLevel(currentZoom + delta); + const newZoom = view.getConstrainedZoom(currentZoom + delta); if (this.duration_ > 0) { if (view.getAnimating()) { view.cancelAnimations(); diff --git a/src/ol/control/ZoomSlider.js b/src/ol/control/ZoomSlider.js index b9629b0cca..050cb0d021 100644 --- a/src/ol/control/ZoomSlider.js +++ b/src/ol/control/ZoomSlider.js @@ -217,7 +217,7 @@ class ZoomSlider extends Control { event.offsetY - this.thumbSize_[1] / 2); const resolution = this.getResolutionForPosition_(relativePosition); - const zoom = view.getValidZoomLevel(view.getZoomForResolution(resolution)); + const zoom = view.getConstrainedZoom(view.getZoomForResolution(resolution)); view.animate({ zoom: zoom, diff --git a/src/ol/interaction/DragPan.js b/src/ol/interaction/DragPan.js index ae31b38003..cfcb9c1530 100644 --- a/src/ol/interaction/DragPan.js +++ b/src/ol/interaction/DragPan.js @@ -116,7 +116,7 @@ class DragPan extends PointerInteraction { centerpx[1] - distance * Math.sin(angle) ]); view.animate({ - center: view.getValidCenter(dest), + center: view.getConstrainedCenter(dest), duration: 500, easing: easeOut }); diff --git a/src/ol/interaction/DragZoom.js b/src/ol/interaction/DragZoom.js index 2dcd12bdd5..4050193eb1 100644 --- a/src/ol/interaction/DragZoom.js +++ b/src/ol/interaction/DragZoom.js @@ -80,8 +80,8 @@ function onBoxEnd() { extent = mapExtent; } - const resolution = view.getValidResolution(view.getResolutionForExtent(extent, size)); - const center = view.getValidCenter(getCenter(extent), resolution); + const resolution = view.getConstrainedResolution(view.getResolutionForExtent(extent, size)); + const center = view.getConstrainedCenter(getCenter(extent), resolution); view.animate({ resolution: resolution, diff --git a/src/ol/interaction/Interaction.js b/src/ol/interaction/Interaction.js index 5834c5900b..80a9644758 100644 --- a/src/ol/interaction/Interaction.js +++ b/src/ol/interaction/Interaction.js @@ -114,7 +114,7 @@ export function pan(view, delta, opt_duration) { view.animate({ duration: opt_duration !== undefined ? opt_duration : 250, easing: linear, - center: view.getValidCenter(center) + center: view.getConstrainedCenter(center) }); } } @@ -132,7 +132,7 @@ export function zoomByDelta(view, delta, opt_anchor, opt_duration) { return; } - const newZoom = view.getValidZoomLevel(currentZoom + delta); + const newZoom = view.getConstrainedZoom(currentZoom + delta); const newResolution = view.getResolutionForZoom(newZoom); if (view.getAnimating()) { diff --git a/test/spec/ol/interaction/dragzoom.test.js b/test/spec/ol/interaction/dragzoom.test.js index 77201d253e..9746ee25ca 100644 --- a/test/spec/ol/interaction/dragzoom.test.js +++ b/test/spec/ol/interaction/dragzoom.test.js @@ -103,7 +103,7 @@ describe('ol.interaction.DragZoom', function() { setTimeout(function() { const view = map.getView(); const resolution = view.getResolution(); - expect(resolution).to.eql(view.getValidResolution(0.5)); + expect(resolution).to.eql(view.getConstrainedResolution(0.5)); done(); }, 50); }, 50); diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index 6fe4ec1e01..3fc8c4e9ce 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -1499,14 +1499,14 @@ describe('ol.View', function() { }); }); - describe('#getValidZoomLevel()', function() { + describe('#getConstrainedZoom()', function() { let view; it('works correctly without constraint', function() { view = new View({ zoom: 0 }); - expect(view.getValidZoomLevel(3)).to.be(3); + expect(view.getConstrainedZoom(3)).to.be(3); }); it('works correctly with resolution constraints', function() { view = new View({ @@ -1514,28 +1514,28 @@ describe('ol.View', function() { minZoom: 4, maxZoom: 8 }); - expect(view.getValidZoomLevel(3)).to.be(4); - expect(view.getValidZoomLevel(10)).to.be(8); + expect(view.getConstrainedZoom(3)).to.be(4); + expect(view.getConstrainedZoom(10)).to.be(8); }); it('works correctly with a specific resolution set', function() { view = new View({ zoom: 0, resolutions: [512, 256, 128, 64, 32, 16, 8] }); - expect(view.getValidZoomLevel(0)).to.be(0); - expect(view.getValidZoomLevel(4)).to.be(4); - expect(view.getValidZoomLevel(8)).to.be(6); + expect(view.getConstrainedZoom(0)).to.be(0); + expect(view.getConstrainedZoom(4)).to.be(4); + expect(view.getConstrainedZoom(8)).to.be(6); }); }); - describe('#getValidResolution()', function() { + describe('#getConstrainedResolution()', function() { let view; const defaultMaxRes = 156543.03392804097; it('works correctly by snapping to power of 2', function() { view = new View(); - expect(view.getValidResolution(1000000)).to.be(defaultMaxRes); - expect(view.getValidResolution(defaultMaxRes / 8)).to.be(defaultMaxRes / 8); + expect(view.getConstrainedResolution(1000000)).to.be(defaultMaxRes); + expect(view.getConstrainedResolution(defaultMaxRes / 8)).to.be(defaultMaxRes / 8); }); it('works correctly by snapping to a custom zoom factor', function() { view = new View({ @@ -1544,11 +1544,11 @@ describe('ol.View', function() { maxZoom: 4, constrainResolution: true }); - expect(view.getValidResolution(90, 1)).to.be(100); - expect(view.getValidResolution(90, -1)).to.be(20); - expect(view.getValidResolution(20)).to.be(20); - expect(view.getValidResolution(5)).to.be(4); - expect(view.getValidResolution(1)).to.be(4); + expect(view.getConstrainedResolution(90, 1)).to.be(100); + expect(view.getConstrainedResolution(90, -1)).to.be(20); + expect(view.getConstrainedResolution(20)).to.be(20); + expect(view.getConstrainedResolution(5)).to.be(4); + expect(view.getConstrainedResolution(1)).to.be(4); }); it('works correctly with a specific resolution set', function() { view = new View({ @@ -1556,12 +1556,12 @@ describe('ol.View', function() { resolutions: [512, 256, 128, 64, 32, 16, 8], constrainResolution: true }); - expect(view.getValidResolution(1000, 1)).to.be(512); - expect(view.getValidResolution(260, 1)).to.be(512); - expect(view.getValidResolution(260)).to.be(256); - expect(view.getValidResolution(30)).to.be(32); - expect(view.getValidResolution(30, -1)).to.be(16); - expect(view.getValidResolution(4, -1)).to.be(8); + expect(view.getConstrainedResolution(1000, 1)).to.be(512); + expect(view.getConstrainedResolution(260, 1)).to.be(512); + expect(view.getConstrainedResolution(260)).to.be(256); + expect(view.getConstrainedResolution(30)).to.be(32); + expect(view.getConstrainedResolution(30, -1)).to.be(16); + expect(view.getConstrainedResolution(4, -1)).to.be(8); }); });