expo-gaode-map-navigation 2.0.3 → 2.0.4

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 (70) hide show
  1. package/android/build.gradle +3 -0
  2. package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapModule.kt +45 -49
  3. package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapView.kt +5 -15
  4. package/android/src/main/java/expo/modules/gaodemap/map/modules/SDKInitializer.kt +143 -14
  5. package/build/ExpoGaodeMapNaviView.d.ts.map +1 -1
  6. package/build/ExpoGaodeMapNaviView.js +3 -2
  7. package/build/ExpoGaodeMapNaviView.js.map +1 -1
  8. package/build/ExpoGaodeMapNavigationModule.d.ts +2 -7
  9. package/build/ExpoGaodeMapNavigationModule.d.ts.map +1 -1
  10. package/build/ExpoGaodeMapNavigationModule.js +19 -2
  11. package/build/ExpoGaodeMapNavigationModule.js.map +1 -1
  12. package/build/index.d.ts.map +1 -1
  13. package/build/index.js +8 -2
  14. package/build/index.js.map +1 -1
  15. package/build/map/ExpoGaodeMapModule.d.ts +245 -4
  16. package/build/map/ExpoGaodeMapModule.d.ts.map +1 -1
  17. package/build/map/ExpoGaodeMapModule.js +197 -15
  18. package/build/map/ExpoGaodeMapModule.js.map +1 -1
  19. package/build/map/ExpoGaodeMapOfflineModule.d.ts.map +1 -1
  20. package/build/map/ExpoGaodeMapOfflineModule.js +19 -2
  21. package/build/map/ExpoGaodeMapOfflineModule.js.map +1 -1
  22. package/build/map/ExpoGaodeMapView.d.ts.map +1 -1
  23. package/build/map/ExpoGaodeMapView.js +8 -2
  24. package/build/map/ExpoGaodeMapView.js.map +1 -1
  25. package/build/map/components/overlays/Circle.d.ts.map +1 -1
  26. package/build/map/components/overlays/Circle.js +3 -2
  27. package/build/map/components/overlays/Circle.js.map +1 -1
  28. package/build/map/components/overlays/Cluster.d.ts.map +1 -1
  29. package/build/map/components/overlays/Cluster.js +3 -2
  30. package/build/map/components/overlays/Cluster.js.map +1 -1
  31. package/build/map/components/overlays/HeatMap.d.ts.map +1 -1
  32. package/build/map/components/overlays/HeatMap.js +3 -2
  33. package/build/map/components/overlays/HeatMap.js.map +1 -1
  34. package/build/map/components/overlays/Marker.d.ts.map +1 -1
  35. package/build/map/components/overlays/Marker.js +3 -2
  36. package/build/map/components/overlays/Marker.js.map +1 -1
  37. package/build/map/components/overlays/MultiPoint.d.ts.map +1 -1
  38. package/build/map/components/overlays/MultiPoint.js +3 -2
  39. package/build/map/components/overlays/MultiPoint.js.map +1 -1
  40. package/build/map/components/overlays/Polygon.d.ts.map +1 -1
  41. package/build/map/components/overlays/Polygon.js +3 -2
  42. package/build/map/components/overlays/Polygon.js.map +1 -1
  43. package/build/map/components/overlays/Polyline.d.ts.map +1 -1
  44. package/build/map/components/overlays/Polyline.js +3 -2
  45. package/build/map/components/overlays/Polyline.js.map +1 -1
  46. package/build/map/types/common.types.d.ts +26 -0
  47. package/build/map/types/common.types.d.ts.map +1 -1
  48. package/build/map/types/common.types.js.map +1 -1
  49. package/build/map/types/native-module.types.d.ts +28 -1
  50. package/build/map/types/native-module.types.d.ts.map +1 -1
  51. package/build/map/types/native-module.types.js.map +1 -1
  52. package/build/map/utils/ErrorHandler.d.ts +6 -0
  53. package/build/map/utils/ErrorHandler.d.ts.map +1 -1
  54. package/build/map/utils/ErrorHandler.js +42 -0
  55. package/build/map/utils/ErrorHandler.js.map +1 -1
  56. package/build/map/utils/GeoUtils.d.ts.map +1 -1
  57. package/build/map/utils/GeoUtils.js +6 -2
  58. package/build/map/utils/GeoUtils.js.map +1 -1
  59. package/build/map/utils/lazyNativeViewManager.d.ts +3 -0
  60. package/build/map/utils/lazyNativeViewManager.d.ts.map +1 -0
  61. package/build/map/utils/lazyNativeViewManager.js +11 -0
  62. package/build/map/utils/lazyNativeViewManager.js.map +1 -0
  63. package/ios/ExpoGaodeMapNavigation.podspec +5 -0
  64. package/ios/map/ExpoGaodeMapModule.swift +27 -40
  65. package/ios/map/ExpoGaodeMapView.swift +160 -77
  66. package/ios/map/GaodeMapPrivacyManager.swift +155 -0
  67. package/ios/map/modules/LocationManager.swift +43 -24
  68. package/package.json +1 -1
  69. package/android/src/main/java/expo/modules/gaodemap/map/MapPreloadManager.kt +0 -494
  70. package/ios/map/MapPreloadManager.swift +0 -348
