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

103 lines
2.8 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 BaQiiao from '@/assets/json/BaQiao.json';
import BeiLin from '@/assets/json/BeiLin.json';
import ChangAn from '@/assets/json/ChangAn.json';
import GaoLing from '@/assets/json/GaoLing.json';
import HuYi from '@/assets/json/HuYi.json';
import LanTian from '@/assets/json/LanTian.json';
import LianHu from '@/assets/json/LianHu.json';
import LinTong from '@/assets/json/LinTong.json';
import WeiYang from '@/assets/json/WeiYang.json';
import XinCheng from '@/assets/json/XinCheng.json';
import YanLiang from '@/assets/json/YanLiang.json';
import YanTa from '@/assets/json/YanTa.json';
import ZhouZhi from '@/assets/json/ZhouZhi.json';
import { CesiumUtilsSingleton } from '@/utils/cesium/CesiumUtils';
import { Color } from 'cesium';
import { onMounted } from 'vue';
2026-04-09 10:26:30 +08:00
const areas = [
BaQiiao,
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>