The map draws any PMTiles file as an overlay, in any sub-directory (#962)

Any PMTiles file under the map directory, at any depth, can be shown.  The API reads each file's header and metadata and says what it is (basemap, terrain, overlay, unreadable).  Overlays are offered in the layer control under the name the file gives itself, hidden until turned on, with a checkbox per vector layer, and are drawn generically.

Map files are named by their path within the map directory everywhere, and unfinished downloads are no longer listed.  A file can be ignored from the Manage page; ignored files are kept in a new maps.yaml config.

PMTiles metadata is not decompressed past its size limit, and the standalone viewer encodes map file paths.
This commit is contained in:
lrnselfreliance 2026-11-13 15:11:01 -07:00 • committed by GitHub
parent 4072ac30ed
commit adb0adbd94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 2115 additions and 170 deletions

View file

@ -29,15 +29,21 @@
var sources = {};
var allLayers = [];
// Add user's PMTiles files (skip terrain). Includes map-overview if present.
// Add user's basemap PMTiles files: not terrain, overlays, or files the user ignores.
var files = (data.files || []).filter(function(f) {
return f.name.indexOf("terrain") !== 0;
if (f.visible === false) return false;
return f.kind ? f.kind === "basemap" : f.name.indexOf("terrain") !== 0;
});
files.forEach(function(f, i) {
sources[f.name] = {type: "vector", url: "pmtiles:///data/" + f.name};
var layers = protomaps_themes_base.default(f.name, flavor);
// A file is named by its path in the map directory; it may be in a sub-directory.
var mapPath = f.map_path || f.name;
// Each part of the path is encoded: a `#` or `?` in a file name would otherwise end the
// path, and another file (or none) would be asked for.
var dataPath = "/data/" + String(mapPath).split("/").map(encodeURIComponent).join("/");
sources[mapPath] = {type: "vector", url: "pmtiles://" + dataPath};
var layers = protomaps_themes_base.default(mapPath, flavor);
if (i > 0) {
layers.forEach(function(l) { l.id = f.name + ":" + l.id; });
layers.forEach(function(l) { l.id = mapPath + ":" + l.id; });
}
allLayers = allLayers.concat(layers);
});