@react-native-ohos/react-native-amap3d 3.3.0-rc.2 → 3.3.0-rc.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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Use these variables when you tailor your ArkTS code. They must be of the const type.
3
3
  */
4
- export const HAR_VERSION = '3.3.0-rc.2';
4
+ export const HAR_VERSION = '3.3.0-rc.4';
5
5
  export const BUILD_MODE_NAME = 'debug';
6
6
  export const DEBUG = true;
7
7
  export const TARGET_NAME = 'default';
@@ -3,7 +3,7 @@
3
3
  "devDependencies": {
4
4
  },
5
5
  "name": "@react-native-ohos/react-native-amap3d",
6
- "version": "3.3.0-rc.2",
6
+ "version": "3.3.0-rc.4",
7
7
  "description": "Please describe the basic information.",
8
8
  "main": "index.ets",
9
9
  "author": "",
@@ -6,6 +6,10 @@ import HashMap from '@ohos.util.HashMap';
6
6
  export default class GlobalCache {
7
7
  public static index: number = 1
8
8
  public static isGO: boolean = false;
9
+ // 记录已销毁的地图组件tag,用于防止异步操作访问已释放资源
10
+ public static destroyedMapTags: Set<number> = new Set();
11
+ // 记录已销毁的Marker组件tag
12
+ public static destroyedMarkerTags: Set<number> = new Set();
9
13
  public static cacheMap: Map<Object | undefined, number> = new Map()
10
14
  public static cacheMapPageDestroy: Map<number, boolean> = new Map()
11
15
  public static mapMarker: Map<number, Array<Marker>> = new Map();//map的tag和 marker集合
@@ -21,4 +25,8 @@ export default class GlobalCache {
21
25
 
22
26
  public static polygonCacheMap: HashMap<number, Polygon> = new HashMap();
23
27
  public static circleCacheMap: HashMap<number, Circle> = new HashMap();
28
+ // 新增: map的tag和circle集合的映射关系
29
+ public static mapCircle: Map<number, Array<Circle>> = new Map();
30
+ // 新增: circle的tag和map的tag的映射关系
31
+ public static currentPageCircle: HashMap<number, number> = new HashMap();
24
32
  }
@@ -90,6 +90,11 @@ export struct AMapCircle {
90
90
  }
91
91
  )
92
92
  }
93
+
94
+ aboutToDisappear(): void {
95
+ this.unregisterDescriptorChangesListener?.();
96
+ }
97
+
93
98
  build() {
94
99
  }
95
100
  }
@@ -77,6 +77,11 @@ export struct AMapMarker {
77
77
  )
78
78
  }
79
79
 
80
+ aboutToDisappear(): void {
81
+ // 取消订阅
82
+ this.unregisterDescriptorChangesListener?.();
83
+ }
84
+
80
85
  build() {
81
86
  ContentSlot(this.ctx.getContentForTag(this.tag))
82
87
  }
@@ -109,14 +109,34 @@ export struct AMapView {
109
109
  }
110
110
  this.unregisterDescriptorChangesListener?.()
111
111
  this.cleanupCallback?.()
112
- GlobalCache.maps.get(this.tag)?.clear()
113
- GlobalCache.mapViews.get(this.tag)?.onDestroy();
114
- GlobalCache.mapMarker.delete(this.tag);
115
- GlobalCache.markerTagAndDescriptorTag.delete(this.tag);
116
- GlobalCache.mapPolyLine.delete(this.tag);
117
- GlobalCache.polyLinesTagAndDescriptorTag.delete(this.tag);
118
- GlobalCache.polygonCacheMap.clear();
119
- GlobalCache.circleCacheMap.clear();
112
+ GlobalCache.maps.get(this.tag)?.clear()
113
+ GlobalCache.mapViews.get(this.tag)?.onDestroy();
114
+ GlobalCache.mapMarker.delete(this.tag);
115
+ GlobalCache.markerTagAndDescriptorTag.delete(this.tag);
116
+ GlobalCache.mapPolyLine.delete(this.tag);
117
+ GlobalCache.polyLinesTagAndDescriptorTag.delete(this.tag);
118
+ GlobalCache.polygonCacheMap.clear();
119
+ // 清理属于当前 MapView 的 Circle
120
+ let circleTagsToRemove: number[] = [];
121
+ GlobalCache.currentPageCircle.forEach((mapTag: number, circleTag: number) => {
122
+ if (mapTag === this.tag) {
123
+ circleTagsToRemove.push(circleTag);
124
+ }
125
+ });
126
+ for (let circleTag of circleTagsToRemove) {
127
+ GlobalCache.circleCacheMap.remove(circleTag);
128
+ GlobalCache.currentPageCircle.remove(circleTag);
129
+ }
130
+ // 清理属于当前 MapView 的 Marker
131
+ let markerTagsToRemove: number[] = [];
132
+ GlobalCache.currentPageMarker.forEach((mapTag: number, markerTag: number) => {
133
+ if (mapTag === this.tag) {
134
+ markerTagsToRemove.push(markerTag);
135
+ }
136
+ });
137
+ for (let markerTag of markerTagsToRemove) {
138
+ GlobalCache.currentPageMarker.remove(markerTag);
139
+ }
120
140
  }
121
141
 
122
142
  //地图
