expo-gaode-map 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.
@@ -266,16 +266,12 @@ public class ExpoGaodeMapModule: Module {
266
266
  }
267
267
 
268
268
  self.permissionManager?.requestPermission { granted, status in
269
- print("🔐 [PermissionManager] 权限回调: granted=\(granted), status=\(status)")
270
-
271
269
  // 无论结果如何,都延迟后再次检查最终状态
272
270
  DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
273
271
  let finalStatus = CLLocationManager.authorizationStatus()
274
272
  let finalGranted = finalStatus == .authorizedAlways || finalStatus == .authorizedWhenInUse
275
273
  let finalStatusString = self.getAuthorizationStatusString(finalStatus)
276
274
 
277
- print("🔐 [PermissionManager] 最终状态: granted=\(finalGranted), status=\(finalStatusString)")
278
-
279
275
  promise.resolve([
280
276
  "granted": finalGranted,
281
277
  "status": finalStatusString
@@ -82,41 +82,35 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate {
82
82
  private var isMapLoaded = false
83
83
  /// 是否正在处理 annotation 选择事件
84
84
  private var isHandlingAnnotationSelect = false
85
+ /// MarkerView 的隐藏容器(用于渲染 children)
86
+ private var markerContainer: UIView!
85
87
 
86
88
  // MARK: - 初始化
87
89
 
88
90
  required init(appContext: AppContext? = nil) {
89
91
  super.init(appContext: appContext)
90
92
 
91
- print("🗺️ [MapView Init] 开始初始化地图视图")
92
- print("🗺️ [MapView Init] bounds: \(bounds)")
93
-
94
93
  // 确保隐私合规已设置
95
94
  MAMapView.updatePrivacyAgree(.didAgree)
96
95
  MAMapView.updatePrivacyShow(.didShow, privacyInfo: .didContain)
97
- print("🗺️ [MapView Init] 隐私合规设置完成")
98
96
 
99
- // 创建 MAMapView(注意:如果 API Key 未设置,可能会在后续操作时报错)
97
+ // 创建 MAMapView
100
98
  mapView = MAMapView(frame: bounds)
101
99
 
102
- // 检查是否创建成功
103
- if mapView == nil {
104
- print("❌ [MapView Init] MAMapView 创建失败!请检查:")
105
- print("❌ [MapView Init] 1. iOS API Key 是否已正确配置")
106
- print("❌ [MapView Init] 2. 是否调用了 initSDK({ iosKey: 'your_key' })")
107
- print("❌ [MapView Init] 3. API Key 是否有效")
108
- } else {
109
- print("🗺️ [MapView Init] ✅ MAMapView 创建成功, frame: \(mapView.frame)")
110
- }
111
-
112
100
  mapView.delegate = self
113
101
  mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
114
102
 
115
- // 立即添加 mapView 到视图层级,确保地图可见
103
+ // 创建 MarkerView 隐藏容器
104
+ markerContainer = UIView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
105
+ markerContainer.isHidden = true
106
+ markerContainer.isUserInteractionEnabled = false
107
+ markerContainer.alpha = 0
108
+
109
+ // 先添加隐藏容器(在最底层)
110
+ addSubview(markerContainer)
111
+
112
+ // 再添加 mapView(在隐藏容器之上,确保地图可以接收触摸)
116
113
  addSubview(mapView)
117
- print("🗺️ [MapView Init] ✅ mapView 已添加到视图层级")
118
- print("🗺️ [MapView Init] mapView.superview: \(mapView.superview != nil ? "存在" : "nil")")
119
- print("🗺️ [MapView Init] subviews.count: \(subviews.count)")
120
114
 
121
115
  cameraManager = CameraManager(mapView: mapView)
122
116
  uiManager = UIManager(mapView: mapView)
@@ -145,17 +139,11 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate {
145
139
  }
146
140
 
147
141
  setupDefaultConfig()
148
- print("🗺️ [MapView Init] 初始化完成")
149
142
  }
150
143
 
151
144
  override func layoutSubviews() {
152
145
  super.layoutSubviews()
153
- print("🗺️ [MapView Layout] layoutSubviews 被调用")
154
- print("🗺️ [MapView Layout] 旧 frame: \(mapView.frame), 新 bounds: \(bounds)")
155
146
  mapView.frame = bounds
156
- print("🗺️ [MapView Layout] mapView frame 已更新: \(mapView.frame)")
157
- print("🗺️ [MapView Layout] mapView.superview: \(mapView.superview != nil ? "存在" : "nil")")
158
- print("🗺️ [MapView Layout] subviews.count: \(subviews.count)")
159
147
 
160
148
  // 收集并设置 MarkerView
161
149
  collectAndSetupMarkerViews()
@@ -165,7 +153,8 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate {
165
153
  * 收集所有 MarkerView 子视图并设置地图
166
154
  */
167
155
  private func collectAndSetupMarkerViews() {
168
- for subview in subviews {
156
+ // 从隐藏容器中收集 MarkerView
157
+ for subview in markerContainer.subviews {
169
158
  if let markerView = subview as? MarkerView {
170
159
  markerView.setMap(mapView)
171
160
  }
@@ -177,16 +166,17 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate {
177
166
  * 将地图实例传递给覆盖物子视图
178
167
  */
179
168
  override func addSubview(_ view: UIView) {
180
- super.addSubview(view)
181
-
182
169
  if let markerView = view as? MarkerView {
183
- // MarkerView 需要添加到视图层级以便其 children 可以渲染
184
- // 但将其移到屏幕外,使其不可见
185
- markerView.frame = CGRect(x: -10000, y: -10000, width: 1, height: 1)
170
+ // 关键修复:将 MarkerView 添加到隐藏容器中,而不是主视图
171
+ // 这样 MarkerView 完全不会影响地图的触摸事件
172
+ markerContainer.addSubview(markerView)
186
173
  markerView.setMap(mapView)
187
174
  return
188
175
  }
189
176
 
177
+ // 其他视图正常添加
178
+ super.addSubview(view)
179
+
190
180
  if let circleView = view as? CircleView {
191
181
  circleView.setMap(mapView)
192
182
  } else if let polylineView = view as? PolylineView {
@@ -221,16 +211,10 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate {
221
211
  * 在 Props 更新时调用
222
212
  */
223
213
  func applyProps() {
224
- print("🗺️ [MapView Props] applyProps 被调用")
225
- print("🗺️ [MapView Props] mapView.superview: \(mapView.superview != nil ? "存在" : "nil")")
226
- print("🗺️ [MapView Props] mapView.frame: \(mapView.frame)")
227
- print("🗺️ [MapView Props] initialCameraPosition: \(initialCameraPosition != nil ? "存在" : "nil")")
228
-
229
214
  uiManager.setMapType(mapType)
230
215
 
231
216
  // 如果有初始位置,设置相机位置
232
217
  if let position = initialCameraPosition {
233
- print("🗺️ [MapView Props] 设置初始相机位置: \(position)")
234
218
  cameraManager.setInitialCameraPosition(position)
235
219
  }
236
220
 
@@ -247,10 +231,6 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate {
247
231
 
248
232
  // 收集并设置所有 MarkerView
249
233
  collectAndSetupMarkerViews()
250
-
251
- print("🗺️ [MapView Props] Props 应用完成")
252
- print("🗺️ [MapView Props] 最终 mapView.superview: \(mapView.superview != nil ? "存在" : "nil")")
253
- print("🗺️ [MapView Props] 最终 subviews.count: \(subviews.count)")
254
234
  }
255
235
 
256
236
  // MARK: - 缩放控制
@@ -384,16 +364,8 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate {
384
364
  * 析构函数 - 清理资源
385
365
  */
386
366
  deinit {
387
- print("🗺️ [MapView] deinit 开始清理")
388
-
389
367
  // 先设置 delegate 为 nil,停止接收回调
390
368
  mapView?.delegate = nil
391
-
392
- // 不调用 overlayManager.clear()
393
- // 因为声明式的 Marker/Circle 等会在自己的 willMove(toSuperview:) 中清理
394
- // 调用 clear() 可能导致重复移除和崩溃
395
-
396
- print("🗺️ [MapView] deinit 完成")
397
369
  }
398
370
  }
399
371
 
@@ -406,9 +378,6 @@ extension ExpoGaodeMapView {
406
378
  public func mapViewDidFinishLoadingMap(_ mapView: MAMapView) {
407
379
  guard !isMapLoaded else { return }
408
380
  isMapLoaded = true
409
- print("🗺️ [MapView Delegate] ✅ 地图加载完成")
410
- print("🗺️ [MapView Delegate] mapView.frame: \(mapView.frame)")
411
- print("🗺️ [MapView Delegate] mapView.superview: \(mapView.superview != nil ? "存在" : "nil")")
412
381
  onLoad(["loaded": true])
413
382
  }
414
383
 
@@ -460,20 +429,14 @@ extension ExpoGaodeMapView {
460
429
  */
461
430
  private func checkCirclePress(at coordinate: CLLocationCoordinate2D) -> Bool {
462
431
  let circleViews = subviews.compactMap { $0 as? CircleView }
463
- print("🔍 检查圆形点击 - 找到 \(circleViews.count) 个 CircleView")
464
432
 
465
433
  for circleView in circleViews {
466
- guard let circle = circleView.circle else {
467
- print("⚠️ CircleView 没有 circle 对象")
468
- continue
469
- }
434
+ guard let circle = circleView.circle else { continue }
470
435
 
471
436
  let circleCenter = circle.coordinate
472
437
  let distance = calculateDistance(from: coordinate, to: circleCenter)
473
- print("📍 圆心: (\(circleCenter.latitude), \(circleCenter.longitude)), 半径: \(circle.radius)m, 距离: \(distance)m")
474
438
 
475
439
  if distance <= circle.radius {
476
- print("✅ 点击在圆形内,触发 onPress")
477
440
  circleView.onPress([
478
441
  "latitude": coordinate.latitude,
479
442
  "longitude": coordinate.longitude
@@ -481,7 +444,6 @@ extension ExpoGaodeMapView {
481
444
  return true
482
445
  }
483
446
  }
484
- print("❌ 点击不在任何圆形内")
485
447
  return false
486
448
  }
487
449
 
@@ -631,16 +593,15 @@ extension ExpoGaodeMapView {
631
593
 
632
594
  if annotation.isKind(of: MAPointAnnotation.self) {
633
595
  // 首先检查是否是声明式 MarkerView 的 annotation
634
- for subview in subviews {
596
+ // 从隐藏容器中查找 MarkerView
597
+ for subview in markerContainer.subviews {
635
598
  if let markerView = subview as? MarkerView, markerView.annotation === annotation {
636
- print("🎯 [MapView Delegate] 找到声明式 MarkerView,调用其 getAnnotationView")
637
599
  return markerView.getAnnotationView(for: mapView, annotation: annotation)
638
600
  }
639
601
  }
640
602
 
641
603
  // 如果不是声明式的,检查是否是命令式 API 的 Marker
642
604
  guard let props = overlayManager.getMarkerProps(for: annotation) else {
643
- print("⚠️ [MapView Delegate] 未找到对应的 Marker props")
644
605
  return nil
645
606
  }
646
607
 
@@ -320,20 +320,16 @@ class OverlayManager {
320
320
 
321
321
  // 设置纹理或颜色
322
322
  if let textureUrl = style?["texture"] as? String, !textureUrl.isEmpty {
323
- print("🔷 OverlayManager: 加载纹理 \(textureUrl)")
324
323
  loadPolylineTexture(url: textureUrl, renderer: renderer)
325
324
  } else {
326
325
  if let color = style?["color"] {
327
326
  let parsedColor = ColorParser.parseColor(color)
328
327
  renderer.strokeColor = parsedColor ?? .red
329
- print("🔷 OverlayManager: color=\(color) -> \(String(describing: parsedColor))")
330
328
  } else if let strokeColor = style?["strokeColor"] {
331
329
  let parsedColor = ColorParser.parseColor(strokeColor)
332
330
  renderer.strokeColor = parsedColor ?? .red
333
- print("🔷 OverlayManager: strokeColor=\(strokeColor) -> \(String(describing: parsedColor))")
334
331
  } else {
335
332
  renderer.strokeColor = .red
336
- print("🔷 OverlayManager: 使用默认红色")
337
333
  }
338
334
  }
339
335
 
@@ -343,8 +339,6 @@ class OverlayManager {
343
339
  return nil
344
340
  }
345
341
 
346
- print("🔶 OverlayManager.getRenderer(Polygon): style=\(String(describing: style))")
347
-
348
342
  // 设置填充颜色
349
343
  if let fillColor = style?["fillColor"] {
350
344
  let parsedColor = ColorParser.parseColor(fillColor)
@@ -119,7 +119,6 @@ class CircleView: ExpoView {
119
119
  * @param color 颜色值
120
120
  */
121
121
  func setFillColor(_ color: Any?) {
122
- print("🔵 CircleView.setFillColor: \(String(describing: color))")
123
122
  fillColor = color
124
123
  renderer = nil
125
124
  updateCircle()
@@ -130,7 +129,6 @@ class CircleView: ExpoView {
130
129
  * @param color 颜色值
131
130
  */
132
131
  func setStrokeColor(_ color: Any?) {
133
- print("🔵 CircleView.setStrokeColor: \(String(describing: color))")
134
132
  strokeColor = color
135
133
  renderer = nil
136
134
  updateCircle()
@@ -141,7 +139,6 @@ class CircleView: ExpoView {
141
139
  * @param width 宽度值
142
140
  */
143
141
  func setStrokeWidth(_ width: Float) {
144
- print("🔵 CircleView.setStrokeWidth: \(width)")
145
142
  strokeWidth = width
146
143
  renderer = nil
147
144
  updateCircle()
@@ -5,8 +5,6 @@ public class ClusterViewModule: Module {
5
5
  Name("ClusterView")
6
6
 
7
7
  View(ClusterView.self) {
8
- Events("onPress", "onClusterPress")
9
-
10
8
  Prop("points") { (view: ClusterView, points: [[String: Any]]) in
11
9
  view.setPoints(points)
12
10
  }
@@ -63,8 +63,28 @@ class MarkerView: ExpoView {
63
63
 
64
64
  required init(appContext: AppContext? = nil) {
65
65
  super.init(appContext: appContext)
66
- // 不可交互,通过父视图定位到屏幕外
66
+ // 完全禁用交互,让触摸事件穿透
67
67
  isUserInteractionEnabled = false
68
+ // 关键:让所有子视图也不接收触摸事件
69
+ isMultipleTouchEnabled = false
70
+ isExclusiveTouch = false
71
+ }
72
+
73
+ /**
74
+ * 重写 hitTest,让触摸事件完全穿透此视图
75
+ * 这是解决旧架构下 children 阻挡地图触摸的关键
76
+ */
77
+ override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
78
+ // 始终返回 nil,让触摸事件穿透到地图
79
+ return nil
80
+ }
81
+
82
+ /**
83
+ * 重写 point(inside:with:),确保此视图不响应任何触摸
84
+ */
85
+ override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
86
+ // 始终返回 false,表示点击不在此视图内
87
+ return false
68
88
  }
69
89
 
70
90
  /**
@@ -90,12 +110,9 @@ class MarkerView: ExpoView {
90
110
  guard let mapView = mapView,
91
111
  let latitude = position["latitude"],
92
112
  let longitude = position["longitude"] else {
93
- print("⚠️ [MarkerView] updateAnnotation: mapView 或坐标为 nil")
94
113
  return
95
114
  }
96
115
 
97
- print("📍 [MarkerView] updateAnnotation: 位置 (\(latitude), \(longitude)), subviews: \(self.subviews.count)")
98
-
99
116
  // 取消之前的延迟任务
100
117
  pendingAddTask?.cancel()
101
118
 
@@ -5,8 +5,6 @@ public class MultiPointViewModule: Module {
5
5
  Name("MultiPointView")
6
6
 
7
7
  View(MultiPointView.self) {
8
- Events("onPress")
9
-
10
8
  Prop("points") { (view: MultiPointView, points: [[String: Any]]) in
11
9
  view.setPoints(points)
12
10
  }
@@ -45,29 +45,19 @@ class PolygonView: ExpoView {
45
45
  * 更新多边形覆盖物
46
46
  */
47
47
  private func updatePolygon() {
48
- guard let mapView = mapView else {
49
- print("❌ PolygonView.updatePolygon: mapView 为空")
50
- return
51
- }
48
+ guard let mapView = mapView else { return }
52
49
  if let old = polygon { mapView.remove(old) }
53
50
 
54
51
  var coords = points.compactMap { point -> CLLocationCoordinate2D? in
55
52
  guard let lat = point["latitude"], let lng = point["longitude"] else { return nil }
56
53
  return CLLocationCoordinate2D(latitude: lat, longitude: lng)
57
54
  }
58
- guard !coords.isEmpty else {
59
- print("❌ PolygonView.updatePolygon: 点数组为空")
60
- return
61
- }
62
-
63
- print("🔶 PolygonView.updatePolygon: points=\(coords.count)个点")
64
- print("🔶 PolygonView.updatePolygon: fillColor=\(String(describing: fillColor)), strokeColor=\(String(describing: strokeColor)), strokeWidth=\(strokeWidth)")
55
+ guard !coords.isEmpty else { return }
65
56
 
66
57
  polygon = MAPolygon(coordinates: &coords, count: UInt(coords.count))
67
58
  mapView.add(polygon!)
68
59
 
69
60
  renderer = nil
70
- print("🔶 PolygonView.updatePolygon: renderer 已清空")
71
61
  }
72
62
 
73
63
  /**
@@ -48,29 +48,19 @@ class PolylineView: ExpoView {
48
48
  * 更新折线覆盖物
49
49
  */
50
50
  private func updatePolyline() {
51
- guard let mapView = mapView else {
52
- print("❌ PolylineView.updatePolyline: mapView 为空")
53
- return
54
- }
51
+ guard let mapView = mapView else { return }
55
52
  if let old = polyline { mapView.remove(old) }
56
53
 
57
54
  var coords = points.compactMap { point -> CLLocationCoordinate2D? in
58
55
  guard let lat = point["latitude"], let lng = point["longitude"] else { return nil }
59
56
  return CLLocationCoordinate2D(latitude: lat, longitude: lng)
60
57
  }
61
- guard !coords.isEmpty else {
62
- print("❌ PolylineView.updatePolyline: 点数组为空")
63
- return
64
- }
65
-
66
- print("🔷 PolylineView.updatePolyline: points=\(coords.count)个点")
67
- print("🔷 PolylineView.updatePolyline: strokeColor=\(String(describing: strokeColor)), strokeWidth=\(strokeWidth), texture=\(String(describing: textureUrl))")
58
+ guard !coords.isEmpty else { return }
68
59
 
69
60
  polyline = MAPolyline(coordinates: &coords, count: UInt(coords.count))
70
61
  mapView.add(polyline!)
71
62
 
72
63
  renderer = nil
73
- print("🔷 PolylineView.updatePolyline: renderer 已清空")
74
64
  }
75
65
 
76
66
  /**
@@ -20,7 +20,6 @@ class PermissionManager: NSObject, CLLocationManagerDelegate {
20
20
  * @param callback 权限结果回调 (granted, status)
21
21
  */
22
22
  func requestPermission(callback: @escaping (Bool, String) -> Void) {
23
- print("🔐 [PermissionManager] requestPermission 被调用")
24
23
  self.permissionCallback = callback
25
24
 
26
25
  // 确保在主线程操作
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-gaode-map",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "一个功能完整的高德地图 React Native 组件库,基于 Expo Modules 开发,提供地图显示、定位、覆盖物等功能。",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",