maringetxway commited on
Commit
3f2ed7e
·
verified ·
1 Parent(s): 12a250b

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +59 -16
script.js CHANGED
@@ -1,11 +1,10 @@
1
  const map = L.map('map').setView([20, 0], 2);
2
 
3
- // OpenStreetMap tile layer
4
  L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
5
  attribution: '© OpenStreetMap contributors'
6
  }).addTo(map);
7
 
8
- // Custom icons for robot and HQ
9
  const robotIcon = L.icon({
10
  iconUrl: 'https://cdn.shopify.com/s/files/1/0767/2040/6877/files/LeRobot.png?v=1745423992',
11
  iconSize: [35, 35],
@@ -13,6 +12,7 @@ const robotIcon = L.icon({
13
  popupAnchor: [0, -35]
14
  });
15
 
 
16
  const hqIcon = L.icon({
17
  iconUrl: 'https://cdn.shopify.com/s/files/1/0767/2040/6877/files/HF_Logo.png?v=1745427981',
18
  iconSize: [35, 35],
@@ -20,28 +20,71 @@ const hqIcon = L.icon({
20
  popupAnchor: [0, -35]
21
  });
22
 
23
- // Function to add markers with icons
24
  function addMarkers(data, icon) {
 
25
  data.forEach(entry => {
26
- const lat = parseFloat(entry.latitude);
27
- const lng = parseFloat(entry.longitude);
 
 
 
 
 
 
28
  if (!isNaN(lat) && !isNaN(lng)) {
29
- const popupContent = `
30
- <strong>${entry.name || 'Unknown'}</strong><br>
31
- ${entry.description || ''}<br>
32
- <strong>Address:</strong> ${entry.address || 'N/A'}<br>
33
  `;
34
- L.marker([lat, lng], { icon: icon }).addTo(map).bindPopup(popupContent);
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
36
  });
37
  }
38
 
39
- // Fetch and add data for HQ
 
40
  fetch('data_HQ_HF.json')
41
- .then(response => response.json())
42
- .then(data => addMarkers(data, hqIcon));
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- // Fetch and add data for robots
45
  fetch('data.json')
46
- .then(response => response.json())
47
- .then(data => addMarkers(data, robotIcon));
 
 
 
 
 
 
 
 
 
 
 
 
1
  const map = L.map('map').setView([20, 0], 2);
2
 
 
3
  L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
4
  attribution: '&copy; OpenStreetMap contributors'
5
  }).addTo(map);
6
 
7
+ // Custom robot marker icon
8
  const robotIcon = L.icon({
9
  iconUrl: 'https://cdn.shopify.com/s/files/1/0767/2040/6877/files/LeRobot.png?v=1745423992',
10
  iconSize: [35, 35],
 
12
  popupAnchor: [0, -35]
13
  });
14
 
15
+ // Custom HQ marker icon
16
  const hqIcon = L.icon({
17
  iconUrl: 'https://cdn.shopify.com/s/files/1/0767/2040/6877/files/HF_Logo.png?v=1745427981',
18
  iconSize: [35, 35],
 
20
  popupAnchor: [0, -35]
21
  });
22
 
23
+ // Function to add markers from a dataset
24
  function addMarkers(data, icon) {
25
+ console.log('Processing data:', data); // Log the data being processed
26
  data.forEach(entry => {
27
+ const lat = parseFloat(entry.latitude || entry.latitude);
28
+ const lng = parseFloat(entry.longitude || entry.longitude);
29
+ const name = entry.name || entry.name || 'Unknown';
30
+ const desc = entry.description || entry.Description || '';
31
+ const address = entry.address || entry.address || 'N/A';
32
+ const nbPeople = entry.nb_of_people || entry.nb_of_people || '';
33
+ const discordUsername = entry.discord_username || entry.discord_username || '';
34
+
35
  if (!isNaN(lat) && !isNaN(lng)) {
36
+ let popupContent = `
37
+ <strong>${name}</strong><br>
38
+ ${desc}<br>
39
+ <strong>Address:</strong> ${address}<br>
40
  `;
41
+
42
+ if (nbPeople && nbPeople !== 'N/A') {
43
+ popupContent += `<strong>Nb of People:</strong> ${nbPeople}<br>`;
44
+ }
45
+
46
+ if (discordUsername && discordUsername !== 'N/A') {
47
+ popupContent += `<strong>Discord Username:</strong> ${discordUsername}<br>`;
48
+ }
49
+
50
+ L.marker([lat, lng], { icon: icon })
51
+ .addTo(map)
52
+ .bindPopup(popupContent);
53
+ } else {
54
+ console.warn('Invalid coordinates:', entry); // Log entries with invalid coordinates
55
  }
56
  });
57
  }
58
 
59
+
60
+ // Fetch and process the first dataset
61
  fetch('data_HQ_HF.json')
62
+ .then(response => {
63
+ if (!response.ok) {
64
+ throw new Error('Network response was not ok');
65
+ }
66
+ return response.json();
67
+ })
68
+ .then(data => {
69
+ console.log('Fetched data_HQ_HF.json:', data); // Log the fetched data
70
+ addMarkers(data, hqIcon);
71
+ })
72
+ .catch(error => {
73
+ console.error('Error fetching data_HQ_HF.json:', error);
74
+ });
75
 
76
+ // Fetch and process the second dataset
77
  fetch('data.json')
78
+ .then(response => {
79
+ if (!response.ok) {
80
+ throw new Error('Network response was not ok');
81
+ }
82
+ return response.json();
83
+ })
84
+ .then(data => {
85
+ console.log('Fetched data.json:', data); // Log the fetched data
86
+ addMarkers(data, robotIcon);
87
+ })
88
+ .catch(error => {
89
+ console.error('Error fetching data.json:', error);
90
+ });