@lugg/maps 0.2.0-alpha.1 → 0.2.0-alpha.11
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/README.md +17 -4
- package/android/src/main/java/com/luggmaps/LuggGoogleMapView.kt +30 -8
- package/android/src/main/java/com/luggmaps/LuggGoogleMapViewManager.kt +10 -2
- package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +7 -1
- package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +6 -0
- package/android/src/main/java/com/luggmaps/LuggPolylineView.kt +7 -0
- package/android/src/main/java/com/luggmaps/LuggPolylineViewManager.kt +6 -0
- package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +89 -43
- package/ios/LuggAppleMapView.mm +45 -5
- package/ios/LuggGoogleMapView.mm +18 -6
- package/ios/LuggMarkerView.h +2 -0
- package/ios/LuggMarkerView.mm +13 -0
- package/ios/LuggPolylineView.h +1 -0
- package/ios/LuggPolylineView.mm +6 -1
- package/ios/core/GMSPolylineAnimator.m +85 -36
- package/ios/core/MKPolylineAnimator.m +63 -32
- package/lib/module/MapProvider.js +13 -0
- package/lib/module/MapProvider.js.map +1 -0
- package/lib/module/MapProvider.types.js +4 -0
- package/lib/module/MapProvider.types.js.map +1 -0
- package/lib/module/MapProvider.web.js +14 -0
- package/lib/module/MapProvider.web.js.map +1 -0
- package/lib/module/MapView.js +8 -2
- package/lib/module/MapView.js.map +1 -1
- package/lib/module/MapView.web.js +235 -0
- package/lib/module/MapView.web.js.map +1 -0
- package/lib/module/components/Marker.js +4 -1
- package/lib/module/components/Marker.js.map +1 -1
- package/lib/module/components/Marker.web.js +25 -0
- package/lib/module/components/Marker.web.js.map +1 -0
- package/lib/module/components/Polyline.js +5 -2
- package/lib/module/components/Polyline.js.map +1 -1
- package/lib/module/components/Polyline.web.js +169 -0
- package/lib/module/components/Polyline.web.js.map +1 -0
- package/lib/module/components/index.js +2 -2
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/index.web.js +5 -0
- package/lib/module/components/index.web.js.map +1 -0
- package/lib/module/fabric/LuggAppleMapViewNativeComponent.ts +4 -1
- package/lib/module/fabric/LuggGoogleMapViewNativeComponent.ts +4 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +6 -0
- package/lib/module/index.web.js.map +1 -0
- package/lib/typescript/src/MapProvider.d.ts +8 -0
- package/lib/typescript/src/MapProvider.d.ts.map +1 -0
- package/lib/typescript/src/MapProvider.types.d.ts +16 -0
- package/lib/typescript/src/MapProvider.types.d.ts.map +1 -0
- package/lib/typescript/src/MapProvider.web.d.ts +3 -0
- package/lib/typescript/src/MapProvider.web.d.ts.map +1 -0
- package/lib/typescript/src/MapView.d.ts.map +1 -1
- package/lib/typescript/src/MapView.types.d.ts +1 -2
- package/lib/typescript/src/MapView.types.d.ts.map +1 -1
- package/lib/typescript/src/MapView.web.d.ts +3 -0
- package/lib/typescript/src/MapView.web.d.ts.map +1 -0
- package/lib/typescript/src/components/Marker.d.ts +4 -0
- package/lib/typescript/src/components/Marker.d.ts.map +1 -1
- package/lib/typescript/src/components/Marker.web.d.ts +3 -0
- package/lib/typescript/src/components/Marker.web.d.ts.map +1 -0
- package/lib/typescript/src/components/Polyline.d.ts +4 -0
- package/lib/typescript/src/components/Polyline.d.ts.map +1 -1
- package/lib/typescript/src/components/Polyline.web.d.ts +3 -0
- package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -0
- package/lib/typescript/src/components/index.web.d.ts +5 -0
- package/lib/typescript/src/components/index.web.d.ts.map +1 -0
- package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts +1 -1
- package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/fabric/LuggGoogleMapViewNativeComponent.d.ts +1 -1
- package/lib/typescript/src/fabric/LuggGoogleMapViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +7 -0
- package/lib/typescript/src/index.web.d.ts.map +1 -0
- package/package.json +15 -2
- package/src/MapProvider.tsx +10 -0
- package/src/MapProvider.types.ts +16 -0
- package/src/MapProvider.web.tsx +6 -0
- package/src/MapView.tsx +11 -2
- package/src/MapView.types.ts +1 -2
- package/src/MapView.web.tsx +283 -0
- package/src/components/Marker.tsx +6 -2
- package/src/components/Marker.web.tsx +24 -0
- package/src/components/Polyline.tsx +6 -1
- package/src/components/Polyline.web.tsx +209 -0
- package/src/components/index.web.ts +4 -0
- package/src/fabric/LuggAppleMapViewNativeComponent.ts +4 -1
- package/src/fabric/LuggGoogleMapViewNativeComponent.ts +4 -1
- package/src/index.ts +8 -1
- package/src/index.web.ts +17 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { useMap } from '@vis.gl/react-google-maps';
|
|
3
|
+
import type { PolylineProps } from './Polyline';
|
|
4
|
+
|
|
5
|
+
const ANIMATION_DURATION = 1500;
|
|
6
|
+
|
|
7
|
+
function interpolateColor(color1: string, color2: string, t: number): string {
|
|
8
|
+
const hex = (c: string) => parseInt(c, 16);
|
|
9
|
+
const r1 = hex(color1.slice(1, 3));
|
|
10
|
+
const g1 = hex(color1.slice(3, 5));
|
|
11
|
+
const b1 = hex(color1.slice(5, 7));
|
|
12
|
+
const r2 = hex(color2.slice(1, 3));
|
|
13
|
+
const g2 = hex(color2.slice(3, 5));
|
|
14
|
+
const b2 = hex(color2.slice(5, 7));
|
|
15
|
+
|
|
16
|
+
const r = Math.round(r1 + (r2 - r1) * t);
|
|
17
|
+
const g = Math.round(g1 + (g2 - g1) * t);
|
|
18
|
+
const b = Math.round(b1 + (b2 - b1) * t);
|
|
19
|
+
|
|
20
|
+
return `#${r.toString(16).padStart(2, '0')}${g
|
|
21
|
+
.toString(16)
|
|
22
|
+
.padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getGradientColor(colors: string[], position: number): string {
|
|
26
|
+
if (colors.length === 0) return '#000000';
|
|
27
|
+
if (colors.length === 1 || position <= 0) return colors[0]!;
|
|
28
|
+
if (position >= 1) return colors[colors.length - 1]!;
|
|
29
|
+
|
|
30
|
+
const scaledPos = position * (colors.length - 1);
|
|
31
|
+
const index = Math.floor(scaledPos);
|
|
32
|
+
const t = scaledPos - index;
|
|
33
|
+
|
|
34
|
+
return interpolateColor(colors[index]!, colors[index + 1]!, t);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function Polyline({
|
|
38
|
+
coordinates,
|
|
39
|
+
strokeColors,
|
|
40
|
+
strokeWidth = 1,
|
|
41
|
+
animated,
|
|
42
|
+
zIndex,
|
|
43
|
+
}: PolylineProps) {
|
|
44
|
+
const resolvedZIndex = zIndex ?? (animated ? 1 : 0);
|
|
45
|
+
const map = useMap();
|
|
46
|
+
const polylinesRef = useRef<google.maps.Polyline[]>([]);
|
|
47
|
+
const animationRef = useRef<number>(0);
|
|
48
|
+
|
|
49
|
+
const colors = useMemo(
|
|
50
|
+
() =>
|
|
51
|
+
strokeColors && strokeColors.length > 0
|
|
52
|
+
? (strokeColors as string[])
|
|
53
|
+
: ['#000000'],
|
|
54
|
+
[strokeColors]
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const hasGradient = colors.length > 1;
|
|
58
|
+
|
|
59
|
+
// Refs for animation loop access
|
|
60
|
+
const propsRef = useRef({
|
|
61
|
+
map,
|
|
62
|
+
colors,
|
|
63
|
+
strokeWidth,
|
|
64
|
+
hasGradient,
|
|
65
|
+
zIndex: resolvedZIndex,
|
|
66
|
+
});
|
|
67
|
+
const [mapReady, setMapReady] = useState(!!map);
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
propsRef.current = {
|
|
71
|
+
map,
|
|
72
|
+
colors,
|
|
73
|
+
strokeWidth,
|
|
74
|
+
hasGradient,
|
|
75
|
+
zIndex: resolvedZIndex,
|
|
76
|
+
};
|
|
77
|
+
if (map && !mapReady) setMapReady(true);
|
|
78
|
+
}, [map, colors, strokeWidth, hasGradient, resolvedZIndex, mapReady]);
|
|
79
|
+
|
|
80
|
+
const updatePath = useCallback((path: google.maps.LatLngLiteral[]) => {
|
|
81
|
+
const {
|
|
82
|
+
map: currentMap,
|
|
83
|
+
colors: currentColors,
|
|
84
|
+
strokeWidth: currentStrokeWidth,
|
|
85
|
+
hasGradient: currentHasGradient,
|
|
86
|
+
zIndex: currentZIndex,
|
|
87
|
+
} = propsRef.current;
|
|
88
|
+
if (!currentMap || path.length < 2) return;
|
|
89
|
+
|
|
90
|
+
const neededSegments = currentHasGradient ? path.length - 1 : 1;
|
|
91
|
+
const existing = polylinesRef.current;
|
|
92
|
+
|
|
93
|
+
// Update or create segments
|
|
94
|
+
for (let i = 0; i < neededSegments; i++) {
|
|
95
|
+
const segmentPath = currentHasGradient ? [path[i]!, path[i + 1]!] : path;
|
|
96
|
+
const color = currentHasGradient
|
|
97
|
+
? getGradientColor(currentColors, i / (path.length - 1))
|
|
98
|
+
: currentColors[0]!;
|
|
99
|
+
|
|
100
|
+
const segment = existing[i];
|
|
101
|
+
if (segment) {
|
|
102
|
+
segment.setPath(segmentPath);
|
|
103
|
+
segment.setOptions({ strokeColor: color });
|
|
104
|
+
} else {
|
|
105
|
+
existing.push(
|
|
106
|
+
new google.maps.Polyline({
|
|
107
|
+
path: segmentPath,
|
|
108
|
+
strokeColor: color,
|
|
109
|
+
strokeWeight: currentStrokeWidth,
|
|
110
|
+
strokeOpacity: 1,
|
|
111
|
+
zIndex: currentZIndex,
|
|
112
|
+
map: currentMap,
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Remove extra segments
|
|
119
|
+
for (let i = neededSegments; i < existing.length; i++) {
|
|
120
|
+
existing[i]?.setMap(null);
|
|
121
|
+
}
|
|
122
|
+
existing.length = neededSegments;
|
|
123
|
+
}, []);
|
|
124
|
+
|
|
125
|
+
// Cleanup on unmount
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
const polylines = polylinesRef.current;
|
|
128
|
+
return () => {
|
|
129
|
+
cancelAnimationFrame(animationRef.current);
|
|
130
|
+
polylines.forEach((p) => p.setMap(null));
|
|
131
|
+
};
|
|
132
|
+
}, []);
|
|
133
|
+
|
|
134
|
+
// Main effect
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (!propsRef.current.map || coordinates.length === 0) return;
|
|
137
|
+
|
|
138
|
+
const fullPath = coordinates.map((c) => ({
|
|
139
|
+
lat: c.latitude,
|
|
140
|
+
lng: c.longitude,
|
|
141
|
+
}));
|
|
142
|
+
|
|
143
|
+
cancelAnimationFrame(animationRef.current);
|
|
144
|
+
|
|
145
|
+
if (!animated) {
|
|
146
|
+
updatePath(fullPath);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const totalPoints = fullPath.length;
|
|
151
|
+
const cycleDuration = ANIMATION_DURATION * 2;
|
|
152
|
+
|
|
153
|
+
const animate = (time: number) => {
|
|
154
|
+
const progress = (time % cycleDuration) / ANIMATION_DURATION;
|
|
155
|
+
const startIdx = progress <= 1 ? 0 : (progress - 1) * totalPoints;
|
|
156
|
+
const endIdx = progress <= 1 ? progress * totalPoints : totalPoints;
|
|
157
|
+
|
|
158
|
+
const partialPath: google.maps.LatLngLiteral[] = [];
|
|
159
|
+
const startFloor = Math.floor(startIdx);
|
|
160
|
+
const endFloor = Math.floor(endIdx);
|
|
161
|
+
|
|
162
|
+
// Start point (interpolated)
|
|
163
|
+
if (startFloor < totalPoints) {
|
|
164
|
+
const frac = startIdx - startFloor;
|
|
165
|
+
const from = fullPath[startFloor]!;
|
|
166
|
+
const to = fullPath[Math.min(startFloor + 1, totalPoints - 1)]!;
|
|
167
|
+
partialPath.push(
|
|
168
|
+
frac > 0
|
|
169
|
+
? {
|
|
170
|
+
lat: from.lat + (to.lat - from.lat) * frac,
|
|
171
|
+
lng: from.lng + (to.lng - from.lng) * frac,
|
|
172
|
+
}
|
|
173
|
+
: from
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Middle points
|
|
178
|
+
for (
|
|
179
|
+
let i = startFloor + 1;
|
|
180
|
+
i <= Math.min(endFloor, totalPoints - 1);
|
|
181
|
+
i++
|
|
182
|
+
) {
|
|
183
|
+
partialPath.push(fullPath[i]!);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// End point (interpolated)
|
|
187
|
+
if (endFloor < totalPoints - 1) {
|
|
188
|
+
const frac = endIdx - endFloor;
|
|
189
|
+
const from = fullPath[endFloor]!;
|
|
190
|
+
const to = fullPath[endFloor + 1]!;
|
|
191
|
+
if (frac > 0) {
|
|
192
|
+
partialPath.push({
|
|
193
|
+
lat: from.lat + (to.lat - from.lat) * frac,
|
|
194
|
+
lng: from.lng + (to.lng - from.lng) * frac,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
updatePath(partialPath);
|
|
200
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
204
|
+
|
|
205
|
+
return () => cancelAnimationFrame(animationRef.current);
|
|
206
|
+
}, [coordinates, animated, hasGradient, updatePath, mapReady]);
|
|
207
|
+
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
@@ -66,7 +66,10 @@ interface NativeCommands {
|
|
|
66
66
|
fitCoordinates: (
|
|
67
67
|
viewRef: React.ElementRef<ComponentType>,
|
|
68
68
|
coordinates: Coordinate[],
|
|
69
|
-
|
|
69
|
+
paddingTop: Double,
|
|
70
|
+
paddingLeft: Double,
|
|
71
|
+
paddingBottom: Double,
|
|
72
|
+
paddingRight: Double,
|
|
70
73
|
duration: Double
|
|
71
74
|
) => void;
|
|
72
75
|
}
|
|
@@ -67,7 +67,10 @@ interface NativeCommands {
|
|
|
67
67
|
fitCoordinates: (
|
|
68
68
|
viewRef: React.ElementRef<ComponentType>,
|
|
69
69
|
coordinates: Coordinate[],
|
|
70
|
-
|
|
70
|
+
paddingTop: Double,
|
|
71
|
+
paddingLeft: Double,
|
|
72
|
+
paddingBottom: Double,
|
|
73
|
+
paddingRight: Double,
|
|
71
74
|
duration: Double
|
|
72
75
|
) => void;
|
|
73
76
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { MapView } from './MapView';
|
|
2
|
+
export { MapProvider } from './MapProvider';
|
|
3
|
+
export type { MapProviderProps } from './MapProvider.types';
|
|
2
4
|
export * from './components';
|
|
3
5
|
export type {
|
|
4
6
|
MapViewProps,
|
|
@@ -7,4 +9,9 @@ export type {
|
|
|
7
9
|
FitCoordinatesOptions,
|
|
8
10
|
CameraEventPayload,
|
|
9
11
|
} from './MapView.types';
|
|
10
|
-
export type {
|
|
12
|
+
export type {
|
|
13
|
+
MapProvider as MapProviderType,
|
|
14
|
+
Coordinate,
|
|
15
|
+
Point,
|
|
16
|
+
EdgeInsets,
|
|
17
|
+
} from './types';
|
package/src/index.web.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { MapView } from './MapView.web';
|
|
2
|
+
export { MapProvider } from './MapProvider.web';
|
|
3
|
+
export type { MapProviderProps } from './MapProvider.types';
|
|
4
|
+
export * from './components/index.web';
|
|
5
|
+
export type {
|
|
6
|
+
MapViewProps,
|
|
7
|
+
MapViewRef,
|
|
8
|
+
MoveCameraOptions,
|
|
9
|
+
FitCoordinatesOptions,
|
|
10
|
+
CameraEventPayload,
|
|
11
|
+
} from './MapView.types';
|
|
12
|
+
export type {
|
|
13
|
+
MapProvider as MapProviderType,
|
|
14
|
+
Coordinate,
|
|
15
|
+
Point,
|
|
16
|
+
EdgeInsets,
|
|
17
|
+
} from './types';
|