@lugg/maps 0.2.0-alpha.13 → 0.2.0-alpha.15
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.
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { View } from 'react-native';
|
|
3
|
+
import { forwardRef, useEffect, useId, useImperativeHandle, useRef, useState } from 'react';
|
|
4
|
+
import { View, StyleSheet } from 'react-native';
|
|
5
5
|
import { Map, useMap } from '@vis.gl/react-google-maps';
|
|
6
6
|
import { Marker } from "./components/Marker.web.js";
|
|
7
|
-
import { Polyline } from "./components/Polyline.web.js";
|
|
8
7
|
import { MapIdContext } from "./MapProvider.web.js";
|
|
9
8
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
-
const MAP_COMPONENT_TYPES = new Set([Marker, Polyline]);
|
|
11
|
-
const isMapComponent = child => MAP_COMPONENT_TYPES.has(child.type);
|
|
12
9
|
const createSyntheticEvent = nativeEvent => ({
|
|
13
10
|
nativeEvent,
|
|
14
11
|
currentTarget: null,
|
|
@@ -91,6 +88,8 @@ export const MapView = /*#__PURE__*/forwardRef(function MapView(props, ref) {
|
|
|
91
88
|
const id = useId();
|
|
92
89
|
const map = useMap(id);
|
|
93
90
|
const readyFired = useRef(false);
|
|
91
|
+
const isDragging = useRef(false);
|
|
92
|
+
const wasGesture = useRef(false);
|
|
94
93
|
useImperativeHandle(ref, () => ({
|
|
95
94
|
moveCamera(coordinate, options) {
|
|
96
95
|
if (!map) return;
|
|
@@ -151,83 +150,54 @@ export const MapView = /*#__PURE__*/forwardRef(function MapView(props, ref) {
|
|
|
151
150
|
onReady?.();
|
|
152
151
|
}
|
|
153
152
|
}, [map, onReady]);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
153
|
+
const handleDragStart = () => {
|
|
154
|
+
isDragging.current = true;
|
|
155
|
+
wasGesture.current = true;
|
|
156
|
+
};
|
|
157
|
+
const handleDragEnd = () => {
|
|
158
|
+
isDragging.current = false;
|
|
159
|
+
};
|
|
160
|
+
const handleCameraChanged = event => {
|
|
161
|
+
const payload = {
|
|
162
|
+
coordinate: {
|
|
163
|
+
latitude: event.detail.center.lat,
|
|
164
|
+
longitude: event.detail.center.lng
|
|
165
|
+
},
|
|
166
|
+
zoom: event.detail.zoom,
|
|
167
|
+
gesture: isDragging.current
|
|
166
168
|
};
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
});
|
|
179
|
-
const idleListener = map.addListener('idle', () => {
|
|
180
|
-
onCameraIdle?.(createSyntheticEvent(createPayload(wasGesture)));
|
|
181
|
-
wasGesture = false;
|
|
182
|
-
});
|
|
183
|
-
return () => {
|
|
184
|
-
google.maps.event.removeListener(dragStartListener);
|
|
185
|
-
google.maps.event.removeListener(dragEndListener);
|
|
186
|
-
google.maps.event.removeListener(centerListener);
|
|
187
|
-
google.maps.event.removeListener(idleListener);
|
|
169
|
+
onCameraMove?.(createSyntheticEvent(payload));
|
|
170
|
+
};
|
|
171
|
+
const handleIdle = event => {
|
|
172
|
+
const center = event.map.getCenter();
|
|
173
|
+
const payload = {
|
|
174
|
+
coordinate: {
|
|
175
|
+
latitude: center?.lat() ?? 0,
|
|
176
|
+
longitude: center?.lng() ?? 0
|
|
177
|
+
},
|
|
178
|
+
zoom: event.map.getZoom() ?? 0,
|
|
179
|
+
gesture: wasGesture.current
|
|
188
180
|
};
|
|
189
|
-
|
|
181
|
+
onCameraIdle?.(createSyntheticEvent(payload));
|
|
182
|
+
wasGesture.current = false;
|
|
183
|
+
};
|
|
190
184
|
const gestureHandling = scrollEnabled === false && zoomEnabled === false ? 'none' : scrollEnabled === false ? 'cooperative' : 'auto';
|
|
191
185
|
const defaultCenter = initialCoordinate ? {
|
|
192
186
|
lat: initialCoordinate.latitude,
|
|
193
187
|
lng: initialCoordinate.longitude
|
|
194
188
|
} : undefined;
|
|
195
|
-
const {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const overlayNodes = [];
|
|
201
|
-
Children.forEach(children, child => {
|
|
202
|
-
if (! /*#__PURE__*/isValidElement(child)) return;
|
|
203
|
-
if (isMapComponent(child)) {
|
|
204
|
-
mapNodes.push(child);
|
|
205
|
-
} else {
|
|
206
|
-
overlayNodes.push(child);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
return {
|
|
210
|
-
mapChildren: mapNodes,
|
|
211
|
-
overlayChildren: overlayNodes
|
|
212
|
-
};
|
|
213
|
-
}, [children]);
|
|
214
|
-
const mapContainerStyle = {
|
|
215
|
-
position: 'absolute',
|
|
216
|
-
top: padding?.top ?? 0,
|
|
217
|
-
left: padding?.left ?? 0,
|
|
218
|
-
right: padding?.right ?? 0,
|
|
219
|
-
bottom: padding?.bottom ?? 0
|
|
220
|
-
};
|
|
221
|
-
const mapStyle = {
|
|
222
|
-
width: '100%',
|
|
223
|
-
height: '100%'
|
|
189
|
+
const paddingStyle = {
|
|
190
|
+
paddingTop: padding?.top ?? 0,
|
|
191
|
+
paddingLeft: padding?.left ?? 0,
|
|
192
|
+
paddingRight: padding?.right ?? 0,
|
|
193
|
+
paddingBottom: padding?.bottom ?? 0
|
|
224
194
|
};
|
|
225
195
|
return /*#__PURE__*/_jsx(MapIdContext.Provider, {
|
|
226
196
|
value: id,
|
|
227
|
-
children: /*#__PURE__*/
|
|
197
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
228
198
|
style: style,
|
|
229
|
-
children:
|
|
230
|
-
style:
|
|
199
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
200
|
+
style: [StyleSheet.absoluteFill, paddingStyle],
|
|
231
201
|
children: /*#__PURE__*/_jsxs(Map, {
|
|
232
202
|
id: id,
|
|
233
203
|
mapId: mapId,
|
|
@@ -237,13 +207,17 @@ export const MapView = /*#__PURE__*/forwardRef(function MapView(props, ref) {
|
|
|
237
207
|
maxZoom: maxZoom,
|
|
238
208
|
gestureHandling: gestureHandling,
|
|
239
209
|
disableDefaultUI: true,
|
|
210
|
+
isFractionalZoomEnabled: true,
|
|
240
211
|
tilt: pitchEnabled === false ? 0 : undefined,
|
|
241
|
-
|
|
212
|
+
onDragstart: handleDragStart,
|
|
213
|
+
onDragend: handleDragEnd,
|
|
214
|
+
onCameraChanged: handleCameraChanged,
|
|
215
|
+
onIdle: handleIdle,
|
|
242
216
|
children: [/*#__PURE__*/_jsx(UserLocationMarker, {
|
|
243
217
|
enabled: userLocationEnabled
|
|
244
|
-
}),
|
|
218
|
+
}), children]
|
|
245
219
|
})
|
|
246
|
-
})
|
|
220
|
+
})
|
|
247
221
|
})
|
|
248
222
|
});
|
|
249
223
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["forwardRef","useEffect","useId","useImperativeHandle","useRef","useState","View","StyleSheet","Map","useMap","Marker","MapIdContext","jsx","_jsx","jsxs","_jsxs","createSyntheticEvent","nativeEvent","currentTarget","target","bubbles","cancelable","defaultPrevented","eventPhase","isTrusted","preventDefault","stopPropagation","isDefaultPrevented","isPropagationStopped","persist","timeStamp","Date","now","type","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","google","maps","DEMO_MAP_ID","initialCoordinate","initialZoom","minZoom","maxZoom","zoomEnabled","scrollEnabled","pitchEnabled","padding","userLocationEnabled","onCameraMove","onCameraIdle","onReady","id","map","readyFired","isDragging","wasGesture","moveCamera","options","zoom","duration","center","lat","lng","currentZoom","getZoom","zoomChanged","undefined","setZoom","panTo","fitCoordinates","coordinates","first","fitPadding","length","bounds","LatLngBounds","forEach","coord","extend","fitBounds","top","left","bottom","right","current","handleDragStart","handleDragEnd","handleCameraChanged","event","payload","detail","gesture","handleIdle","getCenter","gestureHandling","defaultCenter","paddingStyle","paddingTop","paddingLeft","paddingRight","paddingBottom","Provider","value","absoluteFill","defaultZoom","disableDefaultUI","isFractionalZoomEnabled","tilt","onDragstart","onDragend","onCameraChanged","onIdle"],"sourceRoot":"../../src","sources":["MapView.web.tsx"],"mappings":";;AAAA,SACEA,UAAU,EACVC,SAAS,EACTC,KAAK,EACLC,mBAAmB,EACnBC,MAAM,EACNC,QAAQ,QAEH,OAAO;AAEd,SAASC,IAAI,EAAEC,UAAU,QAAQ,cAAc;AAC/C,SACEC,GAAG,EACHC,MAAM,QAGD,2BAA2B;AAClC,SAASC,MAAM,QAAQ,4BAAyB;AAChD,SAASC,YAAY,QAAQ,sBAAmB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAWjD,MAAMC,oBAAoB,GAAQC,WAAc,KAC7C;EACCA,WAAW;EACXC,aAAa,EAAE,IAAI;EACnBC,MAAM,EAAE,IAAI;EACZC,OAAO,EAAE,KAAK;EACdC,UAAU,EAAE,KAAK;EACjBC,gBAAgB,EAAE,KAAK;EACvBC,UAAU,EAAE,CAAC;EACbC,SAAS,EAAE,IAAI;EACfC,cAAc,EAAEA,CAAA,KAAM,CAAC,CAAC;EACxBC,eAAe,EAAEA,CAAA,KAAM,CAAC,CAAC;EACzBC,kBAAkB,EAAEA,CAAA,KAAM,KAAK;EAC/BC,oBAAoB,EAAEA,CAAA,KAAM,KAAK;EACjCC,OAAO,EAAEA,CAAA,KAAM,CAAC,CAAC;EACjBC,SAAS,EAAEC,IAAI,CAACC,GAAG,CAAC,CAAC;EACrBC,IAAI,EAAE;AAC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,SAAU;UAC7C0C,WAAW,EAAEvB,eAAgB;UAC7BwB,SAAS,EAAEvB,aAAc;UACzBwB,eAAe,EAAEvB,mBAAoB;UACrCwB,MAAM,EAAEnB,UAAW;UAAA9D,QAAA,gBAEnB9C,IAAA,CAAC4B,kBAAkB;YAACC,OAAO,EAAEkC;UAAoB,CAAE,CAAC,EACnDjB,QAAQ;QAAA,CACN;MAAC,CACF;IAAC,CACH;EAAC,CACc,CAAC;AAE5B,CAAC,CAAC","ignoreList":[]}
|
|
@@ -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;AAoEzB,eAAO,MAAM,OAAO,qGAuKlB,CAAC"}
|
package/package.json
CHANGED
package/src/MapView.web.tsx
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Children,
|
|
3
2
|
forwardRef,
|
|
4
|
-
isValidElement,
|
|
5
3
|
useEffect,
|
|
6
4
|
useId,
|
|
7
5
|
useImperativeHandle,
|
|
8
|
-
useMemo,
|
|
9
6
|
useRef,
|
|
10
7
|
useState,
|
|
11
8
|
type CSSProperties,
|
|
12
|
-
type ReactElement,
|
|
13
|
-
type ReactNode,
|
|
14
9
|
} from 'react';
|
|
15
10
|
import type { NativeSyntheticEvent, ViewStyle } from 'react-native';
|
|
16
|
-
import { View } from 'react-native';
|
|
17
|
-
import {
|
|
11
|
+
import { View, StyleSheet } from 'react-native';
|
|
12
|
+
import {
|
|
13
|
+
Map,
|
|
14
|
+
useMap,
|
|
15
|
+
type MapCameraChangedEvent,
|
|
16
|
+
type MapEvent,
|
|
17
|
+
} from '@vis.gl/react-google-maps';
|
|
18
18
|
import { Marker } from './components/Marker.web';
|
|
19
|
-
import { Polyline } from './components/Polyline.web';
|
|
20
19
|
import { MapIdContext } from './MapProvider.web';
|
|
21
20
|
|
|
22
21
|
import type {
|
|
@@ -28,11 +27,6 @@ import type {
|
|
|
28
27
|
} from './MapView.types';
|
|
29
28
|
import type { Coordinate } from './types';
|
|
30
29
|
|
|
31
|
-
const MAP_COMPONENT_TYPES = new Set([Marker, Polyline]);
|
|
32
|
-
|
|
33
|
-
const isMapComponent = (child: ReactElement): boolean =>
|
|
34
|
-
MAP_COMPONENT_TYPES.has(child.type as typeof Marker | typeof Polyline);
|
|
35
|
-
|
|
36
30
|
const createSyntheticEvent = <T,>(nativeEvent: T): NativeSyntheticEvent<T> =>
|
|
37
31
|
({
|
|
38
32
|
nativeEvent,
|
|
@@ -123,6 +117,8 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>(function MapView(
|
|
|
123
117
|
const id = useId();
|
|
124
118
|
const map = useMap(id);
|
|
125
119
|
const readyFired = useRef(false);
|
|
120
|
+
const isDragging = useRef(false);
|
|
121
|
+
const wasGesture = useRef(false);
|
|
126
122
|
|
|
127
123
|
useImperativeHandle(
|
|
128
124
|
ref,
|
|
@@ -183,49 +179,40 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>(function MapView(
|
|
|
183
179
|
}
|
|
184
180
|
}, [map, onReady]);
|
|
185
181
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const center = map.getCenter();
|
|
191
|
-
return {
|
|
192
|
-
coordinate: {
|
|
193
|
-
latitude: center?.lat() ?? 0,
|
|
194
|
-
longitude: center?.lng() ?? 0,
|
|
195
|
-
},
|
|
196
|
-
zoom: map.getZoom() ?? 0,
|
|
197
|
-
gesture,
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
let isDragging = false;
|
|
202
|
-
let wasGesture = false;
|
|
203
|
-
|
|
204
|
-
const dragStartListener = map.addListener('dragstart', () => {
|
|
205
|
-
isDragging = true;
|
|
206
|
-
wasGesture = true;
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
const dragEndListener = map.addListener('dragend', () => {
|
|
210
|
-
isDragging = false;
|
|
211
|
-
});
|
|
182
|
+
const handleDragStart = () => {
|
|
183
|
+
isDragging.current = true;
|
|
184
|
+
wasGesture.current = true;
|
|
185
|
+
};
|
|
212
186
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
187
|
+
const handleDragEnd = () => {
|
|
188
|
+
isDragging.current = false;
|
|
189
|
+
};
|
|
216
190
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
191
|
+
const handleCameraChanged = (event: MapCameraChangedEvent) => {
|
|
192
|
+
const payload: CameraEventPayload = {
|
|
193
|
+
coordinate: {
|
|
194
|
+
latitude: event.detail.center.lat,
|
|
195
|
+
longitude: event.detail.center.lng,
|
|
196
|
+
},
|
|
197
|
+
zoom: event.detail.zoom,
|
|
198
|
+
gesture: isDragging.current,
|
|
199
|
+
};
|
|
200
|
+
onCameraMove?.(createSyntheticEvent(payload));
|
|
201
|
+
};
|
|
221
202
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
203
|
+
const handleIdle = (event: MapEvent) => {
|
|
204
|
+
const center = event.map.getCenter();
|
|
205
|
+
const payload: CameraEventPayload = {
|
|
206
|
+
coordinate: {
|
|
207
|
+
latitude: center?.lat() ?? 0,
|
|
208
|
+
longitude: center?.lng() ?? 0,
|
|
209
|
+
},
|
|
210
|
+
zoom: event.map.getZoom() ?? 0,
|
|
211
|
+
gesture: wasGesture.current,
|
|
227
212
|
};
|
|
228
|
-
|
|
213
|
+
onCameraIdle?.(createSyntheticEvent(payload));
|
|
214
|
+
wasGesture.current = false;
|
|
215
|
+
};
|
|
229
216
|
|
|
230
217
|
const gestureHandling =
|
|
231
218
|
scrollEnabled === false && zoomEnabled === false
|
|
@@ -238,39 +225,17 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>(function MapView(
|
|
|
238
225
|
? { lat: initialCoordinate.latitude, lng: initialCoordinate.longitude }
|
|
239
226
|
: undefined;
|
|
240
227
|
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (!isValidElement(child)) return;
|
|
247
|
-
if (isMapComponent(child)) {
|
|
248
|
-
mapNodes.push(child);
|
|
249
|
-
} else {
|
|
250
|
-
overlayNodes.push(child);
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
return { mapChildren: mapNodes, overlayChildren: overlayNodes };
|
|
255
|
-
}, [children]);
|
|
256
|
-
|
|
257
|
-
const mapContainerStyle: ViewStyle = {
|
|
258
|
-
position: 'absolute',
|
|
259
|
-
top: padding?.top ?? 0,
|
|
260
|
-
left: padding?.left ?? 0,
|
|
261
|
-
right: padding?.right ?? 0,
|
|
262
|
-
bottom: padding?.bottom ?? 0,
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
const mapStyle: CSSProperties = {
|
|
266
|
-
width: '100%',
|
|
267
|
-
height: '100%',
|
|
228
|
+
const paddingStyle: ViewStyle = {
|
|
229
|
+
paddingTop: padding?.top ?? 0,
|
|
230
|
+
paddingLeft: padding?.left ?? 0,
|
|
231
|
+
paddingRight: padding?.right ?? 0,
|
|
232
|
+
paddingBottom: padding?.bottom ?? 0,
|
|
268
233
|
};
|
|
269
234
|
|
|
270
235
|
return (
|
|
271
236
|
<MapIdContext.Provider value={id}>
|
|
272
237
|
<View style={style}>
|
|
273
|
-
<View style={
|
|
238
|
+
<View style={[StyleSheet.absoluteFill, paddingStyle]}>
|
|
274
239
|
<Map
|
|
275
240
|
id={id}
|
|
276
241
|
mapId={mapId}
|
|
@@ -280,14 +245,17 @@ export const MapView = forwardRef<MapViewRef, MapViewProps>(function MapView(
|
|
|
280
245
|
maxZoom={maxZoom}
|
|
281
246
|
gestureHandling={gestureHandling}
|
|
282
247
|
disableDefaultUI
|
|
248
|
+
isFractionalZoomEnabled
|
|
283
249
|
tilt={pitchEnabled === false ? 0 : undefined}
|
|
284
|
-
|
|
250
|
+
onDragstart={handleDragStart}
|
|
251
|
+
onDragend={handleDragEnd}
|
|
252
|
+
onCameraChanged={handleCameraChanged}
|
|
253
|
+
onIdle={handleIdle}
|
|
285
254
|
>
|
|
286
255
|
<UserLocationMarker enabled={userLocationEnabled} />
|
|
287
|
-
{
|
|
256
|
+
{children}
|
|
288
257
|
</Map>
|
|
289
258
|
</View>
|
|
290
|
-
{overlayChildren}
|
|
291
259
|
</View>
|
|
292
260
|
</MapIdContext.Provider>
|
|
293
261
|
);
|