2026-04-11 20:09:30 -06:00
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="utf-8"/>
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
<link rel="stylesheet" href="/libs/maplibre-gl.css"/>
|
|
|
|
|
<style>* { margin: 0; padding: 0; } html, body, #map { width: 100%; height: 100%; }</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div id="map"></div>
|
|
|
|
|
<script src="/libs/pmtiles.js"></script>
|
|
|
|
|
<script src="/libs/maplibre-gl.js"></script>
|
|
|
|
|
<script src="/libs/protomaps-themes-base.js"></script>
|
|
|
|
|
<script>
|
|
|
|
|
(function() {
|
|
|
|
|
var protocol = new pmtiles.Protocol();
|
|
|
|
|
maplibregl.addProtocol("pmtiles", protocol.tile);
|
|
|
|
|
|
|
|
|
|
var hash = window.location.hash.replace("#", "");
|
|
|
|
|
var parts = hash ? hash.split(",") : [];
|
|
|
|
|
var lat = parseFloat(parts[0]) || 0;
|
|
|
|
|
var lon = parseFloat(parts[1]) || 0;
|
|
|
|
|
var zoom = parseFloat(parts[2]) || 4;
|
|
|
|
|
|
|
|
|
|
var dark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
|
|
|
var flavor = dark ? "dark" : "light";
|
|
|
|
|
|
|
|
|
|
fetch("/api/map/files").then(function(r) { return r.json(); }).then(function(data) {
|
|
|
|
|
var sources = {};
|
|
|
|
|
var allLayers = [];
|
|
|
|
|
|
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.
2026-11-13 15:11:01 -07:00
|
|
|
// Add user's basemap PMTiles files: not terrain, overlays, or files the user ignores.
|
2026-04-11 20:09:30 -06:00
|
|
|
var files = (data.files || []).filter(function(f) {
|
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.
2026-11-13 15:11:01 -07:00
|
|
|
if (f.visible === false) return false;
|
|
|
|
|
return f.kind ? f.kind === "basemap" : f.name.indexOf("terrain") !== 0;
|
2026-04-11 20:09:30 -06:00
|
|
|
});
|
|
|
|
|
files.forEach(function(f, i) {
|
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.
2026-11-13 15:11:01 -07:00
|
|
|
// 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);
|
2026-04-11 20:09:30 -06:00
|
|
|
if (i > 0) {
|
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.
2026-11-13 15:11:01 -07:00
|
|
|
layers.forEach(function(l) { l.id = mapPath + ":" + l.id; });
|
2026-04-11 20:09:30 -06:00
|
|
|
}
|
|
|
|
|
allLayers = allLayers.concat(layers);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
new maplibregl.Map({
|
|
|
|
|
container: "map",
|
|
|
|
|
style: {
|
|
|
|
|
version: 8,
|
|
|
|
|
glyphs: "/fonts/{fontstack}/{range}.pbf",
|
|
|
|
|
sprite: window.location.origin + "/sprites/" + flavor,
|
|
|
|
|
sources: sources,
|
|
|
|
|
layers: allLayers,
|
|
|
|
|
},
|
|
|
|
|
center: [lon, lat],
|
|
|
|
|
zoom: zoom,
|
|
|
|
|
attributionControl: false,
|
|
|
|
|
interactive: false,
|
|
|
|
|
});
|
|
|
|
|
}).catch(function(e) {
|
|
|
|
|
console.error("Embed map error:", e);
|
|
|
|
|
document.getElementById("map").textContent = "Map unavailable";
|
|
|
|
|
});
|
|
|
|
|
})();
|
|
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|