@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.
- package/android/src/main/java/com/luggmaps/LuggCalloutView.kt +4 -2
- package/android/src/main/java/com/luggmaps/LuggCalloutViewManager.kt +4 -3
- package/android/src/main/java/com/luggmaps/LuggMapView.kt +40 -0
- package/android/src/main/java/com/luggmaps/LuggMapViewManager.kt +31 -0
- package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +23 -0
- package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +13 -0
- package/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +166 -21
- package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +5 -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/LuggMapView.mm +41 -2
- package/ios/LuggMarkerView.h +3 -0
- package/ios/LuggMarkerView.mm +23 -0
- package/ios/core/AppleMapProvider.mm +236 -16
- package/ios/core/GoogleMapProvider.mm +91 -18
- package/ios/core/MapProviderDelegate.h +8 -1
- package/lib/module/MapProvider.web.js +4 -1
- package/lib/module/MapProvider.web.js.map +1 -1
- package/lib/module/MapView.js +12 -1
- package/lib/module/MapView.js.map +1 -1
- package/lib/module/MapView.web.js +21 -18
- package/lib/module/MapView.web.js.map +1 -1
- package/lib/module/components/Circle.web.js +3 -3
- package/lib/module/components/Circle.web.js.map +1 -1
- package/lib/module/components/GeoJson.js +3 -3
- package/lib/module/components/GeoJson.js.map +1 -1
- package/lib/module/components/GroundOverlay.web.js +3 -3
- package/lib/module/components/GroundOverlay.web.js.map +1 -1
- package/lib/module/components/Marker.js +17 -3
- 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.web.js +3 -3
- package/lib/module/components/TileOverlay.web.js.map +1 -1
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/fabric/LuggCalloutViewNativeComponent.ts +1 -1
- package/lib/module/fabric/LuggMapViewNativeComponent.ts +9 -1
- package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +14 -2
- package/lib/module/index.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 +36 -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.web.d.ts +1 -1
- package/lib/typescript/src/components/Circle.web.d.ts.map +1 -1
- 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.web.d.ts +1 -1
- package/lib/typescript/src/components/GroundOverlay.web.d.ts.map +1 -1
- 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 +14 -5
- 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.web.d.ts +1 -1
- package/lib/typescript/src/components/TileOverlay.web.d.ts.map +1 -1
- package/lib/typescript/src/components/index.d.ts +1 -1
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/fabric/LuggCalloutViewNativeComponent.d.ts +1 -1
- package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts +6 -1
- 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/index.d.ts +3 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +1 -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 +1 -1
- package/src/MapProvider.web.tsx +5 -3
- package/src/MapView.tsx +12 -1
- package/src/MapView.types.ts +118 -1
- package/src/MapView.web.tsx +378 -345
- package/src/components/Circle.web.tsx +81 -79
- package/src/components/GeoJson.tsx +3 -3
- package/src/components/GroundOverlay.web.tsx +65 -69
- package/src/components/Marker.tsx +28 -5
- package/src/components/Marker.types.ts +15 -5
- 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.web.tsx +83 -81
- package/src/components/index.ts +1 -0
- package/src/fabric/LuggCalloutViewNativeComponent.ts +1 -1
- package/src/fabric/LuggMapViewNativeComponent.ts +9 -1
- package/src/fabric/LuggMarkerViewNativeComponent.ts +14 -2
- package/src/index.ts +6 -1
- package/src/index.web.ts +3 -0
- 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
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const handleClick = useCallback(() => {
|
|
20
|
+
onPress?.();
|
|
21
|
+
}, [onPress]);
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
// Sync listeners
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const polygon = polygonRef.current;
|
|
36
|
+
if (!polygon) return;
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
listenersRef.current.forEach((l) => l.remove());
|
|
39
|
+
listenersRef.current = [];
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
if (onPress) {
|
|
42
|
+
listenersRef.current.push(polygon.addListener('click', handleClick));
|
|
43
|
+
}
|
|
44
|
+
polygon.set('clickable', !!onPress);
|
|
45
|
+
}, [onPress, handleClick]);
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const outerPath = coordinates.map((c) => ({
|
|
55
|
+
lat: c.latitude,
|
|
56
|
+
lng: c.longitude,
|
|
57
|
+
}));
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
88
|
-
|
|
90
|
+
if (onPress) {
|
|
91
|
+
listenersRef.current.push(polygon.addListener('click', handleClick));
|
|
92
|
+
}
|
|
89
93
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
]);
|
|
94
|
+
}, [
|
|
95
|
+
map,
|
|
96
|
+
coordinates,
|
|
97
|
+
holes,
|
|
98
|
+
strokeColor,
|
|
99
|
+
strokeWidth,
|
|
100
|
+
fillColor,
|
|
101
|
+
zIndex,
|
|
102
|
+
onPress,
|
|
103
|
+
handleClick,
|
|
104
|
+
]);
|
|
102
105
|
|
|
103
|
-
|
|
104
|
-
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
);
|