@lugg/maps 0.2.0-alpha.10 → 0.2.0-alpha.12
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/lib/module/MapIdContext.web.js +6 -0
- package/lib/module/MapIdContext.web.js.map +1 -0
- package/lib/module/MapView.web.js +128 -153
- package/lib/module/MapView.web.js.map +1 -1
- package/lib/module/components/Marker.web.js +16 -25
- package/lib/module/components/Marker.web.js.map +1 -1
- package/lib/module/components/Polyline.web.js +5 -11
- package/lib/module/components/Polyline.web.js.map +1 -1
- package/lib/typescript/src/MapIdContext.web.d.ts +3 -0
- package/lib/typescript/src/MapIdContext.web.d.ts.map +1 -0
- package/lib/typescript/src/MapView.web.d.ts +2 -11
- package/lib/typescript/src/MapView.web.d.ts.map +1 -1
- package/lib/typescript/src/components/Marker.web.d.ts +1 -4
- package/lib/typescript/src/components/Marker.web.d.ts.map +1 -1
- package/lib/typescript/src/components/Polyline.web.d.ts +1 -4
- package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/MapIdContext.web.ts +5 -0
- package/src/MapView.web.tsx +138 -168
- package/src/components/Marker.web.tsx +18 -26
- package/src/components/Polyline.web.tsx +5 -16
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","useContext","MapIdContext","useMapId"],"sourceRoot":"../../src","sources":["MapIdContext.web.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,QAAQ,OAAO;AAEjD,OAAO,MAAMC,YAAY,gBAAGF,aAAa,CAAgB,IAAI,CAAC;AAE9D,OAAO,MAAMG,QAAQ,GAAGA,CAAA,KAAMF,UAAU,CAACC,YAAY,CAAC","ignoreList":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { Children,
|
|
3
|
+
import { Children, forwardRef, isValidElement, useEffect, useId, useImperativeHandle, useRef, useState } from 'react';
|
|
4
4
|
import { View } from 'react-native';
|
|
5
5
|
import { Map, useMap } from '@vis.gl/react-google-maps';
|
|
6
6
|
import { Marker } from "./components/Marker.web.js";
|
|
7
7
|
import { Polyline } from "./components/Polyline.web.js";
|
|
8
|
+
import { MapIdContext } from "./MapIdContext.web.js";
|
|
8
9
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
-
// Map-specific component types that render inside the Google Map
|
|
10
10
|
const MAP_COMPONENT_TYPES = new Set([Marker, Polyline]);
|
|
11
11
|
const isMapComponent = child => MAP_COMPONENT_TYPES.has(child.type);
|
|
12
12
|
const createSyntheticEvent = nativeEvent => ({
|
|
@@ -70,22 +70,87 @@ function UserLocationMarker({
|
|
|
70
70
|
})
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
export const MapView = /*#__PURE__*/forwardRef(function MapView(props, ref) {
|
|
74
|
+
const {
|
|
75
|
+
mapId = 'DEMO_MAP_ID',
|
|
76
|
+
initialCoordinate,
|
|
77
|
+
initialZoom = 10,
|
|
78
|
+
minZoom,
|
|
79
|
+
maxZoom,
|
|
80
|
+
zoomEnabled = true,
|
|
81
|
+
scrollEnabled = true,
|
|
82
|
+
pitchEnabled = true,
|
|
83
|
+
padding,
|
|
84
|
+
userLocationEnabled,
|
|
85
|
+
onCameraMove,
|
|
86
|
+
onCameraIdle,
|
|
87
|
+
onReady,
|
|
88
|
+
children,
|
|
89
|
+
style
|
|
90
|
+
} = props;
|
|
91
|
+
const id = useId();
|
|
92
|
+
const map = useMap(id);
|
|
80
93
|
const readyFired = useRef(false);
|
|
94
|
+
useImperativeHandle(ref, () => ({
|
|
95
|
+
moveCamera(coordinate, options) {
|
|
96
|
+
if (!map) return;
|
|
97
|
+
const {
|
|
98
|
+
zoom,
|
|
99
|
+
duration = -1
|
|
100
|
+
} = options;
|
|
101
|
+
const center = {
|
|
102
|
+
lat: coordinate.latitude,
|
|
103
|
+
lng: coordinate.longitude
|
|
104
|
+
};
|
|
105
|
+
if (duration === 0) {
|
|
106
|
+
map.moveCamera({
|
|
107
|
+
center,
|
|
108
|
+
zoom
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
const currentZoom = map.getZoom();
|
|
112
|
+
const zoomChanged = zoom !== undefined && zoom !== currentZoom;
|
|
113
|
+
if (zoomChanged) {
|
|
114
|
+
map.setZoom(zoom);
|
|
115
|
+
}
|
|
116
|
+
map.panTo(center);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
fitCoordinates(coordinates, options) {
|
|
120
|
+
const first = coordinates[0];
|
|
121
|
+
if (!map || !first) return;
|
|
122
|
+
const {
|
|
123
|
+
padding: fitPadding,
|
|
124
|
+
duration = -1
|
|
125
|
+
} = options ?? {};
|
|
126
|
+
if (coordinates.length === 1) {
|
|
127
|
+
this.moveCamera(first, {
|
|
128
|
+
zoom: initialZoom,
|
|
129
|
+
duration
|
|
130
|
+
});
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const bounds = new google.maps.LatLngBounds();
|
|
134
|
+
coordinates.forEach(coord => {
|
|
135
|
+
bounds.extend({
|
|
136
|
+
lat: coord.latitude,
|
|
137
|
+
lng: coord.longitude
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
map.fitBounds(bounds, {
|
|
141
|
+
top: fitPadding?.top ?? 0,
|
|
142
|
+
left: fitPadding?.left ?? 0,
|
|
143
|
+
bottom: fitPadding?.bottom ?? 0,
|
|
144
|
+
right: fitPadding?.right ?? 0
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}), [map, initialZoom]);
|
|
81
148
|
useEffect(() => {
|
|
82
|
-
if (!
|
|
83
|
-
onMapReady(map);
|
|
84
|
-
if (!readyFired.current) {
|
|
149
|
+
if (map && !readyFired.current) {
|
|
85
150
|
readyFired.current = true;
|
|
86
151
|
onReady?.();
|
|
87
152
|
}
|
|
88
|
-
}, [map,
|
|
153
|
+
}, [map, onReady]);
|
|
89
154
|
useEffect(() => {
|
|
90
155
|
if (!map) return;
|
|
91
156
|
const createPayload = gesture => {
|
|
@@ -100,8 +165,10 @@ function MapController({
|
|
|
100
165
|
};
|
|
101
166
|
};
|
|
102
167
|
let isDragging = false;
|
|
168
|
+
let wasGesture = false;
|
|
103
169
|
const dragStartListener = map.addListener('dragstart', () => {
|
|
104
170
|
isDragging = true;
|
|
171
|
+
wasGesture = true;
|
|
105
172
|
});
|
|
106
173
|
const dragEndListener = map.addListener('dragend', () => {
|
|
107
174
|
isDragging = false;
|
|
@@ -110,7 +177,8 @@ function MapController({
|
|
|
110
177
|
onCameraMove?.(createSyntheticEvent(createPayload(isDragging)));
|
|
111
178
|
});
|
|
112
179
|
const idleListener = map.addListener('idle', () => {
|
|
113
|
-
onCameraIdle?.(createSyntheticEvent(createPayload(
|
|
180
|
+
onCameraIdle?.(createSyntheticEvent(createPayload(wasGesture)));
|
|
181
|
+
wasGesture = false;
|
|
114
182
|
});
|
|
115
183
|
return () => {
|
|
116
184
|
google.maps.event.removeListener(dragStartListener);
|
|
@@ -119,148 +187,55 @@ function MapController({
|
|
|
119
187
|
google.maps.event.removeListener(idleListener);
|
|
120
188
|
};
|
|
121
189
|
}, [map, onCameraMove, onCameraIdle]);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
mapInstance = null;
|
|
135
|
-
handleMapReady = map => {
|
|
136
|
-
this.mapInstance = map;
|
|
137
|
-
};
|
|
138
|
-
moveCamera(coordinate, options) {
|
|
139
|
-
const map = this.mapInstance;
|
|
140
|
-
if (!map) return;
|
|
141
|
-
const {
|
|
142
|
-
zoom,
|
|
143
|
-
duration = -1
|
|
144
|
-
} = options;
|
|
145
|
-
const center = {
|
|
146
|
-
lat: coordinate.latitude,
|
|
147
|
-
lng: coordinate.longitude
|
|
148
|
-
};
|
|
149
|
-
if (duration === 0) {
|
|
150
|
-
map.moveCamera({
|
|
151
|
-
center,
|
|
152
|
-
zoom
|
|
153
|
-
});
|
|
190
|
+
const gestureHandling = scrollEnabled === false && zoomEnabled === false ? 'none' : scrollEnabled === false ? 'none' : 'auto';
|
|
191
|
+
const defaultCenter = initialCoordinate ? {
|
|
192
|
+
lat: initialCoordinate.latitude,
|
|
193
|
+
lng: initialCoordinate.longitude
|
|
194
|
+
} : undefined;
|
|
195
|
+
const mapChildren = [];
|
|
196
|
+
const overlayChildren = [];
|
|
197
|
+
Children.forEach(children, child => {
|
|
198
|
+
if (! /*#__PURE__*/isValidElement(child)) return;
|
|
199
|
+
if (isMapComponent(child)) {
|
|
200
|
+
mapChildren.push(child);
|
|
154
201
|
} else {
|
|
155
|
-
|
|
156
|
-
const zoomChanged = zoom !== undefined && zoom !== currentZoom;
|
|
157
|
-
if (zoomChanged) {
|
|
158
|
-
map.setZoom(zoom);
|
|
159
|
-
}
|
|
160
|
-
map.panTo(center);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
fitCoordinates(coordinates, options) {
|
|
164
|
-
const map = this.mapInstance;
|
|
165
|
-
const first = coordinates[0];
|
|
166
|
-
if (!map || !first) return;
|
|
167
|
-
const {
|
|
168
|
-
padding,
|
|
169
|
-
duration = -1
|
|
170
|
-
} = options ?? {};
|
|
171
|
-
if (coordinates.length === 1) {
|
|
172
|
-
const zoom = this.props.initialZoom ?? 10;
|
|
173
|
-
this.moveCamera(first, {
|
|
174
|
-
zoom,
|
|
175
|
-
duration
|
|
176
|
-
});
|
|
177
|
-
return;
|
|
202
|
+
overlayChildren.push(child);
|
|
178
203
|
}
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
style
|
|
210
|
-
} = this.props;
|
|
211
|
-
const gestureHandling = scrollEnabled === false && zoomEnabled === false ? 'none' : scrollEnabled === false ? 'none' : 'auto';
|
|
212
|
-
const defaultCenter = initialCoordinate ? {
|
|
213
|
-
lat: initialCoordinate.latitude,
|
|
214
|
-
lng: initialCoordinate.longitude
|
|
215
|
-
} : undefined;
|
|
216
|
-
|
|
217
|
-
// Separate map children (Marker, Polyline) from overlay children (regular Views)
|
|
218
|
-
const mapChildren = [];
|
|
219
|
-
const overlayChildren = [];
|
|
220
|
-
Children.forEach(children, child => {
|
|
221
|
-
if (! /*#__PURE__*/isValidElement(child)) return;
|
|
222
|
-
if (isMapComponent(child)) {
|
|
223
|
-
mapChildren.push(child);
|
|
224
|
-
} else {
|
|
225
|
-
overlayChildren.push(child);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
const mapContainerStyle = {
|
|
229
|
-
position: 'absolute',
|
|
230
|
-
top: padding?.top ?? 0,
|
|
231
|
-
left: padding?.left ?? 0,
|
|
232
|
-
right: padding?.right ?? 0,
|
|
233
|
-
bottom: padding?.bottom ?? 0
|
|
234
|
-
};
|
|
235
|
-
const mapStyle = {
|
|
236
|
-
width: '100%',
|
|
237
|
-
height: '100%'
|
|
238
|
-
};
|
|
239
|
-
return /*#__PURE__*/_jsxs(View, {
|
|
240
|
-
style: style,
|
|
241
|
-
children: [/*#__PURE__*/_jsx(View, {
|
|
242
|
-
style: mapContainerStyle,
|
|
243
|
-
children: /*#__PURE__*/_jsxs(Map, {
|
|
244
|
-
mapId: mapId,
|
|
245
|
-
defaultCenter: defaultCenter,
|
|
246
|
-
defaultZoom: initialZoom,
|
|
247
|
-
minZoom: minZoom,
|
|
248
|
-
maxZoom: maxZoom,
|
|
249
|
-
gestureHandling: gestureHandling,
|
|
250
|
-
disableDefaultUI: true,
|
|
251
|
-
tilt: pitchEnabled === false ? 0 : undefined,
|
|
252
|
-
style: mapStyle,
|
|
253
|
-
children: [/*#__PURE__*/_jsx(MapController, {
|
|
254
|
-
onMapReady: this.handleMapReady,
|
|
255
|
-
onCameraMove: onCameraMove,
|
|
256
|
-
onCameraIdle: onCameraIdle,
|
|
257
|
-
onReady: onReady
|
|
258
|
-
}), /*#__PURE__*/_jsx(UserLocationMarker, {
|
|
204
|
+
});
|
|
205
|
+
const mapContainerStyle = {
|
|
206
|
+
position: 'absolute',
|
|
207
|
+
top: padding?.top ?? 0,
|
|
208
|
+
left: padding?.left ?? 0,
|
|
209
|
+
right: padding?.right ?? 0,
|
|
210
|
+
bottom: padding?.bottom ?? 0
|
|
211
|
+
};
|
|
212
|
+
const mapStyle = {
|
|
213
|
+
width: '100%',
|
|
214
|
+
height: '100%'
|
|
215
|
+
};
|
|
216
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
217
|
+
style: style,
|
|
218
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
219
|
+
style: mapContainerStyle,
|
|
220
|
+
children: /*#__PURE__*/_jsx(Map, {
|
|
221
|
+
id: id,
|
|
222
|
+
mapId: mapId,
|
|
223
|
+
defaultCenter: defaultCenter,
|
|
224
|
+
defaultZoom: initialZoom,
|
|
225
|
+
minZoom: minZoom,
|
|
226
|
+
maxZoom: maxZoom,
|
|
227
|
+
gestureHandling: gestureHandling,
|
|
228
|
+
disableDefaultUI: true,
|
|
229
|
+
tilt: pitchEnabled === false ? 0 : undefined,
|
|
230
|
+
style: mapStyle,
|
|
231
|
+
children: /*#__PURE__*/_jsxs(MapIdContext.Provider, {
|
|
232
|
+
value: id,
|
|
233
|
+
children: [/*#__PURE__*/_jsx(UserLocationMarker, {
|
|
259
234
|
enabled: userLocationEnabled
|
|
260
235
|
}), mapChildren]
|
|
261
236
|
})
|
|
262
|
-
})
|
|
263
|
-
})
|
|
264
|
-
}
|
|
265
|
-
}
|
|
237
|
+
})
|
|
238
|
+
}), overlayChildren]
|
|
239
|
+
});
|
|
240
|
+
});
|
|
266
241
|
//# sourceMappingURL=MapView.web.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Children","
|
|
1
|
+
{"version":3,"names":["Children","forwardRef","isValidElement","useEffect","useId","useImperativeHandle","useRef","useState","View","Map","useMap","Marker","Polyline","MapIdContext","jsx","_jsx","jsxs","_jsxs","MAP_COMPONENT_TYPES","Set","isMapComponent","child","has","type","createSyntheticEvent","nativeEvent","currentTarget","target","bubbles","cancelable","defaultPrevented","eventPhase","isTrusted","preventDefault","stopPropagation","isDefaultPrevented","isPropagationStopped","persist","timeStamp","Date","now","userLocationDotStyle","width","height","backgroundColor","border","borderRadius","boxShadow","UserLocationMarker","enabled","coordinate","setCoordinate","watchId","updateLocation","position","latitude","coords","longitude","navigator","geolocation","getCurrentPosition","watchPosition","clearWatch","anchor","x","y","children","style","MapView","props","ref","mapId","initialCoordinate","initialZoom","minZoom","maxZoom","zoomEnabled","scrollEnabled","pitchEnabled","padding","userLocationEnabled","onCameraMove","onCameraIdle","onReady","id","map","readyFired","moveCamera","options","zoom","duration","center","lat","lng","currentZoom","getZoom","zoomChanged","undefined","setZoom","panTo","fitCoordinates","coordinates","first","fitPadding","length","bounds","google","maps","LatLngBounds","forEach","coord","extend","fitBounds","top","left","bottom","right","current","createPayload","gesture","getCenter","isDragging","wasGesture","dragStartListener","addListener","dragEndListener","centerListener","idleListener","event","removeListener","gestureHandling","defaultCenter","mapChildren","overlayChildren","push","mapContainerStyle","mapStyle","defaultZoom","disableDefaultUI","tilt","Provider","value"],"sourceRoot":"../../src","sources":["MapView.web.tsx"],"mappings":";;AAAA,SACEA,QAAQ,EACRC,UAAU,EACVC,c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;MAAArE,QAAA,eAC7BnD,IAAA,CAACN,GAAG;QACF2E,EAAE,EAAEA,EAAG;QACPb,KAAK,EAAEA,KAAM;QACb4D,aAAa,EAAEA,aAAc;QAC7BM,WAAW,EAAEhE,WAAY;QACzBC,OAAO,EAAEA,OAAQ;QACjBC,OAAO,EAAEA,OAAQ;QACjBuD,eAAe,EAAEA,eAAgB;QACjCQ,gBAAgB;QAChBC,IAAI,EAAE7D,YAAY,KAAK,KAAK,GAAG,CAAC,GAAGmB,SAAU;QAC7C9B,KAAK,EAAEqE,QAAS;QAAAtE,QAAA,eAEhBjD,KAAA,CAACJ,YAAY,CAAC+H,QAAQ;UAACC,KAAK,EAAEzD,EAAG;UAAAlB,QAAA,gBAC/BnD,IAAA,CAACiC,kBAAkB;YAACC,OAAO,EAAE+B;UAAoB,CAAE,CAAC,EACnDoD,WAAW;QAAA,CACS;MAAC,CACrB;IAAC,CACF,CAAC,EACNC,eAAe;EAAA,CACZ,CAAC;AAEX,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import React from 'react';
|
|
4
3
|
import { AdvancedMarker } from '@vis.gl/react-google-maps';
|
|
5
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
/**
|
|
7
|
-
* Converts point to % anchor for web.
|
|
8
|
-
* e.g. `0.5` to `-50%`
|
|
9
|
-
*/
|
|
10
5
|
const toWebAnchor = value => `-${value * 100}%`;
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const position = {
|
|
6
|
+
export function Marker({
|
|
7
|
+
coordinate,
|
|
8
|
+
title,
|
|
9
|
+
anchor,
|
|
10
|
+
zIndex,
|
|
11
|
+
children
|
|
12
|
+
}) {
|
|
13
|
+
return /*#__PURE__*/_jsx(AdvancedMarker, {
|
|
14
|
+
position: {
|
|
21
15
|
lat: coordinate.latitude,
|
|
22
16
|
lng: coordinate.longitude
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
children: children
|
|
31
|
-
});
|
|
32
|
-
}
|
|
17
|
+
},
|
|
18
|
+
title: title,
|
|
19
|
+
zIndex: zIndex,
|
|
20
|
+
anchorLeft: anchor ? toWebAnchor(anchor.x) : undefined,
|
|
21
|
+
anchorTop: anchor ? toWebAnchor(anchor.y) : undefined,
|
|
22
|
+
children: children
|
|
23
|
+
});
|
|
33
24
|
}
|
|
34
25
|
//# sourceMappingURL=Marker.web.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["AdvancedMarker","jsx","_jsx","toWebAnchor","value","Marker","coordinate","title","anchor","zIndex","children","position","lat","latitude","lng","longitude","anchorLeft","x","undefined","anchorTop","y"],"sourceRoot":"../../../src","sources":["components/Marker.web.tsx"],"mappings":";;AAAA,SAASA,cAAc,QAAQ,2BAA2B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAG3D,MAAMC,WAAW,GAAIC,KAAa,IAAK,IAAIA,KAAK,GAAG,GAAG,GAAG;AAEzD,OAAO,SAASC,MAAMA,CAAC;EACrBC,UAAU;EACVC,KAAK;EACLC,MAAM;EACNC,MAAM;EACNC;AACW,CAAC,EAAE;EACd,oBACER,IAAA,CAACF,cAAc;IACbW,QAAQ,EAAE;MAAEC,GAAG,EAAEN,UAAU,CAACO,QAAQ;MAAEC,GAAG,EAAER,UAAU,CAACS;IAAU,CAAE;IAClER,KAAK,EAAEA,KAAM;IACbE,MAAM,EAAEA,MAAO;IACfO,UAAU,EAAER,MAAM,GAAGL,WAAW,CAACK,MAAM,CAACS,CAAC,CAAC,GAAGC,SAAU;IACvDC,SAAS,EAAEX,MAAM,GAAGL,WAAW,CAACK,MAAM,CAACY,CAAC,CAAC,GAAGF,SAAU;IAAAR,QAAA,EAErDA;EAAQ,CACK,CAAC;AAErB","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { useMap } from '@vis.gl/react-google-maps';
|
|
5
|
-
import {
|
|
5
|
+
import { useMapId } from "../MapIdContext.web.js";
|
|
6
6
|
const ANIMATION_DURATION = 1500;
|
|
7
7
|
function interpolateColor(color1, color2, t) {
|
|
8
8
|
const hex = c => parseInt(c, 16);
|
|
@@ -26,7 +26,7 @@ function getGradientColor(colors, position) {
|
|
|
26
26
|
const t = scaledPos - index;
|
|
27
27
|
return interpolateColor(colors[index], colors[index + 1], t);
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
export function Polyline({
|
|
30
30
|
coordinates,
|
|
31
31
|
strokeColors,
|
|
32
32
|
strokeWidth = 1,
|
|
@@ -34,7 +34,8 @@ function PolylineImpl({
|
|
|
34
34
|
zIndex
|
|
35
35
|
}) {
|
|
36
36
|
const resolvedZIndex = zIndex ?? (animated ? 1 : 0);
|
|
37
|
-
const
|
|
37
|
+
const mapId = useMapId();
|
|
38
|
+
const map = useMap(mapId);
|
|
38
39
|
const polylinesRef = useRef([]);
|
|
39
40
|
const animationRef = useRef(0);
|
|
40
41
|
const colors = useMemo(() => strokeColors && strokeColors.length > 0 ? strokeColors : ['#000000'], [strokeColors]);
|
|
@@ -167,11 +168,4 @@ function PolylineImpl({
|
|
|
167
168
|
}, [coordinates, animated, hasGradient, updatePath, mapReady]);
|
|
168
169
|
return null;
|
|
169
170
|
}
|
|
170
|
-
export class Polyline extends Component {
|
|
171
|
-
render() {
|
|
172
|
-
return /*#__PURE__*/_jsx(PolylineImpl, {
|
|
173
|
-
...this.props
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
171
|
//# sourceMappingURL=Polyline.web.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useMemo","useRef","useState","useMap","useMapId","ANIMATION_DURATION","interpolateColor","color1","color2","t","hex","c","parseInt","r1","slice","g1","b1","r2","g2","b2","r","Math","round","g","b","toString","padStart","getGradientColor","colors","position","length","scaledPos","index","floor","Polyline","coordinates","strokeColors","strokeWidth","animated","zIndex","resolvedZIndex","mapId","map","polylinesRef","animationRef","hasGradient","propsRef","mapReady","setMapReady","current","updatePath","path","currentMap","currentColors","currentStrokeWidth","currentHasGradient","currentZIndex","neededSegments","existing","i","segmentPath","color","segment","setPath","setOptions","strokeColor","push","google","maps","strokeWeight","strokeOpacity","setMap","polylines","cancelAnimationFrame","forEach","p","fullPath","lat","latitude","lng","longitude","totalPoints","cycleDuration","animate","time","progress","startIdx","endIdx","partialPath","startFloor","endFloor","frac","from","to","min","requestAnimationFrame"],"sourceRoot":"../../../src","sources":["components/Polyline.web.tsx"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACzE,SAASC,MAAM,QAAQ,2BAA2B;AAClD,SAASC,QAAQ,QAAQ,wBAAqB;AAG9C,MAAMC,kBAAkB,GAAG,IAAI;AAE/B,SAASC,gBAAgBA,CAACC,MAAc,EAAEC,MAAc,EAAEC,CAAS,EAAU;EAC3E,MAAMC,GAAG,GAAIC,CAAS,IAAKC,QAAQ,CAACD,CAAC,EAAE,EAAE,CAAC;EAC1C,MAAME,EAAE,GAAGH,GAAG,CAACH,MAAM,CAACO,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAClC,MAAMC,EAAE,GAAGL,GAAG,CAACH,MAAM,CAACO,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAClC,MAAME,EAAE,GAAGN,GAAG,CAACH,MAAM,CAACO,KAAK,CAAC,CAAC,EAAE,C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CAAqC,CAAC;AAE/D,eAAO,MAAM,QAAQ,qBAAiC,CAAC"}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import type { Coordinate } from './types';
|
|
4
|
-
export declare class MapView extends Component<MapViewProps> implements MapViewRef {
|
|
5
|
-
static defaultProps: Partial<MapViewProps>;
|
|
6
|
-
private mapInstance;
|
|
7
|
-
private handleMapReady;
|
|
8
|
-
moveCamera(coordinate: Coordinate, options: MoveCameraOptions): void;
|
|
9
|
-
fitCoordinates(coordinates: Coordinate[], options?: FitCoordinatesOptions): void;
|
|
10
|
-
render(): import("react/jsx-runtime").JSX.Element;
|
|
11
|
-
}
|
|
1
|
+
import type { MapViewProps, MapViewRef } from './MapView.types';
|
|
2
|
+
export declare const MapView: import("react").ForwardRefExoticComponent<MapViewProps & import("react").RefAttributes<MapViewRef>>;
|
|
12
3
|
//# sourceMappingURL=MapView.web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapView.web.d.ts","sourceRoot":"","sources":["../../../src/MapView.web.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MapView.web.d.ts","sourceRoot":"","sources":["../../../src/MapView.web.tsx"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EAIX,MAAM,iBAAiB,CAAC;AAyEzB,eAAO,MAAM,OAAO,qGA6LlB,CAAC"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import type { MarkerProps } from './Marker';
|
|
3
|
-
export declare
|
|
4
|
-
render(): import("react/jsx-runtime").JSX.Element;
|
|
5
|
-
}
|
|
2
|
+
export declare function Marker({ coordinate, title, anchor, zIndex, children, }: MarkerProps): import("react/jsx-runtime").JSX.Element;
|
|
6
3
|
//# sourceMappingURL=Marker.web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Marker.web.d.ts","sourceRoot":"","sources":["../../../../src/components/Marker.web.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Marker.web.d.ts","sourceRoot":"","sources":["../../../../src/components/Marker.web.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI5C,wBAAgB,MAAM,CAAC,EACrB,UAAU,EACV,KAAK,EACL,MAAM,EACN,MAAM,EACN,QAAQ,GACT,EAAE,WAAW,2CAYb"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { Component } from 'react';
|
|
2
1
|
import type { PolylineProps } from './Polyline';
|
|
3
|
-
export declare
|
|
4
|
-
render(): import("react/jsx-runtime").JSX.Element;
|
|
5
|
-
}
|
|
2
|
+
export declare function Polyline({ coordinates, strokeColors, strokeWidth, animated, zIndex, }: PolylineProps): null;
|
|
6
3
|
//# sourceMappingURL=Polyline.web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Polyline.web.d.ts","sourceRoot":"","sources":["../../../../src/components/Polyline.web.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Polyline.web.d.ts","sourceRoot":"","sources":["../../../../src/components/Polyline.web.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAkChD,wBAAgB,QAAQ,CAAC,EACvB,WAAW,EACX,YAAY,EACZ,WAAe,EACf,QAAQ,EACR,MAAM,GACP,EAAE,aAAa,QAuKf"}
|
package/package.json
CHANGED
package/src/MapView.web.tsx
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Children,
|
|
3
|
-
|
|
3
|
+
forwardRef,
|
|
4
4
|
isValidElement,
|
|
5
5
|
useEffect,
|
|
6
|
+
useId,
|
|
7
|
+
useImperativeHandle,
|
|
6
8
|
useRef,
|
|
7
9
|
useState,
|
|
8
10
|
type CSSProperties,
|
|
@@ -14,6 +16,7 @@ import { View } from 'react-native';
|
|
|
14
16
|
import { Map, useMap } from '@vis.gl/react-google-maps';
|
|
15
17
|
import { Marker } from './components/Marker.web';
|
|
16
18
|
import { Polyline } from './components/Polyline.web';
|
|
19
|
+
import { MapIdContext } from './MapIdContext.web';
|
|
17
20
|
|
|
18
21
|
import type {
|
|
19
22
|
MapViewProps,
|
|
@@ -24,7 +27,6 @@ import type {
|
|
|
24
27
|
} from './MapView.types';
|
|
25
28
|
import type { Coordinate } from './types';
|
|
26
29
|
|
|
27
|
-
// Map-specific component types that render inside the Google Map
|
|
28
30
|
const MAP_COMPONENT_TYPES = new Set([Marker, Polyline]);
|
|
29
31
|
|
|
30
32
|
const isMapComponent = (child: ReactElement): boolean =>
|
|
@@ -49,17 +51,6 @@ const createSyntheticEvent = <T,>(nativeEvent: T): NativeSyntheticEvent<T> =>
|
|
|
49
51
|
type: '',
|
|
50
52
|
} as unknown as NativeSyntheticEvent<T>);
|
|
51
53
|
|
|
52
|
-
interface MapControllerProps {
|
|
53
|
-
onMapReady: (map: google.maps.Map) => void;
|
|
54
|
-
onCameraMove?: (event: NativeSyntheticEvent<CameraEventPayload>) => void;
|
|
55
|
-
onCameraIdle?: (event: NativeSyntheticEvent<CameraEventPayload>) => void;
|
|
56
|
-
onReady?: () => void;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
interface UserLocationMarkerProps {
|
|
60
|
-
enabled?: boolean;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
54
|
const userLocationDotStyle: CSSProperties = {
|
|
64
55
|
width: 16,
|
|
65
56
|
height: 16,
|
|
@@ -69,7 +60,7 @@ const userLocationDotStyle: CSSProperties = {
|
|
|
69
60
|
boxShadow: '0 1px 4px rgba(0,0,0,0.3)',
|
|
70
61
|
};
|
|
71
62
|
|
|
72
|
-
function UserLocationMarker({ enabled }:
|
|
63
|
+
function UserLocationMarker({ enabled }: { enabled?: boolean }) {
|
|
73
64
|
const [coordinate, setCoordinate] = useState<Coordinate | null>(null);
|
|
74
65
|
|
|
75
66
|
useEffect(() => {
|
|
@@ -106,24 +97,90 @@ function UserLocationMarker({ enabled }: UserLocationMarkerProps) {
|
|
|
106
97
|
);
|
|
107
98
|
}
|
|
108
99
|
|
|
109
|
-
function
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
100
|
+
export const MapView = forwardRef<MapViewRef, MapViewProps>(function MapView(
|
|
101
|
+
props,
|
|
102
|
+
ref
|
|
103
|
+
) {
|
|
104
|
+
const {
|
|
105
|
+
mapId = 'DEMO_MAP_ID',
|
|
106
|
+
initialCoordinate,
|
|
107
|
+
initialZoom = 10,
|
|
108
|
+
minZoom,
|
|
109
|
+
maxZoom,
|
|
110
|
+
zoomEnabled = true,
|
|
111
|
+
scrollEnabled = true,
|
|
112
|
+
pitchEnabled = true,
|
|
113
|
+
padding,
|
|
114
|
+
userLocationEnabled,
|
|
115
|
+
onCameraMove,
|
|
116
|
+
onCameraIdle,
|
|
117
|
+
onReady,
|
|
118
|
+
children,
|
|
119
|
+
style,
|
|
120
|
+
} = props;
|
|
121
|
+
|
|
122
|
+
const id = useId();
|
|
123
|
+
const map = useMap(id);
|
|
116
124
|
const readyFired = useRef(false);
|
|
117
125
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
126
|
+
useImperativeHandle(
|
|
127
|
+
ref,
|
|
128
|
+
() => ({
|
|
129
|
+
moveCamera(coordinate: Coordinate, options: MoveCameraOptions) {
|
|
130
|
+
if (!map) return;
|
|
131
|
+
|
|
132
|
+
const { zoom, duration = -1 } = options;
|
|
133
|
+
const center = { lat: coordinate.latitude, lng: coordinate.longitude };
|
|
134
|
+
|
|
135
|
+
if (duration === 0) {
|
|
136
|
+
map.moveCamera({ center, zoom });
|
|
137
|
+
} else {
|
|
138
|
+
const currentZoom = map.getZoom();
|
|
139
|
+
const zoomChanged = zoom !== undefined && zoom !== currentZoom;
|
|
140
|
+
|
|
141
|
+
if (zoomChanged) {
|
|
142
|
+
map.setZoom(zoom);
|
|
143
|
+
}
|
|
144
|
+
map.panTo(center);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
fitCoordinates(
|
|
149
|
+
coordinates: Coordinate[],
|
|
150
|
+
options?: FitCoordinatesOptions
|
|
151
|
+
) {
|
|
152
|
+
const first = coordinates[0];
|
|
153
|
+
if (!map || !first) return;
|
|
154
|
+
|
|
155
|
+
const { padding: fitPadding, duration = -1 } = options ?? {};
|
|
156
|
+
|
|
157
|
+
if (coordinates.length === 1) {
|
|
158
|
+
this.moveCamera(first, { zoom: initialZoom, duration });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const bounds = new google.maps.LatLngBounds();
|
|
163
|
+
coordinates.forEach((coord) => {
|
|
164
|
+
bounds.extend({ lat: coord.latitude, lng: coord.longitude });
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
map.fitBounds(bounds, {
|
|
168
|
+
top: fitPadding?.top ?? 0,
|
|
169
|
+
left: fitPadding?.left ?? 0,
|
|
170
|
+
bottom: fitPadding?.bottom ?? 0,
|
|
171
|
+
right: fitPadding?.right ?? 0,
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
}),
|
|
175
|
+
[map, initialZoom]
|
|
176
|
+
);
|
|
121
177
|
|
|
122
|
-
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
if (map && !readyFired.current) {
|
|
123
180
|
readyFired.current = true;
|
|
124
181
|
onReady?.();
|
|
125
182
|
}
|
|
126
|
-
}, [map,
|
|
183
|
+
}, [map, onReady]);
|
|
127
184
|
|
|
128
185
|
useEffect(() => {
|
|
129
186
|
if (!map) return;
|
|
@@ -141,9 +198,11 @@ function MapController({
|
|
|
141
198
|
};
|
|
142
199
|
|
|
143
200
|
let isDragging = false;
|
|
201
|
+
let wasGesture = false;
|
|
144
202
|
|
|
145
203
|
const dragStartListener = map.addListener('dragstart', () => {
|
|
146
204
|
isDragging = true;
|
|
205
|
+
wasGesture = true;
|
|
147
206
|
});
|
|
148
207
|
|
|
149
208
|
const dragEndListener = map.addListener('dragend', () => {
|
|
@@ -155,7 +214,8 @@ function MapController({
|
|
|
155
214
|
});
|
|
156
215
|
|
|
157
216
|
const idleListener = map.addListener('idle', () => {
|
|
158
|
-
onCameraIdle?.(createSyntheticEvent(createPayload(
|
|
217
|
+
onCameraIdle?.(createSyntheticEvent(createPayload(wasGesture)));
|
|
218
|
+
wasGesture = false;
|
|
159
219
|
});
|
|
160
220
|
|
|
161
221
|
return () => {
|
|
@@ -166,154 +226,64 @@ function MapController({
|
|
|
166
226
|
};
|
|
167
227
|
}, [map, onCameraMove, onCameraIdle]);
|
|
168
228
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
mapId: 'DEMO_MAP_ID',
|
|
176
|
-
initialZoom: 10,
|
|
177
|
-
zoomEnabled: true,
|
|
178
|
-
scrollEnabled: true,
|
|
179
|
-
rotateEnabled: true,
|
|
180
|
-
pitchEnabled: true,
|
|
181
|
-
};
|
|
229
|
+
const gestureHandling =
|
|
230
|
+
scrollEnabled === false && zoomEnabled === false
|
|
231
|
+
? 'none'
|
|
232
|
+
: scrollEnabled === false
|
|
233
|
+
? 'none'
|
|
234
|
+
: 'auto';
|
|
182
235
|
|
|
183
|
-
|
|
236
|
+
const defaultCenter = initialCoordinate
|
|
237
|
+
? { lat: initialCoordinate.latitude, lng: initialCoordinate.longitude }
|
|
238
|
+
: undefined;
|
|
184
239
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
moveCamera(coordinate: Coordinate, options: MoveCameraOptions) {
|
|
190
|
-
const map = this.mapInstance;
|
|
191
|
-
if (!map) return;
|
|
240
|
+
const mapChildren: ReactNode[] = [];
|
|
241
|
+
const overlayChildren: ReactNode[] = [];
|
|
192
242
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
map.moveCamera({ center, zoom });
|
|
243
|
+
Children.forEach(children, (child) => {
|
|
244
|
+
if (!isValidElement(child)) return;
|
|
245
|
+
if (isMapComponent(child)) {
|
|
246
|
+
mapChildren.push(child);
|
|
198
247
|
} else {
|
|
199
|
-
|
|
200
|
-
const zoomChanged = zoom !== undefined && zoom !== currentZoom;
|
|
201
|
-
|
|
202
|
-
if (zoomChanged) {
|
|
203
|
-
map.setZoom(zoom);
|
|
204
|
-
}
|
|
205
|
-
map.panTo(center);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
fitCoordinates(coordinates: Coordinate[], options?: FitCoordinatesOptions) {
|
|
210
|
-
const map = this.mapInstance;
|
|
211
|
-
const first = coordinates[0];
|
|
212
|
-
if (!map || !first) return;
|
|
213
|
-
|
|
214
|
-
const { padding, duration = -1 } = options ?? {};
|
|
215
|
-
|
|
216
|
-
if (coordinates.length === 1) {
|
|
217
|
-
const zoom = this.props.initialZoom ?? 10;
|
|
218
|
-
this.moveCamera(first, { zoom, duration });
|
|
219
|
-
return;
|
|
248
|
+
overlayChildren.push(child);
|
|
220
249
|
}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
const mapContainerStyle: ViewStyle = {
|
|
253
|
+
position: 'absolute',
|
|
254
|
+
top: padding?.top ?? 0,
|
|
255
|
+
left: padding?.left ?? 0,
|
|
256
|
+
right: padding?.right ?? 0,
|
|
257
|
+
bottom: padding?.bottom ?? 0,
|
|
258
|
+
};
|
|
221
259
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
map.fitBounds(bounds, {
|
|
228
|
-
top: padding?.top ?? 0,
|
|
229
|
-
left: padding?.left ?? 0,
|
|
230
|
-
bottom: padding?.bottom ?? 0,
|
|
231
|
-
right: padding?.right ?? 0,
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
render() {
|
|
236
|
-
const {
|
|
237
|
-
mapId,
|
|
238
|
-
initialCoordinate,
|
|
239
|
-
initialZoom,
|
|
240
|
-
minZoom,
|
|
241
|
-
maxZoom,
|
|
242
|
-
zoomEnabled,
|
|
243
|
-
scrollEnabled,
|
|
244
|
-
pitchEnabled,
|
|
245
|
-
padding,
|
|
246
|
-
userLocationEnabled,
|
|
247
|
-
onCameraMove,
|
|
248
|
-
onCameraIdle,
|
|
249
|
-
onReady,
|
|
250
|
-
children,
|
|
251
|
-
style,
|
|
252
|
-
} = this.props;
|
|
253
|
-
|
|
254
|
-
const gestureHandling =
|
|
255
|
-
scrollEnabled === false && zoomEnabled === false
|
|
256
|
-
? 'none'
|
|
257
|
-
: scrollEnabled === false
|
|
258
|
-
? 'none'
|
|
259
|
-
: 'auto';
|
|
260
|
-
|
|
261
|
-
const defaultCenter = initialCoordinate
|
|
262
|
-
? { lat: initialCoordinate.latitude, lng: initialCoordinate.longitude }
|
|
263
|
-
: undefined;
|
|
264
|
-
|
|
265
|
-
// Separate map children (Marker, Polyline) from overlay children (regular Views)
|
|
266
|
-
const mapChildren: ReactNode[] = [];
|
|
267
|
-
const overlayChildren: ReactNode[] = [];
|
|
268
|
-
|
|
269
|
-
Children.forEach(children, (child) => {
|
|
270
|
-
if (!isValidElement(child)) return;
|
|
271
|
-
if (isMapComponent(child)) {
|
|
272
|
-
mapChildren.push(child);
|
|
273
|
-
} else {
|
|
274
|
-
overlayChildren.push(child);
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
const mapContainerStyle: ViewStyle = {
|
|
279
|
-
position: 'absolute',
|
|
280
|
-
top: padding?.top ?? 0,
|
|
281
|
-
left: padding?.left ?? 0,
|
|
282
|
-
right: padding?.right ?? 0,
|
|
283
|
-
bottom: padding?.bottom ?? 0,
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
const mapStyle: CSSProperties = {
|
|
287
|
-
width: '100%',
|
|
288
|
-
height: '100%',
|
|
289
|
-
};
|
|
260
|
+
const mapStyle: CSSProperties = {
|
|
261
|
+
width: '100%',
|
|
262
|
+
height: '100%',
|
|
263
|
+
};
|
|
290
264
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
onCameraMove={onCameraMove}
|
|
308
|
-
onCameraIdle={onCameraIdle}
|
|
309
|
-
onReady={onReady}
|
|
310
|
-
/>
|
|
265
|
+
return (
|
|
266
|
+
<View style={style}>
|
|
267
|
+
<View style={mapContainerStyle}>
|
|
268
|
+
<Map
|
|
269
|
+
id={id}
|
|
270
|
+
mapId={mapId}
|
|
271
|
+
defaultCenter={defaultCenter}
|
|
272
|
+
defaultZoom={initialZoom}
|
|
273
|
+
minZoom={minZoom}
|
|
274
|
+
maxZoom={maxZoom}
|
|
275
|
+
gestureHandling={gestureHandling}
|
|
276
|
+
disableDefaultUI
|
|
277
|
+
tilt={pitchEnabled === false ? 0 : undefined}
|
|
278
|
+
style={mapStyle}
|
|
279
|
+
>
|
|
280
|
+
<MapIdContext.Provider value={id}>
|
|
311
281
|
<UserLocationMarker enabled={userLocationEnabled} />
|
|
312
282
|
{mapChildren}
|
|
313
|
-
</
|
|
314
|
-
</
|
|
315
|
-
{overlayChildren}
|
|
283
|
+
</MapIdContext.Provider>
|
|
284
|
+
</Map>
|
|
316
285
|
</View>
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
286
|
+
{overlayChildren}
|
|
287
|
+
</View>
|
|
288
|
+
);
|
|
289
|
+
});
|
|
@@ -1,32 +1,24 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { AdvancedMarker } from '@vis.gl/react-google-maps';
|
|
3
2
|
import type { MarkerProps } from './Marker';
|
|
4
3
|
|
|
5
|
-
/**
|
|
6
|
-
* Converts point to % anchor for web.
|
|
7
|
-
* e.g. `0.5` to `-50%`
|
|
8
|
-
*/
|
|
9
4
|
const toWebAnchor = (value: number) => `-${value * 100}%`;
|
|
10
5
|
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
</AdvancedMarker>
|
|
30
|
-
);
|
|
31
|
-
}
|
|
6
|
+
export function Marker({
|
|
7
|
+
coordinate,
|
|
8
|
+
title,
|
|
9
|
+
anchor,
|
|
10
|
+
zIndex,
|
|
11
|
+
children,
|
|
12
|
+
}: MarkerProps) {
|
|
13
|
+
return (
|
|
14
|
+
<AdvancedMarker
|
|
15
|
+
position={{ lat: coordinate.latitude, lng: coordinate.longitude }}
|
|
16
|
+
title={title}
|
|
17
|
+
zIndex={zIndex}
|
|
18
|
+
anchorLeft={anchor ? toWebAnchor(anchor.x) : undefined}
|
|
19
|
+
anchorTop={anchor ? toWebAnchor(anchor.y) : undefined}
|
|
20
|
+
>
|
|
21
|
+
{children}
|
|
22
|
+
</AdvancedMarker>
|
|
23
|
+
);
|
|
32
24
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Component,
|
|
3
|
-
useCallback,
|
|
4
|
-
useEffect,
|
|
5
|
-
useMemo,
|
|
6
|
-
useRef,
|
|
7
|
-
useState,
|
|
8
|
-
} from 'react';
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
9
2
|
import { useMap } from '@vis.gl/react-google-maps';
|
|
3
|
+
import { useMapId } from '../MapIdContext.web';
|
|
10
4
|
import type { PolylineProps } from './Polyline';
|
|
11
5
|
|
|
12
6
|
const ANIMATION_DURATION = 1500;
|
|
@@ -41,7 +35,7 @@ function getGradientColor(colors: string[], position: number): string {
|
|
|
41
35
|
return interpolateColor(colors[index]!, colors[index + 1]!, t);
|
|
42
36
|
}
|
|
43
37
|
|
|
44
|
-
function
|
|
38
|
+
export function Polyline({
|
|
45
39
|
coordinates,
|
|
46
40
|
strokeColors,
|
|
47
41
|
strokeWidth = 1,
|
|
@@ -49,7 +43,8 @@ function PolylineImpl({
|
|
|
49
43
|
zIndex,
|
|
50
44
|
}: PolylineProps) {
|
|
51
45
|
const resolvedZIndex = zIndex ?? (animated ? 1 : 0);
|
|
52
|
-
const
|
|
46
|
+
const mapId = useMapId();
|
|
47
|
+
const map = useMap(mapId);
|
|
53
48
|
const polylinesRef = useRef<google.maps.Polyline[]>([]);
|
|
54
49
|
const animationRef = useRef<number>(0);
|
|
55
50
|
|
|
@@ -214,9 +209,3 @@ function PolylineImpl({
|
|
|
214
209
|
|
|
215
210
|
return null;
|
|
216
211
|
}
|
|
217
|
-
|
|
218
|
-
export class Polyline extends Component<PolylineProps> {
|
|
219
|
-
render() {
|
|
220
|
-
return <PolylineImpl {...this.props} />;
|
|
221
|
-
}
|
|
222
|
-
}
|