Skip to content

feat: probe-based style discovery, topo style variant#143

Merged
fank merged 3 commits into
mainfrom
feat/dynamic-style-switching
Feb 6, 2026
Merged

feat: probe-based style discovery, topo style variant#143
fank merged 3 commits into
mainfrom
feat/dynamic-style-switching

Conversation

@fank
Copy link
Copy Markdown
Member

@fank fank commented Feb 6, 2026

Summary

  • Replace server-declared maplibreStyles array with maplibre: true boolean flag in map.json
  • Frontend discovers available styles by probing known filenames via HEAD requests
  • Add topo style variant (gray background, hillshade + vector features only)
  • Rename standard style to color-relief
  • Introduce _baseUrl on world objects — set for all sources (local, pmtiles CDN, raster CDN) — eliminating cloud vs local branching for tile and style URLs
  • Fix getWorldByName() cloud cascade: local → pmtiles CDN → raster CDN → placeholder
  • pmtiles CDN responses force maplibre: true (subdomain implies MapLibre support, since both CDNs serve identical map.json content)

Changes

Backend (internal/maptool/)

  • metadata.go: mapJSON uses Maplibre bool instead of MaplibreStyles []mapStyleEntry. Removed mapStyleEntry struct. Styles stage just writes files, sets job.HasMaplibre = true
  • pipeline.go: HasMaplibre bool replaces MaplibreStyles on Job. Removed stylesPrefix() method
  • styles.go: StyleStandardStyleColorRelief, new StyleTopo with buildTopoLayers()
  • scanner.go: Style detection uses color-relief.json instead of standard.json

Frontend (static/)

  • ocap.js getWorldByName(): All paths set _baseUrl (local: images/maps/{world}, pmtiles CDN: https://pmtiles.ocap2.com/{world}, raster CDN: https://maps.ocap2.com/{world}). pmtiles CDN forces maplibre: true
  • ocap.js initMap(): Tile URLs and style candidates derived from world._baseUrl — no cloud vs local branching. useMapLibreMode checks world.maplibre or legacy world.maplibreStyle
  • L.Control.MaplibreStyles.js: Probes candidates with HEAD requests, shows buttons for available styles, hides control if ≤1 available, logs discovery results

Test plan

  • go test ./internal/maptool/... passes
  • Re-import a map, verify map.json has "maplibre": true and no maplibreStyles
  • Verify style buttons appear/hide based on which style files exist
  • Verify cloud fallback cascade (pmtiles CDN → raster CDN → placeholder)
  • Verify legacy maps with old maplibreStyle string still work

fank added 2 commits February 6, 2026 22:15
Rename standard style to color-relief (reflects its actual content), add
new topo variant (color-relief hidden, gray background, vector-only), and
replace the hardcoded 3-button style switcher with a dynamic control driven
by the maplibreStyles array in map.json. Legacy maps with only the single
maplibreStyle string still work via frontend fallback.
@fank fank changed the title feat: add topo style variant and dynamic style switching feat: add topo style, replace maplibreStyles with probe-based discovery Feb 6, 2026
- Backend: map.json now emits `"maplibre": true` instead of a
  `maplibreStyles` array. Remove mapStyleEntry struct and stylesPrefix().
- Frontend: getWorldByName() sets `_baseUrl` on all paths (local,
  pmtiles CDN, raster CDN) so tile/style URLs need no special-casing.
  pmtiles CDN response forces `maplibre: true` (subdomain is the signal).
- Frontend: initMap() builds style candidates from _baseUrl + known
  filenames. L.Control.MaplibreStyles probes each with HEAD, shows
  buttons only for styles that exist, hides control if ≤1 available.
- Cloud cascade fixed: local → pmtiles CDN → raster CDN → placeholder.
@fank fank changed the title feat: add topo style, replace maplibreStyles with probe-based discovery feat: probe-based style discovery, topo style variant Feb 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 6, 2026

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/OCAP2/web/internal/maptool 13.21% (+0.25%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/OCAP2/web/internal/maptool/metadata.go 11.61% (+0.71%) 336 (-22) 39 297 (-22) 👍
github.com/OCAP2/web/internal/maptool/pipeline.go 30.70% (ø) 215 66 149
github.com/OCAP2/web/internal/maptool/scanner.go 32.81% (ø) 192 63 129
github.com/OCAP2/web/internal/maptool/styles.go 33.98% (-0.07%) 668 (+63) 227 (+21) 441 (+42) 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/OCAP2/web/internal/maptool/scanner_test.go
  • github.com/OCAP2/web/internal/maptool/styles_test.go

@fank fank merged commit 44a491f into main Feb 6, 2026
2 checks passed
@fank fank deleted the feat/dynamic-style-switching branch February 6, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant