@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.
- package/LICENSE +21 -0
- package/README.OpenSource +11 -0
- package/README.md +10 -0
- package/harmony/rn_amap3d/BuildProfile.ets +6 -0
- package/harmony/rn_amap3d/build-profile.json5 +28 -0
- package/harmony/rn_amap3d/consumer-rules.txt +0 -0
- package/harmony/rn_amap3d/hvigorfile.ts +6 -0
- package/harmony/rn_amap3d/index.ets +30 -0
- package/harmony/rn_amap3d/obfuscation-rules.txt +18 -0
- package/harmony/rn_amap3d/oh-package.json5 +16 -0
- package/harmony/rn_amap3d/src/main/cpp/AMap3dEventEmitRequestHandler.h +218 -0
- package/harmony/rn_amap3d/src/main/cpp/AMapEventEmitters.cpp +132 -0
- package/harmony/rn_amap3d/src/main/cpp/AMapEventEmitters.h +111 -0
- package/harmony/rn_amap3d/src/main/cpp/CMakeLists.txt +7 -0
- package/harmony/rn_amap3d/src/main/cpp/ComponentDescriptors.h +19 -0
- package/harmony/rn_amap3d/src/main/cpp/MapViewJSIBinder.h +168 -0
- package/harmony/rn_amap3d/src/main/cpp/MapViewPackage.h +43 -0
- package/harmony/rn_amap3d/src/main/cpp/Props.cpp +86 -0
- package/harmony/rn_amap3d/src/main/cpp/Props.h +258 -0
- package/harmony/rn_amap3d/src/main/cpp/ShadowNodes.cpp +15 -0
- package/harmony/rn_amap3d/src/main/cpp/ShadowNodes.h +33 -0
- package/harmony/rn_amap3d/src/main/ets/AMap3DModule.ts +32 -0
- package/harmony/rn_amap3d/src/main/ets/AMap3DPackage.ts +46 -0
- package/harmony/rn_amap3d/src/main/ets/GlobalCache.ets +24 -0
- package/harmony/rn_amap3d/src/main/ets/Logger.ets +65 -0
- package/harmony/rn_amap3d/src/main/ets/View/AMapCircle.ets +96 -0
- package/harmony/rn_amap3d/src/main/ets/View/AMapMarker.ets +83 -0
- package/harmony/rn_amap3d/src/main/ets/View/AMapPolygon.ets +52 -0
- package/harmony/rn_amap3d/src/main/ets/View/AMapPolyline.ets +89 -0
- package/harmony/rn_amap3d/src/main/ets/View/MapView.ets +686 -0
- package/harmony/rn_amap3d/src/main/module.json5 +17 -0
- package/harmony/rn_amap3d/src/main/resources/base/element/string.json +8 -0
- package/harmony/rn_amap3d/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/rn_amap3d/src/main/resources/rawfile/location_map_gps_locked.png +0 -0
- package/harmony/rn_amap3d/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/rn_amap3d/ts.ts +28 -0
- package/harmony/rn_amap3d.har +0 -0
- package/lib/src/NativeAMapSdk.ts +9 -0
- package/lib/src/circle.tsx +17 -0
- package/lib/src/circleNativeComponent.ts +47 -0
- package/lib/src/cluster/cluster-view.tsx +47 -0
- package/lib/src/cluster/index.tsx +159 -0
- package/lib/src/component.ts +31 -0
- package/lib/src/heat-map.tsx +17 -0
- package/lib/src/heat-mapNativeComponent.ts +34 -0
- package/lib/src/index.ts +11 -0
- package/lib/src/map-view.tsx +73 -0
- package/lib/src/map-viewNativeComponent.ts +232 -0
- package/lib/src/marker.tsx +32 -0
- package/lib/src/markerNativeComponent.ts +105 -0
- package/lib/src/multi-point.tsx +17 -0
- package/lib/src/multi-pointNativeComponent.ts +51 -0
- package/lib/src/polygon.tsx +17 -0
- package/lib/src/polygonNativeComponent.ts +42 -0
- package/lib/src/polyline.tsx +21 -0
- package/lib/src/polylineNativeComponent.ts +67 -0
- package/lib/src/types.ts +34 -0
- package/package.json +53 -0
- package/react-native.config.js +20 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
26
|
+
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
|
|
27
|
+
import { AMap3DModule } from './AMap3DModule';
|
|
28
|
+
|
|
29
|
+
class AMap3DModulesFactory extends TurboModulesFactory {
|
|
30
|
+
createTurboModule(name: string): TurboModule | null {
|
|
31
|
+
if (name === 'AMapSdk') {
|
|
32
|
+
return new AMap3DModule(this.ctx)
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
hasTurboModule(name: string): boolean {
|
|
38
|
+
return name === 'AMapSdk';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class AMap3DPackage extends RNPackage {
|
|
43
|
+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
|
|
44
|
+
return new AMap3DModulesFactory(ctx);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AMap, MapView, Marker, Polygon, Polyline, Circle
|
|
3
|
+
} from '@amap/amap_lbs_map3d';
|
|
4
|
+
import HashMap from '@ohos.util.HashMap';
|
|
5
|
+
|
|
6
|
+
export default class GlobalCache {
|
|
7
|
+
public static index: number = 1
|
|
8
|
+
public static isGO: boolean = false;
|
|
9
|
+
public static cacheMap: Map<Object | undefined, number> = new Map()
|
|
10
|
+
public static cacheMapPageDestroy: Map<number, boolean> = new Map()
|
|
11
|
+
public static mapMarker: Map<number, Array<Marker>> = new Map();//map的tag和 marker集合
|
|
12
|
+
public static markerTagAndDescriptorTag: Map<number,Array<HashMap<number, string>>> = new Map();//map的tag和 marker的tag、marker的id
|
|
13
|
+
public static currentPageMarker: HashMap<number, number> = new HashMap();
|
|
14
|
+
|
|
15
|
+
public static mapPolyLine: Map<number, Array<Polyline>> = new Map();//存的是map的tag和polyLine集合
|
|
16
|
+
public static polyLinesTagAndDescriptorTag: Map<number,Array<HashMap<number, string>>> = new Map();//map的tag和 polyLine的tag、marker的id
|
|
17
|
+
public static currentPagePolyline: HashMap<number, number> = new HashMap();//存的是polyline的tag和map的tag
|
|
18
|
+
|
|
19
|
+
public static mapViews: HashMap<number, MapView> = new HashMap();
|
|
20
|
+
public static maps: HashMap<number, AMap> = new HashMap();
|
|
21
|
+
|
|
22
|
+
public static polygonCacheMap: HashMap<number, Polygon> = new HashMap();
|
|
23
|
+
public static circleCacheMap: HashMap<number, Circle> = new HashMap();
|
|
24
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import hilog from '@ohos.hilog';
|
|
26
|
+
|
|
27
|
+
class Logger {
|
|
28
|
+
private domain : number;
|
|
29
|
+
private prefix : string;
|
|
30
|
+
private format : string = '%{public}s, %{public}s';
|
|
31
|
+
private isDebug : boolean;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* constructor.
|
|
36
|
+
*
|
|
37
|
+
* @param Prefix Identifies the log tag.
|
|
38
|
+
* @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
|
|
39
|
+
*/
|
|
40
|
+
constructor(prefix: string = 'MyApp', domain: number = 0xFF00, isDebug = false) {
|
|
41
|
+
this.prefix = prefix;
|
|
42
|
+
this.domain = domain;
|
|
43
|
+
this.isDebug = isDebug;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
debug(...args: string[]): void {
|
|
47
|
+
if (this.isDebug) {
|
|
48
|
+
hilog.debug(this.domain, this.prefix, this.format, args);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
info(...args: string[]): void {
|
|
53
|
+
hilog.info(this.domain, this.prefix, this.format, args);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
warn(...args: string[]) : void {
|
|
57
|
+
hilog.warn(this.domain, this.prefix, this.format, args);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
error(...args: string[]) : void {
|
|
61
|
+
hilog.error(this.domain, this.prefix, this.format, args);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default new Logger('AMap3D', 0xFF00, false)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { LatLng} from '@amap/amap_lbs_map3d'
|
|
2
|
+
import { Descriptor, RNOHContext, ViewBaseProps } from '@rnoh/react-native-openharmony';
|
|
3
|
+
import GlobalCache from '../GlobalCache';
|
|
4
|
+
import { ArrayList } from '@kit.ArkTS';
|
|
5
|
+
|
|
6
|
+
export function rgbaToHex(rgbaString: string): number {
|
|
7
|
+
// 处理十六进制字符串(如 #RGB、#RRGGBB、#AARRGGBB)
|
|
8
|
+
let value: number;
|
|
9
|
+
if (rgbaString.startsWith('#')) {
|
|
10
|
+
const hex = rgbaString.slice(1); // 去掉 #
|
|
11
|
+
// 根据长度解析十六进制
|
|
12
|
+
switch (hex.length) {
|
|
13
|
+
case 3: // #RGB → 转换为 #RRGGBB(Alpha=FF)
|
|
14
|
+
value = parseInt(hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2], 16);
|
|
15
|
+
return 0xFF000000 | value;
|
|
16
|
+
case 6: // #RRGGBB → 转换为 #AARRGGBB(Alpha=FF)
|
|
17
|
+
value = parseInt(hex, 16);
|
|
18
|
+
return 0xFF000000 | value;
|
|
19
|
+
case 8: // #AARRGGBB → 直接转换为数值
|
|
20
|
+
return parseInt(hex, 16);
|
|
21
|
+
default:
|
|
22
|
+
throw new Error('Invalid hex color format (expected #RGB, #RRGGBB, or #AARRGGBB)');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 处理 RGB 格式(无 Alpha)
|
|
27
|
+
if (rgbaString.startsWith('rgb(')) {
|
|
28
|
+
const match = rgbaString.match(/(\d+(\.\d+)?)/g);
|
|
29
|
+
if (!match) throw new Error('Invalid RGB string format');
|
|
30
|
+
const red = parseInt(match[0]);
|
|
31
|
+
const green = parseInt(match[1]);
|
|
32
|
+
const blue = parseInt(match[2]);
|
|
33
|
+
value = 0xFF000000 | (red << 16) | (green << 8) | blue;
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 处理 RGBA 格式
|
|
38
|
+
if (rgbaString.startsWith('rgba(')) {
|
|
39
|
+
const match = rgbaString.match(/(\d+(\.\d+)?)/g);
|
|
40
|
+
if (!match) throw new Error('Invalid RGBA string format');
|
|
41
|
+
const r = match[0];
|
|
42
|
+
const g = match[1];
|
|
43
|
+
const b = match[2];
|
|
44
|
+
const a = match[3];
|
|
45
|
+
const red = Math.min(255, Math.max(0, parseInt(r)));
|
|
46
|
+
const green = Math.min(255, Math.max(0, parseInt(g)));
|
|
47
|
+
const blue = Math.min(255, Math.max(0, parseInt(b)));
|
|
48
|
+
const alpha = Math.round(Math.min(1, Math.max(0, parseFloat(a))) * 255);
|
|
49
|
+
value = (alpha << 24) | (red << 16) | (green << 8) | blue;
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
return 0xFF000000;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface AMapCircleProps extends ViewBaseProps {
|
|
56
|
+
center: LatLng;
|
|
57
|
+
radius?: number;
|
|
58
|
+
strokeWidth?: number;
|
|
59
|
+
strokeColor?: string;
|
|
60
|
+
fillColor?: string;
|
|
61
|
+
zIndex?: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const A_MAP_CIRCLE_VIEW_TYPE: string = "AMapCircle";
|
|
65
|
+
|
|
66
|
+
export type AMapCircleDescriptor = Descriptor<"AMapCircle", AMapCircleProps>
|
|
67
|
+
@Component
|
|
68
|
+
export struct AMapCircle {
|
|
69
|
+
static NAME:string = "AMapCircle";
|
|
70
|
+
ctx!: RNOHContext
|
|
71
|
+
tag: number = -1
|
|
72
|
+
@State circleDescriptor: AMapCircleDescriptor = {} as AMapCircleDescriptor
|
|
73
|
+
private unregisterDescriptorChangesListener?: () => void = undefined
|
|
74
|
+
|
|
75
|
+
aboutToAppear(): void {
|
|
76
|
+
this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
|
|
77
|
+
async (newDescriptor) => {
|
|
78
|
+
/*------ 当RN侧属性props有更改 -------*/
|
|
79
|
+
let currentCircle = GlobalCache.circleCacheMap.get(this.tag)
|
|
80
|
+
this.circleDescriptor = (newDescriptor as AMapCircleDescriptor)
|
|
81
|
+
let mapCircleProp = this.circleDescriptor.props as AMapCircleProps;
|
|
82
|
+
if (currentCircle) {
|
|
83
|
+
currentCircle.setRadius(mapCircleProp.radius ? mapCircleProp.radius : 5000);
|
|
84
|
+
currentCircle.setCenter(new LatLng(mapCircleProp.center.latitude, mapCircleProp.center.longitude));
|
|
85
|
+
currentCircle.setFillColor(rgbaToHex(mapCircleProp.fillColor ? mapCircleProp.fillColor : "rgba(255, 0, 0, 0.5)"));
|
|
86
|
+
currentCircle.setStrokeColor(rgbaToHex(mapCircleProp.strokeColor ? mapCircleProp.strokeColor :
|
|
87
|
+
"rgba(0, 0, 255, 0.5)"))
|
|
88
|
+
currentCircle.setStrokeWidth(mapCircleProp.strokeWidth ? mapCircleProp.strokeWidth : 5);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
build() {
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { BitmapDescriptor, BitmapDescriptorFactory, LatLng, Marker, Point } from '@amap/amap_lbs_map3d';
|
|
2
|
+
import { Descriptor, RNComponentContext, RNOHContext, ViewBaseProps } from '@rnoh/react-native-openharmony';
|
|
3
|
+
import { globalContext } from './MapView';
|
|
4
|
+
import GlobalCache from '../GlobalCache';
|
|
5
|
+
import { HashMap } from '@kit.ArkTS';
|
|
6
|
+
|
|
7
|
+
export interface AMapMarkerProps extends ViewBaseProps {
|
|
8
|
+
position: LatLng;
|
|
9
|
+
icon?: BitmapDescriptor;
|
|
10
|
+
opacity?: number;
|
|
11
|
+
draggable?: boolean;
|
|
12
|
+
flat?: boolean;
|
|
13
|
+
zIndex?: number;
|
|
14
|
+
anchor?: Point;
|
|
15
|
+
centerOffset?: Point;
|
|
16
|
+
tag?:string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const A_MAP_MARKER_TYPE: string = "AMapMarker";
|
|
20
|
+
|
|
21
|
+
export type AMapMarkerDescriptor = Descriptor<"AMapMarker", AMapMarkerProps>;
|
|
22
|
+
|
|
23
|
+
@Component
|
|
24
|
+
export struct AMapMarker {
|
|
25
|
+
ctx !: RNComponentContext
|
|
26
|
+
tag: number = -1
|
|
27
|
+
markers: Array<Marker> = []
|
|
28
|
+
markerTagAndDescriptorTagArray: Array<HashMap<number, string>> = []
|
|
29
|
+
@State amapDescriptor: AMapMarkerDescriptor = {} as AMapMarkerDescriptor
|
|
30
|
+
private unregisterDescriptorChangesListener?: () => void = undefined
|
|
31
|
+
static NAME: string = "AMapMarker";
|
|
32
|
+
|
|
33
|
+
aboutToAppear(): void {
|
|
34
|
+
this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
|
|
35
|
+
async (newDescriptor) => {
|
|
36
|
+
/*------ 当RN侧属性props有更改 -------*/
|
|
37
|
+
let currentMapTag = GlobalCache.currentPageMarker.get(this.tag)
|
|
38
|
+
this.markers = GlobalCache.mapMarker.get(currentMapTag) ?? [];
|
|
39
|
+
this.markerTagAndDescriptorTagArray = GlobalCache.markerTagAndDescriptorTag.get(currentMapTag) ?? [];
|
|
40
|
+
this.amapDescriptor = (newDescriptor as AMapMarkerDescriptor)
|
|
41
|
+
let mapMarkerProps = this.amapDescriptor.props as AMapMarkerProps;
|
|
42
|
+
if (this.markers) {
|
|
43
|
+
|
|
44
|
+
for (let j = 0; j < this.markerTagAndDescriptorTagArray.length; ++j) {
|
|
45
|
+
this.markerTagAndDescriptorTagArray[j].forEach(async (markerID: string, markerTag: number, map: HashMap<number, string>) => {
|
|
46
|
+
if (markerTag == this.tag) {
|
|
47
|
+
for (let i = 0; i < this.markers.length; ++i) {
|
|
48
|
+
if (this.markers[i].getId() == markerID) {
|
|
49
|
+
this.markers[i].setPosition(new LatLng(mapMarkerProps.position.latitude, mapMarkerProps.position.longitude));
|
|
50
|
+
this.markers[i].setAnchor(mapMarkerProps.anchor ? mapMarkerProps.anchor.x : 1,
|
|
51
|
+
mapMarkerProps.anchor ? mapMarkerProps.anchor.y : 0.5);
|
|
52
|
+
this.markers[i].setDraggable(mapMarkerProps.draggable ? mapMarkerProps.draggable : false);
|
|
53
|
+
//this.markers[i].setZIndex(mapMarkerProps.zIndex ? mapMarkerProps.zIndex : 1);
|
|
54
|
+
this.markers[i].setFlat(mapMarkerProps.flat ? mapMarkerProps.flat : false);
|
|
55
|
+
this.markers[i].getOptions().setInfoWindowOffset(mapMarkerProps.centerOffset?.x,mapMarkerProps.centerOffset?.y);
|
|
56
|
+
if (mapMarkerProps.icon) {
|
|
57
|
+
try {
|
|
58
|
+
let resoure: string = mapMarkerProps.icon["uri"];
|
|
59
|
+
let bitmapDes: BitmapDescriptor | undefined =
|
|
60
|
+
await BitmapDescriptorFactory.fromRawfilePath(globalContext, resoure);
|
|
61
|
+
this.markers[i].setIcon(bitmapDes);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
let bitmapDesNull: BitmapDescriptor | undefined =
|
|
64
|
+
await BitmapDescriptorFactory.fromRawfilePath(globalContext, "common/marker_default.png");
|
|
65
|
+
if (bitmapDesNull) {
|
|
66
|
+
this.markers[i].setIcon(bitmapDesNull);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
build() {
|
|
81
|
+
ContentSlot(this.ctx.getContentForTag(this.tag))
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { LatLng, } from '@amap/amap_lbs_map3d';
|
|
2
|
+
import { Descriptor, RNOHContext, ViewBaseProps } from '@rnoh/react-native-openharmony';
|
|
3
|
+
import GlobalCache from '../GlobalCache';
|
|
4
|
+
import { ArrayList } from '@kit.ArkTS';
|
|
5
|
+
import { rgbaToHex } from './AMapCircle';
|
|
6
|
+
|
|
7
|
+
export interface AMapPolygonProps extends ViewBaseProps {
|
|
8
|
+
points: LatLng[];
|
|
9
|
+
strokeWidth?: number;
|
|
10
|
+
strokeColor?: string;
|
|
11
|
+
fillColor?: string;
|
|
12
|
+
zIndex?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const A_MAP_POLYGON_TYPE: string = "AMapPolygon";
|
|
16
|
+
export type AMapPolygonDescriptor = Descriptor<"AMapPolygon", AMapPolygonProps>
|
|
17
|
+
@Component
|
|
18
|
+
export struct AMapPolygon {
|
|
19
|
+
ctx !: RNOHContext
|
|
20
|
+
tag: number = -1
|
|
21
|
+
@State amapDescriptor: AMapPolygonDescriptor = {} as AMapPolygonDescriptor
|
|
22
|
+
static NAME: string = "AMapPolygon";
|
|
23
|
+
private unregisterDescriptorChangesListener?: () => void = undefined
|
|
24
|
+
|
|
25
|
+
aboutToAppear(): void {
|
|
26
|
+
this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
|
|
27
|
+
async (newDescriptor) => {
|
|
28
|
+
/*------ 当RN侧属性props有更改 -------*/
|
|
29
|
+
let currentPolygon = GlobalCache.polygonCacheMap.get(this.tag)
|
|
30
|
+
this.amapDescriptor = (newDescriptor as AMapPolygonDescriptor)
|
|
31
|
+
let mapPolygonProp = this.amapDescriptor.props as AMapPolygonProps;
|
|
32
|
+
if (currentPolygon) {
|
|
33
|
+
let polygonOptionsList = new ArrayList<LatLng>()
|
|
34
|
+
for (let index = 0; index < mapPolygonProp.points.length; index++) {
|
|
35
|
+
polygonOptionsList.add(new LatLng(mapPolygonProp.points[index].latitude,
|
|
36
|
+
mapPolygonProp.points[index].longitude))
|
|
37
|
+
}
|
|
38
|
+
currentPolygon.setPoints(polygonOptionsList);
|
|
39
|
+
currentPolygon.setFillColor(rgbaToHex(mapPolygonProp.fillColor ? mapPolygonProp.fillColor :
|
|
40
|
+
"rgba(255, 0, 0, 0.5)"));
|
|
41
|
+
currentPolygon.setStrokeWidth(mapPolygonProp.strokeWidth ? mapPolygonProp.strokeWidth : 5);
|
|
42
|
+
currentPolygon.setStrokeColor(rgbaToHex(mapPolygonProp.strokeColor ? mapPolygonProp.strokeColor :
|
|
43
|
+
"rgba(255, 0, 0, 0.5)"));
|
|
44
|
+
currentPolygon.setZIndex(mapPolygonProp.zIndex ? mapPolygonProp.zIndex : 2);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
build() {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { LatLng, Polyline, } from '@amap/amap_lbs_map3d';
|
|
2
|
+
import { Descriptor, RNOHContext, ViewBaseProps } from '@rnoh/react-native-openharmony';
|
|
3
|
+
import GlobalCache from '../GlobalCache';
|
|
4
|
+
import { ArrayList, HashMap } from '@kit.ArkTS';
|
|
5
|
+
import { rgbaToHex } from './AMapCircle';
|
|
6
|
+
|
|
7
|
+
export interface AMapPolylineProps extends ViewBaseProps {
|
|
8
|
+
points: LatLng[];
|
|
9
|
+
width?: number;
|
|
10
|
+
color?: string;
|
|
11
|
+
zIndex?: number;
|
|
12
|
+
colors: string[];
|
|
13
|
+
gradient?: boolean;
|
|
14
|
+
geodesic?: boolean;
|
|
15
|
+
dotted?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function convertColorsToNumbers(colorString: string): number {
|
|
19
|
+
const hex = colorString.substring(1);
|
|
20
|
+
return parseInt(hex, 16);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const A_MAP_POLYLINE_TYPE: string = "AMapPolyline";
|
|
24
|
+
|
|
25
|
+
export type AMapPolylineDescriptor = Descriptor<"AMapPolyline", AMapPolylineProps>
|
|
26
|
+
|
|
27
|
+
@Component
|
|
28
|
+
export struct AMapPolyline {
|
|
29
|
+
ctx !: RNOHContext
|
|
30
|
+
tag: number = -1
|
|
31
|
+
polyLines: Array<Polyline> = [];
|
|
32
|
+
polyLineTagAndDescriptorTagArray: Array<HashMap<number, string>> = []
|
|
33
|
+
@State amapDescriptor: AMapPolylineDescriptor = {} as AMapPolylineDescriptor
|
|
34
|
+
static NAME: string = "AMapPolyline";
|
|
35
|
+
private unregisterDescriptorChangesListener?: () => void = undefined
|
|
36
|
+
|
|
37
|
+
aboutToAppear(): void {
|
|
38
|
+
this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
|
|
39
|
+
async (newDescriptor) => {
|
|
40
|
+
/*------ 当RN侧属性props有更改 -------*/
|
|
41
|
+
let currentMapTag = GlobalCache.currentPagePolyline.get(this.tag)
|
|
42
|
+
this.polyLines = GlobalCache.mapPolyLine.get(currentMapTag) ?? [];
|
|
43
|
+
this.polyLineTagAndDescriptorTagArray = GlobalCache.polyLinesTagAndDescriptorTag.get(currentMapTag) ?? [];
|
|
44
|
+
this.amapDescriptor = (newDescriptor as AMapPolylineDescriptor)
|
|
45
|
+
let mapPolylineProp = this.amapDescriptor.props as AMapPolylineProps;
|
|
46
|
+
if (this.polyLines && this.polyLines.length > 0) {
|
|
47
|
+
for (let j = 0; j < this.polyLineTagAndDescriptorTagArray.length; ++j) {
|
|
48
|
+
this.polyLineTagAndDescriptorTagArray[j].forEach(async (polyLineID: string, polyLineTag: number,
|
|
49
|
+
map: HashMap<number, string>) => {
|
|
50
|
+
if (polyLineTag == this.tag) {
|
|
51
|
+
for (let i = 0; i < this.polyLines.length; ++i) {
|
|
52
|
+
if (this.polyLines[i].getId() == polyLineID) {
|
|
53
|
+
this.polyLines[i].setZIndex(mapPolylineProp.zIndex ? mapPolylineProp.zIndex : 1);
|
|
54
|
+
this.polyLines[i].setDottedLine(mapPolylineProp.dotted ? mapPolylineProp.dotted : false);
|
|
55
|
+
this.polyLines[i].setGeodesic(mapPolylineProp.geodesic ? mapPolylineProp.geodesic : false);
|
|
56
|
+
this.polyLines[i].setWidth(mapPolylineProp.width ? vp2px(mapPolylineProp.width) : vp2px(5));
|
|
57
|
+
let polylineOptionsList = new ArrayList<LatLng>()
|
|
58
|
+
for (let index = 0; index < mapPolylineProp.points.length; index++) {
|
|
59
|
+
polylineOptionsList.add(new LatLng(mapPolylineProp.points[index].latitude,
|
|
60
|
+
mapPolylineProp.points[index].longitude))
|
|
61
|
+
}
|
|
62
|
+
this.polyLines[i].setPoints(polylineOptionsList);
|
|
63
|
+
if (mapPolylineProp.color) {
|
|
64
|
+
this.polyLines[i].setColor(rgbaToHex(mapPolylineProp.color ? mapPolylineProp.color :
|
|
65
|
+
"rgba(0, 255, 0, 0.5)"));
|
|
66
|
+
}
|
|
67
|
+
if (mapPolylineProp.colors) {
|
|
68
|
+
let test = new Int32Array(mapPolylineProp.colors.length)
|
|
69
|
+
for (let i = 0; i < mapPolylineProp.colors.length; ++i) {
|
|
70
|
+
let str = mapPolylineProp.colors[i].replace("#", "0xff")
|
|
71
|
+
test[i] = parseInt(str.substring(2, str.length), 16)
|
|
72
|
+
}
|
|
73
|
+
this.polyLines[i].getOptions().setColorValues(test);
|
|
74
|
+
this.polyLines[i].getOptions().setGradient(mapPolylineProp.gradient ? mapPolylineProp.gradient : false);
|
|
75
|
+
this.polyLines[i].setOptions(this.polyLines[i].getOptions());
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
build() {
|
|
88
|
+
}
|
|
89
|
+
}
|