| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>GIS地图系统</title>
- <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
- <style>
- body { margin: 0; padding: 0; font-family: Arial, sans-serif; }
- #map { height: 600px; width: 100%; }
- .map-controls {
- position: absolute;
- top: 10px;
- right: 10px;
- background: white;
- padding: 10px;
- border-radius: 5px;
- box-shadow: 0 2px 5px rgba(0,0,0,0.2);
- z-index: 1000;
- }
- .control-group {
- margin-bottom: 10px;
- }
- .control-group label {
- display: block;
- margin-bottom: 5px;
- font-weight: bold;
- }
- .control-group select, .control-group button {
- width: 100%;
- padding: 5px;
- border: 1px solid #ccc;
- border-radius: 3px;
- }
- .device-popup {
- text-align: center;
- }
- .device-popup h4 {
- margin: 0 0 5px 0;
- color: #2c3e50;
- }
- .device-popup p {
- margin: 0;
- font-size: 12px;
- }
- </style>
- </head>
- <body>
- <div id="map"></div>
- <div class="map-controls">
- <div class="control-group">
- <label>底图选择</label>
- <select id="baseMapSelect">
- <option value="osm">OpenStreetMap</option>
- <option value="satellite">卫星影像</option>
- <option value="terrain">地形图</option>
- </select>
- </div>
- <div class="control-group">
- <label>图层控制</label>
- <div>
- <label><input type="checkbox" id="deviceLayer" checked> 监测点位</label><br>
- <label><input type="checkbox" id="pipeLayer" checked> 管网数据</label><br>
- <label><input type="checkbox" id="trajectoryLayer"> 轨迹回放</label>
- </div>
- </div>
- <div class="control-group">
- <button onclick="refreshData()">刷新数据</button>
- </div>
- </div>
-
- <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
- <script>
- // 初始化地图
- let map = L.map('map').setView([44.0321, 82.8973], 10);
-
- // 底图图层
- let osmLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
- attribution: '© OpenStreetMap contributors'
- });
-
- let satelliteLayer = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
- attribution: '© Esri'
- });
-
- let terrainLayer = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
- attribution: '© OpenTopoMap contributors'
- });
-
- osmLayer.addTo(map);
-
- // 监测点位图层
- let deviceLayer = L.layerGroup();
- let pipeLayer = L.layerGroup();
- let trajectoryLayer = L.layerGroup();
-
- // 加载监测点位数据
- function loadDevices() {
- fetch('/api/gis/devices')
- .then(response => response.json())
- .then(devices => {
- deviceLayer.clearLayers();
- devices.forEach(device => {
- let marker = L.marker([device.latitude, device.longitude])
- .bindPopup(`
- <div class="device-popup">
- <h4>${device.name}</h4>
- <p>编码: ${device.deviceCode}</p>
- <p>类型: ${device.deviceType}</p>
- </div>
- `);
- deviceLayer.addLayer(marker);
- });
- });
- }
-
- // 加载管网数据(模拟)
- function loadPipes() {
- pipeLayer.clearLayers();
- // 这里可以添加实际的管网数据加载逻辑
- let polyline = L.polyline([
- [44.0321, 82.8973],
- [44.0365, 82.9058],
- [44.0410, 82.9143]
- ], {
- color: '#0066cc',
- weight: 3
- });
- pipeLayer.addLayer(polyline);
- }
-
- // 地图切换控制
- document.getElementById('baseMapSelect').addEventListener('change', function(e) {
- // 移除所有底图
- map.eachLayer(layer => {
- if (layer instanceof L.TileLayer) {
- map.removeLayer(layer);
- }
- });
-
- // 添加选中的底图
- switch(e.target.value) {
- case 'osm':
- osmLayer.addTo(map);
- break;
- case 'satellite':
- satelliteLayer.addTo(map);
- break;
- case 'terrain':
- terrainLayer.addTo(map);
- break;
- }
- });
-
- // 图层控制
- document.getElementById('deviceLayer').addEventListener('change', function(e) {
- if (e.target.checked) {
- map.addLayer(deviceLayer);
- } else {
- map.removeLayer(deviceLayer);
- }
- });
-
- document.getElementById('pipeLayer').addEventListener('change', function(e) {
- if (e.target.checked) {
- map.addLayer(pipeLayer);
- } else {
- map.removeLayer(pipeLayer);
- }
- });
-
- document.getElementById('trajectoryLayer').addEventListener('change', function(e) {
- if (e.target.checked) {
- map.addLayer(trajectoryLayer);
- } else {
- map.removeLayer(trajectoryLayer);
- }
- });
-
- // 刷新数据
- function refreshData() {
- loadDevices();
- loadPipes();
- }
-
- // 初始加载数据
- loadDevices();
- loadPipes();
- map.addLayer(deviceLayer);
- map.addLayer(pipeLayer);
-
- // 地图事件监听
- map.on('click', function(e) {
- console.log('地图点击位置:', e.latlng);
- });
- </script>
- </body>
- </html>
|