expo-gaode-map 1.0.4 → 1.0.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/AndroidManifest.xml +13 -1
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapModule.kt +8 -3
- package/android/src/main/java/expo/modules/gaodemap/modules/LocationManager.kt +25 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerView.kt +2 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/MultiPointView.kt +1 -1
- package/android/src/main/java/expo/modules/gaodemap/services/LocationForegroundService.kt +78 -0
- package/build/ExpoGaodeMapModule.d.ts +33 -0
- package/build/ExpoGaodeMapModule.d.ts.map +1 -1
- package/build/ExpoGaodeMapModule.js +0 -1
- package/build/ExpoGaodeMapModule.js.map +1 -1
- package/build/ExpoGaodeMapView.d.ts +6 -35
- package/build/ExpoGaodeMapView.d.ts.map +1 -1
- package/build/ExpoGaodeMapView.js +25 -92
- package/build/ExpoGaodeMapView.js.map +1 -1
- package/build/components/overlays/Circle.d.ts.map +1 -1
- package/build/components/overlays/Circle.js +7 -0
- package/build/components/overlays/Circle.js.map +1 -1
- package/build/components/overlays/Marker.js +10 -0
- package/build/components/overlays/Marker.js.map +1 -1
- package/build/components/overlays/Polygon.d.ts.map +1 -1
- package/build/components/overlays/Polygon.js +7 -0
- package/build/components/overlays/Polygon.js.map +1 -1
- package/build/components/overlays/Polyline.d.ts.map +1 -1
- package/build/components/overlays/Polyline.js +7 -0
- package/build/components/overlays/Polyline.js.map +1 -1
- package/build/modules/AMapLocation.d.ts +2 -19
- package/build/modules/AMapLocation.d.ts.map +1 -1
- package/build/modules/AMapLocation.js +36 -73
- package/build/modules/AMapLocation.js.map +1 -1
- package/build/types/location.types.d.ts +0 -1
- package/build/types/location.types.d.ts.map +1 -1
- package/build/types/location.types.js.map +1 -1
- package/build/utils/EventManager.d.ts +11 -0
- package/build/utils/EventManager.d.ts.map +1 -0
- package/build/utils/EventManager.js +21 -0
- package/build/utils/EventManager.js.map +1 -0
- package/docs/API.md +39 -5
- package/ios/modules/LocationManager.swift +4 -3
- package/package.json +1 -1
- package/src/ExpoGaodeMapModule.ts +39 -5
- package/src/ExpoGaodeMapView.tsx +30 -137
- package/src/components/overlays/Circle.tsx +8 -0
- package/src/components/overlays/Marker.tsx +11 -0
- package/src/components/overlays/Polygon.tsx +8 -0
- package/src/components/overlays/Polyline.tsx +8 -0
- package/src/modules/AMapLocation.ts +38 -73
- package/src/types/location.types.ts +0 -1
- package/src/utils/EventManager.ts +23 -0
|
@@ -1,12 +1,46 @@
|
|
|
1
|
-
|
|
2
1
|
import { NativeModule, requireNativeModule } from 'expo';
|
|
3
2
|
import type { ExpoGaodeMapModuleEvents } from './ExpoGaodeMap.types';
|
|
4
|
-
|
|
3
|
+
import type { LatLng, CoordinateType } from './types';
|
|
5
4
|
|
|
6
5
|
declare class ExpoGaodeMapModule extends NativeModule<ExpoGaodeMapModuleEvents> {
|
|
7
|
-
//
|
|
8
|
-
|
|
6
|
+
// SDK 初始化
|
|
7
|
+
initSDK(config: { androidKey?: string; iosKey?: string }): void;
|
|
8
|
+
getVersion(): string;
|
|
9
|
+
|
|
10
|
+
// 定位控制
|
|
11
|
+
start(): void;
|
|
12
|
+
stop(): void;
|
|
13
|
+
isStarted(): Promise<boolean>;
|
|
14
|
+
getCurrentLocation(): Promise<any>;
|
|
15
|
+
coordinateConvert(coordinate: LatLng, type: CoordinateType): Promise<LatLng>;
|
|
16
|
+
|
|
17
|
+
// 定位配置
|
|
18
|
+
setLocatingWithReGeocode(isReGeocode: boolean): void;
|
|
19
|
+
setLocationMode(mode: number): void;
|
|
20
|
+
setInterval(interval: number): void;
|
|
21
|
+
setOnceLocation(isOnceLocation: boolean): void;
|
|
22
|
+
setSensorEnable(sensorEnable: boolean): void;
|
|
23
|
+
setWifiScan(wifiScan: boolean): void;
|
|
24
|
+
setGpsFirst(gpsFirst: boolean): void;
|
|
25
|
+
setOnceLocationLatest(onceLocationLatest: boolean): void;
|
|
26
|
+
setGeoLanguage(language: string): void;
|
|
27
|
+
setLocationCacheEnable(locationCacheEnable: boolean): void;
|
|
28
|
+
setHttpTimeOut(httpTimeOut: number): void;
|
|
29
|
+
setDesiredAccuracy(accuracy: number): void;
|
|
30
|
+
setLocationTimeout(timeout: number): void;
|
|
31
|
+
setReGeocodeTimeout(timeout: number): void;
|
|
32
|
+
setDistanceFilter(distance: number): void;
|
|
33
|
+
setPausesLocationUpdatesAutomatically(pauses: boolean): void;
|
|
34
|
+
setAllowsBackgroundLocationUpdates(allows: boolean): void;
|
|
35
|
+
setLocationProtocol(protocol: string): void;
|
|
36
|
+
|
|
37
|
+
// 方向更新 (iOS)
|
|
38
|
+
startUpdatingHeading(): void;
|
|
39
|
+
stopUpdatingHeading(): void;
|
|
40
|
+
|
|
41
|
+
// 权限
|
|
42
|
+
checkLocationPermission(): Promise<any>;
|
|
43
|
+
requestLocationPermission(): Promise<any>;
|
|
9
44
|
}
|
|
10
45
|
|
|
11
|
-
// This call loads the native module object from the JSI.
|
|
12
46
|
export default requireNativeModule<ExpoGaodeMapModule>('ExpoGaodeMap');
|
package/src/ExpoGaodeMapView.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { requireNativeViewManager } from 'expo-modules-core';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
|
|
3
|
+
import { EventManager } from './utils/EventManager';
|
|
4
4
|
import type {
|
|
5
5
|
MapViewProps,
|
|
6
6
|
MapViewRef,
|
|
@@ -14,15 +14,12 @@ import type {
|
|
|
14
14
|
PolygonProps,
|
|
15
15
|
} from './types';
|
|
16
16
|
|
|
17
|
-
// 重新导出 MapViewRef 供外部使用
|
|
18
17
|
export type { MapViewRef } from './types';
|
|
19
18
|
|
|
20
19
|
const NativeView: React.ComponentType<MapViewProps & { ref?: React.Ref<NativeMapViewRef> }> = requireNativeViewManager('ExpoGaodeMap');
|
|
21
20
|
|
|
22
|
-
// 创建 Context 用于子组件访问 MapRef
|
|
23
21
|
export const MapContext = React.createContext<React.RefObject<MapViewRef | null> | null>(null);
|
|
24
22
|
|
|
25
|
-
// Marker 事件管理器
|
|
26
23
|
type MarkerEventCallbacks = {
|
|
27
24
|
onPress?: () => void;
|
|
28
25
|
onDragStart?: () => void;
|
|
@@ -30,104 +27,14 @@ type MarkerEventCallbacks = {
|
|
|
30
27
|
onDragEnd?: (event: { nativeEvent: LatLng }) => void;
|
|
31
28
|
};
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
private callbacks = new Map<string, MarkerEventCallbacks>();
|
|
35
|
-
|
|
36
|
-
register(markerId: string, callbacks: MarkerEventCallbacks) {
|
|
37
|
-
this.callbacks.set(markerId, callbacks);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
unregister(markerId: string) {
|
|
41
|
-
this.callbacks.delete(markerId);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
trigger(markerId: string, eventType: keyof MarkerEventCallbacks, data?: any) {
|
|
45
|
-
const callbacks = this.callbacks.get(markerId);
|
|
46
|
-
if (callbacks && callbacks[eventType]) {
|
|
47
|
-
callbacks[eventType]!(data);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const MarkerEventContext = React.createContext<MarkerEventManager | null>(null);
|
|
53
|
-
|
|
54
|
-
// Circle 事件管理器
|
|
55
|
-
type CircleEventCallbacks = {
|
|
56
|
-
onPress?: () => void;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
class CircleEventManager {
|
|
60
|
-
private callbacks = new Map<string, CircleEventCallbacks>();
|
|
61
|
-
|
|
62
|
-
register(circleId: string, callbacks: CircleEventCallbacks) {
|
|
63
|
-
this.callbacks.set(circleId, callbacks);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
unregister(circleId: string) {
|
|
67
|
-
this.callbacks.delete(circleId);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
trigger(circleId: string, eventType: keyof CircleEventCallbacks) {
|
|
71
|
-
const callbacks = this.callbacks.get(circleId);
|
|
72
|
-
if (callbacks && callbacks[eventType]) {
|
|
73
|
-
callbacks[eventType]!();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export const CircleEventContext = React.createContext<CircleEventManager | null>(null);
|
|
79
|
-
|
|
80
|
-
// Polygon 事件管理器
|
|
81
|
-
type PolygonEventCallbacks = {
|
|
82
|
-
onPress?: () => void;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
class PolygonEventManager {
|
|
86
|
-
private callbacks = new Map<string, PolygonEventCallbacks>();
|
|
87
|
-
|
|
88
|
-
register(polygonId: string, callbacks: PolygonEventCallbacks) {
|
|
89
|
-
this.callbacks.set(polygonId, callbacks);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
unregister(polygonId: string) {
|
|
93
|
-
this.callbacks.delete(polygonId);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
trigger(polygonId: string, eventType: keyof PolygonEventCallbacks) {
|
|
97
|
-
const callbacks = this.callbacks.get(polygonId);
|
|
98
|
-
if (callbacks && callbacks[eventType]) {
|
|
99
|
-
callbacks[eventType]!();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export const PolygonEventContext = React.createContext<PolygonEventManager | null>(null);
|
|
105
|
-
|
|
106
|
-
// Polyline 事件管理器
|
|
107
|
-
type PolylineEventCallbacks = {
|
|
30
|
+
type OverlayEventCallbacks = {
|
|
108
31
|
onPress?: () => void;
|
|
109
32
|
};
|
|
110
33
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.callbacks.set(polylineId, callbacks);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
unregister(polylineId: string) {
|
|
119
|
-
this.callbacks.delete(polylineId);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
trigger(polylineId: string, eventType: keyof PolylineEventCallbacks) {
|
|
123
|
-
const callbacks = this.callbacks.get(polylineId);
|
|
124
|
-
if (callbacks && callbacks[eventType]) {
|
|
125
|
-
callbacks[eventType]!();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export const PolylineEventContext = React.createContext<PolylineEventManager | null>(null);
|
|
34
|
+
export const MarkerEventContext = React.createContext<EventManager<MarkerEventCallbacks> | null>(null);
|
|
35
|
+
export const CircleEventContext = React.createContext<EventManager<OverlayEventCallbacks> | null>(null);
|
|
36
|
+
export const PolygonEventContext = React.createContext<EventManager<OverlayEventCallbacks> | null>(null);
|
|
37
|
+
export const PolylineEventContext = React.createContext<EventManager<OverlayEventCallbacks> | null>(null);
|
|
131
38
|
|
|
132
39
|
/**
|
|
133
40
|
* 高德地图视图组件,提供地图操作API和覆盖物管理功能
|
|
@@ -150,37 +57,29 @@ export const PolylineEventContext = React.createContext<PolylineEventManager | n
|
|
|
150
57
|
const ExpoGaodeMapView = React.forwardRef<MapViewRef, MapViewProps>((props, ref) => {
|
|
151
58
|
const nativeRef = React.useRef<NativeMapViewRef>(null);
|
|
152
59
|
const internalRef = React.useRef<MapViewRef | null>(null);
|
|
153
|
-
const markerEventManager = React.
|
|
154
|
-
const circleEventManager = React.
|
|
155
|
-
const polygonEventManager = React.
|
|
156
|
-
const polylineEventManager = React.
|
|
157
|
-
|
|
158
|
-
// 处理 Marker 事件
|
|
159
|
-
const handleMarkerPress = React.useCallback((event: any) => {
|
|
60
|
+
const markerEventManager = React.useMemo(() => new EventManager<MarkerEventCallbacks>(), []);
|
|
61
|
+
const circleEventManager = React.useMemo(() => new EventManager<OverlayEventCallbacks>(), []);
|
|
62
|
+
const polygonEventManager = React.useMemo(() => new EventManager<OverlayEventCallbacks>(), []);
|
|
63
|
+
const polylineEventManager = React.useMemo(() => new EventManager<OverlayEventCallbacks>(), []);
|
|
64
|
+
const handleMarkerPress = (event: any) => {
|
|
160
65
|
const markerId = event.nativeEvent?.markerId;
|
|
161
|
-
if (markerId)
|
|
162
|
-
markerEventManager.trigger(markerId, 'onPress');
|
|
163
|
-
}
|
|
66
|
+
if (markerId) markerEventManager.trigger(markerId, 'onPress');
|
|
164
67
|
props.onMarkerPress?.(event);
|
|
165
|
-
}
|
|
68
|
+
};
|
|
166
69
|
|
|
167
|
-
const handleMarkerDragStart =
|
|
70
|
+
const handleMarkerDragStart = (event: any) => {
|
|
168
71
|
const markerId = event.nativeEvent?.markerId;
|
|
169
|
-
if (markerId)
|
|
170
|
-
markerEventManager.trigger(markerId, 'onDragStart');
|
|
171
|
-
}
|
|
72
|
+
if (markerId) markerEventManager.trigger(markerId, 'onDragStart');
|
|
172
73
|
props.onMarkerDragStart?.(event);
|
|
173
|
-
}
|
|
74
|
+
};
|
|
174
75
|
|
|
175
|
-
const handleMarkerDrag =
|
|
76
|
+
const handleMarkerDrag = (event: any) => {
|
|
176
77
|
const markerId = event.nativeEvent?.markerId;
|
|
177
|
-
if (markerId)
|
|
178
|
-
markerEventManager.trigger(markerId, 'onDrag');
|
|
179
|
-
}
|
|
78
|
+
if (markerId) markerEventManager.trigger(markerId, 'onDrag');
|
|
180
79
|
props.onMarkerDrag?.(event);
|
|
181
|
-
}
|
|
80
|
+
};
|
|
182
81
|
|
|
183
|
-
const handleMarkerDragEnd =
|
|
82
|
+
const handleMarkerDragEnd = (event: any) => {
|
|
184
83
|
const markerId = event.nativeEvent?.markerId;
|
|
185
84
|
if (markerId) {
|
|
186
85
|
markerEventManager.trigger(markerId, 'onDragEnd', {
|
|
@@ -191,31 +90,25 @@ const ExpoGaodeMapView = React.forwardRef<MapViewRef, MapViewProps>((props, ref)
|
|
|
191
90
|
});
|
|
192
91
|
}
|
|
193
92
|
props.onMarkerDragEnd?.(event);
|
|
194
|
-
}
|
|
93
|
+
};
|
|
195
94
|
|
|
196
|
-
const handleCirclePress =
|
|
95
|
+
const handleCirclePress = (event: any) => {
|
|
197
96
|
const circleId = event.nativeEvent?.circleId;
|
|
198
|
-
if (circleId)
|
|
199
|
-
circleEventManager.trigger(circleId, 'onPress');
|
|
200
|
-
}
|
|
97
|
+
if (circleId) circleEventManager.trigger(circleId, 'onPress');
|
|
201
98
|
props.onCirclePress?.(event);
|
|
202
|
-
}
|
|
99
|
+
};
|
|
203
100
|
|
|
204
|
-
const handlePolygonPress =
|
|
101
|
+
const handlePolygonPress = (event: any) => {
|
|
205
102
|
const polygonId = event.nativeEvent?.polygonId;
|
|
206
|
-
if (polygonId)
|
|
207
|
-
polygonEventManager.trigger(polygonId, 'onPress');
|
|
208
|
-
}
|
|
103
|
+
if (polygonId) polygonEventManager.trigger(polygonId, 'onPress');
|
|
209
104
|
props.onPolygonPress?.(event);
|
|
210
|
-
}
|
|
105
|
+
};
|
|
211
106
|
|
|
212
|
-
const handlePolylinePress =
|
|
107
|
+
const handlePolylinePress = (event: any) => {
|
|
213
108
|
const polylineId = event.nativeEvent?.polylineId;
|
|
214
|
-
if (polylineId)
|
|
215
|
-
polylineEventManager.trigger(polylineId, 'onPress');
|
|
216
|
-
}
|
|
109
|
+
if (polylineId) polylineEventManager.trigger(polylineId, 'onPress');
|
|
217
110
|
props.onPolylinePress?.(event);
|
|
218
|
-
}
|
|
111
|
+
};
|
|
219
112
|
|
|
220
113
|
const apiRef: MapViewRef = React.useMemo(() => ({
|
|
221
114
|
/**
|
|
@@ -45,6 +45,14 @@ export default function Circle(props: CircleProps) {
|
|
|
45
45
|
};
|
|
46
46
|
}, []);
|
|
47
47
|
|
|
48
|
+
React.useEffect(() => {
|
|
49
|
+
if (circleIdRef.current && eventManager) {
|
|
50
|
+
eventManager.register(circleIdRef.current, {
|
|
51
|
+
onPress: props.onPress,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}, [props.onPress]);
|
|
55
|
+
|
|
48
56
|
React.useEffect(() => {
|
|
49
57
|
if (circleIdRef.current && mapRef?.current) {
|
|
50
58
|
mapRef.current.updateCircle(circleIdRef.current, props);
|
|
@@ -59,6 +59,17 @@ function MarkerImperative(props: MarkerProps) {
|
|
|
59
59
|
};
|
|
60
60
|
}, []);
|
|
61
61
|
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
if (markerIdRef.current && eventManager) {
|
|
64
|
+
eventManager.register(markerIdRef.current, {
|
|
65
|
+
onPress: props.onPress,
|
|
66
|
+
onDragStart: props.onDragStart,
|
|
67
|
+
onDrag: props.onDrag,
|
|
68
|
+
onDragEnd: props.onDragEnd,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}, [props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);
|
|
72
|
+
|
|
62
73
|
React.useEffect(() => {
|
|
63
74
|
if (markerIdRef.current && mapRef?.current) {
|
|
64
75
|
const processedProps = { ...props };
|
|
@@ -74,6 +74,14 @@ export default function Polygon(props: PolygonProps) {
|
|
|
74
74
|
};
|
|
75
75
|
}, []);
|
|
76
76
|
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (polygonIdRef.current && eventManager) {
|
|
79
|
+
eventManager.register(polygonIdRef.current, {
|
|
80
|
+
onPress: props.onPress,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}, [props.onPress]);
|
|
84
|
+
|
|
77
85
|
useEffect(() => {
|
|
78
86
|
if (polygonIdRef.current && nativeRef?.current) {
|
|
79
87
|
nativeRef.current.updatePolygon(polygonIdRef.current, {
|
|
@@ -73,5 +73,13 @@ export default function Polyline(props: PolylineProps) {
|
|
|
73
73
|
};
|
|
74
74
|
}, []);
|
|
75
75
|
|
|
76
|
+
React.useEffect(() => {
|
|
77
|
+
if (polylineIdRef.current && eventManager) {
|
|
78
|
+
eventManager.register(polylineIdRef.current, {
|
|
79
|
+
onPress: props.onPress,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, [props.onPress]);
|
|
83
|
+
|
|
76
84
|
return null;
|
|
77
85
|
}
|
|
@@ -11,83 +11,48 @@ import type {
|
|
|
11
11
|
CoordinateType,
|
|
12
12
|
} from '../types';
|
|
13
13
|
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 配置方法映射表
|
|
17
|
+
* @type {Record<keyof LocationOptions, string>}
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
const CONFIG_MAP: Record<keyof LocationOptions, string> = {
|
|
21
|
+
withReGeocode: 'setLocatingWithReGeocode',
|
|
22
|
+
accuracy: 'setDesiredAccuracy',
|
|
23
|
+
mode: 'setLocationMode',
|
|
24
|
+
onceLocation: 'setOnceLocation',
|
|
25
|
+
interval: 'setInterval',
|
|
26
|
+
timeout: 'setLocationTimeout',
|
|
27
|
+
reGeocodeTimeout: 'setReGeocodeTimeout',
|
|
28
|
+
distanceFilter: 'setDistanceFilter',
|
|
29
|
+
sensorEnable: 'setSensorEnable',
|
|
30
|
+
wifiScan: 'setWifiScan',
|
|
31
|
+
gpsFirst: 'setGpsFirst',
|
|
32
|
+
onceLocationLatest: 'setOnceLocationLatest',
|
|
33
|
+
geoLanguage: 'setGeoLanguage',
|
|
34
|
+
allowsBackgroundLocationUpdates: 'setAllowsBackgroundLocationUpdates',
|
|
35
|
+
pausesLocationUpdatesAutomatically: 'setPausesLocationUpdatesAutomatically',
|
|
36
|
+
locationCacheEnable: 'setLocationCacheEnable',
|
|
37
|
+
httpTimeout: 'setHttpTimeOut',
|
|
38
|
+
protocol: 'setLocationProtocol',
|
|
39
|
+
};
|
|
40
|
+
|
|
14
41
|
/**
|
|
15
|
-
*
|
|
42
|
+
* 配置高德地图定位选项
|
|
16
43
|
* @param {LocationOptions} options - 定位配置选项对象
|
|
17
|
-
* @
|
|
18
|
-
* @param {number} [options.accuracy] - 定位精度设置
|
|
19
|
-
* @param {string} [options.mode] - 定位模式
|
|
20
|
-
* @param {boolean} [options.onceLocation] - 是否单次定位
|
|
21
|
-
* @param {number} [options.interval] - 定位间隔(毫秒)
|
|
22
|
-
* @param {number} [options.timeout] - 定位超时时间(毫秒)
|
|
23
|
-
* @param {number} [options.reGeocodeTimeout] - 逆地理编码超时时间(毫秒)
|
|
24
|
-
* @param {number} [options.distanceFilter] - 位置更新最小距离(米)
|
|
25
|
-
* @param {boolean} [options.sensorEnable] - 是否启用传感器
|
|
26
|
-
* @param {boolean} [options.wifiScan] - 是否开启WiFi扫描
|
|
27
|
-
* @param {boolean} [options.gpsFirst] - 是否优先使用GPS
|
|
28
|
-
* @param {boolean} [options.onceLocationLatest] - 是否获取最近3秒内最精确的位置
|
|
29
|
-
* @param {string} [options.geoLanguage] - 地理编码语言
|
|
30
|
-
* @param {boolean} [options.allowsBackgroundLocationUpdates] - 是否允许后台定位
|
|
31
|
-
* @param {boolean} [options.pausesLocationUpdatesAutomatically] - 是否自动暂停定位
|
|
32
|
-
* @param {boolean} [options.locationCacheEnable] - 是否启用定位缓存
|
|
33
|
-
* @param {number} [options.httpTimeout] - 网络请求超时时间(毫秒)
|
|
34
|
-
* @param {string} [options.protocol] - 定位协议
|
|
44
|
+
* @throws {Error} 当传入的配置方法不存在或不可调用时抛出错误
|
|
35
45
|
*/
|
|
36
46
|
export function configure(options: LocationOptions): void {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
if (options.onceLocation !== undefined) {
|
|
47
|
-
ExpoGaodeMapModule.setOnceLocation?.(options.onceLocation);
|
|
48
|
-
}
|
|
49
|
-
if (options.interval !== undefined) {
|
|
50
|
-
ExpoGaodeMapModule.setInterval?.(options.interval);
|
|
51
|
-
}
|
|
52
|
-
if (options.timeout !== undefined) {
|
|
53
|
-
ExpoGaodeMapModule.setLocationTimeout?.(options.timeout);
|
|
54
|
-
}
|
|
55
|
-
if (options.reGeocodeTimeout !== undefined) {
|
|
56
|
-
ExpoGaodeMapModule.setReGeocodeTimeout?.(options.reGeocodeTimeout);
|
|
57
|
-
}
|
|
58
|
-
if (options.distanceFilter !== undefined) {
|
|
59
|
-
ExpoGaodeMapModule.setDistanceFilter?.(options.distanceFilter);
|
|
60
|
-
}
|
|
61
|
-
if (options.sensorEnable !== undefined) {
|
|
62
|
-
ExpoGaodeMapModule.setSensorEnable?.(options.sensorEnable);
|
|
63
|
-
}
|
|
64
|
-
if (options.wifiScan !== undefined) {
|
|
65
|
-
ExpoGaodeMapModule.setWifiScan?.(options.wifiScan);
|
|
66
|
-
}
|
|
67
|
-
if (options.gpsFirst !== undefined) {
|
|
68
|
-
ExpoGaodeMapModule.setGpsFirst?.(options.gpsFirst);
|
|
69
|
-
}
|
|
70
|
-
if (options.onceLocationLatest !== undefined) {
|
|
71
|
-
ExpoGaodeMapModule.setOnceLocationLatest?.(options.onceLocationLatest);
|
|
72
|
-
}
|
|
73
|
-
if (options.geoLanguage !== undefined) {
|
|
74
|
-
ExpoGaodeMapModule.setGeoLanguage?.(options.geoLanguage);
|
|
75
|
-
}
|
|
76
|
-
if (options.allowsBackgroundLocationUpdates !== undefined) {
|
|
77
|
-
ExpoGaodeMapModule.setAllowsBackgroundLocationUpdates?.(options.allowsBackgroundLocationUpdates);
|
|
78
|
-
}
|
|
79
|
-
if (options.pausesLocationUpdatesAutomatically !== undefined) {
|
|
80
|
-
ExpoGaodeMapModule.setPausesLocationUpdatesAutomatically?.(options.pausesLocationUpdatesAutomatically);
|
|
81
|
-
}
|
|
82
|
-
if (options.locationCacheEnable !== undefined) {
|
|
83
|
-
ExpoGaodeMapModule.setLocationCacheEnable?.(options.locationCacheEnable);
|
|
84
|
-
}
|
|
85
|
-
if (options.httpTimeout !== undefined) {
|
|
86
|
-
ExpoGaodeMapModule.setHttpTimeOut?.(options.httpTimeout);
|
|
87
|
-
}
|
|
88
|
-
if (options.protocol !== undefined) {
|
|
89
|
-
ExpoGaodeMapModule.setLocationProtocol?.(options.protocol);
|
|
90
|
-
}
|
|
47
|
+
Object.entries(options).forEach(([key, value]) => {
|
|
48
|
+
if (value !== undefined) {
|
|
49
|
+
const methodName = CONFIG_MAP[key as keyof LocationOptions];
|
|
50
|
+
const method = ExpoGaodeMapModule[methodName as keyof typeof ExpoGaodeMapModule];
|
|
51
|
+
if (typeof method === 'function') {
|
|
52
|
+
(method as any).call(ExpoGaodeMapModule, value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
91
56
|
}
|
|
92
57
|
|
|
93
58
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通用事件管理器
|
|
3
|
+
* 用于管理地图覆盖物的事件回调
|
|
4
|
+
*/
|
|
5
|
+
export class EventManager<T extends Record<string, any>> {
|
|
6
|
+
private callbacks = new Map<string, T>();
|
|
7
|
+
|
|
8
|
+
register(id: string, callbacks: T) {
|
|
9
|
+
this.callbacks.set(id, callbacks);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
unregister(id: string) {
|
|
13
|
+
this.callbacks.delete(id);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
trigger<K extends keyof T>(id: string, eventType: K, data?: any) {
|
|
17
|
+
const callbacks = this.callbacks.get(id);
|
|
18
|
+
const callback = callbacks?.[eventType];
|
|
19
|
+
if (typeof callback === 'function') {
|
|
20
|
+
callback(data);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|