feat(settings): pick your own map template or the theme style for MapLibre

The MapLibre style picker offers two more entries after the OpenFreeMap
styles: OpenFreeMap that follows the light or dark theme (trek:ofm-auto),
and the user's own map template (trek:template), which brings the template
field under the picker, and the CARTO key for a CARTO template. Where the
trip map will draw the template with the classic 2D map (Amap, a host the
CSP does not name) the form says so and the preview shows that map. The
preview draws exactly what the trip map will.

Every place the forms load or save a MapLibre style keeps a keyword now,
where it used to turn it into Liberty on the first unchanged save: the
user form on desktop and phone (load, save, the phone's mirrored field,
a provider switch there and back) and the admin defaults (provider switch,
preset pick, typed style). The rules live in mapSettingsModel, so both
shells render from one decision:

- the template keyword with an empty template saves Liberty;
- switching from Leaflet with a template and an empty MapLibre slot
  preselects the template, shown and not saved until Save;
- Leaflet never writes a keyword into the Mapbox slot, and Mapbox shows its
  default for one.

New strings in all locales.
This commit is contained in:
Maurice
2026-11-30 15:35:46 +01:00
parent d39d544297
commit 69eacd5316
40 changed files with 726 additions and 147 deletions
@@ -158,4 +158,44 @@ describe('useDefaultUserSettings', () => {
await waitFor(() => expect(update).toHaveBeenLastCalledWith({ maplibre_style: OPENFREEMAP_DEFAULT_STYLE }));
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(3));
});
it('FE-COMP-DEFAULTSETTINGS-007: a MapLibre keyword default survives loading, a switch, a pick and a typed commit', async () => {
const update = stub({
map_provider: 'maplibre-gl',
maplibre_style: 'trek:template',
mapbox_style: 'mapbox://styles/me/x',
});
const { result } = await loaded();
expect(result.current.mapboxStyle).toBe('trek:template');
// The picker names both keywords after the OpenFreeMap styles.
expect(result.current.glStylePresets.slice(-2)).toEqual([
{ name: 'settings.mapStyleFollowTheme', url: 'trek:ofm-auto', tags: ['OpenFreeMap'] },
{ name: 'settings.mapStyleTemplate', url: 'trek:template' },
]);
act(() => result.current.commitStyle());
await waitFor(() => expect(update).toHaveBeenLastCalledWith({ maplibre_style: 'trek:template' }));
act(() => result.current.saveMapProvider('mapbox-gl'));
await waitFor(() =>
expect(update).toHaveBeenLastCalledWith({ map_provider: 'mapbox-gl', mapbox_style: 'mapbox://styles/me/x' })
);
act(() => result.current.saveMapProvider('maplibre-gl'));
await waitFor(() =>
expect(update).toHaveBeenLastCalledWith({ map_provider: 'maplibre-gl', maplibre_style: 'trek:template' })
);
expect(result.current.mapboxStyle).toBe('trek:template');
act(() => result.current.pickStylePreset('trek:ofm-auto'));
await waitFor(() => expect(update).toHaveBeenLastCalledWith({ maplibre_style: 'trek:ofm-auto' }));
});
it('FE-COMP-DEFAULTSETTINGS-008: a keyword typed for Mapbox is not kept, Mapbox draws neither', async () => {
const update = stub({ map_provider: 'mapbox-gl', mapbox_style: 'trek:template' });
const { result } = await loaded();
expect(result.current.mapboxStyle).toBe(MAPBOX_DEFAULT_STYLE);
expect(result.current.glStylePresets.map((p) => p.url)).not.toContain('trek:template');
act(() => result.current.commitStyle());
await waitFor(() => expect(update).toHaveBeenLastCalledWith({ mapbox_style: MAPBOX_DEFAULT_STYLE }));
});
});
@@ -7,16 +7,13 @@ import { useAuthStore } from '../../store/authStore';
import { useSettingsStore } from '../../store/settingsStore';
import type { DateFormat, DistanceUnit, Place, WeekStart } from '../../types';
import { normalizeTileUrl } from '../../utils/tileUrl';
import {
defaultStyleForProvider,
getStylePresets,
normalizeStyleForProvider,
styleSettingKey,
} from '../Map/glProviders';
import { defaultStyleForProvider, styleSettingKey } from '../Map/glProviders';
import {
type MapProvider,
glStylePresetsFor,
mapboxOffered,
mapPresetsFor,
normalizeGlSelection,
normalizeProvider,
styleForProvider,
} from '../Settings/mapSettingsModel';
@@ -127,7 +124,8 @@ export function useDefaultUserSettings({ errorMessage, previewCreatedAt }: Defau
const [mapPreviewPlaces] = useState((): Place[] => [adminPreviewPlace(previewCreatedAt())]);
const mapProvider = normalizeProvider(defaults.map_provider);
const glStylePresets = mapProvider === 'leaflet' ? [] : getStylePresets(mapProvider);
// MapLibre also offers its keywords: a default that follows the colour scheme, or the template above.
const glStylePresets = mapProvider === 'leaflet' ? [] : glStylePresetsFor(mapProvider, t);
const styleKey: keyof Defaults = mapProvider === 'maplibre-gl' ? 'maplibre_style' : 'mapbox_style';
const saveMapProvider = (nextProvider: MapProvider) => {
@@ -158,11 +156,11 @@ export function useDefaultUserSettings({ errorMessage, previewCreatedAt }: Defau
}
};
/** A typed style is normalized for the provider before it is saved. */
/** A typed style is normalized for the provider before it is saved; a MapLibre keyword stays. */
const commitStyle = () => {
// The style input never renders for leaflet; this only narrows the provider type.
if (mapProvider === 'leaflet') return;
const nextStyle = normalizeStyleForProvider(mapProvider, mapboxStyle);
const nextStyle = normalizeGlSelection(mapProvider, mapboxStyle);
setMapboxStyle(nextStyle);
void save({ [styleKey]: nextStyle });
};