@lugg/maps 0.2.0-alpha.7 → 0.2.0-alpha.9
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,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { Children, Component, isValidElement, useEffect, 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";
|
|
@@ -26,6 +26,50 @@ const createSyntheticEvent = nativeEvent => ({
|
|
|
26
26
|
timeStamp: Date.now(),
|
|
27
27
|
type: ''
|
|
28
28
|
});
|
|
29
|
+
const userLocationDotStyle = {
|
|
30
|
+
width: 16,
|
|
31
|
+
height: 16,
|
|
32
|
+
backgroundColor: '#4285F4',
|
|
33
|
+
border: '2px solid white',
|
|
34
|
+
borderRadius: '50%',
|
|
35
|
+
boxShadow: '0 1px 4px rgba(0,0,0,0.3)'
|
|
36
|
+
};
|
|
37
|
+
function UserLocationMarker({
|
|
38
|
+
enabled
|
|
39
|
+
}) {
|
|
40
|
+
const [coordinate, setCoordinate] = useState(null);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!enabled) {
|
|
43
|
+
setCoordinate(null);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let watchId = null;
|
|
47
|
+
const updateLocation = position => {
|
|
48
|
+
setCoordinate({
|
|
49
|
+
latitude: position.coords.latitude,
|
|
50
|
+
longitude: position.coords.longitude
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
navigator.geolocation.getCurrentPosition(updateLocation, () => {});
|
|
54
|
+
watchId = navigator.geolocation.watchPosition(updateLocation, () => {});
|
|
55
|
+
return () => {
|
|
56
|
+
if (watchId !== null) {
|
|
57
|
+
navigator.geolocation.clearWatch(watchId);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}, [enabled]);
|
|
61
|
+
if (!coordinate) return null;
|
|
62
|
+
return /*#__PURE__*/_jsx(Marker, {
|
|
63
|
+
coordinate: coordinate,
|
|
64
|
+
anchor: {
|
|
65
|
+
x: 0.5,
|
|
66
|
+
y: 0.5
|
|
67
|
+
},
|
|
68
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
69
|
+
style: userLocationDotStyle
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
}
|
|
29
73
|
function MapController({
|
|
30
74
|
onMapReady,
|
|
31
75
|
onCameraMove,
|
|
@@ -33,8 +77,8 @@ function MapController({
|
|
|
33
77
|
onReady
|
|
34
78
|
}) {
|
|
35
79
|
const map = useMap();
|
|
36
|
-
const readyFired =
|
|
37
|
-
|
|
80
|
+
const readyFired = useRef(false);
|
|
81
|
+
useEffect(() => {
|
|
38
82
|
if (!map) return;
|
|
39
83
|
onMapReady(map);
|
|
40
84
|
if (!readyFired.current) {
|
|
@@ -42,7 +86,7 @@ function MapController({
|
|
|
42
86
|
onReady?.();
|
|
43
87
|
}
|
|
44
88
|
}, [map, onMapReady, onReady]);
|
|
45
|
-
|
|
89
|
+
useEffect(() => {
|
|
46
90
|
if (!map) return;
|
|
47
91
|
const createPayload = gesture => {
|
|
48
92
|
const center = map.getCenter();
|
|
@@ -77,9 +121,10 @@ function MapController({
|
|
|
77
121
|
}, [map, onCameraMove, onCameraIdle]);
|
|
78
122
|
return null;
|
|
79
123
|
}
|
|
80
|
-
export class MapView extends
|
|
124
|
+
export class MapView extends Component {
|
|
81
125
|
static defaultProps = {
|
|
82
126
|
provider: 'google',
|
|
127
|
+
mapId: 'DEMO_MAP_ID',
|
|
83
128
|
initialZoom: 10,
|
|
84
129
|
zoomEnabled: true,
|
|
85
130
|
scrollEnabled: true,
|
|
@@ -101,11 +146,11 @@ export class MapView extends React.Component {
|
|
|
101
146
|
lat: coordinate.latitude,
|
|
102
147
|
lng: coordinate.longitude
|
|
103
148
|
};
|
|
104
|
-
if (duration
|
|
105
|
-
map.
|
|
149
|
+
if (duration === 0) {
|
|
150
|
+
map.setCenter(center);
|
|
106
151
|
map.setZoom(zoom);
|
|
107
152
|
} else {
|
|
108
|
-
map.
|
|
153
|
+
map.panTo(center);
|
|
109
154
|
map.setZoom(zoom);
|
|
110
155
|
}
|
|
111
156
|
}
|
|
@@ -150,6 +195,7 @@ export class MapView extends React.Component {
|
|
|
150
195
|
scrollEnabled,
|
|
151
196
|
pitchEnabled,
|
|
152
197
|
padding,
|
|
198
|
+
userLocationEnabled,
|
|
153
199
|
onCameraMove,
|
|
154
200
|
onCameraIdle,
|
|
155
201
|
onReady,
|
|
@@ -165,8 +211,8 @@ export class MapView extends React.Component {
|
|
|
165
211
|
// Separate map children (Marker, Polyline) from overlay children (regular Views)
|
|
166
212
|
const mapChildren = [];
|
|
167
213
|
const overlayChildren = [];
|
|
168
|
-
|
|
169
|
-
if (! /*#__PURE__*/
|
|
214
|
+
Children.forEach(children, child => {
|
|
215
|
+
if (! /*#__PURE__*/isValidElement(child)) return;
|
|
170
216
|
if (isMapComponent(child)) {
|
|
171
217
|
mapChildren.push(child);
|
|
172
218
|
} else {
|
|
@@ -203,6 +249,8 @@ export class MapView extends React.Component {
|
|
|
203
249
|
onCameraMove: onCameraMove,
|
|
204
250
|
onCameraIdle: onCameraIdle,
|
|
205
251
|
onReady: onReady
|
|
252
|
+
}), /*#__PURE__*/_jsx(UserLocationMarker, {
|
|
253
|
+
enabled: userLocationEnabled
|
|
206
254
|
}), mapChildren]
|
|
207
255
|
})
|
|
208
256
|
}), overlayChildren]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["Children","Component","isValidElement","useEffect","useRef","useState","View","Map","useMap","Marker","Polyline","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","MapController","onMapReady","onCameraMove","onCameraIdle","onReady","map","readyFired","current","createPayload","gesture","center","getCenter","lat","lng","zoom","getZoom","isDragging","dragStartListener","addListener","dragEndListener","centerListener","idleListener","google","maps","event","removeListener","MapView","defaultProps","provider","mapId","initialZoom","zoomEnabled","scrollEnabled","rotateEnabled","pitchEnabled","mapInstance","handleMapReady","moveCamera","options","duration","setCenter","setZoom","panTo","fitCoordinates","coordinates","first","padding","length","props","bounds","LatLngBounds","forEach","coord","extend","fitBounds","top","left","bottom","right","render","initialCoordinate","minZoom","maxZoom","userLocationEnabled","gestureHandling","defaultCenter","undefined","mapChildren","overlayChildren","push","mapContainerStyle","mapStyle","defaultZoom","disableDefaultUI","tilt"],"sourceRoot":"../../src","sources":["MapView.web.tsx"],"mappings":";;AAAA,SACEA,QAAQ,EACRC,SAAS,EACTC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,QAAQ,QAIH,OAAO;AAEd,SAASC,IAAI,QAAQ,cAAc;AACnC,SAASC,GAAG,EAAEC,MAAM,QAAQ,2BAA2B;AACvD,SAASC,MAAM,QAAQ,4BAAyB;AAChD,SAASC,QAAQ,QAAQ,8BAA2B;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAWrD;AACA,MAAMC,mBAAmB,GAAG,IAAIC,GAAG,CAAC,CAACP,MAAM,EAAEC,QAAQ,CAAC,CAAC;AAEvD,MAAMO,cAAc,GAAIC,KAAmB,IACzCH,mBAAmB,CAACI,GAAG,CAACD,KAAK,CAACE,IAAuC,CAAC;AAExE,MAAMC,oBAAoB,GAAQC,WAAc,KAC7C;EACCA,WAAW;EACXC,aAAa,E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Y,EAAEA,YAAa;YAC3BC,YAAY,EAAEA,YAAa;YAC3BC,OAAO,EAAEA;UAAQ,CAClB,CAAC,eACFzD,IAAA,CAACiC,kBAAkB;YAACC,OAAO,EAAEkF;UAAoB,CAAE,CAAC,EACnDI,WAAW;QAAA,CACT;MAAC,CACF,CAAC,EACNC,eAAe;IAAA,CACZ,CAAC;EAEX;AACF","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Component } from 'react';
|
|
2
2
|
import type { MapViewProps, MapViewRef, MoveCameraOptions, FitCoordinatesOptions } from './MapView.types';
|
|
3
3
|
import type { Coordinate } from './types';
|
|
4
|
-
export declare class MapView extends
|
|
4
|
+
export declare class MapView extends Component<MapViewProps> implements MapViewRef {
|
|
5
5
|
static defaultProps: Partial<MapViewProps>;
|
|
6
6
|
private mapInstance;
|
|
7
7
|
private handleMapReady;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapView.web.d.ts","sourceRoot":"","sources":["../../../src/MapView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"MapView.web.d.ts","sourceRoot":"","sources":["../../../src/MapView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EAQV,MAAM,OAAO,CAAC;AAOf,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EAEtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAmJ1C,qBAAa,OAAQ,SAAQ,SAAS,CAAC,YAAY,CAAE,YAAW,UAAU;IACxE,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,CAQxC;IAEF,OAAO,CAAC,WAAW,CAAgC;IAEnD,OAAO,CAAC,cAAc,CAEpB;IAEF,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,iBAAiB;IAgB7D,cAAc,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,qBAAqB;IA0BzE,MAAM;CAoFP"}
|
package/package.json
CHANGED
package/src/MapView.web.tsx
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
Component,
|
|
4
|
+
isValidElement,
|
|
5
|
+
useEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type CSSProperties,
|
|
9
|
+
type ReactElement,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
} from 'react';
|
|
2
12
|
import type { NativeSyntheticEvent, ViewStyle } from 'react-native';
|
|
3
13
|
import { View } from 'react-native';
|
|
4
14
|
import { Map, useMap } from '@vis.gl/react-google-maps';
|
|
@@ -17,7 +27,7 @@ import type { Coordinate } from './types';
|
|
|
17
27
|
// Map-specific component types that render inside the Google Map
|
|
18
28
|
const MAP_COMPONENT_TYPES = new Set([Marker, Polyline]);
|
|
19
29
|
|
|
20
|
-
const isMapComponent = (child:
|
|
30
|
+
const isMapComponent = (child: ReactElement): boolean =>
|
|
21
31
|
MAP_COMPONENT_TYPES.has(child.type as typeof Marker | typeof Polyline);
|
|
22
32
|
|
|
23
33
|
const createSyntheticEvent = <T,>(nativeEvent: T): NativeSyntheticEvent<T> =>
|
|
@@ -46,6 +56,56 @@ interface MapControllerProps {
|
|
|
46
56
|
onReady?: () => void;
|
|
47
57
|
}
|
|
48
58
|
|
|
59
|
+
interface UserLocationMarkerProps {
|
|
60
|
+
enabled?: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const userLocationDotStyle: CSSProperties = {
|
|
64
|
+
width: 16,
|
|
65
|
+
height: 16,
|
|
66
|
+
backgroundColor: '#4285F4',
|
|
67
|
+
border: '2px solid white',
|
|
68
|
+
borderRadius: '50%',
|
|
69
|
+
boxShadow: '0 1px 4px rgba(0,0,0,0.3)',
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
function UserLocationMarker({ enabled }: UserLocationMarkerProps) {
|
|
73
|
+
const [coordinate, setCoordinate] = useState<Coordinate | null>(null);
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!enabled) {
|
|
77
|
+
setCoordinate(null);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let watchId: number | null = null;
|
|
82
|
+
|
|
83
|
+
const updateLocation = (position: GeolocationPosition) => {
|
|
84
|
+
setCoordinate({
|
|
85
|
+
latitude: position.coords.latitude,
|
|
86
|
+
longitude: position.coords.longitude,
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
navigator.geolocation.getCurrentPosition(updateLocation, () => {});
|
|
91
|
+
watchId = navigator.geolocation.watchPosition(updateLocation, () => {});
|
|
92
|
+
|
|
93
|
+
return () => {
|
|
94
|
+
if (watchId !== null) {
|
|
95
|
+
navigator.geolocation.clearWatch(watchId);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}, [enabled]);
|
|
99
|
+
|
|
100
|
+
if (!coordinate) return null;
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<Marker coordinate={coordinate} anchor={{ x: 0.5, y: 0.5 }}>
|
|
104
|
+
<div style={userLocationDotStyle} />
|
|
105
|
+
</Marker>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
49
109
|
function MapController({
|
|
50
110
|
onMapReady,
|
|
51
111
|
onCameraMove,
|
|
@@ -53,9 +113,9 @@ function MapController({
|
|
|
53
113
|
onReady,
|
|
54
114
|
}: MapControllerProps) {
|
|
55
115
|
const map = useMap();
|
|
56
|
-
const readyFired =
|
|
116
|
+
const readyFired = useRef(false);
|
|
57
117
|
|
|
58
|
-
|
|
118
|
+
useEffect(() => {
|
|
59
119
|
if (!map) return;
|
|
60
120
|
onMapReady(map);
|
|
61
121
|
|
|
@@ -65,7 +125,7 @@ function MapController({
|
|
|
65
125
|
}
|
|
66
126
|
}, [map, onMapReady, onReady]);
|
|
67
127
|
|
|
68
|
-
|
|
128
|
+
useEffect(() => {
|
|
69
129
|
if (!map) return;
|
|
70
130
|
|
|
71
131
|
const createPayload = (gesture: boolean): CameraEventPayload => {
|
|
@@ -109,12 +169,10 @@ function MapController({
|
|
|
109
169
|
return null;
|
|
110
170
|
}
|
|
111
171
|
|
|
112
|
-
export class MapView
|
|
113
|
-
extends React.Component<MapViewProps>
|
|
114
|
-
implements MapViewRef
|
|
115
|
-
{
|
|
172
|
+
export class MapView extends Component<MapViewProps> implements MapViewRef {
|
|
116
173
|
static defaultProps: Partial<MapViewProps> = {
|
|
117
174
|
provider: 'google',
|
|
175
|
+
mapId: 'DEMO_MAP_ID',
|
|
118
176
|
initialZoom: 10,
|
|
119
177
|
zoomEnabled: true,
|
|
120
178
|
scrollEnabled: true,
|
|
@@ -135,11 +193,11 @@ export class MapView
|
|
|
135
193
|
const { zoom, duration = -1 } = options;
|
|
136
194
|
const center = { lat: coordinate.latitude, lng: coordinate.longitude };
|
|
137
195
|
|
|
138
|
-
if (duration
|
|
139
|
-
map.
|
|
196
|
+
if (duration === 0) {
|
|
197
|
+
map.setCenter(center);
|
|
140
198
|
map.setZoom(zoom);
|
|
141
199
|
} else {
|
|
142
|
-
map.
|
|
200
|
+
map.panTo(center);
|
|
143
201
|
map.setZoom(zoom);
|
|
144
202
|
}
|
|
145
203
|
}
|
|
@@ -181,6 +239,7 @@ export class MapView
|
|
|
181
239
|
scrollEnabled,
|
|
182
240
|
pitchEnabled,
|
|
183
241
|
padding,
|
|
242
|
+
userLocationEnabled,
|
|
184
243
|
onCameraMove,
|
|
185
244
|
onCameraIdle,
|
|
186
245
|
onReady,
|
|
@@ -200,11 +259,11 @@ export class MapView
|
|
|
200
259
|
: undefined;
|
|
201
260
|
|
|
202
261
|
// Separate map children (Marker, Polyline) from overlay children (regular Views)
|
|
203
|
-
const mapChildren:
|
|
204
|
-
const overlayChildren:
|
|
262
|
+
const mapChildren: ReactNode[] = [];
|
|
263
|
+
const overlayChildren: ReactNode[] = [];
|
|
205
264
|
|
|
206
|
-
|
|
207
|
-
if (!
|
|
265
|
+
Children.forEach(children, (child) => {
|
|
266
|
+
if (!isValidElement(child)) return;
|
|
208
267
|
if (isMapComponent(child)) {
|
|
209
268
|
mapChildren.push(child);
|
|
210
269
|
} else {
|
|
@@ -220,7 +279,7 @@ export class MapView
|
|
|
220
279
|
bottom: padding?.bottom ?? 0,
|
|
221
280
|
};
|
|
222
281
|
|
|
223
|
-
const mapStyle:
|
|
282
|
+
const mapStyle: CSSProperties = {
|
|
224
283
|
width: '100%',
|
|
225
284
|
height: '100%',
|
|
226
285
|
};
|
|
@@ -245,6 +304,7 @@ export class MapView
|
|
|
245
304
|
onCameraIdle={onCameraIdle}
|
|
246
305
|
onReady={onReady}
|
|
247
306
|
/>
|
|
307
|
+
<UserLocationMarker enabled={userLocationEnabled} />
|
|
248
308
|
{mapChildren}
|
|
249
309
|
</Map>
|
|
250
310
|
</View>
|