html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>基站分布地图</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
#map {
height: 100vh;
width: 100%;
}
.stats-window {
position: absolute;
top: 20px;
right: 20px;
background: white;
padding: 15px;
border-radius: 8px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
width: 300px;
z-index: 1000;
}
.legend {
position: absolute;
bottom: 20px;
right: 20px;
background: white;
padding: 10px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.legend-item {
margin: 5px 0;
}
.legend-color {
display: inline-block;
width: 20px;
height: 20px;
border-radius: 50%;
margin-right: 8px;
vertical-align: middle;
}
.station-info {
padding: 5px;
font-size: 14px;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="stats" class="stats-window">
<canvas id="statsChart"></canvas>
</div>
<div class="legend">
<div class="legend-item">
<span class="legend-color" style="background: green;"></span>
<span>正常运行</span>
</div>
<div class="legend-item">
<span class="legend-color" style="background: red;"></span>
<span>故障站点</span>
</div>
<div class="legend-item">
<span class="legend-color" style="background: orange;"></span>
<span>断站</span>
</div>
<div class="legend-item">
<span class="legend-color" style="background: gray;"></span>
<span>退服小区</span>
</div>
</div>
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
// 初始化地图
const map = L.map('map').setView([39.9042, 116.4074], 12);
// 添加地图图层
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
// 模拟基站数据
const baseStations = [
{ id: 1, lat: 39.9042, lng: 116.4074, status: 'normal', name: '基站-001' },
{ id: 2, lat: 39.9142, lng: 116.4174, status: 'fault', name: '基站-002' },
{ id: 3, lat: 39.9242, lng: 116.4274, status: 'disconnected', name: '基站-003' },
{ id: 4, lat: 39.8942, lng: 116.3974, status: 'retired', name: '基站-004' },
{ id: 5, lat: 39.9342, lng: 116.4374, status: 'normal', name: '基站-005' },
{ id: 6, lat: 39.8842, lng: 116.3874, status: 'fault', name: '基站-006' },
{ id: 7, lat: 39.9442, lng: 116.4474, status: 'disconnected', name: '基站-007' },
{ id: 8, lat: 39.8742, lng: 116.3774, status: 'retired', name: '基站-008' },
{ id: 9, lat: 39.9142, lng: 116.3974, status: 'normal', name: '基站-009' },
{ id: 10, lat: 39.8942, lng: 116.4174, status: 'normal', name: '基站-010' }
];
// 状态颜色映射
const statusColors = {
normal: 'green',
fault: 'red',
disconnected: 'orange',
retired: 'gray'
};
// 状态中文映射
const statusNames = {
normal: '正常运行',
fault: '故障',
disconnected: '断站',
retired: '退服'
};
// 统计各状态基站数量
const stats = {
normal: 0,
fault: 0,
disconnected: 0,
retired: 0
};
// 在地图上添加基站标记
baseStations.forEach(station => {
const color = statusColors[station.status];
const marker = L.circleMarker([station.lat, station.lng], {
radius: 8,
fillColor: color,
color: '#000',
weight: 1,
opacity: 1,
fillOpacity: 0.8
}).addTo(map);
// 添加弹出信息
marker.bindPopup(`
<div class="station-info">
<h3>${station.name}</h3>
<p>状态: ${statusNames[station.status]}</p>
<p>位置: ${station.lat.toFixed(4)}, ${station.lng.toFixed(4)}</p>
</div>
`);
// 更新统计数据
stats[station.status]++;
});
// 创建统计图表
const ctx = document.getElementById('statsChart').getContext('2d');
new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['正常运行', '故障站点', '断站', '退服小区'],
datasets: [{
data: [stats.normal, stats.fault, stats.disconnected, stats.retired],
backgroundColor: [
statusColors.normal,
statusColors.fault,
statusColors.disconnected,
statusColors.retired
],
borderColor: 'white',
borderWidth: 2
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'bottom',
labels: {
font: {
size: 12
}
}
},
title: {
display: true,
text: '基站状态统计',
font: {
size: 16,
weight: 'bold'
}
}
}
}
});
});
</script>
</body>
</html>