expo-gaode-map 2.2.31 → 2.2.32
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
CHANGED
|
@@ -179,7 +179,7 @@ public class ExpoGaodeMapModule: Module {
|
|
|
179
179
|
|
|
180
180
|
if status == .authorizedAlways || status == .authorizedWhenInUse {
|
|
181
181
|
let manager = self.getLocationManager()
|
|
182
|
-
manager.
|
|
182
|
+
manager.requestSingleLocation { location, regeocode, error in
|
|
183
183
|
if let error = error {
|
|
184
184
|
promise.reject("LOCATION_ERROR", error.localizedDescription)
|
|
185
185
|
return
|
|
@@ -214,7 +214,7 @@ public class ExpoGaodeMapModule: Module {
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
promise.resolve(locationData)
|
|
217
|
-
}
|
|
217
|
+
}
|
|
218
218
|
} else {
|
|
219
219
|
promise.reject("LOCATION_ERROR", "location unauthorized")
|
|
220
220
|
}
|
|
@@ -699,8 +699,13 @@ public class ExpoGaodeMapModule: Module {
|
|
|
699
699
|
if self.permissionManager == nil {
|
|
700
700
|
self.permissionManager = PermissionManager()
|
|
701
701
|
}
|
|
702
|
-
|
|
703
|
-
self.permissionManager
|
|
702
|
+
|
|
703
|
+
guard let permissionManager = self.permissionManager else {
|
|
704
|
+
promise.reject("PERMISSION_MANAGER_INIT_FAILED", "权限管理器初始化失败")
|
|
705
|
+
return
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
permissionManager.requestPermission { _, _ in
|
|
704
709
|
// 无论结果如何,都延迟后再次检查最终状态
|
|
705
710
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
706
711
|
let finalStatus = self.currentAuthorizationStatus()
|
|
@@ -96,6 +96,8 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate, UIGestureRecognizerDelegate
|
|
|
96
96
|
private var uiManager: UIManager!
|
|
97
97
|
/// 地图是否已加载完成
|
|
98
98
|
private var isMapLoaded = false
|
|
99
|
+
/// 初始相机是否已应用(仅应用一次,避免与运行时相机控制冲突)
|
|
100
|
+
private var hasAppliedInitialCameraPosition = false
|
|
99
101
|
/// 是否正在处理 annotation 选择事件
|
|
100
102
|
private var isHandlingAnnotationSelect = false
|
|
101
103
|
/// MarkerView 的隐藏容器(用于渲染 children)
|
|
@@ -380,9 +382,10 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate, UIGestureRecognizerDelegate
|
|
|
380
382
|
|
|
381
383
|
uiManager.setMapType(mapType)
|
|
382
384
|
|
|
383
|
-
//
|
|
384
|
-
if let position = initialCameraPosition {
|
|
385
|
+
// initialCameraPosition 只应用一次,避免每次 props 更新重置相机导致操作延迟感
|
|
386
|
+
if !hasAppliedInitialCameraPosition, let position = initialCameraPosition {
|
|
385
387
|
cameraManager.setInitialCameraPosition(position)
|
|
388
|
+
hasAppliedInitialCameraPosition = true
|
|
386
389
|
}
|
|
387
390
|
|
|
388
391
|
uiManager.setShowsScale(showsScale)
|
|
@@ -856,6 +859,8 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate, UIGestureRecognizerDelegate
|
|
|
856
859
|
|
|
857
860
|
mapView = resolvedMapView
|
|
858
861
|
super.addSubview(resolvedMapView)
|
|
862
|
+
isMapLoaded = false
|
|
863
|
+
hasAppliedInitialCameraPosition = false
|
|
859
864
|
|
|
860
865
|
cameraManager = CameraManager(mapView: resolvedMapView)
|
|
861
866
|
uiManager = UIManager(mapView: resolvedMapView)
|
|
@@ -921,6 +926,12 @@ extension ExpoGaodeMapView {
|
|
|
921
926
|
public func mapViewDidFinishLoadingMap(_ mapView: MAMapView) {
|
|
922
927
|
guard !isMapLoaded else { return }
|
|
923
928
|
isMapLoaded = true
|
|
929
|
+
|
|
930
|
+
// 兜底:若初始化阶段尚未生效,在加载完成后应用一次初始相机
|
|
931
|
+
if !hasAppliedInitialCameraPosition, let position = initialCameraPosition {
|
|
932
|
+
cameraManager?.setInitialCameraPosition(position)
|
|
933
|
+
hasAppliedInitialCameraPosition = true
|
|
934
|
+
}
|
|
924
935
|
|
|
925
936
|
// 地图加载完成后,应用自定义样式
|
|
926
937
|
if let styleData = customMapStyleData {
|
|
@@ -122,6 +122,23 @@ class LocationManager: NSObject, AMapLocationManagerDelegate {
|
|
|
122
122
|
ensureLocationManager()?.stopUpdatingHeading()
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
func requestSingleLocation(completion: @escaping (_ location: CLLocation?, _ reGeocode: AMapLocationReGeocode?, _ error: Error?) -> Void) {
|
|
126
|
+
guard let manager = ensureLocationManager() else {
|
|
127
|
+
let error = NSError(
|
|
128
|
+
domain: "ExpoGaodeMap",
|
|
129
|
+
code: -1,
|
|
130
|
+
userInfo: [NSLocalizedDescriptionKey: "定位管理器未初始化,请先完成隐私协议确认"]
|
|
131
|
+
)
|
|
132
|
+
completion(nil, nil, error)
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
manager.requestLocation(
|
|
137
|
+
withReGeocode: manager.locatingWithReGeocode,
|
|
138
|
+
completionBlock: completion
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
125
142
|
// MARK: - 初始化
|
|
126
143
|
|
|
127
144
|
@discardableResult
|
|
@@ -48,17 +48,22 @@ class PermissionManager: NSObject, CLLocationManagerDelegate {
|
|
|
48
48
|
self.permissionCallback = callback
|
|
49
49
|
|
|
50
50
|
// 确保在主线程操作
|
|
51
|
-
DispatchQueue.main.async {
|
|
52
|
-
guard let self = self else { return }
|
|
53
|
-
|
|
51
|
+
DispatchQueue.main.async {
|
|
54
52
|
if self.locationManager == nil {
|
|
55
53
|
self.locationManager = CLLocationManager()
|
|
56
|
-
self.locationManager?.delegate = self
|
|
57
54
|
}
|
|
55
|
+
|
|
56
|
+
guard let locationManager = self.locationManager else {
|
|
57
|
+
self.permissionCallback?(false, "unknown")
|
|
58
|
+
self.permissionCallback = nil
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
locationManager.delegate = self
|
|
58
63
|
|
|
59
64
|
var currentStatus: CLAuthorizationStatus
|
|
60
65
|
if #available(iOS 14.0, *) {
|
|
61
|
-
currentStatus =
|
|
66
|
+
currentStatus = locationManager.authorizationStatus
|
|
62
67
|
} else {
|
|
63
68
|
currentStatus = CLLocationManager.authorizationStatus()
|
|
64
69
|
}
|
|
@@ -84,7 +89,7 @@ class PermissionManager: NSObject, CLLocationManagerDelegate {
|
|
|
84
89
|
return
|
|
85
90
|
}
|
|
86
91
|
|
|
87
|
-
|
|
92
|
+
locationManager.requestWhenInUseAuthorization()
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-gaode-map",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.32",
|
|
4
4
|
"description": "A full-featured React Native AMap (Gaode Map) library for Expo, including map display, location, overlays, offline maps, and geometry utilities.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|