@react-native-ohos/react-native-amap3d 3.2.5-rc.1 → 3.2.6-rc.2

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 (34) hide show
  1. package/README.md +1 -1
  2. package/harmony/rn_amap3d/index.ets +2 -0
  3. package/harmony/rn_amap3d/obfuscation-rules.txt +5 -1
  4. package/harmony/rn_amap3d/oh-package.json5 +5 -4
  5. package/harmony/rn_amap3d/src/main/cpp/AMap3dEventEmitRequestHandler.h +105 -94
  6. package/harmony/rn_amap3d/src/main/cpp/AMapEventEmitters.cpp +22 -12
  7. package/harmony/rn_amap3d/src/main/cpp/AMapEventEmitters.h +4 -1
  8. package/harmony/rn_amap3d/src/main/cpp/MapViewJSIBinder.h +40 -20
  9. package/harmony/rn_amap3d/src/main/cpp/MapViewPackage.h +6 -3
  10. package/harmony/rn_amap3d/src/main/cpp/Props.cpp +5 -5
  11. package/harmony/rn_amap3d/src/main/cpp/Props.h +14 -11
  12. package/harmony/rn_amap3d/src/main/cpp/ShadowNodes.cpp +7 -7
  13. package/harmony/rn_amap3d/src/main/cpp/ShadowNodes.h +14 -14
  14. package/harmony/rn_amap3d/src/main/ets/AMap3DModule.ts +52 -4
  15. package/harmony/rn_amap3d/src/main/ets/AMap3DPackage.ets +119 -0
  16. package/harmony/rn_amap3d/src/main/ets/DownloadIcon.ets +172 -0
  17. package/harmony/rn_amap3d/src/main/ets/View/AMapCircle.ets +2 -2
  18. package/harmony/rn_amap3d/src/main/ets/View/AMapMarker.ets +2 -2
  19. package/harmony/rn_amap3d/src/main/ets/View/AMapPolygon.ets +4 -2
  20. package/harmony/rn_amap3d/src/main/ets/View/AMapPolyline.ets +2 -2
  21. package/harmony/rn_amap3d/src/main/ets/View/MapView.ets +138 -61
  22. package/harmony/rn_amap3d/{ts.ts → ts.ets} +1 -1
  23. package/harmony/rn_amap3d.har +0 -0
  24. package/lib/src/map-view.tsx +2 -2
  25. package/lib/src/{map-viewNativeComponent.ts → map-viewNativeComponent.tsx} +6 -11
  26. package/package.json +10 -4
  27. package/harmony/rn_amap3d/BuildProfile.ets +0 -6
  28. package/harmony/rn_amap3d/src/main/ets/AMap3DPackage.ts +0 -46
  29. /package/lib/src/{circleNativeComponent.ts → circleNativeComponent.tsx} +0 -0
  30. /package/lib/src/{heat-mapNativeComponent.ts → heat-mapNativeComponent.tsx} +0 -0
  31. /package/lib/src/{markerNativeComponent.ts → markerNativeComponent.tsx} +0 -0
  32. /package/lib/src/{multi-pointNativeComponent.ts → multi-pointNativeComponent.tsx} +0 -0
  33. /package/lib/src/{polygonNativeComponent.ts → polygonNativeComponent.tsx} +0 -0
  34. /package/lib/src/{polylineNativeComponent.ts → polylineNativeComponent.tsx} +0 -0
@@ -1,5 +1,5 @@
1
- #ifndef HARMONY_RN_AMAP3D_SRC_MAIN_CPP_PROPS_H
2
- #define HARMONY_RN_AMAP3D_SRC_MAIN_CPP_PROPS_H
1
+ #ifndef AMAP3D_PROPS_H
2
+ #define AMAP3D_PROPS_H
3
3
 
4
4
  #include <jsi/jsi.h>
5
5
  #include <react/renderer/components/view/ViewProps.h>
@@ -31,8 +31,9 @@ struct ImageSourcePropType {
31
31
  std::string bundle;
32
32
  };
