Compare commits
2 Commits
ef4dd49d74
...
7157c2502a
| Author | SHA1 | Date | |
|---|---|---|---|
| 7157c2502a | |||
| 049bbc5781 |
468
Drawing.js
468
Drawing.js
@ -22,8 +22,7 @@ const map = new mapboxgl.Map({
|
|||||||
const draw = new MapboxDraw({
|
const draw = new MapboxDraw({
|
||||||
displayControlsDefault: false,
|
displayControlsDefault: false,
|
||||||
controls: {
|
controls: {
|
||||||
line_string: true,
|
line_string: true
|
||||||
trash: true
|
|
||||||
},
|
},
|
||||||
defaultMode: 'draw_line_string',
|
defaultMode: 'draw_line_string',
|
||||||
styles: [
|
styles: [
|
||||||
@ -94,17 +93,11 @@ const draw = new MapboxDraw({
|
|||||||
|
|
||||||
|
|
||||||
map.addControl(draw, 'top-left');
|
map.addControl(draw, 'top-left');
|
||||||
|
|
||||||
map.on('draw.create', handleDraw);
|
map.on('draw.create', handleDraw);
|
||||||
map.on('draw.delete', () => {
|
|
||||||
draw.deleteAll();
|
|
||||||
clearAllArrowLayers();
|
|
||||||
clearAllFrontlineLayers();
|
|
||||||
hideArrowEditor();
|
|
||||||
hideFrontlineEditor();
|
|
||||||
document.getElementById('calculated-area').innerHTML = '';
|
|
||||||
});
|
|
||||||
map.on('draw.update', handleDraw);
|
map.on('draw.update', handleDraw);
|
||||||
map.on('click', (e) => {
|
map.on('click', (e) => {
|
||||||
|
// Hledání šipek
|
||||||
const arrowFeatures = map.queryRenderedFeatures(e.point, {
|
const arrowFeatures = map.queryRenderedFeatures(e.point, {
|
||||||
layers: map.getStyle().layers
|
layers: map.getStyle().layers
|
||||||
.filter(l => l.id.startsWith('arrow-'))
|
.filter(l => l.id.startsWith('arrow-'))
|
||||||
@ -121,21 +114,19 @@ map.on('click', (e) => {
|
|||||||
const params = arrowParamsMap.get(featureId);
|
const params = arrowParamsMap.get(featureId);
|
||||||
if (params) {
|
if (params) {
|
||||||
showArrowEditor(params);
|
showArrowEditor(params);
|
||||||
hideFrontlineEditor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
draw.changeMode('direct_select', { featureId: featureId });
|
draw.changeMode('direct_select', { featureId: featureId });
|
||||||
}
|
}
|
||||||
return;
|
return; // pokud kliknul na arrow, dále nekoukáme
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pokud to není arrow, zkus frontline
|
// Hledání frontlinů
|
||||||
const frontlineFeatures = map.queryRenderedFeatures(e.point, {
|
const frontlineFeatures = map.queryRenderedFeatures(e.point, {
|
||||||
layers: map.getStyle().layers
|
layers: map.getStyle().layers
|
||||||
.filter(l => l.id.startsWith('frontline-'))
|
.filter(l => l.id.startsWith('frontline-'))
|
||||||
.map(l => l.id)
|
.map(l => l.id)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (frontlineFeatures.length > 0) {
|
if (frontlineFeatures.length > 0) {
|
||||||
const frontlineFeature = frontlineFeatures[0];
|
const frontlineFeature = frontlineFeatures[0];
|
||||||
const featureId = frontlineFeature.layer.id.replace('frontline-', '');
|
const featureId = frontlineFeature.layer.id.replace('frontline-', '');
|
||||||
@ -147,109 +138,166 @@ map.on('click', (e) => {
|
|||||||
const params = frontlineParamsMap.get(featureId);
|
const params = frontlineParamsMap.get(featureId);
|
||||||
if (params) {
|
if (params) {
|
||||||
showFrontlineEditor(params);
|
showFrontlineEditor(params);
|
||||||
hideArrowEditor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
draw.changeMode('direct_select', { featureId: featureId });
|
draw.changeMode('direct_select', { featureId: featureId });
|
||||||
}
|
}
|
||||||
|
return; // pokud kliknul na frontline, dále nekoukáme
|
||||||
|
}
|
||||||
|
|
||||||
|
// Když nic nenajdeme - schovej editory
|
||||||
|
hideFrontlineEditor();
|
||||||
|
hideArrowEditor();
|
||||||
|
});
|
||||||
|
|
||||||
|
map.dragPan.enable();
|
||||||
|
|
||||||
|
function MyDelete()
|
||||||
|
{
|
||||||
|
if (!currentFeature) return;
|
||||||
|
|
||||||
|
const id = currentFeature.id;
|
||||||
|
|
||||||
|
draw.delete(id);
|
||||||
|
//ARROW
|
||||||
|
const arrowLayerId = `arrow-${id}`;
|
||||||
|
if (map.getLayer(arrowLayerId)) map.removeLayer(arrowLayerId);
|
||||||
|
if (map.getSource(arrowLayerId)) map.removeSource(arrowLayerId);
|
||||||
|
|
||||||
|
arrowParamsMap.delete(id);
|
||||||
|
|
||||||
|
//Frontline
|
||||||
|
const frontlineLayerId = `frontline-${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 = `frontline-${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();
|
||||||
|
document.getElementById('calculated-area').innerHTML = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
|
||||||
|
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
|
||||||
|
frontlineParamsMap.delete(id);
|
||||||
|
|
||||||
hideArrowEditor();
|
hideArrowEditor();
|
||||||
hideFrontlineEditor();
|
hideFrontlineEditor();
|
||||||
});
|
document.getElementById('calculated-area').innerHTML = '';
|
||||||
map.dragPan.enable();
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleDraw(e) {
|
function handleDraw(e) {
|
||||||
const data = draw.getAll();
|
const feature = e.features[0];
|
||||||
const answer = document.getElementById('calculated-area');
|
|
||||||
|
|
||||||
clearAllArrowLayers();
|
if (feature.geometry.type !== 'LineString') return;
|
||||||
clearAllFrontlineLayers();
|
|
||||||
|
|
||||||
if (data.features.length > 0) {
|
const coords = feature.geometry.coordinates;
|
||||||
answer.innerHTML = '';
|
const id = feature.id;
|
||||||
|
|
||||||
data.features.forEach((line, index) => {
|
if (currentDrawStyle === 'arrow') {
|
||||||
if (line.geometry.type !== 'LineString') return;
|
if (!arrowParamsMap.has(id)) {
|
||||||
|
arrowParamsMap.set(id, {
|
||||||
|
splineStep: 20,
|
||||||
|
offsetDistance: 12000,
|
||||||
|
calculation: ARROW_BODY_STYLE_LINEAR,
|
||||||
|
range: 1,
|
||||||
|
minValue: 0.1,
|
||||||
|
widthArrow: 5,
|
||||||
|
lengthArrow: 8
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const coords = line.geometry.coordinates;
|
const params = arrowParamsMap.get(id);
|
||||||
const id = line.id || `line-${index}`;
|
|
||||||
|
|
||||||
if (currentDrawStyle === 'arrow') {
|
const arrowGeoJSON = getArrowPolygon(
|
||||||
if (!arrowParamsMap.has(id)) {
|
{ points: coords, splineStep: params.splineStep, offsetDistance: params.offsetDistance },
|
||||||
arrowParamsMap.set(id, {
|
{ calculation: params.calculation, range: params.range, minValue: params.minValue },
|
||||||
splineStep: 20,
|
{ widthArrow: params.widthArrow, lengthArrow: params.lengthArrow }
|
||||||
offsetDistance: 12000,
|
);
|
||||||
calculation: ARROW_BODY_STYLE_LINEAR,
|
|
||||||
range: 1,
|
const arrowLayerId = `arrow-${id}`;
|
||||||
minValue: 0.1,
|
if (map.getLayer(arrowLayerId)) map.removeLayer(arrowLayerId);
|
||||||
widthArrow: 5,
|
if (map.getSource(arrowLayerId)) map.removeSource(arrowLayerId);
|
||||||
lengthArrow: 8
|
drawArrowOnMap(arrowGeoJSON, `arrow-${id}`);
|
||||||
});
|
const allFeatures = draw.getAll().features;
|
||||||
|
currentFeature = allFeatures.find(f => f.id === id);
|
||||||
|
|
||||||
|
} else if (currentDrawStyle === 'frontline') {
|
||||||
|
if (!frontlineParamsMap.has(id)) {
|
||||||
|
frontlineParamsMap.set(id, {
|
||||||
|
splineStep: 0.08,
|
||||||
|
offsetDistance: 10000,
|
||||||
|
style: LEFT_SIDE,
|
||||||
|
protrusion: {
|
||||||
|
length: 15000,
|
||||||
|
startSize: 5000,
|
||||||
|
endSize: 500,
|
||||||
|
gap: 15000
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const params = arrowParamsMap.get(id);
|
const params = frontlineParamsMap.get(id);
|
||||||
|
|
||||||
const arrowGeoJSON = getArrowPolygon(
|
const frontlineData = {
|
||||||
{ points: coords, splineStep: params.splineStep, offsetDistance: params.offsetDistance },
|
points: coords,
|
||||||
{ calculation: params.calculation, range: params.range, minValue: params.minValue },
|
splineStep: params.splineStep,
|
||||||
{ widthArrow: params.widthArrow, lengthArrow: params.lengthArrow }
|
offsetDistance: params.offsetDistance,
|
||||||
);
|
style: params.style
|
||||||
|
};
|
||||||
|
|
||||||
drawArrowOnMap(arrowGeoJSON, `arrow-${id}`);
|
const protrusionData = params.protrusion;
|
||||||
|
|
||||||
} else if (currentDrawStyle === 'frontline') {
|
console.log("Create");
|
||||||
if (!frontlineParamsMap.has(id)) {
|
console.log(frontlineData);
|
||||||
frontlineParamsMap.set(id, {
|
console.log(protrusionData);
|
||||||
splineStep: 20,
|
const frontlineGeoJSON = getFrontline(frontlineData, protrusionData);
|
||||||
spacing: 500,
|
|
||||||
offsetDistance: 12000,
|
|
||||||
style: LEFT_SIDE,
|
|
||||||
protrusion: {
|
|
||||||
length: 2000,
|
|
||||||
startSize: 5000,
|
|
||||||
endSize: 5000,
|
|
||||||
gap: 10000
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const params = frontlineParamsMap.get(id);
|
let polygonToDraw = frontlineGeoJSON;
|
||||||
|
if (frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly) {
|
||||||
|
polygonToDraw = frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly;
|
||||||
|
}
|
||||||
|
|
||||||
const frontlineData = {
|
if(frontlineGeoJSON.leftPoly && frontlineGeoJSON.rightPoly){
|
||||||
points: coords,
|
let polygonToDrawLeft = frontlineGeoJSON.leftPoly;
|
||||||
splineStep: params.splineStep,
|
let polygonToDrawRight = frontlineGeoJSON.rightPoly;
|
||||||
spacing: params.spacing,
|
|
||||||
offsetDistance: params.offsetDistance,
|
|
||||||
style: params.style
|
|
||||||
};
|
|
||||||
|
|
||||||
const protrusionData = params.protrusion;
|
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);
|
||||||
|
|
||||||
const frontlineGeoJSON = getFrontline(frontlineData, protrusionData);
|
drawFrontlineOnMap(polygonToDrawLeft, `frontline-${id}`);
|
||||||
|
drawFrontlineOnMap(polygonToDrawRight, `frontline-${id+1}`);
|
||||||
|
|
||||||
|
const allFeatures = draw.getAll().features;
|
||||||
|
currentFeature = allFeatures.find(f => f.id === id);
|
||||||
|
|
||||||
let polygonToDraw = frontlineGeoJSON;
|
return;
|
||||||
if (frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly) {
|
}
|
||||||
polygonToDraw = frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawFrontlineOnMap(polygonToDraw, `frontline-${id}`);
|
const frontlineLayerId = `frontline-${id}`;
|
||||||
}
|
if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
|
||||||
});
|
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
|
||||||
} else {
|
drawFrontlineOnMap(polygonToDraw, `frontline-${id}`);
|
||||||
answer.innerHTML = '';
|
const allFeatures = draw.getAll().features;
|
||||||
if (e.type !== 'draw.delete')
|
currentFeature = allFeatures.find(f => f.id === id);
|
||||||
alert('Klikni na mapu pro kreslení čáry.');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawArrowOnMap(geojson, id) {
|
function drawArrowOnMap(geojson, id) {
|
||||||
|
|
||||||
if (map.getLayer(id)) map.removeLayer(id);
|
|
||||||
if (map.getSource(id)) map.removeSource(id);
|
|
||||||
|
|
||||||
map.addSource(id, {
|
map.addSource(id, {
|
||||||
type: 'geojson',
|
type: 'geojson',
|
||||||
data: geojson
|
data: geojson
|
||||||
@ -264,7 +312,6 @@ function drawArrowOnMap(geojson, id) {
|
|||||||
'fill-opacity': 0.5
|
'fill-opacity': 0.5
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log('HERE');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawFrontlineOnMap(frontlineGeoJSON, id) {
|
function drawFrontlineOnMap(frontlineGeoJSON, id) {
|
||||||
@ -289,17 +336,17 @@ function drawFrontlineOnMap(frontlineGeoJSON, id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clearAllArrowLayers() {
|
function clearAllArrowLayers() {
|
||||||
const layers = map.getStyle().layers;
|
const allLayerIds = map.getStyle().layers.map(l => l.id);
|
||||||
if (!layers) return;
|
|
||||||
|
|
||||||
layers.forEach(layer => {
|
allLayerIds.forEach(id => {
|
||||||
if (layer.id.startsWith('arrow-')) {
|
if (id.startsWith('arrow-')) {
|
||||||
if (map.getLayer(layer.id)) map.removeLayer(layer.id);
|
if (map.getLayer(id)) map.removeLayer(id);
|
||||||
if (map.getSource(layer.id)) map.removeSource(layer.id);
|
if (map.getSource(id)) map.removeSource(id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function clearAllFrontlineLayers() {
|
function clearAllFrontlineLayers() {
|
||||||
const layers = map.getStyle().layers;
|
const layers = map.getStyle().layers;
|
||||||
if (!layers) return;
|
if (!layers) return;
|
||||||
@ -343,7 +390,6 @@ function showFrontlineEditor(params) {
|
|||||||
popup.style.top = '70px';
|
popup.style.top = '70px';
|
||||||
|
|
||||||
document.getElementById('splineStepFrontline').value = params.splineStep;
|
document.getElementById('splineStepFrontline').value = params.splineStep;
|
||||||
document.getElementById('spacing').value = params.spacing;
|
|
||||||
document.getElementById('offsetDistanceFrontline').value = params.offsetDistance;
|
document.getElementById('offsetDistanceFrontline').value = params.offsetDistance;
|
||||||
document.getElementById('styleFrontline').value = params.style;
|
document.getElementById('styleFrontline').value = params.style;
|
||||||
|
|
||||||
@ -360,111 +406,167 @@ function hideFrontlineEditor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
document.getElementById('applyArrowChanges').addEventListener('click', () => {
|
|
||||||
|
|
||||||
console.log("arrowFeatures");
|
|
||||||
console.log(arrowFeatures);
|
|
||||||
if (!currentFeature) return;
|
|
||||||
console.log("Test");
|
|
||||||
const coords = currentFeature.geometry.coordinates;
|
|
||||||
const id = currentFeature.id;
|
|
||||||
|
|
||||||
const splineStep = parseFloat(document.getElementById('splineStep').value);
|
document.getElementById('removeArrow').addEventListener('click', () => {
|
||||||
const offsetDistance = parseFloat(document.getElementById('offsetDistance').value);
|
|
||||||
const range = parseFloat(document.getElementById('range').value);
|
MyDelete();
|
||||||
const minValue = parseFloat(document.getElementById('minValue').value);
|
|
||||||
const widthArrow = parseFloat(document.getElementById('widthArrow').value);
|
|
||||||
const lengthArrow = parseFloat(document.getElementById('lengthArrow').value);
|
|
||||||
|
|
||||||
arrowParamsMap.set(id, {
|
|
||||||
splineStep,
|
|
||||||
offsetDistance,
|
|
||||||
calculation: ARROW_BODY_STYLE_LINEAR,
|
|
||||||
range,
|
|
||||||
minValue,
|
|
||||||
widthArrow,
|
|
||||||
lengthArrow
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const arrowGeoJSON = getArrowPolygon({
|
document.getElementById('removeFrontline').addEventListener('click', () => {
|
||||||
points: coords,
|
|
||||||
splineStep,
|
MyDelete();
|
||||||
offsetDistance
|
|
||||||
}, {
|
|
||||||
calculation: ARROW_BODY_STYLE_LINEAR,
|
|
||||||
range,
|
|
||||||
minValue
|
|
||||||
}, {
|
|
||||||
widthArrow,
|
|
||||||
lengthArrow
|
|
||||||
});
|
});
|
||||||
|
|
||||||
drawArrowOnMap(arrowGeoJSON, `arrow-${id}`);
|
document.getElementById('applyArrowChanges').addEventListener('click', () => {
|
||||||
});
|
|
||||||
|
if (!currentFeature) return;
|
||||||
|
console.log("Test");
|
||||||
|
const coords = currentFeature.geometry.coordinates;
|
||||||
|
const id = currentFeature.id;
|
||||||
|
|
||||||
document.getElementById('applyFrontlineChanges').addEventListener('click', () => {
|
const splineStep = parseFloat(document.getElementById('splineStep').value);
|
||||||
if (!currentFeature) return;
|
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);
|
||||||
|
|
||||||
const coords = currentFeature.geometry.coordinates;
|
arrowParamsMap.set(id, {
|
||||||
const id = currentFeature.id;
|
splineStep,
|
||||||
|
offsetDistance,
|
||||||
|
calculation: ARROW_BODY_STYLE_LINEAR,
|
||||||
|
range,
|
||||||
|
minValue,
|
||||||
|
widthArrow,
|
||||||
|
lengthArrow
|
||||||
|
});
|
||||||
|
|
||||||
const splineStep = parseFloat(document.getElementById('splineStepFrontline').value);
|
const arrowGeoJSON = getArrowPolygon({
|
||||||
const spacing = parseFloat(document.getElementById('spacing').value);
|
points: coords,
|
||||||
const offsetDistance = parseFloat(document.getElementById('offsetDistanceFrontline').value);
|
splineStep,
|
||||||
const style = document.getElementById('styleFrontline').value;
|
offsetDistance
|
||||||
|
}, {
|
||||||
|
calculation: ARROW_BODY_STYLE_LINEAR,
|
||||||
|
range,
|
||||||
|
minValue
|
||||||
|
}, {
|
||||||
|
widthArrow,
|
||||||
|
lengthArrow
|
||||||
|
});
|
||||||
|
|
||||||
const length = parseFloat(document.getElementById('protrusionLength').value);
|
//ARROW
|
||||||
const startSize = parseFloat(document.getElementById('protrusionStartSize').value);
|
const arrowLayerId = `arrow-${id}`;
|
||||||
const endSize = parseFloat(document.getElementById('protrusionEndSize').value);
|
if (map.getLayer(arrowLayerId)) map.removeLayer(arrowLayerId);
|
||||||
const gap = parseFloat(document.getElementById('protrusionGap').value);
|
if (map.getSource(arrowLayerId)) map.removeSource(arrowLayerId);
|
||||||
|
|
||||||
frontlineParamsMap.set(id, {
|
drawArrowOnMap(arrowGeoJSON, `arrow-${id}`);
|
||||||
splineStep,
|
|
||||||
spacing,
|
const allFeatures = draw.getAll().features;
|
||||||
offsetDistance,
|
currentFeature = allFeatures.find(f => f.id === id);
|
||||||
style,
|
});
|
||||||
protrusion: {
|
|
||||||
length,
|
document.getElementById('applyFrontlineChanges').addEventListener('click', () => {
|
||||||
startSize,
|
if (!currentFeature) return;
|
||||||
endSize,
|
|
||||||
gap
|
const coords = currentFeature.geometry.coordinates;
|
||||||
|
const id = currentFeature.id;
|
||||||
|
|
||||||
|
const splineStep = parseFloat(document.getElementById('splineStepFrontline').value);
|
||||||
|
const offsetDistance = parseFloat(document.getElementById('offsetDistanceFrontline').value);
|
||||||
|
const style = parseInt(document.getElementById('styleFrontline').value);
|
||||||
|
|
||||||
|
const length = parseFloat(document.getElementById('protrusionLength').value);
|
||||||
|
const startSize = parseFloat(document.getElementById('protrusionStartSize').value);
|
||||||
|
const endSize = parseFloat(document.getElementById('protrusionEndSize').value);
|
||||||
|
const gap = parseFloat(document.getElementById('protrusionGap').value);
|
||||||
|
|
||||||
|
frontlineParamsMap.set(id, {
|
||||||
|
splineStep,
|
||||||
|
offsetDistance,
|
||||||
|
style,
|
||||||
|
protrusion: {
|
||||||
|
length,
|
||||||
|
startSize,
|
||||||
|
endSize,
|
||||||
|
gap
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const frontlineData = {
|
||||||
|
points: coords,
|
||||||
|
splineStep,
|
||||||
|
offsetDistance,
|
||||||
|
style
|
||||||
|
};
|
||||||
|
|
||||||
|
const protrusionData = frontlineParamsMap.get(id).protrusion;
|
||||||
|
|
||||||
|
console.log("Update");
|
||||||
|
console.log(frontlineData);
|
||||||
|
console.log(protrusionData);
|
||||||
|
|
||||||
|
const frontlineGeoJSON = getFrontline(frontlineData, protrusionData);
|
||||||
|
|
||||||
|
console.log("frontlineGeoJSON", frontlineGeoJSON);
|
||||||
|
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;
|
||||||
|
|
||||||
|
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(frontlineLayerId);
|
||||||
|
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);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if (last was both destroy id+1) TODO
|
||||||
|
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);
|
||||||
|
|
||||||
|
drawFrontlineOnMap(polygonToDraw, `frontline-${id}`);
|
||||||
|
|
||||||
|
const allFeatures = draw.getAll().features;
|
||||||
|
currentFeature = allFeatures.find(f => f.id === id);
|
||||||
});
|
});
|
||||||
|
|
||||||
const frontlineData = {
|
const buttonsContainer = document.getElementById('drawStyleButtons');
|
||||||
points: coords,
|
buttonsContainer.addEventListener('click', (event) => {
|
||||||
splineStep,
|
if (event.target.tagName !== 'BUTTON') return;
|
||||||
spacing,
|
|
||||||
offsetDistance,
|
|
||||||
style
|
|
||||||
};
|
|
||||||
|
|
||||||
const protrusionData = frontlineParamsMap.get(id).protrusion;
|
Array.from(buttonsContainer.querySelectorAll('button')).forEach(btn => btn.classList.remove('active'));
|
||||||
|
|
||||||
const frontlineGeoJSON = getFrontline(frontlineData, protrusionData);
|
event.target.classList.add('active');
|
||||||
|
|
||||||
let polygonToDraw = frontlineGeoJSON;
|
currentDrawStyle = event.target.getAttribute('data-style');
|
||||||
if (frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly) {
|
updateButtonStyles();
|
||||||
polygonToDraw = frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly;
|
});
|
||||||
|
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';
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
drawFrontlineOnMap(polygonToDraw, `frontline-${id}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
const buttonsContainer = document.getElementById('drawStyleButtons');
|
|
||||||
buttonsContainer.addEventListener('click', (event) => {
|
|
||||||
if (event.target.tagName !== 'BUTTON') return;
|
|
||||||
|
|
||||||
// Odeber aktivní třídu ze všech tlačítek
|
|
||||||
Array.from(buttonsContainer.querySelectorAll('button')).forEach(btn => btn.classList.remove('active'));
|
|
||||||
|
|
||||||
// Nastav aktivní třídu na kliknuté tlačítko
|
|
||||||
event.target.classList.add('active');
|
|
||||||
|
|
||||||
// Nastav styl podle data atributu
|
|
||||||
currentDrawStyle = event.target.getAttribute('data-style');
|
|
||||||
|
|
||||||
// Při změně stylu překreslíme aktuální kreslené prvky
|
|
||||||
handleDraw({ type: 'draw.update' });
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
11
index.html
11
index.html
@ -70,18 +70,18 @@ MAPBOX - DRAWING
|
|||||||
<label>Width Arrow: <input id="widthArrow" type="number" step="1"></label><br>
|
<label>Width Arrow: <input id="widthArrow" type="number" step="1"></label><br>
|
||||||
<label>Length Arrow: <input id="lengthArrow" type="number" step="1"></label><br>
|
<label>Length Arrow: <input id="lengthArrow" type="number" step="1"></label><br>
|
||||||
<button id="applyArrowChanges">Apply Changes</button>
|
<button id="applyArrowChanges">Apply Changes</button>
|
||||||
|
<button id="removeArrow">Remove Arrow</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="frontline-editor" style="position: absolute; background: white; padding: 10px; border: 1px solid #ccc; display: none; z-index: 1000;">
|
<div id="frontline-editor" style="position: absolute; background: white; padding: 10px; border: 1px solid #ccc; display: none; z-index: 1000;">
|
||||||
<h3>Frontline Editor</h3>
|
<h3>Frontline Editor</h3>
|
||||||
<label>Spline Step: <input id="splineStepFrontline" type="number" step="1"></label><br>
|
<label>Spline Step: <input id="splineStepFrontline" type="number" step="1"></label><br>
|
||||||
<label>Spacing: <input id="spacing" type="number" step="100"></label><br>
|
|
||||||
<label>Offset Distance: <input id="offsetDistanceFrontline" type="number" step="1000"></label><br>
|
<label>Offset Distance: <input id="offsetDistanceFrontline" type="number" step="1000"></label><br>
|
||||||
<label>Style:
|
<label>Style:
|
||||||
<select id="styleFrontline">
|
<select id="styleFrontline">
|
||||||
<option value="leftSide">Left Side</option>
|
<option value=1>Left Side</option>
|
||||||
<option value="rightSide">Right Side</option>
|
<option value=2>Right Side</option>
|
||||||
<option value="bothSides">Both Sides</option>
|
<option value=3>Both Sides</option>
|
||||||
</select>
|
</select>
|
||||||
</label><br>
|
</label><br>
|
||||||
<h4>Protrusion</h4>
|
<h4>Protrusion</h4>
|
||||||
@ -90,10 +90,11 @@ MAPBOX - DRAWING
|
|||||||
<label>End Size: <input id="protrusionEndSize" type="number" step="100"></label><br>
|
<label>End Size: <input id="protrusionEndSize" type="number" step="100"></label><br>
|
||||||
<label>Gap: <input id="protrusionGap" type="number" step="100"></label><br>
|
<label>Gap: <input id="protrusionGap" type="number" step="100"></label><br>
|
||||||
<button id="applyFrontlineChanges">Apply Changes</button>
|
<button id="applyFrontlineChanges">Apply Changes</button>
|
||||||
|
<button id="removeFrontline">Remove Frontline</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="drawStyleButtons" style="position: absolute; top: 10px; left: 50px; background: white; padding: 5px; z-index: 10;">
|
<div id="drawStyleButtons" style="position: absolute; top: 10px; left: 50px; background: white; padding: 5px; z-index: 10;">
|
||||||
<button data-style="frontline" class="active">Frontline</button>
|
<button data-style="frontline">Frontline</button>
|
||||||
<button data-style="arrow">Arrow</button>
|
<button data-style="arrow">Arrow</button>
|
||||||
<!-- další styly můžeš přidat sem -->
|
<!-- další styly můžeš přidat sem -->
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user