-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from reedu-reengineering-education/feat/track-…
…store Feat/track store
- Loading branch information
Showing
23 changed files
with
2,147 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import TrackWrapper from '@/components/Tracks/track-wrapper' | ||
|
||
export default function TracksPage() { | ||
return ( | ||
<div className="h-full w-full p-4"> | ||
<TrackWrapper /> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use client' | ||
|
||
import { useUIStore } from '@/lib/store/useUIStore' | ||
import useSenseBox from '@/lib/useSenseBox' | ||
import { bearing, point } from '@turf/turf' | ||
import { LngLatLike } from 'maplibre-gl' | ||
import { useEffect, useRef } from 'react' | ||
import { MapRef } from 'react-map-gl/dist/esm/exports-maplibre' | ||
import LocationHistory from '../Map/LocationHistory' | ||
import LocationMarker from '../Map/LocationMarker' | ||
import MapComponent from '../Map/Map' | ||
|
||
export default function TrajectoryMap() { | ||
const { values } = useSenseBox() | ||
const { reducedMotion } = useUIStore() | ||
|
||
const mapRef = useRef<MapRef>(null) | ||
|
||
useEffect(() => { | ||
const latestValue = values.at(-1) | ||
if ( | ||
latestValue && | ||
latestValue.gps_lat && | ||
latestValue.gps_lng && | ||
mapRef.current | ||
) { | ||
const center = [latestValue.gps_lng, latestValue.gps_lat] as LngLatLike | ||
const zoom = | ||
mapRef.current?.getZoom() > 10 ? mapRef.current.getZoom() : 18 | ||
let mapBearing = mapRef.current?.getBearing() | ||
let pitch = mapRef.current?.getPitch() | ||
const valueBefore = values.at(-2) | ||
if ( | ||
valueBefore?.gps_lat && | ||
valueBefore?.gps_lng && | ||
(latestValue?.gps_spd ?? 0) > 5 | ||
) { | ||
mapBearing = bearing( | ||
point([valueBefore.gps_lng, valueBefore.gps_lat]), | ||
point([latestValue.gps_lng, latestValue.gps_lat]), | ||
) | ||
pitch = 60 | ||
} else { | ||
mapBearing = 0 | ||
pitch = 0 | ||
} | ||
|
||
if (reducedMotion) { | ||
mapRef.current?.setCenter(center) | ||
mapRef.current?.setZoom(zoom) | ||
mapRef.current?.setBearing(mapBearing) | ||
mapRef.current?.setPitch(pitch) | ||
} else { | ||
mapRef.current?.flyTo({ | ||
center, | ||
zoom, | ||
bearing: mapBearing, | ||
pitch, | ||
}) | ||
} | ||
} | ||
}, [values]) | ||
|
||
return ( | ||
<MapComponent ref={mapRef}> | ||
{values && values.length > 0 && ( | ||
<> | ||
<LocationHistory values={values} /> | ||
<LocationMarker | ||
location={{ | ||
latitude: values.at(-1)?.gps_lat || 0, | ||
longitude: values.at(-1)?.gps_lng || 0, | ||
accuracy: 10, | ||
simulated: false, | ||
altitude: null, | ||
altitudeAccuracy: null, | ||
bearing: null, | ||
speed: null, | ||
time: null, | ||
}} | ||
/> | ||
</> | ||
)} | ||
</MapComponent> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.