Files
xian_vue_new/src/component/map/AdministrativeDivision.vue
T

53 lines
1.6 KiB
Vue
Raw Normal View History

2026-04-09 10:26:30 +08:00
<!-- 加载行政区划 -->
<template>
<div></div>
2026-04-09 10:26:30 +08:00
</template>
<script lang="ts" setup>
import { useAdministrativeDivision } from '@/hooks/map/useAdministrativeDivision';
2026-04-14 08:59:05 +08:00
import { useStatusStore } from '@/stores/useStatusStore';
import { CesiumUtilsSingleton } from '@/utils/cesium/CesiumUtils';
import { Color } from 'cesium';
import { onMounted } from 'vue';
2026-04-09 10:26:30 +08:00
// 配置参数
const { areas, areasId, areasColor, areaTransparency, labelTransparency } =
useAdministrativeDivision();
2026-04-09 10:26:30 +08:00
2026-04-14 08:59:05 +08:00
onMounted(async () => {
2026-04-09 15:52:56 +08:00
// 构建批量添加配置数组
const layerConfigs = areasId.map((id, index) => ({
layerId: id,
geojsonData: areas[index],
options: {
showName: true,
isDefault: true,
labelStyle: {
labelText: areas[index].features[0].properties.name,
center: [
areas[index].features[0].properties.center[0],
areas[index].features[0].properties.center[1],
0,
] as [number, number, number],
labelColor: Color.BLACK,
backgroundColor: areasColor[index].withAlpha(labelTransparency),
},
polygonStyle: {
fill: true,
fillColor: areasColor[index].withAlpha(areaTransparency),
outline: false,
},
},
2026-04-09 15:52:56 +08:00
}));
2026-04-14 08:59:05 +08:00
await CesiumUtilsSingleton.batchAddGeoJsonLayers(layerConfigs);
// 根据状态显示隐藏行政区划
if (!useStatusStore().getShowAdministrativeDivision()) {
CesiumUtilsSingleton.batchHideGeoJsonLayers(areasId);
}
});
2026-04-09 10:26:30 +08:00
</script>
<style scoped></style>