fix markers update issue on load

This commit is contained in:
Azgaar 2021-11-30 22:15:33 +03:00
parent 19a8db4a17
commit 380575be5f

View file

@ -875,54 +875,58 @@ function parseLoadedData(data) {
// v 1.7 changed markers data // v 1.7 changed markers data
const defs = document.getElementById("defs-markers"); const defs = document.getElementById("defs-markers");
const markersGroup = document.getElementById("markers"); const markersGroup = document.getElementById("markers");
const markerElements = markersGroup.querySelectorAll("use");
const rescale = +markersGroup.getAttribute("rescale");
pack.markers = Array.from(markerElements).map((el, i) => { if (defs && markersGroup) {
const id = el.getAttribute("id"); const markerElements = markersGroup.querySelectorAll("use");
const note = notes.find(note => note.id === id); const rescale = +markersGroup.getAttribute("rescale");
if (note) note.id = `marker${i}`;
let x = +el.dataset.x; pack.markers = Array.from(markerElements).map((el, i) => {
let y = +el.dataset.y; const id = el.getAttribute("id");
const transform = el.getAttribute("transform"); const note = notes.find(note => note.id === id);
if (transform) { if (note) note.id = `marker${i}`;
const [dx, dy] = parseTransform(transform);
if (dx) x += +dx;
if (dy) y += +dy;
}
const cell = findCell(x, y);
const size = rn(rescale ? el.dataset.size * 30 : el.getAttribute("width"), 1);
const href = el.href.baseVal; let x = +el.dataset.x;
const type = href.replace("#marker_", ""); let y = +el.dataset.y;
const symbol = defs.querySelector(`symbol${href}`);
const text = symbol.querySelector("text");
const circle = symbol.querySelector("circle");
const icon = text.innerHTML; const transform = el.getAttribute("transform");
const px = Number(text.getAttribute("font-size")?.replace("px", "")); if (transform) {
const dx = Number(text.getAttribute("x")?.replace("%", "")); const [dx, dy] = parseTransform(transform);
const dy = Number(text.getAttribute("y")?.replace("%", "")); if (dx) x += +dx;
const fill = circle.getAttribute("fill"); if (dy) y += +dy;
const stroke = circle.getAttribute("stroke"); }
const cell = findCell(x, y);
const size = rn(rescale ? el.dataset.size * 30 : el.getAttribute("width"), 1);
const marker = {i, icon, type, x, y, size, cell}; const href = el.href.baseVal;
if (size && size !== 30) marker.size = size; const type = href.replace("#marker_", "");
if (!isNaN(px) && px !== 12) marker.px = px; const symbol = defs?.querySelector(`symbol${href}`);
if (!isNaN(dx) && dx !== 50) marker.dx = dx; const text = symbol?.querySelector("text");
if (!isNaN(dy) && dy !== 50) marker.dy = dy; const circle = symbol?.querySelector("circle");
if (fill && fill !== "#ffffff") marker.fill = fill;
if (stroke && stroke !== "#000000") marker.stroke = stroke;
if (circle.getAttribute("opacity") === "0") marker.pin = "no";
return marker; const icon = text?.innerHTML;
}); const px = text && Number(text.getAttribute("font-size")?.replace("px", ""));
const dx = text && Number(text.getAttribute("x")?.replace("%", ""));
const dy = text && Number(text.getAttribute("y")?.replace("%", ""));
const fill = circle && circle.getAttribute("fill");
const stroke = circle && circle.getAttribute("stroke");
markersGroup.style.display = null; const marker = {i, icon, type, x, y, size, cell};
defs?.remove(); if (size && size !== 30) marker.size = size;
markerElements.forEach(el => el.remove()); if (!isNaN(px) && px !== 12) marker.px = px;
if (layerIsOn("markers")) drawMarkers(); if (!isNaN(dx) && dx !== 50) marker.dx = dx;
if (!isNaN(dy) && dy !== 50) marker.dy = dy;
if (fill && fill !== "#ffffff") marker.fill = fill;
if (stroke && stroke !== "#000000") marker.stroke = stroke;
if (circle?.getAttribute("opacity") === "0") marker.pin = "no";
return marker;
});
markersGroup.style.display = null;
defs?.remove();
markerElements.forEach(el => el.remove());
if (layerIsOn("markers")) drawMarkers();
}
} }
})(); })();