@towsila/expo-ui-library 4.18.1 → 4.18.2
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 +27 -19
package/package.json
CHANGED
|
@@ -6,43 +6,45 @@ import { useAppTheme } from "../../context/ThemeContext";
|
|
|
6
6
|
import CustomMarker from "./customMarker";
|
|
7
7
|
import PositionMarker from "./positionMarker";
|
|
8
8
|
import MovingMarker from "./movingMarker";
|
|
9
|
-
import { RouteInfo } from "../../types/route";
|
|
10
9
|
|
|
11
10
|
type LngLat = [number, number];
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
type LineStringGeom = { type: "LineString"; coordinates: [number, number][] };
|
|
14
13
|
|
|
15
14
|
export interface MapMarker {
|
|
16
15
|
id: string;
|
|
17
16
|
lngLat: LngLat;
|
|
18
|
-
icon: any;
|
|
17
|
+
icon: any;
|
|
19
18
|
selected?: boolean;
|
|
20
19
|
onPress?: () => void;
|
|
21
|
-
shadow?:boolean;
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
export interface MapRoute {
|
|
25
|
-
id: string;
|
|
26
|
-
geometry: { type: "LineString"; coordinates: LngLat[] };
|
|
27
|
-
color?: string;
|
|
20
|
+
shadow?: boolean;
|
|
28
21
|
}
|
|
29
22
|
|
|
30
|
-
|
|
23
|
+
// Accepts a single LineString or an array of LineStrings
|
|
24
|
+
type RouteInput = LineStringGeom | LineStringGeom[] | null | undefined;
|
|
25
|
+
|
|
31
26
|
interface Props {
|
|
32
27
|
mapStyle: any;
|
|
33
28
|
position: LngLat;
|
|
34
|
-
userVariant?: "dot" | "arrow";
|
|
29
|
+
userVariant?: "dot" | "arrow";
|
|
35
30
|
heading?: number;
|
|
36
31
|
markers?: MapMarker[];
|
|
37
32
|
routeGeometry?: RouteInput;
|
|
38
|
-
follow?: boolean;
|
|
39
|
-
children?: React.ReactNode;
|
|
33
|
+
follow?: boolean;
|
|
34
|
+
children?: React.ReactNode;
|
|
40
35
|
onCenterChange?: (center: [number, number]) => void;
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
export default function AppMap({
|
|
44
|
-
mapStyle,
|
|
45
|
-
|
|
39
|
+
mapStyle,
|
|
40
|
+
position,
|
|
41
|
+
userVariant = "dot",
|
|
42
|
+
heading = 0,
|
|
43
|
+
markers = [],
|
|
44
|
+
routeGeometry,
|
|
45
|
+
follow = false,
|
|
46
|
+
children,
|
|
47
|
+
onCenterChange,
|
|
46
48
|
}: Props) {
|
|
47
49
|
const { colors } = useAppTheme();
|
|
48
50
|
const cameraRef = useRef<any>(null);
|
|
@@ -52,20 +54,26 @@ export default function AppMap({
|
|
|
52
54
|
cameraRef.current?.easeTo({ center: position, duration: 1000 });
|
|
53
55
|
}, [follow, position[0], position[1]]);
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
// Normalize: LineString OR LineString[] → LineString[]
|
|
58
|
+
const routes: LineStringGeom[] = Array.isArray(routeGeometry)
|
|
56
59
|
? routeGeometry
|
|
57
60
|
: routeGeometry
|
|
58
61
|
? [routeGeometry]
|
|
59
62
|
: [];
|
|
63
|
+
|
|
60
64
|
return (
|
|
61
|
-
<MLMap
|
|
65
|
+
<MLMap
|
|
66
|
+
style={StyleSheet.absoluteFill}
|
|
67
|
+
mapStyle={mapStyle}
|
|
68
|
+
onRegionDidChange={(e: any) => onCenterChange?.(e.nativeEvent.center)}
|
|
69
|
+
>
|
|
62
70
|
<Camera ref={cameraRef} initialViewState={{ center: position, zoom: 15 }} />
|
|
63
71
|
|
|
64
72
|
{routes.map((r, i) => (
|
|
65
73
|
<GeoJSONSource
|
|
66
74
|
key={i}
|
|
67
75
|
id={`route-${i}`}
|
|
68
|
-
data={{ type: "Feature", properties: {}, geometry: r
|
|
76
|
+
data={{ type: "Feature", properties: {}, geometry: r }}
|
|
69
77
|
>
|
|
70
78
|
<Layer
|
|
71
79
|
id={`route-line-${i}`}
|