expo-gaode-map-navigation 1.1.5 → 1.1.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/README.md +213 -73
- package/android/build.gradle +10 -0
- package/android/src/main/cpp/CMakeLists.txt +24 -0
- package/android/src/main/cpp/cluster_jni.cpp +848 -0
- package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapModule.kt +616 -92
- package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapOfflineModule.kt +493 -0
- package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapView.kt +230 -14
- package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapViewModule.kt +37 -27
- package/android/src/main/java/expo/modules/gaodemap/map/MapPreloadManager.kt +494 -0
- package/android/src/main/java/expo/modules/gaodemap/map/companion/BitmapDescriptorCache.kt +30 -0
- package/android/src/main/java/expo/modules/gaodemap/map/companion/IconBitmapCache.kt +37 -0
- package/android/src/main/java/expo/modules/gaodemap/map/managers/UIManager.kt +76 -0
- package/android/src/main/java/expo/modules/gaodemap/map/modules/LocationManager.kt +15 -3
- package/android/src/main/java/expo/modules/gaodemap/map/modules/SDKInitializer.kt +4 -59
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/CircleView.kt +9 -12
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/CircleViewModule.kt +5 -6
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/ClusterView.kt +539 -66
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/ClusterViewModule.kt +17 -1
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/HeatMapView.kt +165 -33
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/HeatMapViewModule.kt +15 -3
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/MarkerView.kt +1249 -672
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/MarkerViewModule.kt +40 -17
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/MultiPointView.kt +177 -22
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/MultiPointViewModule.kt +11 -3
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolygonView.kt +57 -14
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolygonViewModule.kt +9 -5
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolylineView.kt +90 -63
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolylineViewModule.kt +7 -3
- package/android/src/main/java/expo/modules/gaodemap/map/services/LocationForegroundService.kt +3 -2
- package/android/src/main/java/expo/modules/gaodemap/map/utils/BitmapDescriptorCache.kt +20 -0
- package/android/src/main/java/expo/modules/gaodemap/map/utils/ClusterNative.kt +13 -0
- package/android/src/main/java/expo/modules/gaodemap/map/utils/ColorParser.kt +20 -0
- package/android/src/main/java/expo/modules/gaodemap/map/utils/GeometryUtils.kt +515 -0
- package/android/src/main/java/expo/modules/gaodemap/map/utils/LatLngParser.kt +91 -0
- package/android/src/main/java/expo/modules/gaodemap/map/utils/PermissionHelper.kt +248 -0
- package/build/ExpoGaodeMapNaviView.d.ts +7 -7
- package/build/ExpoGaodeMapNaviView.js +10 -11
- package/build/ExpoGaodeMapNavigationModule.d.ts +2 -1
- package/build/index.d.ts +35 -33
- package/build/index.js +70 -106
- package/build/map/ExpoGaodeMapModule.d.ts +2 -201
- package/build/map/ExpoGaodeMapModule.js +586 -18
- package/build/map/ExpoGaodeMapOfflineModule.d.ts +139 -0
- package/build/map/ExpoGaodeMapOfflineModule.js +8 -0
- package/build/map/ExpoGaodeMapView.js +66 -58
- package/build/map/components/FoldableMapView.d.ts +38 -0
- package/build/map/components/FoldableMapView.js +209 -0
- package/build/map/components/MapContext.d.ts +12 -0
- package/build/map/components/MapContext.js +54 -0
- package/build/map/components/MapUI.d.ts +18 -0
- package/build/map/components/MapUI.js +29 -0
- package/build/map/components/overlays/Circle.js +34 -3
- package/build/map/components/overlays/Cluster.d.ts +3 -1
- package/build/map/components/overlays/Cluster.js +31 -2
- package/build/map/components/overlays/HeatMap.d.ts +3 -1
- package/build/map/components/overlays/HeatMap.js +33 -3
- package/build/map/components/overlays/Marker.d.ts +1 -1
- package/build/map/components/overlays/Marker.js +37 -32
- package/build/map/components/overlays/MultiPoint.js +1 -1
- package/build/map/components/overlays/Polygon.js +30 -3
- package/build/map/components/overlays/Polyline.js +36 -3
- package/build/map/index.d.ts +25 -5
- package/build/map/index.js +59 -18
- package/build/map/types/common.types.d.ts +40 -0
- package/build/map/types/common.types.js +0 -4
- package/build/map/types/index.d.ts +3 -2
- package/build/map/types/map-view.types.d.ts +108 -3
- package/build/map/types/native-module.types.d.ts +363 -0
- package/build/map/types/native-module.types.js +5 -0
- package/build/map/types/offline.types.d.ts +132 -0
- package/build/map/types/offline.types.js +5 -0
- package/build/map/types/overlays.types.d.ts +137 -24
- package/build/map/utils/ErrorHandler.d.ts +110 -0
- package/build/map/utils/ErrorHandler.js +421 -0
- package/build/map/utils/GeoUtils.d.ts +20 -0
- package/build/map/utils/GeoUtils.js +76 -0
- package/build/map/utils/OfflineMapManager.d.ts +148 -0
- package/build/map/utils/OfflineMapManager.js +217 -0
- package/build/map/utils/PermissionUtils.d.ts +91 -0
- package/build/map/utils/PermissionUtils.js +255 -0
- package/build/map/utils/PlatformDetector.d.ts +102 -0
- package/build/map/utils/PlatformDetector.js +186 -0
- package/build/types/index.d.ts +1 -0
- package/build/types/index.js +1 -0
- package/build/types/native-module.types.d.ts +69 -0
- package/build/types/native-module.types.js +2 -0
- package/build/types/naviview.types.d.ts +1 -1
- package/expo-module.config.json +12 -10
- package/ios/ExpoGaodeMapNavigation.podspec +9 -0
- package/ios/map/ExpoGaodeMapModule.swift +485 -75
- package/ios/map/ExpoGaodeMapOfflineModule.swift +479 -0
- package/ios/map/ExpoGaodeMapView.swift +611 -62
- package/ios/map/ExpoGaodeMapViewModule.swift +48 -26
- package/ios/map/MapPreloadManager.swift +348 -0
- package/ios/map/cpp/ClusterEngine.cpp +110 -0
- package/ios/map/cpp/ClusterEngine.hpp +20 -0
- package/ios/map/cpp/ColorParser.cpp +135 -0
- package/ios/map/cpp/ColorParser.hpp +14 -0
- package/ios/map/cpp/GeometryEngine.cpp +574 -0
- package/ios/map/cpp/GeometryEngine.hpp +159 -0
- package/ios/map/cpp/QuadTree.cpp +92 -0
- package/ios/map/cpp/QuadTree.hpp +42 -0
- package/ios/map/cpp/README.md +55 -0
- package/ios/map/managers/UIManager.swift +72 -1
- package/ios/map/modules/LocationManager.swift +123 -166
- package/ios/map/overlays/CircleView.swift +16 -32
- package/ios/map/overlays/CircleViewModule.swift +12 -12
- package/ios/map/overlays/ClusterAnnotation.swift +32 -0
- package/ios/map/overlays/ClusterView.swift +331 -45
- package/ios/map/overlays/ClusterViewModule.swift +20 -6
- package/ios/map/overlays/HeatMapView.swift +135 -32
- package/ios/map/overlays/HeatMapViewModule.swift +20 -8
- package/ios/map/overlays/MarkerView.swift +613 -130
- package/ios/map/overlays/MarkerViewModule.swift +38 -18
- package/ios/map/overlays/MultiPointView.swift +168 -10
- package/ios/map/overlays/MultiPointViewModule.swift +27 -5
- package/ios/map/overlays/PolygonView.swift +62 -23
- package/ios/map/overlays/PolygonViewModule.swift +18 -12
- package/ios/map/overlays/PolylineView.swift +21 -13
- package/ios/map/overlays/PolylineViewModule.swift +18 -12
- package/ios/map/utils/ClusterNative.h +96 -0
- package/ios/map/utils/ClusterNative.mm +377 -0
- package/ios/map/utils/ColorParser.swift +12 -1
- package/ios/map/utils/CppBridging.mm +13 -0
- package/ios/map/utils/GeometryUtils.swift +34 -0
- package/ios/map/utils/LatLngParser.swift +87 -0
- package/ios/map/utils/PermissionManager.swift +135 -6
- package/package.json +3 -2
- package/shared/cpp/ClusterEngine.cpp +110 -0
- package/shared/cpp/ClusterEngine.hpp +20 -0
- package/shared/cpp/ColorParser.cpp +135 -0
- package/shared/cpp/ColorParser.hpp +14 -0
- package/shared/cpp/GeometryEngine.cpp +574 -0
- package/shared/cpp/GeometryEngine.hpp +159 -0
- package/shared/cpp/QuadTree.cpp +92 -0
- package/shared/cpp/QuadTree.hpp +42 -0
- package/shared/cpp/README.md +55 -0
- package/shared/cpp/tests/benchmark_js.js +41 -0
- package/shared/cpp/tests/run.sh +17 -0
- package/shared/cpp/tests/test_main.cpp +276 -0
- package/build/map/ExpoGaodeMap.types.d.ts +0 -41
- package/build/map/ExpoGaodeMap.types.js +0 -24
- package/build/map/utils/EventManager.d.ts +0 -10
- package/build/map/utils/EventManager.js +0 -26
- package/build/map/utils/ModuleLoader.d.ts +0 -73
- package/build/map/utils/ModuleLoader.js +0 -112
|
@@ -1,51 +1,619 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* 高德地图原生模块
|
|
4
|
-
* 提供 SDK 初始化、定位、权限管理等功能
|
|
5
|
-
*/
|
|
6
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
3
|
exports.getSDKConfig = getSDKConfig;
|
|
8
4
|
exports.getWebKey = getWebKey;
|
|
9
5
|
const expo_1 = require("expo");
|
|
6
|
+
const react_native_1 = require("react-native");
|
|
7
|
+
const ErrorHandler_1 = require("./utils/ErrorHandler");
|
|
8
|
+
const GeoUtils_1 = require("./utils/GeoUtils");
|
|
10
9
|
// 获取原生模块实例 - 添加容错处理
|
|
11
10
|
let nativeModule = null;
|
|
12
11
|
try {
|
|
13
|
-
nativeModule = (0, expo_1.requireNativeModule)('
|
|
12
|
+
nativeModule = (0, expo_1.requireNativeModule)('ExpoGaodeMap');
|
|
14
13
|
}
|
|
15
14
|
catch (error) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
console.warn('[expo-gaode-map-navigation] NaviMap 原生模块未加载,地图相关功能将不可用');
|
|
20
|
-
}
|
|
15
|
+
console.error('Failed to load ExpoGaodeMap native module:', error);
|
|
16
|
+
const moduleError = ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
17
|
+
ErrorHandler_1.ErrorLogger.log(moduleError);
|
|
21
18
|
}
|
|
22
19
|
// 记录最近一次 initSDK 的配置(含 webKey)
|
|
23
20
|
let _sdkConfig = null;
|
|
21
|
+
let _isSDKInitialized = false;
|
|
24
22
|
// 扩展原生模块,添加便捷方法
|
|
25
23
|
const ExpoGaodeMapModuleWithHelpers = {
|
|
26
24
|
...(nativeModule || {}),
|
|
27
25
|
/**
|
|
28
26
|
* 初始化 SDK,并缓存配置(包含 webKey)
|
|
27
|
+
* 注意:允许不提供任何 API Key,因为原生端可能已通过 Config Plugin 配置
|
|
29
28
|
*/
|
|
30
29
|
initSDK(config) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
if (!nativeModule) {
|
|
31
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
// 检查是否有任何 key 被提供
|
|
35
|
+
const hasJSKeys = !!(config.androidKey || config.iosKey);
|
|
36
|
+
const hasWebKey = !!config.webKey;
|
|
37
|
+
// 如果 JS 端没有提供 androidKey/iosKey,检查原生端是否已配置
|
|
38
|
+
if (!hasJSKeys) {
|
|
39
|
+
const isNativeConfigured = nativeModule.isNativeSDKConfigured();
|
|
40
|
+
if (!isNativeConfigured && !hasWebKey) {
|
|
41
|
+
throw ErrorHandler_1.ErrorHandler.invalidApiKey('both');
|
|
42
|
+
}
|
|
43
|
+
// 如果原生已配置,或者只提供了 webKey,继续初始化
|
|
44
|
+
ErrorHandler_1.ErrorLogger.warn(isNativeConfigured
|
|
45
|
+
? 'SDK 使用原生端配置的 API Key'
|
|
46
|
+
: 'SDK 初始化仅使用 webKey', { config });
|
|
47
|
+
}
|
|
48
|
+
_sdkConfig = config ?? null;
|
|
49
|
+
nativeModule.initSDK(config);
|
|
50
|
+
_isSDKInitialized = true;
|
|
51
|
+
ErrorHandler_1.ErrorLogger.warn('SDK 初始化成功', { config });
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
_isSDKInitialized = false;
|
|
55
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, 'SDK 初始化');
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
isSDKInitialized() {
|
|
59
|
+
return _isSDKInitialized;
|
|
60
|
+
},
|
|
61
|
+
calculateDistanceBetweenPoints(p1, p2) {
|
|
62
|
+
if (!nativeModule) {
|
|
63
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
64
|
+
}
|
|
65
|
+
return nativeModule.distanceBetweenCoordinates((0, GeoUtils_1.normalizeLatLng)(p1), (0, GeoUtils_1.normalizeLatLng)(p2));
|
|
66
|
+
},
|
|
67
|
+
calculateDistance(lat1, lon1, lat2, lon2) {
|
|
68
|
+
if (!nativeModule) {
|
|
69
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
70
|
+
}
|
|
71
|
+
return nativeModule.distanceBetweenCoordinates({ latitude: lat1, longitude: lon1 }, { latitude: lat2, longitude: lon2 });
|
|
72
|
+
},
|
|
73
|
+
setLoadWorldVectorMap(enabled) {
|
|
74
|
+
if (!nativeModule)
|
|
75
|
+
return;
|
|
76
|
+
try {
|
|
77
|
+
nativeModule.setLoadWorldVectorMap(enabled);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
ErrorHandler_1.ErrorLogger.warn('setLoadWorldVectorMap 失败', { enabled, error });
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
getVersion() {
|
|
84
|
+
if (!nativeModule)
|
|
85
|
+
return '0.0.0';
|
|
86
|
+
try {
|
|
87
|
+
return nativeModule.getVersion();
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
ErrorHandler_1.ErrorLogger.warn('getVersion 失败', { error });
|
|
91
|
+
return '0.0.0';
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
start() {
|
|
95
|
+
if (!nativeModule)
|
|
96
|
+
return;
|
|
97
|
+
try {
|
|
98
|
+
nativeModule.start();
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
ErrorHandler_1.ErrorLogger.warn('start 失败', { error });
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
stop() {
|
|
105
|
+
if (!nativeModule)
|
|
106
|
+
return;
|
|
107
|
+
try {
|
|
108
|
+
nativeModule.stop();
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
ErrorHandler_1.ErrorLogger.warn('stop 失败', { error });
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
isStarted() {
|
|
115
|
+
if (!nativeModule)
|
|
116
|
+
return Promise.resolve(false);
|
|
117
|
+
try {
|
|
118
|
+
return nativeModule.isStarted();
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
ErrorHandler_1.ErrorLogger.warn('isStarted 失败', { error });
|
|
122
|
+
return Promise.resolve(false);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
async getCurrentLocation() {
|
|
126
|
+
if (!nativeModule) {
|
|
127
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
return await nativeModule.getCurrentLocation();
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '获取当前位置');
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
async coordinateConvert(coordinate, type) {
|
|
137
|
+
if (!nativeModule) {
|
|
138
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
return await nativeModule.coordinateConvert((0, GeoUtils_1.normalizeLatLng)(coordinate), type);
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '坐标转换');
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
setLocatingWithReGeocode(isReGeocode) {
|
|
148
|
+
if (!nativeModule)
|
|
149
|
+
return;
|
|
150
|
+
try {
|
|
151
|
+
nativeModule.setLocatingWithReGeocode(isReGeocode);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
ErrorHandler_1.ErrorLogger.warn('setLocatingWithReGeocode 失败', { isReGeocode, error });
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
get isBackgroundLocationEnabled() {
|
|
158
|
+
if (!nativeModule)
|
|
159
|
+
return false;
|
|
160
|
+
return nativeModule.isBackgroundLocationEnabled === true;
|
|
161
|
+
},
|
|
162
|
+
/**
|
|
163
|
+
* 检查位置权限状态
|
|
164
|
+
*/
|
|
165
|
+
async checkLocationPermission() {
|
|
166
|
+
if (!nativeModule) {
|
|
167
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
return await nativeModule.checkLocationPermission();
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '检查权限');
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
/**
|
|
177
|
+
* 请求前台位置权限(增强版)
|
|
178
|
+
*/
|
|
179
|
+
async requestLocationPermission() {
|
|
180
|
+
if (!nativeModule) {
|
|
181
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const result = await nativeModule.requestLocationPermission();
|
|
185
|
+
if (!result.granted) {
|
|
186
|
+
ErrorHandler_1.ErrorLogger.warn('前台位置权限未授予', result);
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '请求前台权限');
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
/**
|
|
195
|
+
* 请求后台位置权限
|
|
196
|
+
* 注意:必须在前台权限已授予后才能请求
|
|
197
|
+
*/
|
|
198
|
+
async requestBackgroundLocationPermission() {
|
|
199
|
+
if (!nativeModule) {
|
|
200
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
const result = await nativeModule.requestBackgroundLocationPermission();
|
|
204
|
+
if (!result.granted) {
|
|
205
|
+
ErrorHandler_1.ErrorLogger.warn('后台位置权限未授予', result);
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '请求后台权限');
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
/**
|
|
214
|
+
* 打开应用设置页面
|
|
215
|
+
* 引导用户手动授予权限
|
|
216
|
+
*/
|
|
217
|
+
openAppSettings() {
|
|
218
|
+
if (!nativeModule) {
|
|
219
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
nativeModule.openAppSettings();
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '打开设置');
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
setAllowsBackgroundLocationUpdates(allows) {
|
|
229
|
+
if (!nativeModule) {
|
|
230
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
231
|
+
}
|
|
232
|
+
if (react_native_1.Platform.OS === 'ios' &&
|
|
233
|
+
allows &&
|
|
234
|
+
nativeModule &&
|
|
235
|
+
nativeModule.isBackgroundLocationEnabled === false) {
|
|
236
|
+
ErrorHandler_1.ErrorLogger.warn('⚠️ [ExpoGaodeMap] iOS 后台定位未正确配置,setAllowsBackgroundLocationUpdates(true) 可能不会生效,请检查 Info.plist 是否包含 UIBackgroundModes: location,或者在 app.json 中配置 enableBackgroundLocation: true,然后重新执行 npx expo prebuild');
|
|
237
|
+
}
|
|
238
|
+
if (react_native_1.Platform.OS === 'android' &&
|
|
239
|
+
allows &&
|
|
240
|
+
nativeModule &&
|
|
241
|
+
nativeModule.checkLocationPermission) {
|
|
242
|
+
nativeModule
|
|
243
|
+
.checkLocationPermission()
|
|
244
|
+
.then((status) => {
|
|
245
|
+
if (!status.backgroundLocation) {
|
|
246
|
+
ErrorHandler_1.ErrorLogger.warn('⚠️ [ExpoGaodeMap] Android 后台位置权限未授予,setAllowsBackgroundLocationUpdates(true) 可能不会生效,请先通过 requestBackgroundLocationPermission 或系统设置授予后台定位权限,或者检查是否在 app.json 中配置了 enableBackgroundLocation: true,然后重新执行 npx expo prebuild');
|
|
247
|
+
}
|
|
248
|
+
})
|
|
249
|
+
.catch(() => {
|
|
250
|
+
// 忽略检查失败,只影响日志,不影响功能
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
nativeModule.setAllowsBackgroundLocationUpdates(allows);
|
|
34
254
|
},
|
|
35
255
|
/**
|
|
36
256
|
* 添加定位监听器(便捷方法)
|
|
37
257
|
* 自动订阅 onLocationUpdate 事件,提供容错处理
|
|
38
258
|
* @param listener 定位回调函数
|
|
39
259
|
* @returns 订阅对象,调用 remove() 取消监听
|
|
40
|
-
*
|
|
260
|
+
* 注意:如果使用 Config Plugin 配置了 API Key,无需调用 initSDK()
|
|
41
261
|
*/
|
|
42
262
|
addLocationListener(listener) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
263
|
+
if (!nativeModule) {
|
|
264
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
265
|
+
}
|
|
266
|
+
if (!nativeModule?.addListener) {
|
|
267
|
+
ErrorHandler_1.ErrorLogger.warn('Native module does not support events');
|
|
268
|
+
}
|
|
269
|
+
return nativeModule?.addListener?.('onLocationUpdate', listener) || {
|
|
46
270
|
remove: () => { },
|
|
47
271
|
};
|
|
48
272
|
},
|
|
273
|
+
// ==================== 几何计算方法 ====================
|
|
274
|
+
/**
|
|
275
|
+
* 计算两个坐标点之间的距离
|
|
276
|
+
* @param coordinate1 第一个坐标点
|
|
277
|
+
* @param coordinate2 第二个坐标点
|
|
278
|
+
* @returns 两点之间的距离(单位:米)
|
|
279
|
+
*/
|
|
280
|
+
distanceBetweenCoordinates(coordinate1, coordinate2) {
|
|
281
|
+
if (!nativeModule) {
|
|
282
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
return nativeModule.distanceBetweenCoordinates((0, GeoUtils_1.normalizeLatLng)(coordinate1), (0, GeoUtils_1.normalizeLatLng)(coordinate2));
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '计算距离');
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
/**
|
|
292
|
+
* 判断点是否在圆内
|
|
293
|
+
* @param point 要判断的点
|
|
294
|
+
* @param center 圆心坐标
|
|
295
|
+
* @param radius 圆半径(单位:米)
|
|
296
|
+
* @returns 是否在圆内
|
|
297
|
+
*/
|
|
298
|
+
isPointInCircle(point, center, radius) {
|
|
299
|
+
if (!nativeModule) {
|
|
300
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
return nativeModule.isPointInCircle((0, GeoUtils_1.normalizeLatLng)(point), (0, GeoUtils_1.normalizeLatLng)(center), radius);
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '判断点是否在圆内');
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
/**
|
|
310
|
+
* 判断点是否在多边形内
|
|
311
|
+
* @param point 要判断的点
|
|
312
|
+
* @param polygon 多边形的顶点坐标数组
|
|
313
|
+
* @returns 是否在多边形内
|
|
314
|
+
*/
|
|
315
|
+
isPointInPolygon(point, polygon) {
|
|
316
|
+
if (!nativeModule) {
|
|
317
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
return nativeModule.isPointInPolygon((0, GeoUtils_1.normalizeLatLng)(point), (0, GeoUtils_1.normalizeLatLngList)(polygon));
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '判断点是否在多边形内');
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
/**
|
|
327
|
+
* 计算多边形面积
|
|
328
|
+
* @param polygon 多边形的顶点坐标数组
|
|
329
|
+
* @returns 面积(单位:平方米)
|
|
330
|
+
*/
|
|
331
|
+
calculatePolygonArea(polygon) {
|
|
332
|
+
if (!nativeModule) {
|
|
333
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
return nativeModule.calculatePolygonArea((0, GeoUtils_1.normalizeLatLngList)(polygon));
|
|
337
|
+
}
|
|
338
|
+
catch (error) {
|
|
339
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '计算多边形面积');
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
/**
|
|
343
|
+
* 计算矩形面积
|
|
344
|
+
* @param southWest 西南角坐标
|
|
345
|
+
* @param northEast 东北角坐标
|
|
346
|
+
* @returns 面积(单位:平方米)
|
|
347
|
+
*/
|
|
348
|
+
calculateRectangleArea(southWest, northEast) {
|
|
349
|
+
if (!nativeModule) {
|
|
350
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
351
|
+
}
|
|
352
|
+
try {
|
|
353
|
+
return nativeModule.calculateRectangleArea((0, GeoUtils_1.normalizeLatLng)(southWest), (0, GeoUtils_1.normalizeLatLng)(northEast));
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '计算矩形面积');
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
/**
|
|
360
|
+
* 获取路径上距离目标点最近的点
|
|
361
|
+
* @param path 路径点集合
|
|
362
|
+
* @param target 目标点
|
|
363
|
+
* @returns 最近点信息,包含坐标、索引和距离
|
|
364
|
+
*/
|
|
365
|
+
getNearestPointOnPath(path, target) {
|
|
366
|
+
if (!nativeModule) {
|
|
367
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
368
|
+
}
|
|
369
|
+
try {
|
|
370
|
+
return nativeModule.getNearestPointOnPath((0, GeoUtils_1.normalizeLatLngList)(path), (0, GeoUtils_1.normalizeLatLng)(target));
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '获取最近点');
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
/**
|
|
377
|
+
* 计算多边形质心
|
|
378
|
+
* @param polygon 多边形顶点坐标数组
|
|
379
|
+
* @returns 质心坐标
|
|
380
|
+
*/
|
|
381
|
+
calculateCentroid(polygon) {
|
|
382
|
+
if (!nativeModule) {
|
|
383
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
384
|
+
}
|
|
385
|
+
try {
|
|
386
|
+
return nativeModule.calculateCentroid((0, GeoUtils_1.normalizeLatLngList)(polygon));
|
|
387
|
+
}
|
|
388
|
+
catch (error) {
|
|
389
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '计算质心');
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
/**
|
|
393
|
+
* 计算路径边界和中心点
|
|
394
|
+
* @param points 路径点集合
|
|
395
|
+
* @returns 边界信息,包含 north, south, east, west 和 center
|
|
396
|
+
*/
|
|
397
|
+
calculatePathBounds(points) {
|
|
398
|
+
if (!nativeModule)
|
|
399
|
+
return null;
|
|
400
|
+
try {
|
|
401
|
+
const normalized = (0, GeoUtils_1.normalizeLatLngList)(points);
|
|
402
|
+
if (normalized.length === 0)
|
|
403
|
+
return null;
|
|
404
|
+
return nativeModule.calculatePathBounds(normalized);
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
ErrorHandler_1.ErrorLogger.warn('calculatePathBounds 失败', { pointsCount: points.length, error });
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
/**
|
|
412
|
+
* GeoHash 编码
|
|
413
|
+
* @param coordinate 坐标点
|
|
414
|
+
* @param precision 精度 (1-12)
|
|
415
|
+
* @returns GeoHash 字符串
|
|
416
|
+
*/
|
|
417
|
+
encodeGeoHash(coordinate, precision) {
|
|
418
|
+
if (!nativeModule) {
|
|
419
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
420
|
+
}
|
|
421
|
+
try {
|
|
422
|
+
return nativeModule.encodeGeoHash((0, GeoUtils_1.normalizeLatLng)(coordinate), precision);
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, 'GeoHash 编码');
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
/**
|
|
429
|
+
* 轨迹抽稀 (RDP 算法)
|
|
430
|
+
* @param points 原始轨迹点
|
|
431
|
+
* @param tolerance 允许误差(米)
|
|
432
|
+
* @returns 简化后的轨迹点
|
|
433
|
+
*/
|
|
434
|
+
simplifyPolyline(points, tolerance) {
|
|
435
|
+
if (!nativeModule) {
|
|
436
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
437
|
+
}
|
|
438
|
+
try {
|
|
439
|
+
return nativeModule.simplifyPolyline((0, GeoUtils_1.normalizeLatLngList)(points), tolerance);
|
|
440
|
+
}
|
|
441
|
+
catch (error) {
|
|
442
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '轨迹抽稀');
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
/**
|
|
446
|
+
* 计算路径总长度
|
|
447
|
+
* @param points 路径点
|
|
448
|
+
* @returns 长度(米)
|
|
449
|
+
*/
|
|
450
|
+
calculatePathLength(points) {
|
|
451
|
+
if (!nativeModule)
|
|
452
|
+
return 0;
|
|
453
|
+
try {
|
|
454
|
+
return nativeModule.calculatePathLength((0, GeoUtils_1.normalizeLatLngList)(points));
|
|
455
|
+
}
|
|
456
|
+
catch (error) {
|
|
457
|
+
ErrorHandler_1.ErrorLogger.warn('calculatePathLength 失败', { pointsCount: points.length, error });
|
|
458
|
+
return 0;
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
/**
|
|
462
|
+
* 解析高德地图 API 返回的 Polyline 字符串
|
|
463
|
+
* 格式: "lng,lat;lng,lat;..."
|
|
464
|
+
* @param polylineStr 高德原始 polyline 字符串,或包含 polyline 属性的对象
|
|
465
|
+
* @returns 解析后的点集
|
|
466
|
+
*/
|
|
467
|
+
parsePolyline(polylineStr) {
|
|
468
|
+
if (!nativeModule || !polylineStr)
|
|
469
|
+
return [];
|
|
470
|
+
try {
|
|
471
|
+
// 兼容性处理:如果传入的是对象 { polyline: '...' },自动提取字符串
|
|
472
|
+
let finalStr = '';
|
|
473
|
+
if (typeof polylineStr === 'object' && polylineStr !== null && 'polyline' in polylineStr) {
|
|
474
|
+
finalStr = polylineStr.polyline || '';
|
|
475
|
+
}
|
|
476
|
+
else if (typeof polylineStr === 'string') {
|
|
477
|
+
finalStr = polylineStr;
|
|
478
|
+
}
|
|
479
|
+
if (!finalStr)
|
|
480
|
+
return [];
|
|
481
|
+
return nativeModule.parsePolyline(finalStr);
|
|
482
|
+
}
|
|
483
|
+
catch (error) {
|
|
484
|
+
ErrorHandler_1.ErrorLogger.warn('解析 Polyline 失败', { polylineStr, error });
|
|
485
|
+
return [];
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
/**
|
|
489
|
+
* 获取路径上指定距离的点
|
|
490
|
+
* @param points 路径点
|
|
491
|
+
* @param distance 距离起点的米数
|
|
492
|
+
* @returns 点信息(坐标+角度)
|
|
493
|
+
*/
|
|
494
|
+
getPointAtDistance(points, distance) {
|
|
495
|
+
if (!nativeModule) {
|
|
496
|
+
throw ErrorHandler_1.ErrorHandler.nativeModuleUnavailable();
|
|
497
|
+
}
|
|
498
|
+
try {
|
|
499
|
+
return nativeModule.getPointAtDistance((0, GeoUtils_1.normalizeLatLngList)(points), distance);
|
|
500
|
+
}
|
|
501
|
+
catch (error) {
|
|
502
|
+
throw ErrorHandler_1.ErrorHandler.wrapNativeError(error, '获取路径上的点');
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
/**
|
|
506
|
+
* 经纬度转换为地图瓦片坐标
|
|
507
|
+
* @param coordinate 经纬度点
|
|
508
|
+
* @param zoom 缩放级别
|
|
509
|
+
* @returns 瓦片坐标(x, y, z)
|
|
510
|
+
*/
|
|
511
|
+
latLngToTile(coordinate, zoom) {
|
|
512
|
+
if (!nativeModule)
|
|
513
|
+
return null;
|
|
514
|
+
try {
|
|
515
|
+
return nativeModule.latLngToTile((0, GeoUtils_1.normalizeLatLng)(coordinate), zoom);
|
|
516
|
+
}
|
|
517
|
+
catch (error) {
|
|
518
|
+
ErrorHandler_1.ErrorLogger.warn('latLngToTile 失败', { coordinate, zoom, error });
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
/**
|
|
523
|
+
* 地图瓦片坐标转换为经纬度
|
|
524
|
+
* @param tile 瓦片坐标(x, y, z)
|
|
525
|
+
* @returns 经纬度点
|
|
526
|
+
*/
|
|
527
|
+
tileToLatLng(tile) {
|
|
528
|
+
if (!nativeModule)
|
|
529
|
+
return null;
|
|
530
|
+
try {
|
|
531
|
+
return nativeModule.tileToLatLng(tile);
|
|
532
|
+
}
|
|
533
|
+
catch (error) {
|
|
534
|
+
ErrorHandler_1.ErrorLogger.warn('tileToLatLng 失败', { tile, error });
|
|
535
|
+
return null;
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
/**
|
|
539
|
+
* 经纬度转换为地图像素坐标
|
|
540
|
+
* @param coordinate 经纬度点
|
|
541
|
+
* @param zoom 缩放级别
|
|
542
|
+
* @returns 像素坐标(x, y)
|
|
543
|
+
*/
|
|
544
|
+
latLngToPixel(coordinate, zoom) {
|
|
545
|
+
if (!nativeModule)
|
|
546
|
+
return null;
|
|
547
|
+
try {
|
|
548
|
+
return nativeModule.latLngToPixel((0, GeoUtils_1.normalizeLatLng)(coordinate), zoom);
|
|
549
|
+
}
|
|
550
|
+
catch (error) {
|
|
551
|
+
ErrorHandler_1.ErrorLogger.warn('latLngToPixel 失败', { coordinate, zoom, error });
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
/**
|
|
556
|
+
* 地图像素坐标转换为经纬度
|
|
557
|
+
* @param pixel 像素坐标(x, y)
|
|
558
|
+
* @param zoom 缩放级别
|
|
559
|
+
* @returns 经纬度点
|
|
560
|
+
*/
|
|
561
|
+
pixelToLatLng(pixel, zoom) {
|
|
562
|
+
if (!nativeModule)
|
|
563
|
+
return null;
|
|
564
|
+
try {
|
|
565
|
+
return nativeModule.pixelToLatLng(pixel, zoom);
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
ErrorHandler_1.ErrorLogger.warn('pixelToLatLng 失败', { pixel, zoom, error });
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
571
|
+
},
|
|
572
|
+
/**
|
|
573
|
+
* 批量地理围栏检测
|
|
574
|
+
* @param point 待检查的点
|
|
575
|
+
* @param polygons 多边形数组,格式为 LatLngPoint[][] 或 LatLngPoint[][][]
|
|
576
|
+
* @returns 包含点索引的数组(-1 表示不在任何多边形内)
|
|
577
|
+
*/
|
|
578
|
+
findPointInPolygons(point, polygons) {
|
|
579
|
+
if (!nativeModule)
|
|
580
|
+
return -1;
|
|
581
|
+
try {
|
|
582
|
+
const normalizedPoint = (0, GeoUtils_1.normalizeLatLng)(point);
|
|
583
|
+
let normalizedPolygons;
|
|
584
|
+
// 处理三维数组 (LatLngPoint[][][]) 和二维数组 (LatLngPoint[][])
|
|
585
|
+
if (Array.isArray(polygons[0]) && Array.isArray(polygons[0][0])) {
|
|
586
|
+
// LatLngPoint[][][] -> 扁平化为 LatLngPoint[][] 用于 C++ 遍历
|
|
587
|
+
normalizedPolygons = polygons.reduce((acc, val) => acc.concat(val), []);
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
normalizedPolygons = polygons;
|
|
591
|
+
}
|
|
592
|
+
const processedPolygons = normalizedPolygons.map(p => (0, GeoUtils_1.normalizeLatLngList)(p));
|
|
593
|
+
return nativeModule.findPointInPolygons(normalizedPoint, processedPolygons);
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
ErrorHandler_1.ErrorLogger.warn('findPointInPolygons 失败', { point, error });
|
|
597
|
+
return -1;
|
|
598
|
+
}
|
|
599
|
+
},
|
|
600
|
+
/**
|
|
601
|
+
* 生成网格聚合数据 (常用于展示网格聚合图或大规模点数据处理)
|
|
602
|
+
* @param points 包含经纬度和权重的点数组
|
|
603
|
+
* @param gridSizeMeters 网格大小(米)
|
|
604
|
+
* @returns 包含经纬度和强度的网格点数组
|
|
605
|
+
*/
|
|
606
|
+
generateHeatmapGrid(points, gridSizeMeters) {
|
|
607
|
+
if (!nativeModule || points.length === 0)
|
|
608
|
+
return [];
|
|
609
|
+
try {
|
|
610
|
+
return nativeModule.generateHeatmapGrid(points, gridSizeMeters);
|
|
611
|
+
}
|
|
612
|
+
catch (error) {
|
|
613
|
+
ErrorHandler_1.ErrorLogger.warn('generateHeatmapGrid 失败', { pointsCount: points.length, gridSizeMeters, error });
|
|
614
|
+
return [];
|
|
615
|
+
}
|
|
616
|
+
},
|
|
49
617
|
};
|
|
50
618
|
/**
|
|
51
619
|
* 获取最近一次 initSDK 的配置
|
|
@@ -57,6 +625,6 @@ function getSDKConfig() {
|
|
|
57
625
|
* 获取用于 Web API 的 webKey(若未初始化或未提供则返回 undefined)
|
|
58
626
|
*/
|
|
59
627
|
function getWebKey() {
|
|
60
|
-
return _sdkConfig
|
|
628
|
+
return _sdkConfig?.webKey;
|
|
61
629
|
}
|
|
62
630
|
exports.default = ExpoGaodeMapModuleWithHelpers;
|