33
33
 
34
- static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, LatLng &result) {
35
- auto map = (std::unordered_map<std::string, RawValue>)value;
34
+ inline void fromRawValue(const PropsParserContext &context, const RawValue &value, LatLng &result)
35
+ {
36
+ auto map = (butter::map<std::string, RawValue>)value;
36
37
  auto tmp_latitude = map.find("latitude");
37
38
  if (tmp_latitude != map.end()) {
38
39
  fromRawValue(context, tmp_latitude->second, result.latitude);
@@ -43,10 +44,11 @@ static inline void fromRawValue(const PropsParserContext &context, const RawValu
43
44
  }
44
45
  }
45
46
 
46
- static inline std::string toString(const LatLng &value) { return "[Object LatLng]"; }
47
+ inline std::string toString(const LatLng &value) { return "[Object LatLng]"; }
47
48
 
48
- static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, CameraPosition &result) {
49
- auto map = (std::unordered_map<std::string, RawValue>)value;
49
+ inline void fromRawValue(const PropsParserContext &context, const RawValue &value, CameraPosition &result)
50
+ {
51
+ auto map = (butter::map<std::string, RawValue>)value;
50
52
  auto tmp_target = map.find("target");
51
53
  if (tmp_target != map.end()) {
52
54
  fromRawValue(context, tmp_target->second, result.target);
@@ -65,10 +67,11 @@ static inline void fromRawValue(const PropsParserContext &context, const RawValu
65
67
  }
66
68
  }
67
69
 
68
- static inline std::string toString(const CameraPosition &value) { return "[Object CameraPosition]"; }
70
+ inline std::string toString(const CameraPosition &value) { return "[Object CameraPosition]"; }
69
71
 
70
- static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, ImageSourcePropType &result) {
71
- auto map = (std::unordered_map<std::string, RawValue>)value;
72
+ inline void fromRawValue(const PropsParserContext &context, const RawValue &value, ImageSourcePropType &result)
73
+ {
74
+ auto map = (butter::map<std::string, RawValue>)value;
72
75
  auto tmp_uri = map.find("uri");
73
76
  if (tmp_uri != map.end()) {
74
77
  fromRawValue(context, tmp_uri->second, result.uri);
@@ -99,7 +102,7 @@ static inline void fromRawValue(const PropsParserContext &context, const RawValu
99
102
  }
100
103
  }
101
104
 
102
- static inline std::string toString(const ImageSourcePropType &value) { return "[Object ImageSourcePropType]"; }
105
+ inline std::string toString(const ImageSourcePropType &value) { return "[Object ImageSourcePropType]"; }
103
106
 
104
107
  class JSI_EXPORT MapViewProps final : public ViewProps {
105
108
  public:
@@ -3,13 +3,13 @@
3
3
  namespace facebook {
4
4
  namespace react {
5
5
 
6
- extern const char MapViewComponentName[] = "AMapView";
7
- extern const char HeatMapComponentName[] = "AMapHeatMap";
8
- extern const char CircleComponentName[] = "AMapCircle";
9
- extern const char PolylineComponentName[] = "AMapPolyline";
10
- extern const char PolygonComponentName[] = "AMapPolygon";
11
- extern const char MultipointComponentName[] = "AMapMultiPoint";
12
- extern const char MarkerComponentName[] = "AMapMarker";
6
+ const char MapViewComponentName[] = "AMapView";
7
+ const char HeatMapComponentName[] = "AMapHeatMap";
8
+ const char CircleComponentName[] = "AMapCircle";
9
+ const char PolylineComponentName[] = "AMapPolyline";
10
+ const char PolygonComponentName[] = "AMapPolygon";
11
+ const char MultipointComponentName[] = "AMapMultiPoint";
12
+ const char MarkerComponentName[] = "AMapMarker";
13
13
 
14
14
  } // namespace react
15
15
  } // namespace facebook
@@ -9,24 +9,24 @@
9
9
  namespace facebook {
10
10
  namespace react {
11
11
 
12
- JSI_EXPORT extern const char MapViewComponentName[];
13
- JSI_EXPORT extern const char HeatMapComponentName[];
14
- JSI_EXPORT extern const char CircleComponentName[];
15
- JSI_EXPORT extern const char PolylineComponentName[];
16
- JSI_EXPORT extern const char PolygonComponentName[];
17
- JSI_EXPORT extern const char MultipointComponentName[];
18
- JSI_EXPORT extern const char MarkerComponentName[];
12
+ JSI_EXPORT extern const char MapViewComponentName[100];
13
+ JSI_EXPORT extern const char HeatMapComponentName[100];
14
+ JSI_EXPORT extern const char CircleComponentName[100];
15
+ JSI_EXPORT extern const char PolylineComponentName[100];
16
+ JSI_EXPORT extern const char PolygonComponentName[100];
17
+ JSI_EXPORT extern const char MultipointComponentName[100];
18
+ JSI_EXPORT extern const char MarkerComponentName[100];
19
19
 
20
20
  /*
21
21
  * `ShadowNode` for <RNCViewPager> component.
22
22
  */
23
- using MapViewShadowNode = ConcreteViewShadowNode<MapViewComponentName, MapViewProps,MapViewEventEmitter>;
24
- using HeatMapShadowNode = ConcreteViewShadowNode<HeatMapComponentName, HeatMapProps,HeatMapEventEmitter>;
25
- using CircleShadowNode = ConcreteViewShadowNode<CircleComponentName, CircleProps,CircleEventEmitter>;
26
- using PolylineShadowNode = ConcreteViewShadowNode<PolylineComponentName, PolylineProps,PolylineEventEmitter>;
27
- using PolygonShadowNode = ConcreteViewShadowNode<PolygonComponentName, PolygonProps,PolygonEventEmitter>;
28
- using MultipointShadowNode = ConcreteViewShadowNode<MultipointComponentName, MultipointProps,MultiPointEventEmitter>;
29
- using MarkerShadowNode = ConcreteViewShadowNode<MarkerComponentName, MarkerProps,MarkerEventEmitter>;
23
+ using MapViewShadowNode = ConcreteViewShadowNode<MapViewComponentName, MapViewProps, MapViewEventEmitter>;
24
+ using HeatMapShadowNode = ConcreteViewShadowNode<HeatMapComponentName, HeatMapProps, HeatMapEventEmitter>;
25
+ using CircleShadowNode = ConcreteViewShadowNode<CircleComponentName, CircleProps, CircleEventEmitter>;
26
+ using PolylineShadowNode = ConcreteViewShadowNode<PolylineComponentName, PolylineProps, PolylineEventEmitter>;
27
+ using PolygonShadowNode = ConcreteViewShadowNode<PolygonComponentName, PolygonProps, PolygonEventEmitter>;
28
+ using MultipointShadowNode = ConcreteViewShadowNode<MultipointComponentName, MultipointProps, MultiPointEventEmitter>;
29
+ using MarkerShadowNode = ConcreteViewShadowNode<MarkerComponentName, MarkerProps, MarkerEventEmitter>;
30
30
 
31
31
  } // namespace react
32
32
  } // namespace facebook
@@ -22,11 +22,59 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- import { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
26
25
 
26
+ import type { UITurboModuleContext } from '@rnoh/react-native-openharmony/ts';
27
+ import { UITurboModule } from '@rnoh/react-native-openharmony/ts';
27
28
 
28
- export class AMap3DModule extends TurboModule {
29
- constructor(ctx: TurboModuleContext) {
29
+ declare global {
30
+ var AMapSDK: {
31
+ setXComponentCallback?: (callback: (data: any) => void) => void;
32
+ init?: (apiKey: string) => boolean;
33
+ setCenter?: (lat: number, lng: number) => void;
34
+ } | undefined;
35
+ }
36
+
37
+ export class AMap3DModule extends UITurboModule {
38
+ private static instance: AMap3DModule | null = null;
39
+
40
+ constructor(ctx: UITurboModuleContext) {
30
41
  super(ctx);
42
+ AMap3DModule.instance = this;
43
+ }
44
+
45
+ static getInstance(): AMap3DModule | null {
46
+ return this.instance;
47
+ }
48
+
49
+ nativeSetAMapXComponentCallback(callback: (eventData: any) => void): void {
50
+ try {
51
+ if (globalThis.AMapSDK && globalThis.AMapSDK.setXComponentCallback) {
52
+ globalThis.AMapSDK.setXComponentCallback(callback);
53
+ } else {
54
+ setTimeout(() => {
55
+ try {
56
+ callback({ type: 'mapReady', status: 'success' });
57
+ } catch (e) {
58
+ }
59
+ }, 50);
60
+ }
61
+ } catch (error) {
62
+ setTimeout(() => callback({ type: 'mapReady', status: 'fallback' }), 50);
63
+ }
31
64
  }
32
- }
65
+
66
+ init(apiKey: string): boolean {
67
+ return true;
68
+ }
69
+ setCenter(latitude: number, longitude: number): void {
70
+ }
71
+ isModuleAvailable(): boolean {
72
+ return true;
73
+ }
74
+ }
75
+
76
+ export const getAMapModuleInstance = (): AMap3DModule | null => {
77
+ return AMap3DModule.getInstance();
78
+ };
79
+
80
+ export default AMap3DModule;
@@ -0,0 +1,119 @@
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
+ import type {
25
+ UITurboModule,
26
+ UITurboModuleContext
27
+ } from '@rnoh/react-native-openharmony/ts';
28
+ import { RNOHPackage, TurboModulesFactory, ComponentBuilderContext } from '@rnoh/react-native-openharmony'
29
+ import { AMap3DModule } from './AMap3DModule';
30
+ import type { TurboModule } from '@rnoh/react-native-openharmony/ts';
31
+ import { A_MAP_CIRCLE_VIEW_TYPE, AMapCircle } from './View/AMapCircle';
32
+ import { A_MAP_MARKER_TYPE, AMapMarker } from './View/AMapMarker';
33
+ import { A_MAP_POLYGON_TYPE, AMapPolygon } from './View/AMapPolygon';
34
+ import { A_MAP_POLYLINE_TYPE, AMapPolyline } from './View/AMapPolyline';
35
+ import { GOADE_MAP_VIEW_TYPE, AMapView } from './View/MapView';
36
+
37
+ @Builder
38
+ function aMapCircle(ctx: ComponentBuilderContext) {
39
+ AMapCircle({ ctx: ctx.rnComponentContext, tag: ctx.tag })
40
+ }
41
+
42
+ @Builder
43
+ function aMapMarker(ctx: ComponentBuilderContext) {
44
+ AMapMarker({ ctx: ctx.rnComponentContext, tag: ctx.tag })
45
+ }
46
+
47
+ @Builder
48
+ function aMapPolygon(ctx: ComponentBuilderContext) {
49
+ AMapPolygon({ ctx: ctx.rnComponentContext, tag: ctx.tag })
50
+ }
51
+
52
+ @Builder
53
+ function aMapPolyline(ctx: ComponentBuilderContext) {
54
+ AMapPolyline({ ctx: ctx.rnComponentContext, tag: ctx.tag })
55
+ }
56
+
57
+ @Builder
58
+ function aMapView(ctx: ComponentBuilderContext) {
59
+ AMapView({ ctx: ctx.rnComponentContext, tag: ctx.tag })
60
+ }
61
+
62
+ class RNAMap3DTurboModuleFactory extends TurboModulesFactory {
63
+ createTurboModule(name: string): TurboModule | null {
64
+ if (this.hasTurboModule(name)) {
65
+ return new AMap3DModule(this.ctx);
66
+ }
67
+ return null;
68
+ }
69
+
70
+ hasTurboModule(name: string): boolean {
71
+ return name === 'AMapSdk';
72
+ }
73
+ }
74
+
75
+ export class AMap3DPackage extends RNOHPackage {
76
+ // 确保模块被正确创建
77
+ getUITurboModuleFactoryByNameMap(): Map<
78
+ string,
79
+ (ctx: UITurboModuleContext) => UITurboModule | null
80
+ > {
81
+ const map = new Map<string, (ctx: UITurboModuleContext) => UITurboModule | null>();
82
+ map.set('AMapSdk', (ctx: UITurboModuleContext) => {
83
+ try {
84
+ const module = new AMap3DModule(ctx);
85
+ return module;
86
+ } catch (error) {
87
+ return null;
88
+ }
89
+ });
90
+ return map;
91
+ }
92
+
93
+ createTurboModulesFactory(ctx: UITurboModuleContext): TurboModulesFactory {
94
+ return new RNAMap3DTurboModuleFactory(ctx);
95
+ }
96
+
97
+ getDebugName(): string {
98
+ return 'AMap3DPackage';
99
+ }
100
+
101
+ createWrappedCustomRNComponentBuilderByComponentNameMap(): Map<string, WrappedBuilder<[ComponentBuilderContext]>> {
102
+ const aMapBuilderMap = new Map<string, WrappedBuilder<[ComponentBuilderContext]>>();
103
+
104
+ aMapBuilderMap.set(GOADE_MAP_VIEW_TYPE, wrapBuilder(aMapView))
105
+ aMapBuilderMap.set(A_MAP_CIRCLE_VIEW_TYPE, wrapBuilder(aMapCircle))
106
+ aMapBuilderMap.set(A_MAP_MARKER_TYPE, wrapBuilder(aMapMarker))
107
+ aMapBuilderMap.set(A_MAP_POLYGON_TYPE, wrapBuilder(aMapPolygon))
108
+ aMapBuilderMap.set(A_MAP_POLYLINE_TYPE, wrapBuilder(aMapPolyline))
109
+
110
+ return aMapBuilderMap;
111
+ }
112
+ }
113
+
114
+ export const createAMap3DPackage = () => {
115
+ console.log('Creating AMap3DPackage instance');
116
+ return new AMap3DPackage({});
117
+ };
118
+
119
+ export default AMap3DPackage;
@@ -0,0 +1,172 @@
1
+ import { Marker, MarkerOptions, BitmapDescriptor, BitmapDescriptorFactory, } from '@amap/amap_lbs_map3d';
2
+ import { fileIo } from '@kit.CoreFileKit';
3
+ import { common } from '@kit.AbilityKit';
4
+ import { BusinessError, request } from '@kit.BasicServicesKit';
5
+ import { image } from '@kit.ImageKit';
6
+ import Logger from './Logger';
7
+
8
+ interface packOptsType {
9
+ format: string;
10
+ quality: number;
11
+ }
12
+ const IMAGE_FORMAT = ['gif', 'jpeg', 'jpg', 'webp', 'png'];
13
+ const ENCODE_FORMAT = ['image/png', 'image/jpeg', 'image/webp'];
14
+
15
+ export class DownloadIcon {
16
+ static async updataMakerIcon(context: UIContext, marker: Marker | MarkerOptions, icon: BitmapDescriptor) {
17
+ let src: string = icon['uri'];
18
+ let width: number | undefined = icon['width'] || undefined;
19
+ let height: number | undefined = icon['height'] || undefined;
20
+
21
+ let bitmapDes: BitmapDescriptor | undefined;
22
+
23
+ if (src) {
24
+ if (src!.startsWith('http://') || src!.startsWith('https://')) {
25
+ const filePath: string = await DownloadIcon.doLoadHttpImage(context, src, 0);
26
+ let imagePathToUse = filePath;
27
+
28
+ if (width !== undefined || height !== undefined) {
29
+ // Process the image and get the processed path (could be temp file or original)
30
+ imagePathToUse = await DownloadIcon.resizeImage(filePath, width, height);
31
+ }
32
+
33
+ let file = fileIo.openSync(imagePathToUse, fileIo.OpenMode.READ_ONLY);
34
+ bitmapDes = await BitmapDescriptorFactory.fromFd(file.fd);
35
+ fileIo.closeSync(file.fd);
36
+ marker.setIcon(bitmapDes);
37
+
38
+ // Clean up temporary file if it was created and is different from original
39
+ if (imagePathToUse !== filePath) {
40
+ fileIo.unlinkSync(imagePathToUse);
41
+ }
42
+ } else {
43
+ bitmapDes =
44
+ await BitmapDescriptorFactory.fromRawfilePath(context.getHostContext()!.getApplicationContext(), src);
45
+ marker.setIcon(bitmapDes);
46
+ }
47
+ }
48
+ }
49
+
50
+ static async resizeImage(filePath: string, targetWidth: number | undefined, targetHeight: number | undefined): Promise<string> {
51
+ // Create a safe temporary file path by inserting .temp before the extension
52
+ const lastDotIndex = filePath.lastIndexOf('.');
53
+ let tempFilePath: string;
54
+ if (lastDotIndex !== -1) {
55
+ tempFilePath = filePath.substring(0, lastDotIndex) + '.temp' + filePath.substring(lastDotIndex);
56
+ } else {
57
+ tempFilePath = filePath + '.temp';
58
+ }
59
+
60
+ try {
61
+ let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_ONLY);
62
+ const imageSource = image.createImageSource(file.fd);
63
+ // Get picture format information
64
+ const imageInfo = imageSource.getImageInfoSync();
65
+ const mimeType = imageInfo.mimeType || '';
66
+ targetWidth = targetWidth !== undefined ? targetWidth : imageInfo.size.width;
67
+ targetHeight = targetHeight !== undefined ? targetHeight : imageInfo.size.height;
68
+ fileIo.closeSync(file.fd);
69
+
70
+ const finalWidth = Math.round(targetWidth);
71
+ const finalHeight = Math.round(targetHeight);
72
+ let decodingOptions: image.DecodingOptions = {
73
+ sampleSize: 1,
74
+ editable: true,
75
+ desiredSize: { width: finalWidth, height: finalHeight },
76
+ index: 0
77
+ };
78
+
79
+ let pixelMap = imageSource.createPixelMapSync(decodingOptions);
80
+
81
+ const imagePacker = image.createImagePacker();
82
+
83
+ let outputFormat: string;
84
+ if (mimeType.includes(IMAGE_FORMAT[0])) {
85
+ outputFormat = ENCODE_FORMAT[0];
86
+ } else if (mimeType.includes(IMAGE_FORMAT[1]) || mimeType.includes(IMAGE_FORMAT[2])) {
87
+ outputFormat = ENCODE_FORMAT[1];
88
+ } else if (mimeType.includes(IMAGE_FORMAT[3])) {
89
+ outputFormat = ENCODE_FORMAT[2];
90
+ } else {
91
+ outputFormat = ENCODE_FORMAT[0];
92
+ }
93
+
94
+ const packOpts: packOptsType = {
95
+ format: outputFormat,
96
+ quality: 100
97
+ };
98
+
99
+ const data = await imagePacker.packToData(pixelMap, packOpts);
100
+ const tempFile = fileIo.openSync(tempFilePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY);
101
+ await fileIo.write(tempFile.fd, data);
102
+ fileIo.closeSync(tempFile.fd);
103
+
104
+ pixelMap.release();
105
+ imageSource.release();
106
+ return tempFilePath;
107
+ } catch (error) {
108
+ Logger.error('[resizeImage] Error resizing image: ' + error);
109
+ return filePath;
110
+ }
111
+ }
112
+
113
+ static async doLoadHttpImage(uiContext: UIContext, url: string, redirectCount: number = 0): Promise<string> {
114
+ let context = uiContext.getHostContext()! as common.UIAbilityContext;
115
+ let filesDir = context.filesDir;
116
+ let fileExtension = 'png';
117
+ const urlWithoutParams = url.split('?')[0];
118
+ const lastDotIndex = urlWithoutParams.lastIndexOf('.');
119
+ if (lastDotIndex !== -1) {
120
+ fileExtension = urlWithoutParams.slice(lastDotIndex + 1).toLowerCase();
121
+ }
122
+ const fullFileName: string = filesDir + "/" + new Date().getTime() + "." + fileExtension;
123
+
124
+ if (redirectCount > 5) {
125
+ throw new Error("Too many redirects");
126
+ }
127
+ return new Promise((resolve, reject) => {
128
+ const config: request.agent.Config = {
129
+ action: request.agent.Action.DOWNLOAD,
130
+ url,
131
+ method: 'GET',
132
+ headers: {},
133
+ saveas: fullFileName,
134
+ overwrite: true,
135
+ mode: request.agent.Mode.FOREGROUND,
136
+ };
137
+
138
+ request.agent.create(context, config).then((task: request.agent.Task) => {
139
+ task.on('completed', () => {
140
+ Logger.info(`[maker icon]: finish downloadFile`);
141
+ resolve(fullFileName);
142
+ })
143
+ task.on('failed', (progress: request.agent.Progress) => {
144
+ Logger.info('[maker icon]: downloadFile failed.', JSON.stringify(progress));
145
+ reject(new Error('downloadFile failed: ' + JSON.stringify(progress)));
146
+ });
147
+ task.on('response', async (response: request.agent.HttpResponse) => {
148
+ Logger.info('[maker icon]: downloadFile response.', JSON.stringify(response));
149
+ if (response.statusCode > 300 && response.statusCode < 400) {
150
+ let redirectUrl: string = response.headers.get('location')?.toString() ?? '';
151
+ task.off('progress');
152
+ task.off('completed');
153
+ task.off('failed');
154
+ task.off('response');
155
+ task.stop();
156
+ try {
157
+ const result = await DownloadIcon.doLoadHttpImage(uiContext, redirectUrl, redirectCount + 1);
158
+ Logger.info(`[maker icon]:result: ${result} -----count: ${redirectCount}}`);
159
+ resolve(result)
160
+ } catch (error) {
161
+ reject(error);
162
+ }
163
+ }
164
+ });
165
+ task.start();
166
+ }).catch((error: BusinessError) => {
167
+ Logger.info(`[maker icon]: error downloadHttpFile`);
168
+ reject(new Error("downloadFile failed: " + error.message));
169
+ });
170
+ });
171
+ }
172
+ }
@@ -63,7 +63,7 @@ export interface AMapCircleProps extends ViewBaseProps {
63
63
 
64
64
  export const A_MAP_CIRCLE_VIEW_TYPE: string = "AMapCircle";
65
65
 
66
- export type AMapCircleDescriptor = Descriptor<"AMapCircle", AMapCircleProps>
66
+ export type AMapCircleDescriptor = Descriptor<"AMapCircle", '', '', AMapCircleProps>
67
67
  @Component
68
68
  export struct AMapCircle {
69
69
  static NAME:string = "AMapCircle";
@@ -78,7 +78,7 @@ export struct AMapCircle {
78
78
  /*------ 当RN侧属性props有更改 -------*/
79
79
  let currentCircle = GlobalCache.circleCacheMap.get(this.tag)
80
80
  this.circleDescriptor = (newDescriptor as AMapCircleDescriptor)
81
- let mapCircleProp = this.circleDescriptor.props as AMapCircleProps;
81
+ let mapCircleProp = this.circleDescriptor.rawProps as AMapCircleProps;
82
82
  if (currentCircle) {
83
83
  currentCircle.setRadius(mapCircleProp.radius ? mapCircleProp.radius : 5000);
84
84
  currentCircle.setCenter(new LatLng(mapCircleProp.center.latitude, mapCircleProp.center.longitude));
@@ -18,7 +18,7 @@ export interface AMapMarkerProps extends ViewBaseProps {
18
18
 
19
19
  export const A_MAP_MARKER_TYPE: string = "AMapMarker";
20
20
 
21
- export type AMapMarkerDescriptor = Descriptor<"AMapMarker", AMapMarkerProps>;
21
+ export type AMapMarkerDescriptor = Descriptor<"AMapMarker", '', '', AMapMarkerProps>;
22
22
 
23
23
  @Component
24
24
  export struct AMapMarker {
@@ -38,7 +38,7 @@ export struct AMapMarker {
38
38
  this.markers = GlobalCache.mapMarker.get(currentMapTag) ?? [];
39
39
  this.markerTagAndDescriptorTagArray = GlobalCache.markerTagAndDescriptorTag.get(currentMapTag) ?? [];
40
40
  this.amapDescriptor = (newDescriptor as AMapMarkerDescriptor)
41
- let mapMarkerProps = this.amapDescriptor.props as AMapMarkerProps;
41
+ let mapMarkerProps = this.amapDescriptor.rawProps as AMapMarkerProps;
42
42
  if (this.markers) {
43
43
 
44
44
  for (let j = 0; j < this.markerTagAndDescriptorTagArray.length; ++j) {
@@ -13,7 +13,9 @@ export interface AMapPolygonProps extends ViewBaseProps {
13
13
  }
14
14
 
15
15
  export const A_MAP_POLYGON_TYPE: string = "AMapPolygon";
16
- export type AMapPolygonDescriptor = Descriptor<"AMapPolygon", AMapPolygonProps>
16
+
17
+ export type AMapPolygonDescriptor = Descriptor<"AMapPolygon", '', '', AMapPolygonProps>
18
+
17
19
  @Component
18
20
  export struct AMapPolygon {
19
21
  ctx !: RNOHContext
@@ -28,7 +30,7 @@ export struct AMapPolygon {
28
30
  /*------ 当RN侧属性props有更改 -------*/
29
31
  let currentPolygon = GlobalCache.polygonCacheMap.get(this.tag)
30
32
  this.amapDescriptor = (newDescriptor as AMapPolygonDescriptor)
31
- let mapPolygonProp = this.amapDescriptor.props as AMapPolygonProps;
33
+ let mapPolygonProp = this.amapDescriptor.rawProps as AMapPolygonProps;
32
34
  if (currentPolygon) {
33
35
  let polygonOptionsList = new ArrayList<LatLng>()
34
36
  for (let index = 0; index < mapPolygonProp.points.length; index++) {
@@ -22,7 +22,7 @@ export function convertColorsToNumbers(colorString: string): number {
22
22
 
23
23
  export const A_MAP_POLYLINE_TYPE: string = "AMapPolyline";
24
24
 
25
- export type AMapPolylineDescriptor = Descriptor<"AMapPolyline", AMapPolylineProps>
25
+ export type AMapPolylineDescriptor = Descriptor<"AMapPolyline", '', '', AMapPolylineProps>
26
26
 
27
27
  @Component
28
28
  export struct AMapPolyline {
@@ -42,7 +42,7 @@ export struct AMapPolyline {
42
42
  this.polyLines = GlobalCache.mapPolyLine.get(currentMapTag) ?? [];
43
43
  this.polyLineTagAndDescriptorTagArray = GlobalCache.polyLinesTagAndDescriptorTag.get(currentMapTag) ?? [];
44
44
  this.amapDescriptor = (newDescriptor as AMapPolylineDescriptor)
45
- let mapPolylineProp = this.amapDescriptor.props as AMapPolylineProps;
45
+ let mapPolylineProp = this.amapDescriptor.rawProps as AMapPolylineProps;
46
46
  if (this.polyLines && this.polyLines.length > 0) {
47
47
  for (let j = 0; j < this.polyLineTagAndDescriptorTagArray.length; ++j) {
48
48
  this.polyLineTagAndDescriptorTagArray[j].forEach(async (polyLineID: string, polyLineTag: number,