Update templates/map.html
Browse files- templates/map.html +66 -73
templates/map.html
CHANGED
|
@@ -131,91 +131,84 @@
|
|
| 131 |
let currentZoom = 3;
|
| 132 |
|
| 133 |
|
| 134 |
-
//
|
| 135 |
-
const ws = new WebSocket(`wss://sebastiankay-eft-group-map-websocket.hf.space/ws`)
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
const
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
};
|
| 158 |
-
|
| 159 |
-
ws.onopen = function
|
| 160 |
-
|
| 161 |
-
ws.send(JSON.stringify({ type: "join", group: wsgroup }));
|
| 162 |
};
|
| 163 |
-
|
|
|
|
| 164 |
function removeAllMarkers() {
|
| 165 |
-
// Iterate over all player markers
|
| 166 |
for (const playername in playerMarkers) {
|
| 167 |
if (playerMarkers.hasOwnProperty(playername)) {
|
| 168 |
-
// Remove the marker from the map
|
| 169 |
map.removeLayer(playerMarkers[playername]);
|
| 170 |
}
|
| 171 |
}
|
| 172 |
-
// Clear the playerMarkers object
|
| 173 |
Object.keys(playerMarkers).forEach(key => delete playerMarkers[key]);
|
| 174 |
console.log("Alle Marker wurden entfernt.");
|
| 175 |
}
|
| 176 |
-
|
|
|
|
| 177 |
function loadLocalData() {
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
// Rade is not over yet
|
| 204 |
-
console.log("Rade is not over yet")
|
| 205 |
-
|
| 206 |
-
const new_html = `
|
| 207 |
-
<div class="rade-time"><i class="fa-solid fa-door-open"></i> <h3 id="rade_time_remain" data-seconds="${parseInt(parsedData.rade_end_time) - Math.floor(new Date().getTime() / 1000.0)}" data-rade-end="${parsedData.rade_end_time}" data-rade-start="${parsedData.rade_start_time}" class="rade-time-remain">${parsedData.remaining_time}</h3></div>
|
| 208 |
-
<ul>
|
| 209 |
-
${parsedData.extraction_exit_names.map(name => `<li><span class="tag exit">EXIT</span> ${name}</li>`).join('')}
|
| 210 |
-
${parsedData.extraction_transit_names.map(name => `<li><span class="tag transit">TRANSIT</span> ${name.replaceAll("Transit ", "")}</li>`).join('')}
|
| 211 |
-
</ul>
|
| 212 |
-
`
|
| 213 |
-
addNewRadeData(new_html)
|
| 214 |
-
} else console.log("Rade is over")
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
};
|
| 219 |
|
| 220 |
const images = {
|
| 221 |
'container_bank-cash-register': 'container_cash-register',
|
|
|
|
| 131 |
let currentZoom = 3;
|
| 132 |
|
| 133 |
|
| 134 |
+
// Initialize WebSocket connection
|
| 135 |
+
const ws = new WebSocket(`wss://sebastiankay-eft-group-map-websocket.hf.space/ws`);
|
| 136 |
+
|
| 137 |
+
// WebSocket event handlers
|
| 138 |
+
ws.onmessage = function(event) {
|
| 139 |
+
console.log(event.data);
|
| 140 |
+
const data = JSON.parse(event.data);
|
| 141 |
+
|
| 142 |
+
switch (data.type) {
|
| 143 |
+
case "coordinates":
|
| 144 |
+
const parsedData = data.data;
|
| 145 |
+
localStorage.setItem("last_marker", JSON.stringify(parsedData));
|
| 146 |
+
loadLocalData();
|
| 147 |
+
break;
|
| 148 |
+
|
| 149 |
+
case "location_map":
|
| 150 |
+
const map_name = data.data.map.toLowerCase().replaceAll(" ", "-");
|
| 151 |
+
localStorage.setItem("last_map_name", map_name);
|
| 152 |
+
localStorage.removeItem("last_marker");
|
| 153 |
+
removeAllMarkers(); // Clear all markers when the map changes
|
| 154 |
+
if (!location.pathname.includes(map_name)) {
|
| 155 |
+
location.pathname = `/map/${map_name}`;
|
| 156 |
+
} else {
|
| 157 |
+
location.reload();
|
| 158 |
+
}
|
| 159 |
+
break;
|
| 160 |
+
|
| 161 |
+
case "new_rade_data":
|
| 162 |
+
console.log(data.data);
|
| 163 |
+
const radeData = JSON.parse(data.data);
|
| 164 |
+
localStorage.setItem("rade_data", JSON.stringify(radeData));
|
| 165 |
+
loadLocalData();
|
| 166 |
+
break;
|
| 167 |
+
}
|
| 168 |
};
|
| 169 |
+
|
| 170 |
+
ws.onopen = function(event) {
|
| 171 |
+
ws.send(JSON.stringify({ type: "join", group: wsgroup }));
|
|
|
|
| 172 |
};
|
| 173 |
+
|
| 174 |
+
// Function to remove all markers
|
| 175 |
function removeAllMarkers() {
|
|
|
|
| 176 |
for (const playername in playerMarkers) {
|
| 177 |
if (playerMarkers.hasOwnProperty(playername)) {
|
|
|
|
| 178 |
map.removeLayer(playerMarkers[playername]);
|
| 179 |
}
|
| 180 |
}
|
|
|
|
| 181 |
Object.keys(playerMarkers).forEach(key => delete playerMarkers[key]);
|
| 182 |
console.log("Alle Marker wurden entfernt.");
|
| 183 |
}
|
| 184 |
+
|
| 185 |
+
// Function to load and display local marker data
|
| 186 |
function loadLocalData() {
|
| 187 |
+
const map_name = localStorage.getItem("last_map_name");
|
| 188 |
+
if (map_name) {
|
| 189 |
+
if (!location.pathname.includes(map_name)) {
|
| 190 |
+
localStorage.removeItem("last_marker");
|
| 191 |
+
}
|
| 192 |
+
} else {
|
| 193 |
+
localStorage.removeItem("last_marker");
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
const markerData = localStorage.getItem("last_marker");
|
| 197 |
+
if (markerData) {
|
| 198 |
+
const parsedData = JSON.parse(markerData);
|
| 199 |
+
// Use the new addMarker function with all required parameters
|
| 200 |
+
addMarker(
|
| 201 |
+
parsedData.x,
|
| 202 |
+
parsedData.y,
|
| 203 |
+
parsedData.z,
|
| 204 |
+
parsedData.timestamp,
|
| 205 |
+
parsedData.playername || "Unnamed Player",
|
| 206 |
+
parsedData.preview || false,
|
| 207 |
+
parsedData.actualmap || false,
|
| 208 |
+
parsedData.markercolor || false
|
| 209 |
+
);
|
| 210 |
+
}
|
| 211 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
const images = {
|
| 214 |
'container_bank-cash-register': 'container_cash-register',
|