Keep the placed point on screen until it becomes the marker

Placing a point with Draw > Point removed it immediately and opened the Add
Location form, so the officer filled in a form with nothing at the spot they had
just tapped, and a marker then appeared from nowhere. Nothing visibly turned
into anything, which is what made it read as broken.

The sketch now stays until the form closes. On save the marker has already been
added by then, so the point is replaced by it; on cancel, or on leaving the
drawing tools with the form still open, it is simply discarded. Placing a second
point while a form is open replaces the pending sketch rather than leaving the
first one behind.

Marker loading is also taken out of the undo history. Entering edit mode calls
UndoRedo._watchSources(), which picks up every vector source including the
markers — so reloading the Locations list registered as two undoable edits, and
Undo after saving a location stripped the markers off the map while leaving the
row in the database. That is the same "my point disappeared" symptom by another
route. clearMarkers() uses _silentClearSource for the reason already documented
on the vertex overlay: ol-ext patches VectorSource.clear to fire block events
that the record flag does not gate.

Verified all three endings — save, cancel, and abandoning by leaving Digitise —
plus placing a second point mid-form, and that the undo stack stays empty
through the whole sequence with recording switched back on afterwards.

Service Worker v21 -> v22.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ekke 2026-08-21 09:45:58 +02:00
parent f92a3d43c1
commit 5967b99a73
9 changed files with 83 additions and 28 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
dist/assets/index-D2LXdMvQ.js.map vendored Normal file

File diff suppressed because one or more lines are too long

2
dist/index.html vendored
View File

@ -1917,7 +1917,7 @@
} }
</style> </style>
<script type="module" crossorigin src="/assets/index-BQfxXCp7.js"></script> <script type="module" crossorigin src="/assets/index-D2LXdMvQ.js"></script>
<link rel="modulepreload" crossorigin href="/assets/openlayers-J9qS6Th1.js"> <link rel="modulepreload" crossorigin href="/assets/openlayers-J9qS6Th1.js">
<link rel="modulepreload" crossorigin href="/assets/pako-Xa-UToif.js"> <link rel="modulepreload" crossorigin href="/assets/pako-Xa-UToif.js">
<link rel="modulepreload" crossorigin href="/assets/geotiff-BaoeLn6q.js"> <link rel="modulepreload" crossorigin href="/assets/geotiff-BaoeLn6q.js">

9
dist/sw.js vendored
View File

@ -118,7 +118,14 @@
// point placed with Draw > Point was written to the database and the map // point placed with Draw > Point was written to the database and the map
// panned to it with nothing to see. Creating a location, or picking one // panned to it with nothing to see. Creating a location, or picking one
// from the Locations list, now switches the layer on. // from the Locations list, now switches the layer on.
const CACHE_VERSION = 'v21'; // v22: The point placed with Draw > Point now stays on screen while the Add
// Location form is open, so it visibly becomes the marker on save instead
// of vanishing and a marker appearing from nowhere. It is discarded when
// the form closes, either way. Marker loading is also kept out of the undo
// history: entering edit mode makes UndoRedo watch every source, so Undo
// after saving a location used to strip the markers off the map while
// leaving the row in the database.
const CACHE_VERSION = 'v22';
const SHELL_CACHE = `shell-${CACHE_VERSION}`; const SHELL_CACHE = `shell-${CACHE_VERSION}`;
const MODULES_CACHE = `modules-${CACHE_VERSION}`; const MODULES_CACHE = `modules-${CACHE_VERSION}`;
const API_CACHE = `api-${CACHE_VERSION}`; const API_CACHE = `api-${CACHE_VERSION}`;

View File

@ -118,7 +118,14 @@
// point placed with Draw > Point was written to the database and the map // point placed with Draw > Point was written to the database and the map
// panned to it with nothing to see. Creating a location, or picking one // panned to it with nothing to see. Creating a location, or picking one
// from the Locations list, now switches the layer on. // from the Locations list, now switches the layer on.
const CACHE_VERSION = 'v21'; // v22: The point placed with Draw > Point now stays on screen while the Add
// Location form is open, so it visibly becomes the marker on save instead
// of vanishing and a marker appearing from nowhere. It is discarded when
// the form closes, either way. Marker loading is also kept out of the undo
// history: entering edit mode makes UndoRedo watch every source, so Undo
// after saving a location used to strip the markers off the map while
// leaving the row in the database.
const CACHE_VERSION = 'v22';
const SHELL_CACHE = `shell-${CACHE_VERSION}`; const SHELL_CACHE = `shell-${CACHE_VERSION}`;
const MODULES_CACHE = `modules-${CACHE_VERSION}`; const MODULES_CACHE = `modules-${CACHE_VERSION}`;
const API_CACHE = `api-${CACHE_VERSION}`; const API_CACHE = `api-${CACHE_VERSION}`;

View File

