Skip to content

Colota - Android GPS Location tracker

refactor(map): extract shared TRACK_LINE_STYLE into mapUtils (#441)

Max Dietrich1118fb15af34
diff --git a/apps/mobile/src/components/features/inspector/TrackMap.tsx b/apps/mobile/src/components/features/inspector/TrackMap.tsx
index 7d60573d..773d0f5d 100644
--- a/apps/mobile/src/components/features/inspector/TrackMap.tsx
+++ b/apps/mobile/src/components/features/inspector/TrackMap.tsx
@@ -17,18 +17,12 @@ import {
buildTrackSegmentsGeoJSON,
buildTrackPointsGeoJSON,
computeTrackBounds,
+ TRACK_LINE_STYLE,
type TrackLocation
} from "../map/mapUtils"
import { getSpeedUnit } from "../../../utils/geo"
import { HIT_SLOP_MD, MAP_ANIMATION_DURATION_MS } from "../../../constants"
-const trackLineStyle: any = {
- lineColor: ["get", "color"],
- lineWidth: 3,
- lineCap: "round",
- lineJoin: "round"
-}
-
const trackPointStyle: any = {
circleRadius: 4,
circleColor: ["get", "color"],
@@ -219,7 +213,7 @@ export function TrackMap({ locations, colors, trips, trackColor, fitVersion }: P
onMapReady={handleMapReady}
>
<GeoJSONSource id="track-segments" data={segmentsGeoJSON}>
- <Layer id="track-line" type="line" style={trackLineStyle} />
+ <Layer id="track-line" type="line" style={TRACK_LINE_STYLE} />
</GeoJSONSource>
<GeoJSONSource
id="track-points"
diff --git a/apps/mobile/src/components/features/map/CurrentTrackLayers.tsx b/apps/mobile/src/components/features/map/CurrentTrackLayers.tsx
index feaae43f..b175ae8b 100644
--- a/apps/mobile/src/components/features/map/CurrentTrackLayers.tsx
+++ b/apps/mobile/src/components/features/map/CurrentTrackLayers.tsx
@@ -5,16 +5,9 @@
import React, { useMemo } from "react"
import { GeoJSONSource, Layer } from "@maplibre/maplibre-react-native"
-import { buildTrackSegmentsGeoJSON, type TrackLocation } from "./mapUtils"
+import { buildTrackSegmentsGeoJSON, TRACK_LINE_STYLE, type TrackLocation } from "./mapUtils"
import type { ThemeColors } from "../../../types/global"
-const trackLineStyle: any = {
- lineColor: ["get", "color"],
- lineWidth: 3,
- lineCap: "round",
- lineJoin: "round"
-}
-
interface Props {
locations: TrackLocation[]
version: number
@@ -34,7 +27,7 @@ export function CurrentTrackLayers({ locations, version, visible, colors }: Prop
return (
<GeoJSONSource id="current-track-segments" data={geoJSON}>
- <Layer id="current-track-line" type="line" style={trackLineStyle} />
+ <Layer id="current-track-line" type="line" style={TRACK_LINE_STYLE} />
</GeoJSONSource>
)
}
diff --git a/apps/mobile/src/components/features/map/mapUtils.ts b/apps/mobile/src/components/features/map/mapUtils.ts
index 33cd83a3..d9997e7f 100644
--- a/apps/mobile/src/components/features/map/mapUtils.ts
+++ b/apps/mobile/src/components/features/map/mapUtils.ts
@@ -5,6 +5,14 @@
import type { ThemeColors, Geofence } from "../../../types/global"
+/** MapLibre line-layer style for colored track segments (`color` is a per-feature property). */
+export const TRACK_LINE_STYLE: any = {
+ lineColor: ["get", "color"],
+ lineWidth: 3,
+ lineCap: "round",
+ lineJoin: "round"
+}
+
// ============================================================================
// SPEED COLOR INTERPOLATION
// ============================================================================