Rework filename dialog

This commit is contained in:
Antonia 2025-05-02 23:23:22 +02:00
parent 9b29a713a9
commit c4661546f2

View file

@ -289,6 +289,7 @@ let editing
async function resetEditing() { async function resetEditing() {
editFilename = undefined; editFilename = undefined;
document.querySelector('#featurename').value = ""
editing = false editing = false
document.querySelector('#featurename').innerHTML = "" document.querySelector('#featurename').innerHTML = ""
} }
@ -297,11 +298,10 @@ 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) {
if (editing) { if (markers.length > 0) {
return return
} }
L.DomEvent.stopPropagation(e) L.DomEvent.stopPropagation(e)
@ -314,6 +314,7 @@ async function whenClicked(e, feature, filename) {
mark.on('click', startEdit) mark.on('click', startEdit)
} }
editFilename = filename editFilename = filename
document.querySelector('#featurename').value = editFilename
} }
@ -361,7 +362,7 @@ async function pickDirectory(e){
alert("There is no path to save!"); alert("There is no path to save!");
return; return;
} }
const filename = window.prompt("Enter filename:", editFilename ?? "feature"); const filename = document.querySelector('#featurename').value
if (!filename) { if (!filename) {
return; return;
} }
@ -385,7 +386,7 @@ async function pickDirectory(e){
alert(`Could not open file: ${error.message}`); alert(`Could not open file: ${error.message}`);
return return
} }
if (filename != editFilename) { if (editFilename != undefined && filename != editFilename) {
await dirHandle.removeEntry(editFilename) await dirHandle.removeEntry(editFilename)
} }
const blob = new Blob([JSON.stringify(dat)]); const blob = new Blob([JSON.stringify(dat)]);
@ -415,7 +416,7 @@ if (edit) {
buttonDiv.innerHTML = `<button id="edit-mode" onClick="pickDirectory(event)" >Edit</button> buttonDiv.innerHTML = `<button id="edit-mode" onClick="pickDirectory(event)" >Edit</button>
<div class="edit-ui"> <div class="edit-ui">
<div id="layername" ></div> <div id="layername" ></div>
<div id="featurename"></div> <label for="featurename">Filename</label><br><input type="text" id="featurename"><br>
<label for="brouter-profile">Brouter Profile</label><br> <label for="brouter-profile">Brouter Profile</label><br>
<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>