expo-gaode-map-navigation 2.0.7-next.0 → 2.0.8-next.0
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/ios/map/overlays/MarkerView.swift +149 -12
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ExpoModulesCore
|
|
2
|
-
import
|
|
2
|
+
import MAMapKit
|
|
3
3
|
import UIKit
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -154,9 +154,9 @@ class MarkerView: ExpoView {
|
|
|
154
154
|
|
|
155
155
|
// JS 侧可以调用
|
|
156
156
|
func setCacheKey(_ key: String?) {
|
|
157
|
+
guard cacheKey != key else { return }
|
|
157
158
|
self.cacheKey = key
|
|
158
|
-
|
|
159
|
-
updateAnnotation()
|
|
159
|
+
refreshAnnotationAppearance(invalidateChildrenCache: !subviews.isEmpty)
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
/**
|
|
@@ -246,8 +246,6 @@ class MarkerView: ExpoView {
|
|
|
246
246
|
if let generated = self.createImageFromSubviews() {
|
|
247
247
|
annotationView.image = generated
|
|
248
248
|
self.applyCenterOffset(to: annotationView, defaultOffset: .zero)
|
|
249
|
-
} else if self.hasPendingImageContent() {
|
|
250
|
-
self.scheduleSubviewRefresh(allowFallbackToDefault: false)
|
|
251
249
|
}
|
|
252
250
|
}
|
|
253
251
|
return annotationView
|
|
@@ -255,10 +253,12 @@ class MarkerView: ExpoView {
|
|
|
255
253
|
|
|
256
254
|
// 2. 如果有 icon 属性,使用自定义图标
|
|
257
255
|
if let iconUri = iconUri, !iconUri.isEmpty {
|
|
258
|
-
let key =
|
|
256
|
+
let key = iconCacheKey(for: iconUri)
|
|
259
257
|
if let cached = IconBitmapCache.shared.image(forKey: key) {
|
|
260
258
|
annotationView?.image = cached
|
|
261
|
-
annotationView
|
|
259
|
+
if let annotationView = annotationView {
|
|
260
|
+
applyCenterOffset(to: annotationView, defaultOffset: CGPoint(x: 0, y: -cached.size.height / 2))
|
|
261
|
+
}
|
|
262
262
|
return annotationView
|
|
263
263
|
}
|
|
264
264
|
|
|
@@ -274,7 +274,7 @@ class MarkerView: ExpoView {
|
|
|
274
274
|
if let img = resizedImage {
|
|
275
275
|
IconBitmapCache.shared.setImage(img, forKey: key)
|
|
276
276
|
annotationView.image = img
|
|
277
|
-
|
|
277
|
+
self.applyCenterOffset(to: annotationView, defaultOffset: CGPoint(x: 0, y: -img.size.height / 2))
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
return annotationView
|
|
@@ -391,10 +391,12 @@ class MarkerView: ExpoView {
|
|
|
391
391
|
self.annotationView = annotationView
|
|
392
392
|
|
|
393
393
|
// 构建 key
|
|
394
|
-
let key =
|
|
394
|
+
let key = iconCacheKey(for: iconUri)
|
|
395
395
|
if let cached = IconBitmapCache.shared.image(forKey: key) {
|
|
396
396
|
annotationView?.image = cached
|
|
397
|
-
annotationView
|
|
397
|
+
if let annotationView = annotationView {
|
|
398
|
+
applyCenterOffset(to: annotationView, defaultOffset: CGPoint(x: 0, y: -cached.size.height / 2))
|
|
399
|
+
}
|
|
398
400
|
return annotationView
|
|
399
401
|
}
|
|
400
402
|
|
|
@@ -411,7 +413,9 @@ class MarkerView: ExpoView {
|
|
|
411
413
|
if let img = resizedImage {
|
|
412
414
|
IconBitmapCache.shared.setImage(img, forKey: key)
|
|
413
415
|
annotationView?.image = img
|
|
414
|
-
annotationView
|
|
416
|
+
if let annotationView = annotationView {
|
|
417
|
+
self.applyCenterOffset(to: annotationView, defaultOffset: CGPoint(x: 0, y: -img.size.height / 2))
|
|
418
|
+
}
|
|
415
419
|
}
|
|
416
420
|
}
|
|
417
421
|
}
|
|
@@ -451,6 +455,9 @@ class MarkerView: ExpoView {
|
|
|
451
455
|
pinView?.canShowCallout = canShowCallout
|
|
452
456
|
pinView?.isDraggable = draggable
|
|
453
457
|
pinView?.animatesDrop = animatesDrop
|
|
458
|
+
if let pinView = pinView {
|
|
459
|
+
applyCenterOffset(to: pinView, defaultOffset: .zero)
|
|
460
|
+
}
|
|
454
461
|
|
|
455
462
|
self.annotationView = pinView
|
|
456
463
|
return pinView
|
|
@@ -538,6 +545,41 @@ class MarkerView: ExpoView {
|
|
|
538
545
|
return image
|
|
539
546
|
}
|
|
540
547
|
|
|
548
|
+
private func iconCacheKey(for iconUri: String) -> String {
|
|
549
|
+
let baseKey = cacheKey ?? "icon|\(iconUri)"
|
|
550
|
+
return "\(baseKey)|\(Int(iconWidth.rounded()))x\(Int(iconHeight.rounded()))"
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
private func applyCenterOffset(to annotationView: MAAnnotationView, defaultOffset: CGPoint) {
|
|
554
|
+
annotationView.centerOffset = resolvedCenterOffset(defaultOffset: defaultOffset)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
private func resolvedCenterOffset(defaultOffset: CGPoint) -> CGPoint {
|
|
558
|
+
guard let centerOffset else {
|
|
559
|
+
return defaultOffset
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
let x = centerOffset["x"] ?? Double(defaultOffset.x)
|
|
563
|
+
let y = centerOffset["y"] ?? Double(defaultOffset.y)
|
|
564
|
+
return CGPoint(x: x, y: y)
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
private func currentDefaultCenterOffset() -> CGPoint {
|
|
568
|
+
if !subviews.isEmpty {
|
|
569
|
+
return .zero
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
if let image = annotationView?.image ?? animatedAnnotationView?.image {
|
|
573
|
+
return CGPoint(x: 0, y: -image.size.height / 2)
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
if let iconUri, !iconUri.isEmpty {
|
|
577
|
+
return CGPoint(x: 0, y: -iconHeight / 2)
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return .zero
|
|
581
|
+
}
|
|
582
|
+
|
|
541
583
|
private func resolvedCustomSubviewSize(defaultSize: CGSize) -> CGSize {
|
|
542
584
|
guard let firstSubview = subviews.first else {
|
|
543
585
|
return defaultSize
|
|
@@ -808,6 +850,45 @@ class MarkerView: ExpoView {
|
|
|
808
850
|
IconBitmapCache.shared.removeImage(forKey: childrenCacheKey(for: size))
|
|
809
851
|
}
|
|
810
852
|
}
|
|
853
|
+
|
|
854
|
+
private func refreshAnnotationAppearance(invalidateChildrenCache: Bool = false) {
|
|
855
|
+
guard !isRemoving else { return }
|
|
856
|
+
|
|
857
|
+
let refresh = { [weak self] in
|
|
858
|
+
guard let self = self, let mapView = self.mapView else { return }
|
|
859
|
+
|
|
860
|
+
self.pendingSubviewRefreshTask?.cancel()
|
|
861
|
+
self.pendingSubviewRefreshTask = nil
|
|
862
|
+
|
|
863
|
+
if invalidateChildrenCache {
|
|
864
|
+
self.lastRenderedChildrenSignature = nil
|
|
865
|
+
if !self.subviews.isEmpty {
|
|
866
|
+
self.invalidateCurrentChildrenCache()
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
if let animatedAnnotation = self.animatedAnnotation {
|
|
871
|
+
self.animatedAnnotationView = nil
|
|
872
|
+
mapView.removeAnnotation(animatedAnnotation)
|
|
873
|
+
mapView.addAnnotation(animatedAnnotation)
|
|
874
|
+
return
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
if let annotation = self.annotation {
|
|
878
|
+
self.annotationView = nil
|
|
879
|
+
mapView.removeAnnotation(annotation)
|
|
880
|
+
mapView.addAnnotation(annotation)
|
|
881
|
+
} else {
|
|
882
|
+
self.updateAnnotation()
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
if Thread.isMainThread {
|
|
887
|
+
refresh()
|
|
888
|
+
} else {
|
|
889
|
+
DispatchQueue.main.async(execute: refresh)
|
|
890
|
+
}
|
|
891
|
+
}
|
|
811
892
|
|
|
812
893
|
/**
|
|
813
894
|
* 设置纬度
|
|
@@ -893,28 +974,83 @@ class MarkerView: ExpoView {
|
|
|
893
974
|
*/
|
|
894
975
|
func setDraggable(_ draggable: Bool) {
|
|
895
976
|
self.draggable = draggable
|
|
977
|
+
annotationView?.isDraggable = draggable
|
|
978
|
+
animatedAnnotationView?.isDraggable = draggable
|
|
896
979
|
updateAnnotation()
|
|
897
980
|
}
|
|
898
981
|
|
|
899
982
|
func setIconUri(_ uri: String?) {
|
|
900
983
|
self.iconUri = uri
|
|
901
|
-
|
|
984
|
+
refreshAnnotationAppearance()
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
func setIconWidth(_ width: Double) {
|
|
988
|
+
guard iconWidth != width else { return }
|
|
989
|
+
iconWidth = width
|
|
990
|
+
if let iconUri, !iconUri.isEmpty {
|
|
991
|
+
refreshAnnotationAppearance()
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
func setIconHeight(_ height: Double) {
|
|
996
|
+
guard iconHeight != height else { return }
|
|
997
|
+
iconHeight = height
|
|
998
|
+
if let iconUri, !iconUri.isEmpty {
|
|
999
|
+
refreshAnnotationAppearance()
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
func setCustomViewWidth(_ width: Double) {
|
|
1004
|
+
guard customViewWidth != width else { return }
|
|
1005
|
+
customViewWidth = width
|
|
1006
|
+
if !subviews.isEmpty {
|
|
1007
|
+
refreshAnnotationAppearance(invalidateChildrenCache: true)
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
func setCustomViewHeight(_ height: Double) {
|
|
1012
|
+
guard customViewHeight != height else { return }
|
|
1013
|
+
customViewHeight = height
|
|
1014
|
+
if !subviews.isEmpty {
|
|
1015
|
+
refreshAnnotationAppearance(invalidateChildrenCache: true)
|
|
1016
|
+
}
|
|
902
1017
|
}
|
|
903
1018
|
|
|
904
1019
|
func setCenterOffset(_ offset: [String: Double]) {
|
|
905
1020
|
self.centerOffset = offset
|
|
1021
|
+
if let annotationView = annotationView {
|
|
1022
|
+
applyCenterOffset(to: annotationView, defaultOffset: currentDefaultCenterOffset())
|
|
1023
|
+
}
|
|
1024
|
+
if let animatedAnnotationView = animatedAnnotationView {
|
|
1025
|
+
applyCenterOffset(to: animatedAnnotationView, defaultOffset: currentDefaultCenterOffset())
|
|
1026
|
+
}
|
|
906
1027
|
}
|
|
907
1028
|
|
|
908
1029
|
func setAnimatesDrop(_ animate: Bool) {
|
|
909
1030
|
self.animatesDrop = animate
|
|
1031
|
+
(annotationView as? MAPinAnnotationView)?.animatesDrop = animate
|
|
910
1032
|
}
|
|
911
1033
|
|
|
912
1034
|
func setPinColor(_ color: String) {
|
|
1035
|
+
guard pinColor != color else { return }
|
|
913
1036
|
self.pinColor = color
|
|
1037
|
+
if subviews.isEmpty && (iconUri?.isEmpty ?? true) {
|
|
1038
|
+
refreshAnnotationAppearance()
|
|
1039
|
+
}
|
|
914
1040
|
}
|
|
915
1041
|
|
|
916
1042
|
func setCanShowCallout(_ show: Bool) {
|
|
917
1043
|
self.canShowCallout = show
|
|
1044
|
+
if subviews.isEmpty {
|
|
1045
|
+
annotationView?.canShowCallout = show
|
|
1046
|
+
animatedAnnotationView?.canShowCallout = show
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
func setGrowAnimation(_ enabled: Bool) {
|
|
1051
|
+
guard growAnimation != enabled else { return }
|
|
1052
|
+
growAnimation = enabled
|
|
1053
|
+
refreshAnnotationAppearance()
|
|
918
1054
|
}
|
|
919
1055
|
|
|
920
1056
|
// MARK: - 平滑移动相关方法
|
|
@@ -1125,6 +1261,7 @@ class MarkerView: ExpoView {
|
|
|
1125
1261
|
// 取消待处理的任务
|
|
1126
1262
|
pendingAddTask?.cancel()
|
|
1127
1263
|
pendingUpdateTask?.cancel()
|
|
1264
|
+
pendingSubviewRefreshTask?.cancel()
|
|
1128
1265
|
|
|
1129
1266
|
// 清理引用,防止内存泄漏
|
|
1130
1267
|
mapView = nil
|
package/package.json
CHANGED