markers - auto-update on load

This commit is contained in:
Azgaar 2021-09-28 21:47:54 +03:00
parent 0c18589140
commit ee582ddf45
2 changed files with 44 additions and 3 deletions

View file

@ -453,11 +453,11 @@ function saveGeoJSON_Markers() {
track("export", "getJSON markers"); track("export", "getJSON markers");
const features = pack.markers.map(marker => { const features = pack.markers.map(marker => {
const {i, type, icon, x, y, size, fill, stroke, size} = marker; const {i, type, icon, x, y, size, fill, stroke} = marker;
const coordinates = getQGIScoordinates(x, y); const coordinates = getQGIScoordinates(x, y);
const id = `marker${i}`; const id = `marker${i}`;
const note = notes.find(note => note.id === id); const note = notes.find(note => note.id === id);
const properties = {id, type, icon, ...note, size, fill, stroke, size}; const properties = {id, type, icon, ...note, size, fill, stroke};
return {type: "Feature", geometry: {type: "Point", coordinates}, properties}; return {type: "Feature", geometry: {type: "Point", coordinates}, properties};
}); });

View file

@ -872,7 +872,48 @@ function parseLoadedData(data) {
if (version < 1.7) { if (version < 1.7) {
// v 1.7 changed markers data // v 1.7 changed markers data
// TODO: get markers data from svg const defs = document.getElementById("defs-markers");
const markersGroup = document.getElementById("markers");
const markerElements = markersGroup.querySelectorAll("use");
pack.markers = Array.from(markerElements).map((el, i) => {
const id = el.getAttribute("id");
const note = notes.find(note => note.id === id);
if (note) note.id = `marker${i}`;
const x = rn(+el.dataset.x, 1);
const y = rn(+el.dataset.y, 1);
const cell = findCell(x, y);
const size = rn(el.dataset.size * 30, 1);
const href = el.href.baseVal;
const type = href.replace("#marker_", "");
const symbol = defs.querySelector(`symbol${href}`);
const text = symbol.querySelector("text");
const circle = symbol.querySelector("circle");
const icon = text.innerHTML;
const px = Number(text.getAttribute("font-size")?.replace("px", ""));
const dx = Number(text.getAttribute("x")?.replace("%", ""));
const dy = Number(text.getAttribute("y")?.replace("%", ""));
const fill = circle.getAttribute("fill");
const stroke = circle.getAttribute("stroke");
const marker = {i, icon, type, x, y, size, cell};
if (size && size !== 30) marker.size = size;
if (!isNaN(px) && px !== 12) marker.px = px;
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;
return marker;
});
markersGroup.style.display = null;
defs.remove();
markerElements.forEach(el => el.remove());
if (layerIsOn("markers")) drawMarkers();
} }
})(); })();