diff options
Diffstat (limited to 'src/client/views/nodes/MapBox/AnimationUtility.ts')
-rw-r--r-- | src/client/views/nodes/MapBox/AnimationUtility.ts | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/client/views/nodes/MapBox/AnimationUtility.ts b/src/client/views/nodes/MapBox/AnimationUtility.ts index f4bae66bb..a3ac68b99 100644 --- a/src/client/views/nodes/MapBox/AnimationUtility.ts +++ b/src/client/views/nodes/MapBox/AnimationUtility.ts @@ -1,11 +1,12 @@ import * as turf from '@turf/turf'; -import { Position } from '@turf/turf'; import * as d3 from 'd3'; -import { Feature, GeoJsonProperties, Geometry } from 'geojson'; -import mapboxgl, { MercatorCoordinate } from 'mapbox-gl'; +import { Feature, GeoJsonProperties, Geometry, LineString } from 'geojson'; +import { MercatorCoordinate } from 'mapbox-gl'; import { action, computed, makeObservable, observable, runInAction } from 'mobx'; import { MapRef } from 'react-map-gl'; +export type Position = [number, number]; + export enum AnimationStatus { START = 'start', RESUME = 'resume', @@ -23,7 +24,7 @@ export class AnimationUtility { private ROUTE_COORDINATES: Position[] = []; @observable - private PATH?: turf.helpers.Feature<turf.helpers.LineString, turf.helpers.Properties> = undefined; + private PATH?: Feature<LineString> = undefined; // turf.helpers.Feature<turf.helpers.LineString, turf.helpers.Properties> = undefined; private PATH_DISTANCE: number = 0; private FLY_IN_START_PITCH = 40; @@ -65,7 +66,7 @@ export class AnimationUtility { const coords: mapboxgl.LngLatLike = [this.previousLngLat.lng, this.previousLngLat.lat]; // console.log('MAP REF: ', this.MAP_REF) // console.log("current elevation: ", this.MAP_REF?.queryTerrainElevation(coords)); - let altitude = this.MAP_REF ? this.MAP_REF.queryTerrainElevation(coords) ?? 0 : 0; + let altitude = this.MAP_REF ? (this.MAP_REF.queryTerrainElevation(coords) ?? 0) : 0; if (altitude === 0) { altitude += 50; } @@ -165,7 +166,8 @@ export class AnimationUtility { } @action - public setPath = (path: turf.helpers.Feature<turf.helpers.LineString, turf.helpers.Properties>) => { + public setPath = (path: Feature<LineString>) => { + // turf.helpers.Feature<turf.helpers.LineString, turf.helpers.Properties>) => { this.PATH = path; }; @@ -178,7 +180,7 @@ export class AnimationUtility { this.ROUTE_COORDINATES = routeCoordinates; this.PATH = turf.lineString(routeCoordinates); - this.PATH_DISTANCE = turf.lineDistance(this.PATH); + this.PATH_DISTANCE = turf.length(this.PATH as Feature<LineString>); this.terrainDisplayed = terrainDisplayed; const bearing = this.calculateBearing( @@ -232,7 +234,7 @@ export class AnimationUtility { if (!this.PATH) return; // calculate the distance along the path based on the animationPhase - const alongPath = turf.along(this.PATH, this.PATH_DISTANCE * animationPhase).geometry.coordinates; + const alongPath = turf.along(this.PATH as Feature<LineString>, this.PATH_DISTANCE * animationPhase).geometry.coordinates; const lngLat = { lng: alongPath[0], |