expo-gaode-map 1.1.8 → 2.0.0-alpha.2

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.
Files changed (116) hide show
  1. package/README.en.md +32 -46
  2. package/README.md +51 -70
  3. package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapView.kt +98 -268
  4. package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapViewModule.kt +1 -49
  5. package/android/src/main/java/expo/modules/gaodemap/managers/CameraManager.kt +30 -7
  6. package/android/src/main/java/expo/modules/gaodemap/managers/UIManager.kt +1 -0
  7. package/android/src/main/java/expo/modules/gaodemap/modules/LocationManager.kt +10 -1
  8. package/android/src/main/java/expo/modules/gaodemap/overlays/CircleView.kt +38 -14
  9. package/android/src/main/java/expo/modules/gaodemap/overlays/CircleViewModule.kt +3 -3
  10. package/android/src/main/java/expo/modules/gaodemap/overlays/ClusterView.kt +8 -1
  11. package/android/src/main/java/expo/modules/gaodemap/overlays/HeatMapView.kt +4 -1
  12. package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerView.kt +322 -93
  13. package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerViewModule.kt +11 -3
  14. package/android/src/main/java/expo/modules/gaodemap/overlays/MultiPointView.kt +4 -1
  15. package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonView.kt +25 -11
  16. package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonViewModule.kt +3 -3
  17. package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineView.kt +20 -10
  18. package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineViewModule.kt +6 -2
  19. package/build/ExpoGaodeMap.types.d.ts +27 -6
  20. package/build/ExpoGaodeMap.types.d.ts.map +1 -1
  21. package/build/ExpoGaodeMap.types.js +3 -0
  22. package/build/ExpoGaodeMap.types.js.map +1 -1
  23. package/build/ExpoGaodeMapModule.d.ts +157 -10
  24. package/build/ExpoGaodeMapModule.d.ts.map +1 -1
  25. package/build/ExpoGaodeMapModule.js +4 -0
  26. package/build/ExpoGaodeMapModule.js.map +1 -1
  27. package/build/ExpoGaodeMapView.d.ts +1 -17
  28. package/build/ExpoGaodeMapView.d.ts.map +1 -1
  29. package/build/ExpoGaodeMapView.js +4 -221
  30. package/build/ExpoGaodeMapView.js.map +1 -1
  31. package/build/components/overlays/Circle.d.ts +11 -1
  32. package/build/components/overlays/Circle.d.ts.map +1 -1
  33. package/build/components/overlays/Circle.js +12 -58
  34. package/build/components/overlays/Circle.js.map +1 -1
  35. package/build/components/overlays/Cluster.d.ts.map +1 -1
  36. package/build/components/overlays/Cluster.js.map +1 -1
  37. package/build/components/overlays/Marker.d.ts +13 -1
  38. package/build/components/overlays/Marker.d.ts.map +1 -1
  39. package/build/components/overlays/Marker.js +51 -115
  40. package/build/components/overlays/Marker.js.map +1 -1
  41. package/build/components/overlays/Polygon.d.ts +7 -15
  42. package/build/components/overlays/Polygon.d.ts.map +1 -1
  43. package/build/components/overlays/Polygon.js +10 -80
  44. package/build/components/overlays/Polygon.js.map +1 -1
  45. package/build/components/overlays/Polyline.d.ts +7 -14
  46. package/build/components/overlays/Polyline.d.ts.map +1 -1
  47. package/build/components/overlays/Polyline.js +9 -66
  48. package/build/components/overlays/Polyline.js.map +1 -1
  49. package/build/index.d.ts +1 -4
  50. package/build/index.d.ts.map +1 -1
  51. package/build/index.js +2 -10
  52. package/build/index.js.map +1 -1
  53. package/build/types/map-view.types.d.ts +0 -90
  54. package/build/types/map-view.types.d.ts.map +1 -1
  55. package/build/types/map-view.types.js.map +1 -1
  56. package/build/types/overlays.types.d.ts +9 -9
  57. package/build/types/overlays.types.d.ts.map +1 -1
  58. package/build/types/overlays.types.js.map +1 -1
  59. package/docs/API.en.md +1 -21
  60. package/docs/API.md +84 -56
  61. package/docs/EXAMPLES.en.md +0 -48
  62. package/docs/EXAMPLES.md +49 -102
  63. package/docs/INITIALIZATION.md +59 -71
  64. package/docs/MIGRATION.md +423 -0
  65. package/ios/ExpoGaodeMapModule.swift +4 -0
  66. package/ios/ExpoGaodeMapView.swift +365 -258
  67. package/ios/ExpoGaodeMapViewModule.swift +3 -50
  68. package/ios/managers/CameraManager.swift +23 -2
  69. package/ios/managers/UIManager.swift +10 -5
  70. package/ios/modules/LocationManager.swift +10 -0
  71. package/ios/overlays/CircleView.swift +98 -19
  72. package/ios/overlays/CircleViewModule.swift +21 -0
  73. package/ios/overlays/ClusterView.swift +33 -4
  74. package/ios/overlays/HeatMapView.swift +16 -4
  75. package/ios/overlays/MarkerView.swift +235 -146
  76. package/ios/overlays/MarkerViewModule.swift +7 -3
  77. package/ios/overlays/MultiPointView.swift +30 -1
  78. package/ios/overlays/PolygonView.swift +63 -12
  79. package/ios/overlays/PolygonViewModule.swift +17 -0
  80. package/ios/overlays/PolylineView.swift +95 -25
  81. package/ios/overlays/PolylineViewModule.swift +17 -8
  82. package/ios/utils/PermissionManager.swift +9 -14
  83. package/package.json +4 -3
  84. package/src/ExpoGaodeMap.types.ts +28 -3
  85. package/src/ExpoGaodeMapModule.ts +201 -12
  86. package/src/ExpoGaodeMapView.tsx +9 -234
  87. package/src/components/overlays/Circle.tsx +14 -70
  88. package/src/components/overlays/Cluster.tsx +0 -1
  89. package/src/components/overlays/Marker.tsx +63 -138
  90. package/src/components/overlays/Polygon.tsx +12 -92
  91. package/src/components/overlays/Polyline.tsx +11 -77
  92. package/src/index.ts +4 -29
  93. package/src/types/map-view.types.ts +1 -85
  94. package/src/types/overlays.types.ts +9 -9
  95. package/android/src/main/java/expo/modules/gaodemap/managers/OverlayManager.kt +0 -574
  96. package/build/modules/AMapLocation.d.ts +0 -78
  97. package/build/modules/AMapLocation.d.ts.map +0 -1
  98. package/build/modules/AMapLocation.js +0 -132
  99. package/build/modules/AMapLocation.js.map +0 -1
  100. package/build/modules/AMapPermissions.d.ts +0 -29
  101. package/build/modules/AMapPermissions.d.ts.map +0 -1
  102. package/build/modules/AMapPermissions.js +0 -23
  103. package/build/modules/AMapPermissions.js.map +0 -1
  104. package/build/modules/AMapSDK.d.ts +0 -22
  105. package/build/modules/AMapSDK.d.ts.map +0 -1
  106. package/build/modules/AMapSDK.js +0 -25
  107. package/build/modules/AMapSDK.js.map +0 -1
  108. package/build/modules/AMapView.d.ts +0 -44
  109. package/build/modules/AMapView.d.ts.map +0 -1
  110. package/build/modules/AMapView.js +0 -65
  111. package/build/modules/AMapView.js.map +0 -1
  112. package/ios/managers/OverlayManager.swift +0 -522
  113. package/src/modules/AMapLocation.ts +0 -165
  114. package/src/modules/AMapPermissions.ts +0 -41
  115. package/src/modules/AMapSDK.ts +0 -31
  116. package/src/modules/AMapView.ts +0 -72
