Files
dune-dashboard/templates/map.html
T
Reditus f4ee1b85cf feat: themes dual-variant, Leaflet maps, RMQ explorer, security hardening
Themes: 28 variants (14 light + 14 dark) with grid-based switcher
Maps: Leaflet.js smooth zoom/pan, marker clustering, search, owner labels
Experimental: RMQ queue/exchange explorer, publish, message inspector, safety gate
Security: timing-safe login, rate limiter, token env-var, session timeout, Erlang injection fix
Fixes: logout, auto-login removed, table-header theme, default dark theme, ConfigMap name
2026-05-29 16:03:13 +01:00

348 lines
15 KiB
HTML

{% extends "base.html" %}
{% block title %}Map - Dune Dashboard{% endblock %}
{% block head_extra %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet.markercluster@1.5.3/dist/MarkerCluster.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet.markercluster@1.5.3/dist/MarkerCluster.Default.css" />
<style>
.map-page { display:flex; flex-direction:column; height:calc(100vh - 104px); min-height:620px; gap:14px; }
.map-header { display:flex; justify-content:space-between; align-items:flex-start; gap:16px; flex-shrink:0; }
.map-header h2 { margin:0; }
.map-summary { display:flex; gap:10px; flex-wrap:wrap; }
.map-summary-item { min-width:92px; padding:8px 10px; border:1px solid var(--border); border-radius:6px; background:var(--card-bg); }
.map-summary-item strong { display:block; font-size:18px; line-height:1.1; color:var(--primary); }
.map-summary-item span { display:block; margin-top:3px; font-size:11px; color:var(--text-muted); text-transform:uppercase; }
.map-layout { display:grid; grid-template-columns:minmax(0,1fr) 320px; grid-template-rows:1fr; gap:16px; min-height:0; flex:1; }
#map-container { position:relative; width:100%; height:100%; border:1px solid var(--border); border-radius:8px; overflow:hidden; background:#101312; }
#map-container .leaflet-container { background:#101312; width:100% !important; height:100% !important; }
.map-panel { min-height:0; overflow:auto; border:1px solid var(--border); border-radius:8px; background:var(--card-bg); display:flex; flex-direction:column; }
.panel-section { padding:14px; border-bottom:1px solid var(--border); }
.panel-section:last-child { border-bottom:0; }
.panel-title { margin:0 0 10px; font-size:12px; color:var(--text-muted); text-transform:uppercase; letter-spacing:0; }
.map-choice { display:block; width:100%; padding:10px; margin-bottom:8px; border:1px solid var(--border); border-radius:6px; background:var(--bg); color:var(--text); text-align:left; cursor:pointer; }
.map-choice:hover { border-color:var(--primary); }
.map-choice.active { border-color:var(--primary); box-shadow:inset 3px 0 0 var(--primary); }
.map-choice strong { font-size:13px; display:block; }
.map-choice .counts { font-size:11px; color:var(--text-muted); margin-top:2px; }
.map-toggle { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:7px 0; font-size:13px; }
.map-toggle input { accent-color:var(--primary); }
.legend-dot { display:inline-block; width:10px; height:10px; margin-right:7px; border-radius:999px; border:1px solid #fff; vertical-align:middle; }
.legend-dot.player { background:#e7c65b; }
.legend-dot.vehicle { background:#45a3ff; }
.legend-dot.base { background:#54c878; }
.search-box { width:100%; padding:8px 10px; border:1px solid var(--border); border-radius:6px; background:var(--bg); color:var(--text); font-size:13px; box-sizing:border-box; }
.search-box::placeholder { color:var(--text-muted); }
.location-list { display:flex; flex-direction:column; gap:4px; max-height:350px; overflow:auto; }
.location-item { display:grid; grid-template-columns:1fr auto; gap:2px 8px; padding:7px 8px; border:1px solid var(--border); border-radius:6px; background:var(--bg); color:var(--text); text-align:left; cursor:pointer; font-size:12px; }
.location-item:hover, .location-item.active { border-color:var(--primary); }
.location-item strong { font-size:11px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.location-item .meta { font-size:10px; color:var(--text-muted); }
.leaflet-tooltip.marker-tooltip { font-size:11px; padding:4px 8px; border-radius:4px; background:rgba(0,0,0,0.85); border:none; color:#fff; }
.leaflet-tooltip.marker-tooltip::before { border-top-color:rgba(0,0,0,0.85); }
.map-credit { position:absolute; bottom:4px; right:8px; z-index:1000; font-size:11px; color:var(--text-muted); background:rgba(0,0,0,0.7); padding:4px 10px; border-radius:4px; pointer-events:auto; }
.map-credit a { color:var(--primary); text-decoration:none; }
.map-credit a:hover { text-decoration:underline; }
.map-notice { background:rgba(234,179,8,0.1); border:1px solid rgba(234,179,8,0.4); border-left:4px solid #eab308; border-radius:6px; padding:10px 14px; font-size:13px; color:var(--text); line-height:1.5; flex-shrink:0; }
@media (max-width:980px) {
.map-page { height:auto; }
.map-layout { grid-template-columns:1fr; }
#map-container { height:64vh; }
}
</style>
{% endblock %}
{% block content %}
<div class="map-page">
<div class="map-header">
<h2>World Map</h2>
<div class="map-summary">
<div class="map-summary-item"><strong id="summary-players">0</strong><span>Players</span></div>
<div class="map-summary-item"><strong id="summary-vehicles">0</strong><span>Vehicles</span></div>
<div class="map-summary-item"><strong id="summary-bases">0</strong><span>Bases</span></div>
</div>
</div>
<div class="map-notice">
&#9888; This page is still a work in progress - expect bugs and quirks. Base ownership names are inferred heuristically and may be inaccurate.
</div>
<div class="map-layout">
<div id="map-container">
<div class="map-credit">Map images sourced from <a href="https://awakening.wiki/" target="_blank" rel="noopener">awakening.wiki</a> — a massive thank you for their incredible work mapping Arrakis!</div>
</div>
<aside class="map-panel">
<section class="panel-section">
<h3 class="panel-title">Map</h3>
<div id="map-choices"></div>
</section>
<section class="panel-section">
<h3 class="panel-title">Assets</h3>
<label class="map-toggle"><span><i class="legend-dot player"></i>Players</span><input type="checkbox" data-type="player" checked></label>
<label class="map-toggle"><span><i class="legend-dot vehicle"></i>Vehicles</span><input type="checkbox" data-type="vehicle" checked></label>
<label class="map-toggle"><span><i class="legend-dot base"></i>Bases</span><input type="checkbox" data-type="base" checked></label>
</section>
<section class="panel-section">
<h3 class="panel-title">Search</h3>
<input type="text" class="search-box" id="search-input" placeholder="Filter by name, type, or ID...">
</section>
<section class="panel-section" style="flex:1;min-height:0;display:flex;flex-direction:column;">
<h3 class="panel-title">Visible (<span id="list-count">0</span>)</h3>
<div class="location-list" id="location-list" style="flex:1;max-height:none;"></div>
</section>
</aside>
</div>
</div>
{% endblock %}
{% block scripts %}
<script id="leaflet-src" src="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.js"></script>
<script>if (typeof L === 'undefined') { document.getElementById('map-container').innerHTML = '<div style="display:flex;align-items:center;justify-content:center;height:100%;color:var(--text-muted);padding:40px;text-align:center"><div><h3>Map library failed to load</h3><p>Check network connectivity or refresh the page.</p></div></div>'; }</script>
<script src="https://cdn.jsdelivr.net/npm/leaflet.markercluster@1.5.3/dist/leaflet.markercluster.js"></script>
<script>
const mapOptions = {{ map_options|tojson }};
const allMarkers = [
...{{ players|tojson }},
...{{ vehicles|tojson }},
...{{ buildings|tojson }}
];
const mapImageUrls = {
{% for map in map_options %}
"{{ map.key }}": "{{ url_for('static', filename=map.image) }}"{% if not loop.last %},{% endif %}
{% endfor %}
};
let currentMap = "{{ default_map }}";
let mapInstance = null;
let markerClusterGroup = null;
let allLayers = { player: [], vehicle: [], base: [] };
let activeMarkerId = null;
let searchQuery = '';
const enabledTypes = { player: true, vehicle: true, base: true };
const typeColors = { player: '#e7c65b', vehicle: '#45a3ff', base: '#54c878' };
function markerKey(m) { return `${m.type}-${m.id}`; }
function markerLabel(m) {
if (m.type === 'player') return m.name || `Player ${m.id}`;
if (m.type === 'vehicle') {
const className = m.class || m.name || `Vehicle ${m.id}`;
return className;
}
if (m.type === 'base') return m.name || m.class || `Base ${m.id}`;
return m.name || m.class || '';
}
function escapeHtml(v) {
return String(v ?? '').replace(/[&<>"']/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
}
function selectedMapConfig() {
return mapOptions.find(m => m.key === currentMap) || mapOptions[0] || null;
}
function markersForCurrentMap() {
return allMarkers.filter(m => m.map === currentMap && m.in_bounds && enabledTypes[m.type]);
}
function initMap() {
const cfg = selectedMapConfig();
if (!cfg) return;
if (mapInstance) {
mapInstance.remove();
mapInstance = null;
}
mapInstance = L.map('map-container', {
crs: L.CRS.Simple,
zoomControl: true,
zoomSnap: 0.5,
zoomDelta: 1,
minZoom: -4,
maxZoom: 5,
renderer: L.canvas({ padding: 0.5 }),
attributionControl: false,
});
var overlayBounds = [[-cfg.height, 0], [0, cfg.width]];
L.imageOverlay(mapImageUrls[cfg.key] || '', overlayBounds).addTo(mapInstance);
mapInstance.fitBounds(overlayBounds, { padding: [0, 0] });
mapInstance.setMinZoom(mapInstance.getZoom());
mapInstance.setMaxBounds(overlayBounds);
markerClusterGroup = (typeof L.markerClusterGroup !== 'undefined')
? L.markerClusterGroup({
chunkedLoading: true,
maxClusterRadius: 5,
spiderfyOnMaxZoom: true,
showCoverageOnHover: false,
iconCreateFunction: function(cluster) {
var count = cluster.getChildCount();
return L.divIcon({
html: '<div style="background:rgba(231,198,91,0.88);border:2px solid #fff;border-radius:999px;width:34px;height:34px;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:13px;color:#111">' + count + '</div>',
className: '',
iconSize: L.point(34, 34),
});
}
})
: L.layerGroup();
mapInstance.addLayer(markerClusterGroup);
mapInstance.whenReady(function() { mapInstance.invalidateSize(); });
renderAllMarkers();
}
function createMarker(m) {
const color = typeColors[m.type] || '#888';
const py = m.py ?? 0;
const px = m.px ?? 0;
const marker = L.circleMarker([-py, px], {
radius: 6,
fillColor: color,
color: '#fff',
weight: 1.5,
fillOpacity: 0.88,
bubblingMouseEvents: false,
});
const label = markerLabel(m);
let tooltipHtml = `<strong>${escapeHtml(m.type.toUpperCase())}</strong>: ${escapeHtml(label)}`;
tooltipHtml += `<br>${Number(m.x).toFixed(0)}, ${Number(m.y).toFixed(0)}`;
marker.bindTooltip(tooltipHtml,
{ direction: 'top', offset: [0, -8], className: 'marker-tooltip' }
);
marker.on('click', function() { selectMarker(markerKey(m)); });
marker._dune = { data: m, key: markerKey(m) };
return marker;
}
function renderAllMarkers() {
markerClusterGroup.clearLayers();
allLayers = { player: [], vehicle: [], base: [] };
markersForCurrentMap().forEach(m => {
if (!searchQuery || matchesSearch(m)) {
const layer = createMarker(m);
allLayers[m.type].push(layer);
markerClusterGroup.addLayer(layer);
}
});
updateSummary();
renderList();
}
function matchesSearch(m) {
if (!searchQuery) return true;
const q = searchQuery.toLowerCase();
const label = markerLabel(m).toLowerCase();
return label.includes(q) || m.type.includes(q) || String(m.id).includes(q);
}
function updateSummary() {
document.getElementById('summary-players').textContent = allLayers.player.length;
document.getElementById('summary-vehicles').textContent = allLayers.vehicle.length;
document.getElementById('summary-bases').textContent = allLayers.base.length;
}
function selectMarker(key) {
activeMarkerId = key;
const m = allMarkers.find(c => markerKey(c) === key);
if (!m || !mapInstance) return;
mapInstance.setView([-(m.py ?? 0), m.px ?? 0], Math.max(mapInstance.getZoom(), 2), { animate: true });
renderList();
const listEl = document.getElementById('location-list');
const item = listEl.querySelector(`[data-marker-key="${key}"]`);
if (item) {
item.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
}
function renderList() {
const list = document.getElementById('location-list');
const countEl = document.getElementById('list-count');
const items = [];
for (const [type, layers] of Object.entries(allLayers)) {
for (const layer of layers) {
const m = layer._dune && layer._dune.data;
if (!m || (searchQuery && !matchesSearch(m))) continue;
items.push({ m, type });
}
}
items.sort((a, b) => a.type.localeCompare(b.type) || markerLabel(a.m).localeCompare(markerLabel(b.m)));
countEl.textContent = items.length;
list.innerHTML = '';
if (!items.length) {
const empty = document.createElement('div');
empty.className = 'location-item';
empty.innerHTML = '<strong>No matching assets</strong>';
list.appendChild(empty);
return;
}
items.forEach(({ m, type }) => {
const key = markerKey(m);
const label = escapeHtml(markerLabel(m));
const item = document.createElement('div');
item.className = `location-item${activeMarkerId === key ? ' active' : ''}`;
item.dataset.markerKey = key;
item.innerHTML = `
<strong><i class="legend-dot ${type}"></i>${label}</strong>
<span class="meta">${type}</span>
<span class="meta">${Number(m.x).toFixed(0)}, ${Number(m.y).toFixed(0)}</span>
`;
item.addEventListener('click', () => selectMarker(key));
list.appendChild(item);
});
}
function switchMap(mapKey) {
currentMap = mapKey;
activeMarkerId = null;
initMap();
renderChoices();
}
function renderChoices() {
const container = document.getElementById('map-choices');
container.innerHTML = '';
const sorted = [...mapOptions].sort((a, b) => {
if (a.key === 'HaggaBasin') return -1;
if (b.key === 'HaggaBasin') return 1;
return 0;
});
sorted.forEach(map => {
const btn = document.createElement('button');
btn.className = `map-choice${map.key === currentMap ? ' active' : ''}`;
btn.innerHTML = `<strong>${escapeHtml(map.label)}</strong><span class="counts">${map.counts.players}P / ${map.counts.vehicles}V / ${map.counts.bases}B</span>`;
btn.addEventListener('click', () => switchMap(map.key));
container.appendChild(btn);
});
}
document.querySelectorAll('[data-type]').forEach(input => {
input.addEventListener('change', function() {
enabledTypes[this.dataset.type] = this.checked;
activeMarkerId = null;
renderAllMarkers();
});
});
document.getElementById('search-input').addEventListener('input', function() {
searchQuery = this.value.trim();
renderAllMarkers();
});
renderChoices();
setTimeout(() => { initMap(); }, 100);
</script>
{% endblock %}