@react-native-ohos/react-native-amap3d 3.2.5-rc.1

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +10 -0
  4. package/harmony/rn_amap3d/BuildProfile.ets +6 -0
  5. package/harmony/rn_amap3d/build-profile.json5 +28 -0
  6. package/harmony/rn_amap3d/consumer-rules.txt +0 -0
  7. package/harmony/rn_amap3d/hvigorfile.ts +6 -0
  8. package/harmony/rn_amap3d/index.ets +30 -0
  9. package/harmony/rn_amap3d/obfuscation-rules.txt +18 -0
  10. package/harmony/rn_amap3d/oh-package.json5 +16 -0
  11. package/harmony/rn_amap3d/src/main/cpp/AMap3dEventEmitRequestHandler.h +218 -0
  12. package/harmony/rn_amap3d/src/main/cpp/AMapEventEmitters.cpp +132 -0
  13. package/harmony/rn_amap3d/src/main/cpp/AMapEventEmitters.h +111 -0
  14. package/harmony/rn_amap3d/src/main/cpp/CMakeLists.txt +7 -0
  15. package/harmony/rn_amap3d/src/main/cpp/ComponentDescriptors.h +19 -0
  16. package/harmony/rn_amap3d/src/main/cpp/MapViewJSIBinder.h +168 -0
  17. package/harmony/rn_amap3d/src/main/cpp/MapViewPackage.h +43 -0
  18. package/harmony/rn_amap3d/src/main/cpp/Props.cpp +86 -0
  19. package/harmony/rn_amap3d/src/main/cpp/Props.h +258 -0
  20. package/harmony/rn_amap3d/src/main/cpp/ShadowNodes.cpp +15 -0
  21. package/harmony/rn_amap3d/src/main/cpp/ShadowNodes.h +33 -0
  22. package/harmony/rn_amap3d/src/main/ets/AMap3DModule.ts +32 -0
  23. package/harmony/rn_amap3d/src/main/ets/AMap3DPackage.ts +46 -0
  24. package/harmony/rn_amap3d/src/main/ets/GlobalCache.ets +24 -0
  25. package/harmony/rn_amap3d/src/main/ets/Logger.ets +65 -0
  26. package/harmony/rn_amap3d/src/main/ets/View/AMapCircle.ets +96 -0
  27. package/harmony/rn_amap3d/src/main/ets/View/AMapMarker.ets +83 -0
  28. package/harmony/rn_amap3d/src/main/ets/View/AMapPolygon.ets +52 -0
  29. package/harmony/rn_amap3d/src/main/ets/View/AMapPolyline.ets +89 -0
  30. package/harmony/rn_amap3d/src/main/ets/View/MapView.ets +686 -0
  31. package/harmony/rn_amap3d/src/main/module.json5 +17 -0
  32. package/harmony/rn_amap3d/src/main/resources/base/element/string.json +8 -0
  33. package/harmony/rn_amap3d/src/main/resources/en_US/element/string.json +8 -0
  34. package/harmony/rn_amap3d/src/main/resources/rawfile/location_map_gps_locked.png +0 -0
  35. package/harmony/rn_amap3d/src/main/resources/zh_CN/element/string.json +8 -0
  36. package/harmony/rn_amap3d/ts.ts +28 -0
  37. package/harmony/rn_amap3d.har +0 -0
  38. package/lib/src/NativeAMapSdk.ts +9 -0
  39. package/lib/src/circle.tsx +17 -0
  40. package/lib/src/circleNativeComponent.ts +47 -0
  41. package/lib/src/cluster/cluster-view.tsx +47 -0
  42. package/lib/src/cluster/index.tsx +159 -0
  43. package/lib/src/component.ts +31 -0
  44. package/lib/src/heat-map.tsx +17 -0
  45. package/lib/src/heat-mapNativeComponent.ts +34 -0
  46. package/lib/src/index.ts +11 -0
  47. package/lib/src/map-view.tsx +73 -0
  48. package/lib/src/map-viewNativeComponent.ts +232 -0
  49. package/lib/src/marker.tsx +32 -0
  50. package/lib/src/markerNativeComponent.ts +105 -0
  51. package/lib/src/multi-point.tsx +17 -0
  52. package/lib/src/multi-pointNativeComponent.ts +51 -0
  53. package/lib/src/polygon.tsx +17 -0
  54. package/lib/src/polygonNativeComponent.ts +42 -0
  55. package/lib/src/polyline.tsx +21 -0
  56. package/lib/src/polylineNativeComponent.ts +67 -0
  57. package/lib/src/types.ts +34 -0
  58. package/package.json +53 -0
  59. package/react-native.config.js +20 -0
