Update templates/map.html
Browse files- templates/map.html +80 -1
templates/map.html
CHANGED
|
@@ -110,7 +110,8 @@
|
|
| 110 |
<script src="/static/js/leaflet.controlCoordinates.js"></script>
|
| 111 |
<script>
|
| 112 |
// GLOBAL VARIABLE TO HOLD THE CURRENT MARKER
|
| 113 |
-
|
|
|
|
| 114 |
const client_id = Date.now()
|
| 115 |
const mapData = {{ maps[0] | tojson }}
|
| 116 |
console.info(mapData)
|
|
@@ -1015,6 +1016,84 @@
|
|
| 1015 |
|
| 1016 |
// Funktion zum Hinzufügen eines Markers
|
| 1017 |
function addMarker(x, y, z, timestamp, preview = false, actualmap = false, playername = false, markercolor = false) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1018 |
// Position validieren
|
| 1019 |
|
| 1020 |
const position = {
|
|
|
|
| 110 |
<script src="/static/js/leaflet.controlCoordinates.js"></script>
|
| 111 |
<script>
|
| 112 |
// GLOBAL VARIABLE TO HOLD THE CURRENT MARKER
|
| 113 |
+
const playerMarkers = {}
|
| 114 |
+
let currentMarker = null
|
| 115 |
const client_id = Date.now()
|
| 116 |
const mapData = {{ maps[0] | tojson }}
|
| 117 |
console.info(mapData)
|
|
|
|
| 1016 |
|
| 1017 |
// Funktion zum Hinzufügen eines Markers
|
| 1018 |
function addMarker(x, y, z, timestamp, preview = false, actualmap = false, playername = false, markercolor = false) {
|
| 1019 |
+
|
| 1020 |
+
// Validate position
|
| 1021 |
+
const position = {
|
| 1022 |
+
x: parseFloat(x),
|
| 1023 |
+
y: parseFloat(y),
|
| 1024 |
+
z: parseFloat(z)
|
| 1025 |
+
};
|
| 1026 |
+
if (!positionIsInBounds(position)) {
|
| 1027 |
+
console.error("Position außerhalb der Karte:", position);
|
| 1028 |
+
return;
|
| 1029 |
+
}
|
| 1030 |
+
|
| 1031 |
+
// SVG-Icon als String mit dynamischer Farbe
|
| 1032 |
+
let markerColor;
|
| 1033 |
+
if (markercolor) {
|
| 1034 |
+
markerColor = '#' + markercolor;
|
| 1035 |
+
} else {
|
| 1036 |
+
markerColor = 'currentColor';
|
| 1037 |
+
}
|
| 1038 |
+
const svgString = `
|
| 1039 |
+
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 384 512' class="marker-svg">
|
| 1040 |
+
<path fill='${markerColor}' d='M172.3 501.7C27 291 0 269.4 0 192 0 86 86 0 192 0s192 86 192 192c0 77.4-27 99-172.3 309.7-9.5 13.8-29.9 13.8-39.5 0zM192 272c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80z'/>
|
| 1041 |
+
</svg>
|
| 1042 |
+
`;
|
| 1043 |
+
|
| 1044 |
+
// DivIcon mit dynamischem SVG erstellen
|
| 1045 |
+
const markerIcon = L.divIcon({
|
| 1046 |
+
html: svgString,
|
| 1047 |
+
className: 'custom-marker',
|
| 1048 |
+
iconSize: [32, 32],
|
| 1049 |
+
iconAnchor: [16, 32],
|
| 1050 |
+
popupAnchor: [0, -32]
|
| 1051 |
+
});
|
| 1052 |
+
|
| 1053 |
+
// Remove old marker for this player, if it exists
|
| 1054 |
+
if (playerMarkers[playername]) {
|
| 1055 |
+
map.removeLayer(playerMarkers[playername]);
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
// Create new marker
|
| 1059 |
+
playerMarkers[playername] = L.marker(pos(position), {
|
| 1060 |
+
icon: markerIcon,
|
| 1061 |
+
position: position,
|
| 1062 |
+
title: `Koordinaten: ${x}, ${y}, ${z}`,
|
| 1063 |
+
riseOnHover: true
|
| 1064 |
+
});
|
| 1065 |
+
|
| 1066 |
+
// Popup mit Informationen erstellen
|
| 1067 |
+
const popupContent = `
|
| 1068 |
+
<div class="marker-popup">
|
| 1069 |
+
${playername ? `<strong>Player: ${playername}</strong>` : ''}
|
| 1070 |
+
<strong>Koordinaten:</strong>
|
| 1071 |
+
<span>X: ${x} Y: ${y} Z: ${z}</span>
|
| 1072 |
+
${preview ? `<img class="preview-image" src="${preview}"><br>` : ''}
|
| 1073 |
+
<small>${timestamp}</small>
|
| 1074 |
+
</div>
|
| 1075 |
+
`;
|
| 1076 |
+
playerMarkers[playername].bindPopup(popupContent, {
|
| 1077 |
+
maxWidth: 250,
|
| 1078 |
+
minWidth: 150,
|
| 1079 |
+
autoClose: true,
|
| 1080 |
+
closeOnClick: true
|
| 1081 |
+
});
|
| 1082 |
+
|
| 1083 |
+
// Marker zur Karte hinzufügen
|
| 1084 |
+
playerMarkers[playername].addTo(map);
|
| 1085 |
+
|
| 1086 |
+
// Karte auf Marker zentrieren
|
| 1087 |
+
map.setView(pos(position), map.getZoom(), {
|
| 1088 |
+
animate: true,
|
| 1089 |
+
duration: 0.5
|
| 1090 |
+
});
|
| 1091 |
+
|
| 1092 |
+
console.log("Neuer Marker gesetzt für " + playername + ": " + position);
|
| 1093 |
+
}
|
| 1094 |
+
|
| 1095 |
+
|
| 1096 |
+
function addMarker_OLD(x, y, z, timestamp, preview = false, actualmap = false, playername = false, markercolor = false) {
|
| 1097 |
// Position validieren
|
| 1098 |
|
| 1099 |
const position = {
|