From d90a4569da133eef7bfa948ca4c826f970725ae3 Mon Sep 17 00:00:00 2001 From: Brian Helba Date: Tue, 5 Nov 2019 21:25:40 -0500 Subject: [PATCH] Allow View.adjust* methods to take a null opt_anchor The methods `View.adjustRotation`, `View.adjustZoom` and `View.adjustResolution` optionally take an `opt_anchor` parameter. When `opt_anchor` is `undefined`, the methods work properly. When it is `null`, they currently attempt to access the `null` value as though it is a `Coordinate` object, and throw: ``` TypeError: Cannot read property '0' of null ``` This change allows `opt_anchor` to safely be `null`. Existing code paths already expect this to be supported. For example, when `MouseWheelZoom.useAnchor_` is `false`, then [`MouseWheelZoom.lastAnchor_` remains `null`](https://github.com/openlayers/openlayers/blob/77bc6897dd4f4dd47d7f6d4dc34fb9d4c5a34a29/src/ol/interaction/MouseWheelZoom.js#L166); thus, this `null` value [is passed to `View.adjustZoom` as `opt_anchor`](https://github.com/openlayers/openlayers/blob/77bc6897dd4f4dd47d7f6d4dc34fb9d4c5a34a29/src/ol/interaction/MouseWheelZoom.js#L209). --- src/ol/View.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ol/View.js b/src/ol/View.js index a3fde0570f..abdf4b04f5 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -1252,7 +1252,7 @@ class View extends BaseObject { const size = this.getSizeFromViewport_(this.getRotation()); const newResolution = this.constraints_.resolution(this.targetResolution_ * ratio, 0, size, isMoving); - if (opt_anchor !== undefined) { + if (opt_anchor) { this.targetCenter_ = this.calculateCenterZoom(newResolution, opt_anchor); } @@ -1292,7 +1292,7 @@ class View extends BaseObject { adjustRotationInternal(delta, opt_anchor) { const isMoving = this.getAnimating() || this.getInteracting(); const newRotation = this.constraints_.rotation(this.targetRotation_ + delta, isMoving); - if (opt_anchor !== undefined) { + if (opt_anchor) { this.targetCenter_ = this.calculateCenterRotate(newRotation, opt_anchor); } this.targetRotation_ += delta;