@@ -447,21 +467,24 @@ export struct AMapView {
447
467
 
448
468
  // 收集当前所有 Circle 子组件的 tag
449
469
  let currentCircleTags: Set<number> = new Set();
470
+ // 收集当前所有 Marker 子组件的 tag
471
+ let currentMarkerTags: Set<number> = new Set();
450
472
  for (let i = 0; i < descriptor.childrenTags.length; i++) {
451
473
  let childTagName =
452
474
  this.ctx.rnInstance.getComponentNameFromDescriptorType(this.ctx.descriptorRegistry.getDescriptor(descriptor.childrenTags[i])?.type);
453
475
  if (childTagName === A_MAP_CIRCLE_VIEW_TYPE) {
454
476
  currentCircleTags.add(descriptor.childrenTags[i]);
477
+ } else if (childTagName === A_MAP_MARKER_TYPE) {
478
+ currentMarkerTags.add(descriptor.childrenTags[i]);
455
479
  }
456
480
  }
457
481
 
458
- // 删除不再需要的 Circle
482
+ // 删除不再需要的 Circle(只删除属于当前 MapView 的)
459
483
  let circlesToRemove: number[] = [];
460
- GlobalCache.circleCacheMap.forEach((circle, circleTag) => {
461
- if (circleTag != undefined) {
462
- if (!currentCircleTags.has(circleTag)) {
463
- circlesToRemove.push(circleTag);
464
- }
484
+ GlobalCache.currentPageCircle.forEach((mapTag: number, circleTag: number) => {
485
+ // 只处理属于当前 MapView Circle
486
+ if (mapTag === this.tag && !currentCircleTags.has(circleTag)) {
487
+ circlesToRemove.push(circleTag);
465
488
  }
466
489
  });
467
490
  for (let circleTag of circlesToRemove) {
@@ -470,7 +493,52 @@ export struct AMapView {
470
493
  circleToRemove.remove(); // 从地图上移除圆
471
494
  }
472
495
  GlobalCache.circleCacheMap.remove(circleTag); // 从缓存中删除
496
+ GlobalCache.currentPageCircle.remove(circleTag); // 从映射关系中删除
497
+ }
498
+
499
+ // 删除不再需要的 Marker(只删除属于当前 MapView 的)
500
+ let markersToRemove: number[] = [];
501
+ GlobalCache.currentPageMarker.forEach((mapTag: number, markerTag: number) => {
502
+ // 只处理属于当前 MapView 的 Marker
503
+ if (mapTag === this.tag && !currentMarkerTags.has(markerTag)) {
504
+ markersToRemove.push(markerTag);
505
+ }
506
+ });
507
+
508
+ // 删除 Marker
509
+ let markers = GlobalCache.mapMarker.get(this.tag) ?? [];
510
+ let markerTagAndDescriptorTagArray = GlobalCache.markerTagAndDescriptorTag.get(this.tag) ?? [];
511
+
512
+ for (let markerTag of markersToRemove) {
513
+ // 从地图上移除 Marker
514
+ for (let index = 0; index < markerTagAndDescriptorTagArray.length; index++) {
515
+ markerTagAndDescriptorTagArray[index].forEach((markerID: string, tag: number) => {
516
+ if (tag === markerTag) {
517
+ // 找到对应的 Marker 并移除
518
+ for (let markerIndex = 0; markerIndex < markers.length; markerIndex++) {
519
+ if (markers[markerIndex].getId() === markerID) {
520
+ markers[markerIndex].remove(); // 从地图上移除 Marker
521
+ markers.splice(markerIndex, 1); // 从数组中删除
522
+ break;
523
+ }
524
+ }
525
+ markerTagAndDescriptorTagArray.splice(index, 1); // 从映射关系中删除
526
+ }
527
+ });
528
+ }
529
+ GlobalCache.currentPageMarker.remove(markerTag); // 从映射关系中删除
530
+ // 从 markerTag 数组中删除
531
+ let markerTagIndex = this.markerTag.indexOf(markerTag);
532
+ if (markerTagIndex !== -1) {
533
+ this.markerTag.splice(markerTagIndex, 1);
534
+ }
473
535
  }
536
+
537
+ // 更新缓存
538
+ GlobalCache.mapMarker.set(this.tag, markers);
539
+ GlobalCache.markerTagAndDescriptorTag.set(this.tag, markerTagAndDescriptorTagArray);
540
+ this.markers = markers;
541
+ this.markerTagAndDescriptorTagArray = markerTagAndDescriptorTagArray;
474
542
 
475
543
  for (let i = 0; i < descriptor.childrenTags.length; i++) {
476
544
  tagName =
@@ -501,6 +569,8 @@ export struct AMapView {
501
569
  let circle = this.aMap?.addCircle(circleOptions);
502
570
  //Put the overlay ring in the cache and hot-update the properties to modify
503
571
  GlobalCache.circleCacheMap.set(childCircleTag, circle);
572
+ // 记录 Circle 与 MapView 的关联关系
573
+ GlobalCache.currentPageCircle.set(childCircleTag, this.tag);
504
574
  if (circle) {
505
575
  circle.setRadius(circleProp.radius ? circleProp.radius : 5000);
506
576
  circle.setCenter(new LatLng(circleProp.center.latitude, circleProp.center.longitude));
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-ohos/react-native-amap3d",
3
- "version": "3.3.0-rc.2",
3
+ "version": "3.3.0-rc.4",
4
4
  "description": "react-native 高德地图组件,支持 harmonyOS",
5
5
  "license": "MIT",
6
6
  "keywords": [