fix(map): Fix state labels by using coalesce fallback for text-field

The protomaps theme generates text-field expressions using name:short,
but the PMTiles data doesn't have that property. States have 'ref' (e.g.
'CA', 'ON') and 'name' (e.g. 'California', 'Ontario').

- Use coalesce expression: name:short -> ref -> name
- Expand zoom ranges slightly: country z1-5, region z4-8
- Verified fix in built JS before deployment

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Matt 2026-05-02 19:36:58 +00:00
commit bb164965ef

View file

@ -272,10 +272,18 @@ function applyBaseLabelStyling(map) {
// - Cities: unchanged (natural min_zoom in tile data) // - Cities: unchanged (natural min_zoom in tile data)
try { try {
if (map.getLayer('places_country')) { if (map.getLayer('places_country')) {
map.setLayerZoomRange('places_country', 1, 4) map.setLayerZoomRange('places_country', 1, 5)
} }
if (map.getLayer('places_region')) { if (map.getLayer('places_region')) {
map.setLayerZoomRange('places_region', 4, 7) map.setLayerZoomRange('places_region', 4, 8)
// FIX: The protomaps theme uses name:short which doesn't exist in tiles
// Use coalesce to fall back to ref (e.g., "CA") then name (e.g., "California")
map.setLayoutProperty('places_region', 'text-field', [
'coalesce',
['get', 'name:short'],
['get', 'ref'],
['get', 'name']
])
} }
} catch (e) { } catch (e) {
// Ignore if layers don't exist // Ignore if layers don't exist