hbt-training-ui/src/components/map.component.vue

109 lines
3.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<div :id="id" class="myMap"></div>
</template>
<style lang="scss" scoped>
.myMap{
width: 100%;
height: 100%;
}
</style>
<script lang="ts">
import {Component,Emit,Prop,Vue} from 'vue-property-decorator';
import PlayerUtils from "@/utils/player"
@Component
export default class MapComponent extends Vue {
@Prop()
id:string;
public playerUtils = new PlayerUtils();
public player:any;
public timer: any;
public moving = false;
public playerApi:any;
@Emit("onLoaded")
public loadPlayer(){
return {
palyer:this.player,
api:this.playerApi,
utils:this.playerUtils
}
}
@Emit("onHandleChange")
public handleChange(data){
//
}
created(){
this.playerUtils.onEvent = async(data)=>{
this.handleChange(data)
}
this.playerUtils.onReady = (data)=>{
this.playerApi.settings.setMapMode(2, {
'coordType': 0, //坐标系类型0经纬度1本地默认值是0
'serviceType': 4,//服务类型0MVT矢量切片默认值 1WMTS(ArcGIS) 2WMS 3MapServer(ArcGIS) 4Mapbox
'mapPoint': [492848.00, 2491968.00],//同名点,取值范围:[x,y],(默认值是[0, 0]
'longitude': 113.9354020,//经度,取值范围:[0~180]默认值是0.0
'latitude': 22.5222660,//纬度,取值范围:[0~90]默认值是0.0
'style': 'mapbox://styles/mapbox/streets-v10',//风格路径,字符串地址,(默认值是 "mapbox://styles/mapbox/streets-v10"
'coordOrder': 0,//坐标顺序0: XY; 1: YX默认值为0
'cache': ':memory:',//缓存路径,字符串地址,(默认值是 ":memory:"
'renderMode': 0,//渲染模式0正常1透明2标注3贴地默认值是0
'groundHeight': 0,//地面高度,取值范围:[0~任意数值]默认值是0.0
//'serverURL': []
}, () => {
console.log('设置大地图模式完成');
});
// this.playerApi.tileLayer.hide("48D390964B7F0D37D07DD8A2D5596E64")
this.loadPlayer();
}
}
mounted(){
window.addEventListener("resize",this.resize)
// document.addEventListener("mousemove", this.fixedCamera)
this.player = this.playerUtils.initPlayer(this.id,"2423385884355");
this.playerApi = this.player.getAPI();
}
// 旋转镜头
public fixedCamera() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
if(this.moving){
this.playerApi.camera.stop();
this.moving= false
}
}
this.timer = setInterval(() => {
this.moving = true;
this.playerApi.camera.flyAround([
13312716.658437,
4098255.982695,
60.714346
], [0,-45,0], 60, 20)
}, 20 * 1000)
}
beforeDestroy(){
if (this.timer) {
clearInterval(this.timer);
this.timer = null
}
}
destroyed(){
window.removeEventListener("resize",this.resize)
document.removeEventListener("mousemove", this.fixedCamera)
//关闭云渲染并释放资源
this.playerApi.destroy();
}
beforeRouteLeave(){
console.log('des')
}
public resize(){
this.player.resize()
}
}
</script>