- <template>
- <!-- 长效考核-雨水资源利用 -->
- <div class="rainWaterCX">
- <!-- gis地图 -->
- <MapBox :initJson="`/static/libs/mapbox/style/preventionSFQ.json`" l7=""></MapBox>
-
- <!-- <img src="@/assets/images/longTerm/yszy.png" class="imgTL" /> -->
- <!-- 右侧内容 -->
- <div :class="['videoImgRCX', ifExpand ? 'rightZkCX' : 'rightSqCX']" @click="ifExpand = !ifExpand"></div>
- <div :class="['preContentRight', 'animate__animated', ifExpand ? 'animate__bounceInRight' : 'animate__bounceOutRight']">
- <div class="selectTitle">
- <div class="name">年度雨水资源利用量情况</div>
- <!-- <el-select v-model="currentYear" @change="changeMonitorYear" style="width: 100px" size="small">
- <el-option label="2023年" value="2023"></el-option>
- <el-option label="2024年" value="2024"></el-option>
- <el-option label="2025年" value="2025"></el-option>
- </el-select> -->
- </div>
- <div id="chartRainST" class="chartHeight"></div>
-
- <div class="selectTitle">
- <div class="name">年度项目雨水资源利用量情况</div>
- </div>
- <el-table ref="tableArea" :data="tableData" height="500" v-loading="tableLoading" @row-click="checkProject" highlight-current-row>
- <el-table-column label="项目名称" prop="projectName" />
- <el-table-column label="完工年度" prop="year" width="80" />
- <el-table-column label="雨水资源利用量(t)" prop="rainwaterUtilization" width="130" />
- </el-table>
- </div>
- </div>
- </template>
- <script setup>
- import MapBox from '@/views/gisMapPage/gisMapBox1'; //gis地图
- import { rainwaterUtilizationChart } from '@/api/longTerm/index.js';
- import optionChart from './chartOption.js';
- import bus from '@/bus';
- const { proxy } = getCurrentInstance();
- const ifExpand = ref(true);
- const chartKst = shallowRef(null);
- const tableData = ref([
- { name: '开封市疾病预防控制中心实验楼项目', year: '2024', val: 45, id: 1 },
- { name: '市妇幼保健院东院城区', year: '2024', val: 35, id: 2 },
- ]);
- const tableLoading = ref(false);
- const tableArea = ref(null);
- const dataLists = ref([]);
- // const currentYear = ref('2024');
- // 可渗透地面变化echarts
- function kstChart() {
- //先销毁实例
- chartKst.value && chartKst.value.dispose();
- chartKst.value = proxy.echarts.init(document.getElementById('chartRainST'));
- rainwaterUtilizationChart().then(res => {
- let datas = res.data;
- let charts = JSON.parse(JSON.stringify(optionChart.option3));
- charts.graphic.invisible = true; // 暂无数据
- charts.yAxis.name = 't';
- charts.series[0].name = '雨水资源利用量';
- charts.series[0].data = datas.rainwaterUtilizationTotals;
- dataLists.value = datas.projectCompletionAcceptanceList;
- charts.xAxis.data = datas.years;
- if (datas.years.length == 0) {
- charts.graphic.invisible = false; // 暂无数据
- } else {
- charts.graphic.invisible = true; // 暂无数据
- }
- chartKst.value.clear();
- chartKst.value.setOption(charts);
- // 默认加载第一个年份的表格数据
- tableData.value = datas.projectCompletionAcceptanceList[0];
- // gis地图渲染
- tableData.value &&
- tableData.value.map(item => {
- item.type = 'error_zishui';
- });
- intiMapDataPoint(tableData.value);
- barChartClick(); //柱状图点击事件
- });
- }
-
- // 可渗透地面变化echarts柱状图点击事件
- function barChartClick() {
- chartKst.value.getZr().setCursorStyle('pointer'); //设置鼠标移入手形
- chartKst.value.off('click'); //防止触发两次点击事件
- // 柱状图点击
- chartKst.value.getZr().on('click', params => {
- let pointInPixel = [params.offsetX, params.offsetY];
- if (chartKst.value.containPixel('grid', pointInPixel)) {
- let pointInGrid = chartKst.value.convertFromPixel({ seriesIndex: 0 }, pointInPixel);
- let xIndex = pointInGrid[0]; //索引
- let handleIndex = Number(xIndex);
- if (handleIndex == -0) handleIndex = 0;
- console.log(handleIndex);
- // gis地图渲染
- let dataArr = dataLists.value[handleIndex];
- dataArr &&
- dataArr.map(item => {
- item.type = 'error_zishui';
- });
- tableData.value = dataArr;
- intiMapDataPoint(dataArr);
- }
- });
- }
-
- // 表格项目点击在地图定位
- function checkProject(row) {
- // console.log(row);
- let lonlat = row.projectLocation.split(',');
- newfiberMapbox.map.easeTo({
- center: [Number(lonlat[0]), Number(lonlat[1])],
- });
- }
-
- //自适应
- function resizeTheChart() {
- chartKst.value.resize();
- }
-
- // 地图渲染点位
- function intiMapDataPoint(data) {
- newfiberMapbox.popupService.popups.forEach((popup, index) => {
- nextTick(() => {
- newfiberMapbox.removePopup(popup);
- });
- });
- if (newfiberMapbox.map.getLayer('rainwater')) {
- newfiberMapbox.map.removeLayer('rainwater');
- newfiberMapbox.map.removeSource('rainwater');
- }
- let geojson1 = turf.featureCollection(
- data.map(item =>
- turf.point(item.projectLocation.split(','), {
- ...item,
- projectName: `${item.projectName}`,
- rainwaterUtilization: `${item.rainwaterUtilization} t`,
- color: '#d9001b',
- })
- )
- );
- addWaterloggingLayer(geojson1, 'rainwater');
- let key = 'error_zishui';
- // bus.emit('getGeojsonByType', {
- // type: 'error_zishui',
- // callback: geojson => {
- // setTimeout(() => {
- // bus.emit('removeMapDatas', ['error_zishui']);
- // if (!!!geojson.features.length) bus.emit('setGeoJSON', { json: geojson1, key });
- // bus.emit('setLayerVisible', { layername: key, isCheck: true });
- // }, 2000);
- // },
- // });
- geojson1.features.forEach(feature => {
- return newfiberMapbox.addPopup(
- new mapboxL7.Popup({
- title: '',
- html: `
- <div class='popupMapPoint successPopup' style="background:rgba(129, 211, 248, 0.5); border: 2px solid #81d3f8;" ><div class='titles' style=" padding-left:10px">${feature.properties.projectName}</div>
- <div class='part'>雨水资源利用量:${feature.properties.rainwaterUtilization}</div>
- </div>`,
- lngLat: {
- lng: feature.geometry.coordinates[0],
- lat: feature.geometry.coordinates[1],
- },
- anchor: 'center',
- offsets: [20, 60],
- autoClose: false,
- })
- );
- });
- }
- //地图渲染点位
- const addWaterloggingLayer = (geojson, layerName) => {
- !!!newfiberMapbox.map.getSource(layerName) && newfiberMapbox.map.addSource(layerName, { type: 'geojson', data: geojson });
- !!!newfiberMapbox.map.getLayer(layerName) &&
- newfiberMapbox.map.addLayer({
- id: layerName,
- type: 'circle',
- source: layerName,
- paint: {
- 'circle-color': ['get', 'color'],
- 'circle-radius': 7,
- },
- });
- };
- onMounted(() => {
- kstChart();
- tableArea.value.setCurrentRow(tableData.value[0], true); //表格默认第一个高亮选中
- window.addEventListener('resize', resizeTheChart);
- });
- onBeforeUnmount(() => {
- if (!!!newfiberMapbox) return;
- !!newfiberMapbox.map.getLayer('rainwater') && newfiberMapbox.map.removeLayer('rainwater');
- !!newfiberMapbox.map.getSource('rainwater') && newfiberMapbox.map.removeSource('rainwater');
- });
- </script>
- <style lang="scss" scoped>
- @import '@/assets/styles/variables.module.scss';
- .l7-popup-tip {
- display: none !important;
- }
- .l7-popup .l7-popup-content {
- padding: 0px;
- background: rgba(3, 59, 79, 0) !important;
- }
- .l7-popup-content {
- padding: 0px;
- background: rgba(3, 59, 79, 0) !important;
- }
-
- .successPopup {
- border-radius: 8px;
- background-color: rgba(129, 211, 248, 0.5);
- border: 2px solid #81d3f8;
- padding: 5px;
- }
- .titles {
- font-size: 16px;
- padding: 10px;
- }
- .rainWaterCX {
- width: 100%;
- height: 100%;
- position: relative;
- .imgTL {
- position: absolute;
- z-index: 99;
- left: 30px;
- bottom: 20px;
- }
- .preContentRight {
- width: 500px;
- height: calc(100vh - 100px);
- border: 1px solid #1d8db4;
- background: $mainBg;
- border-radius: 8px;
- position: absolute;
- top: 20px;
- right: 20px;
- z-index: 90;
- padding: 15px;
- overflow: auto;
- .chartHeight {
- width: 100%;
- height: 260px;
- }
- .el-table__body tr {
- cursor: pointer;
- }
- }
- }
- </style>