Create, Update

This commit is contained in:
Tomas Richtar 2025-07-10 21:04:42 +02:00
parent 4e8169a679
commit 89d137e577

View File

@ -1,11 +1,33 @@
import { getArrowPolygon } from "athena-utils/shape/Arrow.js"; import { getArrowPolygon } from "athena-utils/shape/Arrow.js";
import { ARROW_BODY_STYLE_CONSTANT, ARROW_BODY_STYLE_LINEAR, ARROW_BODY_STYLE_EXPONENTIAL } from "athena-utils/shape/Arrow.js"; import {  ARROW_BODY_STYLE_CONSTANT, ARROW_BODY_STYLE_LINEAR, ARROW_BODY_STYLE_EXPONENTIAL  } from "athena-utils/shape/Arrow.js";
import { getFrontline } from "athena-utils/shape/Frontline.js"; import { getFrontline } from "athena-utils/shape/Frontline.js";
import { LEFT_SIDE, RIGHT_SIDE, BOTH_SIDES } from "athena-utils/shape/Frontline.js"; import { LEFT_SIDE, RIGHT_SIDE, BOTH_SIDES } from "athena-utils/shape/Frontline.js";
const ARROW = "arrow"; const ARROW = "arrow";
const FRONTLINE = "frontline"; const FRONTLINE = "frontline";
const DEFAULT_ARROW_PARAMS = {
splineStep: 20,
offsetDistance: 12000,
calculation: ARROW_BODY_STYLE_LINEAR,
range: 1,
minValue: 0.1,
widthArrow: 5,
lengthArrow: 8
};
const DEFAULT_FRONTLINE_PARAMS = {
splineStep: 0.08,
offsetDistance: 10000,
style: LEFT_SIDE,
protrusion: {
length: 15000,
startSize: 5000,
endSize: 500,
gap: 15000
}
};
let currentFeature = null; let currentFeature = null;
let currentDrawStyle = ARROW; let currentDrawStyle = ARROW;
@ -47,7 +69,7 @@ const draw = new MapboxDraw({
{ {
id: 'gl-draw-line-inactive', id: 'gl-draw-line-inactive',
type: 'line', type: 'line',
filter: ['all', ['==', '$type', 'LineString'], ['==', 'active', 'false']], filter: ['all', ['==', '$type', 'LineString'], ['==', 'deactive', 'false']],
layout: { layout: {
'line-cap': 'round', 'line-cap': 'round',
'line-join': 'round' 'line-join': 'round'
@ -100,104 +122,13 @@ map.on('click', (e) => {
handleClick(e, ARROW, arrowParamsMap, showArrowEditor); handleClick(e, ARROW, arrowParamsMap, showArrowEditor);
handleClick(e, FRONTLINE, frontlineParamsMap, showFrontlineEditor); handleClick(e, FRONTLINE, frontlineParamsMap, showFrontlineEditor);
}); });
map.dragPan.enable();
function DrawArrow(coordinates, polygonId)
{
if (!arrowParamsMap.has(polygonId)) {
arrowParamsMap.set(polygonId, {
splineStep: 20,
offsetDistance: 12000,
calculation: ARROW_BODY_STYLE_LINEAR,
range: 1,
minValue: 0.1,
widthArrow: 5,
lengthArrow: 8
});
}
const params = arrowParamsMap.get(polygonId);
const arrowGeoJSON = getArrowPolygon(
{ points: coordinates, splineStep: params.splineStep, offsetDistance: params.offsetDistance },
{ calculation: params.calculation, range: params.range, minValue: params.minValue },
{ widthArrow: params.widthArrow, lengthArrow: params.lengthArrow }
);
const arrowLayerId = ARROW + "-" + polygonId;
if (map.getLayer(arrowLayerId)) map.removeLayer(arrowLayerId);
if (map.getSource(arrowLayerId)) map.removeSource(arrowLayerId);
drawArrowOnMap(arrowGeoJSON, ARROW + "-" + polygonId);
const allFeatures = draw.getAll().features;
currentFeature = allFeatures.find(f => f.polygonId === polygonId);
}
function DrawFrontline(coordinates, polygonId){
if (!frontlineParamsMap.has(polygonId)) {
frontlineParamsMap.set(polygonId, {
splineStep: 0.08,
offsetDistance: 10000,
style: LEFT_SIDE,
protrusion: {
length: 15000,
startSize: 5000,
endSize: 500,
gap: 15000
}
});
}
const params = frontlineParamsMap.get(polygonId);
const frontlineData = {
points: coordinates,
splineStep: params.splineStep,
offsetDistance: params.offsetDistance,
style: params.style
};
const protrusionData = params.protrusion;
const frontlineGeoJSON = getFrontline(frontlineData, protrusionData);
let polygonToDraw = frontlineGeoJSON;
if (frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly) {
polygonToDraw = frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly;
}
if(frontlineGeoJSON.leftPoly && frontlineGeoJSON.rightPoly){
let polygonToDrawLeft = frontlineGeoJSON.leftPoly;
let polygonToDrawRight = frontlineGeoJSON.rightPoly;
const frontlineLayerId = FRONTLINE + "-" + polygonId;
if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
drawFrontlineOnMap(polygonToDrawLeft, FRONTLINE + "-" + polygonId);
drawFrontlineOnMap(polygonToDrawRight, FRONTLINE + "-" + (polygonId+1));
const allFeatures = draw.getAll().features;
currentFeature = allFeatures.find(f => f.polygonId === polygonId);
return;
}
const frontlineLayerId = FRONTLINE + "-" + polygonId;
if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
drawFrontlineOnMap(polygonToDraw, FRONTLINE + "-" + polygonId);
const allFeatures = draw.getAll().features;
currentFeature = allFeatures.find(f => f.polygonId === polygonId);
}
function handleDraw(e) { function handleDraw(e) {
const feature = e.features[0]; const feature = e.features[0];
const coords = feature.geometry.coordinates; const coords = feature.geometry.coordinates;
const id = feature.id; const id = feature.id;
if (currentDrawStyle === ARROW) { if (currentDrawStyle === ARROW) {
DrawArrow(coords, id); DrawArrow(coords, id);
} else if (currentDrawStyle === FRONTLINE) { } else if (currentDrawStyle === FRONTLINE) {
@ -205,9 +136,7 @@ function handleDraw(e) {
} }
} }
function handleClick(click, prefix, paramsMap, showEditorFunction, hideEditorFunction) { function handleClick(click, prefix, paramsMap, showEditorFunction) {
console.log("currentFeature" + currentFeature);
const features = map.queryRenderedFeatures(click.point, { const features = map.queryRenderedFeatures(click.point, {
layers: map.getStyle().layers layers: map.getStyle().layers
.filter(l => l.id.startsWith(prefix + "-")) .filter(l => l.id.startsWith(prefix + "-"))
@ -216,13 +145,14 @@ function handleClick(click, prefix, paramsMap, showEditorFunction, hideEditorFun
if (features.length === 0) return; if (features.length === 0) return;
currentDrawStyle = prefix;
updateButtonStyles();
const feature = features[0]; const feature = features[0];
const featureId = feature.layer.id.replace(prefix + "-", ''); const featureId = feature.layer.id.replace(prefix + "-", '');
const allFeatures = draw.getAll().features; const allFeatures = draw.getAll().features;
currentFeature = allFeatures.find(f => f.id === featureId); currentFeature = allFeatures.find(f => f.id === featureId);
console.log("currentFeature" + currentFeature);
if (currentFeature) { if (currentFeature) {
const params = paramsMap.get(featureId); const params = paramsMap.get(featureId);
if (params) { if (params) {
@ -232,297 +162,370 @@ function handleClick(click, prefix, paramsMap, showEditorFunction, hideEditorFun
} }
} }
function MyDelete(polygonType) function DrawArrow(coordinates, polygonId) {
{ if (!arrowParamsMap.has(polygonId)) {
if (!currentFeature) return; arrowParamsMap.set(polygonId, structuredClone(DEFAULT_ARROW_PARAMS));
const id = currentFeature.id;
draw.delete(id);
//ARROW
if(polygonType == ARROW){
const arrowLayerId = polygonType + "-" + id;
if (map.getLayer(arrowLayerId)) map.removeLayer(arrowLayerId);
if (map.getSource(arrowLayerId)) map.removeSource(arrowLayerId);
arrowParamsMap.delete(id);
} }
//Frontline const params = arrowParamsMap.get(polygonId);
if(polygonType == FRONTLINE){ const arrowGeoJSON = getArrowPolygon(
const frontlineLayerId = polygonType + "-" + id; {
points: coordinates,
splineStep: params.splineStep,
offsetDistance: params.offsetDistance
},
{
calculation: params.calculation,
range: params.range,
minValue: params.minValue
},
{
widthArrow: params.widthArrow,
lengthArrow: params.lengthArrow
}
);
if (frontlineParamsMap.get(id).style == 3){ //BOTH_SIDES updatePolygonOnMap(ARROW, polygonId, drawArrowOnMap, arrowGeoJSON);
}
if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId); function DrawFrontline(coordinates, polygonId) {
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId); if (!frontlineParamsMap.has(polygonId)) {
const frontlineLayerIdB = polygonType + "-" + (id+1); frontlineParamsMap.set(polygonId, structuredClone(DEFAULT_FRONTLINE_PARAMS));
if (map.getLayer(frontlineLayerIdB)) map.removeLayer(frontlineLayerIdB); }
if (map.getSource(frontlineLayerIdB)) map.removeSource(frontlineLayerIdB);
frontlineParamsMap.delete(id);
frontlineParamsMap.delete(id+1);
hideArrowEditor(); const params = frontlineParamsMap.get(polygonId);
hideFrontlineEditor(); const frontlineGeoJSON = getFrontline(
{
points: coordinates,
splineStep: params.splineStep,
offsetDistance: params.offsetDistance,
style: params.style
},
params.protrusion
);
let polygonToDraw = frontlineGeoJSON;
// Only one side
if (frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly) {
polygonToDraw = frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly;
}
// Both sides
if(frontlineGeoJSON.leftPoly && frontlineGeoJSON.rightPoly){
updatePolygonOnMap(FRONTLINE, polygonId, drawFrontlineOnMap, polygonToDraw);
let additionalPolygonToDraw = frontlineGeoJSON.rightPoly;
drawFrontlineOnMap(additionalPolygonToDraw, FRONTLINE + "-" + (polygonId+1));
return; return;
} }
if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId); updatePolygonOnMap(FRONTLINE, polygonId, drawFrontlineOnMap, polygonToDraw);
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
frontlineParamsMap.delete(id);
}
hideArrowEditor();
hideFrontlineEditor();
} }
function updatePolygonOnMap(prefix, polygonId, drawFunction, geojson) {
const layerId =  prefix + "-" + polygonId;
if (map.getLayer(layerId)) map.removeLayer(layerId);
if (map.getSource(layerId)) map.removeSource(layerId);
drawFunction(geojson, layerId);
const allFeatures = draw.getAll().features;
currentFeature = allFeatures.find(f => f.polygonId === polygonId);
}
function drawArrowOnMap(geojson, id) { function drawArrowOnMap(geojson, id) {
map.addSource(id, {     map.addSource(id, {
type: 'geojson',         type: 'geojson',
data: geojson         data: geojson
});     });
map.addLayer({     map.addLayer({
id: id,         id: id,
type: 'fill',         type: 'fill',
source: id,         source: id,
paint: {         paint: {
'fill-color': '#ff0000',             'fill-color': '#ff0000',
'fill-opacity': 0.5             'fill-opacity': 0.5
}         }
});     });
} }
function drawFrontlineOnMap(frontlineGeoJSON, id) { function drawFrontlineOnMap(frontlineGeoJSON, id) {
if (map.getLayer(id)) map.removeLayer(id);     if (map.getLayer(id)) map.removeLayer(id);
if (map.getSource(id)) map.removeSource(id);     if (map.getSource(id)) map.removeSource(id);
map.addSource(id, {     map.addSource(id, {
type: 'geojson',         type: 'geojson',
data: frontlineGeoJSON         data: frontlineGeoJSON
});     });
map.addLayer({     map.addLayer({
id: id,         id: id,
type: 'fill',         type: 'fill',
source: id,         source: id,
paint: {         paint: {
'fill-color': '#ff6600',             'fill-color': '#ff6600',
'fill-opacity': 0.6,             'fill-opacity': 0.6,
'fill-outline-color': '#cc3300'             'fill-outline-color': '#cc3300'
}         }
});     });
} }
function MyDelete(polygonType)
{
    if (!currentFeature) return;
   
    const id = currentFeature.id;
    draw.delete(id);
    //ARROW
    if(polygonType == ARROW){
        const arrowLayerId = polygonType + "-" + id;
        if (map.getLayer(arrowLayerId)) map.removeLayer(arrowLayerId);
        if (map.getSource(arrowLayerId)) map.removeSource(arrowLayerId);
        arrowParamsMap.delete(id);
    }
   
    //Frontline
    if(polygonType == FRONTLINE){
        const frontlineLayerId = polygonType + "-" + id;
        if (frontlineParamsMap.get(id).style == 3){ //BOTH_SIDES
            if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
            if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
            const frontlineLayerIdB = polygonType + "-" + (id+1);
            if (map.getLayer(frontlineLayerIdB)) map.removeLayer(frontlineLayerIdB);
            if (map.getSource(frontlineLayerIdB)) map.removeSource(frontlineLayerIdB);
            frontlineParamsMap.delete(id);
            frontlineParamsMap.delete(id+1);
           
            hideArrowEditor();
            hideFrontlineEditor();
            return;
        }
        if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
        if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
        frontlineParamsMap.delete(id);
    }
   
    hideArrowEditor();
    hideFrontlineEditor();
}
function showArrowEditor(params) { function showArrowEditor(params) {
const popup = document.getElementById('arrow-editor');     const popup = document.getElementById('arrow-editor');
popup.style.display = 'block';     popup.style.display = 'block';
popup.style.left = '10px';     popup.style.left = '10px';
popup.style.top = '70px';     popup.style.top = '70px';
document.getElementById('splineStep').value = params.splineStep;     document.getElementById('splineStep').value = params.splineStep;
document.getElementById('offsetDistance').value = params.offsetDistance;     document.getElementById('offsetDistance').value = params.offsetDistance;
document.getElementById('range').value = params.range;     document.getElementById('range').value = params.range;
document.getElementById('minValue').value = params.minValue;     document.getElementById('minValue').value = params.minValue;
document.getElementById('widthArrow').value = params.widthArrow;     document.getElementById('widthArrow').value = params.widthArrow;
document.getElementById('lengthArrow').value = params.lengthArrow;     document.getElementById('lengthArrow').value = params.lengthArrow;
} }
function hideArrowEditor() { function hideArrowEditor() {
const popup = document.getElementById('arrow-editor');     const popup = document.getElementById('arrow-editor');
popup.style.display = 'none';     popup.style.display = 'none';
currentFeature = null;     currentFeature = null;
} }
function showFrontlineEditor(params) { function showFrontlineEditor(params) {
const popup = document.getElementById('frontline-editor');     const popup = document.getElementById('frontline-editor');
popup.style.display = 'block';     popup.style.display = 'block';
popup.style.left = '10px';     popup.style.left = '10px';
popup.style.top = '70px';     popup.style.top = '70px';
document.getElementById('splineStepFrontline').value = params.splineStep;     document.getElementById('splineStepFrontline').value = params.splineStep;
document.getElementById('offsetDistanceFrontline').value = params.offsetDistance;     document.getElementById('offsetDistanceFrontline').value = params.offsetDistance;
document.getElementById('styleFrontline').value = params.style;     document.getElementById('styleFrontline').value = params.style;
document.getElementById('protrusionLength').value = params.protrusion.length;     document.getElementById('protrusionLength').value = params.protrusion.length;
document.getElementById('protrusionStartSize').value = params.protrusion.startSize;     document.getElementById('protrusionStartSize').value = params.protrusion.startSize;
document.getElementById('protrusionEndSize').value = params.protrusion.endSize;     document.getElementById('protrusionEndSize').value = params.protrusion.endSize;
document.getElementById('protrusionGap').value = params.protrusion.gap;     document.getElementById('protrusionGap').value = params.protrusion.gap;
} }
function hideFrontlineEditor() { function hideFrontlineEditor() {
const popup = document.getElementById('frontline-editor');     const popup = document.getElementById('frontline-editor');
popup.style.display = 'none';     popup.style.display = 'none';
currentFeature = null;     currentFeature = null;
} }
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
document.getElementById('removeArrow').addEventListener('click', () => {     document.getElementById('removeArrow').addEventListener('click', () => {
       
        MyDelete(ARROW);
    });
MyDelete(ARROW);     document.getElementById('removeFrontline').addEventListener('click', () => {
});        
        MyDelete(FRONTLINE);
    });
document.getElementById('removeFrontline').addEventListener('click', () => {     document.getElementById('applyArrowChanges').addEventListener('click', () => {
       
        if (!currentFeature) return;
        console.log("Test");
        const coords = currentFeature.geometry.coordinates;
        const id = currentFeature.id;
MyDelete(FRONTLINE);         const splineStep = parseFloat(document.getElementById('splineStep').value);
});         const offsetDistance = parseFloat(document.getElementById('offsetDistance').value);
        const range = parseFloat(document.getElementById('range').value);
        const minValue = parseFloat(document.getElementById('minValue').value);
        const widthArrow = parseFloat(document.getElementById('widthArrow').value);
        const lengthArrow = parseFloat(document.getElementById('lengthArrow').value);
document.getElementById('applyArrowChanges').addEventListener('click', () => {         arrowParamsMap.set(id, {
            splineStep,
            offsetDistance,
            calculation: ARROW_BODY_STYLE_LINEAR,
            range,
            minValue,
            widthArrow,
            lengthArrow
        });
if (!currentFeature) return;         const arrowGeoJSON = getArrowPolygon({
console.log("Test");             points: coords,
const coords = currentFeature.geometry.coordinates;             splineStep,
const id = currentFeature.id;             offsetDistance
        }, {
            calculation: ARROW_BODY_STYLE_LINEAR,
            range,
            minValue
        }, {
            widthArrow,
            lengthArrow
        });
const splineStep = parseFloat(document.getElementById('splineStep').value);         //ARROW
const offsetDistance = parseFloat(document.getElementById('offsetDistance').value);         const arrowLayerId = ARROW + "-" + id;
const range = parseFloat(document.getElementById('range').value);         if (map.getLayer(arrowLayerId)) map.removeLayer(arrowLayerId);
const minValue = parseFloat(document.getElementById('minValue').value);         if (map.getSource(arrowLayerId)) map.removeSource(arrowLayerId);
const widthArrow = parseFloat(document.getElementById('widthArrow').value);
const lengthArrow = parseFloat(document.getElementById('lengthArrow').value);
arrowParamsMap.set(id, {         drawArrowOnMap(arrowGeoJSON, ARROW + "-" + id);
splineStep,
offsetDistance,
calculation: ARROW_BODY_STYLE_LINEAR,
range,
minValue,
widthArrow,
lengthArrow
});
const arrowGeoJSON = getArrowPolygon({         const allFeatures = draw.getAll().features;
points: coords,         currentFeature = allFeatures.find(f => f.id === id);
splineStep,     });
offsetDistance
}, {
calculation: ARROW_BODY_STYLE_LINEAR,
range,
minValue
}, {
widthArrow,
lengthArrow
});
//ARROW     document.getElementById('applyFrontlineChanges').addEventListener('click', () => {
const arrowLayerId = ARROW + "-" + id;         if (!currentFeature) return;
if (map.getLayer(arrowLayerId)) map.removeLayer(arrowLayerId);
if (map.getSource(arrowLayerId)) map.removeSource(arrowLayerId);
drawArrowOnMap(arrowGeoJSON, ARROW + "-" + id);         const coords = currentFeature.geometry.coordinates;
        const id = currentFeature.id;
const allFeatures = draw.getAll().features;         const splineStep = parseFloat(document.getElementById('splineStepFrontline').value);
currentFeature = allFeatures.find(f => f.id === id);         const offsetDistance = parseFloat(document.getElementById('offsetDistanceFrontline').value);
});         const style = parseInt(document.getElementById('styleFrontline').value);
document.getElementById('applyFrontlineChanges').addEventListener('click', () => {         const length = parseFloat(document.getElementById('protrusionLength').value);
if (!currentFeature) return;         const startSize = parseFloat(document.getElementById('protrusionStartSize').value);
        const endSize = parseFloat(document.getElementById('protrusionEndSize').value);
        const gap = parseFloat(document.getElementById('protrusionGap').value);
const coords = currentFeature.geometry.coordinates;         frontlineParamsMap.set(id, {
const id = currentFeature.id;             splineStep,
            offsetDistance,
            style,
            protrusion: {
                length,
                startSize,
                endSize,
                gap
            }
        });
const splineStep = parseFloat(document.getElementById('splineStepFrontline').value);         const frontlineData = {
const offsetDistance = parseFloat(document.getElementById('offsetDistanceFrontline').value);             points: coords,
const style = parseInt(document.getElementById('styleFrontline').value);             splineStep,
            offsetDistance,
            style
        };
const length = parseFloat(document.getElementById('protrusionLength').value);         const protrusionData = frontlineParamsMap.get(id).protrusion;
const startSize = parseFloat(document.getElementById('protrusionStartSize').value);
const endSize = parseFloat(document.getElementById('protrusionEndSize').value);
const gap = parseFloat(document.getElementById('protrusionGap').value);
frontlineParamsMap.set(id, {         console.log("Update");
splineStep,         console.log(frontlineData);
offsetDistance,         console.log(protrusionData);
style,
protrusion: {
length,
startSize,
endSize,
gap
}
});
const frontlineData = {         const frontlineGeoJSON = getFrontline(frontlineData, protrusionData);
points: coords,
splineStep,
offsetDistance,
style
};
const protrusionData = frontlineParamsMap.get(id).protrusion;         console.log("frontlineGeoJSON", frontlineGeoJSON);
        let polygonToDraw = frontlineGeoJSON;
console.log("Update");         if (frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly) {
console.log(frontlineData);             polygonToDraw = frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly;
console.log(protrusionData);         }
        if(frontlineGeoJSON.leftPoly && frontlineGeoJSON.rightPoly){
            let polygonToDrawLeft = frontlineGeoJSON.leftPoly;
            let polygonToDrawRight = frontlineGeoJSON.rightPoly;
const frontlineGeoJSON = getFrontline(frontlineData, protrusionData);             console.log("polygonToDrawLeft", polygonToDrawLeft);
            console.log("polygonToDrawRight", polygonToDrawRight);
           
            const frontlineLayerId = FRONTLINE + "-" + id;
            if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
            if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
console.log("frontlineGeoJSON", frontlineGeoJSON);             console.log(frontlineLayerId);
let polygonToDraw = frontlineGeoJSON;             console.log(FRONTLINE + "-" + (id+1));
            drawFrontlineOnMap(polygonToDrawLeft, FRONTLINE + "-" + id);
            drawFrontlineOnMap(polygonToDrawRight, FRONTLINE + "-" + (id+1));
           
            const allFeatures = draw.getAll().features;
            currentFeature = allFeatures.find(f => f.id === id);
if (frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly) {             return;
polygonToDraw = frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly;         }
}
if(frontlineGeoJSON.leftPoly && frontlineGeoJSON.rightPoly){
let polygonToDrawLeft = frontlineGeoJSON.leftPoly;
let polygonToDrawRight = frontlineGeoJSON.rightPoly;
console.log("polygonToDrawLeft", polygonToDrawLeft);         //if (last was both destroy id+1) TODO
console.log("polygonToDrawRight", polygonToDrawRight);         console.log("Test2");
        const frontlineLayerId = FRONTLINE + "-" + id;
        if (map.getLayer(frontlineLayerId+1)) map.removeLayer(frontlineLayerId+1);
        if (map.getSource(frontlineLayerId+1)) map.removeSource(frontlineLayerId+1);
        if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
        if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
const frontlineLayerId = FRONTLINE + "-" + id;         drawFrontlineOnMap(polygonToDraw, FRONTLINE + "-" + id);
if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);        
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);         const allFeatures = draw.getAll().features;
        currentFeature = allFeatures.find(f => f.id === id);
    });
console.log(frontlineLayerId);     const buttonsContainer = document.getElementById('drawStyleButtons');
console.log(FRONTLINE + "-" + (id+1));     buttonsContainer.addEventListener('click', (event) => {
drawFrontlineOnMap(polygonToDrawLeft, FRONTLINE + "-" + id);         if (event.target.tagName !== 'BUTTON') return;
drawFrontlineOnMap(polygonToDrawRight, FRONTLINE + "-" + (id+1));
const allFeatures = draw.getAll().features;         Array.from(buttonsContainer.querySelectorAll('button')).forEach(btn => btn.classList.remove('active'));
currentFeature = allFeatures.find(f => f.id === id);
return;         event.target.classList.add('active');
}
//if (last was both destroy id+1) TODO         currentDrawStyle = event.target.getAttribute('data-style');
console.log("Test2");         updateButtonStyles();
const frontlineLayerId = FRONTLINE + "-" + id;     });
if (map.getLayer(frontlineLayerId+1)) map.removeLayer(frontlineLayerId+1);     updateButtonStyles();
if (map.getSource(frontlineLayerId+1)) map.removeSource(frontlineLayerId+1);
if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
drawFrontlineOnMap(polygonToDraw, FRONTLINE + "-" + id);
const allFeatures = draw.getAll().features;
currentFeature = allFeatures.find(f => f.id === id);
});
const buttonsContainer = document.getElementById('drawStyleButtons');
buttonsContainer.addEventListener('click', (event) => {
if (event.target.tagName !== 'BUTTON') return;
Array.from(buttonsContainer.querySelectorAll('button')).forEach(btn => btn.classList.remove('active'));
event.target.classList.add('active');
currentDrawStyle = event.target.getAttribute('data-style');
updateButtonStyles();
});
updateButtonStyles();
function updateButtonStyles() {
Array.from(buttonsContainer.querySelectorAll('button')).forEach(btn => {
const isSelected = btn.getAttribute('data-style') === currentDrawStyle;
btn.style.backgroundColor = isSelected ? '#333' : '#f0f0f0';
btn.style.color = isSelected ? '#fff' : '#000';
});
}
}); });
function updateButtonStyles() {
    const buttonsContainer = document.getElementById('drawStyleButtons');
    Array.from(buttonsContainer.querySelectorAll('button')).forEach(btn => {
        const isSelected = btn.getAttribute('data-style') === currentDrawStyle;
        btn.style.backgroundColor = isSelected ? '#333' : '#f0f0f0';
        btn.style.color = isSelected ? '#fff' : '#000';
    });
}