Browse Source

docs:首页模块

master
waibao2 2 months ago
parent
commit
0878c53809
  1. 82
      src/views/index.vue

82
src/views/index.vue

@ -4,13 +4,11 @@ @@ -4,13 +4,11 @@
<div id="mapContainer" class="map" style="height: calc(100vh - 50px);">
</div>
</div>
</div>
</template>
<script setup name="Index">
import { onMounted, ref, reactive, nextTick } from "vue";
import { onMounted, ref, reactive, nextTick, onUnmounted } from "vue";
import _ from "lodash";
import L from 'leaflet'
import dayjs from 'dayjs'
@ -19,7 +17,6 @@ @@ -19,7 +17,6 @@
const { proxy } = getCurrentInstance()
import qtGeojsonData from '@/assets/data/qingtian.json'
const tdtKey = 'e0d855b509f09b891605c4dc5f29868b'
@ -84,7 +81,6 @@ @@ -84,7 +81,6 @@
const TownGov = [28.205423, 120.165288] //
const initMap = () => {
//
const defaultBase = '影像'
tiandituMap = L.map('mapContainer', {
@ -153,6 +149,7 @@ @@ -153,6 +149,7 @@
//
maskLayer.bringToFront();
};
let MapData = []
//
const getIndexData = async () => {
@ -162,7 +159,7 @@ @@ -162,7 +159,7 @@
if (res.code == 0) {
let rawData = res.data
rawData = _.filter(rawData, function (o) {
return !o.longitude == "" || !o.latitude == '';
return o.longitude !== "" && o.latitude !== "";
});
MapData = _.map(rawData, item => {
item.position_xy = [item.latitude, item.longitude]
@ -178,12 +175,12 @@ @@ -178,12 +175,12 @@
addMarkers()
}
} catch (error) {
console.error(error)
} finally {
mapLoading.value = false
}
};
let dialogVisible = ref(false) //
let popupData = ref([])
let pinMarkers = []; // marker
@ -191,6 +188,35 @@ @@ -191,6 +188,35 @@
let autoPlayInterval = null; //
let isPaused = false; //
let currentPopup = null; //
//
const showMarkerPopup = (e) => {
popupData.value = e.target.options;
const popupContent = `
<div style="color: white; padding: 10px; font-size: 14px;">
<h3 style="margin-top: 0;">${popupData.value.stnm}</h3>
<table class='dialog-table' style="width: 100%; border-collapse: collapse;">
${popupData.value.data ? popupData.value.data.map(row => `
<tr>
<td style="padding: 5px; width: 50%;">${row.name}${row.unit ? `${row.unit}` : ''}</td>
<td style="padding: 5px; width: 50%;">${row.value || row.latestValue || ''}</td>
</tr>
`).join('') : ''}
</table>
</div>
`;
// popup
if (currentPopup) {
tiandituMap.closePopup(currentPopup);
}
currentPopup = L.popup()
.setLatLng(e.target._latlng)
.setContent(popupContent)
.openOn(tiandituMap);
};
//
const startAutoPlay = () => {
if (autoPlayInterval) {
@ -234,7 +260,7 @@ @@ -234,7 +260,7 @@
//
pinMarkers.forEach(m => tiandituMap.removeLayer(m));
pinMarkers = [];
MapData.forEach(item => {
MapData.forEach((item, index) => {
let marker;
const markerIcon = L.icon({
iconUrl: item.icon || rain0,
@ -245,7 +271,7 @@ @@ -245,7 +271,7 @@
icon: markerIcon,
data: item.data,
stnm: item.stnm,
stnmId:item.stnmId
stnmId: item.stnmId
});
//
marker.on('mouseover', (e) => {
@ -265,6 +291,7 @@ @@ -265,6 +291,7 @@
});
marker.on('click', (e) => {
currentIndex = index; //
showMarkerPopup(e);
});
pinMarkers.push(marker);
@ -280,7 +307,6 @@ @@ -280,7 +307,6 @@
firstMarker.fire('click');
}
//
/**************************** CodeGeeX Inline Diff ****************************/
startAutoPlay();
}
}, 1000);
@ -289,42 +315,20 @@ @@ -289,42 +315,20 @@
tiandituMap.on('click', () => {
if (currentPopup) {
tiandituMap.closePopup(currentPopup);
}
})
}
//
const showMarkerPopup = (e) => {
/******************** 49ec4b3d-3bf0-41fc-a821-48f719365cbd ********************/
popupData.value = e.target.options;
const popupContent = `
<div style="color: white; padding: 10px; font-size: 14px;">
<h3 style="margin-top: 0;">${popupData.value.stnm}</h3>
<table class='dialog-table' style="width: 100%; border-collapse: collapse;">
${popupData.value.data.map(row => `
<tr>
<td style="padding: 5px; width: 50%;">${row.name}${row.unit ? `${row.unit}` : ''}</td>
<td style="padding: 5px; width: 50%;">${row.value || row.latestValue}</td>
</tr>
`).join('')}
</table>
</div>
`;
// popup
currentPopup = L.popup()
.setLatLng(e.target._latlng)
.setContent(popupContent)
.openOn(tiandituMap);
};
/*********************************************************** 弹窗 *****************************************/
onMounted(() => {
initMap()
})
//
onUnmounted(() => {
if (autoPlayInterval) {
clearInterval(autoPlayInterval);
}
});
})
</script>
<style scoped lang="scss">
@ -343,8 +347,6 @@ @@ -343,8 +347,6 @@
}
}
.el-table,
.el-table__expanded-cell,
.el-table tr,
@ -375,8 +377,6 @@ @@ -375,8 +377,6 @@
color: skyblue;
}
}
}
/* 隐藏popup的关闭按钮 */

Loading…
Cancel
Save