@@ -0,0 +1,686 @@
1
+ import {
2
+ AMap,
3
+ BitmapDescriptor,
4
+ BitmapDescriptorFactory,
5
+ CameraPosition,
6
+ CameraUpdateFactory,
7
+ CircleOptions,
8
+ LatLng,
9
+ MapView,
10
+ MapViewComponent,
11
+ MapViewManager,
12
+ Marker,
13
+ MarkerOptions,
14
+ OnCameraChangeListener,
15
+ OnMarkerDragListener,
16
+ Poi,
17
+ PolygonOptions,
18
+ Polyline,
19
+ PolylineOptions
20
+ } from '@amap/amap_lbs_map3d';
21
+
22
+ import { Descriptor, RNComponentContext, RNOHContext, RNViewBase, ViewBaseProps } from '@rnoh/react-native-openharmony';
23
+ import { A_MAP_CIRCLE_VIEW_TYPE, AMapCircleProps, rgbaToHex } from './AMapCircle';
24
+ import { A_MAP_POLYGON_TYPE, AMapPolygonProps } from './AMapPolygon';
25
+ import { A_MAP_POLYLINE_TYPE, AMapPolylineProps } from './AMapPolyline';
26
+ import { A_MAP_MARKER_TYPE, AMapMarkerProps } from './AMapMarker';
27
+
28
+ import Logger from '../Logger';
29
+ import { ArrayList, HashMap } from '@kit.ArkTS';
30
+ import GlobalCache from '../GlobalCache';
31
+
32
+ export interface MapViewProps extends ViewBaseProps {
33
+ initialCameraPosition?: CameraPosition;
34
+ mapType: number;
35
+ myLocationEnabled?: boolean;
36
+ indoorViewEnabled?: boolean;
37
+ buildingsEnabled?: boolean;
38
+ labelsEnabled?: boolean;
39
+ compassEnabled?: boolean;
40
+ zoomControlsEnabled?: boolean;
41
+ scaleControlsEnabled?: boolean;
42
+ myLocationButtonEnabled?: boolean;
43
+ trafficEnabled?: boolean;
44
+ maxZoom?: number;
45
+ minZoom?: number;
46
+ zoomGesturesEnabled?: boolean;
47
+ scrollGesturesEnabled?: boolean;
48
+ rotateGesturesEnabled?: boolean;
49
+ tiltGesturesEnabled?: boolean;
50
+ distanceFilter?: number;
51
+ headingFilter?: number;
52
+ }
53
+
54
+ const MAP_SHOW_FUNC = 'AMapView';
55
+
56
+ export const GOADE_MAP_VIEW_TYPE: string = "AMapView"
57
+
58
+ export type GDMapViewDescriptor = Descriptor<"AMapView", MapViewProps>;
59
+
60
+ export let globalContext: Context;
61
+
62
+ @Component
63
+ export struct AMapView {
64
+ static NAME: string = "AMapView";
65
+ static num: number = 0;
66
+ ctx!: RNComponentContext
67
+ tag: number = -1
68
+ type: string = ""
69
+ polyLineTag: Array<number> = []
70
+ markerTag: Array<number> = []
71
+ @State gDMapDescriptor: GDMapViewDescriptor = {} as GDMapViewDescriptor
72
+ private unregisterDescriptorChangesListener?: () => void = undefined
73
+ private cleanupCallback?: () => void = undefined;
74
+ private markers : Array<Marker> = new Array();
75
+ private polylines : Array<Polyline> = new Array();
76
+ private markerTagAndDescriptorTagArray : Array<HashMap<number, string>> = new Array();
77
+ private polylineTagAndDescriptorTagArray : Array<HashMap<number, string>> = new Array();
78
+
79
+ aboutToAppear(): void {
80
+ this.cleanupCallback = this.ctx.componentCommandReceiver.registerCommandCallback(
81
+ this.tag,
82
+ (command, args: ESObject[]) => {
83
+ if (command === 'moveCamera') {
84
+ this.aMap?.animateCamera(CameraUpdateFactory.newCameraPosition(args[0]), null, args[1]);
85
+ }
86
+ });
87
+ globalContext = getContext().getApplicationContext();
88
+ this.gDMapDescriptor = this.ctx.descriptorRegistry.getDescriptor<GDMapViewDescriptor>(this.tag);
89
+ // GlobalCache.markerProp = new HashMap();
90
+ this.getProp(this.gDMapDescriptor);
91
+ this.show();
92
+ this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
93
+ (newDescriptor) => {
94
+ if (this.aMap) {
95
+ GlobalCache.mapPolyLine.clear();
96
+ /*------ 当RN侧属性props有更改 -------*/
97
+ this.gDMapDescriptor = (newDescriptor as GDMapViewDescriptor)
98
+ this.getProp(this.gDMapDescriptor);
99
+ this.getOverlay(this.gDMapDescriptor);
100
+ }
101
+
102
+ }
103
+ )
104
+ }
105
+
106
+ aboutToDisappear(): void {
107
+ if (this.mapViewCreateCallback) {
108
+ MapViewManager.getInstance().unregisterMapViewCreatedCallback(this.mapViewCreateCallback);
109
+ }
110
+ this.unregisterDescriptorChangesListener?.()
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();
120
+ }
121
+
122
+ //地图
123
+ private mapView?: MapView;
124
+ private aMap?: AMap;
125
+ mapType: number = 1;
126
+ initialCameraPosition?: CameraPosition;
127
+ myLocationEnabled: boolean = false;
128
+ indoorViewEnabled: boolean = false;
129
+ compassEnabled: boolean = false;
130
+ buildingsEnabled: boolean = false;
131
+ labelsEnabled: boolean = false;
132
+ zoomControlsEnabled: boolean = false;
133
+ scaleControlsEnabled: boolean = false;
134
+ myLocationButtonEnabled: boolean = false;
135
+ distanceFilter: number = 1;
136
+ headingFilter: number = 1;
137
+ trafficEnabled: boolean = false;
138
+ maxZoom: number = 19;
139
+ minZoom: number = 3
140
+ zoomGesturesEnabled: boolean = true; //控制缩放
141
+ scrollGesturesEnabled: boolean = true; //控制平移
142
+ rotateGesturesEnabled: boolean = true; //控制手势旋转
143
+ tiltGesturesEnabled: boolean = true; //控制倾斜
144
+
145
+ //覆盖物
146
+ getMapView(): MapView | undefined {
147
+ return this.mapView;
148
+ }
149
+
150
+ getAMap(): AMap | undefined {
151
+ return this.aMap;
152
+ }
153
+
154
+ onClickFunction(point: LatLng) {
155
+ this.ctx.rnInstance.emitComponentEvent(this.gDMapDescriptor.tag, MAP_SHOW_FUNC, {
156
+ type: 'onPress',
157
+ LatLng: point
158
+ })
159
+ }
160
+
161
+ onLongClickFunction(point: LatLng) {
162
+ this.ctx.rnInstance.emitComponentEvent(this.gDMapDescriptor.tag, MAP_SHOW_FUNC, {
163
+ type: 'onLongPress',
164
+ LatLng: point
165
+ })
166
+ }
167
+
168
+ onPressPoiFunction(poi: Poi) {
169
+ this.ctx.rnInstance.emitComponentEvent(this.gDMapDescriptor.tag, MAP_SHOW_FUNC, {
170
+ type: 'onPressPoi',
171
+ Poi: poi
172
+ })
173
+ }
174
+
175
+ onCameraMoveFunction(cameraMoveEvent: CameraPosition) {
176
+ this.ctx.rnInstance.emitComponentEvent(this.gDMapDescriptor.tag, MAP_SHOW_FUNC, {
177
+ type: 'onCameraMove',
178
+ CameraPosition: cameraMoveEvent
179
+ })
180
+ }
181
+
182
+ onCameraIdleFunction(cameraIdleEvent: CameraPosition) {
183
+ this.ctx.rnInstance.emitComponentEvent(this.gDMapDescriptor.tag, MAP_SHOW_FUNC, {
184
+ type: 'onCameraIdle',
185
+ CameraPosition: cameraIdleEvent
186
+ })
187
+ }
188
+
189
+ onLoadFunction(): void {
190
+ Logger.info('map3d', 'EntryAbility', 'get map onLoadFunction');
191
+ this.ctx.rnInstance.emitComponentEvent(this.gDMapDescriptor.tag, MAP_SHOW_FUNC, {
192
+ type: 'onLoad'
193
+ })
194
+ }
195
+
196
+ onPolyLineClickFunction(num: number): void {
197
+ this.ctx.rnInstance.emitComponentEvent(this.polyLineTag[num], A_MAP_POLYLINE_TYPE, {
198
+ type: 'onPress'
199
+ })
200
+ }
201
+
202
+ onMarkerClickFunction(num: number): void {
203
+ this.ctx.rnInstance.emitComponentEvent(this.markerTag[num], A_MAP_MARKER_TYPE, {
204
+ type: 'onPress'
205
+ })
206
+ }
207
+
208
+ onMarkerDragStartFunction(num: number): void {
209
+ this.ctx.rnInstance.emitComponentEvent(this.markerTag[num], A_MAP_MARKER_TYPE, {
210
+ type: 'onDragStart'
211
+ })
212
+ }
213
+
214
+ onMarkerDragFunction(num: number): void {
215
+ this.ctx.rnInstance.emitComponentEvent(this.markerTag[num], A_MAP_MARKER_TYPE, {
216
+ type: 'onDrag'
217
+ })
218
+ }
219
+
220
+ onMarkerDragEndFunction(point: LatLng, num: number): void {
221
+ this.ctx.rnInstance.emitComponentEvent(this.markerTag[num], A_MAP_MARKER_TYPE, {
222
+ type: 'onDragEnd',
223
+ LatLng: point
224
+ })
225
+ }
226
+
227
+ private mapViewCreateCallback = (mapview?: MapView, mapViewName?: string) => {
228
+ if (!mapview) {
229
+ return;
230
+ }
231
+ if (mapview.getMapViewName() != this.tag.toString()) {
232
+ return;
233
+ }
234
+ mapview.onCreate();
235
+ GlobalCache.mapViews.set(this.tag, mapview);
236
+ this.mapView = GlobalCache.mapViews.get(this.tag);
237
+ this.mapView.getMapAsync((map:AMap) => {
238
+ GlobalCache.maps.set(this.tag, map);
239
+ this.aMap = GlobalCache.maps.get(this.tag);
240
+ this.getOverlay(this.gDMapDescriptor);
241
+ if (this.initialCameraPosition != null) {
242
+ this.aMap?.moveCamera(CameraUpdateFactory.newCameraPosition(this.initialCameraPosition));
243
+ }
244
+ this.aMap?.setOnMapClickListener((point: LatLng) => {
245
+ this.onClickFunction(point)
246
+ });
247
+ this.aMap?.setOnCameraChangeListener(new OnCameraChangeListener(
248
+ (position: CameraPosition) => {
249
+ this.onCameraMoveFunction(position);
250
+ },
251
+ (position: CameraPosition) => {
252
+ this.onCameraIdleFunction(position);
253
+ }));
254
+ this.aMap?.addOnPOIClickListener((poi: Poi) => {
255
+ this.onPressPoiFunction(poi);
256
+ })
257
+ this.aMap?.setOnMapLongClickListener((point: LatLng) => {
258
+ this.onLongClickFunction(point)
259
+ });
260
+
261
+ let approvalNumber = this.aMap?.getMapContentApprovalNumber();
262
+ let satelliteImageApprovalNumber = this.aMap?.getSatelliteImageApprovalNumber();
263
+ Logger.info('map3d', 'EntryAbility',
264
+ `getMapContentApprovalNumber ${approvalNumber} satelliteImageApprovalNumber ${satelliteImageApprovalNumber}`);
265
+
266
+ //地图属性
267
+ this.aMap.setMapType(this.mapType);
268
+ this.aMap.setTrafficEnabled(this.trafficEnabled);
269
+ //设置地图最大缩放级别 缩放级别范围为[3, 20],超出范围将按最大级别计算 。
270
+ // 注:只有在有室内地图显示的情况下最大级别为20,否则最大级别为19。
271
+ this.aMap.setMinZoomLevel(this.minZoom);
272
+ this.aMap.setMaxZoomLevel(this.maxZoom);
273
+ this.aMap.setMyLocationEnabled(this.myLocationEnabled);
274
+ //设置最小缩放级别 缩放级别范围为[3, 20],超出范围将按最小级别计算
275
+ this.aMap.showBuildings(this.buildingsEnabled);
276
+ this.aMap.showMapText(this.labelsEnabled);
277
+ let uiSettings = this.aMap?.getUiSettings();
278
+ uiSettings?.setZoomGesturesEnabled(this.zoomGesturesEnabled);
279
+ uiSettings?.setScrollGesturesEnabled(this.scrollGesturesEnabled);
280
+ uiSettings?.setRotateGesturesEnabled(this.rotateGesturesEnabled);
281
+ uiSettings?.setTiltGesturesEnabled(this.tiltGesturesEnabled);
282
+ uiSettings?.setScaleControlsEnabled(this.scaleControlsEnabled);
283
+ uiSettings?.setCompassEnabled(this.compassEnabled);
284
+ uiSettings?.setMyLocationButtonEnabled(this.myLocationButtonEnabled);
285
+ uiSettings?.setZoomControlsEnabled(this.zoomControlsEnabled);
286
+
287
+ this.onLoadFunction();
288
+ this.aMap?.setOnPolylineClickListener((polyLine: Polyline): void => {
289
+ let len: number | undefined = GlobalCache.mapPolyLine.get(this.tag)?.length;
290
+ let polyLinesArray: Array<Polyline> | undefined = GlobalCache.mapPolyLine.get(this.tag);
291
+ if (len && polyLinesArray) {
292
+ for (let index = 0; index < len; ++index) {
293
+ if (polyLine.getId() == polyLinesArray[index].getId()) {
294
+ this.onPolyLineClickFunction(index)
295
+ }
296
+ }
297
+ }
298
+ });
299
+
300
+ this.aMap?.setOnMarkerClickListener((marker: Marker): boolean => {
301
+ if (GlobalCache.mapMarker.get(this.tag)) {
302
+ let len: number | undefined = GlobalCache.mapMarker.get(this.tag)?.length;
303
+ let markers: Array<Marker> | undefined = GlobalCache.mapMarker.get(this.tag);
304
+ if (len && markers) {
305
+ for (let index = 0; index < len; ++index) {
306
+ if (marker.getId() == markers[index].getId()) {
307
+ this.onMarkerClickFunction(index);
308
+ }
309
+ }
310
+ }
311
+ }
312
+ return true;
313
+ });
314
+
315
+ this.aMap?.setOnMarkerDragListener(new OnMarkerDragListener(
316
+ (DragStart: Marker) => {
317
+ let len: number | undefined = GlobalCache.mapMarker.get(this.tag)?.length;
318
+ let markers: Array<Marker> | undefined = GlobalCache.mapMarker.get(this.tag);
319
+ if (len && markers) {
320
+ for (let index = 0; index < len; ++index) {
321
+ if (len && markers) {
322
+ if (DragStart == markers[index]) {
323
+ this.onMarkerDragStartFunction(index);
324
+ }
325
+ }
326
+ }
327
+ }
328
+ },
329
+ (Drag: Marker) => {
330
+ let len: number | undefined = GlobalCache.mapMarker.get(this.tag)?.length;
331
+ let markers: Array<Marker> | undefined = GlobalCache.mapMarker.get(this.tag);
332
+ if (len && markers) {
333
+ for (let index = 0; index < len; ++index) {
334
+ if (len && markers) {
335
+ if (Drag == markers[index]) {
336
+ this.onMarkerDragFunction(index);
337
+ }
338
+ }
339
+ }
340
+ }
341
+ },
342
+ (DragEnd: Marker) => {
343
+ let len: number | undefined = GlobalCache.mapMarker.get(this.tag)?.length;
344
+ let markers: Array<Marker> | undefined = GlobalCache.mapMarker.get(this.tag);
345
+ if (len && markers) {
346
+ for (let index = 0; index < len; ++index) {
347
+ if (len && markers) {
348
+ if (DragEnd == markers[index]) {
349
+ this.onMarkerDragEndFunction(DragEnd.getPosition(), index)
350
+ }
351
+ }
352
+ }
353
+ }
354
+ })
355
+ )
356
+ })
357
+ }
358
+
359
+ show(): void {
360
+ MapViewManager.getInstance().registerMapViewCreatedCallback(this.mapViewCreateCallback);
361
+ }
362
+
363
+ /**
364
+ * 获取rn侧传递多来的prop
365
+ */
366
+ private getProp(descriptor: GDMapViewDescriptor) {
367
+ this.mapType = descriptor.props.mapType;
368
+ //初始位置
369
+ if (descriptor.props.initialCameraPosition != null) {
370
+ this.initialCameraPosition = descriptor.props.initialCameraPosition;
371
+ }
372
+ //是否显示当前定位
373
+ if (descriptor.props.myLocationEnabled != null) {
374
+ this.myLocationEnabled = descriptor.props.myLocationEnabled;
375
+ }
376
+ //是否显示室内地图
377
+ if (descriptor.props.indoorViewEnabled != null) {
378
+ this.indoorViewEnabled = descriptor.props.indoorViewEnabled;
379
+ }
380
+ //是否显示3D建筑
381
+ if (descriptor.props.buildingsEnabled != null) {
382
+ this.buildingsEnabled = descriptor.props.buildingsEnabled;
383
+ }
384
+ //是否显示标注
385
+ if (descriptor.props.labelsEnabled != null) {
386
+ this.labelsEnabled = descriptor.props.labelsEnabled;
387
+ }
388
+ //是否显示指南针
389
+ if (descriptor.props.compassEnabled != null) {
390
+ this.compassEnabled = descriptor.props.compassEnabled;
391
+ }
392
+ //是否显示放大缩小按钮
393
+ if (descriptor.props.zoomControlsEnabled != null) {
394
+ this.zoomControlsEnabled = descriptor.props.zoomControlsEnabled;
395
+ }
396
+
397
+ if (descriptor.props.myLocationButtonEnabled != null) {
398
+ this.myLocationButtonEnabled = descriptor.props.myLocationButtonEnabled;
399
+ }
400
+ //是否显示比例尺
401
+ if (descriptor.props.scaleControlsEnabled != null) {
402
+ this.scaleControlsEnabled = descriptor.props.scaleControlsEnabled;
403
+ }
404
+ //是否显示路况
405
+ if (descriptor.props.trafficEnabled != null) {
406
+ this.trafficEnabled = descriptor.props.trafficEnabled;
407
+ }
408
+ //最大缩放级别
409
+ if (descriptor.props.maxZoom != null) {
410
+ this.maxZoom = descriptor.props.maxZoom;
411
+ }
412
+ //最小缩放级别
413
+ if (descriptor.props.minZoom != null) {
414
+ this.minZoom = descriptor.props.minZoom;
415
+ }
416
+ //是否启用缩放手势,用于放大缩小
417
+ if (descriptor.props.zoomGesturesEnabled != null) {
418
+ this.zoomGesturesEnabled = descriptor.props.zoomGesturesEnabled;
419
+ }
420
+ //是否启用滑动手势,用于平移
421
+ if (descriptor.props.scrollGesturesEnabled != null) {
422
+ this.scrollGesturesEnabled = descriptor.props.scrollGesturesEnabled;
423
+ }
424
+ //是否启用旋转手势,用于调整方向
425
+ if (descriptor.props.rotateGesturesEnabled != null) {
426
+ this.rotateGesturesEnabled = descriptor.props.rotateGesturesEnabled;
427
+ }
428
+ //是否启用倾斜手势,用于改变视角
429
+ if (descriptor.props.tiltGesturesEnabled != null) {
430
+ this.tiltGesturesEnabled = descriptor.props.tiltGesturesEnabled;
431
+ }
432
+ //设定定位的最小更新距离 @platform ios
433
+ if (descriptor.props.distanceFilter != null) {
434
+ this.distanceFilter = descriptor.props.distanceFilter;
435
+ }
436
+ //设定最小更新角度,默认为 1 度 @platform ios
437
+ if (descriptor.props.headingFilter != null) {
438
+ this.headingFilter = descriptor.props.headingFilter;
439
+ }
440
+ }
441
+
442
+ private async getOverlay(descriptor: GDMapViewDescriptor) {
443
+ let tagName = "";
444
+ let flag = false;
445
+ let flagLine = false;
446
+ for (let i = 0; i < descriptor.childrenTags.length; i++) {
447
+ tagName =
448
+ this.ctx.rnInstance.getComponentNameFromDescriptorType(this.ctx.descriptorRegistry.getDescriptor(descriptor.childrenTags[i])?.type);
449
+ switch (tagName) {
450
+ case A_MAP_CIRCLE_VIEW_TYPE:
451
+ let circleOptions = new CircleOptions();
452
+ let circleProp =
453
+ this.ctx.descriptorRegistry.getDescriptor(descriptor.childrenTags[i]).props as AMapCircleProps;
454
+ let childCircleTag: number = this.ctx.descriptorRegistry.getDescriptor(descriptor.childrenTags[i]).tag;
455
+ let circle = this.aMap?.addCircle(circleOptions);
456
+ //Put the overlay ring in the cache and hot-update the properties to modify
457
+ GlobalCache.circleCacheMap.set(childCircleTag, circle);
458
+ if (circle) {
459
+ circle.setRadius(circleProp.radius ? circleProp.radius : 5000);
460
+ circle.setCenter(new LatLng(circleProp.center.latitude, circleProp.center.longitude));
461
+ circle.setFillColor(rgbaToHex(circleProp.fillColor ? circleProp.fillColor : "rgba(255, 0, 0, 0.5)"));
462
+ circle.setStrokeColor(rgbaToHex(circleProp.strokeColor ? circleProp.strokeColor :
463
+ "rgba(0, 0, 255, 0.5)"));
464
+ circle.setStrokeWidth(circleProp.strokeWidth ? circleProp.strokeWidth : 5);
465
+ }
466
+ break;
467
+ case A_MAP_POLYGON_TYPE:
468
+ let polygonOptions = new PolygonOptions();
469
+ let polygon = this.aMap?.addPolygon(polygonOptions);
470
+ let childPolygonTag: number = this.ctx.descriptorRegistry.getDescriptor(descriptor.childrenTags[i]).tag;
471
+ GlobalCache.polygonCacheMap.set(childPolygonTag, polygon);
472
+ let mapPolygonProp =
473
+ this.ctx.descriptorRegistry.getDescriptor(descriptor.childrenTags[i]).props as AMapPolygonProps;
474
+ if (polygon) {
475
+ let polygonOptionsList = new ArrayList<LatLng>()
476
+ for (let index = 0; index < mapPolygonProp.points.length; index++) {
477
+ polygonOptionsList.add(new LatLng(mapPolygonProp.points[index].latitude,
478
+ mapPolygonProp.points[index].longitude))
479
+ }
480
+ polygon.setPoints(polygonOptionsList);
481
+ polygon.setFillColor(rgbaToHex(mapPolygonProp.fillColor ? mapPolygonProp.fillColor :
482
+ "rgba(255, 0, 0, 0.5)"));
483
+ polygon.setStrokeWidth(mapPolygonProp.strokeWidth ? mapPolygonProp.strokeWidth : 5);
484
+ polygon.setStrokeColor(rgbaToHex(mapPolygonProp.strokeColor ? mapPolygonProp.strokeColor :
485
+ "rgba(255, 0, 0, 0.5)"));
486
+ polygon.setZIndex(mapPolygonProp.zIndex ? mapPolygonProp.zIndex : 2);
487
+ }
488
+ break;
489
+ case A_MAP_POLYLINE_TYPE:
490
+ flagLine = false;
491
+ let mapPolylineProp =
492
+ this.ctx.descriptorRegistry.getDescriptor(descriptor.childrenTags[i]).props as AMapPolylineProps;
493
+ let childPolyLineTag: number = this.ctx.descriptorRegistry.getDescriptor(descriptor.childrenTags[i]).tag;
494
+ let GlobalCachePolyLines : Array<Polyline> = GlobalCache.mapPolyLine.get(this.tag) ?? [];
495
+ let polyLinesTagAndDescriptorTagArray: Array<HashMap<number, string>> = GlobalCache.polyLinesTagAndDescriptorTag.get(this.tag) ?? [];
496
+ for (let index = 0; index < polyLinesTagAndDescriptorTagArray.length; index++) {
497
+ polyLinesTagAndDescriptorTagArray[index].forEach(async (value: string, key: number,
498
+ map: HashMap<number, string>) => {
499
+ if (childPolyLineTag == key) {
500
+ for (let polylineIndex = 0; polylineIndex < GlobalCachePolyLines.length; polylineIndex++) {
501
+ if (GlobalCachePolyLines[polylineIndex].getId() == value) {
502
+ flagLine = true;
503
+ GlobalCachePolyLines[polylineIndex].setZIndex(mapPolylineProp.zIndex ? mapPolylineProp.zIndex : 1);
504
+ GlobalCachePolyLines[polylineIndex].setDottedLine(mapPolylineProp.dotted ? mapPolylineProp.dotted : false);
505
+ GlobalCachePolyLines[polylineIndex].setGeodesic(mapPolylineProp.geodesic ? mapPolylineProp.geodesic : false);
506
+ GlobalCachePolyLines[polylineIndex].setWidth(mapPolylineProp.width ? vp2px(mapPolylineProp.width) : vp2px(5));
507
+ if (mapPolylineProp.color) {
508
+ GlobalCachePolyLines[polylineIndex].setColor(rgbaToHex(mapPolylineProp.color ? mapPolylineProp.color :
509
+ "rgba(0, 255, 0, 0.5)"));
510
+ }
511
+ if (mapPolylineProp.colors) {
512
+ let test = new Int32Array(mapPolylineProp.colors.length)
513
+ for (let i = 0; i < mapPolylineProp.colors.length; ++i) {
514
+ let str = mapPolylineProp.colors[i].replace("#", "0xff")
515
+ test[i] = parseInt(str.substring(2, str.length), 16)
516
+ }
517
+ }
518
+ break;
519
+ }
520
+ }
521
+ }
522
+ })
523
+ }
524
+ if (!flagLine) {//处理GlobalCache中不存在的情况
525
+ let polylineOptions = new PolylineOptions();
526
+ this.polyLineTag.push(childPolyLineTag);
527
+ GlobalCache.currentPagePolyline.set(childPolyLineTag, this.tag)
528
+ if (this.aMap) {
529
+ try {
530
+ let polylineOptionsList = new ArrayList<LatLng>()
531
+ for (let index = 0; index < mapPolylineProp.points.length; index++) {
532
+ polylineOptionsList.add(new LatLng(mapPolylineProp.points[index].latitude,
533
+ mapPolylineProp.points[index].longitude))
534
+ }
535
+ if (mapPolylineProp.colors) {
536
+ let test = new Int32Array(mapPolylineProp.colors.length)
537
+ for (let i = 0; i < mapPolylineProp.colors.length; ++i) {
538
+ let str = mapPolylineProp.colors[i].replace("#", "0xff")
539
+ test[i] = parseInt(str.substring(2, str.length), 16)
540
+ }
541
+ polylineOptions.setColorValues(test);
542
+ } else if (mapPolylineProp.color) {
543
+ polylineOptions.setColor(rgbaToHex(mapPolylineProp.color ? mapPolylineProp.color : "rgba(0, 255, 0, 0.5)"))
544
+ }
545
+ let polyline = this.aMap?.addPolyline(
546
+ polylineOptions
547
+ .setGradient(mapPolylineProp.gradient ? mapPolylineProp.gradient : false)
548
+ .setZIndex(mapPolylineProp.zIndex ? mapPolylineProp.zIndex : 1)
549
+ .setDottedLine(mapPolylineProp.dotted ? mapPolylineProp.dotted : false)
550
+ .setGeodesic(mapPolylineProp.geodesic ? mapPolylineProp.geodesic : false)
551
+ .setWidth(mapPolylineProp.width ? vp2px(mapPolylineProp.width) : vp2px(5))
552
+ .setGradient(mapPolylineProp.gradient ? mapPolylineProp.gradient : false));
553
+ if(polyline){
554
+ polyline.setPoints(polylineOptionsList);
555
+ let polyLineTagAndDescriptorTagMap : HashMap<number, string> = new HashMap<number, string>();
556
+ polyLineTagAndDescriptorTagMap.set(childPolyLineTag, polyline.getId())
557
+ this.polylineTagAndDescriptorTagArray.push(polyLineTagAndDescriptorTagMap);
558
+ this.polylines.push(polyline);
559
+ }
560
+ GlobalCache.polyLinesTagAndDescriptorTag.set(this.tag, this.polylineTagAndDescriptorTagArray);
561
+ GlobalCache.mapPolyLine.set(this.tag, this.polylines);
562
+ } catch (error) {
563
+ Logger.error('mapPolylineProp---------Error adding polyline:', error);
564
+ }
565
+ }
566
+ }
567
+ break;
568
+ case A_MAP_MARKER_TYPE:
569
+ let markerDescriptor: Descriptor = this.ctx.descriptorRegistry.getDescriptor(descriptor.childrenTags[i])
570
+ let markerChild: number[] = markerDescriptor.childrenTags;
571
+ let mapMarkerProps = markerDescriptor.props as AMapMarkerProps;
572
+ this.markers = (GlobalCache.mapMarker.get(this.tag) ?? []);
573
+ let markerTagAndDescriptorTagArray = GlobalCache.markerTagAndDescriptorTag.get(this.tag) ?? [];
574
+
575
+ for (let index = 0; index < markerTagAndDescriptorTagArray.length; index++) {
576
+ markerTagAndDescriptorTagArray[index].forEach(async (value: string, key: number, map: HashMap<number, string>) => {
577
+ if (markerDescriptor.tag == key) {
578
+ for (let markerIndex = 0; markerIndex < this.markers.length; markerIndex++) {
579
+ if (this.markers[markerIndex].getId() == value) {
580
+ flag = true;
581
+ this.markers[markerIndex].setPosition(new LatLng(mapMarkerProps.position.latitude, mapMarkerProps.position.longitude));
582
+ this.markers[markerIndex].setAnchor(mapMarkerProps.anchor ? mapMarkerProps.anchor.x : 1,
583
+ mapMarkerProps.anchor ? mapMarkerProps.anchor.y : 0.5);
584
+ this.markers[markerIndex].setDraggable(mapMarkerProps.draggable ? mapMarkerProps.draggable : false);
585
+ //this.markers[markerIndex].setZIndex(mapMarkerProps.zIndex ? mapMarkerProps.zIndex : 1);
586
+ this.markers[markerIndex].setFlat(mapMarkerProps.flat ? mapMarkerProps.flat : false);
587
+ this.markers[markerIndex].getOptions().setInfoWindowOffset(mapMarkerProps.centerOffset?.x,mapMarkerProps.centerOffset?.y);
588
+ this.markers[markerIndex].setMarkerOptions(this.markers[markerIndex].getOptions());
589
+ //Handel Custom Marker
590
+ if(markerChild.length > 0) {
591
+ let bitmapView : BitmapDescriptor | undefined = await BitmapDescriptorFactory.fromView(() => {
592
+ this.customMarkerBuilder(markerDescriptor.tag);
593
+ })
594
+ this.markers[markerIndex].setIcon(bitmapView);
595
+ } else {
596
+ if (mapMarkerProps.icon) {
597
+ try {
598
+ let resoure: string = mapMarkerProps.icon["uri"];
599
+ let bitmapDes: BitmapDescriptor | undefined =
600
+ await BitmapDescriptorFactory.fromRawfilePath(globalContext, resoure);
601
+ this.markers[markerIndex].setIcon(bitmapDes);
602
+ } catch (error) {
603
+ let bitmapDesNull: BitmapDescriptor | undefined =
604
+ await BitmapDescriptorFactory.fromRawfilePath(globalContext, "common/marker_default.png");
605
+ if (bitmapDesNull) {
606
+ this.markers[markerIndex].setIcon(bitmapDesNull);
607
+ }
608
+ }
609
+ }
610
+ }
611
+ break;
612
+ }
613
+ }
614
+ }
615
+ })
616
+ }
617
+
618
+ if (!flag) {
619
+ let markerOptions = new MarkerOptions();
620
+ GlobalCache.currentPageMarker.set(markerDescriptor.tag, this.tag)
621
+ this.markerTag.push(this.ctx.descriptorRegistry.getDescriptor(descriptor.childrenTags[i]).tag);
622
+ if (this.aMap) {
623
+ try {
624
+ if (markerOptions) {
625
+ markerOptions.setPosition(new LatLng(mapMarkerProps.position.latitude, mapMarkerProps.position.longitude));
626
+ markerOptions.setAnchor(mapMarkerProps.anchor ? mapMarkerProps.anchor.x : 1,
627
+ mapMarkerProps.anchor ? mapMarkerProps.anchor.y : 0.5);
628
+ //handle custom marker
629
+ if (markerChild.length > 0) {
630
+ let bitmapView: BitmapDescriptor | undefined = await BitmapDescriptorFactory.fromView(() => {
631
+ this.customMarkerBuilder(markerDescriptor.tag);
632
+ })
633
+ markerOptions.setIcon(bitmapView);
634
+ } else {
635
+ if (mapMarkerProps.icon) {
636
+ try {
637
+ let resoure: string = mapMarkerProps.icon["uri"];
638
+ let bitmapDes: BitmapDescriptor | undefined =
639
+ await BitmapDescriptorFactory.fromRawfilePath(globalContext, resoure);
640
+ markerOptions.setIcon(bitmapDes);
641
+ } catch (error) {
642
+ let bitmapDesNull: BitmapDescriptor | undefined =
643
+ await BitmapDescriptorFactory.fromRawfilePath(globalContext, "common/marker_default.png");
644
+ if (bitmapDesNull) {
645
+ markerOptions.setIcon(bitmapDesNull);
646
+ }
647
+ }
648
+ }
649
+ }
650
+ markerOptions.setDraggable(mapMarkerProps.draggable ? mapMarkerProps.draggable : false);
651
+ markerOptions.setZIndex(mapMarkerProps.zIndex ? mapMarkerProps.zIndex : 1);
652
+ markerOptions.setFlat(mapMarkerProps.flat ? mapMarkerProps.flat : false);
653
+ markerOptions.setInfoWindowOffset(mapMarkerProps.centerOffset?.x,mapMarkerProps.centerOffset?.y);
654
+ let marker: Marker| undefined = this.aMap.addMarker(markerOptions);
655
+ if(marker){
656
+ let markerTagAndDescriptorTagMap : HashMap<number, string> = new HashMap<number, string>();
657
+ markerTagAndDescriptorTagMap.set(markerDescriptor.tag, marker.getId())
658
+ this.markerTagAndDescriptorTagArray.push(markerTagAndDescriptorTagMap);
659
+ this.markers.push(marker);
660
+ }
661
+ GlobalCache.markerTagAndDescriptorTag.set(this.tag, this.markerTagAndDescriptorTagArray);
662
+ GlobalCache.mapMarker.set(this.tag, this.markers);
663
+ }
664
+ } catch (error) {
665
+ Logger.error('mapMarkerProps---------Error adding marker:', error);
666
+ }
667
+ }
668
+ }
669
+ break;
670
+ }
671
+ flag = false;
672
+ flagLine = false;
673
+ }
674
+ }
675
+
676
+ @Builder
677
+ customMarkerBuilder(markerTag: number) {
678
+ ContentSlot(this.ctx.getContentForTag(markerTag))
679
+ }
680
+
681
+ build() {
682
+ RNViewBase({ ctx: this.ctx, tag: this.tag }) {
683
+ MapViewComponent({ mapViewName: new String(this.tag).valueOf() }).width('100%').height('100%')
684
+ }
685
+ }
686
+ }