WholeProcessPlatform/frontend/src/components/mapController/index.vue

273 lines
6.0 KiB
Vue
Raw Normal View History

2026-03-31 14:17:30 +08:00
<template>
2026-04-02 08:56:49 +08:00
<div class="map-controller" :style="{ right: drawerOpen ? '480px' : '12px' }">
2026-04-02 13:51:36 +08:00
<div class="map-controller-group" v-for="item in controllers">
<a-tooltip
:title="child.name"
:placement="child.key === 'Calculate' ? 'right' : 'left'"
v-for="child in item.children"
:key="child.key"
>
2026-04-22 17:53:20 +08:00
<component v-if="child.component" :is="child.component" :map="map" />
<div
v-else
class="map-controller-item"
:class="{ 'is-active': child.key === 'TJ' && tjVisible }"
@click="handleControllerClick(child)"
>
2026-04-02 13:51:36 +08:00
<i class="icon iconfont" :class="'icon-' + child.icon"></i>
2026-04-02 09:27:56 +08:00
</div>
</a-tooltip>
2026-03-31 14:17:30 +08:00
</div>
</div>
</template>
<script setup lang="ts">
import { ref, watch, computed } from 'vue';
import { useUiStore } from '@/store/modules/ui';
import Calculate from './Calculate.vue';
import LayerController from './LayerController.vue';
2026-04-22 17:53:20 +08:00
const props = defineProps<{
map: any;
onClick: (key: any, mapType: any) => void;
2026-04-22 17:53:20 +08:00
}>();
const map = props.map;
2026-04-02 08:56:49 +08:00
// 使用 Pinia store
const uiStore = useUiStore();
const drawerOpen = ref(uiStore.drawerOpen);
const tjVisible = ref(false);
2026-04-02 08:56:49 +08:00
// 监听 store 中的 drawerOpen 变化
2026-04-02 09:27:56 +08:00
watch(
() => uiStore.drawerOpen,
newVal => {
2026-04-02 09:27:56 +08:00
drawerOpen.value = newVal;
}
);
2026-04-02 08:56:49 +08:00
watch(
() => uiStore.mapType,
newVal => {
if (newVal !== '2D') {
tjVisible.value = false;
}
}
);
2026-03-31 14:17:30 +08:00
const isFullScreen = ref(false);
2026-04-02 08:56:49 +08:00
// 响应式的控制器配置
2026-04-02 13:51:36 +08:00
const controllers: any = computed(() => [
2026-03-31 14:17:30 +08:00
{
2026-04-02 09:27:56 +08:00
children: [
{
name: '全屏',
key: 'fullScreen',
icon: isFullScreen.value ? 'exitFullScreen' : 'fullScreen'
}
]
2026-03-31 14:17:30 +08:00
},
2026-04-02 09:27:56 +08:00
2026-03-31 14:17:30 +08:00
{
2026-04-02 09:27:56 +08:00
children: [
2026-04-02 13:51:36 +08:00
// {
// name: "定位",
// key: "positioning",
// icon: "iconGlobal",
// },
2026-04-02 09:27:56 +08:00
{
name: '放大',
key: 'zoomIn',
icon: 'zoomIn'
2026-04-02 09:27:56 +08:00
},
{
name: '缩小',
key: 'zoomOut',
icon: 'zoomOut'
}
]
2026-03-31 14:17:30 +08:00
},
{
2026-04-02 13:51:36 +08:00
children: [
{
name: '3D',
key: 'dim',
icon: uiStore.mapType === '2D' ? 'a-3D' : 'a-2D'
}
]
2026-03-31 14:17:30 +08:00
},
{
2026-04-02 13:51:36 +08:00
children: [
{
name: '图层管理',
key: 'layerController',
component: LayerController
}
]
2026-03-31 14:17:30 +08:00
},
uiStore.mapType === '2D'
? {
children: [
{
name: '测量工具',
key: 'Calculate',
component: Calculate
}
]
}
: {},
uiStore.mapType === '2D'
? {
children: [
{
name: '梯级',
key: 'TJ',
icon: 'tiji'
}
]
}
: {},
uiStore.mapType === '3D'
? {
children: [
{
name: '电站倾斜摄影',
key: 'OSBGController',
icon: 'obliquePhotography'
}
]
}
: {},
uiStore.mapType === '3D'
? {
children: [
{
name: '流域三维漫游',
key: 'threedRoam',
icon: 'roaming'
}
]
}
: {},
2026-03-31 14:17:30 +08:00
{
2026-04-02 13:51:36 +08:00
children: [
{
name: '下载',
key: 'screenShot',
icon: 'downLoad'
}
]
}
2026-03-31 14:17:30 +08:00
]);
2026-04-02 13:51:36 +08:00
// 添加全屏切换功能
const toggleFullScreen = () => {
if (!document.fullscreenElement) {
// 进入全屏
document.documentElement.requestFullscreen().catch(err => {
console.error('进入全屏失败:', err);
isFullScreen.value = false;
});
} else {
// 退出全屏
document.exitFullscreen().catch(err => {
console.error('退出全屏失败:', err);
isFullScreen.value = true;
});
}
};
// 监听全屏状态变化
document.addEventListener('fullscreenchange', () => {
isFullScreen.value = !!document.fullscreenElement;
});
2026-04-02 13:51:36 +08:00
// 控制器点击事件处理
const handleControllerClick = (item: any) => {
switch (item.key) {
case 'fullScreen':
isFullScreen.value = !isFullScreen.value;
// console.log(mapClass.hasLayer('eng_point'));
// map.jdPanelControlShowAndHidden("01", false);
map.mdLayerTreeShowOrHidden('eng_point', false);
map.mdLayerTreeShowOrHidden('wq_countryWq_point', true);
// map.controlBaseLayerTreeShowAndHidden(
// 'eng_point',
// 'eng_point',
// !isFullScreen.value
// );
2026-04-22 17:53:20 +08:00
// map.controlBaseLayerTreeShowAndHidden('lcj_bhq','lcj_bhq',!isFullScreen.value);
// toggleFullScreen();
2026-04-22 17:53:20 +08:00
break;
case 'zoomIn':
map.zoomToggle('in');
2026-04-22 17:53:20 +08:00
break;
case 'zoomOut':
map.zoomToggle('out');
2026-04-22 17:53:20 +08:00
break;
case 'dim':
uiStore.mapType = uiStore.mapType === '2D' ? '3D' : '2D';
if (uiStore.mapType === '2D') {
uiStore.drawerOpen = true;
} else {
uiStore.drawerOpen = false;
}
props.onClick('dim', uiStore.mapType);
2026-04-02 13:51:36 +08:00
break;
case 'rightDrawer':
2026-04-02 13:51:36 +08:00
// 使用全局事件切换右侧面板
// GlobalEvents.get('rightDrawerState').set(!drawerOpen);
break;
// 可以在这里添加其他控制器的处理逻辑
case 'screenShot':
map.mapOutPut();
2026-04-22 17:53:20 +08:00
break;
case 'TJ':
tjVisible.value = !tjVisible.value;
props.onClick(4, null);
2026-04-22 17:53:20 +08:00
// map.addTertiarybasinLayer(servers.Tertiarybasin, '#4DFFDD', '#92A0A5')
break;
2026-04-02 13:51:36 +08:00
default:
console.log(`点击了控制器: ${item.name}`);
break;
}
};
2026-03-31 14:17:30 +08:00
</script>
<style lang="scss" scoped>
.map-controller {
position: absolute;
right: 480px;
bottom: 114px;
z-index: 10;
.map-controller-group {
box-shadow: 0 1px 2px #00000026;
background-color: #fff;
border: none;
.map-controller-item {
height: 40px;
width: 40px;
color: #000;
line-height: 40px;
text-align: center;
position: relative;
cursor: pointer;
.iconfont {
font-size: 20px;
}
&:hover {
background-color: #005292;
color: #ffffff;
}
&.is-active {
background-color: #005292;
color: #ffffff;
}
2026-03-31 14:17:30 +08:00
}
2026-04-02 13:51:36 +08:00
}
.map-controller-group:not(:first-child) {
margin-top: 10px;
2026-03-31 14:17:30 +08:00
}
}
2026-04-02 09:27:56 +08:00
</style>