Download script.js from LeRobot-worldwide-hackathon/worldwide-map: direct link, hf CLI and curl.
- Browser
- Download file 2.78 kB
-
https://huggingface.co/spaces/LeRobot-worldwide-hackathon/worldwide-map/resolve/main/script.js
- Command line
-
hf download hf://spaces/LeRobot-worldwide-hackathon/worldwide-map/script.js
-
curl -L -o script.js https://huggingface.co/spaces/LeRobot-worldwide-hackathon/worldwide-map/resolve/main/script.js
2.78 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 for Local Hackathon | |
| const robotIcon = L.icon({ | |
| iconUrl: 'https://cdn.shopify.com/s/files/1/0767/2040/6877/files/LeRobot.png?v=1745423992', | |
| iconSize: [35, 35], | |
| iconAnchor: [20, 40], | |
| popupAnchor: [0, -35] | |
| }); | |
| // Custom HQ marker icon | |
| const hqIcon = L.icon({ | |
| iconUrl: 'https://cdn.shopify.com/s/files/1/0767/2040/6877/files/HF_Logo.png?v=1745427981', | |
| iconSize: [35, 35], | |
| iconAnchor: [20, 40], | |
| popupAnchor: [0, -35] | |
| }); | |
| // Function to add markers from a dataset | |
| function addMarkers(data, icon) { | |
| console.log('Processing data:', data); // Log the data being processed | |
| 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 || ''; | |
| const address = entry.address || entry.address || 'N/A'; | |
| const nbPeople = entry.nb_of_people || entry.nb_of_people || ''; | |
| const discordUsername = entry.discord_username || entry.discord_username || ''; | |
| if (!isNaN(lat) && !isNaN(lng)) { | |
| let popupContent = ` | |
| <strong>${name}</strong><br> | |
| ${desc}<br> | |
| <strong>Address:</strong> ${address}<br> | |
| `; | |
| if (nbPeople && nbPeople !== 'N/A') { | |
| popupContent += `<strong>Nb of People:</strong> ${nbPeople}<br>`; | |
| } | |
| if (discordUsername && discordUsername !== 'N/A') { | |
| popupContent += `<strong>Discord Username:</strong> ${discordUsername}<br>`; | |
| } | |
| L.marker([lat, lng], { icon: icon }) | |
| .addTo(map) | |
| .bindPopup(popupContent); | |
| } else { | |
| console.warn('Invalid coordinates:', entry); // Log entries with invalid coordinates | |
| } | |
| }); | |
| } | |
| // Fetch and process the first dataset | |
| fetch('data_HQ_HF.json') | |
| .then(response => { | |
| if (!response.ok) { | |
| throw new Error('Network response was not ok'); | |
| } | |
| return response.json(); | |
| }) | |
| .then(data => { | |
| console.log('Fetched data_HQ_HF.json:', data); // Log the fetched data | |
| addMarkers(data, hqIcon); | |
| }) | |
| .catch(error => { | |
| console.error('Error fetching data_HQ_HF.json:', error); | |
| }); | |
| // Fetch and process the second dataset | |
| fetch('data.json') | |
| .then(response => { | |
| if (!response.ok) { | |
| throw new Error('Network response was not ok'); | |
| } | |
| return response.json(); | |
| }) | |
| .then(data => { | |
| console.log('Fetched data.json:', data); // Log the fetched data | |
| addMarkers(data, robotIcon); | |
| }) | |
| .catch(error => { | |
| console.error('Error fetching data.json:', error); | |
| }); |