worldwide-map / script.js
maringetxway's picture
Update script.js
9e4ae9e verified
raw
history blame
1.17 kB
const map = L.map('map').setView([20, 0], 2);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Custom robot marker icon
const robotIcon = L.icon({
iconUrl: 'https://cdn.shopify.com/s/files/1/0767/2040/6877/files/LeRobot.png?v=1745423992', // Change to your preferred robot icon URL
iconSize: [35, 35], // size of the icon
iconAnchor: [20, 40], // point of the icon which will correspond to marker's location
popupAnchor: [0, -35] // point from which the popup should open relative to the iconAnchor
});
fetch('data.json')
.then(response => response.json())
.then(data => {
data.forEach(entry => {
const lat = parseFloat(entry.latitude || entry.Latitude);
const lng = parseFloat(entry.longitude || entry.Longitude);
const name = entry.name || entry.Name || 'Unknown';
const desc = entry.description || entry.Description || '';
if (!isNaN(lat) && !isNaN(lng)) {
L.marker([lat, lng], { icon: robotIcon })
.addTo(map)
.bindPopup(`<strong>${name}</strong><br>${desc}`);
}
});
});