Skip to content

adds support for local OpenStreetMap basemaps served as PMTiles - #13149

Open
robgaston wants to merge 2 commits into
dev/8.2.xfrom
rmg/local-basemap-install
Open

robgaston wants to merge 2 commits into
dev/8.2.xfrom
rmg/local-basemap-install

Conversation

@robgaston

Copy link
Copy Markdown
Member

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Description of Change

Today every Arches basemap loads from a third-party service (Maptoolkit by default). Instances on closed networks, in the field, or under data-sovereignty rules have no way to show a basemap. This PR lets an instance extract an area of OpenStreetMap as a single .pmtiles file and serve it itself, online or fully offline, in both the Knockout maps and the Vue MapComponent.

PMTiles support

  • Both map stacks accept pmtiles:// URLs in map sources. A shared registerPmtilesProtocol() is used by the maplibre-gl binding and by MapComponent.
  • When LOCAL_BASEMAPS_ROOT is set, that folder is served at /basemaps/ with HTTP range requests (LocalBasemapFileView), so there's no tile server. Dot-files and paths outside the folder are refused.
  • /basemaps/styles/<name>.json (LocalBasemapStyleView) generates a MapLibre style for each basemap from Protomaps' light and dark layers.
  • Font requests for fonts that aren't stored locally redirect to LOCAL_BASEMAPS_FONT_FALLBACK. Online basemaps keep their labels beside local ones. Setting it to None makes the instance fully offline.
  • MapDataAPI lists the local basemaps the user can read, ahead of settings.BASEMAPS.

manage.py basemap

  • extract --name <name> --bbox w,s,e,n (or --region <geojson> / --from-default-bounds):
    • finds the latest Protomaps daily build and estimates the download size, asking before it downloads (--noinput skips the prompt);
    • extracts the area with the go-pmtiles CLI over range requests;
    • on first use, downloads fonts, sprites and a shared world overview (zooms 0–6, about 45 MB);
    • then installs the basemap.
  • install <archive.pmtiles> installs an archive you already have.
  • What install does:
    • adds a LocalBasemap record linked to a normal MapLayer and MapSource, so existing map code treats it as another basemap;
    • points the glyphs and sprites System Settings at local files;
    • draws the overview's earth and water layers under the extract, so there's no gray gap outside it at mid zooms.
  • Install options:
    • --flavor light|dark;
    • --default makes maps open on this basemap;
    • --fit-default-bounds makes maps open on its area;
    • --offline removes online basemaps, sources and sprites, first saving them to LOCAL_BASEMAPS_ROOT/.online_basemaps.json.
  • Management operations:
    • list;
    • remove: deletes files no other basemap uses, but always keeps fonts, and promotes another basemap, preferring local ones, if the removed one was the default;
    • set-default;
    • restore-online.
  • Refreshing:
    • running extract again with the same name refreshes the basemap from the latest build, keeping its title and flavor;
    • --refresh-overview re-extracts the overview too.
  • Glyphs and sprites are System Settings, read once per process, so the command tells you to restart the web server afterwards.

Settings and dependencies

  • New settings: LOCAL_BASEMAPS_ROOT (default None, off), LOCAL_BASEMAPS_FONT_FALLBACK and LOCAL_BASEMAPS_PMTILES_COMMAND.
  • The project template gets a commented-out LOCAL_BASEMAPS_ROOT, and its .gitignore ignores the basemaps folder.
  • New dependencies: pmtiles 3.8.1 (Python, reads archive headers) and pmtiles 4.5.0 (JavaScript).
  • The go-pmtiles CLI is an external requirement, needed only for extract.

Nothing changes unless LOCAL_BASEMAPS_ROOT is set.

Issues Solved

Closes #

Checklist

  • I targeted one of these branches:
    • dev/8.2.x (under development): features, bugfixes not covered below
    • dev/8.1.x (main support): regressions, crashing bugs, security issues, major bugs in new features
    • dev/7.6.x (extended support): major security issues, data loss issues
  • I added a changelog in arches/releases
  • I submitted a PR to arches-docs (if appropriate)
  • Unit tests pass locally with my changes
  • I added tests that prove my fix is effective or that my feature works
  • My test fails on the target branch

Accessibility Checklist

Developer Guide

No UI components were added or changed. Local basemaps appear in the existing basemap lists.

Topic Changed Retested
Color contrast
Form fields
Headings
Links
Keyboard
Responsive Design
HTML validation
Screen reader

Ticket Background

  • Sponsored by:
  • Found by: @
  • Tested by: @
  • Designed by: @robgaston

Further comments

Why PMTiles and Protomaps. A PMTiles archive is one static file that the browser reads with range requests. Django (or nginx in production) can serve it without running a tile server. Protomaps publishes a daily planet build and open styles. go-pmtiles reads just the tiles for an area from that build over HTTP, so nobody downloads the planet. The alternatives (a tile server, or a vendor's offline package) add infrastructure or a license dependency.

Why existing models. Each local basemap is a regular MapLayer and MapSource plus a small LocalBasemap record (migration local_basemaps), so the Knockout maps needed only the protocol registration. --offline is needed because the Knockout maps load every source in the combined style, visible or not, so one online source breaks the map offline.

Notes for reviewers

  • Several web servers: LOCAL_BASEMAPS_ROOT is read on every request, so on several web servers it must be one shared or synced folder. This is documented only, and S3 storage is out of scope.
  • Reinstall drops the overview: reinstalling an archive in place without --overview currently drops the basemap's overview. A later remove can then delete the shared world.pmtiles. It is open whether an in-place reinstall should keep the overview by default.
  • Missing icon: Protomaps' sprite has no townhall icon, so MapLibre logs a console warning. That has to be fixed upstream.
  • Follow-ups: an arches-docs page and container support.

Testing: new tests cover the extractor, files view, installer, manager, styles and views, plus MapDataAPI basemaps. go-pmtiles and HTTP are mocked.

@robgaston
robgaston force-pushed the rmg/local-basemap-install branch from 18a78e2 to 92c638b Compare November 23, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant