@lugg/maps 1.0.0-beta.5 → 1.0.0-beta.7

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.
Files changed (55) hide show
  1. package/ios/core/AppleMapProvider.mm +91 -50
  2. package/lib/module/MapProvider.web.js +4 -1
  3. package/lib/module/MapProvider.web.js.map +1 -1
  4. package/lib/module/MapView.js +1 -1
  5. package/lib/module/MapView.js.map +1 -1
  6. package/lib/module/MapView.web.js +18 -18
  7. package/lib/module/MapView.web.js.map +1 -1
  8. package/lib/module/components/Circle.web.js +3 -3
  9. package/lib/module/components/Circle.web.js.map +1 -1
  10. package/lib/module/components/GeoJson.js +3 -3
  11. package/lib/module/components/GeoJson.js.map +1 -1
  12. package/lib/module/components/GroundOverlay.web.js +3 -3
  13. package/lib/module/components/GroundOverlay.web.js.map +1 -1
  14. package/lib/module/components/Marker.web.js +6 -6
  15. package/lib/module/components/Marker.web.js.map +1 -1
  16. package/lib/module/components/Polygon.web.js +3 -3
  17. package/lib/module/components/Polygon.web.js.map +1 -1
  18. package/lib/module/components/Polyline.web.js +6 -12
  19. package/lib/module/components/Polyline.web.js.map +1 -1
  20. package/lib/module/components/TileOverlay.web.js +3 -3
  21. package/lib/module/components/TileOverlay.web.js.map +1 -1
  22. package/lib/typescript/src/MapProvider.web.d.ts +3 -2
  23. package/lib/typescript/src/MapProvider.web.d.ts.map +1 -1
  24. package/lib/typescript/src/MapView.d.ts +1 -1
  25. package/lib/typescript/src/MapView.d.ts.map +1 -1
  26. package/lib/typescript/src/MapView.types.d.ts +1 -1
  27. package/lib/typescript/src/MapView.types.d.ts.map +1 -1
  28. package/lib/typescript/src/MapView.web.d.ts +1 -1
  29. package/lib/typescript/src/MapView.web.d.ts.map +1 -1
  30. package/lib/typescript/src/components/Circle.web.d.ts +1 -1
  31. package/lib/typescript/src/components/Circle.web.d.ts.map +1 -1
  32. package/lib/typescript/src/components/GeoJson.d.ts +2 -1
  33. package/lib/typescript/src/components/GeoJson.d.ts.map +1 -1
  34. package/lib/typescript/src/components/GroundOverlay.web.d.ts +1 -1
  35. package/lib/typescript/src/components/GroundOverlay.web.d.ts.map +1 -1
  36. package/lib/typescript/src/components/Marker.web.d.ts +1 -1
  37. package/lib/typescript/src/components/Marker.web.d.ts.map +1 -1
  38. package/lib/typescript/src/components/Polygon.web.d.ts +1 -1
  39. package/lib/typescript/src/components/Polygon.web.d.ts.map +1 -1
  40. package/lib/typescript/src/components/Polyline.web.d.ts +1 -1
  41. package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -1
  42. package/lib/typescript/src/components/TileOverlay.web.d.ts +1 -1
  43. package/lib/typescript/src/components/TileOverlay.web.d.ts.map +1 -1
  44. package/package.json +1 -1
  45. package/src/MapProvider.web.tsx +5 -3
  46. package/src/MapView.tsx +1 -1
  47. package/src/MapView.types.ts +33 -0
  48. package/src/MapView.web.tsx +378 -356
  49. package/src/components/Circle.web.tsx +81 -79
  50. package/src/components/GeoJson.tsx +3 -3
  51. package/src/components/GroundOverlay.web.tsx +65 -69
  52. package/src/components/Marker.web.tsx +184 -181
  53. package/src/components/Polygon.web.tsx +93 -89
  54. package/src/components/Polyline.web.tsx +235 -235
  55. package/src/components/TileOverlay.web.tsx +83 -81
