Skip to content

Commit 9a477b5

Browse files
authored
feat: MapView属性事件补充,虚线绘制方法修改 (#14)
1 parent 3bb2f8d commit 9a477b5

10 files changed

+80
-31
lines changed

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

+29
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ static jsi::Value __hostFunction_AIRMapManagerTurboModule_coordinateForPoint(jsi
7878
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "coordinateForPoint", args, count);
7979
}
8080

81+
static jsi::Value __hostFunction_AIRMapManagerTurboModule_setIndoorActiveLevelIndex(jsi::Runtime &rt,
82+
react::TurboModule &turboModule,
83+
const jsi::Value *args, size_t count) {
84+
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "setIndoorActiveLevelIndex", args, count);
85+
}
86+
87+
static jsi::Value __hostFunction_AIRMapManagerTurboModule_fitToElements(jsi::Runtime &rt,
88+
react::TurboModule &turboModule,
89+
const jsi::Value *args, size_t count) {
90+
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "fitToElements", args, count);
91+
}
92+
93+
static jsi::Value __hostFunction_AIRMapManagerTurboModule_fitToSuppliedMarkers(jsi::Runtime &rt,
94+
react::TurboModule &turboModule,
95+
const jsi::Value *args, size_t count) {
96+
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "fitToSuppliedMarkers", args, count);
97+
}
98+
99+
static jsi::Value __hostFunction_AIRMapManagerTurboModule_getMarkersFrames(jsi::Runtime &rt,
100+
react::TurboModule &turboModule,
101+
const jsi::Value *args, size_t count) {
102+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "getMarkersFrames", args, count);
103+
}
104+
81105
AIRMapManagerTurboModule::AIRMapManagerTurboModule(const ArkTSTurboModule::Context ctx, const std::string name)
82106
: ArkTSTurboModule(ctx, name) {
83107
methodMap_["getCamera"] = MethodMetadata{0, __hostFunction_AIRMapManagerTurboModule_getCamera};
@@ -92,4 +116,9 @@ AIRMapManagerTurboModule::AIRMapManagerTurboModule(const ArkTSTurboModule::Conte
92116
methodMap_["takeSnapshot"] = MethodMetadata{1, __hostFunction_AIRMapManagerTurboModule_takeSnapshot};
93117
methodMap_["pointForCoordinate"] = MethodMetadata{1, __hostFunction_AIRMapManagerTurboModule_pointForCoordinate};
94118
methodMap_["coordinateForPoint"] = MethodMetadata{1, __hostFunction_AIRMapManagerTurboModule_coordinateForPoint};
119+
120+
methodMap_["setIndoorActiveLevelIndex"] = MethodMetadata{1, __hostFunction_AIRMapManagerTurboModule_setIndoorActiveLevelIndex};
121+
methodMap_["fitToElements"] = MethodMetadata{1, __hostFunction_AIRMapManagerTurboModule_fitToElements};
122+
methodMap_["fitToSuppliedMarkers"] = MethodMetadata{2, __hostFunction_AIRMapManagerTurboModule_fitToSuppliedMarkers};
123+
methodMap_["getMarkersFrames"] = MethodMetadata{1, __hostFunction_AIRMapManagerTurboModule_getMarkersFrames};
95124
}

harmony/maps/src/main/cpp/MapsJSIBinder.h

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace rnoh {
1111
object.setProperty(rt, "initialRegion", "Region");
1212
object.setProperty(rt, "camera", "Camera");
1313
object.setProperty(rt, "initialCamera", "Camera");
14+
object.setProperty(rt, "mapPadding", "EdgePadding");
1415
object.setProperty(rt, "paddingAdjustmentBehavior", "PaddingAdjustmentBehavior");
1516
object.setProperty(rt, "liteMode", "bool");
1617
object.setProperty(rt, "mapType", "string");

harmony/maps/src/main/cpp/MapsNapiBinder.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ return ArkJS(env)
1717
.addProperty("initialRegion", props->initialRegion)
1818
.addProperty("camera", props->camera)
1919
.addProperty("initialCamera", props->initialCamera)
20+
.addProperty("mapPadding", props->mapPadding)
2021
.addProperty("paddingAdjustmentBehavior", props->paddingAdjustmentBehavior)
2122
.addProperty("liteMode", props->liteMode)
2223
.addProperty("mapType", props->mapType)

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ export struct AIRMap {
222222
maxZoom: this.descriptor.rawProps.maxZoomLevel,
223223
minZoom: this.descriptor.rawProps.minZoomLevel,
224224
rotateGesturesEnabled: this.descriptor.rawProps.rotateEnabled,
225-
scaleControlsEnabled: this.descriptor.rawProps.scrollEnabled,
225+
scaleControlsEnabled: this.descriptor.rawProps.showsScale,
226226
scrollGesturesEnabled: this.descriptor.rawProps.scrollEnabled,
227227
tiltGesturesEnabled: true,
228-
zoomGesturesEnabled: this.descriptor.rawProps.zoomTapEnabled,
228+
zoomGesturesEnabled: this.descriptor.rawProps.zoomEnabled,
229229
zoomControlsEnabled: this.descriptor.rawProps.zoomControlEnabled,
230230
myLocationControlsEnabled: this.descriptor.rawProps.showsMyLocationButton,
231231
compassControlsEnabled: this.descriptor.rawProps.showsCompass,
@@ -284,15 +284,14 @@ export struct AIRMap {
284284
lat = this.descriptor.rawProps.camera.center.latitude;
285285
lng = this.descriptor.rawProps.camera.center.longitude;
286286
zoom = this.descriptor.rawProps.camera.zoom;
287-
return { center: {latitude: this.descriptor.rawProps.camera.center.latitude} } as Camera;
288287
} else if (this.descriptor.rawProps.initialCamera) {
289288
lat = this.descriptor.rawProps.initialCamera.center.latitude;
290289
lng = this.descriptor.rawProps.initialCamera.center.longitude;
291290
zoom = this.descriptor.rawProps.initialCamera.zoom;
292291
} else if (this.descriptor.rawProps.region) {
293292
lat = this.descriptor.rawProps.region.latitude;
294293
lng = this.descriptor.rawProps.region.longitude;
295-
}else if (this.descriptor.rawProps.initialRegion) {
294+
} else if (this.descriptor.rawProps.initialRegion) {
296295
lat = this.descriptor.rawProps.initialRegion.latitude;
297296
lng = this.descriptor.rawProps.initialRegion.longitude;
298297
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface AIRMapRawProps extends ViewRawProps {
2929
camera?: Camera;
3030
customMapStyle?: MapStyleElement[];
3131
followsUserLocation?: boolean;
32+
isAccessibilityElement?: boolean;
3233
initialCamera?: Camera;
3334
region?: Region;
3435
initialRegion?: Region;

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ export class AIRMapManager extends TurboModule {
6161
return camera;
6262
}
6363

64-
//github api 上未标出
65-
// public takeSnapshot(width: number, height: number, region: Region, format?: 'png' | 'jpg', quality?: number, result?: 'file' | 'base64', callback?: Function){
64+
/**
65+
* Takes a snapshot of the map and saves it to a picture file or returns the image as a base64 encoded string
66+
*
67+
* @param config Configuration options
68+
* @returns Promise Promise with either the file-uri or base64 encoded string
69+
*/
6670
public takeSnapshot(config: SnapshotOptions): Promise<string>{
6771
return MapsTurboManager.getInstance().takeSnapshot(this.ctx, config);
6872
}
@@ -124,7 +128,7 @@ export class AIRMapManager extends TurboModule {
124128
*/
125129
public getMarkersFrames(onlyVisible: Boolean){
126130
//todo 华为地图不支持
127-
MapsTurboManager.getInstance().getMarkersFrames(onlyVisible);
131+
return MapsTurboManager.getInstance().getMarkersFrames(onlyVisible);
128132
}
129133

130134
public animateToRegion(region: Region, duration: number) {

harmony/maps/src/main/ets/MapsManager.ets

+20-16
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,19 @@ export class MapsManager{
9797
longitude: desc.rawProps.coordinate.longitude
9898
},
9999
rotation: desc.rawProps.rotation,
100-
visible: true,
101-
zIndex: desc.rawProps.zIndex,
102-
alpha: desc.rawProps.opacity?desc.rawProps.opacity:1.0,
100+
icon: this.imageSourceConvert(desc.rawProps.image),
101+
alpha: desc.rawProps.opacity ?? 1.0,
103102
anchorU: this.getPointX(desc.rawProps.anchor, 0.5),
104103
anchorV: this.getPointY(desc.rawProps.anchor, 1),
105-
clickable: desc.rawProps.tappable===undefined?true:desc.rawProps.tappable,
104+
clickable: desc.rawProps.tappable === undefined ? true : desc.rawProps.tappable,
106105
draggable: desc.rawProps.draggable,
107-
icon: this.imageSourceConvert(desc.rawProps.image),
108-
106+
flat: desc.rawProps.flat,
109107
title: desc.rawProps.title,
110108
snippet: desc.rawProps.description,
111-
flat: desc.rawProps.flat,
112109
infoWindowAnchorU: this.getPointX(desc.rawProps.calloutAnchor, 0.5),
113110
infoWindowAnchorV: this.getPointX(desc.rawProps.calloutAnchor, 0),
111+
zIndex: desc.rawProps.zIndex,
112+
visible: true,
114113
};
115114
this.mapController.addMarker(markerOptions).then(marker => {
116115
LWLog('MapsManager.addMarker----------marker=' + marker.getId())
@@ -143,17 +142,17 @@ export class MapsManager{
143142
let polylineOption: mapCommon.MapPolylineOptions = {
144143
points: desc.rawProps.coordinates,
145144
clickable: desc.rawProps.tappable,
145+
color: this.colorCovertHex(desc.rawProps.strokeColor, 0XFF000000),
146+
colors: desc.rawProps.strokeColors?.map((color, i): number => { return this.colorCovertHex(color) }),
146147
startCap: this.lineCapTypeConvert(desc.rawProps.lineCap),
147148
endCap: this.lineCapTypeConvert(desc.rawProps.lineCap),
148149
geodesic: desc.rawProps.geodesic,
149150
jointType: this.lineJoinTypeConvert(desc.rawProps.lineJoin),
150-
visible: true,
151+
patterns: this.lineDashPatternConvert(desc.rawProps.lineDashPattern),
151152
width: desc.rawProps.strokeWidth,
152-
zIndex: 0,
153153
gradient: false,
154-
color: this.colorCovertHex(desc.rawProps.strokeColor, 0XFF000000),
155-
colors: desc.rawProps.strokeColors?.map((color, i): number => { return this.colorCovertHex(color) }),
156-
patterns: this.lineDashPatternConvert(desc.rawProps.lineDashPattern)
154+
visible: true,
155+
zIndex: 0,
157156
}
158157
// 创建polyline
159158
this.mapController.addPolyline(polylineOption).then(mapPolyline=>{
@@ -170,6 +169,7 @@ export class MapsManager{
170169
}
171170
let polygonOptions: mapCommon.MapPolygonOptions = {
172171
points: desc.rawProps.coordinates,
172+
holes: desc.rawProps.holes,
173173
clickable: desc.rawProps.tappable,
174174
fillColor: this.colorCovertHex(desc.rawProps.fillColor, 0XFF000000),
175175
geodesic: desc.rawProps.geodesic,
@@ -179,7 +179,6 @@ export class MapsManager{
179179
strokeWidth: desc.rawProps.strokeWidth,
180180
visible: true,
181181
zIndex: desc.rawProps.zIndex,
182-
holes: desc.rawProps.holes,
183182
}
184183
// 创建多边形
185184
this.mapController.addPolygon(polygonOptions).then(mapPolygon=>{
@@ -203,10 +202,10 @@ export class MapsManager{
203202
clickable: true,
204203
fillColor: this.colorCovertHex(desc.rawProps.fillColor, 0XFF000000),
205204
strokeColor: this.colorCovertHex(desc.rawProps.strokeColor, 0XFF000000),
205+
patterns: this.lineDashPatternConvert(desc.rawProps.lineDashPattern),
206206
strokeWidth: desc.rawProps.strokeWidth,
207207
visible: true,
208208
zIndex: desc.rawProps.zIndex,
209-
patterns: this.lineDashPatternConvert(desc.rawProps.lineDashPattern)
210209
}
211210
// 创建Circle
212211
this.mapController.addCircle(mapCircleOptions).then(mapCircle=>{
@@ -309,8 +308,13 @@ export class MapsManager{
309308
lineDashPatternConvert(target: number[]){
310309
if (target && target.length > 0) {
311310
let result = new Array<mapCommon.PatternItem>();
312-
target.forEach(element => {
313-
result.push({type: mapCommon.PatternItemType.DASH, length: element})
311+
const source = target.length % 2 === 0 ? target : [...target, ...target];
312+
source.forEach((element, index) => {
313+
if (index % 2 === 0) {
314+
result.push({type: mapCommon.PatternItemType.DASH, length: element});
315+
} else {
316+
result.push({type: mapCommon.PatternItemType.GAP, length: element});
317+
}
314318
});
315319
return result;
316320
}

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,13 @@ export class MapsTurboManager{
256256
let width = config.width;
257257
let height = config.height;
258258
let quality = config.quality * 100;
259-
let format = config.format === 'png'?'image/png':'image/jpg'
259+
let format = config.format === 'png' ? 'image/png' : 'image/jpg';
260+
const region = this.mapController.getCameraPosition().target; // 没有值时,取地图当前的中心位置
260261
LWLog('MapsTurboManager.takeSnapshot------>width=' + width + ' height=' + height + ' quality=' + quality + ' format=' + format);
261262
let option: staticMap.StaticMapOptions = {
262263
location: {
263-
latitude: config.region?.latitude,
264-
longitude: config.region?.longitude
264+
latitude: config.region?.latitude ?? region.latitude,
265+
longitude: config.region?.longitude ?? region.longitude
265266
},
266267
zoom: DEFAULT_ZOOM,
267268
imageWidth: width,
@@ -276,7 +277,7 @@ export class MapsTurboManager{
276277
let cacheFileUrl = "file://" + cacheFilePath;
277278
await this.savePixel2File(imagePixel, cacheFilePath);
278279
resolve(cacheFileUrl);
279-
}else {
280+
} else {
280281
const imagePackerApi: image.ImagePacker = image.createImagePacker();
281282
let packOpts: image.PackingOption = { format: format, quality: quality };
282283
imagePackerApi.packing(imagePixel, packOpts).then((readBuffer)=>{
@@ -298,7 +299,8 @@ export class MapsTurboManager{
298299
}
299300

300301
public getMarkersFrames(onlyVisible: Boolean) {
301-
302+
//todo 华为地图不支持
303+
return Promise.resolve({ 'key': {} });
302304
}
303305

304306
public async savePixel2File(pm: image.PixelMap, filePath: string){

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"lib",
2424
"android",
2525
"ios",
26-
"harmony",
26+
"harmony",
2727
"react-native-google-maps.podspec",
2828
"react-native-maps.podspec",
2929
"!android/build",
@@ -76,7 +76,7 @@
7676
},
7777
"dependencies": {
7878
"@types/geojson": "^7946.0.13",
79-
"react-native-maps": "1.10.3"
79+
"react-native-maps": "1.10.3"
8080
},
8181
"jest": {
8282
"preset": "react-native",
@@ -89,6 +89,6 @@
8989
"node": ">=18"
9090
},
9191
"harmony": {
92-
"alias": "react-native-maps"
92+
"alias": "react-native-maps"
9393
}
9494
}

src/MapView.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ export type MapViewProps = ViewProps & {
156156
*/
157157
kmlSrc?: string;
158158

159+
/**
160+
* Determines whether the MapView captures VoiceOver touches or forwards them to children. When `true`, map markers are not visible to VoiceOver.
161+
*
162+
* @platform iOS: Supported
163+
* @platform Android: Not Supported
164+
*/
165+
isAccessibilityElement?: boolean;
166+
159167
/**
160168
* If set, changes the position of the "Legal" label link in Apple maps.
161169
*

0 commit comments

Comments
 (0)