Реализована подложка на leaflet
649
client/app.js
|
|
@ -5,9 +5,19 @@
|
|||
const RECONNECT_DELAY_MS = 2000;
|
||||
const REQUEST_TIMEOUT_MS = 5000;
|
||||
const SOCKET_CONNECT_TIMEOUT_MS = 5000;
|
||||
const CANVAS_PADDING = 36;
|
||||
const GRID_STEP_METERS = 2;
|
||||
|
||||
const START_POINT = { x: -55.0, y: 27.0 };
|
||||
const PLAN_MIN_X = -139.3;
|
||||
const PLAN_MAX_X = -49.3;
|
||||
const PLAN_MIN_Y = 23;
|
||||
const PLAN_MAX_Y = 113;
|
||||
const PLAN_IMAGE_WIDTH = 8640;
|
||||
const PLAN_IMAGE_HEIGHT = 8632;
|
||||
const PLAN_TILE_SIZE = 256;
|
||||
const PLAN_MIN_ZOOM = -6;
|
||||
const PLAN_MAX_NATIVE_ZOOM = 6;
|
||||
const PLAN_TILE_TEMPLATE = "assets/plan_tiles/{z}/{x}/{y}.png";
|
||||
const PLAN_OVERLAY_URL = "assets/plan_overlay.png";
|
||||
|
||||
const elements = {
|
||||
apiBaseInput: document.getElementById("api-base-input"),
|
||||
|
|
@ -19,15 +29,8 @@
|
|||
sidebarMeta: document.getElementById("sidebar-meta"),
|
||||
selectedObjectTitle: document.getElementById("selected-object-title"),
|
||||
selectedObjectWifi: document.getElementById("selected-object-wifi"),
|
||||
bssidFilterMeta: document.getElementById("bssid-filter-meta"),
|
||||
bssidFilterToggle: document.getElementById("bssid-filter-toggle"),
|
||||
bssidFilterMenu: document.getElementById("bssid-filter-menu"),
|
||||
bssidFilterSearch: document.getElementById("bssid-filter-search"),
|
||||
bssidFilterSelectAll: document.getElementById("bssid-filter-select-all"),
|
||||
bssidFilterClear: document.getElementById("bssid-filter-clear"),
|
||||
bssidFilterOptions: document.getElementById("bssid-filter-options"),
|
||||
objectList: document.getElementById("object-list"),
|
||||
mapCanvas: document.getElementById("map-canvas"),
|
||||
mapRoot: document.getElementById("map-root"),
|
||||
canvasEmptyState: document.getElementById("canvas-empty-state"),
|
||||
};
|
||||
|
||||
|
|
@ -40,50 +43,132 @@
|
|||
liveById: new Map(),
|
||||
historyById: new Map(),
|
||||
bssidLocations: [],
|
||||
bssidFilterSearch: "",
|
||||
selectedSsids: new Set(),
|
||||
isBssidFilterMenuOpen: false,
|
||||
selectedObjectId: null,
|
||||
socket: null,
|
||||
renderTimerId: null,
|
||||
reconnectTimerId: null,
|
||||
socketConnectTimerId: null,
|
||||
resizeObserver: null,
|
||||
map: null,
|
||||
objectLayer: null,
|
||||
tailLayer: null,
|
||||
originLayer: null,
|
||||
hasFittedPlanView: false,
|
||||
};
|
||||
|
||||
const planBounds = L.latLngBounds(
|
||||
L.latLng(0, 0),
|
||||
L.latLng(PLAN_IMAGE_HEIGHT, PLAN_IMAGE_WIDTH),
|
||||
);
|
||||
const planMaxBounds = L.latLngBounds(
|
||||
L.latLng(-240, -240),
|
||||
L.latLng(PLAN_IMAGE_HEIGHT + 240, PLAN_IMAGE_WIDTH + 240),
|
||||
);
|
||||
const planCrs = L.extend({}, L.CRS.Simple, {
|
||||
transformation: new L.Transformation(1, 0, 1, 0),
|
||||
infinite: false,
|
||||
});
|
||||
|
||||
function bootstrap() {
|
||||
ensureLeafletLoaded();
|
||||
elements.apiBaseInput.value = state.apiBase;
|
||||
elements.renderIntervalInput.value = String(state.renderIntervalMs);
|
||||
elements.tailLengthInput.value = String(state.tailLength);
|
||||
initializeMap();
|
||||
bindEvents();
|
||||
observeCanvasResize();
|
||||
observeMapResize();
|
||||
refreshConnectionBadge();
|
||||
restartRenderLoop();
|
||||
initializeDataFlow();
|
||||
}
|
||||
|
||||
function ensureLeafletLoaded() {
|
||||
if (!window.L) {
|
||||
throw new Error("Leaflet failed to load");
|
||||
}
|
||||
}
|
||||
|
||||
function initializeMap() {
|
||||
state.map = L.map(elements.mapRoot, {
|
||||
crs: planCrs,
|
||||
minZoom: PLAN_MIN_ZOOM,
|
||||
maxZoom: PLAN_MAX_NATIVE_ZOOM + 2,
|
||||
zoomSnap: 0.25,
|
||||
zoomDelta: 0.5,
|
||||
wheelPxPerZoomLevel: 90,
|
||||
attributionControl: false,
|
||||
maxBounds: planMaxBounds,
|
||||
maxBoundsViscosity: 0.9,
|
||||
preferCanvas: true,
|
||||
});
|
||||
|
||||
L.tileLayer(PLAN_TILE_TEMPLATE, {
|
||||
tileSize: PLAN_TILE_SIZE,
|
||||
minZoom: PLAN_MIN_ZOOM,
|
||||
minNativeZoom: 0,
|
||||
maxNativeZoom: PLAN_MAX_NATIVE_ZOOM,
|
||||
noWrap: true,
|
||||
bounds: planBounds,
|
||||
keepBuffer: 2,
|
||||
updateWhenIdle: true,
|
||||
}).addTo(state.map);
|
||||
|
||||
L.imageOverlay(PLAN_OVERLAY_URL, planBounds, {
|
||||
opacity: 1,
|
||||
interactive: false,
|
||||
zIndex: 1,
|
||||
}).addTo(state.map);
|
||||
|
||||
state.tailLayer = L.layerGroup().addTo(state.map);
|
||||
state.objectLayer = L.layerGroup().addTo(state.map);
|
||||
state.originLayer = L.layerGroup().addTo(state.map);
|
||||
|
||||
fitPlanBounds();
|
||||
window.requestAnimationFrame(() => {
|
||||
fitPlanBounds();
|
||||
});
|
||||
renderOriginMarker();
|
||||
}
|
||||
|
||||
function bindEvents() {
|
||||
elements.applySettingsButton.addEventListener("click", applySettings);
|
||||
elements.reconnectButton.addEventListener("click", () => {
|
||||
clearReconnectTimer();
|
||||
reconnectSocket(true);
|
||||
});
|
||||
elements.bssidFilterToggle.addEventListener("click", toggleBssidFilterMenu);
|
||||
elements.bssidFilterSearch.addEventListener("input", handleBssidFilterSearchInput);
|
||||
elements.bssidFilterSelectAll.addEventListener("click", selectAllVisibleSsids);
|
||||
elements.bssidFilterClear.addEventListener("click", clearSelectedSsids);
|
||||
document.addEventListener("click", handleDocumentClick);
|
||||
}
|
||||
|
||||
function observeCanvasResize() {
|
||||
state.resizeObserver = new ResizeObserver(() => resizeCanvasToDisplaySize());
|
||||
state.resizeObserver.observe(elements.mapCanvas);
|
||||
resizeCanvasToDisplaySize();
|
||||
function observeMapResize() {
|
||||
state.resizeObserver = new ResizeObserver(() => {
|
||||
if (state.map) {
|
||||
state.map.invalidateSize(false);
|
||||
if (!state.hasFittedPlanView) {
|
||||
fitPlanBounds();
|
||||
}
|
||||
}
|
||||
});
|
||||
state.resizeObserver.observe(elements.mapRoot);
|
||||
}
|
||||
|
||||
function fitPlanBounds() {
|
||||
if (!state.map) {
|
||||
return;
|
||||
}
|
||||
const size = state.map.getSize();
|
||||
if (size.x <= 0 || size.y <= 0) {
|
||||
state.hasFittedPlanView = false;
|
||||
return;
|
||||
}
|
||||
const zoom = state.map.getBoundsZoom(planBounds, false, L.point(48, 48));
|
||||
state.map.setView(planBounds.getCenter(), zoom, { animate: false });
|
||||
state.map.panInsideBounds(planBounds, { animate: false });
|
||||
state.hasFittedPlanView = true;
|
||||
}
|
||||
|
||||
async function initializeDataFlow() {
|
||||
const catalogLoaded = await loadCatalog();
|
||||
await loadBssidLocations();
|
||||
renderMap();
|
||||
if (!catalogLoaded) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -117,6 +202,7 @@
|
|||
state.selectedObjectId = nextCatalog.keys().next().value;
|
||||
}
|
||||
renderSidebar();
|
||||
renderMap();
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
|
@ -137,12 +223,10 @@
|
|||
.map((item) => normalizeBssidLocation(item))
|
||||
.filter((item) => item !== null)
|
||||
: [];
|
||||
syncSelectedSsidsWithCatalog();
|
||||
renderBssidFilter();
|
||||
renderMap();
|
||||
} catch (error) {
|
||||
state.bssidLocations = [];
|
||||
syncSelectedSsidsWithCatalog();
|
||||
renderBssidFilter();
|
||||
renderMap();
|
||||
console.warn("Failed to load BSSID locations", error);
|
||||
}
|
||||
}
|
||||
|
|
@ -225,6 +309,7 @@
|
|||
state.selectedObjectId = nextLiveById.keys().next().value;
|
||||
}
|
||||
renderSidebar();
|
||||
renderMap();
|
||||
}
|
||||
|
||||
function appendHistoryPoint(objectState) {
|
||||
|
|
@ -259,7 +344,6 @@
|
|||
const items = buildUiObjects();
|
||||
elements.sidebarMeta.textContent = items.length + " objects";
|
||||
renderSelectedObjectPanel(items);
|
||||
renderBssidFilter();
|
||||
if (items.length === 0) {
|
||||
elements.objectList.innerHTML = '<li class="object-row-empty">No catalog objects configured</li>';
|
||||
return;
|
||||
|
|
@ -272,13 +356,14 @@
|
|||
row.addEventListener("click", () => {
|
||||
state.selectedObjectId = item.objectId;
|
||||
renderSidebar();
|
||||
renderMap();
|
||||
});
|
||||
|
||||
const speedText = formatSpeed(item.speedMps);
|
||||
const coordText = item.location
|
||||
? "x: " + item.location.x.toFixed(1) + ", y: " + item.location.y.toFixed(1)
|
||||
: "No location";
|
||||
const wifiText = "BSSID: " + formatBssid(item.bssid) + " · RSSI: " + formatRssi(item.rssiDbm);
|
||||
const wifiText = "BSSID: " + formatBssid(item.bssid) + " В· RSSI: " + formatRssi(item.rssiDbm);
|
||||
|
||||
row.innerHTML =
|
||||
'<div class="object-row-main">' +
|
||||
|
|
@ -301,232 +386,128 @@
|
|||
const selected = items.find((item) => item.objectId === state.selectedObjectId) || null;
|
||||
if (!selected) {
|
||||
elements.selectedObjectTitle.textContent = "No object selected";
|
||||
elements.selectedObjectWifi.textContent = "BSSID: n/a · RSSI: n/a";
|
||||
elements.selectedObjectWifi.textContent = "BSSID: n/a В· RSSI: n/a";
|
||||
return;
|
||||
}
|
||||
elements.selectedObjectTitle.textContent = formatObjectLabel(selected) + " · " + selected.status;
|
||||
elements.selectedObjectTitle.textContent = formatObjectLabel(selected) + " В· " + selected.status;
|
||||
elements.selectedObjectWifi.textContent =
|
||||
"BSSID: " + formatBssid(selected.bssid) + " · RSSI: " + formatRssi(selected.rssiDbm);
|
||||
"BSSID: " + formatBssid(selected.bssid) + " В· RSSI: " + formatRssi(selected.rssiDbm);
|
||||
}
|
||||
|
||||
function restartRenderLoop() {
|
||||
if (state.renderTimerId !== null) {
|
||||
window.clearInterval(state.renderTimerId);
|
||||
}
|
||||
state.renderTimerId = window.setInterval(renderCanvas, state.renderIntervalMs);
|
||||
renderCanvas();
|
||||
state.renderTimerId = window.setInterval(renderMap, state.renderIntervalMs);
|
||||
renderMap();
|
||||
}
|
||||
|
||||
function renderCanvas() {
|
||||
resizeCanvasToDisplaySize();
|
||||
|
||||
const canvas = elements.mapCanvas;
|
||||
const ctx = canvas.getContext("2d");
|
||||
const width = canvas.width;
|
||||
const height = canvas.height;
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
function renderMap() {
|
||||
if (!state.map) {
|
||||
return;
|
||||
}
|
||||
|
||||
const visibleObjects = buildUiObjects().filter((item) => item.location !== null);
|
||||
const visibleBssidLocations = getVisibleBssidLocations();
|
||||
const hasCanvasContent = visibleObjects.length > 0 || visibleBssidLocations.length > 0;
|
||||
elements.canvasEmptyState.hidden = hasCanvasContent;
|
||||
if (!hasCanvasContent) {
|
||||
return;
|
||||
}
|
||||
const hasLiveContent = visibleObjects.length > 0;
|
||||
elements.canvasEmptyState.hidden = hasLiveContent;
|
||||
|
||||
const bounds = computeBounds(visibleObjects, visibleBssidLocations);
|
||||
const project = createProjector(bounds, width, height);
|
||||
state.tailLayer.clearLayers();
|
||||
state.objectLayer.clearLayers();
|
||||
renderOriginMarker();
|
||||
|
||||
drawGrid(ctx, bounds, project, width, height);
|
||||
drawStartPointMarker(ctx, project);
|
||||
drawBssidLocations(ctx, project, visibleBssidLocations);
|
||||
drawTrajectories(ctx, visibleObjects, project);
|
||||
drawObjects(ctx, visibleObjects, project);
|
||||
renderTrajectories(visibleObjects);
|
||||
renderObjects(visibleObjects);
|
||||
}
|
||||
|
||||
function drawGrid(ctx, bounds, project, width, height) {
|
||||
ctx.save();
|
||||
ctx.strokeStyle = "#d9dfcf";
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
const minGridX = Math.floor(bounds.minX / GRID_STEP_METERS) * GRID_STEP_METERS;
|
||||
const maxGridX = Math.ceil(bounds.maxX / GRID_STEP_METERS) * GRID_STEP_METERS;
|
||||
const minGridY = Math.floor(bounds.minY / GRID_STEP_METERS) * GRID_STEP_METERS;
|
||||
const maxGridY = Math.ceil(bounds.maxY / GRID_STEP_METERS) * GRID_STEP_METERS;
|
||||
|
||||
for (let gridX = minGridX; gridX <= maxGridX; gridX += GRID_STEP_METERS) {
|
||||
const x = Math.round(project(gridX, 0).x) + 0.5;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x, 0);
|
||||
ctx.lineTo(x, height);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let gridY = minGridY; gridY <= maxGridY; gridY += GRID_STEP_METERS) {
|
||||
const y = Math.round(project(0, gridY).y) + 0.5;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, y);
|
||||
ctx.lineTo(width, y);
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
function renderOriginMarker() {
|
||||
state.originLayer.clearLayers();
|
||||
const marker = L.circleMarker(toLatLng(START_POINT.x, START_POINT.y), {
|
||||
radius: 5,
|
||||
color: "#1f291a",
|
||||
weight: 1.5,
|
||||
fillColor: "#1f291a",
|
||||
fillOpacity: 1,
|
||||
});
|
||||
marker.bindTooltip(
|
||||
'<div class="map-tooltip-title">(' +
|
||||
START_POINT.x.toFixed(1) +
|
||||
", " +
|
||||
START_POINT.y.toFixed(1) +
|
||||
")</div>",
|
||||
{
|
||||
permanent: true,
|
||||
direction: "right",
|
||||
offset: [10, 0],
|
||||
className: "map-tooltip map-tooltip-origin",
|
||||
},
|
||||
);
|
||||
marker.addTo(state.originLayer);
|
||||
}
|
||||
|
||||
function drawStartPointMarker(ctx, project) {
|
||||
const origin = project(START_POINT.x, START_POINT.y);
|
||||
const label = "(" + START_POINT.x.toFixed(1) + ", " + START_POINT.y.toFixed(1) + ")";
|
||||
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
ctx.arc(origin.x, origin.y, 5, 0, Math.PI * 2);
|
||||
ctx.fillStyle = "#1f291a";
|
||||
ctx.fill();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(origin.x - 10, origin.y);
|
||||
ctx.lineTo(origin.x + 10, origin.y);
|
||||
ctx.moveTo(origin.x, origin.y - 10);
|
||||
ctx.lineTo(origin.x, origin.y + 10);
|
||||
ctx.strokeStyle = "rgba(31, 41, 26, 0.65)";
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.stroke();
|
||||
|
||||
ctx.font = "12px Segoe UI, sans-serif";
|
||||
ctx.textBaseline = "middle";
|
||||
const textWidth = ctx.measureText(label).width;
|
||||
roundRect(ctx, origin.x + 10, origin.y - 18, textWidth + 10, 18, 7);
|
||||
ctx.fillStyle = "rgba(255, 255, 255, 0.9)";
|
||||
ctx.fill();
|
||||
ctx.fillStyle = "#1f291a";
|
||||
ctx.fillText(label, origin.x + 15, origin.y - 9);
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
function drawBssidLocations(ctx, project, locations) {
|
||||
if (locations.length === 0) {
|
||||
return;
|
||||
}
|
||||
ctx.save();
|
||||
ctx.font = "11px Segoe UI, sans-serif";
|
||||
ctx.textBaseline = "top";
|
||||
for (const location of locations) {
|
||||
const projected = project(location.x, location.y);
|
||||
const markerColor = trajectoryColorForBssid(location.bssid, false);
|
||||
const primaryLabel = formatSsid(location.ssid);
|
||||
const secondaryLabel = location.bssid;
|
||||
const textWidth = Math.max(
|
||||
ctx.measureText(primaryLabel).width,
|
||||
ctx.measureText(secondaryLabel).width
|
||||
);
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(projected.x, projected.y, 4, 0, Math.PI * 2);
|
||||
ctx.fillStyle = markerColor;
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.strokeStyle = "#ffffff";
|
||||
ctx.stroke();
|
||||
|
||||
roundRect(ctx, projected.x + 8, projected.y - 16, textWidth + 10, 32, 7);
|
||||
ctx.fillStyle = "rgba(255, 255, 255, 0.92)";
|
||||
ctx.fill();
|
||||
ctx.fillStyle = "#1f291a";
|
||||
ctx.fillText(primaryLabel, projected.x + 13, projected.y - 10);
|
||||
ctx.fillStyle = "#4f5b47";
|
||||
ctx.fillText(secondaryLabel, projected.x + 13, projected.y + 2);
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
function drawTrajectories(ctx, objects, project) {
|
||||
function renderTrajectories(objects) {
|
||||
for (const objectState of objects) {
|
||||
const history = state.historyById.get(objectState.objectId) || [];
|
||||
if (history.length < 2) {
|
||||
continue;
|
||||
}
|
||||
const selected = objectState.objectId === state.selectedObjectId;
|
||||
|
||||
ctx.save();
|
||||
for (let index = 1; index < history.length; index += 1) {
|
||||
const previousPoint = history[index - 1];
|
||||
const currentPoint = history[index];
|
||||
const previousProjected = project(previousPoint.x, previousPoint.y);
|
||||
const currentProjected = project(currentPoint.x, currentPoint.y);
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(previousProjected.x, previousProjected.y);
|
||||
ctx.lineTo(currentProjected.x, currentProjected.y);
|
||||
ctx.strokeStyle = trajectoryColorForBssid(currentPoint.bssid, selected);
|
||||
ctx.lineWidth = selected ? 3 : 1.5;
|
||||
ctx.stroke();
|
||||
const latLngs = history.map((point) => toLatLng(point.x, point.y));
|
||||
const polyline = L.polyline(latLngs, {
|
||||
color: trajectoryColorForBssid(objectState.bssid, selected),
|
||||
weight: selected ? 4 : 2,
|
||||
opacity: selected ? 0.95 : 0.6,
|
||||
lineCap: "round",
|
||||
lineJoin: "round",
|
||||
});
|
||||
polyline.addTo(state.tailLayer);
|
||||
if (selected) {
|
||||
polyline.bringToFront();
|
||||
}
|
||||
|
||||
ctx.fillStyle = selected ? "#384331" : "#56624d";
|
||||
ctx.font = selected ? "11px Segoe UI, sans-serif" : "10px Segoe UI, sans-serif";
|
||||
ctx.textBaseline = "bottom";
|
||||
for (const point of history) {
|
||||
if (typeof point.rssiDbm !== "number") {
|
||||
continue;
|
||||
}
|
||||
const projected = project(point.x, point.y);
|
||||
drawRssiTag(ctx, projected.x + 6, projected.y - 6, formatRssiShort(point.rssiDbm), selected);
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
function drawObjects(ctx, objects, project) {
|
||||
ctx.font = "12px Segoe UI, sans-serif";
|
||||
ctx.textBaseline = "middle";
|
||||
function renderObjects(objects) {
|
||||
for (const objectState of objects) {
|
||||
const selected = objectState.objectId === state.selectedObjectId;
|
||||
const projected = project(objectState.location.x, objectState.location.y);
|
||||
const markerColor = markerColorForStatus(objectState.status);
|
||||
const speedText = formatSpeed(objectState.speedMps);
|
||||
const primaryLabel = formatObjectLabel(objectState) + " · " + speedText;
|
||||
const secondaryLabel = "BSSID " + formatBssid(objectState.bssid) + " · RSSI " + formatRssi(objectState.rssiDbm);
|
||||
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
ctx.arc(projected.x, projected.y, selected ? 8 : 6, 0, Math.PI * 2);
|
||||
ctx.fillStyle = markerColor;
|
||||
ctx.fill();
|
||||
ctx.lineWidth = selected ? 3 : 2;
|
||||
ctx.strokeStyle = selected ? "#0b6f55" : "#ffffff";
|
||||
ctx.stroke();
|
||||
|
||||
const textX = projected.x + 12;
|
||||
const textY = projected.y - 18;
|
||||
const primaryWidth = ctx.measureText(primaryLabel).width;
|
||||
const secondaryWidth = selected ? ctx.measureText(secondaryLabel).width : 0;
|
||||
const textWidth = Math.max(primaryWidth, secondaryWidth);
|
||||
const boxHeight = selected ? 38 : 20;
|
||||
ctx.fillStyle = selected ? "rgba(11, 111, 85, 0.16)" : "rgba(255, 255, 255, 0.84)";
|
||||
roundRect(ctx, textX - 6, textY - 10, textWidth + 12, boxHeight, 8);
|
||||
ctx.fill();
|
||||
|
||||
ctx.fillStyle = "#1f291a";
|
||||
ctx.fillText(primaryLabel, textX, selected ? textY : textY + 8);
|
||||
const marker = L.circleMarker(toLatLng(objectState.location.x, objectState.location.y), {
|
||||
radius: selected ? 8 : 6,
|
||||
color: selected ? "#0b6f55" : "#ffffff",
|
||||
weight: selected ? 3 : 2,
|
||||
fillColor: markerColorForStatus(objectState.status),
|
||||
fillOpacity: 0.95,
|
||||
});
|
||||
marker.on("click", () => {
|
||||
state.selectedObjectId = objectState.objectId;
|
||||
renderSidebar();
|
||||
renderMap();
|
||||
});
|
||||
marker.bindTooltip(buildObjectTooltipHtml(objectState, selected), {
|
||||
permanent: true,
|
||||
direction: "right",
|
||||
offset: [12, selected ? -6 : -2],
|
||||
className: "map-tooltip map-tooltip-object" + (selected ? " is-selected" : ""),
|
||||
});
|
||||
marker.addTo(state.objectLayer);
|
||||
if (selected) {
|
||||
ctx.fillStyle = "#4f5b47";
|
||||
ctx.fillText(secondaryLabel, textX, textY + 16);
|
||||
marker.bringToFront();
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
function drawRssiTag(ctx, x, y, text, selected) {
|
||||
const textWidth = ctx.measureText(text).width;
|
||||
const paddingX = 4;
|
||||
const height = selected ? 16 : 14;
|
||||
const top = y - height + 2;
|
||||
ctx.save();
|
||||
roundRect(ctx, x - paddingX, top, textWidth + paddingX * 2, height, 6);
|
||||
ctx.fillStyle = selected ? "rgba(255, 252, 244, 0.96)" : "rgba(255, 255, 255, 0.92)";
|
||||
ctx.fill();
|
||||
ctx.fillStyle = selected ? "#384331" : "#56624d";
|
||||
ctx.fillText(text, x, y);
|
||||
ctx.restore();
|
||||
function buildObjectTooltipHtml(objectState, selected) {
|
||||
const primaryLabel = formatObjectLabel(objectState) + " В· " + formatSpeed(objectState.speedMps);
|
||||
if (!selected) {
|
||||
return '<div class="map-tooltip-title">' + escapeHtml(primaryLabel) + "</div>";
|
||||
}
|
||||
const secondaryLabel =
|
||||
"BSSID " + formatBssid(objectState.bssid) + " В· RSSI " + formatRssi(objectState.rssiDbm);
|
||||
return (
|
||||
'<div class="map-tooltip-title">' +
|
||||
escapeHtml(primaryLabel) +
|
||||
'</div><div class="map-tooltip-meta">' +
|
||||
escapeHtml(secondaryLabel) +
|
||||
"</div>"
|
||||
);
|
||||
}
|
||||
|
||||
function buildUiObjects() {
|
||||
|
|
@ -576,61 +557,6 @@
|
|||
return distanceMeters / (deltaTimeMs / 1000);
|
||||
}
|
||||
|
||||
function computeBounds(objects, bssidLocations) {
|
||||
let minX = START_POINT.x;
|
||||
let minY = START_POINT.y;
|
||||
let maxX = START_POINT.x;
|
||||
let maxY = START_POINT.y;
|
||||
|
||||
for (const bssidLocation of bssidLocations) {
|
||||
minX = Math.min(minX, bssidLocation.x);
|
||||
minY = Math.min(minY, bssidLocation.y);
|
||||
maxX = Math.max(maxX, bssidLocation.x);
|
||||
maxY = Math.max(maxY, bssidLocation.y);
|
||||
}
|
||||
|
||||
for (const objectState of objects) {
|
||||
const history = state.historyById.get(objectState.objectId) || [];
|
||||
for (const point of history) {
|
||||
minX = Math.min(minX, point.x);
|
||||
minY = Math.min(minY, point.y);
|
||||
maxX = Math.max(maxX, point.x);
|
||||
maxY = Math.max(maxY, point.y);
|
||||
}
|
||||
minX = Math.min(minX, objectState.location.x);
|
||||
minY = Math.min(minY, objectState.location.y);
|
||||
maxX = Math.max(maxX, objectState.location.x);
|
||||
maxY = Math.max(maxY, objectState.location.y);
|
||||
}
|
||||
|
||||
if (minX === maxX) {
|
||||
minX -= 1;
|
||||
maxX += 1;
|
||||
}
|
||||
if (minY === maxY) {
|
||||
minY -= 1;
|
||||
maxY += 1;
|
||||
}
|
||||
return { minX, minY, maxX, maxY };
|
||||
}
|
||||
|
||||
function createProjector(bounds, width, height) {
|
||||
const drawableWidth = Math.max(width - CANVAS_PADDING * 2, 1);
|
||||
const drawableHeight = Math.max(height - CANVAS_PADDING * 2, 1);
|
||||
const spanX = bounds.maxX - bounds.minX;
|
||||
const spanY = bounds.maxY - bounds.minY;
|
||||
const scale = Math.min(drawableWidth / spanX, drawableHeight / spanY);
|
||||
const offsetX = (width - spanX * scale) / 2;
|
||||
const offsetY = (height - spanY * scale) / 2;
|
||||
|
||||
return function project(x, y) {
|
||||
return {
|
||||
x: offsetX + (x - bounds.minX) * scale,
|
||||
y: height - (offsetY + (y - bounds.minY) * scale),
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function applySettings() {
|
||||
const nextApiBase = normalizeApiBase(elements.apiBaseInput.value);
|
||||
const nextRenderInterval = clampInteger(elements.renderIntervalInput.value, 100, 60_000, DEFAULT_RENDER_INTERVAL_MS);
|
||||
|
|
@ -654,6 +580,7 @@
|
|||
});
|
||||
} else {
|
||||
renderSidebar();
|
||||
renderMap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -665,17 +592,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
function resizeCanvasToDisplaySize() {
|
||||
const canvas = elements.mapCanvas;
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const width = Math.max(Math.round(rect.width), 1);
|
||||
const height = Math.max(Math.round(rect.height), 1);
|
||||
if (canvas.width !== width || canvas.height !== height) {
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
function markerColorForStatus(status) {
|
||||
switch (status) {
|
||||
case "online":
|
||||
|
|
@ -691,10 +607,10 @@
|
|||
|
||||
function trajectoryColorForBssid(bssid, selected) {
|
||||
if (typeof bssid !== "string" || bssid.trim() === "") {
|
||||
return selected ? "rgba(11, 111, 85, 0.95)" : "rgba(39, 89, 181, 0.28)";
|
||||
return selected ? "rgba(11, 111, 85, 0.95)" : "rgba(39, 89, 181, 0.45)";
|
||||
}
|
||||
const hue = hashStringToHue(bssid);
|
||||
const alpha = selected ? 0.95 : 0.5;
|
||||
const alpha = selected ? 0.95 : 0.55;
|
||||
const lightness = selected ? 38 : 48;
|
||||
return "hsla(" + hue + ", 72%, " + lightness + "%, " + alpha + ")";
|
||||
}
|
||||
|
|
@ -727,10 +643,6 @@
|
|||
return typeof rssiDbm === "number" ? rssiDbm.toFixed(0) + " dBm" : "n/a";
|
||||
}
|
||||
|
||||
function formatRssiShort(rssiDbm) {
|
||||
return typeof rssiDbm === "number" ? rssiDbm.toFixed(0) : "";
|
||||
}
|
||||
|
||||
function normalizeBssidLocation(item) {
|
||||
if (!item || typeof item.bssid !== "string") {
|
||||
return null;
|
||||
|
|
@ -748,143 +660,6 @@
|
|||
};
|
||||
}
|
||||
|
||||
function renderBssidFilter() {
|
||||
const options = getBssidFilterOptions();
|
||||
const visibleOptions = getVisibleBssidFilterOptions(options);
|
||||
const selectedCount = state.selectedSsids.size;
|
||||
|
||||
elements.bssidFilterMeta.textContent = selectedCount > 0
|
||||
? selectedCount + " selected"
|
||||
: "All SSID";
|
||||
elements.bssidFilterToggle.textContent = selectedCount > 0
|
||||
? "SSID: " + selectedCount + " selected"
|
||||
: "Select SSID";
|
||||
elements.bssidFilterToggle.setAttribute("aria-expanded", String(state.isBssidFilterMenuOpen));
|
||||
elements.bssidFilterMenu.hidden = !state.isBssidFilterMenuOpen;
|
||||
if (elements.bssidFilterSearch.value !== state.bssidFilterSearch) {
|
||||
elements.bssidFilterSearch.value = state.bssidFilterSearch;
|
||||
}
|
||||
|
||||
if (visibleOptions.length === 0) {
|
||||
elements.bssidFilterOptions.innerHTML = '<div class="filter-option-empty">No SSID found</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
const fragment = document.createDocumentFragment();
|
||||
for (const option of visibleOptions) {
|
||||
const label = document.createElement("label");
|
||||
label.className = "filter-option";
|
||||
|
||||
const checkbox = document.createElement("input");
|
||||
checkbox.type = "checkbox";
|
||||
checkbox.checked = state.selectedSsids.has(option.ssid);
|
||||
checkbox.addEventListener("change", () => toggleSsidSelection(option.ssid));
|
||||
|
||||
const textWrap = document.createElement("div");
|
||||
textWrap.className = "filter-option-text";
|
||||
|
||||
const title = document.createElement("div");
|
||||
title.className = "filter-option-title";
|
||||
title.textContent = option.ssid;
|
||||
|
||||
const meta = document.createElement("div");
|
||||
meta.className = "filter-option-meta";
|
||||
meta.textContent = option.count + " BSSID";
|
||||
|
||||
textWrap.appendChild(title);
|
||||
textWrap.appendChild(meta);
|
||||
label.appendChild(checkbox);
|
||||
label.appendChild(textWrap);
|
||||
fragment.appendChild(label);
|
||||
}
|
||||
elements.bssidFilterOptions.replaceChildren(fragment);
|
||||
}
|
||||
|
||||
function toggleBssidFilterMenu() {
|
||||
state.isBssidFilterMenuOpen = !state.isBssidFilterMenuOpen;
|
||||
renderBssidFilter();
|
||||
if (state.isBssidFilterMenuOpen) {
|
||||
window.setTimeout(() => elements.bssidFilterSearch.focus(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
function handleDocumentClick(event) {
|
||||
if (!state.isBssidFilterMenuOpen) {
|
||||
return;
|
||||
}
|
||||
if (event.target.closest(".filter-panel")) {
|
||||
return;
|
||||
}
|
||||
state.isBssidFilterMenuOpen = false;
|
||||
renderBssidFilter();
|
||||
}
|
||||
|
||||
function handleBssidFilterSearchInput(event) {
|
||||
state.bssidFilterSearch = event.target.value;
|
||||
renderBssidFilter();
|
||||
}
|
||||
|
||||
function toggleSsidSelection(ssid) {
|
||||
if (state.selectedSsids.has(ssid)) {
|
||||
state.selectedSsids.delete(ssid);
|
||||
} else {
|
||||
state.selectedSsids.add(ssid);
|
||||
}
|
||||
renderBssidFilter();
|
||||
renderCanvas();
|
||||
}
|
||||
|
||||
function selectAllVisibleSsids() {
|
||||
for (const option of getVisibleBssidFilterOptions(getBssidFilterOptions())) {
|
||||
state.selectedSsids.add(option.ssid);
|
||||
}
|
||||
renderBssidFilter();
|
||||
renderCanvas();
|
||||
}
|
||||
|
||||
function clearSelectedSsids() {
|
||||
state.selectedSsids.clear();
|
||||
renderBssidFilter();
|
||||
renderCanvas();
|
||||
}
|
||||
|
||||
function getBssidFilterOptions() {
|
||||
const countsBySsid = new Map();
|
||||
for (const location of state.bssidLocations) {
|
||||
const ssid = formatSsid(location.ssid);
|
||||
countsBySsid.set(ssid, (countsBySsid.get(ssid) || 0) + 1);
|
||||
}
|
||||
return Array.from(countsBySsid.entries())
|
||||
.map(([ssid, count]) => ({ ssid, count }))
|
||||
.sort((left, right) => left.ssid.localeCompare(right.ssid, "ru"));
|
||||
}
|
||||
|
||||
function getVisibleBssidFilterOptions(options) {
|
||||
const query = state.bssidFilterSearch.trim().toLocaleLowerCase("ru");
|
||||
if (query === "") {
|
||||
return options;
|
||||
}
|
||||
return options.filter((option) => option.ssid.toLocaleLowerCase("ru").includes(query));
|
||||
}
|
||||
|
||||
function getVisibleBssidLocations() {
|
||||
if (state.selectedSsids.size === 0) {
|
||||
return state.bssidLocations;
|
||||
}
|
||||
return state.bssidLocations.filter((location) => state.selectedSsids.has(formatSsid(location.ssid)));
|
||||
}
|
||||
|
||||
function syncSelectedSsidsWithCatalog() {
|
||||
const availableSsids = new Set(
|
||||
state.bssidLocations.map((location) => formatSsid(location.ssid))
|
||||
);
|
||||
for (const ssid of Array.from(state.selectedSsids)) {
|
||||
if (!availableSsids.has(ssid)) {
|
||||
state.selectedSsids.delete(ssid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setConnectionStatus(status) {
|
||||
state.connectionStatus = status;
|
||||
refreshConnectionBadge();
|
||||
|
|
@ -945,18 +720,12 @@
|
|||
return fallback;
|
||||
}
|
||||
|
||||
function roundRect(ctx, x, y, width, height, radius) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x + radius, y);
|
||||
ctx.lineTo(x + width - radius, y);
|
||||
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
||||
ctx.lineTo(x + width, y + height - radius);
|
||||
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
|
||||
ctx.lineTo(x + radius, y + height);
|
||||
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
|
||||
ctx.lineTo(x, y + radius);
|
||||
ctx.quadraticCurveTo(x, y, x + radius, y);
|
||||
ctx.closePath();
|
||||
function toLatLng(x, y) {
|
||||
const normalizedX = (x - PLAN_MIN_X) / (PLAN_MAX_X - PLAN_MIN_X);
|
||||
const normalizedY = (y - PLAN_MIN_Y) / (PLAN_MAX_Y - PLAN_MIN_Y);
|
||||
const pixelY = normalizedX * PLAN_IMAGE_HEIGHT;
|
||||
const pixelX = normalizedY * PLAN_IMAGE_WIDTH;
|
||||
return L.latLng(pixelY, pixelX);
|
||||
}
|
||||
|
||||
function normalizeApiBase(value) {
|
||||
|
|
|
|||
|
After Width: | Height: | Size: 1.1 MiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 993 B |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 6.2 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 9.4 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 8.7 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 7.4 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
After Width: | Height: | Size: 8.3 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 9.8 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |