Skip to content

Commit

Permalink
Switch from setting rotation directly to setting bearing
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhamley committed Jul 27, 2021
1 parent 706f825 commit 40bf158
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ class Camera extends Evented {
return {
center: tr.center,
zoom: tr.zoom,
bearing: tr.rotation,
bearing: tr.bearing,
pitch: tr.pitch
};
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/handler_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 40bf158

Please sign in to comment.