diff --git a/src/geo/transform.js b/src/geo/transform.js index 51570d54446..bc8cb1af5cb 100644 --- a/src/geo/transform.js +++ b/src/geo/transform.js @@ -264,7 +264,10 @@ class Transform { return new Point(this.width, this.height); } - _getBearingOffset(lngLat): number { + // calculates the angle between a vector pointing north in + // Mercator and a vector pointing north in the projection + // and converts the angle from radians to degrees + _getBearingOffset(lngLat?: LngLat): number { const {lng, lat} = lngLat || this.center; const north = {lng, lat: lat + 0.0001}; const projectedCenter = this.projection.project(lng, lat); @@ -889,7 +892,7 @@ class Transform { if (!minmax) { minmax = {min: minRange, max: maxRange}; } - // TODO: ensure that we want `this.rotation` instead of `this.bearing` here + // ensure that we want `this.rotation` instead of `this.bearing` here const cornerFar = furthestTileCorner(this.rotation); const farX = cornerFar[0] * EXTENT; diff --git a/src/ui/camera.js b/src/ui/camera.js index 02863b977ec..7087194e2ab 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -700,7 +700,7 @@ class Camera extends Evented { return { center: tr.center, zoom: tr.zoom, - bearing: tr.rotation, + bearing: tr.bearing, pitch: tr.pitch }; } @@ -909,9 +909,9 @@ class Camera extends Evented { tr.center = LngLat.convert(options.center); } - if ('bearing' in options && tr.rotation !== +options.bearing) { + if ('bearing' in options && tr.bearing !== +options.bearing) { bearingChanged = true; - tr.rotation = +options.bearing; + tr.bearing = +options.bearing; } if ('pitch' in options && tr.pitch !== +options.pitch) { @@ -986,13 +986,13 @@ class Camera extends Evented { const tr = this.transform; const prevZoom = tr.zoom; const prevPitch = tr.pitch; - const prevBearing = tr.rotation; + const prevBearing = tr.bearing; tr.setFreeCameraOptions(options); const zoomChanged = prevZoom !== tr.zoom; const pitchChanged = prevPitch !== tr.pitch; - const bearingChanged = prevBearing !== tr.rotation; + const bearingChanged = prevBearing !== tr.bearing; this.fire(new Event('movestart', eventData)) .fire(new Event('move', eventData)); @@ -1104,7 +1104,7 @@ class Camera extends Evented { tr.zoom = interpolate(startZoom, zoom, k); } if (this._rotating) { - tr.rotation = interpolate(startBearing, bearing, k); + tr.bearing = interpolate(startBearing, bearing, k); } if (this._pitching) { tr.pitch = interpolate(startPitch, pitch, k); @@ -1394,7 +1394,7 @@ class Camera extends Evented { tr.zoom = k === 1 ? zoom : startZoom + tr.scaleZoom(scale); if (this._rotating) { - tr.rotation = interpolate(startBearing, bearing, k); + tr.bearing = interpolate(startBearing, bearing, k); } if (this._pitching) { tr.pitch = interpolate(startPitch, pitch, k); diff --git a/src/ui/handler_manager.js b/src/ui/handler_manager.js index e53ae21b8f3..aa3dadf6018 100644 --- a/src/ui/handler_manager.js +++ b/src/ui/handler_manager.js @@ -514,7 +514,7 @@ class HandlerManager { map._stop(true); around = around || map.transform.centerPoint; - if (bearingDelta) tr.rotation += bearingDelta; + if (bearingDelta) tr.bearing += bearingDelta; if (pitchDelta) tr.pitch += pitchDelta; tr._updateCameraState();