-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmap.php
More file actions
65 lines (54 loc) · 1.73 KB
/
Copy pathmap.php
File metadata and controls
65 lines (54 loc) · 1.73 KB
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
65
<?php
$page = 'map';
include 'header.php';
?>
<div class="cards">
<section class="card" style="width:100%;height:600px;position:relative;">
<h2>Last heard stations map</h2>
<div id="map" style="height:540px;border-radius:12px;"></div>
</section>
</div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
<script>
const markers = {};
const smallIcon = L.icon({
iconUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon.png',
shadowUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-shadow.png',
iconSize: [16, 26],
iconAnchor: [8, 26],
popupAnchor: [0, -26],
shadowSize: [26, 26]
});
var map = L.map('map').setView([20,0], 2);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18
}).addTo(map);
const markersLayer = L.layerGroup().addTo(map);
function updateMap() {
fetch('get_coordinates.php')
.then(r => r.json())
.then(data => {
if (!Array.isArray(data)) return;
data.forEach(p => {
const lat = Number(p.lat);
const lon = Number(p.lon);
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return;
const key = p.callsign || `${lat},${lon}`;
if (markers[key]) {
// update position + popup text
markers[key].setLatLng([lat, lon]);
markers[key].setPopupContent(p.location || '');
} else {
// create new marker
markers[key] = L.marker([lat, lon], { icon: smallIcon })
.addTo(map)
.bindPopup(p.location || '');
}
});
});
}
updateMap();
setInterval(updateMap, 2000); // pull every 2 seconds
</script>
<?php include 'footer.php'; ?>