Repository navigation
Conversation
robgaston
force-pushed
the
rmg/local-basemap-install
branch
from
November 23, 2026 17:15
18a78e2 to
92c638b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Types of changes
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
.pmtilesfile and serve it itself, online or fully offline, in both the Knockout maps and the VueMapComponent.PMTiles support
pmtiles://URLs in map sources. A sharedregisterPmtilesProtocol()is used by themaplibre-glbinding and byMapComponent.LOCAL_BASEMAPS_ROOTis 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.LOCAL_BASEMAPS_FONT_FALLBACK. Online basemaps keep their labels beside local ones. Setting it toNonemakes the instance fully offline.MapDataAPIlists the local basemaps the user can read, ahead ofsettings.BASEMAPS.manage.py basemapextract --name <name> --bbox w,s,e,n(or--region <geojson>/--from-default-bounds):--noinputskips the prompt);install <archive.pmtiles>installs an archive you already have.LocalBasemaprecord linked to a normalMapLayerandMapSource, so existing map code treats it as another basemap;earthandwaterlayers under the extract, so there's no gray gap outside it at mid zooms.--flavor light|dark;--defaultmakes maps open on this basemap;--fit-default-boundsmakes maps open on its area;--offlineremoves online basemaps, sources and sprites, first saving them toLOCAL_BASEMAPS_ROOT/.online_basemaps.json.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.extractagain with the same name refreshes the basemap from the latest build, keeping its title and flavor;--refresh-overviewre-extracts the overview too.Settings and dependencies
LOCAL_BASEMAPS_ROOT(defaultNone, off),LOCAL_BASEMAPS_FONT_FALLBACKandLOCAL_BASEMAPS_PMTILES_COMMAND.LOCAL_BASEMAPS_ROOT, and its.gitignoreignores the basemaps folder.pmtiles3.8.1 (Python, reads archive headers) andpmtiles4.5.0 (JavaScript).extract.Nothing changes unless
LOCAL_BASEMAPS_ROOTis set.Issues Solved
Closes #
Checklist
Accessibility Checklist
Developer Guide
No UI components were added or changed. Local basemaps appear in the existing basemap lists.
Ticket Background
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
MapLayerandMapSourceplus a smallLocalBasemaprecord (migrationlocal_basemaps), so the Knockout maps needed only the protocol registration.--offlineis 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
LOCAL_BASEMAPS_ROOTis 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.--overviewcurrently drops the basemap's overview. A laterremovecan then delete the sharedworld.pmtiles. It is open whether an in-place reinstall should keep the overview by default.townhallicon, so MapLibre logs a console warning. That has to be fixed upstream.Testing: new tests cover the extractor, files view, installer, manager, styles and views, plus
MapDataAPIbasemaps.go-pmtilesand HTTP are mocked.