2025-03-31 15:26:29 +00:00
|
|
|
<template>
|
|
|
|
|
<div class="HomeMpa">
|
2025-04-01 16:12:21 +00:00
|
|
|
<div class="zoom-level">当前缩放等级: {{ zoomLevel }}</div>
|
2025-03-31 15:26:29 +00:00
|
|
|
<div id="mars3dContainer" ref="MarsMap" class="mars3d-container"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
"use script";
|
|
|
|
|
import { mapGetters } from "vuex";
|
|
|
|
|
export default {
|
|
|
|
|
name: "HomeMap",
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2025-04-01 16:12:21 +00:00
|
|
|
player: null,
|
|
|
|
|
zoomLevel: null
|
2025-03-31 15:26:29 +00:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
// console.clear();
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.getMapJson();
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
...mapGetters(["statePage", "cityCode"])
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
getMapJson() {
|
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
|
mars3d.Util.fetchJson({
|
|
|
|
|
// ***_***
|
|
|
|
|
url: "/configJson/map.json"
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
this.initMarsMap({
|
|
|
|
|
// 合并配置项
|
|
|
|
|
...res.map3d
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
initMarsMap(options) {
|
|
|
|
|
let map;
|
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
|
map = new mars3d.Map(this.$refs.MarsMap, options);
|
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
|
window.marsMap = map;
|
|
|
|
|
// 禁止右键菜单
|
|
|
|
|
// map.unbindContextMenu();
|
|
|
|
|
//禁用切换动画效果
|
|
|
|
|
if (map.viewer.sceneModePicker) {
|
|
|
|
|
map.viewer.sceneModePicker.viewModel.duration = 0.0;
|
|
|
|
|
}
|
|
|
|
|
// map构造完成后的一些处理
|
|
|
|
|
this.onMapLoad(map);
|
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
|
map.on(mars3d.EventType.click, this.map_clickHandler, map);
|
2025-04-01 16:12:21 +00:00
|
|
|
map.on(mars3d.EventType.cameraMoveEnd, this.map_zoomHandler, map);
|
2025-04-12 15:15:32 +00:00
|
|
|
// map.scene.screenSpaceCameraController.enableTranslate = false;
|
|
|
|
|
// map.scene.screenSpaceCameraController.enableRotate = false; // 禁用旋转
|
|
|
|
|
// map.scene.screenSpaceCameraController.enableTilt = false; // 禁用倾斜
|
|
|
|
|
// map.scene.screenSpaceCameraController.enableZoom = false; // 禁用缩放
|
2025-03-31 15:26:29 +00:00
|
|
|
},
|
|
|
|
|
map_clickHandler(event) {
|
|
|
|
|
console.log(event);
|
|
|
|
|
},
|
2025-04-01 16:12:21 +00:00
|
|
|
map_zoomHandler(event) {
|
|
|
|
|
let { alt } = window.marsMap.getCameraView();
|
|
|
|
|
this.zoomLevel = this.estimateZoomLevel(alt);
|
|
|
|
|
console.log(this.zoomLevel);
|
|
|
|
|
},
|
|
|
|
|
estimateZoomLevel(height) {
|
|
|
|
|
const maxZoom = 18;
|
|
|
|
|
const baseHeight = 1000;
|
|
|
|
|
const zoom = maxZoom - Math.log2(height / baseHeight);
|
|
|
|
|
return Math.round(zoom);
|
|
|
|
|
},
|
2025-03-31 15:26:29 +00:00
|
|
|
onMapLoad(map) {
|
|
|
|
|
map.changeMouseModel(true);
|
2025-04-12 15:15:32 +00:00
|
|
|
// 在地图初始化后禁用平移
|
|
|
|
|
let camera = window.mapConfig;
|
|
|
|
|
console.log(camera, "camera");
|
|
|
|
|
if (camera.isCamera) {
|
|
|
|
|
let cameraHistory = new mars3d.thing.CameraHistory({
|
|
|
|
|
limit: {
|
|
|
|
|
// 限定视角范围
|
|
|
|
|
position: Cesium.Cartesian3.fromDegrees(
|
|
|
|
|
camera.cameraLon,
|
|
|
|
|
camera.cameraLat,
|
|
|
|
|
0
|
|
|
|
|
),
|
|
|
|
|
radius: camera.cameraRadius,
|
|
|
|
|
debugExtent: false
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
map.addThing(cameraHistory);
|
|
|
|
|
map.scene.screenSpaceCameraController.minimumZoomDistance = 1000; //相机的高度的最小值
|
|
|
|
|
map.scene.screenSpaceCameraController.maximumZoomDistance = 500000; //相机高度的最大值
|
|
|
|
|
}
|
2025-03-31 15:26:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.HomeMpa {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
2025-04-01 16:12:21 +00:00
|
|
|
.zoom-level {
|
|
|
|
|
position: absolute;
|
|
|
|
|
bottom: 0.8%;
|
|
|
|
|
left: 1%;
|
|
|
|
|
z-index: 5;
|
|
|
|
|
color: #fff;
|
|
|
|
|
}
|
2025-03-31 15:26:29 +00:00
|
|
|
|
|
|
|
|
#mars3dContainer {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|