Skip to content

feat(karte): download offline Kartenpakete and show them as a map - #789

Closed
DeepDiver1975 wants to merge 3 commits into
mainfrom
feat/karte-offline-kartenpakete
Closed

DeepDiver1975 wants to merge 3 commits into
mainfrom
feat/karte-offline-kartenpakete

Conversation

@DeepDiver1975

@DeepDiver1975 DeepDiver1975 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

First of four PRs towards a Lagekarte in Führung (Einsatzort and vehicles on an offline map). This one is the groundwork: offline Kartenpakete on the device, and a map that shows them. No incident data is touched yet.

What it does

Deviation from the plan: packs are device-local, not Stammdaten

The salvage stored the pack's folder path in MasterDataSet. But Stammdaten travel to every joined client over /masterdata, and a Windows host's folder means nothing on an Android tablet. So packs live in <app data>/regions/<slug>/ with their own pack.json, the Karten section acts immediately and never marks the editor dirty, and the editor keeps the one section instance across a reload so a running download is not lost. docs/master-data.example.json and the wire are unchanged.

Security

Catalogue and zip cross a trust boundary:

  • catalogue capped at 1 MB / 500 entries; entries with a slug that could name a path, a bounding box off the globe, or a non-numeric size are skipped (the slug regex uses \z, since .NET's $ lets ffb\n through);
  • https only, refused before any request otherwise; the body is cut off at the size the catalogue declared, Content-Length or not; hard cap 1 GB zipped / 2 GB unpacked;
  • only region.mbtiles and region.dem are unpacked, under fixed names — no entry name ever reaches a path;
  • install goes through a staging folder and a folder swap, so a failed update leaves the older copy;
  • Remove re-contains the folder, so a tampered pack.json cannot delete outside regions/.

Each has a test that replays it. docs/datenschutz-und-sicherheit.md now lists the pack download as the fifth way data leaves the device (GitHub sees the IP and which pack, nothing about an Einsatz), and regions/ in the stored-files table.

Screenshots

Before — no Karten section:

Before

After — Stammdaten → Karten with the published Fürstenfeldbruck pack (diagnostic render, the committed test uses a fictional pack):

After

Verification

  • make clean ci: 0 warnings, 0 errors, every test assembly passed, no Test Run Failed.
  • make format-check passed.
  • New tests: Domain 10, Persistence 12, AppLogic 135 (incl. editor tests), Acceptance 18.
  • Not run: the Android head (no workload here); its change is two lines of wiring.

Next

PR 2: KARTE tab in Führung with Einsatzort and vehicles placed by hand (migration, sync commands, protocol bump). PR 3: offline address search — will be built so it switches on once the redesigned regions packs carry address data. PR 4: Lagekarte in the PDF.

🤖 Generated with Claude Code

Groundwork for the Lagekarte in Führung. Stammdaten gains a Karten
section that lists the packs published in CodeForFire/lagebuch-regions,
downloads one per Landkreis onto the device, and shows it as a map that
pans by dragging and zooms by wheel, pinch or keyboard.

The map code is salvaged from #164, which never reached main, and moved
out of the Wasserförderung: MapCanvasControl, the MBTiles reader, the
Web-Mercator math and the pack installer. The #152 review findings that
apply to it are fixed: decoded tiles are cached instead of re-decoded on
every frame, failures surface as German status text, and a pack can be
removed while nothing holds its file open.

A pack belongs to the device, not to the Stammdaten: the Stammdaten
travel to every joined client, and a folder on the host means nothing on
a tablet. So the section acts at once and never marks the editor dirty.

Downloads cross a trust boundary and are treated that way: https only,
the body is cut off at the size the catalogue declared, only
region.mbtiles and region.dem are unpacked under fixed names, and a
failed update leaves the older copy in place. The privacy page lists the
pack download as the fifth way data leaves the device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
Addresses CodeQL alerts 291-296 on #789.

- WebMercator.CenterOfTiles summed tile indices as int before widening.
  The indices come from an MBTiles file that caps the zoom but not the
  columns, so a tampered pack could wrap the int and open the map on the
  wrong side of the world. The arithmetic now runs in double; a test
  replays such a range.
- MapDrawing does the same multiplication in double. The viewport's
  zoom clamp keeps it from overflowing today, but Draw is public.
- RegionPackLibrary's best-effort cleanup catches IOException and
  UnauthorizedAccessException only, with the reason in the block, as
  SessionPdfExport.DeleteQuietly does, instead of an empty catch-all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
The mutation gate failed on Domain (72.7 %), Persistence (62.1 %) and
AppLogic (70.3 %). Locally it now reads 100 %, 94.7 % and 94.8 %.

- Boundary tests for GeoPoint, the MBTiles zoom and tile range, and the
  catalogue's caps, field types and bounding box.
- The off-world tile test now stores a tile at the address an unchecked
  lookup would read, so it fails if the guard goes.
- The oversized-body test claimed "no Content-Length" but its
  StreamContent computed one, so the byte-counting cut-off never ran.
  It now sends a body of unknown length; a second test sends a lying one.
- Progress, leftovers of an interrupted install, timeout, an
  undeletable pack, the catalogue address, and the section's selection
  and catalogue rows after install and remove.
- RegionPackInfo.Covers had no caller; removed until address search
  needs it.
- Equivalent mutants carry a Stryker disable with the reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
DeepDiver1975 added a commit that referenced this pull request Oct 27, 2026
…ck with it

#789 dropped Covers while nothing there called it. The Lagekarte does: it
shows the installed pack whose box holds the Einsatzort. Restored with a
test of the box edges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
@DeepDiver1975

Copy link
Copy Markdown
Contributor Author

Superseded by #798, which carries this PR's commits rebased onto current main and moves the Kartenpakete to lagebuch-geodata format 2 (checksummed packs, zoom 17, Hydranten and offline address search on the Lagekarte).

DeepDiver1975 added a commit that referenced this pull request Oct 29, 2026
…ddress search (#798)

* feat(karte): download offline Kartenpakete and show them as a map

Groundwork for the Lagekarte in Führung. Stammdaten gains a Karten
section that lists the packs published in CodeForFire/lagebuch-regions,
downloads one per Landkreis onto the device, and shows it as a map that
pans by dragging and zooms by wheel, pinch or keyboard.

The map code is salvaged from #164, which never reached main, and moved
out of the Wasserförderung: MapCanvasControl, the MBTiles reader, the
Web-Mercator math and the pack installer. The #152 review findings that
apply to it are fixed: decoded tiles are cached instead of re-decoded on
every frame, failures surface as German status text, and a pack can be
removed while nothing holds its file open.

A pack belongs to the device, not to the Stammdaten: the Stammdaten
travel to every joined client, and a folder on the host means nothing on
a tablet. So the section acts at once and never marks the editor dirty.

Downloads cross a trust boundary and are treated that way: https only,
the body is cut off at the size the catalogue declared, only
region.mbtiles and region.dem are unpacked under fixed names, and a
failed update leaves the older copy in place. The privacy page lists the
pack download as the fifth way data leaves the device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* fix(karte): keep tile math in double and narrow cleanup catches

Addresses CodeQL alerts 291-296 on #789.

- WebMercator.CenterOfTiles summed tile indices as int before widening.
  The indices come from an MBTiles file that caps the zoom but not the
  columns, so a tampered pack could wrap the int and open the map on the
  wrong side of the world. The arithmetic now runs in double; a test
  replays such a range.
- MapDrawing does the same multiplication in double. The viewport's
  zoom clamp keeps it from overflowing today, but Draw is public.
- RegionPackLibrary's best-effort cleanup catches IOException and
  UnauthorizedAccessException only, with the reason in the block, as
  SessionPdfExport.DeleteQuietly does, instead of an empty catch-all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* test(karte): kill the surviving mutants on the Kartenpakete diff

The mutation gate failed on Domain (72.7 %), Persistence (62.1 %) and
AppLogic (70.3 %). Locally it now reads 100 %, 94.7 % and 94.8 %.

- Boundary tests for GeoPoint, the MBTiles zoom and tile range, and the
  catalogue's caps, field types and bounding box.
- The off-world tile test now stores a tile at the address an unchecked
  lookup would read, so it fails if the guard goes.
- The oversized-body test claimed "no Content-Length" but its
  StreamContent computed one, so the byte-counting cut-off never ran.
  It now sends a body of unknown length; a second test sends a lying one.
- Progress, leftovers of an interrupted install, timeout, an
  undeletable pack, the catalogue address, and the section's selection
  and catalogue rows after install and remove.
- RegionPackInfo.Covers had no caller; removed until address search
  needs it.
- Equivalent mutants carry a Stryker disable with the reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* feat(fuehrung): mark the Einsatzort and the units on a Lagekarte

Führung gains a KARTE tab beside ORGANISATION, FUNKTIONEN and KRÄFTE.
The Lagebuchführer picks the Einsatzort or a unit and taps the map to
place it, or places it in the middle of the map from the keyboard; a
mark already on the map is dragged to move it. Picking and tapping works
the same on a desk and a tablet, where drag and drop does not.

Positions live in the incident, not in the Kartenpaket: Incident.Location
and ForceUnit.Position, saved in four nullable REAL columns (migration
V36, declared in SchemaGuard). A file that stores something other than a
position there loses the mark, not the Einsatz.

The ETB records the Einsatzort being set, moved and removed, with its
coordinates, and a unit's first placement and removal. Moving a unit
already on the map writes nothing: that is tidying the picture, and an
entry per drag would bury the ones that matter.

Two new commands a client may send, setIncidentLocation and
placeForceUnit, so the protocol and its floor rise to 26. Coordinates
cross the wire as plain numbers and are checked on arrival; a half-given
or impossible pair is refused, never read as "take it off".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* fix(fuehrung): keep RegionPackInfo.Covers, the Lagekarte picks its pack with it

#789 dropped Covers while nothing there called it. The Lagekarte does: it
shows the installed pack whose box holds the Einsatzort. Restored with a
test of the box edges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* feat(karte): read Kartenpakete from lagebuch-geodata format 2

The catalogue moves to CodeForFire/lagebuch-geodata's packs.json. A pack
is now checked end to end before it is installed: the zip's SHA-256
against the catalogue, its entries against the six files FORMAT.md
names (anything else refuses the pack rather than being skipped), and
each data file's size and SHA-256 against the pack's own pack.json.
The app's record of the catalogue entry moves to installed.json, since
pack.json is now the publisher's. A pack is current when its version
and checksum match, and the list shows "Stand <Tag> · Version n".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* feat(karte): Hydranten and offline address search on the Lagekarte

A Kartenpaket from lagebuch-geodata carries water.geojson and
addresses.sqlite, and the KARTE tab now uses both.

- Hydranten, Saugstellen, Löschwasserbehälter and Löschteiche are drawn
  over the map from zoom 15 (red dot / blue square, "UH 100" labels
  from 17), behind a HYDRANTEN switch, with "Hydranten aus OpenStreetMap
  – nicht amtlich." under the attribution. Drawn, not controls: a
  Landkreis has thousands.
- An address search over the map reads "Hauptstr 12a Maisach" as
  street, number and place, treats Str./Strasse/Straße alike, ranks the
  exact number and a confirmed place first, and a picked hit marks the
  Einsatzort with the usual ETB entry (read-only: it only centres). It
  starts from the Einsatz's recorded address while nothing is marked.
- Both files are read off the UI thread through IRegionPackLibrary;
  addresses.sqlite is opened read-only with every value bound and LIKE
  wildcards escaped, water.geojson is size- and feature-capped.

The pure map tests in MapCanvasControlTests now run on the Avalonia
thread: touching MapCanvasControl from an xUnit thread raced the
headless thread's InputElement initialisation once more test classes
ran together.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* fix(karte): keep the water point radius in double

CodeQL's cs/loss-of-precision flagged 2 * radius as an int product cast to double. The radius is 5 or 7 and cannot overflow, but double literals keep the drawing math in one type, as the tile math already is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* fix(karte): draw every installed Kartenpaket as one map

The KARTE tab showed one pack at a time and switched only when
something was placed or centred, so with FFB and STA installed,
panning across the Landkreis border ran off the edge into blank land.
It also read the installed packs once, when the incident was opened.

- CombinedMapTileSource serves a tile from the first pack that has it,
  so a border is a seam; the attribution lists each distinct licence
  line once.
- Hydranten come from every pack; an unreadable water file costs only
  that pack's points and is reported with its name.
- Opening the KARTE tab re-reads the installed packs, so a pack
  downloaded or deleted under Stammdaten during an Einsatz shows up
  without reopening the incident. The view stays where it was.

Refs #796 (tiles; stitching elevation belongs to the DGM sampler, #587)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* fix(karte): draw each Kartenpaket only within its own area

A pack's edge tiles are only partly map: its OSM data is cut to the
Landkreis plus 3 km before rendering, so the rest of an edge tile is
empty land. Taking a whole tile from the first pack that had one let
FFB's empty margin cover STA's streets, as a cream band across the
Ammersee and the Landkreis Starnberg.

Each pack is now a MapTileLayer drawn clipped to its area (even-odd,
so holes stay holes); in the overlap both packs show the same streets.
The area comes from the zip when a pack carries boundary.geojson, then
declared in pack.json and checked like any data file, and otherwise
from the catalogue's boundaryUrl, fetched once at install over https,
capped at 1 MB and refused unless it is a Polygon or MultiPolygon on
the globe. A pack without a known area is drawn whole, underneath the
others; packs installed before this need AKTUALISIEREN once to get
theirs.

The tile cache is keyed by pack as well, sharing its capacity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* fix(karte): offer AKTUALISIEREN for a pack installed without its area

A pack installed before the catalogue named its boundaryUrl has no area to be clipped to, but matched the catalogue's version and checksum and so showed as INSTALLIERT with no way to fetch it. A different boundaryUrl now makes it outdated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* fix(karte): say why a Kartenpaket is offered for update

AKTUALISIEREN appeared on a pack with the same version number and no explanation (a pack installed before its area was stored). The row now says why: a new version, a rebuild of the same version on another day, or the area still to fetch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* feat(karte): a symbol per water point kind and a card for each

#795 asked for a symbol per kind and a detail view. Hydranten stay red
dots; a Saugstelle is now a blue ring, a Löschwasserbehälter a blue
square and a Löschteich a blue diamond, with a key in the map's corner
whenever they are drawn.

A tap on the map with nothing picked to place opens the card of the
water point under the finger (within a fingertip, only where symbols
are drawn) and rings it; a tap beside it closes the card. The card
lists what OSM holds from FORMAT.md's allowlist -- Bauart, Durchmesser,
Druck, Förderleistung, Volumen, Kupplungen, Lage, Wasser aus, Nummer,
Name, Betreiber, OSM id -- saying the well-known values in German
("Überflur", "DN 150", "Trinkwassernetz") and showing anything else as
OSM spells it, and repeats that OSM is not the Wasserversorger's
register. An OSM reference that is no object id is left off.

WaterPointLayer holds the zoom thresholds and the hit test, so a point
can be tapped exactly when it can be seen.

Closes #795

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* fix(karte): cut each pack file off at the size pack.json declares

#794 listed what a Kartenpaket installer has to withstand. Two pieces
were still missing:

- A single entry was read until the whole pack reached the 2 GB cap and
  only compared with its declared size afterwards. pack.json is now
  unpacked first (capped at 64 KB), and every other file is read only up
  to the size pack.json declares for it, then checked against its
  declared SHA-256. A zip bomb behind a valid outer checksum stops after
  its first chunk.
- A truncated zip had no test. It is refused as "beschädigt" and leaves
  the older copy in place.

A declared size that is negative or not a number, or a checksum that is
not 64 hex digits, refuses the pack before anything else is unpacked.

Closes #794

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* fix(karte): find every street the address search names, in any case

The SQL prefilter capped its candidates at 2000 rows before the street
and place were compared, so a short stem such as "Haupt" filled the cap
with other streets that sort first. The cap now counts matched hits.

SQLite's LIKE folds ASCII only, so "ölmühlweg" never reached Normalize.
The prefix now stops before the first non-ASCII letter and binds the
first letter in both cases.

Search also takes the cancellation token and checks it per row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* refactor(karte): read a Kartenpaket's area from its zip only

Every pack is rebuilt with boundary.geojson inside it, so the fallback
that fetched the area from the catalogue's boundaryUrl is gone. The area
is now one of the data files pack.json declares, a zip without it is
refused, and it must still parse before the pack is installed.
RegionPackInfo no longer carries BoundaryUrl, so a pack no longer counts
as outdated only because the catalogue started naming its area.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

---------

Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants