MonitorMap.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <template>
  2. <div class="monitor-map-container">
  3. <div id="monitorMap" class="map"></div>
  4. <el-drawer v-model="chartVisible" title="实时数据曲线" size="500px">
  5. <div ref="detailChart" class="detail-chart"></div>
  6. </el-drawer>
  7. </div>
  8. </template>
  9. <script setup>
  10. import { ref, onMounted, nextTick } from 'vue'
  11. import { getPointsWithLatestData } from '@/api/pipeNetwork/hazard'
  12. const chartVisible = ref(false)
  13. const detailChart = ref(null)
  14. let mapInstance = null
  15. async function initMap() {
  16. await nextTick()
  17. const el = document.getElementById('monitorMap')
  18. if (!el) return
  19. try {
  20. const L = await import('leaflet')
  21. mapInstance = L.map('monitorMap').setView([34.77, 113.65], 13)
  22. L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  23. attribution: '&copy; OpenStreetMap contributors'
  24. }).addTo(mapInstance)
  25. } catch (e) {
  26. el.innerHTML = '<div style="display:flex;align-items:center;justify-content:center;height:100%;color:#999;">请安装Leaflet: npm install leaflet</div>'
  27. }
  28. }
  29. onMounted(() => { initMap() })
  30. </script>
  31. <style scoped>
  32. .monitor-map-container { height: calc(100vh - 100px); padding: 16px; }
  33. .map { width: 100%; height: 100%; border-radius: 4px; }
  34. .detail-chart { width: 100%; height: 400px; }
  35. </style>