maps: draw each transit mode from its own zoom, tile stops to z16
- Commit
8ab9459b6338f686987440d9b0ed8e982c88b1fa- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-25 02:01 UTC (3 months ago)
- Parents
40ad197
Diff
maps/src/main/java/com/vayunmathur/maps/ui/TransitStopsLayer.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/TransitStopsLayer.kt b/maps/src/main/java/com/vayunmathur/maps/ui/TransitStopsLayer.ktindex f4b6887fad..446e21e54b 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/TransitStopsLayer.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/TransitStopsLayer.kt@@ -12,12 +12,14 @@ import com.vayunmathur.maps.data.transit.TransitStop import org.maplibre.compose.expressions.dsl.case import org.maplibre.compose.expressions.dsl.const import org.maplibre.compose.expressions.dsl.feature+import org.maplibre.compose.expressions.dsl.gte import org.maplibre.compose.expressions.dsl.image import org.maplibre.compose.expressions.dsl.interpolate import org.maplibre.compose.expressions.dsl.linear import org.maplibre.compose.expressions.dsl.switch import org.maplibre.compose.expressions.dsl.zoom import org.maplibre.compose.expressions.value.IntValue+import org.maplibre.compose.expressions.value.NumberValue import org.maplibre.compose.layers.CircleLayer import org.maplibre.compose.layers.SymbolLayer import org.maplibre.compose.sources.VectorSource@@ -34,7 +36,7 @@ private const val TRANSIT_STOP_DOT_LAYER_ID = "transit-stop-dots" * the `transit_stops` source-layer in the overlay PMTiles archive, written by * `scripts/maps/build_transit_stops_layer.sh`. *- * Bus and trolleybus stops are filtered out; see [TransitStopsLayer].+ * Every mode is drawn, but not from the same zoom: see [TRANSIT_STOP_MIN_ZOOM]. * * This replaced a per-viewport `GET /api/v1/map/stops` fetch. Stops are static * data, so a network round-trip on every camera idle bought nothing, and the baked@@ -47,8 +49,8 @@ object TransitStopsSource { /** Transit teal so stops read distinctly from Google POIs (category colours), * saved pins (blue) and search results (red). Reached by the modes that are- * neither rail-like nor ferries and are not filtered out: cable tram, aerial- * lift, funicular, monorail. */+ * neither rail-like nor ferries: cable tram, aerial lift, funicular, monorail,+ * bus and trolleybus. */ private val TRANSIT_STOP_COLOR = Color(0xFF00897B) /** Rail-like modes get a distinct colour from buses, so a subway entrance is@@ -57,9 +59,39 @@ private val TRANSIT_STOP_COLOR = Color(0xFF00897B) private val TRANSIT_RAIL_COLOR = Color(0xFF3949AB) private val TRANSIT_FERRY_COLOR = Color(0xFF0277BD) +/**+ * The zoom each GTFS mode starts drawing at, listed in the same order as+ * `mode_rank` in `scripts/maps/gtfs_ingest/src/bin/transit_stops.rs` — that+ * function is already the project's statement of which modes are prominent, and it+ * is what decides a stop's `route_type` when several modes call there.+ *+ * Buses are the overwhelming majority of a planetary stops layer, millions of+ * them, and drawn from the archive floor they read as a field of dots with the rail+ * network lost inside it. So the prominent half starts at the floor and buses wait+ * until the map is zoomed in far enough for them to be individually useful.+ */+private val TRANSIT_STOP_MIN_ZOOM = listOf(+ 1 to 10, // subway / metro+ 2 to 10, // rail+ 0 to 10, // tram / light rail+ 12 to 10, // monorail+ 4 to 12, // ferry+ 6 to 12, // aerial lift+ 7 to 12, // funicular+ 5 to 12, // cable tram+ 3 to 15, // bus+ 11 to 15, // trolleybus+)++/** `normalize_route_type` folds every unrecognised GTFS route type onto 3, so an+ * unknown value is already a bus by the time it reaches the tile and the fallback+ * only has to agree with that. */+private const val TRANSIT_STOP_DEFAULT_MIN_ZOOM = 15+ /** * Draw the `transit_stops` source-layer: a [CircleLayer] dot with a [SymbolLayer]- * glyph on top, from z10 up. Takes the shared overlay [VectorSource] the admin and+ * glyph on top, from z10 up, each mode appearing at its own zoom+ * ([TRANSIT_STOP_MIN_ZOOM]). Takes the shared overlay [VectorSource] the admin and * POI overlays also read, since they are all layers of the same archive. * * The marker is a runtime Canvas bitmap rather than a sprite asset, so it renders@@ -73,20 +105,19 @@ private val TRANSIT_FERRY_COLOR = Color(0xFF0277BD) fun TransitStopsLayer(source: VectorSource) { val marker = remember { generateTransitMarkerBitmap() } - // Bus and trolleybus stops are not drawn. They are the overwhelming majority of- // a planetary stops layer - millions of them - and at that density the map reads- // as a field of dots with the rail network lost inside it. `transit_stops` also- // folds every unrecognised GTFS route type onto 3 (see `normalize_route_type` in- // gtfs_ingest/src/bin/transit_stops.rs), so this drops junk classifications too.+ // Per-mode min-zoom, the same shape as MaPoisLayer's per-category one. Compare+ // against `zoom()` (a NumberValue), so the Int threshold is cast to the same+ // value type for `gte` to resolve to the numeric overload. //- // A `switch` rather than a negated comparison, because it is the DSL this file- // already uses and needs no further imports.- val notABus = switch(+ // ONE filter for both layers below: a glyph without its dot still draws, and is+ // still a tap target that would open a departure board for a stop the map is+ // not showing.+ val minZoomForMode = switch( feature["route_type"].cast<IntValue>(),- case(3, const(false)),- case(11, const(false)),- fallback = const(true),+ *TRANSIT_STOP_MIN_ZOOM.map { (mode, minZoom) -> case(mode, const(minZoom)) }.toTypedArray(),+ fallback = const(TRANSIT_STOP_DEFAULT_MIN_ZOOM), )+ val stopFilter = zoom() gte minZoomForMode.cast<NumberValue<Number>>() // Colour by mode. `switch` over the numeric route_type, as MyMapLayers does // for its own data-driven paint.@@ -104,7 +135,7 @@ fun TransitStopsLayer(source: VectorSource) { source, sourceLayer = TransitStopsSource.SOURCE_LAYER, minZoom = 10f,- filter = notABus,+ filter = stopFilter, color = dotColor, radius = interpolate( linear(), zoom(),@@ -124,9 +155,7 @@ fun TransitStopsLayer(source: VectorSource) { source, sourceLayer = TransitStopsSource.SOURCE_LAYER, minZoom = 10f,- // Same filter as the dot, or a glyph would float with nothing under it -- // and a tap on it would open a departure board for a hidden stop.- filter = notABus,+ filter = stopFilter, iconImage = image(marker), iconSize = interpolate( linear(), zoom(),
scripts/maps/build_all.ps1
diff --git a/scripts/maps/build_all.ps1 b/scripts/maps/build_all.ps1index b41131bcad..6233b9cd18 100644--- a/scripts/maps/build_all.ps1+++ b/scripts/maps/build_all.ps1@@ -309,10 +309,13 @@ if (Test-Stage "tiles") { Invoke-Step "cargo" @("run", "--release", "--quiet", "--manifest-path", $GtfsCargo, "--bin", "transit_stops", "--", "--geojson", $stopsGeo, "--manifest", $script:EffectiveGtfsManifest)+ # z16, matching the merged archive: the merge unions each input's maxzoom+ # and MapLibre overzooms per source, not per layer, so a stops layer tiled+ # lower has its stops vanish above its own maxzoom. Invoke-Step "cargo" @("run", "--release", "--quiet", "--manifest-path", $TileManifest, "--bin", "tile_points", "--", "--geojson", $stopsGeo, "--out", $StopsTile, "--layer", "transit_stops",- "--minzoom", "10", "--maxzoom", "14")+ "--minzoom", "10", "--maxzoom", "16") } else { Write-Warning "no GTFS manifest available; skipping the transit_stops layer" }
scripts/maps/build_transit_stops_layer.ps1
diff --git a/scripts/maps/build_transit_stops_layer.ps1 b/scripts/maps/build_transit_stops_layer.ps1index 6c81d1fe72..db9f470e88 100644--- a/scripts/maps/build_transit_stops_layer.ps1+++ b/scripts/maps/build_transit_stops_layer.ps1@@ -19,7 +19,7 @@ # Usage: # .\build_transit_stops_layer.ps1 -Manifest ca_transit_work\feeds.manifest # .\build_transit_stops_layer.ps1 -Manifest m.txt -Out transit_stops.pmtiles `-# -MinZoom 10 -MaxZoom 14+# -MinZoom 10 -MaxZoom 16 # # Requires: cargo (https://rustup.rs). Nothing else. [CmdletBinding()]@@ -32,7 +32,11 @@ param( [string]$Work = "transit_stops_work", # 10 because stops are denser than ma_pois (12) but far sparser than roads. [int]$MinZoom = 10,- [int]$MaxZoom = 14,+ # 16 to MATCH THE MERGED ARCHIVE. The merge unions each input's maxzoom into one+ # source-level maxzoom and MapLibre overzooms per source, not per layer: tiled+ # below the union, this layer's stops vanish above its own maxzoom because the+ # client fetches real tiles that simply have no `transit_stops` in them.+ [int]$MaxZoom = 16, # Keep the intermediate geojsonseq for inspection. [switch]$KeepWork )
scripts/maps/build_transit_stops_layer.sh
diff --git a/scripts/maps/build_transit_stops_layer.sh b/scripts/maps/build_transit_stops_layer.shindex 0e6fac431c..6781f7d11c 100644--- a/scripts/maps/build_transit_stops_layer.sh+++ b/scripts/maps/build_transit_stops_layer.sh@@ -22,14 +22,19 @@ set -euo pipefail # Usage: # ./build_transit_stops_layer.sh --manifest world_transit_work/feeds.manifest # ./build_transit_stops_layer.sh --manifest m.txt --out transit_stops.pmtiles \-# --minzoom 10 --maxzoom 14+# --minzoom 10 --maxzoom 16 # # Options: # --manifest FILE feeds.manifest: `name=dir[=motis_prefix]` per line (required) # --out FILE output .pmtiles (default transit_stops.pmtiles) # --workdir DIR scratch dir for the geojsonseq (default ./transit_stops_work) # --minzoom N default 10 (stops are denser than ma_pois, sparser than roads)-# --maxzoom N default 14+# --maxzoom N default 16, and it must MATCH THE MERGED ARCHIVE. The merge+# unions each input's maxzoom into one source-level maxzoom, and+# MapLibre overzooms per source, not per layer: tiled below the+# union, this layer's stops vanish above its own maxzoom because+# the client fetches real tiles that simply have no+# `transit_stops` in them. # --keep-work keep the intermediate geojsonseq # # Tools required: cargo. Nothing else.@@ -38,7 +43,7 @@ MANIFEST="" OUT="transit_stops.pmtiles" WORK="./transit_stops_work" MINZOOM=10-MAXZOOM=14+MAXZOOM=16 KEEP_WORK=0 while [[ $# -gt 0 ]]; do case "$1" in@@ -48,7 +53,7 @@ while [[ $# -gt 0 ]]; do --minzoom) MINZOOM="$2"; shift 2 ;; --maxzoom) MAXZOOM="$2"; shift 2 ;; --keep-work) KEEP_WORK=1; shift ;;- -h|--help) sed -n '3,34p' "$0" | sed 's/^# \?//'; exit 0 ;;+ -h|--help) sed -n '3,39p' "$0" | sed 's/^# \?//'; exit 0 ;; *) echo "Unknown arg: $1" >&2; exit 1 ;; esac done
scripts/maps/build_v5_pmtiles.sh
diff --git a/scripts/maps/build_v5_pmtiles.sh b/scripts/maps/build_v5_pmtiles.shindex 3c575ed3d9..abfce33958 100644--- a/scripts/maps/build_v5_pmtiles.sh+++ b/scripts/maps/build_v5_pmtiles.sh@@ -360,10 +360,16 @@ if [[ "$SKIP_TRANSIT_STOPS" == "0" ]]; then # that never asked for stops. echo "[v5] no --gtfs-manifest given; skipping transit_stops layer" >&2 else+ # --maxzoom explicitly, and equal to the archive's: the merge unions every+ # input's maxzoom into one source-level maxzoom, and MapLibre overzooms per+ # source rather than per layer. A stops layer tiled below the union has its+ # stops disappear above its own maxzoom, because the client then fetches real+ # tiles that carry no `transit_stops`. run "$HERE/build_transit_stops_layer.sh" \ --manifest "$GTFS_MANIFEST" \ --out "$WORK/transit_stops.pmtiles" \- --workdir "$WORK/transit_stops"+ --workdir "$WORK/transit_stops" \+ --maxzoom 16 INPUTS+=("$WORK/transit_stops.pmtiles") fi fi