This commit is contained in:
+28
-5
@@ -126,6 +126,26 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
return text(poi?.id ?? poi?.poiId);
|
||||
}
|
||||
|
||||
function numericPoiId(value) {
|
||||
const raw = text(value).trim();
|
||||
if (!raw) return null;
|
||||
const parsed = Number(raw);
|
||||
return Number.isSafeInteger(parsed) && parsed >= 0 ? parsed : null;
|
||||
}
|
||||
|
||||
function nextLocalPoiId() {
|
||||
let highest = -1;
|
||||
for (const poi of state.pois) {
|
||||
const identifier = numericPoiId(poi?.id ?? poi?.poiId);
|
||||
if (identifier != null && identifier > highest) highest = identifier;
|
||||
}
|
||||
const next = highest + 1;
|
||||
if (!Number.isSafeInteger(next)) {
|
||||
throw new Error('Für diese lokale Strecke kann keine weitere Streckenpunkt-ID vergeben werden.');
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
function routeName(route) {
|
||||
return text(route?.name || route?.title || 'Unbenannte Strecke');
|
||||
}
|
||||
@@ -479,7 +499,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
byId(ids.routeName).value = routeName(route) === 'Unbenannte Strecke' ? '' : routeName(route);
|
||||
byId(ids.routeDescription).value = text(route?.description);
|
||||
byId(ids.routeGpx).value = '';
|
||||
setHidden(byId(ids.routeGpxGroup), !routeId(route));
|
||||
setHidden(byId(ids.routeGpxGroup), state.currentSource !== 'server');
|
||||
|
||||
const uploadButton = byId(ids.routeUpload);
|
||||
if (state.currentSource === 'local') {
|
||||
@@ -983,7 +1003,9 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
|
||||
const accuracy = Number(position?.accuracy);
|
||||
state.currentPoi = null;
|
||||
const identifier = state.currentSource === 'local' ? nextLocalPoiId() : null;
|
||||
fillPoiForm({
|
||||
...(identifier == null ? {} : { id: identifier }),
|
||||
lat,
|
||||
lon,
|
||||
triggerRadiusM: Number.isFinite(accuracy) && accuracy > 0 ? accuracy : 25
|
||||
@@ -1062,9 +1084,10 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
if (!Number.isFinite(values.lat) || !Number.isFinite(values.lon)) {
|
||||
throw new TypeError('Für einen Streckenpunkt sind gültige Breiten- und Längengrade erforderlich.');
|
||||
}
|
||||
const currentId = Number(byId(ids.poiId).value);
|
||||
const identifier = Number.isSafeInteger(currentId) ? currentId : ns.LocalRoutes.createPoiId();
|
||||
const existing = state.pois.find(poi => Number(poi.id) === identifier) || state.currentPoi;
|
||||
const currentId = numericPoiId(byId(ids.poiId).value);
|
||||
const identifier = currentId ?? nextLocalPoiId();
|
||||
byId(ids.poiId).value = String(identifier);
|
||||
const existing = state.pois.find(poi => numericPoiId(poi?.id ?? poi?.poiId) === identifier) || state.currentPoi;
|
||||
const media = await mediaFromLocalForm(existing, identifier);
|
||||
const savedPoi = {
|
||||
...existing,
|
||||
@@ -1074,7 +1097,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
id: identifier,
|
||||
sequence: existing?.sequence ?? state.pois.length
|
||||
};
|
||||
const index = state.pois.findIndex(poi => Number(poi.id) === identifier);
|
||||
const index = state.pois.findIndex(poi => numericPoiId(poi?.id ?? poi?.poiId) === identifier);
|
||||
if (index >= 0) state.pois[index] = savedPoi;
|
||||
else state.pois.push(savedPoi);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user