jhbigscreen/src/pages/detail/mapModle.vue

133 lines
3.8 KiB
Vue
Raw Normal View History

2023-09-10 23:20:30 +08:00
<template>
<div style="height: 100%;">
<div v-if="showMap" style="height: 100%;" v-loading="loading">
<div id="cesiumContainer" style="height: 100%;"></div>
</div>
2023-09-17 17:01:50 +08:00
<template v-else>
<template v-if="images && images.length>0">
<el-carousel height="500px">
<el-carousel-item v-for="item in images" :key="item">
<div style="width: 100%;display: flex;align-items: center;justify-content: center;height: 500px;">
<el-image :src="item" style="width:100%" :preview-src-list="images"></el-image>
</div>
</el-carousel-item>
</el-carousel>
</template>
<img v-else :src="'images/830.png'">
</template>
2023-09-10 23:20:30 +08:00
</div>
</template>
<script>
export default {
name: 'JhbigscreenMapModle',
2023-09-17 17:01:50 +08:00
props:{
images:{
type:Array,
default:()=>[]
}
},
2023-09-10 23:20:30 +08:00
data() {
return {
loading:false,
showMap: false,
mapInfo: null,
project: null
};
},
mounted() {
window.mymap = this;
this.$bus.$on("projectChange", res => {
this.project = res;
this.reloadMap();
2023-09-14 00:59:01 +08:00
});
2023-09-10 23:20:30 +08:00
},
methods: {
loadCss(id, href) {
if (document.getElementById(id)) {
return;
}
let node = document.createElement("link");
node.rel = "stylesheet";
node.type = "text/css";
node.href = href;
node.id=id;
document.getElementsByTagName("head")[0].appendChild(node);
},
initScript(id, url) {
return new Promise((resolve, reject) => {
if (document.getElementById(id)) {
resolve();
return;
}
let script = document.createElement('script');
script.type = "text/javascript";
id = id;
script.src = url;
document.body.appendChild(script);
script.onload = () => {
resolve();
}
script.onerror = () => {
reject();
}
})
},
reloadMap() {
let items = window.mapModels.filter(d => d.prjId == this.project.id);
if (items.length > 0) {
this.mapInfo = items[0];
this.showMap = true;
this.loading=true;
setTimeout(this.initMap, 200);
} else {
this.mapInfo = null;
this.showMap = false;
}
},
initMap() {
const func = () => {
if (!window.initMap) {
setTimeout(func, 100);
return;
}
this.loading=false;
window.initMap();
window.mapApi.Model.add(
this.mapInfo.root,
this.mapInfo.modelId,
null,
function (data) {
if (Cesium.defined(data)) {
if (Cesium.defined(data.obj) && data.obj instanceof Cesium.Cesium3DTileset) {
console.log(data);
}
}
},
function (data) {
$("#box,#LoadingShadow").hide()
});
}
func();
}
},
};
</script>
<style lang="less">
#cesiumContainer {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
position: relative;
}
</style>