@lugg/maps 1.0.0-beta.4 → 1.0.0-beta.6

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 (104) hide show
  1. package/android/src/main/java/com/luggmaps/LuggCalloutView.kt +4 -2
  2. package/android/src/main/java/com/luggmaps/LuggCalloutViewManager.kt +4 -3
  3. package/android/src/main/java/com/luggmaps/LuggMapView.kt +40 -0
  4. package/android/src/main/java/com/luggmaps/LuggMapViewManager.kt +31 -0
  5. package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +23 -0
  6. package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +13 -0
  7. package/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +166 -21
  8. package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +5 -0
  9. package/android/src/main/java/com/luggmaps/extensions/ViewExtensions.kt +11 -0
  10. package/ios/LuggCalloutView.h +1 -1
  11. package/ios/LuggCalloutView.mm +21 -11
  12. package/ios/LuggMapView.mm +41 -2
  13. package/ios/LuggMarkerView.h +3 -0
  14. package/ios/LuggMarkerView.mm +23 -0
  15. package/ios/core/AppleMapProvider.mm +236 -16
  16. package/ios/core/GoogleMapProvider.mm +91 -18
  17. package/ios/core/MapProviderDelegate.h +8 -1
  18. package/lib/module/MapProvider.web.js +4 -1
  19. package/lib/module/MapProvider.web.js.map +1 -1
  20. package/lib/module/MapView.js +12 -1
  21. package/lib/module/MapView.js.map +1 -1
  22. package/lib/module/MapView.web.js +21 -18
  23. package/lib/module/MapView.web.js.map +1 -1
  24. package/lib/module/components/Circle.web.js +3 -3
  25. package/lib/module/components/Circle.web.js.map +1 -1
  26. package/lib/module/components/GeoJson.js +3 -3
  27. package/lib/module/components/GeoJson.js.map +1 -1
  28. package/lib/module/components/GroundOverlay.web.js +3 -3
  29. package/lib/module/components/GroundOverlay.web.js.map +1 -1
  30. package/lib/module/components/Marker.js +17 -3
  31. package/lib/module/components/Marker.js.map +1 -1
  32. package/lib/module/components/Marker.web.js +23 -10
  33. package/lib/module/components/Marker.web.js.map +1 -1
  34. package/lib/module/components/Polygon.web.js +3 -3
  35. package/lib/module/components/Polygon.web.js.map +1 -1
  36. package/lib/module/components/Polyline.web.js +6 -12
  37. package/lib/module/components/Polyline.web.js.map +1 -1
  38. package/lib/module/components/TileOverlay.web.js +3 -3
  39. package/lib/module/components/TileOverlay.web.js.map +1 -1
  40. package/lib/module/components/index.js.map +1 -1
  41. package/lib/module/fabric/LuggCalloutViewNativeComponent.ts +1 -1
  42. package/lib/module/fabric/LuggMapViewNativeComponent.ts +9 -1
  43. package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +14 -2
  44. package/lib/module/index.js.map +1 -1
  45. package/lib/typescript/src/MapProvider.web.d.ts +3 -2
  46. package/lib/typescript/src/MapProvider.web.d.ts.map +1 -1
  47. package/lib/typescript/src/MapView.d.ts +1 -1
  48. package/lib/typescript/src/MapView.d.ts.map +1 -1
  49. package/lib/typescript/src/MapView.types.d.ts +36 -1
  50. package/lib/typescript/src/MapView.types.d.ts.map +1 -1
  51. package/lib/typescript/src/MapView.web.d.ts +1 -1
  52. package/lib/typescript/src/MapView.web.d.ts.map +1 -1
  53. package/lib/typescript/src/components/Circle.web.d.ts +1 -1
  54. package/lib/typescript/src/components/Circle.web.d.ts.map +1 -1
  55. package/lib/typescript/src/components/GeoJson.d.ts +2 -1
  56. package/lib/typescript/src/components/GeoJson.d.ts.map +1 -1
  57. package/lib/typescript/src/components/GroundOverlay.web.d.ts +1 -1
  58. package/lib/typescript/src/components/GroundOverlay.web.d.ts.map +1 -1
  59. package/lib/typescript/src/components/Marker.d.ts +6 -3
  60. package/lib/typescript/src/components/Marker.d.ts.map +1 -1
  61. package/lib/typescript/src/components/Marker.types.d.ts +14 -5
  62. package/lib/typescript/src/components/Marker.types.d.ts.map +1 -1
  63. package/lib/typescript/src/components/Marker.web.d.ts +3 -2
  64. package/lib/typescript/src/components/Marker.web.d.ts.map +1 -1
  65. package/lib/typescript/src/components/Polygon.web.d.ts +1 -1
  66. package/lib/typescript/src/components/Polygon.web.d.ts.map +1 -1
  67. package/lib/typescript/src/components/Polyline.web.d.ts +1 -1
  68. package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -1
  69. package/lib/typescript/src/components/TileOverlay.web.d.ts +1 -1
  70. package/lib/typescript/src/components/TileOverlay.web.d.ts.map +1 -1
  71. package/lib/typescript/src/components/index.d.ts +1 -1
  72. package/lib/typescript/src/components/index.d.ts.map +1 -1
  73. package/lib/typescript/src/fabric/LuggCalloutViewNativeComponent.d.ts +1 -1
  74. package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts +6 -1
  75. package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -1
  76. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts +8 -1
  77. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts.map +1 -1
  78. package/lib/typescript/src/index.d.ts +3 -3
  79. package/lib/typescript/src/index.d.ts.map +1 -1
  80. package/lib/typescript/src/index.web.d.ts +1 -1
  81. package/lib/typescript/src/index.web.d.ts.map +1 -1
  82. package/lib/typescript/src/types.d.ts +0 -4
  83. package/lib/typescript/src/types.d.ts.map +1 -1
  84. package/package.json +1 -1
  85. package/src/MapProvider.web.tsx +5 -3
  86. package/src/MapView.tsx +12 -1
  87. package/src/MapView.types.ts +118 -1
  88. package/src/MapView.web.tsx +378 -345
  89. package/src/components/Circle.web.tsx +81 -79
  90. package/src/components/GeoJson.tsx +3 -3
  91. package/src/components/GroundOverlay.web.tsx +65 -69
  92. package/src/components/Marker.tsx +28 -5
  93. package/src/components/Marker.types.ts +15 -5
  94. package/src/components/Marker.web.tsx +196 -150
  95. package/src/components/Polygon.web.tsx +93 -89
  96. package/src/components/Polyline.web.tsx +235 -235
  97. package/src/components/TileOverlay.web.tsx +83 -81
  98. package/src/components/index.ts +1 -0
  99. package/src/fabric/LuggCalloutViewNativeComponent.ts +1 -1
  100. package/src/fabric/LuggMapViewNativeComponent.ts +9 -1
  101. package/src/fabric/LuggMarkerViewNativeComponent.ts +14 -2
  102. package/src/index.ts +6 -1
  103. package/src/index.web.ts +3 -0
  104. package/src/types.ts +0 -5
