Legend page served as a view with the map's versioned importmap (shared partial): as a static page it imported icons.js and mdi.mjs unversioned and a browser with an older copy showed no symbols; it also stays light (color-scheme) since auto-darkening washed out its swatches, no autofocus, a clearer filter and a symbol count
CI / check (push) Successful in 19s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-11-18 23:47:07 +01:00
1 parent 1bb0e1137a
commit 3e5fada66a
5 files changed
+83 -52

No files matched your search

+8
View File
@@ -305,6 +305,14 @@ module Maptool
erb :index, locals: { logged_in: logged_in?, user: session[:user], revision: REVISION } erb :index, locals: { logged_in: logged_in?, user: session[:user], revision: REVISION }
end end
# Map legend + symbol browser. A view, not a static public/ page, so it
# gets the same versioned importmap as the map: as a static page it
# imported /js/icons.js and /vendor/mdi/mdi.mjs unversioned, and a
# browser still holding an older copy of either rendered no symbols.
get "/symbols.html" do
erb :symbols, layout: false
end
# A share to the installed app normally never reaches the server: the # A share to the installed app normally never reaches the server: the
# service worker (public/sw.js) takes the POST, parks the files and # service worker (public/sw.js) takes the POST, parks the files and
# opens the app. Only lands here if no worker is running yet — back to # opens the app. Only lands here if no worker is running yet — back to
+12
View File
@@ -47,6 +47,18 @@ class AppTest < Minitest::Test
end end
end end
# The legend page imports app and vendor modules too: it must get the
# same versioned importmap, and stay light (auto-darkening washed out its
# color swatches on a tablet).
def test_symbols_page_has_the_versioned_importmap_and_a_light_color_scheme
response = request.get("/symbols.html")
assert_equal 200, response.status
assert_match(%r{"/vendor/mdi/mdi\.mjs":\s*"/vendor/mdi/mdi\.mjs\?v=\d+"}, response.body)
assert_match(%r{"/js/icons\.js":\s*"/js/icons\.js\?v=\d+"}, response.body)
assert_includes response.body, '<meta name="color-scheme" content="light">'
assert_operator response.body.index("importmap"), :<, response.body.index('<script type="module">')
end
# Unversioned /vendor modules must be revalidated, or a deploy adding an # Unversioned /vendor modules must be revalidated, or a deploy adding an
# export to one (imported by a freshly versioned /js module) breaks a # export to one (imported by a freshly versioned /js module) breaks a
# browser still holding the old copy — see static_cache_control in app.rb. # browser still holding the old copy — see static_cache_control in app.rb.
+48
View File
@@ -0,0 +1,48 @@
<%# Every app module and every vendored module they import is versioned
(ASSET_VERSION, a fresh value per deploy): map.js and the rest import
each other — and /vendor modules — by plain path, and an import map
remaps those paths to a versioned URL, so a deploy busts all of them
without touching any import statement. A vendored module that changes
with the app (mdi.mjs gaining an icon) can't be left cached while the
module importing it is fresh. Static files are also revalidated
(static_cache_control in app.rb) as a backstop for anything loaded
some other way. Must come before the module script below: the
importmap has to be parsed first. %>
<script type="importmap">
{
"imports": {
"/js/auth.js": "/js/auth.js?v=<%= ASSET_VERSION %>",
"/js/contour.js": "/js/contour.js?v=<%= ASSET_VERSION %>",
"/js/dem.js": "/js/dem.js?v=<%= ASSET_VERSION %>",
"/js/gnss.js": "/js/gnss.js?v=<%= ASSET_VERSION %>",
"/js/gpx.js": "/js/gpx.js?v=<%= ASSET_VERSION %>",
"/js/hiking_trails.js": "/js/hiking_trails.js?v=<%= ASSET_VERSION %>",
"/js/icons.js": "/js/icons.js?v=<%= ASSET_VERSION %>",
"/js/livetrack.js": "/js/livetrack.js?v=<%= ASSET_VERSION %>",
"/js/locate.js": "/js/locate.js?v=<%= ASSET_VERSION %>",
"/js/map_themes.js": "/js/map_themes.js?v=<%= ASSET_VERSION %>",
"/js/measure.js": "/js/measure.js?v=<%= ASSET_VERSION %>",
"/js/notes.js": "/js/notes.js?v=<%= ASSET_VERSION %>",
"/js/debug.js": "/js/debug.js?v=<%= ASSET_VERSION %>",
"/js/offline_data.js": "/js/offline_data.js?v=<%= ASSET_VERSION %>",
"/js/overlays.js": "/js/overlays.js?v=<%= ASSET_VERSION %>",
"/js/panels.js": "/js/panels.js?v=<%= ASSET_VERSION %>",
"/js/plugins.js": "/js/plugins.js?v=<%= ASSET_VERSION %>",
"/js/preview.js": "/js/preview.js?v=<%= ASSET_VERSION %>",
"/js/radar.js": "/js/radar.js?v=<%= ASSET_VERSION %>",
"/js/route.js": "/js/route.js?v=<%= ASSET_VERSION %>",
"/js/share_import.js": "/js/share_import.js?v=<%= ASSET_VERSION %>",
"/js/search.js": "/js/search.js?v=<%= ASSET_VERSION %>",
"/js/shadow.js": "/js/shadow.js?v=<%= ASSET_VERSION %>",
"/js/sun.js": "/js/sun.js?v=<%= ASSET_VERSION %>",
"/js/track_profile.js": "/js/track_profile.js?v=<%= ASSET_VERSION %>",
"/vendor/maplibre-gl/maplibre-gl.mjs": "/vendor/maplibre-gl/maplibre-gl.mjs?v=<%= ASSET_VERSION %>",
"/vendor/maplibre-gl-lanes/maplibre-gl-lanes.mjs": "/vendor/maplibre-gl-lanes/maplibre-gl-lanes.mjs?v=<%= ASSET_VERSION %>",
"/vendor/mdi/mdi.mjs": "/vendor/mdi/mdi.mjs?v=<%= ASSET_VERSION %>",
"/vendor/nps-symbols/nps-symbols.mjs": "/vendor/nps-symbols/nps-symbols.mjs?v=<%= ASSET_VERSION %>",
"/vendor/npmap-home-button/home-button.esm.js": "/vendor/npmap-home-button/home-button.esm.js?v=<%= ASSET_VERSION %>",
"/vendor/npmap-overview/overview.esm.js": "/vendor/npmap-overview/overview.esm.js?v=<%= ASSET_VERSION %>",
"/vendor/suncalc/suncalc.js": "/vendor/suncalc/suncalc.js?v=<%= ASSET_VERSION %>"
}
}
</script>
+1 -48
View File
@@ -27,54 +27,7 @@
</script> </script>
<script src="/vendor/pmtiles/pmtiles.js?v=<%= ASSET_VERSION %>"></script> <script src="/vendor/pmtiles/pmtiles.js?v=<%= ASSET_VERSION %>"></script>
<script src="/vendor/maplibre-contour/maplibre-contour.min.js?v=<%= ASSET_VERSION %>"></script> <script src="/vendor/maplibre-contour/maplibre-contour.min.js?v=<%= ASSET_VERSION %>"></script>
<%# Every app module and every vendored module they import is versioned <%= erb :importmap, layout: false %>
(ASSET_VERSION, a fresh value per deploy): map.js and the rest import
each other — and /vendor modules — by plain path, and an import map
remaps those paths to a versioned URL, so a deploy busts all of them
without touching any import statement. A vendored module that changes
with the app (mdi.mjs gaining an icon) can't be left cached while the
module importing it is fresh. Static files are also revalidated
(static_cache_control in app.rb) as a backstop for anything loaded
some other way. Must come before the module script below: the
importmap has to be parsed first. %>
<script type="importmap">
{
"imports": {
"/js/auth.js": "/js/auth.js?v=<%= ASSET_VERSION %>",
"/js/contour.js": "/js/contour.js?v=<%= ASSET_VERSION %>",
"/js/dem.js": "/js/dem.js?v=<%= ASSET_VERSION %>",
"/js/gnss.js": "/js/gnss.js?v=<%= ASSET_VERSION %>",
"/js/gpx.js": "/js/gpx.js?v=<%= ASSET_VERSION %>",
"/js/hiking_trails.js": "/js/hiking_trails.js?v=<%= ASSET_VERSION %>",
"/js/icons.js": "/js/icons.js?v=<%= ASSET_VERSION %>",
"/js/livetrack.js": "/js/livetrack.js?v=<%= ASSET_VERSION %>",
"/js/locate.js": "/js/locate.js?v=<%= ASSET_VERSION %>",
"/js/map_themes.js": "/js/map_themes.js?v=<%= ASSET_VERSION %>",
"/js/measure.js": "/js/measure.js?v=<%= ASSET_VERSION %>",
"/js/notes.js": "/js/notes.js?v=<%= ASSET_VERSION %>",
"/js/debug.js": "/js/debug.js?v=<%= ASSET_VERSION %>",
"/js/offline_data.js": "/js/offline_data.js?v=<%= ASSET_VERSION %>",
"/js/overlays.js": "/js/overlays.js?v=<%= ASSET_VERSION %>",
"/js/panels.js": "/js/panels.js?v=<%= ASSET_VERSION %>",
"/js/plugins.js": "/js/plugins.js?v=<%= ASSET_VERSION %>",
"/js/preview.js": "/js/preview.js?v=<%= ASSET_VERSION %>",
"/js/radar.js": "/js/radar.js?v=<%= ASSET_VERSION %>",
"/js/route.js": "/js/route.js?v=<%= ASSET_VERSION %>",
"/js/share_import.js": "/js/share_import.js?v=<%= ASSET_VERSION %>",
"/js/search.js": "/js/search.js?v=<%= ASSET_VERSION %>",
"/js/shadow.js": "/js/shadow.js?v=<%= ASSET_VERSION %>",
"/js/sun.js": "/js/sun.js?v=<%= ASSET_VERSION %>",
"/js/track_profile.js": "/js/track_profile.js?v=<%= ASSET_VERSION %>",
"/vendor/maplibre-gl/maplibre-gl.mjs": "/vendor/maplibre-gl/maplibre-gl.mjs?v=<%= ASSET_VERSION %>",
"/vendor/maplibre-gl-lanes/maplibre-gl-lanes.mjs": "/vendor/maplibre-gl-lanes/maplibre-gl-lanes.mjs?v=<%= ASSET_VERSION %>",
"/vendor/mdi/mdi.mjs": "/vendor/mdi/mdi.mjs?v=<%= ASSET_VERSION %>",
"/vendor/nps-symbols/nps-symbols.mjs": "/vendor/nps-symbols/nps-symbols.mjs?v=<%= ASSET_VERSION %>",
"/vendor/npmap-home-button/home-button.esm.js": "/vendor/npmap-home-button/home-button.esm.js?v=<%= ASSET_VERSION %>",
"/vendor/npmap-overview/overview.esm.js": "/vendor/npmap-overview/overview.esm.js?v=<%= ASSET_VERSION %>",
"/vendor/suncalc/suncalc.js": "/vendor/suncalc/suncalc.js?v=<%= ASSET_VERSION %>"
}
}
</script>
<script type="module" src="/js/map.js?v=<%= ASSET_VERSION %>"></script> <script type="module" src="/js/map.js?v=<%= ASSET_VERSION %>"></script>
</body> </body>
</html> </html>
+14 -4
View File
@@ -3,11 +3,13 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<%# Light only: without this, Android/Chrome auto-darkening repaints the
page dark and washes out the legend swatches. %>
<meta name="color-scheme" content="light">
<title>MapTool legend</title> <title>MapTool legend</title>
<link rel="icon" href="/icons/icon.svg" type="image/svg+xml"> <link rel="icon" href="/icons/icon.svg" type="image/svg+xml">
<style> <style>
:root { --bg: #fff; --fg: #1a1a1a; --muted: #666; --line: #ddd; --hover: #eef3ee; } :root { color-scheme: light; --bg: #fff; --fg: #1a1a1a; --muted: #666; --line: #ddd; --hover: #eef3ee; }
@media (prefers-color-scheme: dark) { :root { --bg: #1a1a1a; --fg: #eee; --muted: #999; --line: #333; --hover: #26302a; } }
body { margin: 0; padding: 16px; background: var(--bg); color: var(--fg); font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; } body { margin: 0; padding: 16px; background: var(--bg); color: var(--fg); font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
header { position: sticky; top: 0; background: var(--bg); padding-bottom: 12px; } header { position: sticky; top: 0; background: var(--bg); padding-bottom: 12px; }
h1 { font-size: 1.2rem; margin: 0 0 4px; } h1 { font-size: 1.2rem; margin: 0 0 4px; }
@@ -38,11 +40,12 @@
</table> </table>
</section> </section>
<header> <header>
<h2>Point symbols</h2> <h2>Point symbols <small class="count"></small></h2>
<p>National Park Service map symbols (CC0) and the OsmAnd names mapped onto them. Click one to copy its name, the value of a point's <code>icon</code> property.</p> <p>National Park Service map symbols (CC0) and the OsmAnd names mapped onto them. Click one to copy its name, the value of a point's <code>icon</code> property.</p>
<input type="search" placeholder="Search" autofocus> <input type="search" placeholder="Filter symbols, e.g. water, campground">
</header> </header>
<main></main> <main></main>
<%= erb :importmap, layout: false %>
<script type="module"> <script type="module">
import { POI_ICONS } from "/js/icons.js"; import { POI_ICONS } from "/js/icons.js";
@@ -59,9 +62,16 @@
button.addEventListener("click", () => navigator.clipboard?.writeText(key)); button.addEventListener("click", () => navigator.clipboard?.writeText(key));
main.append(button); main.append(button);
} }
const count = document.querySelector(".count");
const showCount = () => {
const shown = [...main.children].filter((b) => !b.hidden).length;
count.textContent = shown === main.children.length ? `(${shown})` : `(${shown} of ${main.children.length})`;
};
showCount();
document.querySelector("input").addEventListener("input", (event) => { document.querySelector("input").addEventListener("input", (event) => {
const words = event.target.value.toLowerCase().split(/\s+/).filter(Boolean); const words = event.target.value.toLowerCase().split(/\s+/).filter(Boolean);
for (const button of main.children) button.hidden = !words.every((w) => button.dataset.search.includes(w)); for (const button of main.children) button.hidden = !words.every((w) => button.dataset.search.includes(w));
showCount();
}); });
</script> </script>
<script type="module"> <script type="module">