expo-gaode-map 1.1.7 → 2.0.0-alpha.1
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/README.en.md +32 -46
- package/README.md +51 -71
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapView.kt +37 -237
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapViewModule.kt +1 -49
- package/android/src/main/java/expo/modules/gaodemap/managers/CameraManager.kt +30 -7
- package/android/src/main/java/expo/modules/gaodemap/managers/UIManager.kt +1 -0
- package/android/src/main/java/expo/modules/gaodemap/modules/LocationManager.kt +10 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleView.kt +38 -14
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleViewModule.kt +3 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/ClusterView.kt +8 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/HeatMapView.kt +4 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerView.kt +322 -93
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerViewModule.kt +11 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/MultiPointView.kt +4 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonView.kt +25 -11
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonViewModule.kt +3 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineView.kt +20 -10
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineViewModule.kt +6 -2
- package/build/ExpoGaodeMap.types.d.ts +27 -6
- package/build/ExpoGaodeMap.types.d.ts.map +1 -1
- package/build/ExpoGaodeMap.types.js +3 -0
- package/build/ExpoGaodeMap.types.js.map +1 -1
- package/build/ExpoGaodeMapModule.d.ts +157 -10
- package/build/ExpoGaodeMapModule.d.ts.map +1 -1
- package/build/ExpoGaodeMapModule.js +4 -0
- package/build/ExpoGaodeMapModule.js.map +1 -1
- package/build/ExpoGaodeMapView.d.ts +1 -17
- package/build/ExpoGaodeMapView.d.ts.map +1 -1
- package/build/ExpoGaodeMapView.js +4 -209
- package/build/ExpoGaodeMapView.js.map +1 -1
- package/build/components/overlays/Circle.d.ts +10 -1
- package/build/components/overlays/Circle.d.ts.map +1 -1
- package/build/components/overlays/Circle.js +11 -86
- package/build/components/overlays/Circle.js.map +1 -1
- package/build/components/overlays/Cluster.d.ts.map +1 -1
- package/build/components/overlays/Cluster.js.map +1 -1
- package/build/components/overlays/Marker.d.ts +13 -1
- package/build/components/overlays/Marker.d.ts.map +1 -1
- package/build/components/overlays/Marker.js +51 -115
- package/build/components/overlays/Marker.js.map +1 -1
- package/build/components/overlays/Polygon.d.ts +7 -15
- package/build/components/overlays/Polygon.d.ts.map +1 -1
- package/build/components/overlays/Polygon.js +10 -80
- package/build/components/overlays/Polygon.js.map +1 -1
- package/build/components/overlays/Polyline.d.ts +7 -14
- package/build/components/overlays/Polyline.d.ts.map +1 -1
- package/build/components/overlays/Polyline.js +9 -66
- package/build/components/overlays/Polyline.js.map +1 -1
- package/build/index.d.ts +1 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -10
- package/build/index.js.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/index.js.map +1 -1
- package/build/types/map-view.types.d.ts +0 -76
- package/build/types/map-view.types.d.ts.map +1 -1
- package/build/types/map-view.types.js.map +1 -1
- package/build/types/overlays.types.d.ts +11 -16
- package/build/types/overlays.types.d.ts.map +1 -1
- package/build/types/overlays.types.js.map +1 -1
- package/docs/API.en.md +1 -21
- package/docs/API.md +84 -56
- package/docs/EXAMPLES.en.md +0 -48
- package/docs/EXAMPLES.md +49 -102
- package/docs/INITIALIZATION.md +59 -71
- package/docs/MIGRATION.md +423 -0
- package/ios/ExpoGaodeMapView.swift +317 -258
- package/ios/ExpoGaodeMapViewModule.swift +3 -50
- package/ios/managers/CameraManager.swift +23 -2
- package/ios/managers/UIManager.swift +10 -5
- package/ios/modules/LocationManager.swift +10 -0
- package/ios/overlays/CircleView.swift +98 -19
- package/ios/overlays/CircleViewModule.swift +21 -0
- package/ios/overlays/ClusterView.swift +33 -4
- package/ios/overlays/HeatMapView.swift +16 -4
- package/ios/overlays/MarkerView.swift +235 -146
- package/ios/overlays/MarkerViewModule.swift +7 -3
- package/ios/overlays/MultiPointView.swift +30 -1
- package/ios/overlays/PolygonView.swift +63 -12
- package/ios/overlays/PolygonViewModule.swift +17 -0
- package/ios/overlays/PolylineView.swift +95 -25
- package/ios/overlays/PolylineViewModule.swift +17 -8
- package/ios/utils/PermissionManager.swift +9 -14
- package/package.json +4 -3
- package/src/ExpoGaodeMap.types.ts +28 -3
- package/src/ExpoGaodeMapModule.ts +201 -12
- package/src/ExpoGaodeMapView.tsx +11 -225
- package/src/components/overlays/Circle.tsx +12 -104
- package/src/components/overlays/Cluster.tsx +0 -1
- package/src/components/overlays/Marker.tsx +63 -138
- package/src/components/overlays/Polygon.tsx +12 -92
- package/src/components/overlays/Polyline.tsx +11 -77
- package/src/index.ts +4 -29
- package/src/types/index.ts +1 -1
- package/src/types/map-view.types.ts +1 -69
- package/src/types/overlays.types.ts +11 -16
- package/android/src/main/java/expo/modules/gaodemap/managers/OverlayManager.kt +0 -574
- package/build/modules/AMapLocation.d.ts +0 -78
- package/build/modules/AMapLocation.d.ts.map +0 -1
- package/build/modules/AMapLocation.js +0 -132
- package/build/modules/AMapLocation.js.map +0 -1
- package/build/modules/AMapPermissions.d.ts +0 -29
- package/build/modules/AMapPermissions.d.ts.map +0 -1
- package/build/modules/AMapPermissions.js +0 -23
- package/build/modules/AMapPermissions.js.map +0 -1
- package/build/modules/AMapSDK.d.ts +0 -22
- package/build/modules/AMapSDK.d.ts.map +0 -1
- package/build/modules/AMapSDK.js +0 -25
- package/build/modules/AMapSDK.js.map +0 -1
- package/build/modules/AMapView.d.ts +0 -44
- package/build/modules/AMapView.d.ts.map +0 -1
- package/build/modules/AMapView.js +0 -65
- package/build/modules/AMapView.js.map +0 -1
- package/ios/managers/OverlayManager.swift +0 -522
- package/src/modules/AMapLocation.ts +0 -165
- package/src/modules/AMapPermissions.ts +0 -41
- package/src/modules/AMapSDK.ts +0 -31
- package/src/modules/AMapView.ts +0 -72
- package/test/ClockMapView.tsx +0 -532
- package/test/useMap.ts +0 -1360
|
@@ -1,46 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 高德地图原生模块
|
|
3
|
+
* 提供 SDK 初始化、定位、权限管理等功能
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import { NativeModule, requireNativeModule } from 'expo';
|
|
2
7
|
import type { ExpoGaodeMapModuleEvents } from './ExpoGaodeMap.types';
|
|
3
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
LatLng,
|
|
10
|
+
CoordinateType,
|
|
11
|
+
Coordinates,
|
|
12
|
+
ReGeocode,
|
|
13
|
+
LocationMode,
|
|
14
|
+
LocationAccuracy,
|
|
15
|
+
} from './types';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* SDK 配置参数
|
|
19
|
+
*/
|
|
20
|
+
export interface SDKConfig {
|
|
21
|
+
/** Android 平台的高德地图 API Key */
|
|
22
|
+
androidKey?: string;
|
|
23
|
+
/** iOS 平台的高德地图 API Key */
|
|
24
|
+
iosKey?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 权限状态
|
|
29
|
+
*/
|
|
30
|
+
export interface PermissionStatus {
|
|
31
|
+
/** 是否已授权 */
|
|
32
|
+
granted: boolean;
|
|
33
|
+
/** iOS 权限状态字符串 */
|
|
34
|
+
status?: 'notDetermined' | 'restricted' | 'denied' | 'authorizedAlways' | 'authorizedWhenInUse' | 'unknown';
|
|
35
|
+
/** Android 精确位置权限 */
|
|
36
|
+
fineLocation?: boolean;
|
|
37
|
+
/** Android 粗略位置权限 */
|
|
38
|
+
coarseLocation?: boolean;
|
|
39
|
+
}
|
|
4
40
|
|
|
41
|
+
/**
|
|
42
|
+
* 高德地图原生模块类声明
|
|
43
|
+
*/
|
|
5
44
|
declare class ExpoGaodeMapModule extends NativeModule<ExpoGaodeMapModuleEvents> {
|
|
6
|
-
// SDK 初始化
|
|
7
|
-
|
|
45
|
+
// ==================== SDK 初始化 ====================
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 初始化高德地图 SDK
|
|
49
|
+
* @param config SDK 配置参数,包含 Android 和 iOS 的 API Key
|
|
50
|
+
*/
|
|
51
|
+
initSDK(config: SDKConfig): void;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 获取高德地图 SDK 版本号
|
|
55
|
+
* @returns SDK 版本字符串
|
|
56
|
+
*/
|
|
8
57
|
getVersion(): string;
|
|
9
58
|
|
|
10
|
-
// 定位控制
|
|
59
|
+
// ==================== 定位控制 ====================
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 开始连续定位
|
|
63
|
+
* 启动后会持续接收位置更新,通过 onLocationUpdate 事件回调
|
|
64
|
+
*/
|
|
11
65
|
start(): void;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 停止定位
|
|
69
|
+
* 停止接收位置更新
|
|
70
|
+
*/
|
|
12
71
|
stop(): void;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 检查是否正在定位
|
|
75
|
+
* @returns Promise<boolean> 是否正在定位
|
|
76
|
+
*/
|
|
13
77
|
isStarted(): Promise<boolean>;
|
|
14
|
-
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 获取当前位置(单次定位)
|
|
81
|
+
* @returns Promise<Coordinates | ReGeocode> 位置信息,包含坐标和可选的逆地理编码信息
|
|
82
|
+
*/
|
|
83
|
+
getCurrentLocation(): Promise<Coordinates | ReGeocode>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 坐标转换
|
|
87
|
+
* 将其他坐标系的坐标转换为高德地图使用的 GCJ-02 坐标系
|
|
88
|
+
* @param coordinate 需要转换的坐标
|
|
89
|
+
* @param type 原坐标系类型
|
|
90
|
+
* @returns Promise<LatLng> 转换后的 GCJ-02 坐标
|
|
91
|
+
*/
|
|
15
92
|
coordinateConvert(coordinate: LatLng, type: CoordinateType): Promise<LatLng>;
|
|
16
93
|
|
|
17
|
-
// 定位配置
|
|
94
|
+
// ==================== 定位配置 ====================
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 设置是否返回逆地理编码信息
|
|
98
|
+
* @param isReGeocode true: 返回地址信息; false: 只返回坐标
|
|
99
|
+
*/
|
|
18
100
|
setLocatingWithReGeocode(isReGeocode: boolean): void;
|
|
19
|
-
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 设置定位模式(Android)
|
|
104
|
+
* @param mode 定位模式:0-低功耗, 1-仅设备, 2-高精度
|
|
105
|
+
*/
|
|
106
|
+
setLocationMode(mode: LocationMode): void;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 设置定位间隔(毫秒)
|
|
110
|
+
* @param interval 定位间隔时间,单位毫秒,默认 2000ms
|
|
111
|
+
*/
|
|
20
112
|
setInterval(interval: number): void;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 设置是否单次定位(Android)
|
|
116
|
+
* @param isOnceLocation true: 单次定位; false: 连续定位
|
|
117
|
+
*/
|
|
21
118
|
setOnceLocation(isOnceLocation: boolean): void;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 设置是否使用设备传感器(Android)
|
|
122
|
+
* @param sensorEnable true: 使用传感器; false: 不使用
|
|
123
|
+
*/
|
|
22
124
|
setSensorEnable(sensorEnable: boolean): void;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 设置是否允许 WiFi 扫描(Android)
|
|
128
|
+
* @param wifiScan true: 允许; false: 不允许
|
|
129
|
+
*/
|
|
23
130
|
setWifiScan(wifiScan: boolean): void;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 设置是否 GPS 优先(Android)
|
|
134
|
+
* @param gpsFirst true: GPS 优先; false: 网络优先
|
|
135
|
+
*/
|
|
24
136
|
setGpsFirst(gpsFirst: boolean): void;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 设置是否等待 WiFi 列表刷新(Android)
|
|
140
|
+
* @param onceLocationLatest true: 等待; false: 不等待
|
|
141
|
+
*/
|
|
25
142
|
setOnceLocationLatest(onceLocationLatest: boolean): void;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 设置逆地理编码语言
|
|
146
|
+
* @param language 语言代码,如 "zh-CN", "en"
|
|
147
|
+
*/
|
|
26
148
|
setGeoLanguage(language: string): void;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 设置是否使用缓存策略(Android)
|
|
152
|
+
* @param locationCacheEnable true: 使用缓存; false: 不使用
|
|
153
|
+
*/
|
|
27
154
|
setLocationCacheEnable(locationCacheEnable: boolean): void;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 设置网络请求超时时间(Android)
|
|
158
|
+
* @param httpTimeOut 超时时间,单位毫秒
|
|
159
|
+
*/
|
|
28
160
|
setHttpTimeOut(httpTimeOut: number): void;
|
|
29
|
-
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 设置期望的定位精度(iOS)
|
|
164
|
+
* @param accuracy 精度级别:0-最佳, 1-10米, 2-100米, 3-1公里, 4-3公里
|
|
165
|
+
*/
|
|
166
|
+
setDesiredAccuracy(accuracy: LocationAccuracy): void;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 设置定位超时时间(秒)
|
|
170
|
+
* @param timeout 超时时间,单位秒,默认 10 秒
|
|
171
|
+
*/
|
|
30
172
|
setLocationTimeout(timeout: number): void;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 设置逆地理编码超时时间(秒)
|
|
176
|
+
* @param timeout 超时时间,单位秒,默认 5 秒
|
|
177
|
+
*/
|
|
31
178
|
setReGeocodeTimeout(timeout: number): void;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 设置距离过滤器(米)(iOS)
|
|
182
|
+
* 只有移动超过指定距离才会更新位置
|
|
183
|
+
* @param distance 距离阈值,单位米
|
|
184
|
+
*/
|
|
32
185
|
setDistanceFilter(distance: number): void;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 设置是否自动暂停位置更新(iOS)
|
|
189
|
+
* @param pauses true: 自动暂停; false: 不暂停
|
|
190
|
+
*/
|
|
33
191
|
setPausesLocationUpdatesAutomatically(pauses: boolean): void;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* 设置是否允许后台定位(iOS)
|
|
195
|
+
* @param allows true: 允许; false: 不允许
|
|
196
|
+
*/
|
|
34
197
|
setAllowsBackgroundLocationUpdates(allows: boolean): void;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 设置定位协议
|
|
201
|
+
* @param protocol 协议类型
|
|
202
|
+
*/
|
|
35
203
|
setLocationProtocol(protocol: string): void;
|
|
36
204
|
|
|
37
|
-
// 方向更新 (iOS)
|
|
205
|
+
// ==================== 方向更新 (iOS) ====================
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* 开始更新设备方向(罗盘朝向)
|
|
209
|
+
* 通过 onHeadingUpdate 事件接收方向更新
|
|
210
|
+
* @platform ios
|
|
211
|
+
*/
|
|
38
212
|
startUpdatingHeading(): void;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 停止更新设备方向
|
|
216
|
+
* @platform ios
|
|
217
|
+
*/
|
|
39
218
|
stopUpdatingHeading(): void;
|
|
40
219
|
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
220
|
+
// ==================== 权限管理 ====================
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 检查位置权限状态
|
|
224
|
+
* @returns Promise<PermissionStatus> 权限状态
|
|
225
|
+
*/
|
|
226
|
+
checkLocationPermission(): Promise<PermissionStatus>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* 请求位置权限
|
|
230
|
+
* @returns Promise<PermissionStatus> 请求后的权限状态
|
|
231
|
+
*/
|
|
232
|
+
requestLocationPermission(): Promise<PermissionStatus>;
|
|
44
233
|
}
|
|
45
234
|
|
|
46
235
|
export default requireNativeModule<ExpoGaodeMapModule>('ExpoGaodeMap');
|
package/src/ExpoGaodeMapView.tsx
CHANGED
|
@@ -1,41 +1,20 @@
|
|
|
1
1
|
import { requireNativeViewManager } from 'expo-modules-core';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
import { EventManager } from './utils/EventManager';
|
|
3
|
+
|
|
5
4
|
import type {
|
|
6
5
|
MapViewProps,
|
|
7
6
|
MapViewRef,
|
|
8
|
-
NativeMapViewRef,
|
|
9
7
|
CameraPosition,
|
|
10
8
|
LatLng,
|
|
11
9
|
Point,
|
|
12
|
-
|
|
13
|
-
MarkerProps,
|
|
14
|
-
PolylineProps,
|
|
15
|
-
PolygonProps,
|
|
10
|
+
|
|
16
11
|
} from './types';
|
|
17
12
|
|
|
18
13
|
export type { MapViewRef } from './types';
|
|
19
14
|
|
|
20
|
-
const NativeView: React.ComponentType<MapViewProps & { ref?: React.Ref<
|
|
21
|
-
|
|
22
|
-
export const MapContext = React.createContext<React.RefObject<MapViewRef | null> | null>(null);
|
|
15
|
+
const NativeView: React.ComponentType<MapViewProps & { ref?: React.Ref<MapViewRef> }> = requireNativeViewManager('ExpoGaodeMapView');
|
|
23
16
|
|
|
24
|
-
type MarkerEventCallbacks = {
|
|
25
|
-
onPress?: (event: NativeSyntheticEvent<{}>) => void;
|
|
26
|
-
onDragStart?: (event: NativeSyntheticEvent<LatLng>) => void;
|
|
27
|
-
onDrag?: (event: NativeSyntheticEvent<LatLng>) => void;
|
|
28
|
-
onDragEnd?: (event: NativeSyntheticEvent<LatLng>) => void;
|
|
29
|
-
};
|
|
30
17
|
|
|
31
|
-
type OverlayEventCallbacks = {
|
|
32
|
-
onPress?: (event: NativeSyntheticEvent<{}>) => void;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const MarkerEventContext = React.createContext<EventManager<MarkerEventCallbacks> | null>(null);
|
|
36
|
-
export const CircleEventContext = React.createContext<EventManager<OverlayEventCallbacks> | null>(null);
|
|
37
|
-
export const PolygonEventContext = React.createContext<EventManager<OverlayEventCallbacks> | null>(null);
|
|
38
|
-
export const PolylineEventContext = React.createContext<EventManager<OverlayEventCallbacks> | null>(null);
|
|
39
18
|
|
|
40
19
|
/**
|
|
41
20
|
* 高德地图视图组件,提供地图操作API和覆盖物管理功能
|
|
@@ -56,55 +35,9 @@ export const PolylineEventContext = React.createContext<EventManager<OverlayEven
|
|
|
56
35
|
* 所有API方法都会检查地图是否已初始化,未初始化时抛出错误
|
|
57
36
|
*/
|
|
58
37
|
const ExpoGaodeMapView = React.forwardRef<MapViewRef, MapViewProps>((props, ref) => {
|
|
59
|
-
const nativeRef = React.useRef<
|
|
38
|
+
const nativeRef = React.useRef<MapViewRef>(null);
|
|
60
39
|
const internalRef = React.useRef<MapViewRef | null>(null);
|
|
61
|
-
const markerEventManager = React.useMemo(() => new EventManager<MarkerEventCallbacks>(), []);
|
|
62
|
-
const circleEventManager = React.useMemo(() => new EventManager<OverlayEventCallbacks>(), []);
|
|
63
|
-
const polygonEventManager = React.useMemo(() => new EventManager<OverlayEventCallbacks>(), []);
|
|
64
|
-
const polylineEventManager = React.useMemo(() => new EventManager<OverlayEventCallbacks>(), []);
|
|
65
|
-
const handleMarkerPress = (event: any) => {
|
|
66
|
-
const markerId = event.nativeEvent?.markerId;
|
|
67
|
-
if (markerId) markerEventManager.trigger(markerId, 'onPress', event);
|
|
68
|
-
props.onMarkerPress?.(event);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const handleMarkerDragStart = (event: any) => {
|
|
72
|
-
const markerId = event.nativeEvent?.markerId;
|
|
73
|
-
if (markerId) markerEventManager.trigger(markerId, 'onDragStart', event);
|
|
74
|
-
props.onMarkerDragStart?.(event);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const handleMarkerDrag = (event: any) => {
|
|
78
|
-
const markerId = event.nativeEvent?.markerId;
|
|
79
|
-
if (markerId) markerEventManager.trigger(markerId, 'onDrag', event);
|
|
80
|
-
props.onMarkerDrag?.(event);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const handleMarkerDragEnd = (event: any) => {
|
|
84
|
-
const markerId = event.nativeEvent?.markerId;
|
|
85
|
-
if (markerId) {
|
|
86
|
-
markerEventManager.trigger(markerId, 'onDragEnd', event);
|
|
87
|
-
}
|
|
88
|
-
props.onMarkerDragEnd?.(event);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const handleCirclePress = (event: any) => {
|
|
92
|
-
const circleId = event.nativeEvent?.circleId;
|
|
93
|
-
if (circleId) circleEventManager.trigger(circleId, 'onPress', event);
|
|
94
|
-
props.onCirclePress?.(event);
|
|
95
|
-
};
|
|
96
40
|
|
|
97
|
-
const handlePolygonPress = (event: any) => {
|
|
98
|
-
const polygonId = event.nativeEvent?.polygonId;
|
|
99
|
-
if (polygonId) polygonEventManager.trigger(polygonId, 'onPress', event);
|
|
100
|
-
props.onPolygonPress?.(event);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const handlePolylinePress = (event: any) => {
|
|
104
|
-
const polylineId = event.nativeEvent?.polylineId;
|
|
105
|
-
if (polylineId) polylineEventManager.trigger(polylineId, 'onPress', event);
|
|
106
|
-
props.onPolylinePress?.(event);
|
|
107
|
-
};
|
|
108
41
|
|
|
109
42
|
const apiRef: MapViewRef = React.useMemo(() => ({
|
|
110
43
|
/**
|
|
@@ -156,137 +89,8 @@ const ExpoGaodeMapView = React.forwardRef<MapViewRef, MapViewProps>((props, ref)
|
|
|
156
89
|
getCameraPosition: async () => {
|
|
157
90
|
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
158
91
|
return nativeRef.current.getCameraPosition();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
* 在地图上添加圆形覆盖物
|
|
162
|
-
* @param id - 圆形覆盖物的唯一标识符
|
|
163
|
-
* @param props - 圆形覆盖物的属性配置
|
|
164
|
-
* @returns Promise<void> 添加操作的异步结果
|
|
165
|
-
* @throws 如果地图视图未初始化,抛出错误'MapView not initialized'
|
|
166
|
-
*/
|
|
167
|
-
addCircle: async (id: string, props: CircleProps) => {
|
|
168
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
169
|
-
return nativeRef.current.addCircle(id, props);
|
|
170
|
-
},
|
|
171
|
-
/**
|
|
172
|
-
* 从地图上移除指定的圆形覆盖物
|
|
173
|
-
* @param id - 要移除的圆形覆盖物的唯一标识符
|
|
174
|
-
* @throws 如果地图视图未初始化,抛出错误
|
|
175
|
-
* @returns Promise<void> 异步操作完成
|
|
176
|
-
*/
|
|
177
|
-
removeCircle: async (id: string) => {
|
|
178
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
179
|
-
return nativeRef.current.removeCircle(id);
|
|
180
|
-
},
|
|
181
|
-
/**
|
|
182
|
-
* 更新地图上的圆形覆盖物
|
|
183
|
-
* @param id 要更新的圆形覆盖物的唯一标识符
|
|
184
|
-
* @param props 要更新的圆形属性(部分属性)
|
|
185
|
-
* @throws 如果地图视图未初始化,抛出错误
|
|
186
|
-
* @returns Promise<void> 表示更新操作完成
|
|
187
|
-
*/
|
|
188
|
-
updateCircle: async (id: string, props: Partial<CircleProps>) => {
|
|
189
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
190
|
-
return nativeRef.current.updateCircle(id, props);
|
|
191
|
-
},
|
|
192
|
-
/**
|
|
193
|
-
* 添加一个标记点到地图上
|
|
194
|
-
* @param id 标记点的唯一标识符
|
|
195
|
-
* @param props 标记点的配置属性
|
|
196
|
-
* @returns Promise<void> 添加操作完成后的Promise
|
|
197
|
-
* @throws 如果地图视图未初始化则抛出错误
|
|
198
|
-
*/
|
|
199
|
-
addMarker: async (id: string, props: MarkerProps) => {
|
|
200
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
201
|
-
return nativeRef.current.addMarker(id, props);
|
|
202
|
-
},
|
|
203
|
-
/**
|
|
204
|
-
* 从地图上移除指定ID的标记点
|
|
205
|
-
* @param id 要移除的标记点ID
|
|
206
|
-
* @throws 如果地图视图未初始化则抛出错误
|
|
207
|
-
* @returns Promise<void> 异步操作完成
|
|
208
|
-
*/
|
|
209
|
-
removeMarker: async (id: string) => {
|
|
210
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
211
|
-
return nativeRef.current.removeMarker(id);
|
|
212
|
-
},
|
|
213
|
-
/**
|
|
214
|
-
* 更新地图上指定ID的标记点属性
|
|
215
|
-
* @param id - 要更新的标记点唯一标识符
|
|
216
|
-
* @param props - 需要更新的标记点属性对象(部分属性)
|
|
217
|
-
* @throws 如果地图视图未初始化则抛出错误
|
|
218
|
-
* @returns Promise对象,表示异步更新操作
|
|
219
|
-
*/
|
|
220
|
-
updateMarker: async (id: string, props: Partial<MarkerProps>) => {
|
|
221
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
222
|
-
return nativeRef.current.updateMarker(id, props);
|
|
223
|
-
},
|
|
224
|
-
/**
|
|
225
|
-
* 添加折线覆盖物到地图
|
|
226
|
-
* @param id - 折线的唯一标识符
|
|
227
|
-
* @param props - 折线的配置属性
|
|
228
|
-
* @returns Promise<void> 添加操作的异步结果
|
|
229
|
-
* @throws 如果地图视图未初始化则抛出错误
|
|
230
|
-
*/
|
|
231
|
-
addPolyline: async (id: string, props: PolylineProps) => {
|
|
232
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
233
|
-
return nativeRef.current.addPolyline(id, props);
|
|
234
|
-
},
|
|
235
|
-
/**
|
|
236
|
-
* 移除地图上的指定折线
|
|
237
|
-
* @param id - 要移除的折线的唯一标识符
|
|
238
|
-
* @throws 如果地图视图未初始化,抛出错误
|
|
239
|
-
* @returns Promise<void>
|
|
240
|
-
*/
|
|
241
|
-
removePolyline: async (id: string) => {
|
|
242
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
243
|
-
return nativeRef.current.removePolyline(id);
|
|
244
|
-
},
|
|
245
|
-
/**
|
|
246
|
-
* 更新地图上的折线覆盖物
|
|
247
|
-
*
|
|
248
|
-
* @param id 要更新的折线覆盖物的唯一标识符
|
|
249
|
-
* @param props 要更新的折线属性,包含部分PolylineProps属性
|
|
250
|
-
* @returns Promise<void> 异步操作结果
|
|
251
|
-
* @throws 如果地图视图未初始化,抛出错误
|
|
252
|
-
*/
|
|
253
|
-
updatePolyline: async (id: string, props: Partial<PolylineProps>) => {
|
|
254
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
255
|
-
return nativeRef.current.updatePolyline(id, props);
|
|
256
|
-
},
|
|
257
|
-
/**
|
|
258
|
-
* 向地图添加多边形覆盖物
|
|
259
|
-
* @param id - 多边形的唯一标识符
|
|
260
|
-
* @param props - 多边形的配置属性
|
|
261
|
-
* @returns Promise<void> 添加操作的异步结果
|
|
262
|
-
* @throws 如果地图视图未初始化则抛出错误
|
|
263
|
-
*/
|
|
264
|
-
addPolygon: async (id: string, props: PolygonProps) => {
|
|
265
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
266
|
-
return nativeRef.current.addPolygon(id, props);
|
|
267
|
-
},
|
|
268
|
-
/**
|
|
269
|
-
* 移除地图上的多边形覆盖物
|
|
270
|
-
* @param id - 要移除的多边形覆盖物的唯一标识符
|
|
271
|
-
* @throws 如果地图视图未初始化,抛出错误 'MapView not initialized'
|
|
272
|
-
* @returns Promise<void> 异步操作完成
|
|
273
|
-
*/
|
|
274
|
-
removePolygon: async (id: string) => {
|
|
275
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
276
|
-
return nativeRef.current.removePolygon(id);
|
|
277
|
-
},
|
|
278
|
-
/**
|
|
279
|
-
* 更新多边形覆盖物的属性
|
|
280
|
-
*
|
|
281
|
-
* @param id - 要更新的多边形覆盖物的唯一标识符
|
|
282
|
-
* @param props - 要更新的多边形属性对象,包含需要更新的部分属性
|
|
283
|
-
* @throws {Error} 当地图视图未初始化时抛出错误
|
|
284
|
-
* @returns Promise<void> 异步操作完成后的Promise
|
|
285
|
-
*/
|
|
286
|
-
updatePolygon: async (id: string, props: Partial<PolygonProps>) => {
|
|
287
|
-
if (!nativeRef.current) throw new Error('MapView not initialized');
|
|
288
|
-
return nativeRef.current.updatePolygon(id, props);
|
|
289
|
-
},
|
|
92
|
+
}
|
|
93
|
+
|
|
290
94
|
}), []);
|
|
291
95
|
|
|
292
96
|
/**
|
|
@@ -304,29 +108,11 @@ const ExpoGaodeMapView = React.forwardRef<MapViewRef, MapViewProps>((props, ref)
|
|
|
304
108
|
React.useImperativeHandle(ref, () => apiRef, [apiRef]);
|
|
305
109
|
|
|
306
110
|
return (
|
|
307
|
-
<
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
<NativeView
|
|
313
|
-
ref={nativeRef}
|
|
314
|
-
{...props}
|
|
315
|
-
onMarkerPress={handleMarkerPress}
|
|
316
|
-
onMarkerDragStart={handleMarkerDragStart}
|
|
317
|
-
onMarkerDrag={handleMarkerDrag}
|
|
318
|
-
onMarkerDragEnd={handleMarkerDragEnd}
|
|
319
|
-
onCirclePress={handleCirclePress}
|
|
320
|
-
onPolygonPress={handlePolygonPress}
|
|
321
|
-
onPolylinePress={handlePolylinePress}
|
|
322
|
-
>
|
|
323
|
-
{props.children}
|
|
324
|
-
</NativeView>
|
|
325
|
-
</PolylineEventContext.Provider>
|
|
326
|
-
</PolygonEventContext.Provider>
|
|
327
|
-
</CircleEventContext.Provider>
|
|
328
|
-
</MarkerEventContext.Provider>
|
|
329
|
-
</MapContext.Provider>
|
|
111
|
+
<NativeView
|
|
112
|
+
ref={nativeRef}
|
|
113
|
+
{...props}>
|
|
114
|
+
{props.children}
|
|
115
|
+
</NativeView>
|
|
330
116
|
);
|
|
331
117
|
});
|
|
332
118
|
|
|
@@ -1,111 +1,19 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author : 尚博信_王强 wangqiang03@sunboxsoft.com
|
|
3
|
-
* @Date : 2025-11-13 15:02:04
|
|
4
|
-
* @LastEditors : 尚博信_王强 wangqiang03@sunboxsoft.com
|
|
5
|
-
* @LastEditTime : 2025-11-21 10:36:10
|
|
6
|
-
* @FilePath : /expo-gaode-map/src/components/overlays/Circle.tsx
|
|
7
|
-
* @Description :
|
|
8
|
-
*
|
|
9
|
-
* Copyright (c) 2025 by 尚博信_王强, All Rights Reserved.
|
|
10
|
-
*/
|
|
11
1
|
import * as React from 'react';
|
|
12
2
|
import { requireNativeViewManager } from 'expo-modules-core';
|
|
13
3
|
import type { CircleProps } from '../../types';
|
|
14
|
-
import { MapContext, CircleEventContext } from '../../ExpoGaodeMapView';
|
|
15
4
|
|
|
16
|
-
const NativeCircleView = requireNativeViewManager('CircleView');
|
|
5
|
+
const NativeCircleView = requireNativeViewManager<CircleProps>('CircleView');
|
|
17
6
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
function CircleDeclarative(props: CircleProps) {
|
|
28
|
-
const eventManager = React.useContext(CircleEventContext);
|
|
29
|
-
const circleIdRef = React.useRef(`circle_${Date.now()}_${Math.random()}`);
|
|
30
|
-
|
|
31
|
-
React.useEffect(() => {
|
|
32
|
-
if (eventManager) {
|
|
33
|
-
eventManager.register(circleIdRef.current, {
|
|
34
|
-
onPress: props.onPress,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return () => {
|
|
38
|
-
if (eventManager) {
|
|
39
|
-
eventManager.unregister(circleIdRef.current);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}, [props.onPress]);
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<NativeCircleView
|
|
46
|
-
{...props}
|
|
47
|
-
>
|
|
48
|
-
{props.children}
|
|
49
|
-
</NativeCircleView>
|
|
50
|
-
);
|
|
7
|
+
/**
|
|
8
|
+
* 高德地图圆形覆盖物组件(声明式)
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* @param props 圆形组件的属性配置
|
|
12
|
+
* @returns 渲染原生圆形组件
|
|
13
|
+
*/
|
|
14
|
+
function Circle(props: CircleProps) {
|
|
15
|
+
return <NativeCircleView {...props} />;
|
|
51
16
|
}
|
|
52
17
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const eventManager = React.useContext(CircleEventContext);
|
|
56
|
-
const circleIdRef = React.useRef<string | null>(null);
|
|
57
|
-
const propsRef = React.useRef(props);
|
|
58
|
-
|
|
59
|
-
React.useEffect(() => {
|
|
60
|
-
propsRef.current = props;
|
|
61
|
-
}, [props]);
|
|
62
|
-
|
|
63
|
-
React.useEffect(() => {
|
|
64
|
-
const checkAndAdd = () => {
|
|
65
|
-
if (!mapRef?.current) {
|
|
66
|
-
setTimeout(checkAndAdd, 50);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const circleId = `circle_${Date.now()}_${Math.random()}`;
|
|
71
|
-
circleIdRef.current = circleId;
|
|
72
|
-
|
|
73
|
-
if (eventManager && props.onPress) {
|
|
74
|
-
eventManager.register(circleId, {
|
|
75
|
-
onPress: props.onPress,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
mapRef.current.addCircle(circleId, propsRef.current);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
checkAndAdd();
|
|
83
|
-
|
|
84
|
-
return () => {
|
|
85
|
-
if (circleIdRef.current) {
|
|
86
|
-
if (eventManager) {
|
|
87
|
-
eventManager.unregister(circleIdRef.current);
|
|
88
|
-
}
|
|
89
|
-
if (mapRef?.current) {
|
|
90
|
-
mapRef.current.removeCircle(circleIdRef.current);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}, []);
|
|
95
|
-
|
|
96
|
-
React.useEffect(() => {
|
|
97
|
-
if (circleIdRef.current && eventManager) {
|
|
98
|
-
eventManager.register(circleIdRef.current, {
|
|
99
|
-
onPress: props.onPress,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}, [props.onPress]);
|
|
103
|
-
|
|
104
|
-
React.useEffect(() => {
|
|
105
|
-
if (circleIdRef.current && mapRef?.current) {
|
|
106
|
-
mapRef.current.updateCircle(circleIdRef.current, props);
|
|
107
|
-
}
|
|
108
|
-
}, [props.center, props.radius, props.fillColor, props.strokeColor, props.strokeWidth]);
|
|
109
|
-
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
18
|
+
// 导出优化后的组件
|
|
19
|
+
export default React.memo(Circle);
|