@@ -1,7 +1,10 @@
1
1
  import React, {
2
+ forwardRef,
2
3
  isValidElement,
4
+ memo,
3
5
  useCallback,
4
6
  useEffect,
7
+ useImperativeHandle,
5
8
  useRef,
6
9
  useState,
7
10
  } from 'react';
@@ -11,7 +14,7 @@ import {
11
14
  useAdvancedMarkerRef,
12
15
  } from '@vis.gl/react-google-maps';
13
16
  import { useMapContext } from '../MapProvider.web';
14
- import type { MarkerProps } from './Marker.types';
17
+ import type { MarkerProps, MarkerRef } from './Marker.types';
15
18
 
16
19
  const CALLOUT_ARROW_HEIGHT = 12;
17
20
  const UNBUBBLED_CLASS = 'rnm-callout-unbubbled';
@@ -58,153 +61,196 @@ const createEvent = (
58
61
  },
59
62
  } as any);
60
63
 
61
- export const Marker = ({
62
- coordinate,
63
- title,
64
- description,
65
- anchor,
66
- zIndex,
67
- rotate,
68
- scale,
69
- draggable,
70
- onPress,
71
- onDragStart,
72
- onDragChange,
73
- onDragEnd,
74
- callout,
75
- calloutOptions,
76
- children,
77
- }: MarkerProps) => {
78
- const { moveCamera, onCalloutClose, closeCallouts } = useMapContext();
79
- const dragPositionRef = useRef<google.maps.LatLngLiteral | null>(null);
80
- const [markerRef, markerElement] = useAdvancedMarkerRef();
81
- const [infoWindowOpen, setInfoWindowOpen] = useState(false);
82
- const calloutBubbled = calloutOptions?.bubbled ?? true;
83
-
84
- const closeCallout = useCallback(() => setInfoWindowOpen(false), []);
85
-
86
- useEffect(() => onCalloutClose(closeCallout), [onCalloutClose, closeCallout]);
87
-
88
- useEffect(() => {
89
- if (!calloutBubbled) injectUnbubbledStyle();
90
- }, [calloutBubbled]);
91
-
92
- const hasCallout = !!(callout || title);
93
-
94
- const calloutContent = callout
95
- ? isValidElement(callout)
96
- ? callout
97
- : React.createElement(callout)
98
- : title
99
- ? React.createElement(
100
- 'div',
101
- { style: { fontSize: 14 } },
102
- React.createElement('div', { style: { fontWeight: 500 } }, title),
103
- description ? React.createElement('div', null, description) : null
104
- )
105
- : null;
106
-
107
- const transforms: string[] = [];
108
- if (rotate) transforms.push(`rotate(${rotate}deg)`);
109
- if (scale && scale !== 1) transforms.push(`scale(${scale})`);
110
-
111
- const handleClick = useCallback(
112
- (e: google.maps.MapMouseEvent) => {
113
- const pos = dragPositionRef.current;
114
- const coord = pos
115
- ? { latitude: pos.lat, longitude: pos.lng }
116
- : coordinate;
117
- moveCamera(coord);
118
- onPress?.(createEvent(e, coordinate));
119
- if (hasCallout) {
120
- closeCallouts(closeCallout);
121
- setInfoWindowOpen((prev) => !prev);
122
- }
123
- },
124
- [moveCamera, onPress, coordinate, hasCallout, closeCallouts, closeCallout]
125
- );
126
-
127
- const handleDragStart = useCallback(
128
- (e: google.maps.MapMouseEvent) => {
129
- const latLng = e.latLng;
130
- if (latLng) {
131
- dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
132
- }
133
- onDragStart?.(createEvent(e, coordinate));
134
- },
135
- [onDragStart, coordinate]
136
- );
137
-
138
- const handleDrag = useCallback(
139
- (e: google.maps.MapMouseEvent) => {
140
- const latLng = e.latLng;
141
- if (latLng) {
142
- dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
143
- }
144
- onDragChange?.(createEvent(e, coordinate));
145
- },
146
- [onDragChange, coordinate]
147
- );
148
-
149
- const handleDragEnd = useCallback(
150
- (e: google.maps.MapMouseEvent) => {
151
- const latLng = e.latLng;
152
- if (latLng) {
153
- dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
154
- }
155
- onDragEnd?.(createEvent(e, coordinate));
156
- },
157
- [onDragEnd, coordinate]
158
- );
159
-
160
- useEffect(() => {
161
- dragPositionRef.current = null;
162
- }, [coordinate.latitude, coordinate.longitude]);
163
-
164
- const latLngPosition = {
165
- lat: coordinate.latitude,
166
- lng: coordinate.longitude,
167
- };
168
-
169
- const position = dragPositionRef.current ?? latLngPosition;
170
-
171
- return (
172
- <>
173
- <AdvancedMarker
174
- ref={markerRef}
175
- position={position}
176
- title={title}
177
- zIndex={zIndex}
178
- anchorLeft={anchor ? toWebAnchor(anchor.x) : undefined}
179
- anchorTop={anchor ? toWebAnchor(anchor.y) : undefined}
180
- clickable
181
- draggable={draggable}
182
- onClick={handleClick}
183
- onDragStart={handleDragStart}
184
- onDrag={handleDrag}
185
- onDragEnd={handleDragEnd}
186
- style={
187
- transforms.length > 0
188
- ? { transform: transforms.join(' ') }
189
- : undefined
190
- }
191
- >
192
- {children}
193
- </AdvancedMarker>
194
- {calloutContent && infoWindowOpen && markerElement && (
195
- <InfoWindow
196
- anchor={markerElement}
197
- pixelOffset={!calloutBubbled ? [0, CALLOUT_ARROW_HEIGHT] : undefined}
198
- headerDisabled
199
- onClose={() => setInfoWindowOpen(false)}
200
- >
201
- {!calloutBubbled ? (
202
- <div className={UNBUBBLED_CLASS}>{calloutContent}</div>
203
- ) : (
204
- calloutContent
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));
148
+ if (hasCallout) {
149
+ closeCallouts(closeCallout);
150
+ setInfoWindowOpen((prev) => !prev);
151
+ }
152
+ },
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));
171
+ },
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() };
180
+ }
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(' ') }
226
+ : undefined
227
+ }
228
+ >
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>
205
251
  )}
206
- </InfoWindow>
207
- )}
208
- </>
209
- );
210
- };
252
+ </>
253
+ );
254
+ }
255
+ )
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
+ );