-
Notifications
You must be signed in to change notification settings - Fork 0
/
rough.html
64 lines (59 loc) · 2.27 KB
/
rough.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Drone Charging Stations</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.css" />
<style>
#map {
width: 100%;
height: 600px;
}
.leaflet-bar a {
background-color: #000;
color: #fff;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js"></script>
<script>
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
}).addTo(map);
var stations = [
{ "name": "Station 1", "lat": 51.505, "lng": -0.09 },
{ "name": "Station 2", "lat": 51.515, "lng": -0.1 },
{ "name": "Station 3", "lat": 51.525, "lng": -0.11 }
];
function getMarkerIcon(color) {
return L.icon({
iconUrl: `https://leafletjs.com/examples/custom-icons/leaf-${color}.png`,
shadowUrl: 'https://leafletjs.com/examples/custom-icons/leaf-shadow.png',
iconSize: [38, 95],
shadowSize: [50, 64],
iconAnchor: [22, 94],
shadowAnchor: [4, 62],
popupAnchor: [-3, -76]
});
}
stations.forEach(station => {
var marker = L.marker([station.lat, station.lng], { icon: getMarkerIcon('red') }).addTo(map)
.bindPopup(`<label><input type="checkbox" onchange="toggleStation(this, ${station.lat}, ${station.lng})"> ${station.name}</label>`);
});
function toggleStation(checkbox, lat, lng) {
var marker = L.marker([lat, lng]);
if (checkbox.checked) {
marker.setIcon(getMarkerIcon('green'));
} else {
marker.setIcon(getMarkerIcon('red'));
}
}
</script>
</body>
</html>