Compare commits
9 Commits
7157c2502a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c7d9dcde5e | |||
| 0df4c7777d | |||
| ed42327ff5 | |||
| 3559fd9ecd | |||
| 136cb264a6 | |||
| 478ff1d7d5 | |||
| 89d137e577 | |||
| 4e8169a679 | |||
| 9fadc3681a |
480
Drawing.js
480
Drawing.js
@@ -1,14 +1,14 @@
|
|||||||
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 { getFrontline } from "./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";
|
||||||
|
import { handleDraw, handleClick, showArrowEditor, hideArrowEditor, showFrontlineEditor, hideFrontlineEditor, handleDelete, drawOnMap } from "./DrawingFunctions.js";
|
||||||
|
import { arrowParamsMap, frontlineParamsMap, currentFeature, setCurrentFeature} from "./DrawingFunctions.js";
|
||||||
|
|
||||||
let mouseMoveListener = null;
|
export const ARROW = "arrow";
|
||||||
let currentFeature = null;
|
export const FRONTLINE = "frontline";
|
||||||
let currentDrawStyle = 'arrow';
|
export const ADDITIONAL_SIDE = "additionalSide"; // used for Id in BOTH_SIDES style
|
||||||
|
|
||||||
const arrowParamsMap = new Map();
|
let currentDrawStyle = ARROW;
|
||||||
const frontlineParamsMap = new Map();
|
|
||||||
|
|
||||||
mapboxgl.accessToken = 'pk.eyJ1Ijoib3V0ZG9vcm1hcHBpbmdjb21wYW55IiwiYSI6ImNqYmh3cDdjYzNsMnozNGxsYzlvMmk2bTYifQ.QqcZ4LVoLWnXafXdjZxnZg';
|
mapboxgl.accessToken = 'pk.eyJ1Ijoib3V0ZG9vcm1hcHBpbmdjb21wYW55IiwiYSI6ImNqYmh3cDdjYzNsMnozNGxsYzlvMmk2bTYifQ.QqcZ4LVoLWnXafXdjZxnZg';
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@ const map = new mapboxgl.Map({
|
|||||||
zoom: 5
|
zoom: 5
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Drawing visuals
|
||||||
const draw = new MapboxDraw({
|
const draw = new MapboxDraw({
|
||||||
displayControlsDefault: false,
|
displayControlsDefault: false,
|
||||||
controls: {
|
controls: {
|
||||||
@@ -26,7 +27,7 @@ const draw = new MapboxDraw({
|
|||||||
},
|
},
|
||||||
defaultMode: 'draw_line_string',
|
defaultMode: 'draw_line_string',
|
||||||
styles: [
|
styles: [
|
||||||
// Aktivní linka - úplně průhledná
|
// Main drawing line
|
||||||
{
|
{
|
||||||
id: 'gl-draw-line',
|
id: 'gl-draw-line',
|
||||||
type: 'line',
|
type: 'line',
|
||||||
@@ -36,391 +37,95 @@ const draw = new MapboxDraw({
|
|||||||
'line-join': 'round'
|
'line-join': 'round'
|
||||||
},
|
},
|
||||||
paint: {
|
paint: {
|
||||||
'line-color': '#00ff00', // zelená
|
'line-color': 'rgb(0, 255, 0)',
|
||||||
'line-width': 4
|
'line-width': 4
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Neaktivní linka - taky průhledná
|
// This makes the nonstop visible line invisible
|
||||||
{
|
{
|
||||||
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'
|
||||||
},
|
},
|
||||||
paint: {
|
paint: {
|
||||||
'line-color': 'rgba(0,0,0,0)',
|
'line-color': 'rgba(0, 0, 0, 0)',
|
||||||
'line-width': 2
|
'line-width': 2
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Body (vertexy) - průhledné, pokud chceš
|
// Selected point
|
||||||
{
|
{
|
||||||
id: 'gl-draw-polygon-and-line-vertex-active',
|
id: 'gl-draw-polygon-and-line-vertex-active',
|
||||||
type: 'circle',
|
type: 'circle',
|
||||||
filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'vertex'], ['==', 'active', 'true']],
|
filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'vertex'], ['==', 'active', 'true']],
|
||||||
paint: {
|
paint: {
|
||||||
'circle-radius': 6,
|
'circle-radius': 6,
|
||||||
'circle-color': '#00ff00' // zelená
|
'circle-color': 'rgb(255, 255, 0)'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// Main points
|
||||||
{
|
{
|
||||||
id: 'gl-draw-polygon-and-line-vertex-inactive',
|
id: 'gl-draw-polygon-and-line-vertex-inactive',
|
||||||
type: 'circle',
|
type: 'circle',
|
||||||
filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'vertex'], ['==', 'active', 'false']],
|
filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'vertex'], ['==', 'active', 'false']],
|
||||||
paint: {
|
paint: {
|
||||||
'circle-radius': 4,
|
'circle-radius': 4,
|
||||||
'circle-color': '#00aa00' // tmavší zelená
|
'circle-color': 'rgb(0, 255, 0)'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// Midpoints
|
||||||
// midpointy - musí být viditelné, aby fungovalo kliknutí a přidávání vertexů
|
|
||||||
{
|
{
|
||||||
id: 'gl-draw-polygon-midpoint',
|
id: 'gl-draw-polygon-midpoint',
|
||||||
type: 'circle',
|
type: 'circle',
|
||||||
filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'midpoint']],
|
filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'midpoint']],
|
||||||
paint: { 'circle-radius': 4, 'circle-color': '#fbb03b' } // žlutá
|
paint: {
|
||||||
},
|
'circle-radius': 4,
|
||||||
{
|
'circle-color': 'rgb(0, 255, 174)'
|
||||||
id: 'gl-draw-polygon-midpoint-active',
|
}
|
||||||
type: 'circle',
|
|
||||||
filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'midpoint'], ['==', 'active', 'true']],
|
|
||||||
paint: { 'circle-radius': 6, 'circle-color': '#fbb03b' }
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Map controlls
|
||||||
|
|
||||||
map.addControl(draw, 'top-left');
|
map.addControl(draw, 'top-left');
|
||||||
|
map.on('draw.create', (e) => {
|
||||||
map.on('draw.create', handleDraw);
|
handleDraw(e, map, draw, currentDrawStyle)
|
||||||
map.on('draw.update', handleDraw);
|
});
|
||||||
map.on('click', (e) => {
|
map.on('draw.update', (e) => {
|
||||||
// Hledání šipek
|
handleDraw(e, map, draw, currentDrawStyle)
|
||||||
const arrowFeatures = map.queryRenderedFeatures(e.point, {
|
});
|
||||||
layers: map.getStyle().layers
|
map.on('click', (e) => {
|
||||||
.filter(l => l.id.startsWith('arrow-'))
|
hideArrowEditor();
|
||||||
.map(l => l.id)
|
hideFrontlineEditor();
|
||||||
});
|
handleClick(e, ARROW, arrowParamsMap, showArrowEditor, map, draw, currentDrawStyle);
|
||||||
if (arrowFeatures.length > 0) {
|
handleClick(e, FRONTLINE, frontlineParamsMap, showFrontlineEditor, map, draw, currentDrawStyle);
|
||||||
const arrowFeature = arrowFeatures[0];
|
|
||||||
const featureId = arrowFeature.layer.id.replace('arrow-', '');
|
|
||||||
|
|
||||||
const allFeatures = draw.getAll().features;
|
|
||||||
currentFeature = allFeatures.find(f => f.id === featureId);
|
|
||||||
|
|
||||||
if (currentFeature) {
|
|
||||||
const params = arrowParamsMap.get(featureId);
|
|
||||||
if (params) {
|
|
||||||
showArrowEditor(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
draw.changeMode('direct_select', { featureId: featureId });
|
|
||||||
}
|
|
||||||
return; // pokud kliknul na arrow, dále nekoukáme
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hledání frontlinů
|
|
||||||
const frontlineFeatures = map.queryRenderedFeatures(e.point, {
|
|
||||||
layers: map.getStyle().layers
|
|
||||||
.filter(l => l.id.startsWith('frontline-'))
|
|
||||||
.map(l => l.id)
|
|
||||||
});
|
|
||||||
if (frontlineFeatures.length > 0) {
|
|
||||||
const frontlineFeature = frontlineFeatures[0];
|
|
||||||
const featureId = frontlineFeature.layer.id.replace('frontline-', '');
|
|
||||||
|
|
||||||
const allFeatures = draw.getAll().features;
|
|
||||||
currentFeature = allFeatures.find(f => f.id === featureId);
|
|
||||||
|
|
||||||
if (currentFeature) {
|
|
||||||
const params = frontlineParamsMap.get(featureId);
|
|
||||||
if (params) {
|
|
||||||
showFrontlineEditor(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
map.dragPan.enable();
|
||||||
|
|
||||||
function MyDelete()
|
export function updateButtonStyles(drawStyle) {
|
||||||
{
|
currentDrawStyle = drawStyle;
|
||||||
if (!currentFeature) return;
|
const buttonsContainer = document.getElementById('drawStyleButtons');
|
||||||
|
Array.from(buttonsContainer.querySelectorAll('button')).forEach(btn => {
|
||||||
const id = currentFeature.id;
|
const isSelected = btn.getAttribute('data-style') === drawStyle;
|
||||||
|
btn.style.backgroundColor = isSelected ? '#333' : '#f0f0f0';
|
||||||
draw.delete(id);
|
btn.style.color = isSelected ? '#fff' : '#000';
|
||||||
//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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
|
|
||||||
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
|
|
||||||
frontlineParamsMap.delete(id);
|
|
||||||
|
|
||||||
hideArrowEditor();
|
|
||||||
hideFrontlineEditor();
|
|
||||||
document.getElementById('calculated-area').innerHTML = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleDraw(e) {
|
|
||||||
const feature = e.features[0];
|
|
||||||
|
|
||||||
if (feature.geometry.type !== 'LineString') return;
|
|
||||||
|
|
||||||
const coords = feature.geometry.coordinates;
|
|
||||||
const id = feature.id;
|
|
||||||
|
|
||||||
if (currentDrawStyle === 'arrow') {
|
|
||||||
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 params = arrowParamsMap.get(id);
|
|
||||||
|
|
||||||
const arrowGeoJSON = getArrowPolygon(
|
|
||||||
{ points: coords, splineStep: params.splineStep, offsetDistance: params.offsetDistance },
|
|
||||||
{ calculation: params.calculation, range: params.range, minValue: params.minValue },
|
|
||||||
{ widthArrow: params.widthArrow, lengthArrow: params.lengthArrow }
|
|
||||||
);
|
|
||||||
|
|
||||||
const arrowLayerId = `arrow-${id}`;
|
|
||||||
if (map.getLayer(arrowLayerId)) map.removeLayer(arrowLayerId);
|
|
||||||
if (map.getSource(arrowLayerId)) map.removeSource(arrowLayerId);
|
|
||||||
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 = frontlineParamsMap.get(id);
|
|
||||||
|
|
||||||
const frontlineData = {
|
|
||||||
points: coords,
|
|
||||||
splineStep: params.splineStep,
|
|
||||||
offsetDistance: params.offsetDistance,
|
|
||||||
style: params.style
|
|
||||||
};
|
|
||||||
|
|
||||||
const protrusionData = params.protrusion;
|
|
||||||
|
|
||||||
console.log("Create");
|
|
||||||
console.log(frontlineData);
|
|
||||||
console.log(protrusionData);
|
|
||||||
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;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
drawFrontlineOnMap(polygonToDrawLeft, `frontline-${id}`);
|
|
||||||
drawFrontlineOnMap(polygonToDrawRight, `frontline-${id+1}`);
|
|
||||||
|
|
||||||
const allFeatures = draw.getAll().features;
|
|
||||||
currentFeature = allFeatures.find(f => f.id === id);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const frontlineLayerId = `frontline-${id}`;
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawArrowOnMap(geojson, id) {
|
|
||||||
map.addSource(id, {
|
|
||||||
type: 'geojson',
|
|
||||||
data: geojson
|
|
||||||
});
|
});
|
||||||
|
|
||||||
map.addLayer({
|
|
||||||
id: id,
|
|
||||||
type: 'fill',
|
|
||||||
source: id,
|
|
||||||
paint: {
|
|
||||||
'fill-color': '#ff0000',
|
|
||||||
'fill-opacity': 0.5
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawFrontlineOnMap(frontlineGeoJSON, id) {
|
|
||||||
if (map.getLayer(id)) map.removeLayer(id);
|
|
||||||
if (map.getSource(id)) map.removeSource(id);
|
|
||||||
|
|
||||||
map.addSource(id, {
|
|
||||||
type: 'geojson',
|
|
||||||
data: frontlineGeoJSON
|
|
||||||
});
|
|
||||||
|
|
||||||
map.addLayer({
|
|
||||||
id: id,
|
|
||||||
type: 'fill',
|
|
||||||
source: id,
|
|
||||||
paint: {
|
|
||||||
'fill-color': '#ff6600',
|
|
||||||
'fill-opacity': 0.6,
|
|
||||||
'fill-outline-color': '#cc3300'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearAllArrowLayers() {
|
|
||||||
const allLayerIds = map.getStyle().layers.map(l => l.id);
|
|
||||||
|
|
||||||
allLayerIds.forEach(id => {
|
|
||||||
if (id.startsWith('arrow-')) {
|
|
||||||
if (map.getLayer(id)) map.removeLayer(id);
|
|
||||||
if (map.getSource(id)) map.removeSource(id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function clearAllFrontlineLayers() {
|
|
||||||
const layers = map.getStyle().layers;
|
|
||||||
if (!layers) return;
|
|
||||||
|
|
||||||
layers.forEach(layer => {
|
|
||||||
if (layer.id.startsWith('frontline-')) {
|
|
||||||
if (map.getLayer(layer.id)) map.removeLayer(layer.id);
|
|
||||||
if (map.getSource(layer.id)) map.removeSource(layer.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function showArrowEditor(params) {
|
|
||||||
const popup = document.getElementById('arrow-editor');
|
|
||||||
popup.style.display = 'block';
|
|
||||||
|
|
||||||
popup.style.left = '10px';
|
|
||||||
popup.style.top = '70px';
|
|
||||||
|
|
||||||
document.getElementById('splineStep').value = params.splineStep;
|
|
||||||
document.getElementById('offsetDistance').value = params.offsetDistance;
|
|
||||||
document.getElementById('range').value = params.range;
|
|
||||||
document.getElementById('minValue').value = params.minValue;
|
|
||||||
document.getElementById('widthArrow').value = params.widthArrow;
|
|
||||||
document.getElementById('lengthArrow').value = params.lengthArrow;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function hideArrowEditor() {
|
|
||||||
const popup = document.getElementById('arrow-editor');
|
|
||||||
popup.style.display = 'none';
|
|
||||||
currentFeature = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function showFrontlineEditor(params) {
|
|
||||||
const popup = document.getElementById('frontline-editor');
|
|
||||||
popup.style.display = 'block';
|
|
||||||
|
|
||||||
popup.style.left = '10px';
|
|
||||||
popup.style.top = '70px';
|
|
||||||
|
|
||||||
document.getElementById('splineStepFrontline').value = params.splineStep;
|
|
||||||
document.getElementById('offsetDistanceFrontline').value = params.offsetDistance;
|
|
||||||
document.getElementById('styleFrontline').value = params.style;
|
|
||||||
|
|
||||||
document.getElementById('protrusionLength').value = params.protrusion.length;
|
|
||||||
document.getElementById('protrusionStartSize').value = params.protrusion.startSize;
|
|
||||||
document.getElementById('protrusionEndSize').value = params.protrusion.endSize;
|
|
||||||
document.getElementById('protrusionGap').value = params.protrusion.gap;
|
|
||||||
}
|
|
||||||
|
|
||||||
function hideFrontlineEditor() {
|
|
||||||
const popup = document.getElementById('frontline-editor');
|
|
||||||
popup.style.display = 'none';
|
|
||||||
currentFeature = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
|
||||||
document.getElementById('removeArrow').addEventListener('click', () => {
|
document.getElementById('removeArrow').addEventListener('click', () => {
|
||||||
|
handleDelete(ARROW, map, draw);
|
||||||
MyDelete();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('removeFrontline').addEventListener('click', () => {
|
document.getElementById('removeFrontline').addEventListener('click', () => {
|
||||||
|
handleDelete(FRONTLINE, map, draw);
|
||||||
MyDelete();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('applyArrowChanges').addEventListener('click', () => {
|
document.getElementById('applyArrowChanges').addEventListener('click', () => {
|
||||||
|
|
||||||
if (!currentFeature) return;
|
if (!currentFeature) return;
|
||||||
console.log("Test");
|
|
||||||
const coords = currentFeature.geometry.coordinates;
|
const coords = currentFeature.geometry.coordinates;
|
||||||
const id = currentFeature.id;
|
const id = currentFeature.id;
|
||||||
|
|
||||||
@@ -430,15 +135,27 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const minValue = parseFloat(document.getElementById('minValue').value);
|
const minValue = parseFloat(document.getElementById('minValue').value);
|
||||||
const widthArrow = parseFloat(document.getElementById('widthArrow').value);
|
const widthArrow = parseFloat(document.getElementById('widthArrow').value);
|
||||||
const lengthArrow = parseFloat(document.getElementById('lengthArrow').value);
|
const lengthArrow = parseFloat(document.getElementById('lengthArrow').value);
|
||||||
|
const calculation = parseInt(document.getElementById('styleArrow').value);
|
||||||
|
|
||||||
|
const fillColor = document.getElementById('arrowFillColor').value;
|
||||||
|
const outlineColor = document.getElementById('arrowOutlineColor').value;
|
||||||
|
const opacity = parseFloat(document.getElementById('arrowOpacity').value);
|
||||||
|
|
||||||
|
const paintOptions = {
|
||||||
|
'fill-color': fillColor,
|
||||||
|
'fill-outline-color': outlineColor,
|
||||||
|
'fill-opacity': opacity
|
||||||
|
};
|
||||||
|
|
||||||
arrowParamsMap.set(id, {
|
arrowParamsMap.set(id, {
|
||||||
splineStep,
|
splineStep,
|
||||||
offsetDistance,
|
offsetDistance,
|
||||||
calculation: ARROW_BODY_STYLE_LINEAR,
|
calculation,
|
||||||
range,
|
range,
|
||||||
minValue,
|
minValue,
|
||||||
widthArrow,
|
widthArrow,
|
||||||
lengthArrow
|
lengthArrow,
|
||||||
|
paintOptions
|
||||||
});
|
});
|
||||||
|
|
||||||
const arrowGeoJSON = getArrowPolygon({
|
const arrowGeoJSON = getArrowPolygon({
|
||||||
@@ -446,7 +163,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
splineStep,
|
splineStep,
|
||||||
offsetDistance
|
offsetDistance
|
||||||
}, {
|
}, {
|
||||||
calculation: ARROW_BODY_STYLE_LINEAR,
|
calculation,
|
||||||
range,
|
range,
|
||||||
minValue
|
minValue
|
||||||
}, {
|
}, {
|
||||||
@@ -455,14 +172,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//ARROW
|
//ARROW
|
||||||
const arrowLayerId = `arrow-${id}`;
|
const arrowLayerId = ARROW + "-" + id;
|
||||||
if (map.getLayer(arrowLayerId)) map.removeLayer(arrowLayerId);
|
if (map.getLayer(arrowLayerId)) map.removeLayer(arrowLayerId);
|
||||||
if (map.getSource(arrowLayerId)) map.removeSource(arrowLayerId);
|
if (map.getSource(arrowLayerId)) map.removeSource(arrowLayerId);
|
||||||
|
|
||||||
drawArrowOnMap(arrowGeoJSON, `arrow-${id}`);
|
drawOnMap(arrowGeoJSON, ARROW + "-" + id, paintOptions, map);
|
||||||
|
|
||||||
const allFeatures = draw.getAll().features;
|
const allFeatures = draw.getAll().features;
|
||||||
currentFeature = allFeatures.find(f => f.id === id);
|
setCurrentFeature(allFeatures.find(f => f.id === id));
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('applyFrontlineChanges').addEventListener('click', () => {
|
document.getElementById('applyFrontlineChanges').addEventListener('click', () => {
|
||||||
@@ -480,6 +197,24 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const endSize = parseFloat(document.getElementById('protrusionEndSize').value);
|
const endSize = parseFloat(document.getElementById('protrusionEndSize').value);
|
||||||
const gap = parseFloat(document.getElementById('protrusionGap').value);
|
const gap = parseFloat(document.getElementById('protrusionGap').value);
|
||||||
|
|
||||||
|
const fillColorLeft = document.getElementById('frontlineFillColorLeft').value;
|
||||||
|
const outlineColorLeft = document.getElementById('frontlineOutlineColorLeft').value;
|
||||||
|
const opacityLeft = parseFloat(document.getElementById('frontlineOpacityLeft').value);
|
||||||
|
const paintOptionsLeft = {
|
||||||
|
'fill-color': fillColorLeft,
|
||||||
|
'fill-outline-color': outlineColorLeft,
|
||||||
|
'fill-opacity': opacityLeft
|
||||||
|
};
|
||||||
|
|
||||||
|
const fillColorRight = document.getElementById('frontlineFillColorRight').value;
|
||||||
|
const outlineColorRight = document.getElementById('frontlineOutlineColorRight').value;
|
||||||
|
const opacityRight = parseFloat(document.getElementById('frontlineOpacityRight').value);
|
||||||
|
const paintOptionsRight = {
|
||||||
|
'fill-color': fillColorRight,
|
||||||
|
'fill-outline-color': outlineColorRight,
|
||||||
|
'fill-opacity': opacityRight
|
||||||
|
};
|
||||||
|
|
||||||
frontlineParamsMap.set(id, {
|
frontlineParamsMap.set(id, {
|
||||||
splineStep,
|
splineStep,
|
||||||
offsetDistance,
|
offsetDistance,
|
||||||
@@ -489,7 +224,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
startSize,
|
startSize,
|
||||||
endSize,
|
endSize,
|
||||||
gap
|
gap
|
||||||
}
|
},
|
||||||
|
paintOptionsLeft,
|
||||||
|
paintOptionsRight
|
||||||
});
|
});
|
||||||
|
|
||||||
const frontlineData = {
|
const frontlineData = {
|
||||||
@@ -500,14 +237,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const protrusionData = frontlineParamsMap.get(id).protrusion;
|
const protrusionData = frontlineParamsMap.get(id).protrusion;
|
||||||
|
|
||||||
console.log("Update");
|
|
||||||
console.log(frontlineData);
|
|
||||||
console.log(protrusionData);
|
|
||||||
|
|
||||||
const frontlineGeoJSON = getFrontline(frontlineData, protrusionData);
|
const frontlineGeoJSON = getFrontline(frontlineData, protrusionData);
|
||||||
|
|
||||||
console.log("frontlineGeoJSON", frontlineGeoJSON);
|
|
||||||
let polygonToDraw = frontlineGeoJSON;
|
let polygonToDraw = frontlineGeoJSON;
|
||||||
|
|
||||||
if (frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly) {
|
if (frontlineGeoJSON.leftPoly || frontlineGeoJSON.rightPoly) {
|
||||||
@@ -516,37 +246,38 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if(frontlineGeoJSON.leftPoly && frontlineGeoJSON.rightPoly){
|
if(frontlineGeoJSON.leftPoly && frontlineGeoJSON.rightPoly){
|
||||||
let polygonToDrawLeft = frontlineGeoJSON.leftPoly;
|
let polygonToDrawLeft = frontlineGeoJSON.leftPoly;
|
||||||
let polygonToDrawRight = frontlineGeoJSON.rightPoly;
|
let polygonToDrawRight = frontlineGeoJSON.rightPoly;
|
||||||
|
const frontlineLayerId = FRONTLINE + "-" + id;
|
||||||
|
|
||||||
console.log("polygonToDrawLeft", polygonToDrawLeft);
|
|
||||||
console.log("polygonToDrawRight", polygonToDrawRight);
|
|
||||||
|
|
||||||
const frontlineLayerId = `frontline-${id}`;
|
|
||||||
if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
|
if (map.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
|
||||||
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
|
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
|
||||||
|
|
||||||
console.log(frontlineLayerId);
|
drawOnMap(polygonToDrawLeft, FRONTLINE + "-" + id + ADDITIONAL_SIDE, paintOptionsLeft, map);
|
||||||
console.log(`frontline-${id+1}`);
|
drawOnMap(polygonToDrawRight, FRONTLINE + "-" + (id), paintOptionsRight, map);
|
||||||
drawFrontlineOnMap(polygonToDrawLeft, `frontline-${id}`);
|
|
||||||
drawFrontlineOnMap(polygonToDrawRight, `frontline-${id+1}`);
|
|
||||||
|
|
||||||
const allFeatures = draw.getAll().features;
|
const allFeatures = draw.getAll().features;
|
||||||
currentFeature = allFeatures.find(f => f.id === id);
|
setCurrentFeature(allFeatures.find(f => f.id === id));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (last was both destroy id+1) TODO
|
const frontlineLayerId = FRONTLINE + "-" + id;
|
||||||
console.log("Test2");
|
if (map.getLayer(frontlineLayerId + ADDITIONAL_SIDE)) map.removeLayer(frontlineLayerId + ADDITIONAL_SIDE);
|
||||||
const frontlineLayerId = `frontline-${id}`;
|
if (map.getSource(frontlineLayerId + ADDITIONAL_SIDE)) map.removeSource(frontlineLayerId + ADDITIONAL_SIDE);
|
||||||
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.getLayer(frontlineLayerId)) map.removeLayer(frontlineLayerId);
|
||||||
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
|
if (map.getSource(frontlineLayerId)) map.removeSource(frontlineLayerId);
|
||||||
|
|
||||||
drawFrontlineOnMap(polygonToDraw, `frontline-${id}`);
|
let paintOptions;
|
||||||
|
if(frontlineData.style == LEFT_SIDE){
|
||||||
|
paintOptions = paintOptionsLeft;
|
||||||
|
}else if(frontlineData.style == RIGHT_SIDE)
|
||||||
|
{
|
||||||
|
paintOptions = paintOptionsRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawOnMap(polygonToDraw, FRONTLINE + "-" + id, paintOptions, map);
|
||||||
|
|
||||||
const allFeatures = draw.getAll().features;
|
const allFeatures = draw.getAll().features;
|
||||||
currentFeature = allFeatures.find(f => f.id === id);
|
setCurrentFeature(allFeatures.find(f => f.id === id));
|
||||||
});
|
});
|
||||||
|
|
||||||
const buttonsContainer = document.getElementById('drawStyleButtons');
|
const buttonsContainer = document.getElementById('drawStyleButtons');
|
||||||
@@ -558,15 +289,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
event.target.classList.add('active');
|
event.target.classList.add('active');
|
||||||
|
|
||||||
currentDrawStyle = event.target.getAttribute('data-style');
|
currentDrawStyle = event.target.getAttribute('data-style');
|
||||||
updateButtonStyles();
|
updateButtonStyles(currentDrawStyle);
|
||||||
});
|
});
|
||||||
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';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
updateButtonStyles(currentDrawStyle);
|
||||||
});
|
});
|
||||||
285
DrawingFunctions.js
Normal file
285
DrawingFunctions.js
Normal file
@@ -0,0 +1,285 @@
|
|||||||
|
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 { getFrontline } from "./Frontline.js";
|
||||||
|
import { LEFT_SIDE, RIGHT_SIDE, BOTH_SIDES } from "athena-utils/shape/Frontline.js";
|
||||||
|
import { updateButtonStyles } from "./Drawing.js";
|
||||||
|
import { ARROW, FRONTLINE, ADDITIONAL_SIDE } from "./Drawing.js";
|
||||||
|
|
||||||
|
const DEFAULT_ARROW_PARAMS = {
|
||||||
|
splineStep: 20,
|
||||||
|
offsetDistance: 12000,
|
||||||
|
calculation: ARROW_BODY_STYLE_LINEAR,
|
||||||
|
range: 1,
|
||||||
|
minValue: 0.1,
|
||||||
|
widthArrow: 5,
|
||||||
|
lengthArrow: 8,
|
||||||
|
paintOptions: {
|
||||||
|
"fill-color": "#0099ff",
|
||||||
|
"fill-outline-color": "#005588",
|
||||||
|
"fill-opacity": 0.6
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const DEFAULT_FRONTLINE_PARAMS = {
|
||||||
|
splineStep: 0.08,
|
||||||
|
offsetDistance: 10000,
|
||||||
|
style: LEFT_SIDE,
|
||||||
|
protrusion: {
|
||||||
|
length: 15000,
|
||||||
|
startSize: 5000,
|
||||||
|
endSize: 500,
|
||||||
|
gap: 15000
|
||||||
|
},
|
||||||
|
paintOptionsLeft: {
|
||||||
|
"fill-color": "#00ff37",
|
||||||
|
"fill-outline-color": "#008809",
|
||||||
|
"fill-opacity": 0.6
|
||||||
|
},
|
||||||
|
paintOptionsRight: {
|
||||||
|
"fill-color": "#0011ff",
|
||||||
|
"fill-outline-color": "#002b88",
|
||||||
|
"fill-opacity": 0.6
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export let currentFeature = null;
|
||||||
|
|
||||||
|
export function setCurrentFeature(feature) {
|
||||||
|
currentFeature = feature;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const arrowParamsMap = new Map();
|
||||||
|
export const frontlineParamsMap = new Map();
|
||||||
|
|
||||||
|
export function handleDraw(e, myMap, myDraw, drawStyle) {
|
||||||
|
const feature = e.features[0];
|
||||||
|
const coords = feature.geometry.coordinates;
|
||||||
|
const id = feature.id;
|
||||||
|
|
||||||
|
if (drawStyle === ARROW) {
|
||||||
|
DrawArrow(coords, id, myMap, myDraw);
|
||||||
|
} else if (drawStyle === FRONTLINE) {
|
||||||
|
DrawFrontline(coords, id, myMap, myDraw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handleClick(click, prefix, paramsMap, showEditorFunction, myMap, myDraw, drawStyle) {
|
||||||
|
const features = myMap.queryRenderedFeatures(click.point, {
|
||||||
|
layers: myMap.getStyle().layers
|
||||||
|
.filter(l => l.id.startsWith(prefix + "-"))
|
||||||
|
.map(l => l.id)
|
||||||
|
});
|
||||||
|
|
||||||
|
if (features.length === 0) return;
|
||||||
|
|
||||||
|
drawStyle = prefix;
|
||||||
|
updateButtonStyles(drawStyle);
|
||||||
|
const feature = features[0];
|
||||||
|
const featureId = feature.layer.id.replace(prefix + "-", '');
|
||||||
|
|
||||||
|
const allFeatures = myDraw.getAll().features;
|
||||||
|
currentFeature = allFeatures.find(f => f.id === featureId);
|
||||||
|
|
||||||
|
if (currentFeature) {
|
||||||
|
const params = paramsMap.get(featureId);
|
||||||
|
if (params) {
|
||||||
|
showEditorFunction(params);
|
||||||
|
}
|
||||||
|
myDraw.changeMode('direct_select', { featureId: featureId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function DrawArrow(coordinates, polygonId, myMap, myDraw) {
|
||||||
|
if (!arrowParamsMap.has(polygonId)) {
|
||||||
|
arrowParamsMap.set(polygonId, structuredClone(DEFAULT_ARROW_PARAMS));
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
);
|
||||||
|
updatePolygonOnMap(ARROW, polygonId, drawOnMap, arrowGeoJSON, params.paintOptions, myMap, myDraw);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DrawFrontline(coordinates, polygonId, myMap, myDraw) {
|
||||||
|
if (!frontlineParamsMap.has(polygonId)) {
|
||||||
|
frontlineParamsMap.set(polygonId, structuredClone(DEFAULT_FRONTLINE_PARAMS));
|
||||||
|
}
|
||||||
|
|
||||||
|
const params = frontlineParamsMap.get(polygonId);
|
||||||
|
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, drawOnMap, polygonToDraw, params.paintOptionsLeft, myMap, myDraw);
|
||||||
|
|
||||||
|
let additionalPolygonToDraw = frontlineGeoJSON.rightPoly;
|
||||||
|
|
||||||
|
drawOnMap(additionalPolygonToDraw, FRONTLINE + "-" + (polygonId + ADDITIONAL_SIDE), params.paintOptionsRight, myMap, myDraw);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.style == 1){ // LEFT_SIDE
|
||||||
|
updatePolygonOnMap(FRONTLINE, polygonId, drawOnMap, polygonToDraw, params.paintOptionsLeft, myMap, myDraw);
|
||||||
|
}else if(params.style == 2){ // RIGHT_SIDE
|
||||||
|
updatePolygonOnMap(FRONTLINE, polygonId, drawOnMap, polygonToDraw, params.paintOptionsRight, myMap, myDraw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePolygonOnMap(prefix, polygonId, drawFunction, geojson, paintOptions, myMap, myDraw) {
|
||||||
|
const layerId = prefix + "-" + polygonId;
|
||||||
|
|
||||||
|
if (myMap.getLayer(layerId)) myMap.removeLayer(layerId);
|
||||||
|
if (myMap.getSource(layerId)) myMap.removeSource(layerId);
|
||||||
|
|
||||||
|
drawFunction(geojson, layerId, paintOptions, myMap);
|
||||||
|
|
||||||
|
const allFeatures = myDraw.getAll().features;
|
||||||
|
currentFeature = allFeatures.find(f => f.id === polygonId);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function drawOnMap(frontlineGeoJSON, id, paintOptions = {}, myMap) {
|
||||||
|
if (myMap.getLayer(id)) myMap.removeLayer(id);
|
||||||
|
if (myMap.getSource(id)) myMap.removeSource(id);
|
||||||
|
|
||||||
|
myMap.addSource(id, {
|
||||||
|
type: 'geojson',
|
||||||
|
data: frontlineGeoJSON
|
||||||
|
});
|
||||||
|
|
||||||
|
myMap.addLayer({
|
||||||
|
id: id,
|
||||||
|
type: 'fill',
|
||||||
|
source: id,
|
||||||
|
paint: {
|
||||||
|
'fill-color': paintOptions['fill-color'],
|
||||||
|
'fill-opacity': paintOptions['fill-opacity'],
|
||||||
|
'fill-outline-color': paintOptions['fill-outline-color']
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function handleDelete(polygonType, myMap, myDraw)
|
||||||
|
{
|
||||||
|
if (!currentFeature) return;
|
||||||
|
|
||||||
|
const id = currentFeature.id;
|
||||||
|
myDraw.delete(id);
|
||||||
|
|
||||||
|
//ARROW
|
||||||
|
if(polygonType == ARROW){
|
||||||
|
const arrowLayerId = polygonType + "-" + id;
|
||||||
|
DeleteFromMap(arrowLayerId, id, myMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Frontline
|
||||||
|
if(polygonType == FRONTLINE){
|
||||||
|
const frontlineLayerId = polygonType + "-" + id;
|
||||||
|
|
||||||
|
if (frontlineParamsMap.get(id).style == 3){ //BOTH_SIDES
|
||||||
|
const frontlineLayerIdB = polygonType + "-" + (id + ADDITIONAL_SIDE);
|
||||||
|
|
||||||
|
DeleteFromMap(frontlineLayerId, id, myMap);
|
||||||
|
DeleteFromMap(frontlineLayerIdB, id + ADDITIONAL_SIDE, myMap);
|
||||||
|
hideArrowEditor();
|
||||||
|
hideFrontlineEditor();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeleteFromMap(frontlineLayerId, id, myMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
hideArrowEditor();
|
||||||
|
hideFrontlineEditor();
|
||||||
|
}
|
||||||
|
|
||||||
|
function DeleteFromMap(layerId, FeatureId, myMap){
|
||||||
|
if (myMap.getLayer(layerId)) myMap.removeLayer(layerId);
|
||||||
|
if (myMap.getSource(layerId)) myMap.removeSource(layerId);
|
||||||
|
|
||||||
|
arrowParamsMap.delete(FeatureId);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showArrowEditor(params) {
|
||||||
|
const popup = document.getElementById('arrow-editor');
|
||||||
|
popup.style.display = 'block';
|
||||||
|
popup.style.left = '10px';
|
||||||
|
popup.style.top = '70px';
|
||||||
|
|
||||||
|
document.getElementById('splineStep').value = params.splineStep;
|
||||||
|
document.getElementById('offsetDistance').value = params.offsetDistance;
|
||||||
|
document.getElementById('range').value = params.range;
|
||||||
|
document.getElementById('minValue').value = params.minValue;
|
||||||
|
document.getElementById('widthArrow').value = params.widthArrow;
|
||||||
|
document.getElementById('lengthArrow').value = params.lengthArrow;
|
||||||
|
document.getElementById('styleArrow').value = params.calculation;
|
||||||
|
|
||||||
|
document.getElementById('arrowFillColor').value = params.paintOptions["fill-color"];
|
||||||
|
document.getElementById('arrowOutlineColor').value = params.paintOptions["fill-outline-color"];
|
||||||
|
parseFloat(document.getElementById('arrowOpacity').value = params.paintOptions["fill-opacity"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hideArrowEditor() {
|
||||||
|
const popup = document.getElementById('arrow-editor');
|
||||||
|
popup.style.display = 'none';
|
||||||
|
currentFeature = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showFrontlineEditor(params) {
|
||||||
|
const popup = document.getElementById('frontline-editor');
|
||||||
|
popup.style.display = 'block';
|
||||||
|
popup.style.left = '10px';
|
||||||
|
popup.style.top = '70px';
|
||||||
|
|
||||||
|
document.getElementById('splineStepFrontline').value = params.splineStep;
|
||||||
|
document.getElementById('offsetDistanceFrontline').value = params.offsetDistance;
|
||||||
|
document.getElementById('styleFrontline').value = params.style;
|
||||||
|
|
||||||
|
document.getElementById('protrusionLength').value = params.protrusion.length;
|
||||||
|
document.getElementById('protrusionStartSize').value = params.protrusion.startSize;
|
||||||
|
document.getElementById('protrusionEndSize').value = params.protrusion.endSize;
|
||||||
|
document.getElementById('protrusionGap').value = params.protrusion.gap;
|
||||||
|
|
||||||
|
document.getElementById('frontlineFillColorLeft').value = params.paintOptionsLeft["fill-color"];
|
||||||
|
document.getElementById('frontlineOutlineColorLeft').value = params.paintOptionsLeft["fill-outline-color"];
|
||||||
|
parseFloat(document.getElementById('frontlineOpacityLeft').value = params.paintOptionsLeft["fill-opacity"]);
|
||||||
|
|
||||||
|
document.getElementById('frontlineFillColorRight').value = params.paintOptionsRight["fill-color"];
|
||||||
|
document.getElementById('frontlineOutlineColorRight').value = params.paintOptionsRight["fill-outline-color"];
|
||||||
|
parseFloat(document.getElementById('frontlineOpacityRight').value = params.paintOptionsRight["fill-opacity"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hideFrontlineEditor() {
|
||||||
|
const popup = document.getElementById('frontline-editor');
|
||||||
|
popup.style.display = 'none';
|
||||||
|
currentFeature = null;
|
||||||
|
}
|
||||||
@@ -182,7 +182,7 @@ function computeProtrusion(leftSidePoints, protrusionData, sideOffset) {
|
|||||||
const localDistance = distance - currentSegmentPos;
|
const localDistance = distance - currentSegmentPos;
|
||||||
|
|
||||||
const pointOnSegment = turf.along(turf.lineString([seg.p0, seg.p1]), localDistance, { units: METERS }).geometry.coordinates;
|
const pointOnSegment = turf.along(turf.lineString([seg.p0, seg.p1]), localDistance, { units: METERS }).geometry.coordinates;
|
||||||
const thicknessOffset = sideOffset * 0.2;
|
const thicknessOffset = sideOffset * 0.1;
|
||||||
|
|
||||||
const adjustedPoint = movePoint(pointOnSegment, thicknessOffset, seg.bearing + 90);
|
const adjustedPoint = movePoint(pointOnSegment, thicknessOffset, seg.bearing + 90);
|
||||||
const centerPoint = movePoint(adjustedPoint, protrusionData.length, seg.bearing - 90);
|
const centerPoint = movePoint(adjustedPoint, protrusionData.length, seg.bearing - 90);
|
||||||
|
|||||||
37
index.html
37
index.html
@@ -59,8 +59,6 @@ MAPBOX - DRAWING
|
|||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
<!-- Editor parametrů šipky -->
|
|
||||||
<div id="arrow-editor" style="position: absolute; background: white; padding: 10px; border: 1px solid #ccc; display: none; z-index: 1000;">
|
<div id="arrow-editor" style="position: absolute; background: white; padding: 10px; border: 1px solid #ccc; display: none; z-index: 1000;">
|
||||||
<h3>Arrow Editor</h3>
|
<h3>Arrow Editor</h3>
|
||||||
<label>Spline Step: <input id="splineStep" type="number" step="1"></label><br>
|
<label>Spline Step: <input id="splineStep" type="number" step="1"></label><br>
|
||||||
@@ -69,8 +67,23 @@ MAPBOX - DRAWING
|
|||||||
<label>Min Value: <input id="minValue" type="number" step="0.1" min="0"></label><br>
|
<label>Min Value: <input id="minValue" type="number" step="0.1" min="0"></label><br>
|
||||||
<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>
|
||||||
|
|
||||||
|
<label>Style:
|
||||||
|
<select id="styleArrow">
|
||||||
|
<option value=1>Constant</option>
|
||||||
|
<option value=2>Linear</option>
|
||||||
|
<option value=3>Exponential</option>
|
||||||
|
</select>
|
||||||
|
</label><br>
|
||||||
|
|
||||||
|
<h4>Styling</h4>
|
||||||
|
<label>Fill Color: <input id="arrowFillColor" type="color" value="#000000"></label><br>
|
||||||
|
<label>Outline Color: <input id="arrowOutlineColor" type="color" value="#000000"></label><br>
|
||||||
|
<label>Opacity: <input id="arrowOpacity" type="number" min="0" max="1" step="0.1" value="0.6"></label><br>
|
||||||
|
|
||||||
<button id="applyArrowChanges">Apply Changes</button>
|
<button id="applyArrowChanges">Apply Changes</button>
|
||||||
<button id="removeArrow">Remove Arrow</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;">
|
||||||
@@ -89,6 +102,17 @@ MAPBOX - DRAWING
|
|||||||
<label>Start Size: <input id="protrusionStartSize" type="number" step="100"></label><br>
|
<label>Start Size: <input id="protrusionStartSize" type="number" step="100"></label><br>
|
||||||
<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>
|
||||||
|
|
||||||
|
<h4>Styling right side</h4>
|
||||||
|
<label>Fill Color: <input id="frontlineFillColorRight" type="color" value="#000000"></label><br>
|
||||||
|
<label>Outline Color: <input id="frontlineOutlineColorRight" type="color" value="#000000"></label><br>
|
||||||
|
<label>Opacity: <input id="frontlineOpacityRight" type="number" min="0" max="1" step="0.1" value="0.6"></label><br>
|
||||||
|
|
||||||
|
<h4>Styling left side</h4>
|
||||||
|
<label>Fill Color: <input id="frontlineFillColorLeft" type="color" value="#000000"></label><br>
|
||||||
|
<label>Outline Color: <input id="frontlineOutlineColorLeft" type="color" value="#000000"></label><br>
|
||||||
|
<label>Opacity: <input id="frontlineOpacityLeft" type="number" min="0" max="1" step="0.1" value="0.6"></label><br>
|
||||||
|
|
||||||
<button id="applyFrontlineChanges">Apply Changes</button>
|
<button id="applyFrontlineChanges">Apply Changes</button>
|
||||||
<button id="removeFrontline">Remove Frontline</button>
|
<button id="removeFrontline">Remove Frontline</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -96,16 +120,7 @@ MAPBOX - DRAWING
|
|||||||
<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">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 -->
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Box pro výpis -->
|
|
||||||
<div class="calculation-box">
|
|
||||||
<p>Click the map to draw a polygon.</p>
|
|
||||||
<div id="calculated-area"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Hlavní JS -->
|
|
||||||
<script type="module" src="Drawing.js"></script>
|
<script type="module" src="Drawing.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user