@@ -1,6 +1,7 @@
1
1
  import React, {
2
2
  forwardRef,
3
3
  isValidElement,
4
+ memo,
4
5
  useCallback,
5
6
  useEffect,
6
7
  useImperativeHandle,
@@ -60,194 +61,196 @@ const createEvent = (
60
61
  },
61
62
  } as any);
62
63
 
63
- export const Marker = forwardRef<MarkerRef, MarkerProps>(
64
- (
65
- {
66
- coordinate,
67
- title,
68
- description,
69
- anchor,
70
- zIndex,
71
- rotate,
72
- scale,
73
- centerOnPress = true,
74
- draggable,
75
- onPress,
76
- onDragStart,
77
- onDragChange,
78
- onDragEnd,
79
- callout,
80
- calloutOptions,
81
- children,
82
- },
83
- ref
84
- ) => {
85
- const { moveCamera, onCalloutClose, closeCallouts } = useMapContext();
86
- const dragPositionRef = useRef<google.maps.LatLngLiteral | null>(null);
87
- const [markerRef, markerElement] = useAdvancedMarkerRef();
88
- const [infoWindowOpen, setInfoWindowOpen] = useState(false);
89
- const calloutBubbled = calloutOptions?.bubbled ?? true;
90
- const calloutOffset = calloutOptions?.offset;
91
-
92
- const closeCallout = useCallback(() => setInfoWindowOpen(false), []);
93
-
94
- useEffect(
95
- () => onCalloutClose(closeCallout),
96
- [onCalloutClose, closeCallout]
97
- );
98
-
99
- useEffect(() => {
100
- if (!calloutBubbled) injectUnbubbledStyle();
101
- }, [calloutBubbled]);
102
-
103
- const hasCallout = !!(callout || title);
104
-
105
- useImperativeHandle(
106
- ref,
107
- () => ({
108
- showCallout() {
64
+ export const Marker = memo(
65
+ forwardRef<MarkerRef, MarkerProps>(
66
+ (
67
+ {
68
+ coordinate,
69
+ title,
70
+ description,
71
+ anchor,
72
+ zIndex,
73
+ rotate,
74
+ scale,
75
+ centerOnPress = true,
76
+ draggable,
77
+ onPress,
78
+ onDragStart,
79
+ onDragChange,
80
+ onDragEnd,
81
+ callout,
82
+ calloutOptions,
83
+ children,
84
+ },
85
+ ref
86
+ ) => {
87
+ const { moveCamera, onCalloutClose, closeCallouts } = useMapContext();
88
+ const dragPositionRef = useRef<google.maps.LatLngLiteral | null>(null);
89
+ const [markerRef, markerElement] = useAdvancedMarkerRef();
90
+ const [infoWindowOpen, setInfoWindowOpen] = useState(false);
91
+ const calloutBubbled = calloutOptions?.bubbled ?? true;
92
+ const calloutOffset = calloutOptions?.offset;
93
+
94
+ const closeCallout = useCallback(() => setInfoWindowOpen(false), []);
95
+
96
+ useEffect(
97
+ () => onCalloutClose(closeCallout),
98
+ [onCalloutClose, closeCallout]
99
+ );
100
+
101
+ useEffect(() => {
102
+ if (!calloutBubbled) injectUnbubbledStyle();
103
+ }, [calloutBubbled]);
104
+
105
+ const hasCallout = !!(callout || title);
106
+
107
+ useImperativeHandle(
108
+ ref,
109
+ () => ({
110
+ showCallout() {
111
+ if (hasCallout) {
112
+ closeCallouts(closeCallout);
113
+ setInfoWindowOpen(true);
114
+ }
115
+ },
116
+ hideCallout() {
117
+ setInfoWindowOpen(false);
118
+ },
119
+ }),
120
+ [hasCallout, closeCallouts, closeCallout]
121
+ );
122
+
123
+ const calloutContent = callout
124
+ ? isValidElement(callout)
125
+ ? callout
126
+ : React.createElement(callout)
127
+ : title
128
+ ? React.createElement(
129
+ 'div',
130
+ { style: { fontSize: 14 } },
131
+ React.createElement('div', { style: { fontWeight: 500 } }, title),
132
+ description ? React.createElement('div', null, description) : null
133
+ )
134
+ : null;
135
+
136
+ const transforms: string[] = [];
137
+ if (rotate) transforms.push(`rotate(${rotate}deg)`);
138
+ if (scale && scale !== 1) transforms.push(`scale(${scale})`);
139
+
140
+ const handleClick = useCallback(
141
+ (e: google.maps.MapMouseEvent) => {
142
+ const pos = dragPositionRef.current;
143
+ const coord = pos
144
+ ? { latitude: pos.lat, longitude: pos.lng }
145
+ : coordinate;
146
+ if (centerOnPress) moveCamera(coord);
147
+ onPress?.(createEvent(e, coordinate));
109
148
  if (hasCallout) {
110
149
  closeCallouts(closeCallout);
111
- setInfoWindowOpen(true);
150
+ setInfoWindowOpen((prev) => !prev);
112
151
  }
113
152
  },
114
- hideCallout() {
115
- setInfoWindowOpen(false);
153
+ [
154
+ centerOnPress,
155
+ moveCamera,
156
+ onPress,
157
+ coordinate,
158
+ hasCallout,
159
+ closeCallouts,
160
+ closeCallout,
161
+ ]
162
+ );
163
+
164
+ const handleDragStart = useCallback(
165
+ (e: google.maps.MapMouseEvent) => {
166
+ const latLng = e.latLng;
167
+ if (latLng) {
168
+ dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
169
+ }
170
+ onDragStart?.(createEvent(e, coordinate));
116
171
  },
117
- }),
118
- [hasCallout, closeCallouts, closeCallout]
119
- );
120
-
121
- const calloutContent = callout
122
- ? isValidElement(callout)
123
- ? callout
124
- : React.createElement(callout)
125
- : title
126
- ? React.createElement(
127
- 'div',
128
- { style: { fontSize: 14 } },
129
- React.createElement('div', { style: { fontWeight: 500 } }, title),
130
- description ? React.createElement('div', null, description) : null
131
- )
132
- : null;
133
-
134
- const transforms: string[] = [];
135
- if (rotate) transforms.push(`rotate(${rotate}deg)`);
136
- if (scale && scale !== 1) transforms.push(`scale(${scale})`);
137
-
138
- const handleClick = useCallback(
139
- (e: google.maps.MapMouseEvent) => {
140
- const pos = dragPositionRef.current;
141
- const coord = pos
142
- ? { latitude: pos.lat, longitude: pos.lng }
143
- : coordinate;
144
- if (centerOnPress) moveCamera(coord);
145
- onPress?.(createEvent(e, coordinate));
146
- if (hasCallout) {
147
- closeCallouts(closeCallout);
148
- setInfoWindowOpen((prev) => !prev);
149
- }
150
- },
151
- [
152
- centerOnPress,
153
- moveCamera,
154
- onPress,
155
- coordinate,
156
- hasCallout,
157
- closeCallouts,
158
- closeCallout,
159
- ]
160
- );
161
-
162
- const handleDragStart = useCallback(
163
- (e: google.maps.MapMouseEvent) => {
164
- const latLng = e.latLng;
165
- if (latLng) {
166
- dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
167
- }
168
- onDragStart?.(createEvent(e, coordinate));
169
- },
170
- [onDragStart, coordinate]
171
- );
172
-
173
- const handleDrag = useCallback(
174
- (e: google.maps.MapMouseEvent) => {
175
- const latLng = e.latLng;
176
- if (latLng) {
177
- dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
178
- }
179
- onDragChange?.(createEvent(e, coordinate));
180
- },
181
- [onDragChange, coordinate]
182
- );
183
-
184
- const handleDragEnd = useCallback(
185
- (e: google.maps.MapMouseEvent) => {
186
- const latLng = e.latLng;
187
- if (latLng) {
188
- dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
189
- }
190
- onDragEnd?.(createEvent(e, coordinate));
191
- },
192
- [onDragEnd, coordinate]
193
- );
194
-
195
- useEffect(() => {
196
- dragPositionRef.current = null;
197
- }, [coordinate.latitude, coordinate.longitude]);
198
-
199
- const latLngPosition = {
200
- lat: coordinate.latitude,
201
- lng: coordinate.longitude,
202
- };
203
-
204
- const position = dragPositionRef.current ?? latLngPosition;
205
-
206
- return (
207
- <>
208
- <AdvancedMarker
209
- ref={markerRef}
210
- position={position}
211
- title={title}
212
- zIndex={zIndex}
213
- anchorLeft={anchor ? toWebAnchor(anchor.x) : undefined}
214
- anchorTop={anchor ? toWebAnchor(anchor.y) : undefined}
215
- clickable
216
- draggable={draggable}
217
- onClick={handleClick}
218
- onDragStart={handleDragStart}
219
- onDrag={handleDrag}
220
- onDragEnd={handleDragEnd}
221
- style={
222
- transforms.length > 0
223
- ? { transform: transforms.join(' ') }
224
- : undefined
172
+ [onDragStart, coordinate]
173
+ );
174
+
175
+ const handleDrag = useCallback(
176
+ (e: google.maps.MapMouseEvent) => {
177
+ const latLng = e.latLng;
178
+ if (latLng) {
179
+ dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
225
180
  }
226
- >
227
- {children}
228
- </AdvancedMarker>
229
- {calloutContent && infoWindowOpen && markerElement && (
230
- <InfoWindow
231
- anchor={markerElement}
232
- pixelOffset={
233
- !calloutBubbled
234
- ? [
235
- calloutOffset?.x ?? 0,
236
- CALLOUT_ARROW_HEIGHT + (calloutOffset?.y ?? 0),
237
- ]
181
+ onDragChange?.(createEvent(e, coordinate));
182
+ },
183
+ [onDragChange, coordinate]
184
+ );
185
+
186
+ const handleDragEnd = useCallback(
187
+ (e: google.maps.MapMouseEvent) => {
188
+ const latLng = e.latLng;
189
+ if (latLng) {
190
+ dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
191
+ }
192
+ onDragEnd?.(createEvent(e, coordinate));
193
+ },
194
+ [onDragEnd, coordinate]
195
+ );
196
+
197
+ useEffect(() => {
198
+ dragPositionRef.current = null;
199
+ }, [coordinate.latitude, coordinate.longitude]);
200
+
201
+ const latLngPosition = {
202
+ lat: coordinate.latitude,
203
+ lng: coordinate.longitude,
204
+ };
205
+
206
+ const position = dragPositionRef.current ?? latLngPosition;
207
+
208
+ return (
209
+ <>
210
+ <AdvancedMarker
211
+ ref={markerRef}
212
+ position={position}
213
+ title={title}
214
+ zIndex={zIndex}
215
+ anchorLeft={anchor ? toWebAnchor(anchor.x) : undefined}
216
+ anchorTop={anchor ? toWebAnchor(anchor.y) : undefined}
217
+ clickable
218
+ draggable={draggable}
219
+ onClick={handleClick}
220
+ onDragStart={draggable ? handleDragStart : undefined}
221
+ onDrag={draggable ? handleDrag : undefined}
222
+ onDragEnd={draggable ? handleDragEnd : undefined}
223
+ style={
224
+ transforms.length > 0
225
+ ? { transform: transforms.join(' ') }
238
226
  : undefined
239
227
  }
240
- headerDisabled
241
- onClose={() => setInfoWindowOpen(false)}
242
228
  >
243
- {!calloutBubbled ? (
244
- <div className={UNBUBBLED_CLASS}>{calloutContent}</div>
245
- ) : (
246
- calloutContent
247
- )}
248
- </InfoWindow>
249
- )}
250
- </>
251
- );
252
- }
229
+ {children}
230
+ </AdvancedMarker>
231
+ {calloutContent && infoWindowOpen && markerElement && (
232
+ <InfoWindow
233
+ anchor={markerElement}
234
+ pixelOffset={
235
+ !calloutBubbled
236
+ ? [
237
+ calloutOffset?.x ?? 0,
238
+ CALLOUT_ARROW_HEIGHT + (calloutOffset?.y ?? 0),
239
+ ]
240
+ : undefined
241
+ }
242
+ headerDisabled
243
+ onClose={() => setInfoWindowOpen(false)}
244
+ >
245
+ {!calloutBubbled ? (
246
+ <div className={UNBUBBLED_CLASS}>{calloutContent}</div>
247
+ ) : (
248
+ calloutContent
249
+ )}
250
+ </InfoWindow>
251
+ )}
252
+ </>
253
+ );
254
+ }
255
+ )
253
256
  );
@@ -1,104 +1,108 @@
1
- import { useCallback, useEffect, useRef } from 'react';
1
+ import { memo, useCallback, useEffect, useRef } from 'react';
2
2
  import { useMapContext } from '../MapProvider.web';
3
3
  import type { PolygonProps } from './Polygon.types';
4
4
 
5
- export const Polygon = ({
6
- coordinates,
7
- holes,
8
- strokeColor = '#000000',
9
- strokeWidth = 1,
10
- fillColor = 'rgba(0, 0, 0, 0.3)',
11
- zIndex = 0,
12
- onPress,
13
- }: PolygonProps) => {
14
- const { map } = useMapContext();
15
- const polygonRef = useRef<google.maps.Polygon | null>(null);
16
- const listenersRef = useRef<google.maps.MapsEventListener[]>([]);
5
+ export const Polygon = memo(
6
+ ({
7
+ coordinates,
8
+ holes,
9
+ strokeColor = '#000000',
10
+ strokeWidth = 1,
11
+ fillColor = 'rgba(0, 0, 0, 0.3)',
12
+ zIndex = 0,
13
+ onPress,
14
+ }: PolygonProps) => {
15
+ const { map } = useMapContext();
16
+ const polygonRef = useRef<google.maps.Polygon | null>(null);
17
+ const listenersRef = useRef<google.maps.MapsEventListener[]>([]);
17
18
 
18
- const handleClick = useCallback(() => {
19
- onPress?.();
20
- }, [onPress]);
19
+ const handleClick = useCallback(() => {
20
+ onPress?.();
21
+ }, [onPress]);
21
22
 
22
- // Cleanup on unmount
23
- useEffect(() => {
24
- return () => {
25
- listenersRef.current.forEach((l) => l.remove());
26
- listenersRef.current = [];
27
- polygonRef.current?.setMap(null);
28
- polygonRef.current = null;
29
- };
30
- }, []);
23
+ // Cleanup on unmount
24
+ useEffect(() => {
25
+ return () => {
26
+ listenersRef.current.forEach((l) => l.remove());
27
+ listenersRef.current = [];
28
+ polygonRef.current?.setMap(null);
29
+ polygonRef.current = null;
30
+ };
31
+ }, []);
31
32
 
32
- // Sync listeners
33
- useEffect(() => {
34
- const polygon = polygonRef.current;
35
- if (!polygon) return;
33
+ // Sync listeners
34
+ useEffect(() => {
35
+ const polygon = polygonRef.current;
36
+ if (!polygon) return;
36
37
 
37
- listenersRef.current.forEach((l) => l.remove());
38
- listenersRef.current = [];
38
+ listenersRef.current.forEach((l) => l.remove());
39
+ listenersRef.current = [];
39
40
 
40
- if (onPress) {
41
- listenersRef.current.push(polygon.addListener('click', handleClick));
42
- }
43
- polygon.set('clickable', !!onPress);
44
- }, [onPress, handleClick]);
41
+ if (onPress) {
42
+ listenersRef.current.push(polygon.addListener('click', handleClick));
43
+ }
44
+ polygon.set('clickable', !!onPress);
45
+ }, [onPress, handleClick]);
45
46
 
46
- // Sync polygon with props
47
- useEffect(() => {
48
- if (!map || coordinates.length === 0) {
49
- polygonRef.current?.setMap(null);
50
- return;
51
- }
47
+ // Sync polygon with props
48
+ useEffect(() => {
49
+ if (!map || coordinates.length === 0) {
50
+ polygonRef.current?.setMap(null);
51
+ return;
52
+ }
52
53
 
53
- const outerPath = coordinates.map((c) => ({
54
- lat: c.latitude,
55
- lng: c.longitude,
56
- }));
54
+ const outerPath = coordinates.map((c) => ({
55
+ lat: c.latitude,
56
+ lng: c.longitude,
57
+ }));
57
58
 
58
- const paths = [
59
- outerPath,
60
- ...(holes ?? []).map((hole) =>
61
- [...hole].reverse().map((c) => ({ lat: c.latitude, lng: c.longitude }))
62
- ),
63
- ];
59
+ const paths = [
60
+ outerPath,
61
+ ...(holes ?? []).map((hole) =>
62
+ [...hole]
63
+ .reverse()
64
+ .map((c) => ({ lat: c.latitude, lng: c.longitude }))
65
+ ),
66
+ ];
64
67
 
65
- if (polygonRef.current) {
66
- polygonRef.current.setPaths(paths);
67
- polygonRef.current.setOptions({
68
- strokeColor: strokeColor as string,
69
- strokeWeight: strokeWidth,
70
- fillColor: fillColor as string,
71
- zIndex,
72
- });
73
- } else {
74
- const polygon = new google.maps.Polygon({
75
- paths,
76
- strokeColor: strokeColor as string,
77
- strokeWeight: strokeWidth,
78
- strokeOpacity: 1,
79
- fillColor: fillColor as string,
80
- fillOpacity: 1,
81
- zIndex,
82
- clickable: !!onPress,
83
- map,
84
- });
85
- polygonRef.current = polygon;
68
+ if (polygonRef.current) {
69
+ polygonRef.current.setPaths(paths);
70
+ polygonRef.current.setOptions({
71
+ strokeColor: strokeColor as string,
72
+ strokeWeight: strokeWidth,
73
+ fillColor: fillColor as string,
74
+ zIndex,
75
+ });
76
+ } else {
77
+ const polygon = new google.maps.Polygon({
78
+ paths,
79
+ strokeColor: strokeColor as string,
80
+ strokeWeight: strokeWidth,
81
+ strokeOpacity: 1,
82
+ fillColor: fillColor as string,
83
+ fillOpacity: 1,
84
+ zIndex,
85
+ clickable: !!onPress,
86
+ map,
87
+ });
88
+ polygonRef.current = polygon;
86
89
 
87
- if (onPress) {
88
- listenersRef.current.push(polygon.addListener('click', handleClick));
90
+ if (onPress) {
91
+ listenersRef.current.push(polygon.addListener('click', handleClick));
92
+ }
89
93
  }
90
- }
91
- }, [
92
- map,
93
- coordinates,
94
- holes,
95
- strokeColor,
96
- strokeWidth,
97
- fillColor,
98
- zIndex,
99
- onPress,
100
- handleClick,
101
- ]);
94
+ }, [
95
+ map,
96
+ coordinates,
97
+ holes,
98
+ strokeColor,
99
+ strokeWidth,
100
+ fillColor,
101
+ zIndex,
102
+ onPress,
103
+ handleClick,
104
+ ]);
102
105
 
103
- return null;
104
- };
106
+ return null;
107
+ }
108
+ );