Skip to content

Commit 72bcccd

Browse files
committed
新增api
1 parent ac38ef9 commit 72bcccd

9 files changed

+71
-16
lines changed

harmony/maps.har

859 Bytes
Binary file not shown.

harmony/maps/src/main/cpp/AIRMapManagerTurboModule.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ static jsi::Value __hostFunction_AIRMapManagerTurboModule_getAddressFromCoordina
6565
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "getAddressFromCoordinates", args, count);
6666
}
6767

68+
static jsi::Value __hostFunction_AIRMapManagerTurboModule_pointForCoordinate(jsi::Runtime &rt,
69+
react::TurboModule &turboModule,
70+
const jsi::Value *args,
71+
size_t count) {
72+
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "pointForCoordinate", args, count);
73+
}
74+
75+
static jsi::Value __hostFunction_AIRMapManagerTurboModule_coordinateForPoint(jsi::Runtime &rt,
76+
react::TurboModule &turboModule,
77+
const jsi::Value *args, size_t count) {
78+
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "coordinateForPoint", args, count);
79+
}
80+
6881
AIRMapManagerTurboModule::AIRMapManagerTurboModule(const ArkTSTurboModule::Context ctx, const std::string name)
6982
: ArkTSTurboModule(ctx, name) {
7083
methodMap_["getCamera"] = MethodMetadata{0, __hostFunction_AIRMapManagerTurboModule_getCamera};
@@ -77,4 +90,6 @@ AIRMapManagerTurboModule::AIRMapManagerTurboModule(const ArkTSTurboModule::Conte
7790
methodMap_["getAddressFromCoordinates"] = MethodMetadata{1, __hostFunction_AIRMapManagerTurboModule_getAddressFromCoordinates};
7891

7992
methodMap_["takeSnapshot"] = MethodMetadata{1, __hostFunction_AIRMapManagerTurboModule_takeSnapshot};
93+
methodMap_["pointForCoordinate"] = MethodMetadata{1, __hostFunction_AIRMapManagerTurboModule_pointForCoordinate};
94+
methodMap_["coordinateForPoint"] = MethodMetadata{1, __hostFunction_AIRMapManagerTurboModule_coordinateForPoint};
8095
}

harmony/maps/src/main/ets/AIRMaps/AIRMapManager.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class AIRMapManager extends TurboModule {
5757
* @return Promise Promise with the bounding box ({ northEast: <LatLng>, southWest: <LatLng> })
5858
*/
5959
public getMapBoundaries(){
60-
//todo 暂无对应api实现
60+
return MapsTurboManager.getInstance().getMapBoundaries();
6161
}
6262

6363
/**
@@ -83,7 +83,7 @@ export class AIRMapManager extends TurboModule {
8383
* @return Promise Promise with the point ({ x: Number, y: Number })
8484
*/
8585
public pointForCoordinate(coordinate: LatLng){
86-
//todo 暂无对应api实现
86+
return MapsTurboManager.getInstance().pointForCoordinate(coordinate);
8787
}
8888

8989
/**
@@ -96,7 +96,7 @@ export class AIRMapManager extends TurboModule {
9696
* @return Promise Promise with the coordinate ({ latitude: Number, longitude: Number })
9797
*/
9898
public coordinateForPoint(point: Point){
99-
//todo 暂无对应api实现
99+
return MapsTurboManager.getInstance().coordinateForPoint(point);
100100
}
101101

102102
/**
@@ -107,7 +107,7 @@ export class AIRMapManager extends TurboModule {
107107
* @return Promise Promise with { <identifier>: { point: Point, frame: Frame } }
108108
*/
109109
public getMarkersFrames(onlyVisible: Boolean){
110-
//todo 暂无对应api实现
110+
//todo 华为地图不支持
111111
}
112112

113113
public animateToRegion(region: Region, duration: number) {
@@ -131,7 +131,7 @@ export class AIRMapManager extends TurboModule {
131131
* @param animated
132132
*/
133133
public fitToElements(edgePadding: EdgePadding, animated: boolean) {
134-
//todo 暂无对应api实现
134+
//todo 华为地图不支持 地图加载kml数据后的操作
135135
}
136136

137137
/**
@@ -142,7 +142,7 @@ export class AIRMapManager extends TurboModule {
142142
* @param animated
143143
*/
144144
public fitToSuppliedMarkers(markers: string[], edgePadding: EdgePadding, animated: boolean) {
145-
//todo 暂无对应api实现
145+
//todo 华为地图不支持
146146
}
147147

148148
/**
@@ -167,6 +167,6 @@ export class AIRMapManager extends TurboModule {
167167
}
168168

169169
public setIndoorActiveLevelIndex(activeLevelIndex: number) {
170-
//todo 暂无对应api实现
170+
//todo 华为地图不支持
171171
}
172172
}

harmony/maps/src/main/ets/AIRMaps/AIRMapMarker.ets

+3-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ export struct AIRMapMarker {
7373
this.marker.setInfoWindowVisible(false);
7474
}
7575
} else if (command === 'redrawCallout') {
76-
//todo 华为地图不支持
76+
//todo 华为地图不支持 当infoWindow为自定义view的时候,调用此方法更新infoWindow里的内容
7777
} else if (command === 'animateMarkerToCoordinate') {
7878
//todo 华为地图不支持
7979
} else if (command === 'redraw') {
80-
//todo 华为地图不支持
80+
this.marker?.remove();
81+
MapsManager.getInstance().addMarker(this, false);
8182
}
8283
}));
8384

harmony/maps/src/main/ets/AIRMaps/AIRMapMarkerManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ export class AIRMapMarkerManager extends TurboModule {
5858
* Causes a redraw of the marker. Useful when there are updates to the marker and tracksViewChanges comes with a cost that is too high.
5959
*/
6060
public redraw(){
61-
//todo 华为地图不支持
61+
MapsTurboManager.getInstance().redraw();
6262
}
6363
}

harmony/maps/src/main/ets/LWLog.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222

2323
import { TAG } from './sharedTypes'
24-
const RELEASE = true;
24+
const RELEASE = false;
2525

2626
export function LWLog(...args: any[]) {
2727
if (RELEASE) {

harmony/maps/src/main/ets/Logger.ets

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/**
2-
* MIT License
3-
*
1+
/*
42
* Copyright (C) 2024 Huawei Device Co., Ltd.
53
*
64
* Permission is hereby granted, free of charge, to any person obtaining a copy

harmony/maps/src/main/ets/MapsTurboManager.ts

+42-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import { map, mapCommon, site, staticMap } from '@kit.MapKit';
2424
import { LWError, LWLog } from './LWLog';
2525
import {
2626
Address,
27-
Camera, ColorMap, DEFAULT_ZOOM, EdgePadding, ImageURISource, LatLng, Region,
27+
Camera, ColorMap, DEFAULT_ZOOM, EdgePadding, ImageURISource, LatLng,
28+
Point,
29+
Region,
2830
SnapshotOptions,
2931
TAG } from './sharedTypes';
3032
import { image } from '@kit.ImageKit';
@@ -34,6 +36,7 @@ import fs from '@ohos.file.fs';
3436
import { RNOHContext } from 'rnoh/ts';
3537

3638
export class MapsTurboManager{
39+
3740
private constructor() {
3841
}
3942

@@ -174,6 +177,40 @@ export class MapsTurboManager{
174177
this.mapController?.setLatLngBounds({northeast: northEast, southwest: southWest})
175178
}
176179

180+
getMapBoundaries() {
181+
try {
182+
let bounds = this.mapController?.getProjection().getVisibleRegion();
183+
let north = bounds.bounds.northeast;
184+
let south = bounds.bounds.southwest;
185+
return {
186+
northEast: north,
187+
southWest: south,
188+
};
189+
} catch (e) {
190+
LWError('getMapBoundaries exception=' + JSON.stringify(e));
191+
}
192+
return {};
193+
}
194+
195+
pointForCoordinate(coordinate: LatLng) {
196+
try {
197+
let mapPoint: mapCommon.MapPoint = this.mapController?.getProjection().toScreenLocation({latitude: coordinate.latitude, longitude: coordinate.longitude});
198+
return {x: mapPoint?.positionX, y: mapPoint?.positionY};
199+
} catch (e) {
200+
LWError('pointForCoordinate exception=' + JSON.stringify(e));
201+
}
202+
return {};
203+
}
204+
205+
coordinateForPoint(point: Point) {
206+
try {
207+
return this.mapController?.getProjection().fromScreenLocation({positionX: point.x, positionY: point.y});
208+
} catch (e) {
209+
LWError('coordinateForPoint exception=' + JSON.stringify(e));
210+
}
211+
return {};
212+
}
213+
177214
public getAddressFromCoordinates(coordinate: LatLng): Promise<Address> {
178215
return new Promise((resolve, reject) => {
179216
let params: site.ReverseGeocodeParams = {
@@ -285,4 +322,8 @@ export class MapsTurboManager{
285322
public hideCallout(){
286323

287324
}
325+
326+
public redraw() {
327+
328+
}
288329
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "lib/index.js",
66
"author": "Leland Richardson <leland.m.richardson@gmail.com>",
77
"homepage": "https://github.com/react-native-maps/react-native-maps#readme",
8-
"version": "1.10.3-0.0.2",
8+
"version": "1.10.3-0.0.3",
99
"license": "MIT",
1010
"scripts": {
1111
"lint": "eslint . --max-warnings 0",

0 commit comments

Comments
 (0)