@lugg/maps 1.0.0-beta.2 → 1.0.0-beta.21
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 +3 -0
- package/android/src/main/java/com/luggmaps/LuggCalloutView.kt +9 -2
- package/android/src/main/java/com/luggmaps/LuggCalloutViewManager.kt +4 -3
- package/android/src/main/java/com/luggmaps/LuggCircleView.kt +85 -0
- package/android/src/main/java/com/luggmaps/LuggCircleViewManager.kt +79 -0
- package/android/src/main/java/com/luggmaps/LuggGroundOverlayView.kt +81 -0
- package/android/src/main/java/com/luggmaps/LuggGroundOverlayViewManager.kt +82 -0
- package/android/src/main/java/com/luggmaps/LuggMapView.kt +90 -0
- package/android/src/main/java/com/luggmaps/LuggMapViewManager.kt +45 -0
- package/android/src/main/java/com/luggmaps/LuggMapWrapperView.kt +27 -2
- package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +30 -2
- package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +13 -0
- package/android/src/main/java/com/luggmaps/LuggPackage.kt +4 -1
- package/android/src/main/java/com/luggmaps/LuggPolylineView.kt +3 -23
- package/android/src/main/java/com/luggmaps/LuggTileOverlayView.kt +92 -0
- package/android/src/main/java/com/luggmaps/LuggTileOverlayViewManager.kt +80 -0
- package/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +737 -37
- package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +15 -0
- package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +65 -11
- package/android/src/main/java/com/luggmaps/events/CirclePressEvent.kt +12 -0
- package/android/src/main/java/com/luggmaps/events/GroundOverlayPressEvent.kt +12 -0
- package/android/src/main/java/com/luggmaps/events/TileOverlayPressEvent.kt +12 -0
- package/android/src/main/java/com/luggmaps/extensions/ViewExtensions.kt +11 -0
- package/ios/LuggCalloutView.h +1 -1
- package/ios/LuggCalloutView.mm +21 -11
- package/ios/LuggCircleView.h +31 -0
- package/ios/LuggCircleView.mm +133 -0
- package/ios/LuggGroundOverlayView.h +30 -0
- package/ios/LuggGroundOverlayView.mm +125 -0
- package/ios/LuggMapView.mm +254 -4
- package/ios/LuggMapWrapperView.h +5 -0
- package/ios/LuggMapWrapperView.mm +18 -0
- package/ios/LuggMarkerView.h +3 -0
- package/ios/LuggMarkerView.mm +25 -0
- package/ios/LuggTileOverlayView.h +31 -0
- package/ios/LuggTileOverlayView.mm +130 -0
- package/ios/core/AppleMapProvider.h +8 -0
- package/ios/core/AppleMapProvider.mm +663 -29
- package/ios/core/AppleStaticMapProvider.h +14 -0
- package/ios/core/AppleStaticMapProvider.mm +159 -0
- package/ios/core/GMSPolylineAnimator.m +46 -18
- package/ios/core/GoogleMapProvider.h +10 -0
- package/ios/core/GoogleMapProvider.mm +430 -51
- package/ios/core/GoogleStaticMapProvider.h +21 -0
- package/ios/core/GoogleStaticMapProvider.mm +213 -0
- package/ios/core/MKPolylineAnimator.m +67 -43
- package/ios/core/MapProviderDelegate.h +27 -1
- package/ios/core/StaticMapProviderBase.h +75 -0
- package/ios/core/StaticMapProviderBase.mm +845 -0
- package/ios/events/CameraIdleEvent.h +4 -2
- package/ios/events/CameraMoveEvent.h +4 -2
- package/ios/events/CirclePressEvent.h +22 -0
- package/ios/events/GroundOverlayPressEvent.h +22 -0
- package/ios/events/LongPressEvent.h +4 -2
- package/ios/events/MarkerDragEvent.h +12 -6
- package/ios/events/MarkerPressEvent.h +4 -2
- package/ios/events/PolygonPressEvent.h +4 -2
- package/ios/events/PressEvent.h +4 -2
- package/ios/events/ReadyEvent.h +4 -2
- package/ios/events/TileOverlayPressEvent.h +22 -0
- package/ios/extensions/MKMapView+Zoom.h +20 -0
- package/ios/extensions/MKMapView+Zoom.m +28 -18
- package/ios/extensions/UIView+Snapshot.h +16 -0
- package/ios/extensions/UIView+Snapshot.m +27 -0
- package/lib/module/MapProvider.web.js +4 -1
- package/lib/module/MapProvider.web.js.map +1 -1
- package/lib/module/MapView.js +19 -1
- package/lib/module/MapView.js.map +1 -1
- package/lib/module/MapView.web.js +30 -22
- package/lib/module/MapView.web.js.map +1 -1
- package/lib/module/components/Circle.js +46 -0
- package/lib/module/components/Circle.js.map +1 -0
- package/lib/module/components/Circle.types.js +4 -0
- package/lib/module/components/Circle.types.js.map +1 -0
- package/lib/module/components/Circle.web.js +79 -0
- package/lib/module/components/Circle.web.js.map +1 -0
- package/lib/module/components/GeoJson.js +3 -3
- package/lib/module/components/GeoJson.js.map +1 -1
- package/lib/module/components/GroundOverlay.js +45 -0
- package/lib/module/components/GroundOverlay.js.map +1 -0
- package/lib/module/components/GroundOverlay.types.js +4 -0
- package/lib/module/components/GroundOverlay.types.js.map +1 -0
- package/lib/module/components/GroundOverlay.web.js +77 -0
- package/lib/module/components/GroundOverlay.web.js.map +1 -0
- package/lib/module/components/Marker.js +22 -4
- package/lib/module/components/Marker.js.map +1 -1
- package/lib/module/components/Marker.web.js +23 -10
- package/lib/module/components/Marker.web.js.map +1 -1
- package/lib/module/components/Polygon.web.js +3 -3
- package/lib/module/components/Polygon.web.js.map +1 -1
- package/lib/module/components/Polyline.web.js +6 -12
- package/lib/module/components/Polyline.web.js.map +1 -1
- package/lib/module/components/TileOverlay.js +44 -0
- package/lib/module/components/TileOverlay.js.map +1 -0
- package/lib/module/components/TileOverlay.types.js +4 -0
- package/lib/module/components/TileOverlay.types.js.map +1 -0
- package/lib/module/components/TileOverlay.web.js +69 -0
- package/lib/module/components/TileOverlay.web.js.map +1 -0
- package/lib/module/components/index.js +3 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/index.web.js +3 -0
- package/lib/module/components/index.web.js.map +1 -1
- package/lib/module/fabric/LuggCalloutViewNativeComponent.ts +1 -1
- package/lib/module/fabric/LuggCircleViewNativeComponent.ts +25 -0
- package/lib/module/fabric/LuggGroundOverlayViewNativeComponent.ts +29 -0
- package/lib/module/fabric/LuggMapViewNativeComponent.ts +16 -5
- package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +14 -2
- package/lib/module/fabric/LuggTileOverlayViewNativeComponent.ts +30 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +3 -0
- package/lib/module/index.web.js.map +1 -1
- package/lib/typescript/src/MapProvider.web.d.ts +3 -2
- package/lib/typescript/src/MapProvider.web.d.ts.map +1 -1
- package/lib/typescript/src/MapView.d.ts +1 -1
- package/lib/typescript/src/MapView.d.ts.map +1 -1
- package/lib/typescript/src/MapView.types.d.ts +60 -1
- package/lib/typescript/src/MapView.types.d.ts.map +1 -1
- package/lib/typescript/src/MapView.web.d.ts +1 -1
- package/lib/typescript/src/MapView.web.d.ts.map +1 -1
- package/lib/typescript/src/components/Circle.d.ts +10 -0
- package/lib/typescript/src/components/Circle.d.ts.map +1 -0
- package/lib/typescript/src/components/Circle.types.d.ts +33 -0
- package/lib/typescript/src/components/Circle.types.d.ts.map +1 -0
- package/lib/typescript/src/components/Circle.web.d.ts +3 -0
- package/lib/typescript/src/components/Circle.web.d.ts.map +1 -0
- package/lib/typescript/src/components/GeoJson.d.ts +2 -1
- package/lib/typescript/src/components/GeoJson.d.ts.map +1 -1
- package/lib/typescript/src/components/GroundOverlay.d.ts +10 -0
- package/lib/typescript/src/components/GroundOverlay.d.ts.map +1 -0
- package/lib/typescript/src/components/GroundOverlay.types.d.ts +35 -0
- package/lib/typescript/src/components/GroundOverlay.types.d.ts.map +1 -0
- package/lib/typescript/src/components/GroundOverlay.web.d.ts +3 -0
- package/lib/typescript/src/components/GroundOverlay.web.d.ts.map +1 -0
- package/lib/typescript/src/components/Marker.d.ts +6 -3
- package/lib/typescript/src/components/Marker.d.ts.map +1 -1
- package/lib/typescript/src/components/Marker.types.d.ts +18 -6
- package/lib/typescript/src/components/Marker.types.d.ts.map +1 -1
- package/lib/typescript/src/components/Marker.web.d.ts +3 -2
- package/lib/typescript/src/components/Marker.web.d.ts.map +1 -1
- package/lib/typescript/src/components/Polygon.web.d.ts +1 -1
- package/lib/typescript/src/components/Polygon.web.d.ts.map +1 -1
- package/lib/typescript/src/components/Polyline.web.d.ts +1 -1
- package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -1
- package/lib/typescript/src/components/TileOverlay.d.ts +10 -0
- package/lib/typescript/src/components/TileOverlay.d.ts.map +1 -0
- package/lib/typescript/src/components/TileOverlay.types.d.ts +36 -0
- package/lib/typescript/src/components/TileOverlay.types.d.ts.map +1 -0
- package/lib/typescript/src/components/TileOverlay.web.d.ts +3 -0
- package/lib/typescript/src/components/TileOverlay.web.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +7 -1
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/components/index.web.d.ts +6 -0
- package/lib/typescript/src/components/index.web.d.ts.map +1 -1
- package/lib/typescript/src/fabric/LuggCalloutViewNativeComponent.d.ts +1 -1
- package/lib/typescript/src/fabric/LuggCircleViewNativeComponent.d.ts +18 -0
- package/lib/typescript/src/fabric/LuggCircleViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/LuggGroundOverlayViewNativeComponent.d.ts +21 -0
- package/lib/typescript/src/fabric/LuggGroundOverlayViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts +13 -5
- package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts +8 -1
- package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/fabric/LuggTileOverlayViewNativeComponent.d.ts +21 -0
- package/lib/typescript/src/fabric/LuggTileOverlayViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +9 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +7 -1
- package/lib/typescript/src/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +0 -4
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +17 -11
- package/src/MapProvider.web.tsx +5 -3
- package/src/MapView.tsx +19 -1
- package/src/MapView.types.ts +142 -1
- package/src/MapView.web.tsx +379 -340
- package/src/components/Circle.tsx +52 -0
- package/src/components/Circle.types.ts +33 -0
- package/src/components/Circle.web.tsx +95 -0
- package/src/components/GeoJson.tsx +3 -3
- package/src/components/GroundOverlay.tsx +47 -0
- package/src/components/GroundOverlay.types.ts +36 -0
- package/src/components/GroundOverlay.web.tsx +81 -0
- package/src/components/Marker.tsx +32 -6
- package/src/components/Marker.types.ts +19 -6
- package/src/components/Marker.web.tsx +196 -150
- package/src/components/Polygon.web.tsx +93 -89
- package/src/components/Polyline.web.tsx +235 -235
- package/src/components/TileOverlay.tsx +44 -0
- package/src/components/TileOverlay.types.ts +37 -0
- package/src/components/TileOverlay.web.tsx +97 -0
- package/src/components/index.ts +10 -0
- package/src/components/index.web.ts +9 -0
- package/src/fabric/LuggCalloutViewNativeComponent.ts +1 -1
- package/src/fabric/LuggCircleViewNativeComponent.ts +25 -0
- package/src/fabric/LuggGroundOverlayViewNativeComponent.ts +29 -0
- package/src/fabric/LuggMapViewNativeComponent.ts +16 -5
- package/src/fabric/LuggMarkerViewNativeComponent.ts +14 -2
- package/src/fabric/LuggTileOverlayViewNativeComponent.ts +30 -0
- package/src/index.ts +12 -1
- package/src/index.web.ts +15 -0
- package/src/types.ts +0 -5
- package/plugin/build/withMapsAndroid.d.ts +0 -5
- package/plugin/build/withMapsAndroid.js +0 -15
- package/plugin/build/withMapsIOS.d.ts +0 -5
- package/plugin/build/withMapsIOS.js +0 -27
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
1
|
+
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { useMapContext } from '../MapProvider.web';
|
|
3
3
|
import type { PolylineProps, PolylineEasing } from './Polyline.types';
|
|
4
4
|
|
|
@@ -51,270 +51,270 @@ const getGradientColor = (colors: string[], position: number): string => {
|
|
|
51
51
|
return interpolateColor(colors[index]!, colors[index + 1]!, t);
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
export const Polyline = (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
map,
|
|
99
|
-
colors,
|
|
100
|
-
strokeWidth,
|
|
101
|
-
hasGradient,
|
|
102
|
-
zIndex: resolvedZIndex,
|
|
103
|
-
});
|
|
104
|
-
const [mapReady, setMapReady] = useState(!!map);
|
|
105
|
-
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
propsRef.current = {
|
|
54
|
+
export const Polyline = memo(
|
|
55
|
+
({
|
|
56
|
+
coordinates,
|
|
57
|
+
strokeColors,
|
|
58
|
+
strokeWidth = 1,
|
|
59
|
+
animated,
|
|
60
|
+
animatedOptions,
|
|
61
|
+
zIndex,
|
|
62
|
+
}: PolylineProps) => {
|
|
63
|
+
const resolvedZIndex = zIndex ?? (animated ? 1 : 0);
|
|
64
|
+
const { map, isDraggingRef } = useMapContext();
|
|
65
|
+
|
|
66
|
+
const { duration, easing, trailLength, delay } = useMemo(
|
|
67
|
+
() => ({
|
|
68
|
+
duration: animatedOptions?.duration ?? DEFAULT_DURATION,
|
|
69
|
+
easing: animatedOptions?.easing ?? 'linear',
|
|
70
|
+
trailLength: Math.max(
|
|
71
|
+
0.01,
|
|
72
|
+
Math.min(1, animatedOptions?.trailLength ?? 1)
|
|
73
|
+
),
|
|
74
|
+
delay: animatedOptions?.delay ?? 0,
|
|
75
|
+
}),
|
|
76
|
+
[
|
|
77
|
+
animatedOptions?.duration,
|
|
78
|
+
animatedOptions?.easing,
|
|
79
|
+
animatedOptions?.trailLength,
|
|
80
|
+
animatedOptions?.delay,
|
|
81
|
+
]
|
|
82
|
+
);
|
|
83
|
+
const polylinesRef = useRef<google.maps.Polyline[]>([]);
|
|
84
|
+
const animationRef = useRef<number>(0);
|
|
85
|
+
|
|
86
|
+
const colors = useMemo(
|
|
87
|
+
() =>
|
|
88
|
+
strokeColors && strokeColors.length > 0
|
|
89
|
+
? (strokeColors as string[])
|
|
90
|
+
: ['#000000'],
|
|
91
|
+
[strokeColors]
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const hasGradient = colors.length > 1;
|
|
95
|
+
|
|
96
|
+
// Refs for animation loop access
|
|
97
|
+
const propsRef = useRef({
|
|
108
98
|
map,
|
|
109
99
|
colors,
|
|
110
100
|
strokeWidth,
|
|
111
101
|
hasGradient,
|
|
112
102
|
zIndex: resolvedZIndex,
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const segment = existing[i];
|
|
144
|
-
if (segment) {
|
|
145
|
-
segment.setPath(segmentPath);
|
|
146
|
-
segment.setOptions({ strokeColor: color });
|
|
147
|
-
} else {
|
|
148
|
-
existing.push(
|
|
149
|
-
new google.maps.Polyline({
|
|
150
|
-
path: segmentPath,
|
|
151
|
-
strokeColor: color,
|
|
152
|
-
strokeWeight: currentStrokeWidth,
|
|
153
|
-
strokeOpacity: 1,
|
|
154
|
-
zIndex: currentZIndex,
|
|
155
|
-
map: currentMap,
|
|
156
|
-
})
|
|
157
|
-
);
|
|
103
|
+
});
|
|
104
|
+
const [mapReady, setMapReady] = useState(!!map);
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
propsRef.current = {
|
|
108
|
+
map,
|
|
109
|
+
colors,
|
|
110
|
+
strokeWidth,
|
|
111
|
+
hasGradient,
|
|
112
|
+
zIndex: resolvedZIndex,
|
|
113
|
+
};
|
|
114
|
+
if (map && !mapReady) setMapReady(true);
|
|
115
|
+
}, [map, colors, strokeWidth, hasGradient, resolvedZIndex, mapReady]);
|
|
116
|
+
|
|
117
|
+
const updatePath = useCallback((path: google.maps.LatLngLiteral[]) => {
|
|
118
|
+
const {
|
|
119
|
+
map: currentMap,
|
|
120
|
+
colors: currentColors,
|
|
121
|
+
strokeWidth: currentStrokeWidth,
|
|
122
|
+
hasGradient: currentHasGradient,
|
|
123
|
+
zIndex: currentZIndex,
|
|
124
|
+
} = propsRef.current;
|
|
125
|
+
const existing = polylinesRef.current;
|
|
126
|
+
if (!currentMap) return;
|
|
127
|
+
|
|
128
|
+
if (path.length < 2) {
|
|
129
|
+
existing.forEach((p) => p.setMap(null));
|
|
130
|
+
existing.length = 0;
|
|
131
|
+
return;
|
|
158
132
|
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Remove extra segments
|
|
162
|
-
for (let i = neededSegments; i < existing.length; i++) {
|
|
163
|
-
existing[i]?.setMap(null);
|
|
164
|
-
}
|
|
165
|
-
existing.length = neededSegments;
|
|
166
|
-
}, []);
|
|
167
|
-
|
|
168
|
-
// Cleanup on unmount
|
|
169
|
-
useEffect(() => {
|
|
170
|
-
const polylines = polylinesRef.current;
|
|
171
|
-
return () => {
|
|
172
|
-
cancelAnimationFrame(animationRef.current);
|
|
173
|
-
polylines.forEach((p) => p.setMap(null));
|
|
174
|
-
};
|
|
175
|
-
}, []);
|
|
176
|
-
|
|
177
|
-
// Pause/resume animation during drag
|
|
178
|
-
useEffect(() => {
|
|
179
|
-
isPausedRef.current = isDragging;
|
|
180
|
-
}, [isDragging]);
|
|
181
133
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
134
|
+
const neededSegments = currentHasGradient ? path.length - 1 : 1;
|
|
135
|
+
|
|
136
|
+
// Update or create segments
|
|
137
|
+
for (let i = 0; i < neededSegments; i++) {
|
|
138
|
+
const segmentPath = currentHasGradient
|
|
139
|
+
? [path[i]!, path[i + 1]!]
|
|
140
|
+
: path;
|
|
141
|
+
const color = currentHasGradient
|
|
142
|
+
? getGradientColor(currentColors, i / (path.length - 1))
|
|
143
|
+
: currentColors[0]!;
|
|
144
|
+
|
|
145
|
+
const segment = existing[i];
|
|
146
|
+
if (segment) {
|
|
147
|
+
segment.setPath(segmentPath);
|
|
148
|
+
segment.setOptions({ strokeColor: color });
|
|
149
|
+
} else {
|
|
150
|
+
existing.push(
|
|
151
|
+
new google.maps.Polyline({
|
|
152
|
+
path: segmentPath,
|
|
153
|
+
strokeColor: color,
|
|
154
|
+
strokeWeight: currentStrokeWidth,
|
|
155
|
+
strokeOpacity: 1,
|
|
156
|
+
zIndex: currentZIndex,
|
|
157
|
+
map: currentMap,
|
|
158
|
+
})
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
185
162
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
163
|
+
// Remove extra segments
|
|
164
|
+
for (let i = neededSegments; i < existing.length; i++) {
|
|
165
|
+
existing[i]?.setMap(null);
|
|
166
|
+
}
|
|
167
|
+
existing.length = neededSegments;
|
|
168
|
+
}, []);
|
|
169
|
+
|
|
170
|
+
// Cleanup on unmount
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
const polylines = polylinesRef.current;
|
|
173
|
+
return () => {
|
|
174
|
+
cancelAnimationFrame(animationRef.current);
|
|
175
|
+
polylines.forEach((p) => p.setMap(null));
|
|
176
|
+
};
|
|
177
|
+
}, []);
|
|
178
|
+
|
|
179
|
+
// Main effect
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (!propsRef.current.map || coordinates.length === 0) return;
|
|
182
|
+
|
|
183
|
+
const fullPath = coordinates.map((c) => ({
|
|
184
|
+
lat: c.latitude,
|
|
185
|
+
lng: c.longitude,
|
|
186
|
+
}));
|
|
190
187
|
|
|
191
|
-
|
|
188
|
+
cancelAnimationFrame(animationRef.current);
|
|
192
189
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
190
|
+
if (!animated) {
|
|
191
|
+
updatePath(fullPath);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
197
194
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
195
|
+
const totalPoints = fullPath.length;
|
|
196
|
+
const useTrailMode = trailLength < 1;
|
|
197
|
+
const renderMax = useTrailMode ? 1 : 2;
|
|
198
|
+
const cycleMax = useTrailMode ? 1 : 2.15;
|
|
202
199
|
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
let startTime: number | null = null;
|
|
201
|
+
let delayRemaining = delay;
|
|
205
202
|
|
|
206
|
-
|
|
203
|
+
let pausedAt: number | null = null;
|
|
207
204
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
205
|
+
const animate = (time: number) => {
|
|
206
|
+
if (isDraggingRef.current) {
|
|
207
|
+
if (pausedAt === null) pausedAt = time;
|
|
208
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
214
211
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
212
|
+
if (pausedAt !== null) {
|
|
213
|
+
if (startTime !== null) {
|
|
214
|
+
startTime += time - pausedAt;
|
|
215
|
+
}
|
|
216
|
+
pausedAt = null;
|
|
218
217
|
}
|
|
219
|
-
pausedAt = null;
|
|
220
|
-
}
|
|
221
218
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
219
|
+
if (startTime === null) {
|
|
220
|
+
startTime = time;
|
|
221
|
+
}
|
|
225
222
|
|
|
226
|
-
|
|
223
|
+
const elapsed = time - startTime;
|
|
227
224
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
225
|
+
if (delayRemaining > 0) {
|
|
226
|
+
if (elapsed < delayRemaining) {
|
|
227
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
startTime = time - (elapsed - delayRemaining);
|
|
231
|
+
delayRemaining = 0;
|
|
232
232
|
}
|
|
233
|
-
startTime = time - (elapsed - delayRemaining);
|
|
234
|
-
delayRemaining = 0;
|
|
235
|
-
}
|
|
236
233
|
|
|
237
|
-
|
|
234
|
+
const rawProgress = (time - startTime) / duration;
|
|
238
235
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
236
|
+
if (rawProgress >= cycleMax) {
|
|
237
|
+
delayRemaining = delay;
|
|
238
|
+
startTime = time;
|
|
239
|
+
}
|
|
243
240
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
const clampedProgress = Math.min(rawProgress, renderMax);
|
|
242
|
+
const easedProgress =
|
|
243
|
+
applyEasing(clampedProgress / renderMax, easing) * renderMax;
|
|
247
244
|
|
|
248
|
-
|
|
249
|
-
|
|
245
|
+
let startIdx: number;
|
|
246
|
+
let endIdx: number;
|
|
250
247
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
248
|
+
if (useTrailMode) {
|
|
249
|
+
endIdx = easedProgress * totalPoints;
|
|
250
|
+
startIdx = Math.max(0, endIdx - trailLength * totalPoints);
|
|
251
|
+
} else {
|
|
252
|
+
startIdx = easedProgress <= 1 ? 0 : (easedProgress - 1) * totalPoints;
|
|
253
|
+
endIdx =
|
|
254
|
+
easedProgress <= 1 ? easedProgress * totalPoints : totalPoints;
|
|
255
|
+
}
|
|
258
256
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
257
|
+
const partialPath: google.maps.LatLngLiteral[] = [];
|
|
258
|
+
const startFloor = Math.floor(startIdx);
|
|
259
|
+
const endFloor = Math.floor(endIdx);
|
|
260
|
+
|
|
261
|
+
// Start point (interpolated)
|
|
262
|
+
if (startFloor < totalPoints) {
|
|
263
|
+
const frac = startIdx - startFloor;
|
|
264
|
+
const from = fullPath[startFloor]!;
|
|
265
|
+
const to = fullPath[Math.min(startFloor + 1, totalPoints - 1)]!;
|
|
266
|
+
partialPath.push(
|
|
267
|
+
frac > 0
|
|
268
|
+
? {
|
|
269
|
+
lat: from.lat + (to.lat - from.lat) * frac,
|
|
270
|
+
lng: from.lng + (to.lng - from.lng) * frac,
|
|
271
|
+
}
|
|
272
|
+
: from
|
|
273
|
+
);
|
|
274
|
+
}
|
|
277
275
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
276
|
+
// Middle points
|
|
277
|
+
for (
|
|
278
|
+
let i = startFloor + 1;
|
|
279
|
+
i <= Math.min(endFloor, totalPoints - 1);
|
|
280
|
+
i++
|
|
281
|
+
) {
|
|
282
|
+
partialPath.push(fullPath[i]!);
|
|
283
|
+
}
|
|
286
284
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
285
|
+
// End point (interpolated)
|
|
286
|
+
if (endFloor < totalPoints - 1) {
|
|
287
|
+
const frac = endIdx - endFloor;
|
|
288
|
+
const from = fullPath[endFloor]!;
|
|
289
|
+
const to = fullPath[endFloor + 1]!;
|
|
290
|
+
if (frac > 0) {
|
|
291
|
+
partialPath.push({
|
|
292
|
+
lat: from.lat + (to.lat - from.lat) * frac,
|
|
293
|
+
lng: from.lng + (to.lng - from.lng) * frac,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
297
296
|
}
|
|
298
|
-
}
|
|
299
297
|
|
|
300
|
-
|
|
298
|
+
updatePath(partialPath);
|
|
299
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
300
|
+
};
|
|
301
|
+
|
|
301
302
|
animationRef.current = requestAnimationFrame(animate);
|
|
302
|
-
};
|
|
303
303
|
|
|
304
|
-
|
|
304
|
+
return () => cancelAnimationFrame(animationRef.current);
|
|
305
|
+
}, [
|
|
306
|
+
coordinates,
|
|
307
|
+
animated,
|
|
308
|
+
duration,
|
|
309
|
+
easing,
|
|
310
|
+
trailLength,
|
|
311
|
+
delay,
|
|
312
|
+
hasGradient,
|
|
313
|
+
updatePath,
|
|
314
|
+
mapReady,
|
|
315
|
+
isDraggingRef,
|
|
316
|
+
]);
|
|
305
317
|
|
|
306
|
-
return
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
animated,
|
|
310
|
-
duration,
|
|
311
|
-
easing,
|
|
312
|
-
trailLength,
|
|
313
|
-
delay,
|
|
314
|
-
hasGradient,
|
|
315
|
-
updatePath,
|
|
316
|
-
mapReady,
|
|
317
|
-
]);
|
|
318
|
-
|
|
319
|
-
return null;
|
|
320
|
-
};
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
|
+
import LuggTileOverlayViewNativeComponent from '../fabric/LuggTileOverlayViewNativeComponent';
|
|
4
|
+
import type { TileOverlayProps } from './TileOverlay.types';
|
|
5
|
+
|
|
6
|
+
export type { TileOverlayProps } from './TileOverlay.types';
|
|
7
|
+
|
|
8
|
+
export class TileOverlay extends React.PureComponent<TileOverlayProps> {
|
|
9
|
+
private _cachedZIndex: number | undefined;
|
|
10
|
+
private _cachedStyle: any;
|
|
11
|
+
|
|
12
|
+
private getStyle(zIndex: number | undefined) {
|
|
13
|
+
if (zIndex == null) return styles.overlay;
|
|
14
|
+
if (zIndex !== this._cachedZIndex) {
|
|
15
|
+
this._cachedZIndex = zIndex;
|
|
16
|
+
this._cachedStyle = [{ zIndex }, styles.overlay];
|
|
17
|
+
}
|
|
18
|
+
return this._cachedStyle!;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
render() {
|
|
22
|
+
const { urlTemplate, tileSize, opacity, bounds, zIndex, onPress } =
|
|
23
|
+
this.props;
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<LuggTileOverlayViewNativeComponent
|
|
27
|
+
style={this.getStyle(zIndex)}
|
|
28
|
+
urlTemplate={urlTemplate}
|
|
29
|
+
tileSize={tileSize}
|
|
30
|
+
opacity={opacity}
|
|
31
|
+
bounds={bounds}
|
|
32
|
+
tappable={!!onPress}
|
|
33
|
+
onTileOverlayPress={onPress}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const styles = StyleSheet.create({
|
|
40
|
+
overlay: {
|
|
41
|
+
position: 'absolute',
|
|
42
|
+
pointerEvents: 'none',
|
|
43
|
+
},
|
|
44
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Coordinate } from '../types';
|
|
2
|
+
|
|
3
|
+
export interface TileOverlayBounds {
|
|
4
|
+
northeast: Coordinate;
|
|
5
|
+
southwest: Coordinate;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface TileOverlayProps {
|
|
9
|
+
/**
|
|
10
|
+
* URL template for tile images.
|
|
11
|
+
* Use `{x}`, `{y}`, `{z}` placeholders for tile coordinates and zoom level.
|
|
12
|
+
* @example "https://tile.openstreetmap.org/{z}/{x}/{y}.png"
|
|
13
|
+
*/
|
|
14
|
+
urlTemplate: string;
|
|
15
|
+
/**
|
|
16
|
+
* Size of each tile in pixels
|
|
17
|
+
* @default 256
|
|
18
|
+
*/
|
|
19
|
+
tileSize?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Opacity of the tile overlay (0-1)
|
|
22
|
+
*/
|
|
23
|
+
opacity?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Restrict tiles to a geographic region.
|
|
26
|
+
* Tiles outside these bounds will not be loaded.
|
|
27
|
+
*/
|
|
28
|
+
bounds?: TileOverlayBounds;
|
|
29
|
+
/**
|
|
30
|
+
* Z-index for layering
|
|
31
|
+
*/
|
|
32
|
+
zIndex?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Called when the tile overlay is tapped
|
|
35
|
+
*/
|
|
36
|
+
onPress?: () => void;
|
|
37
|
+
}
|