diff options
| author | bobzel <zzzman@gmail.com> | 2024-05-16 23:42:12 -0400 | 
|---|---|---|
| committer | bobzel <zzzman@gmail.com> | 2024-05-16 23:42:12 -0400 | 
| commit | 99931c4ca423d51555c24533a98e921c83c941e1 (patch) | |
| tree | 07baab3cb627eae837c18fb2a6981a746765ec61 /src/client/views/nodes/MapBox/AnimationUtility.ts | |
| parent | a197d8d37e62235bfa59bc8e3bb74c39381c30a4 (diff) | |
| parent | 69e286b504c2f1bbef7d489dc675b9e54ef8d983 (diff) | |
Merge branch 'restoringEslint' into eleanor-starter
Diffstat (limited to 'src/client/views/nodes/MapBox/AnimationUtility.ts')
| -rw-r--r-- | src/client/views/nodes/MapBox/AnimationUtility.ts | 59 | 
1 files changed, 28 insertions, 31 deletions
diff --git a/src/client/views/nodes/MapBox/AnimationUtility.ts b/src/client/views/nodes/MapBox/AnimationUtility.ts index 35153f439..f4bae66bb 100644 --- a/src/client/views/nodes/MapBox/AnimationUtility.ts +++ b/src/client/views/nodes/MapBox/AnimationUtility.ts @@ -87,25 +87,24 @@ export class AnimationUtility {      @computed get currentPitch(): number {          if (!this.isStreetViewAnimation) return 50;          if (!this.terrainDisplayed) return 80; -        else { -            // const groundElevation = 0; -            const heightAboveGround = this.currentAnimationAltitude; -            const horizontalDistance = 500; - -            let pitch; -            if (heightAboveGround >= 0) { -                pitch = 90 - Math.atan(heightAboveGround / horizontalDistance) * (180 / Math.PI); -            } else { -                pitch = 80; -            } -            console.log(Math.max(50, Math.min(pitch, 85))); +        // const groundElevation = 0; +        const heightAboveGround = this.currentAnimationAltitude; +        const horizontalDistance = 500; -            if (this.previousPitch) { -                return this.lerp(Math.max(50, Math.min(pitch, 85)), this.previousPitch, 0.02); -            } -            return Math.max(50, Math.min(pitch, 85)); +        let pitch; +        if (heightAboveGround >= 0) { +            pitch = 90 - Math.atan(heightAboveGround / horizontalDistance) * (180 / Math.PI); +        } else { +            pitch = 80; +        } + +        console.log(Math.max(50, Math.min(pitch, 85))); + +        if (this.previousPitch) { +            return this.lerp(Math.max(50, Math.min(pitch, 85)), this.previousPitch, 0.02);          } +        return Math.max(50, Math.min(pitch, 85));      }      @computed get flyInEndPitch() { @@ -214,8 +213,9 @@ export class AnimationUtility {          currentAnimationPhase: number;          updateAnimationPhase: (newAnimationPhase: number) => void;          updateFrameId: (newFrameId: number) => void; -    }) => { -        return new Promise<void>(async resolve => { +    }) => +        // eslint-disable-next-line no-async-promise-executor +        new Promise<void>(async resolve => {              let startTime: number | null = null;              const frame = async (currentTime: number) => { @@ -257,7 +257,7 @@ export class AnimationUtility {                  updateAnimationPhase(animationPhase);                  // compute corrected camera ground position, so that he leading edge of the path is in view -                var correctedPosition = this.computeCameraPosition( +                const correctedPosition = this.computeCameraPosition(                      this.isStreetViewAnimation,                      this.currentPitch,                      bearing, @@ -277,7 +277,7 @@ export class AnimationUtility {                  map.setFreeCameraOptions(camera);                  this.previousAltitude = this.currentAnimationAltitude; -                this.previousPitch = this.previousPitch; +                // this.previousPitch = this.previousPitch;                  // repeat!                  const innerFrameId = await window.requestAnimationFrame(frame); @@ -287,15 +287,15 @@ export class AnimationUtility {              const outerFrameId = await window.requestAnimationFrame(frame);              updateFrameId(outerFrameId);          }); -    }; -    public flyInAndRotate = async ({ map, updateFrameId }: { map: MapRef; updateFrameId: (newFrameId: number) => void }) => { -        return new Promise<{ bearing: number; altitude: number }>(async resolve => { +    public flyInAndRotate = async ({ map, updateFrameId }: { map: MapRef; updateFrameId: (newFrameId: number) => void }) => +        // eslint-disable-next-line no-async-promise-executor +        new Promise<{ bearing: number; altitude: number }>(async resolve => {              let start: number | null; -            var currentAltitude; -            var currentBearing; -            var currentPitch; +            let currentAltitude; +            let currentBearing; +            let currentPitch;              // the animation frame will run as many times as necessary until the duration has been reached              const frame = async (time: number) => { @@ -319,7 +319,7 @@ export class AnimationUtility {                  currentPitch = this.FLY_IN_START_PITCH + (this.flyInEndPitch - this.FLY_IN_START_PITCH) * d3.easeCubicOut(animationPhase);                  // compute corrected camera ground position, so the start of the path is always in view -                var correctedPosition = this.computeCameraPosition(false, currentPitch, currentBearing, this.FIRST_LNG_LAT, currentAltitude); +                const correctedPosition = this.computeCameraPosition(false, currentPitch, currentBearing, this.FIRST_LNG_LAT, currentAltitude);                  // set the pitch and bearing of the camera                  const camera = map.getFreeCameraOptions(); @@ -349,13 +349,10 @@ export class AnimationUtility {              const outerFrameId = await window.requestAnimationFrame(frame);              updateFrameId(outerFrameId);          }); -    };      previousCameraPosition: { lng: number; lat: number } | null = null; -    lerp = (start: number, end: number, amt: number) => { -        return (1 - amt) * start + amt * end; -    }; +    lerp = (start: number, end: number, amt: number) => (1 - amt) * start + amt * end;      computeCameraPosition = (isStreetViewAnimation: boolean, pitch: number, bearing: number, targetPosition: { lng: number; lat: number }, altitude: number, smooth = false) => {          const bearingInRadian = (bearing * Math.PI) / 180;  | 
