2025-05-22 13:56:20 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div id="map-container" class="map-container">
|
|
|
|
|
<slot></slot>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import * as Cesium from 'cesium';
|
2025-05-23 10:04:18 +08:00
|
|
|
|
import { useConfigSetting } from './mixins/useConfigSetting.js';
|
2025-05-22 13:56:20 +08:00
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
options: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default: () => {
|
|
|
|
|
return {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
2025-05-30 17:27:47 +08:00
|
|
|
|
const emits = defineEmits(['init'])
|
2025-05-22 13:56:20 +08:00
|
|
|
|
let viewer = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
initMap();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 初始化地图
|
|
|
|
|
const initMap = async () => {
|
|
|
|
|
const oldOptions = {
|
|
|
|
|
// 动画仪表盘
|
|
|
|
|
animation: false,
|
|
|
|
|
// 基础图层选择按钮
|
|
|
|
|
baseLayerPicker: false,
|
|
|
|
|
// 全屏按钮
|
|
|
|
|
fullscreenButton: false,
|
|
|
|
|
vrButton: false,
|
|
|
|
|
// 地名地址查询框
|
|
|
|
|
geocoder: false,
|
|
|
|
|
// 返回地球视角按钮
|
|
|
|
|
homeButton: false,
|
|
|
|
|
// 属性框(显示拾取要素的属性)
|
|
|
|
|
infoBox: false,
|
|
|
|
|
// 场景模式切换按钮(三维地球、2.5维场景、二维地图)
|
|
|
|
|
sceneModePicker: false,
|
|
|
|
|
// 拾取要素识别(显示个框,但不明确选中内容)???
|
|
|
|
|
selectionIndicator: false,
|
|
|
|
|
// 时间轴
|
|
|
|
|
timeline: false,
|
|
|
|
|
// 操作提示按钮
|
|
|
|
|
navigationHelpButton: false,
|
|
|
|
|
// 超采样开4倍,如果显示困难再降低
|
|
|
|
|
msaaSamples: 2,
|
|
|
|
|
scene3DOnly: true,
|
|
|
|
|
shouldAnimate: true,
|
|
|
|
|
contextOptions: {
|
|
|
|
|
webgl: {
|
|
|
|
|
// 允许截图
|
|
|
|
|
preserveDrawingBuffer: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
// 添加cesium的token(目前使用zq发布的)
|
|
|
|
|
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiZjljMTU0MC03OGY5LTRjMzQtYWJkYS02MzI2OTI2OGUyNTgiLCJpZCI6MzE3NTgsImlhdCI6MTc0MTA1MjY3OH0.uvbT5jSUFS-wU41MvzAuY33yfYnUiOWQCWad2KSX28o'
|
|
|
|
|
console.log(props.options.configJson)
|
|
|
|
|
let configJson = props.options.configJson;
|
|
|
|
|
try {
|
|
|
|
|
configJson = JSON.parse(configJson)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
configJson = {}
|
|
|
|
|
}
|
|
|
|
|
if (props.options.isTerrainProvider) {
|
2025-05-23 10:04:18 +08:00
|
|
|
|
let terrainProvider = await Cesium.createWorldTerrainAsync()
|
2025-05-22 16:42:40 +08:00
|
|
|
|
// 是否使用自定义地形
|
|
|
|
|
if(props.options.cesiumTerrainProviderUrl) {
|
|
|
|
|
const customTerrainProvider = await Cesium.CesiumTerrainProvider.fromUrl(props.options.cesiumTerrainProviderUrl);
|
|
|
|
|
if(customTerrainProvider) {
|
|
|
|
|
terrainProvider = customTerrainProvider;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-22 13:56:20 +08:00
|
|
|
|
oldOptions.terrainProvider = terrainProvider;
|
|
|
|
|
}
|
|
|
|
|
let options = Object.assign(oldOptions, configJson)
|
|
|
|
|
viewer = new Cesium.Viewer('map-container', options)
|
|
|
|
|
|
|
|
|
|
// 启用深度测试
|
|
|
|
|
// viewer.scene.globe.depthTestAgainstTerrain = true;
|
|
|
|
|
// 隐藏logo
|
|
|
|
|
viewer.cesiumWidget.creditContainer.style.display = 'none'
|
|
|
|
|
|
2025-05-23 10:04:18 +08:00
|
|
|
|
const { setInitConfig } = useConfigSetting(viewer);
|
|
|
|
|
|
|
|
|
|
setInitConfig(props.options);
|
2025-05-22 13:56:20 +08:00
|
|
|
|
|
|
|
|
|
// 取消左键双击
|
|
|
|
|
viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
|
2025-05-30 17:27:47 +08:00
|
|
|
|
|
|
|
|
|
emits('init', viewer);
|
2025-05-22 13:56:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-22 16:42:40 +08:00
|
|
|
|
|
2025-05-22 13:56:20 +08:00
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
if (viewer) {
|
|
|
|
|
viewer.entities.removeAll()
|
|
|
|
|
viewer.imageryLayers.removeAll()
|
|
|
|
|
for (let index = 0; index < viewer.dataSources.length; index++) {
|
|
|
|
|
const datasource = viewer.dataSources.get(index);
|
|
|
|
|
datasource.entities.removeAll()
|
|
|
|
|
}
|
|
|
|
|
viewer.dataSources.removeAll(true)
|
|
|
|
|
// viewer.scene.primitives.removeAll();
|
|
|
|
|
viewer.destroy()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.map-container {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
</style>
|