@@ -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 { LatLng, CoordinateType } from './types';
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
- initSDK(config: { androidKey?: string; iosKey?: string }): void;
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
- getCurrentLocation(): Promise<any>;
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
- setLocationMode(mode: number): void;
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
- setDesiredAccuracy(accuracy: number): void;
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
- checkLocationPermission(): Promise<any>;
43
- requestLocationPermission(): Promise<any>;
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');
@@ -1,40 +1,20 @@
1
1
  import { requireNativeViewManager } from 'expo-modules-core';
2
2
  import * as React from 'react';
3
- import { NativeSyntheticEvent } from 'react-native';
4
- import { EventManager } from './utils/EventManager';
3
+
5
4
  import type {
6
5
  MapViewProps,
7
6
  MapViewRef,
8
7
  CameraPosition,
9
8
  LatLng,
10
9
  Point,
11
- CircleProps,
12
- MarkerProps,
13
- PolylineProps,
14
- PolygonProps,
10
+
15
11
  } from './types';
16
12
 
17
13
  export type { MapViewRef } from './types';
18
14
 
19
15
  const NativeView: React.ComponentType<MapViewProps & { ref?: React.Ref<MapViewRef> }> = requireNativeViewManager('ExpoGaodeMapView');
20
16
 
21
- export const MapContext = React.createContext<React.RefObject<MapViewRef | null> | null>(null);
22
-
23
- type MarkerEventCallbacks = {
24
- onPress?: (event: NativeSyntheticEvent<{}>) => void;
25
- onDragStart?: (event: NativeSyntheticEvent<LatLng>) => void;
26
- onDrag?: (event: NativeSyntheticEvent<LatLng>) => void;
27
- onDragEnd?: (event: NativeSyntheticEvent<LatLng>) => void;
28
- };
29
17
 