@ -537,22 +537,23 @@ export class MapView {
const coordinate = evt.feature?.getGeometry?.()?.getCoordinates?.(); const coordinate = evt.feature?.getGeometry?.()?.getCoordinates?.();
if (!coordinate) return; if (!coordinate) return;
// ol adds the sketch to the source *after* this handler returns, so the // The sketch stays on screen while the form is open, as the anchor for
// add and its removal straddle a tick. Recording has to be suppressed // what is being named — removing it here left the officer filling in a
// across both: suppressing only the removal leaves the add on the undo // form with nothing at the spot they had just tapped, and a marker then
// stack, and pressing Undo would then resurrect a point the officer // appearing from nowhere. hideAddLocationPopup() discards it, so it is
// never kept. // replaced by the marker on save and cleaned up on cancel either way.
// Any sketch still pending belongs to a form that is no longer open.
this._discardPendingLocationSketch();
this._pendingLocationSketch = evt.feature;
// ol adds the sketch to the source *after* this handler returns. Keep
// that add off the undo stack: the sketch is transient scaffolding, and
// recording it means Undo can resurrect a point the officer never kept.
const undoRedo = this._undoRedo; const undoRedo = this._undoRedo;
const wasRecording = undoRedo?._record; const wasRecording = undoRedo?._record;
if (undoRedo) undoRedo._record = false; if (undoRedo) undoRedo._record = false;
setTimeout(() => { setTimeout(() => {
try {
this.drawingsSource.removeFeature(evt.feature);
} catch {
// Already gone (e.g. the layer was cleared) — nothing to undo.
} finally {
if (undoRedo) undoRedo._record = wasRecording; if (undoRedo) undoRedo._record = wasRecording;
}
}, 0); }, 0);
for (const cb of this._drawnPointCallbacks || []) { for (const cb of this._drawnPointCallbacks || []) {
@ -996,6 +997,13 @@ export class MapView {
this.touchCursor.setActive(this._editBarActive); this.touchCursor.setActive(this._editBarActive);
} }
// Leaving edit mode abandons any half-finished Add Location, so its sketch
// goes too. main.js also hides the popup on the way out; this covers callers
// that switch edit mode directly.
if (!this._editBarActive) {
this._discardPendingLocationSketch();
}
// Clear persistent vertex highlights when leaving edit mode (excluded // Clear persistent vertex highlights when leaving edit mode (excluded
// from the undo stack — see _withoutUndoRecording / _silentClearSource). // from the undo stack — see _withoutUndoRecording / _silentClearSource).
if (!this._editBarActive && this._vertexOverlaySource) { if (!this._editBarActive && this._vertexOverlaySource) {
@ -2925,6 +2933,30 @@ export class MapView {
hideAddLocationPopup() { hideAddLocationPopup() {
this.addLocationPopup.setPosition(undefined); this.addLocationPopup.setPosition(undefined);
this.addLocationCoords = null; this.addLocationCoords = null;
// The popup closing is the end of that point's life either way: on save the
// marker has already been added and now takes its place, and on cancel there
// is nothing to keep.
this._discardPendingLocationSketch();
}
/**
* Remove the sketch left by Draw Point once its Add Location form is done.
*
* Kept off the undo stack to match the add the pair is scaffolding for
* placing a marker, not an edit the officer should be able to step back into.
* @private
*/
_discardPendingLocationSketch() {
const sketch = this._pendingLocationSketch;
if (!sketch) return;
this._pendingLocationSketch = null;
this._withoutUndoRecording(() => {
try {
this.drawingsSource.removeFeature(sketch);
} catch {
// Already gone (e.g. the layer was cleared) — nothing to do.
}
});
} }
/** /**
@ -3538,7 +3570,12 @@ export class MapView {
return feature; return feature;
}); });
this.markerSource.addFeatures(features); // Kept off the undo stack. Entering edit mode calls UndoRedo._watchSources(),
// which picks up every vector source including this one — so reloading the
// Locations list would otherwise register as an undoable edit, and Undo
// after saving a location would strip the markers off the map while leaving
// the row in the database. Undo belongs to drawing, not to the locations list.
this._withoutUndoRecording(() => this.markerSource.addFeatures(features));
console.log('[MapView] Markers added, total features:', this.markerSource.getFeatures().length); console.log('[MapView] Markers added, total features:', this.markerSource.getFeatures().length);
return features; return features;
} }
@ -3547,7 +3584,11 @@ export class MapView {
* Clear all markers * Clear all markers
*/ */
clearMarkers() { clearMarkers() {
this.markerSource.clear(); // _silentClearSource rather than clear(): ol-ext patches VectorSource.clear
// to fire clearstart/clearend, which drive UndoRedo's block events and are
// NOT gated by the record flag. See the note on addMarkers for why the
// markers source stays out of the undo history.
this._withoutUndoRecording(() => this._silentClearSource(this.markerSource));
this.selectedFeature = null; this.selectedFeature = null;
} }