@@ -0,0 +1,155 @@
1
+ import AMapFoundationKit
2
+ import AMapLocationKit
3
+ import AMapNaviKit
4
+ import Foundation
5
+
6
+ extension Notification.Name {
7
+ static let gaodeMapPrivacyStatusDidChange = Notification.Name("ExpoGaodeMapPrivacyStatusDidChange")
8
+ }
9
+
10
+ enum GaodeMapPrivacyManager {
11
+ private enum StorageKeys {
12
+ static let hasShow = "expo.gaodemap.privacy.hasShow"
13
+ static let hasContainsPrivacy = "expo.gaodemap.privacy.hasContainsPrivacy"
14
+ static let hasAgree = "expo.gaodemap.privacy.hasAgree"
15
+ static let privacyVersion = "expo.gaodemap.privacy.currentVersion"
16
+ static let agreedPrivacyVersion = "expo.gaodemap.privacy.agreedVersion"
17
+ }
18
+
19
+ private static let defaults = UserDefaults.standard
20
+
21
+ private(set) static var hasShow = false
22
+ private(set) static var hasContainsPrivacy = false
23
+ private(set) static var hasAgree = false
24
+ private(set) static var privacyVersion: String?
25
+ private(set) static var agreedPrivacyVersion: String?
26
+ private(set) static var restoredFromStorage = false
27
+
28
+ static var isReady: Bool {
29
+ hasShow && hasContainsPrivacy && hasAgree
30
+ }
31
+
32
+ static func restorePersistedState() {
33
+ hasShow = defaults.bool(forKey: StorageKeys.hasShow)
34
+ hasContainsPrivacy = defaults.bool(forKey: StorageKeys.hasContainsPrivacy)
35
+ hasAgree = defaults.bool(forKey: StorageKeys.hasAgree)
36
+ privacyVersion = defaults.string(forKey: StorageKeys.privacyVersion)
37
+ agreedPrivacyVersion = defaults.string(forKey: StorageKeys.agreedPrivacyVersion)
38
+ restoredFromStorage = true
39
+
40
+ if let version = privacyVersion,
41
+ let agreedVersion = agreedPrivacyVersion,
42
+ version != agreedVersion {
43
+ clearConsentPersistedState(keepCurrentVersion: true)
44
+ }
45
+
46
+ applyPrivacyState()
47
+ }
48
+
49
+ static func setPrivacyShow(_ show: Bool, hasContainsPrivacy: Bool) {
50
+ let previousStatus = status()
51
+ hasShow = show
52
+ self.hasContainsPrivacy = hasContainsPrivacy
53
+ persistState()
54
+ applyPrivacyState()
55
+ notifyIfNeeded(previousStatus: previousStatus)
56
+ }
57
+
58
+ static func setPrivacyAgree(_ agree: Bool) {
59
+ let previousStatus = status()
60
+ hasAgree = agree
61
+ agreedPrivacyVersion = agree ? privacyVersion : nil
62
+ persistState()
63
+ applyPrivacyState()
64
+ notifyIfNeeded(previousStatus: previousStatus)
65
+ }
66
+
67
+ static func setPrivacyVersion(_ version: String) {
68
+ let previousStatus = status()
69
+ privacyVersion = version.trimmingCharacters(in: .whitespacesAndNewlines)
70
+ if privacyVersion?.isEmpty == true {
71
+ privacyVersion = nil
72
+ }
73
+
74
+ if let currentVersion = privacyVersion,
75
+ let agreedVersion = agreedPrivacyVersion,
76
+ currentVersion != agreedVersion {
77
+ clearConsentPersistedState(keepCurrentVersion: true)
78
+ } else {
79
+ persistState()
80
+ }
81
+
82
+ applyPrivacyState()
83
+ notifyIfNeeded(previousStatus: previousStatus)
84
+ }
85
+
86
+ static func resetPrivacyConsent() {
87
+ let previousStatus = status()
88
+ clearConsentPersistedState(keepCurrentVersion: false)
89
+ applyPrivacyState()
90
+ notifyIfNeeded(previousStatus: previousStatus)
91
+ }
92
+
93
+ static func applyPrivacyState() {
94
+ let showStatus: AMapPrivacyShowStatus = hasShow ? .didShow : .notShow
95
+ let infoStatus: AMapPrivacyInfoStatus = hasContainsPrivacy ? .didContain : .notContain
96
+ let agreeStatus: AMapPrivacyAgreeStatus = hasAgree ? .didAgree : .notAgree
97
+
98
+ MAMapView.updatePrivacyShow(showStatus, privacyInfo: infoStatus)
99
+ MAMapView.updatePrivacyAgree(agreeStatus)
100
+ AMapLocationManager.updatePrivacyShow(showStatus, privacyInfo: infoStatus)
101
+ AMapLocationManager.updatePrivacyAgree(agreeStatus)
102
+ }
103
+
104
+ static func status() -> [String: Any] {
105
+ [
106
+ "hasShow": hasShow,
107
+ "hasContainsPrivacy": hasContainsPrivacy,
108
+ "hasAgree": hasAgree,
109
+ "isReady": isReady,
110
+ "privacyVersion": privacyVersion ?? NSNull(),
111
+ "agreedPrivacyVersion": agreedPrivacyVersion ?? NSNull(),
112
+ "restoredFromStorage": restoredFromStorage,
113
+ ]
114
+ }
115
+
116
+ private static func persistState() {
117
+ defaults.set(hasShow, forKey: StorageKeys.hasShow)
118
+ defaults.set(hasContainsPrivacy, forKey: StorageKeys.hasContainsPrivacy)
119
+ defaults.set(hasAgree, forKey: StorageKeys.hasAgree)
120
+ defaults.set(privacyVersion, forKey: StorageKeys.privacyVersion)
121
+ defaults.set(agreedPrivacyVersion, forKey: StorageKeys.agreedPrivacyVersion)
122
+ }
123
+
124
+ private static func clearConsentPersistedState(keepCurrentVersion: Bool) {
125
+ hasShow = false
126
+ hasContainsPrivacy = false
127
+ hasAgree = false
128
+ agreedPrivacyVersion = nil
129
+
130
+ defaults.set(false, forKey: StorageKeys.hasShow)
131
+ defaults.set(false, forKey: StorageKeys.hasContainsPrivacy)
132
+ defaults.set(false, forKey: StorageKeys.hasAgree)
133
+ defaults.removeObject(forKey: StorageKeys.agreedPrivacyVersion)
134
+
135
+ if keepCurrentVersion {
136
+ defaults.set(privacyVersion, forKey: StorageKeys.privacyVersion)
137
+ } else {
138
+ privacyVersion = nil
139
+ defaults.removeObject(forKey: StorageKeys.privacyVersion)
140
+ }
141
+ }
142
+
143
+ private static func notifyIfNeeded(previousStatus: [String: Any]) {
144
+ let currentStatus = status()
145
+ guard NSDictionary(dictionary: previousStatus).isEqual(to: currentStatus) == false else {
146
+ return
147
+ }
148
+
149
+ NotificationCenter.default.post(
150
+ name: .gaodeMapPrivacyStatusDidChange,
151
+ object: nil,
152
+ userInfo: currentStatus
153
+ )
154
+ }
155
+ }
@@ -28,18 +28,17 @@ class LocationManager: NSObject, AMapLocationManagerDelegate {
28
28
 
29
29
  override init() {
30
30
  super.init()
31
- initLocationManager()
32
31
  }
33
32
 
34
33
  // MARK: - 连续定位控制
35
34
 
36
35
  func start() {
37
- locationManager?.startUpdatingLocation()
36
+ ensureLocationManager()?.startUpdatingLocation()
38
37
  isLocationStarted = true
39
38
  }
40
39
 
41
40
  func stop() {
42
- locationManager?.stopUpdatingLocation()
41
+ ensureLocationManager()?.stopUpdatingLocation()
43
42
  isLocationStarted = false
44
43
  }
45
44
 
@@ -50,19 +49,19 @@ class LocationManager: NSObject, AMapLocationManagerDelegate {
50
49
  // MARK: - 高德定位配置 API
51
50
 
52
51
  func setLocatingWithReGeocode(_ isReGeocode: Bool) {
53
- locationManager?.locatingWithReGeocode = isReGeocode
52
+ ensureLocationManager()?.locatingWithReGeocode = isReGeocode
54
53
  }
55
54
 
56
55
  func setDistanceFilter(_ distance: Double) {
57
- locationManager?.distanceFilter = distance
56
+ ensureLocationManager()?.distanceFilter = distance
58
57
  }
59
58
 
60
59
  func setLocationTimeout(_ timeout: Int) {
61
- locationManager?.locationTimeout = timeout
60
+ ensureLocationManager()?.locationTimeout = timeout
62
61
  }
63
62
 
64
63
  func setReGeocodeTimeout(_ timeout: Int) {
65
- locationManager?.reGeocodeTimeout = timeout
64
+ ensureLocationManager()?.reGeocodeTimeout = timeout
66
65
  }
67
66
 
68
67
  func setDesiredAccuracy(_ accuracy: Int) {
@@ -76,11 +75,11 @@ class LocationManager: NSObject, AMapLocationManagerDelegate {
76
75
  case 5: value = kCLLocationAccuracyThreeKilometers
77
76
  default: value = kCLLocationAccuracyBest
78
77
  }
79
- locationManager?.desiredAccuracy = value
78
+ ensureLocationManager()?.desiredAccuracy = value
80
79
  }
81
80
 
82
81
  func setPausesLocationUpdatesAutomatically(_ pauses: Bool) {
83
- locationManager?.pausesLocationUpdatesAutomatically = pauses
82
+ ensureLocationManager()?.pausesLocationUpdatesAutomatically = pauses
84
83
  }
85
84
 
86
85
  func setAllowsBackgroundLocationUpdates(_ allows: Bool) {
@@ -91,14 +90,14 @@ class LocationManager: NSObject, AMapLocationManagerDelegate {
91
90
  return
92
91
  }
93
92
  }
94
- locationManager?.allowsBackgroundLocationUpdates = allows
93
+ ensureLocationManager()?.allowsBackgroundLocationUpdates = allows
95
94
  }
96
95
 
97
96
  func setGeoLanguage(_ language: Int) {
98
97
  switch language {
99
- case 0: locationManager?.reGeocodeLanguage = .default
100
- case 1: locationManager?.reGeocodeLanguage = .chinse
101
- case 2: locationManager?.reGeocodeLanguage = .english
98
+ case 0: ensureLocationManager()?.reGeocodeLanguage = .default
99
+ case 1: ensureLocationManager()?.reGeocodeLanguage = .chinse
100
+ case 2: ensureLocationManager()?.reGeocodeLanguage = .english
102
101
  default: break
103
102
  }
104
103
  }
@@ -106,26 +105,41 @@ class LocationManager: NSObject, AMapLocationManagerDelegate {
106
105
  // MARK: - 方向
107
106
 
108
107
  func startUpdatingHeading() {
109
- locationManager?.startUpdatingHeading()
108
+ ensureLocationManager()?.startUpdatingHeading()
110
109
  }
111
110
 
112
111
  func stopUpdatingHeading() {
113
- locationManager?.stopUpdatingHeading()
112
+ ensureLocationManager()?.stopUpdatingHeading()
114
113
  }
115
114
 
116
115
  // MARK: - 初始化
117
116
 
118
- private func initLocationManager() {
119
- locationManager = AMapLocationManager()
120
- locationManager?.delegate = self
117
+ @discardableResult
118
+ private func ensureLocationManager() -> AMapLocationManager? {
119
+ if let locationManager {
120
+ return locationManager
121
+ }
122
+
123
+ guard GaodeMapPrivacyManager.isReady else {
124
+ log.warn("⚠️ [ExpoGaodeMap] iOS 定位模块在隐私同意前不会初始化 AMapLocationManager")
125
+ return nil
126
+ }
127
+
128
+ GaodeMapPrivacyManager.applyPrivacyState()
129
+
130
+ let manager = AMapLocationManager()
131
+ manager.delegate = self
121
132
 
122
133
  // 默认配置
123
- locationManager?.desiredAccuracy = kCLLocationAccuracyHundredMeters
124
- locationManager?.distanceFilter = 10
125
- locationManager?.locationTimeout = 10
126
- locationManager?.reGeocodeTimeout = 5
127
- locationManager?.locatingWithReGeocode = true
128
- locationManager?.pausesLocationUpdatesAutomatically = false
134
+ manager.desiredAccuracy = kCLLocationAccuracyHundredMeters
135
+ manager.distanceFilter = 10
136
+ manager.locationTimeout = 10
137
+ manager.reGeocodeTimeout = 5
138
+ manager.locatingWithReGeocode = true
139
+ manager.pausesLocationUpdatesAutomatically = false
140
+
141
+ locationManager = manager
142
+ return manager
129
143
  }
130
144
 
131
145
  // MARK: - Delegate(连续定位回调)
@@ -184,6 +198,11 @@ class LocationManager: NSObject, AMapLocationManagerDelegate {
184
198
  * @param promise Promise
185
199
  */
186
200
  func coordinateConvert(_ coordinate: [String: Double], type: Int, promise: Promise) {
201
+ guard GaodeMapPrivacyManager.isReady else {
202
+ promise.reject("PRIVACY_NOT_AGREED", "隐私协议未完成确认,请先调用 setPrivacyShow/setPrivacyAgree")
203
+ return
204
+ }
205
+
187
206
  guard let lat = coordinate["latitude"],
188
207
  let lon = coordinate["longitude"] else {
189
208
  promise.reject("INVALID_ARGUMENT", "Invalid coordinate")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-gaode-map-navigation",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "高德地图导航功能模块 - 路径规划、导航引导,独立版本包含完整地图功能",
5
5
  "author": "<TomWq> (https://github.com/TomWq)",
6
6
  "repository": "https://github.com/TomWq/expo-gaode-map",