mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
feat(maps): MapLibre draws the user's map template on trek:template
A MapLibre user could only draw OpenFreeMap styles; a raster template was Leaflet's alone. With maplibre_style set to trek:template, MapLibre now draws the template the trip map already resolves for Leaflet (CARTO key, keyless fallback and dark default included), so both renderers show the same map. No stored row holds the keyword, so every existing user sees exactly the map they saw before, and Mapbox is untouched. - glBasemap turns the basemap spec into a raster style document (256px tiles as Leaflet requests them, the provider's deepest zoom, the credit, OpenFreeMap glyphs for the map's own labels) and resolves trek:ofm-auto to Liberty or OpenFreeMap Dark with the colour scheme. - glCanFetch decides whether a GL map may fetch a basemap here: https on a host the CSP names, the shipped ones or MAP_EXTRA_CONNECT_HOSTS from the app config. GCJ-02 tiles (Amap) and other hosts are drawn by Leaflet for that render, the setting untouched. - rasterHealth watches the first tiles of a template map: a CSP refusal or twelve failures without a success move every map drawing that template to Leaflet for the session, with a pill that says so. - useEffectiveMapEngine decides this on the engine that actually draws and runs the offline checks after it; a stored raster template keeps drawing offline where Leaflet would keep the same tiles. - The journey map uses the same hook: the same template, the same fallback and now the offline basemap with its pill as the trip map has it. - A MapLibre raster style stops at zoom 19 like Leaflet; the Mapbox options stay as they were. The offline pill moves to BasemapPill for both maps. Dropping the unused imports there lowers the eslint baseline.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import type mapboxgl from 'mapbox-gl';
|
||||
|
||||
import { MAP_MAX_ZOOM } from '../../constants/mapDefaults';
|
||||
import { mapboxTileCacheRequest, tileCacheActive } from '../../native/tileCache';
|
||||
import { isGlRasterStyle, type GlStyle } from './glBasemap';
|
||||
import { MAPBOX_DEFAULT_STYLE, type GlMapProvider } from './glProviders';
|
||||
import {
|
||||
addCustom3dBuildings,
|
||||
@@ -57,6 +59,9 @@ export function glMapOptions(input: GlMapOptionsInput): Record<string, unknown>
|
||||
if (!isMapLibre && input.appTileStore && tileCacheActive()) options.transformRequest = mapboxTileCacheRequest;
|
||||
// MapLibre's around-center rotate ping-pongs near mid-screen (#1545); false is mapbox-gl's dx rotate.
|
||||
if (isMapLibre) options.aroundCenter = false;
|
||||
// A raster template ends where Leaflet's map ends: past it the provider has no
|
||||
// tiles and the map would only enlarge its last ones.
|
||||
if (isMapLibre && isGlRasterStyle(input.style)) options.maxZoom = MAP_MAX_ZOOM;
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -71,7 +76,8 @@ export function glMapOptions(input: GlMapOptionsInput): Record<string, unknown>
|
||||
* on their coordinates at every zoom; the satellite variant keeps it, the DEM is
|
||||
* what gives it its character. A MapLibre style matches none of these.
|
||||
*/
|
||||
export function applyGl3d(map: mapboxgl.Map, style: string, enable3d: boolean, dark: boolean): void {
|
||||
export function applyGl3d(map: mapboxgl.Map, style: GlStyle, enable3d: boolean, dark: boolean): void {
|
||||
if (typeof style !== 'string') return;
|
||||
if (enable3d) {
|
||||
if (!isStandardFamily(style) && wantsTerrain(style)) addTerrainAndSky(map);
|
||||
if (supportsCustom3d(style)) addCustom3dBuildings(map, dark);
|
||||
|
||||
Reference in New Issue
Block a user