HarmonyOS 鸿蒙Next 华为地图全屏化
HarmonyOS 鸿蒙Next 华为地图全屏化
setFullScreen(status: boolean) {
window.getLastWindow(getContext(this)).then((window) => {
window.setWindowLayoutFullScreen(status)
}) }
您好,上次您说用这种方法,在地图页让它全屏,然后退出页面时设为false。虽然可以达到需求。但是在退出页面后,然后显示的下面一层的页面,会出现从全屏到不全屏的一个效果,这个效果不好。 有没有办法在地图页用expandSafeArea来实现地图全屏
更多关于HarmonyOS 鸿蒙Next 华为地图全屏化的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
可参考下
import { MapComponent, mapCommon, map } from '@kit.MapKit';
import { AsyncCallback } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { display } from '@kit.ArkUI';
[@Entry](/user/Entry)
[@Component](/user/Component)
struct HuaweiMapDemo {
private TAG = "HuaweiMapDemo";
private mapOption?: mapCommon.MapOptions;
private callback?: AsyncCallback<map.MapComponentController>;
private mapController?: map.MapComponentController;
[@State](/user/State) displayHeight: number = 0
[@State](/user/State) message: string = 'Hello World';
aboutToAppear(): void {
let displayClass: Array<display.Display> = [];
display.getAllDisplays((err: BusinessError, data: Array<display.Display>) => {
displayClass = data;
const errCode: number = err.code;
if (errCode) {
console.error('Failed to obtain all the display objects. Code: ${err.code}, message: ${err.message}');
return;
}
this.displayHeight = data[0].height
console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
});
// 地图初始化参数,设置地图中心点坐标及层级
this.mapOption = {
position: {
target: {
latitude: 39.9,
longitude: 116.4
},
zoom: 10
}
};
// 地图初始化的回调
this.callback = async (err, mapController) => {
if (!err) {
// 获取地图的控制器类,用来操作地图
this.mapController = mapController;
this.mapController.on("mapLoad", () => {
console.info(this.TAG, `on-mapLoad`);
});
}
};
}
build() {
Column(){
Stack() {
// 调用MapComponent组件初始化地图
MapComponent({ mapOptions: this.mapOption, mapCallback: this.callback })
.width('100%')
.height(this.displayHeight + 'px')
.margin({
top: -10
})
}
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP,SafeAreaEdge.BOTTOM])
}
}
}
更多关于HarmonyOS 鸿蒙Next 华为地图全屏化的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html