30
- type OverlayEventCallbacks = {
31
- onPress?: (event: NativeSyntheticEvent<{}>) => void;
32
- };
33
-
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);
38
18
 
39
19
  /**
40
20
  * 高德地图视图组件,提供地图操作API和覆盖物管理功能
@@ -57,53 +37,7 @@ export const PolylineEventContext = React.createContext<EventManager<OverlayEven
57
37
  const ExpoGaodeMapView = React.forwardRef<MapViewRef, MapViewProps>((props, ref) => {
58
38
  const nativeRef = React.useRef<MapViewRef>(null);
59
39
  const internalRef = React.useRef<MapViewRef | null>(null);
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) => {
65
- const markerId = event.nativeEvent?.markerId;
66
- if (markerId) markerEventManager.trigger(markerId, 'onPress', event);
67
- props.onMarkerPress?.(event);
68
- };
69
-
70
- const handleMarkerDragStart = (event: any) => {
71
- const markerId = event.nativeEvent?.markerId;
72
- if (markerId) markerEventManager.trigger(markerId, 'onDragStart', event);
73
- props.onMarkerDragStart?.(event);
74
- };
75
-
76
- const handleMarkerDrag = (event: any) => {
77
- const markerId = event.nativeEvent?.markerId;
78
- if (markerId) markerEventManager.trigger(markerId, 'onDrag', event);
79
- props.onMarkerDrag?.(event);
80
- };
81
-
82
- const handleMarkerDragEnd = (event: any) => {
83
- const markerId = event.nativeEvent?.markerId;
84
- if (markerId) {
85
- markerEventManager.trigger(markerId, 'onDragEnd', event);
86
- }
87
- props.onMarkerDragEnd?.(event);
88
- };
89
-
90
- const handleCirclePress = (event: any) => {
91
- const circleId = event.nativeEvent?.circleId;
92
- if (circleId) circleEventManager.trigger(circleId, 'onPress', event);
93
- props.onCirclePress?.(event);
94
- };
95
40
 
96
- const handlePolygonPress = (event: any) => {
97
- const polygonId = event.nativeEvent?.polygonId;
98
- if (polygonId) polygonEventManager.trigger(polygonId, 'onPress', event);
99
- props.onPolygonPress?.(event);
100
- };
101
-
102
- const handlePolylinePress = (event: any) => {
103
- const polylineId = event.nativeEvent?.polylineId;
104
- if (polylineId) polylineEventManager.trigger(polylineId, 'onPress', event);
105
- props.onPolylinePress?.(event);
106
- };
107
41
 
108
42
  const apiRef: MapViewRef = React.useMemo(() => ({
109
43
  /**
@@ -155,149 +89,8 @@ const ExpoGaodeMapView = React.forwardRef<MapViewRef, MapViewProps>((props, ref)
155
89
  getCameraPosition: async () => {
156
90
  if (!nativeRef.current) throw new Error('MapView not initialized');
157
91
  return nativeRef.current.getCameraPosition();
158
- },
159
- /**
160
- * 在地图上添加圆形覆盖物
161
- * @param id - 圆形覆盖物的唯一标识符
162
- * @param props - 圆形覆盖物的属性配置
163
- * @returns Promise<void> 添加操作的异步结果
164
- * @throws 如果地图视图未初始化,抛出错误'MapView not initialized'
165
- * @deprecated 该方法已被弃用,请使用声明式添加
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
- * @deprecated 该方法已被弃用,请使用声明式添加
177
- */
178
- removeCircle: async (id: string) => {
179
- if (!nativeRef.current) throw new Error('MapView not initialized');
180
- return nativeRef.current.removeCircle(id);
181
- },
182
- /**
183
- * 更新地图上的圆形覆盖物
184
- * @param id 要更新的圆形覆盖物的唯一标识符
185
- * @param props 要更新的圆形属性(部分属性)
186
- * @throws 如果地图视图未初始化,抛出错误
187
- * @returns Promise<void> 表示更新操作完成
188
- * @deprecated 该方法已被弃用,请使用声明式添加
189
- */
190
- updateCircle: async (id: string, props: Partial<CircleProps>) => {
191
- if (!nativeRef.current) throw new Error('MapView not initialized');
192
- return nativeRef.current.updateCircle(id, props);
193
- },
194
- /**
195
- * 添加一个标记点到地图上
196
- * @param id 标记点的唯一标识符
197
- * @param props 标记点的配置属性
198
- * @returns Promise<void> 添加操作完成后的Promise
199
- * @throws 如果地图视图未初始化则抛出错误
200
- * @deprecated 该方法已被弃用,请使用声明式添加
201
- */
202
- addMarker: async (id: string, props: MarkerProps) => {
203
- if (!nativeRef.current) throw new Error('MapView not initialized');
204
- return nativeRef.current.addMarker(id, props);
205
- },
206
- /**
207
- * 从地图上移除指定ID的标记点
208
- * @param id 要移除的标记点ID
209
- * @throws 如果地图视图未初始化则抛出错误
210
- * @returns Promise<void> 异步操作完成
211
- * @deprecated 该方法已被弃用,请使用声明式添加
212
- */
213
- removeMarker: async (id: string) => {
214
- if (!nativeRef.current) throw new Error('MapView not initialized');
215
- return nativeRef.current.removeMarker(id);
216
- },
217
- /**
218
- * 更新地图上指定ID的标记点属性
219
- * @param id - 要更新的标记点唯一标识符
220
- * @param props - 需要更新的标记点属性对象(部分属性)
221
- * @throws 如果地图视图未初始化则抛出错误
222
- * @returns Promise对象,表示异步更新操作
223
- * @deprecated 该方法已被弃用,请使用声明式添加
224
- */
225
- updateMarker: async (id: string, props: Partial<MarkerProps>) => {
226
- if (!nativeRef.current) throw new Error('MapView not initialized');
227
- return nativeRef.current.updateMarker(id, props);
228
- },
229
- /**
230
- * 添加折线覆盖物到地图
231
- * @param id - 折线的唯一标识符
232
- * @param props - 折线的配置属性
233
- * @returns Promise<void> 添加操作的异步结果
234
- * @throws 如果地图视图未初始化则抛出错误
235
- * @deprecated 该方法已被弃用,请使用声明式添加
236
- */
237
- addPolyline: async (id: string, props: PolylineProps) => {
238
- if (!nativeRef.current) throw new Error('MapView not initialized');
239
- return nativeRef.current.addPolyline(id, props);
240
- },
241
- /**
242
- * 移除地图上的指定折线
243
- * @param id - 要移除的折线的唯一标识符
244
- * @throws 如果地图视图未初始化,抛出错误
245
- * @returns Promise<void>
246
- * @deprecated 该方法已被弃用,请使用声明式添加
247
- */
248
- removePolyline: async (id: string) => {
249
- if (!nativeRef.current) throw new Error('MapView not initialized');
250
- return nativeRef.current.removePolyline(id);
251
- },
252
- /**
253
- * 更新地图上的折线覆盖物
254
- *
255
- * @param id 要更新的折线覆盖物的唯一标识符
256
- * @param props 要更新的折线属性,包含部分PolylineProps属性
257
- * @returns Promise<void> 异步操作结果
258
- * @throws 如果地图视图未初始化,抛出错误
259
- * @deprecated 该方法已被弃用,请使用声明式添加
260
- */
261
- updatePolyline: async (id: string, props: Partial<PolylineProps>) => {
262
- if (!nativeRef.current) throw new Error('MapView not initialized');
263
- return nativeRef.current.updatePolyline(id, props);
264
- },
265
- /**
266
- * 向地图添加多边形覆盖物
267
- * @param id - 多边形的唯一标识符
268
- * @param props - 多边形的配置属性
269
- * @returns Promise<void> 添加操作的异步结果
270
- * @throws 如果地图视图未初始化则抛出错误
271
- * @deprecated 该方法已被弃用,请使用声明式添加
272
- */
273
- addPolygon: async (id: string, props: PolygonProps) => {
274
- if (!nativeRef.current) throw new Error('MapView not initialized');
275
- return nativeRef.current.addPolygon(id, props);
276
- },
277
- /**
278
- * 移除地图上的多边形覆盖物
279
- * @param id - 要移除的多边形覆盖物的唯一标识符
280
- * @throws 如果地图视图未初始化,抛出错误 'MapView not initialized'
281
- * @returns Promise<void> 异步操作完成
282
- * @deprecated 该方法已被弃用,请使用声明式添加
283
- */
284
- removePolygon: async (id: string) => {
285
- if (!nativeRef.current) throw new Error('MapView not initialized');
286
- return nativeRef.current.removePolygon(id);
287
- },
288
- /**
289
- * 更新多边形覆盖物的属性
290
- *
291
- * @param id - 要更新的多边形覆盖物的唯一标识符
292
- * @param props - 要更新的多边形属性对象,包含需要更新的部分属性
293
- * @throws {Error} 当地图视图未初始化时抛出错误
294
- * @returns Promise<void> 异步操作完成后的Promise
295
- * @deprecated 该方法已被弃用,请使用声明式添加
296
- */
297
- updatePolygon: async (id: string, props: Partial<PolygonProps>) => {
298
- if (!nativeRef.current) throw new Error('MapView not initialized');
299
- return nativeRef.current.updatePolygon(id, props);
300
- },
92
+ }
93
+
301
94
  }), []);
