Rework save button
This commit is contained in:
parent
8c053140a6
commit
9b29a713a9
1 changed files with 17 additions and 4 deletions
|
@ -197,6 +197,8 @@ async function updateBrouter () {
|
||||||
}
|
}
|
||||||
markers[markers.length-1]._icon.classList.add("red");
|
markers[markers.length-1]._icon.classList.add("red");
|
||||||
markers[0]._icon.classList.add("green");
|
markers[0]._icon.classList.add("green");
|
||||||
|
} else {
|
||||||
|
resetEditing()
|
||||||
}
|
}
|
||||||
geojsons = [];
|
geojsons = [];
|
||||||
recompute_anglemarkers(geojsons);
|
recompute_anglemarkers(geojsons);
|
||||||
|
@ -204,6 +206,7 @@ async function updateBrouter () {
|
||||||
map.removeLayer(geojson);
|
map.removeLayer(geojson);
|
||||||
}
|
}
|
||||||
if (markers.length < 2) {
|
if (markers.length < 2) {
|
||||||
|
document.querySelector("#save").disabled = true
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (let i = 0; i < markers.length - 1 ; i++) {
|
for (let i = 0; i < markers.length - 1 ; i++) {
|
||||||
|
@ -221,6 +224,7 @@ async function updateBrouter () {
|
||||||
if (geojson != undefined) {
|
if (geojson != undefined) {
|
||||||
map.removeLayer(geojson);
|
map.removeLayer(geojson);
|
||||||
}
|
}
|
||||||
|
document.querySelector("#save").disabled = false
|
||||||
delete data.features[0].properties.messages;
|
delete data.features[0].properties.messages;
|
||||||
geojsons.push(data.features[0]);
|
geojsons.push(data.features[0]);
|
||||||
recompute_anglemarkers(geojsons);
|
recompute_anglemarkers(geojsons);
|
||||||
|
@ -236,6 +240,10 @@ async function updateBrouter () {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addBrouterMarker(pos) {
|
async function addBrouterMarker(pos) {
|
||||||
|
if (!editing) {
|
||||||
|
editFilename = undefined
|
||||||
|
}
|
||||||
|
purgeLayer(endmarkers)
|
||||||
const marker = new L.marker(pos, {draggable: true}) ;
|
const marker = new L.marker(pos, {draggable: true}) ;
|
||||||
markers.push(marker);
|
markers.push(marker);
|
||||||
marker.on("click", function(e) {
|
marker.on("click", function(e) {
|
||||||
|
@ -279,10 +287,17 @@ const mapJSONs = {}
|
||||||
let editFilename
|
let editFilename
|
||||||
let editing
|
let editing
|
||||||
|
|
||||||
|
async function resetEditing() {
|
||||||
|
editFilename = undefined;
|
||||||
|
editing = false
|
||||||
|
document.querySelector('#featurename').innerHTML = ""
|
||||||
|
}
|
||||||
|
|
||||||
async function startEdit(e) {
|
async function startEdit(e) {
|
||||||
editing = true
|
editing = true
|
||||||
purgeLayer(endmarkers)
|
purgeLayer(endmarkers)
|
||||||
addBrouterMarker(this._latlng)
|
addBrouterMarker(this._latlng)
|
||||||
|
document.querySelector('#featurename').innerHTML = `Editing ${editFilename.replace(/\.geojson$|\.json$/,"")}</br>`
|
||||||
}
|
}
|
||||||
|
|
||||||
async function whenClicked(e, feature, filename) {
|
async function whenClicked(e, feature, filename) {
|
||||||
|
@ -299,7 +314,6 @@ async function whenClicked(e, feature, filename) {
|
||||||
mark.on('click', startEdit)
|
mark.on('click', startEdit)
|
||||||
}
|
}
|
||||||
editFilename = filename
|
editFilename = filename
|
||||||
document.querySelector('#featurename').innerHTML = `Editing ${editFilename.replace(/\.geojson$|\.json$/,"")}</br>`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -384,8 +398,7 @@ async function pickDirectory(e){
|
||||||
}
|
}
|
||||||
markers = [];
|
markers = [];
|
||||||
updateBrouter();
|
updateBrouter();
|
||||||
editing = false;
|
resetEditing();
|
||||||
editFilename = undefined;
|
|
||||||
alert("Saved file!");
|
alert("Saved file!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -407,7 +420,7 @@ if (edit) {
|
||||||
<input type="text" id="brouter-profile" onchange="updateBrouter()" ><br>
|
<input type="text" id="brouter-profile" onchange="updateBrouter()" ><br>
|
||||||
<label for="angle">Turn restriction sensitivity</label><br>
|
<label for="angle">Turn restriction sensitivity</label><br>
|
||||||
<input type="range" min="0" step="0.05" max="1" value="0.35" class="slider" id="angle" onchange="recompute_anglemarkers(geojsons)" ><br>
|
<input type="range" min="0" step="0.05" max="1" value="0.35" class="slider" id="angle" onchange="recompute_anglemarkers(geojsons)" ><br>
|
||||||
<button id="save" onClick="pickDirectory(event)" >Save</button><button id="quit" onclick="quitEdit(event)" >Quit</button>
|
<button id="save" onClick="pickDirectory(event)" disabled>Save</button><button id="quit" onclick="quitEdit(event)" >Quit</button>
|
||||||
</div>`
|
</div>`
|
||||||
} else {
|
} else {
|
||||||
buttonDiv.innerHTML = "Your browser does not support editing. <br> As of 2025, editing is supported on Chromium-based browsers only.";
|
buttonDiv.innerHTML = "Your browser does not support editing. <br> As of 2025, editing is supported on Chromium-based browsers only.";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue