-
Notifications
You must be signed in to change notification settings - Fork 0
Add map composition helpers for tmap, mapgl, leaflet, and QGIS #14
Description
Problem
gq handles style translation (colors, weights, classification) but map composition — scales, logos, north arrows, element placement, basemaps, bbox padding — is copy-pasted between projects. Every bookdown report and vignette across the org re-implements the same layout boilerplate. The cartography conventions in soul describe what to do (four-corner rule, map-fills-frame, suppress auto-legends) but there's no code encoding those defaults.
Proposed Solution
Extend gq with composition helpers that encode our cartographic conventions as sensible defaults with overrides. Three interactive targets reflect actual usage: mapgl (default per conventions), leaflet (Shiny apps, mapgl workarounds), and QGIS (field work, Mergin Maps).
Static (tmap v4)
| Function | Purpose |
|---|---|
gq_tmap_layout() |
Standard margins, font, frame settings |
gq_tmap_legend() |
Position, sizing, background — follows four-corner rule |
gq_tmap_scalebar() |
Position, auto-breaks appropriate for extent |
gq_tmap_logo() |
NGE logo placement, corner selection |
gq_tmap_basemap() |
maptiles provider + alpha blending for terrain context |
gq_tmap_keymap() |
Inset overview/context map |
Interactive — mapgl (default)
| Function | Purpose |
|---|---|
gq_mapgl_basemap() |
Standard tile source configuration |
gq_mapgl_controls() |
Navigation, scale bar, layer toggle |
gq_mapgl_popup() |
Standard popup template from column names |
Interactive — leaflet
mapgl is the default per conventions, but leaflet keeps being needed — diggs Shiny app, restoration watershed picker, and whenever mapgl hits limitations. Worth having helpers rather than re-inventing each time.
| Function | Purpose |
|---|---|
gq_leaflet_basemap() |
Standard tile layers with provider defaults |
gq_leaflet_controls() |
Layer toggle, scale bar |
gq_leaflet_popup() |
Standard popup from column names |
Track which mapgl limitations force the leaflet fallback — file upstream issues or document workarounds.
QGIS
gq already extracts styles from QGIS (gq_qgs_extract). The reverse — pushing registry styles into QGIS projects or QML files — would close the loop for field work and Mergin Maps. This is heavier (Python/XML generation) so may belong in a later phase, but noting it here since QGIS is a core part of the workflow.
Design principles
- Defaults encode soul cartography conventions (four-corner rule, element spacing, no titles, suppress auto-legends)
- All defaults overridable — conventions are defaults not constraints
- Ship NGE logo as
inst/assets/logo.png
Out of scope (stays in soul)
- Conventions prose (design rationale, self-review checklist)
- Style registry unchanged — composition sits alongside
Relates to NewGraphEnvironment/sred-2025-2026#5