302
95
 
303
96
  /**
@@ -315,29 +108,11 @@ const ExpoGaodeMapView = React.forwardRef<MapViewRef, MapViewProps>((props, ref)
315
108
  React.useImperativeHandle(ref, () => apiRef, [apiRef]);
316
109
 
317
110
  return (
318
- <MapContext.Provider value={internalRef}>
319
- <MarkerEventContext.Provider value={markerEventManager}>
320
- <CircleEventContext.Provider value={circleEventManager}>
321
- <PolygonEventContext.Provider value={polygonEventManager}>
322
- <PolylineEventContext.Provider value={polylineEventManager}>
323
- <NativeView
324
- ref={nativeRef}
325
- {...props}
326
- onMarkerPress={handleMarkerPress}
327
- onMarkerDragStart={handleMarkerDragStart}
328
- onMarkerDrag={handleMarkerDrag}
329
- onMarkerDragEnd={handleMarkerDragEnd}
330
- onCirclePress={handleCirclePress}
331
- onPolygonPress={handlePolygonPress}
332
- onPolylinePress={handlePolylinePress}
333
- >
334
- {props.children}
335
- </NativeView>
336
- </PolylineEventContext.Provider>
337
- </PolygonEventContext.Provider>
338
- </CircleEventContext.Provider>
339
- </MarkerEventContext.Provider>
340
- </MapContext.Provider>
111
+ <NativeView
112
+ ref={nativeRef}
113
+ {...props}>
114
+ {props.children}
115
+ </NativeView>
341
116
  );
342
117
  });
343
118
 
@@ -1,75 +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-24 18:51:17
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
-
16
-
17
- export default function CircleImperative(props: CircleProps) {
18
- const mapRef = React.useContext(MapContext);
19
- const eventManager = React.useContext(CircleEventContext);
20
- const circleIdRef = React.useRef<string | null>(null);
21
- const propsRef = React.useRef(props);
22
-
23
- React.useEffect(() => {
24
- propsRef.current = props;
25
- }, [props]);
26
-
27
- React.useEffect(() => {
28
- const checkAndAdd = () => {
29
- if (!mapRef?.current) {
30
- setTimeout(checkAndAdd, 50);
31
- return;
32
- }
33
-
34
- const circleId = `circle_${Date.now()}_${Math.random()}`;
35
- circleIdRef.current = circleId;
36
-
37
- if (eventManager && props.onPress) {
38
- eventManager.register(circleId, {
39
- onPress: props.onPress,
40
- });
41
- }
42
-
43
- mapRef.current.addCircle(circleId, propsRef.current);
44
- };
45
-
46
- checkAndAdd();
47
-
48
- return () => {
49
- if (circleIdRef.current) {
50
- if (eventManager) {
51
- eventManager.unregister(circleIdRef.current);
52
- }
53
- if (mapRef?.current) {
54
- mapRef.current.removeCircle(circleIdRef.current);
55
- }
56
- }
57
- };
58
- }, []);
59
4
 
60
- React.useEffect(() => {
61
- if (circleIdRef.current && eventManager) {
62
- eventManager.register(circleIdRef.current, {
63
- onPress: props.onPress,
64
- });
65
- }
66
- }, [props.onPress]);
5
+ const NativeCircleView = requireNativeViewManager<CircleProps>('CircleView');
67
6
 
68
- React.useEffect(() => {
69
- if (circleIdRef.current && mapRef?.current) {
70
- mapRef.current.updateCircle(circleIdRef.current, props);
71
- }
72
- }, [props.center, props.radius, props.fillColor, props.strokeColor, props.strokeWidth]);
73
-
74
- return null;
7
+ /**
8
+ * 高德地图圆形覆盖物组件(声明式)
9
+ *
10
+ *
11
+ * @param props 圆形组件的属性配置
12
+ * @returns 渲染原生圆形组件
13
+ */
14
+ function Circle(props: CircleProps) {
15
+ return <NativeCircleView {...props} />;
75
16
  }
17
+
18
+ // 导出优化后的组件
19
+ export default React.memo(Circle);
@@ -5,7 +5,6 @@ import type { ClusterProps } from '../../types';
5
5
 
6
6
  const NativeCluster = requireNativeViewManager('ClusterView');
7
7
 
8
-
9
8
  /**
10
9
  * 高德地图点聚合组件
11
10
  *