智慧水务管理系统 - 精河县供水工程综合管理平台

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <template>
  2. <div ref="mapContainer" class="map-container"></div>
  3. </template>
  4. <script setup lang="ts">
  5. import { ref, onMounted, onUnmounted } from 'vue'
  6. const props = defineProps<{
  7. center?: [number, number]
  8. zoom?: number
  9. markers?: Array<{ lat: number; lng: number; name: string; value?: string }>
  10. }>()
  11. const mapContainer = ref<HTMLElement>()
  12. let map: any = null
  13. onMounted(async () => {
  14. const L = (await import('leaflet')).default
  15. await import('leaflet/dist/leaflet.css')
  16. map = L.map(mapContainer.value!).setView(props.center || [44.6000, 82.9000], props.zoom || 10)
  17. L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  18. attribution: '&copy; OpenStreetMap', maxZoom: 18
  19. }).addTo(map)
  20. if (props.markers) {
  21. props.markers.forEach(m => {
  22. L.marker([m.lat, m.lng])
  23. .addTo(map)
  24. .bindPopup(`<b>${m.name}</b><br/>${m.value || ''}`)
  25. })
  26. }
  27. })
  28. onUnmounted(() => { if (map) map.remove() })
  29. </script>
  30. <style scoped>
  31. .map-container { width: 100%; height: 500px; border-radius: 8px }
  32. </style>