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`](77bc6897dd/src/ol/interaction/MouseWheelZoom.js (L166));
thus, this `null` value
[is passed to `View.adjustZoom` as `opt_anchor`](77bc6897dd/src/ol/interaction/MouseWheelZoom.js (L209)).
This commit is contained in:
Brian Helba
2019-11-05 21:25:40 -05:00
parent 77bc6897dd
commit d90a4569da

View File

@@ -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;