forked from thejanRajapaksha/SW-Tools-and-Practices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
33 lines (26 loc) · 1.07 KB
/
script.js
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
document.addEventListener('DOMContentLoaded', function () {
initMap();
});
async function initMap() {
const response = await fetch('fetch_locations.php'); // Assuming your server endpoint is 'fetch_locations.php'
const markers = await response.json();
const map = L.map('map').setView([6.8235313, 80.0367716], 10);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
const bounds = [];
// Loop through all markers
markers.forEach(markerInfo => {
const marker = L.marker([parseFloat(markerInfo.lat), parseFloat(markerInfo.lng)]).addTo(map);
bounds.push([parseFloat(markerInfo.lat), parseFloat(markerInfo.lng)]);
marker.bindPopup(`
<div class="feh-content">
<h3>${markerInfo.locationName}</h3>
<address>
<p>${markerInfo.address}</p>
</address>
</div>
`);
});
map.fitBounds(bounds);
}