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

105 lines
2.4 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>
2026-04-13 20:55:32 +08:00
import {
baQiao,
beiLin,
changAn,
gaoLing,
huYi,
lanTian,
lianHu,
linTong,
weiYang,
xinCheng,
yanLiang,
yanTa,
zhouZhi,
} from '@/assets';
import { CesiumUtilsSingleton } from '@/utils/cesium/CesiumUtils';
import { Color } from 'cesium';
import { onMounted } from 'vue';
2026-04-09 10:26:30 +08:00
const areas = [
2026-04-13 20:55:32 +08:00
baQiao,
beiLin,
changAn,
gaoLing,
huYi,
lanTian,
lianHu,
linTong,
weiYang,
xinCheng,
yanLiang,
yanTa,
zhouZhi,
];
const areasId = [
'baqiao',
'beilin',
'changan',
'gaoling',
'huyi',
'lantian',
'lianhu',
'lintong',
'weiyang',
'xincheng',
'yanliang',
'yanta',
'zhouzhi',
];
const areasColor = [
new Color(255 / 255, 153 / 255, 0 / 255),
new Color(255 / 255, 51 / 255, 102 / 255),
new Color(0 / 255, 178 / 255, 255 / 255),
new Color(102 / 255, 255 / 255, 102 / 255),
new Color(204 / 255, 102 / 255, 255 / 255),
new Color(255 / 255, 204 / 255, 0 / 255),
new Color(0 / 255, 204 / 255, 153 / 255),
new Color(255 / 255, 102 / 255, 102 / 255),
new Color(102 / 255, 153 / 255, 255 / 255),
new Color(255 / 255, 178 / 255, 102 / 255),
new Color(153 / 255, 255 / 255, 204 / 255),
new Color(255 / 255, 153 / 255, 204 / 255),
new Color(190 / 255, 255 / 255, 232 / 255),
];
const areaTransparency = 0.3;
const labelTransparency = 1;
2026-04-09 10:26:30 +08:00
onMounted(() => {
2026-04-09 15:52:56 +08:00
// 构建批量添加配置数组
const layerConfigs = areasId.map((id, index) => ({
layerId: id,
geojsonData: areas[index],
isDefault: true,
options: {
showName: 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
}));
CesiumUtilsSingleton.batchAddGeoJsonLayers(layerConfigs);
});
2026-04-09 10:26:30 +08:00
</script>
<style scoped></style>