@towsila/expo-ui-library 4.17.1 → 4.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/ui/appMap.tsx +31 -6
package/package.json
CHANGED
|
@@ -9,6 +9,8 @@ import MovingMarker from "./movingMarker";
|
|
|
9
9
|
|
|
10
10
|
type LngLat = [number, number];
|
|
11
11
|
|
|
12
|
+
|
|
13
|
+
|
|
12
14
|
export interface MapMarker {
|
|
13
15
|
id: string;
|
|
14
16
|
lngLat: LngLat;
|
|
@@ -18,14 +20,24 @@ export interface MapMarker {
|
|
|
18
20
|
shadow?:boolean;
|
|
19
21
|
|
|
20
22
|
}
|
|
23
|
+
export interface MapRoute {
|
|
24
|
+
id: string;
|
|
25
|
+
geometry: { type: "LineString"; coordinates: LngLat[] };
|
|
26
|
+
color?: string;
|
|
27
|
+
}
|
|
21
28
|
|
|
29
|
+
type RouteInput =
|
|
30
|
+
| { type: "LineString"; coordinates: LngLat[] } // single route (old callers)
|
|
31
|
+
| MapRoute[] // array of routes (new)
|
|
32
|
+
| null
|
|
33
|
+
| undefined;
|
|
22
34
|
interface Props {
|
|
23
35
|
mapStyle: any;
|
|
24
36
|
position: LngLat;
|
|
25
37
|
userVariant?: "dot" | "arrow"; // dot = blue dot, arrow = moving marker
|
|
26
38
|
heading?: number;
|
|
27
39
|
markers?: MapMarker[];
|
|
28
|
-
routeGeometry?:
|
|
40
|
+
routeGeometry?: RouteInput;
|
|
29
41
|
follow?: boolean; // camera follows the user
|
|
30
42
|
children?: React.ReactNode; // extra layers if a screen needs them
|
|
31
43
|
onCenterChange?: (center: [number, number]) => void;
|
|
@@ -43,20 +55,33 @@ export default function AppMap({
|
|
|
43
55
|
cameraRef.current?.easeTo({ center: position, duration: 1000 });
|
|
44
56
|
}, [follow, position[0], position[1]]);
|
|
45
57
|
|
|
58
|
+
const routes: MapRoute[] = Array.isArray(routeGeometry)
|
|
59
|
+
? routeGeometry
|
|
60
|
+
: routeGeometry
|
|
61
|
+
? [{ id: "default-route", geometry: routeGeometry, color: colors.text.primary }]
|
|
62
|
+
: [];
|
|
46
63
|
return (
|
|
47
64
|
<MLMap style={StyleSheet.absoluteFill} mapStyle={mapStyle} onRegionDidChange={(e: any) => onCenterChange?.(e.nativeEvent.center)}>
|
|
48
65
|
<Camera ref={cameraRef} initialViewState={{ center: position, zoom: 15 }} />
|
|
49
66
|
|
|
50
|
-
{
|
|
51
|
-
<GeoJSONSource
|
|
67
|
+
{routes.map((r) => (
|
|
68
|
+
<GeoJSONSource
|
|
69
|
+
key={r.id}
|
|
70
|
+
id={r.id}
|
|
71
|
+
data={{ type: "Feature", properties: {}, geometry: r.geometry }}
|
|
72
|
+
>
|
|
52
73
|
<Layer
|
|
53
|
-
id=
|
|
74
|
+
id={`${r.id}-line`}
|
|
54
75
|
type="line"
|
|
55
76
|
layout={{ "line-join": "round", "line-cap": "round" }}
|
|
56
|
-
paint={{
|
|
77
|
+
paint={{
|
|
78
|
+
"line-color": r.color ?? colors.text.primary,
|
|
79
|
+
"line-width": 5,
|
|
80
|
+
"line-opacity": 0.85,
|
|
81
|
+
}}
|
|
57
82
|
/>
|
|
58
83
|
</GeoJSONSource>
|
|
59
|
-
)}
|
|
84
|
+
))}
|
|
60
85
|
|
|
61
86
|
{userVariant === "arrow" ? (
|
|
62
87
|
<MovingMarker id="me" lngLat={position} icon={MarkerIcon} rotation={heading} />
|