feat(map): setting to hide the Mapbox basemap points of interest (#1761)

Mapbox Standard labels shops, restaurants and sights of its own; they look like trip
places but cannot be picked. A Hide Points of Interest switch next to the other Mapbox
options, on the desktop and the phone, turns them off on the trip map and the preview
without a rebuild. The Standard config handling moves into useStandardBasemapConfig.
This commit is contained in:
Maurice
2026-11-13 09:44:33 +01:00
parent 5176dc29d6
commit 12ae32b69e
43 changed files with 294 additions and 24 deletions
@@ -1,4 +1,4 @@
// FE-COMP-MAP-001 to FE-COMP-MAP-035
// FE-COMP-MAP-001 to FE-COMP-MAP-036
import { render, screen, waitFor, within, fireEvent } from '../../../tests/helpers/render';
import userEvent from '@testing-library/user-event';
import { useAuthStore } from '../../store/authStore';
@@ -19,8 +19,8 @@ vi.mock('../Map/MapView', () => ({
// The GL preview boots a real mapbox/maplibre instance; the tab only cares that
// it gets the right provider/style, so render those as data attributes.
vi.mock('./MapboxPreview', () => ({
default: ({ provider, style, token, enable3d, quality }: {
provider?: string; style: string; token?: string; enable3d: boolean; quality?: boolean;
default: ({ provider, style, token, enable3d, quality, hidePois }: {
provider?: string; style: string; token?: string; enable3d: boolean; quality?: boolean; hidePois?: boolean;
}) => (
<div
data-testid="gl-preview"
@@ -29,6 +29,7 @@ vi.mock('./MapboxPreview', () => ({
data-token={token}
data-3d={String(enable3d)}
data-quality={String(quality)}
data-hide-pois={String(hidePois)}
/>
),
}));
@@ -467,4 +468,18 @@ describe('MapSettingsTab – CARTO key', () => {
expect(screen.queryByText(/API KEY REQUIRED/)).not.toBeInTheDocument();
});
it('FE-COMP-MAP-036: under Mapbox the basemap points of interest can be hidden, in the preview and on save (#1761)', async () => {
const user = userEvent.setup();
const updateSettings = vi.fn().mockResolvedValue(undefined);
seedStore(useSettingsStore, { settings: buildSettings(), updateSettings });
render(<MapSettingsTab />);
await user.click(screen.getByText('Mapbox GL'));
await user.click(screen.getByRole('button', { name: 'Hide Points of Interest' }));
expect(await screen.findByTestId('gl-preview')).toHaveAttribute('data-hide-pois', 'true');
await user.click(screen.getByText('Save Map'));
expect(updateSettings).toHaveBeenCalledWith(expect.objectContaining({ map_hide_basemap_pois: true }));
});
});
@@ -132,7 +132,8 @@ export default function MapSettingsTab(): React.ReactElement {
const {
managed, presets, canMapbox, saving, provider, changeProvider, mapTileUrl, setMapTileUrl, mapboxToken, setMapboxToken,
cartoKey, setCartoKey, cartoNeedsKey, mapboxStyle, setMapboxStyle, mapbox3d, setMapbox3d,
mapboxQuality, setMapboxQuality, previewPlaces, glPreview, webgl2Missing, save: saveMapSettings,
mapboxQuality, setMapboxQuality, hideBasemapPois, setHideBasemapPois, previewPlaces, glPreview, webgl2Missing,
save: saveMapSettings,
} = useMapSettingsForm()
// One chunk per engine — see components/Map/glLazy.tsx.
const GlMapPreview = provider === 'maplibre-gl' ? GlMapPreviewMaplibre : GlMapPreviewMapbox
@@ -307,6 +308,11 @@ export default function MapSettingsTab(): React.ReactElement {
}
control={<ToggleSwitch on={mapboxQuality} onToggle={() => setMapboxQuality(!mapboxQuality)} label={t('settings.mapHighQuality')} />}
/>
<SettingRow
label={t('settings.mapHidePois')}
hint={t('settings.mapHidePoisHint')}
control={<ToggleSwitch on={hideBasemapPois} onToggle={() => setHideBasemapPois(!hideBasemapPois)} label={t('settings.mapHidePois')} />}
/>
</SettingRows>
<div className="rounded-[12px] border border-edge-faint bg-surface-card px-3.5 py-3">
@@ -337,6 +343,7 @@ export default function MapSettingsTab(): React.ReactElement {
zoom={PREVIEW_ZOOM}
enable3d={provider === 'mapbox-gl' && mapbox3d && supports3d}
quality={provider === 'mapbox-gl' && mapboxQuality}
hidePois={provider === 'mapbox-gl' && hideBasemapPois}
/>
</Suspense>
</ErrorBoundary>
@@ -1,4 +1,4 @@
// FE-COMP-GLPREVIEW-001 to FE-COMP-GLPREVIEW-014
// FE-COMP-GLPREVIEW-001 to FE-COMP-GLPREVIEW-015
import { render, screen, act } from '../../../tests/helpers/render';
type ClickHandler = (e: { lngLat: { lat: number; lng: number } }) => void;
@@ -20,6 +20,7 @@ const glMap = vi.hoisted(() => ({
remove: vi.fn(),
jumpTo: vi.fn(),
setTerrain: vi.fn(),
setConfigProperty: vi.fn(),
}));
const mapboxCtor = vi.hoisted(() => vi.fn(function (_options: Record<string, unknown>) {
@@ -216,4 +217,17 @@ describe('GlMapPreview', () => {
expect(() => unmount()).not.toThrow();
expect(glMap.remove).toHaveBeenCalled();
});
it('FE-COMP-GLPREVIEW-015: on a Standard style the preview hides the basemap points of interest when asked (#1761)', () => {
vi.mocked(isStandardFamily).mockReturnValue(true);
const { unmount } = render(<GlMapPreview token="pk.test" style={MAPBOX_DEFAULT_STYLE} lat={48.8} lng={2.3} zoom={16} enable3d={false} hidePois />);
act(() => glHandlers.load?.());
expect(glMap.setConfigProperty).toHaveBeenCalledWith('basemap', 'showPointOfInterestLabels', false);
unmount();
glMap.setConfigProperty.mockClear();
render(<GlMapPreview token="pk.test" style={MAPBOX_DEFAULT_STYLE} lat={48.8} lng={2.3} zoom={16} enable3d={false} />);
act(() => glHandlers.load?.());
expect(glMap.setConfigProperty).not.toHaveBeenCalled();
});
});
@@ -2,6 +2,7 @@ import { useEffect, useRef } from 'react'
import { isStandardFamily, supportsCustom3d, addCustom3dBuildings, addTerrainAndSky } from '../Map/mapboxSetup'
import { MAPBOX_DEFAULT_STYLE, normalizeStyleForProvider, type GlMapProvider } from '../Map/glProviders'
import { buildGlMap } from '../Map/glSupport'
import { setBasemapConfig } from '../Map/useStandardBasemapConfig'
import { fs } from '../shared/DialogShell'
interface Props {
@@ -13,6 +14,8 @@ interface Props {
zoom: number
enable3d: boolean
quality?: boolean
/** Leaves out Mapbox Standard's own points of interest, as the trip map does (#1761). */
hidePois?: boolean
onClick?: (latlng: { lat: number; lng: number }) => void
/**
* The GL engine, injected instead of imported. Both SDKs used to be pulled in
@@ -23,7 +26,7 @@ interface Props {
gl: any
}
export default function GlMapPreview({ provider = 'mapbox-gl', token = '', style, lat, lng, zoom, enable3d, quality = false, onClick, gl }: Props) {
export default function GlMapPreview({ provider = 'mapbox-gl', token = '', style, lat, lng, zoom, enable3d, quality = false, hidePois = false, onClick, gl }: Props) {
const containerRef = useRef<HTMLDivElement>(null)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const mapRef = useRef<any | null>(null)
@@ -67,6 +70,7 @@ export default function GlMapPreview({ provider = 'mapbox-gl', token = '', style
if (glStyle === MAPBOX_DEFAULT_STYLE) {
try { map.setTerrain(null) } catch { /* noop */ }
}
if (hidePois && !isMapLibre && isStandardFamily(glStyle)) setBasemapConfig(map, 'showPointOfInterestLabels', false)
})
map.on('click', (e) => {
@@ -77,7 +81,7 @@ export default function GlMapPreview({ provider = 'mapbox-gl', token = '', style
try { map.remove() } catch { /* noop */ }
mapRef.current = null
}
}, [provider, token, glStyle, enableMapbox3d, quality])
}, [provider, token, glStyle, enableMapbox3d, quality, hidePois])
// Recenter without rebuilding the map when lat/lng/zoom change externally
useEffect(() => {
@@ -118,4 +118,14 @@ describe('useMapSettingsForm', () => {
await act(() => result.current.save());
expect(toast.error).toHaveBeenCalledWith('common.error');
});
it('FE-COMP-MAPFORM-009: the basemap points of interest switch is read from the settings and saved back (#1761)', async () => {
seed({ map_provider: 'mapbox-gl', map_hide_basemap_pois: true });
const { result } = renderHook(() => useMapSettingsForm());
expect(result.current.hideBasemapPois).toBe(true);
act(() => result.current.setHideBasemapPois(false));
await act(() => result.current.save());
expect(updateSettings).toHaveBeenCalledWith(expect.objectContaining({ map_hide_basemap_pois: false }));
});
});
@@ -28,7 +28,8 @@ export interface MapSettingsFormOptions {
/**
* The user's map settings form behind both settings shells (the desktop tab and the
* phone section render their own markup over this): the provider, the raster tiles
* and CARTO key, the Mapbox token, the GL style and the 3D and quality toggles,
* and CARTO key, the Mapbox token, the GL style, the 3D and quality toggles and the switch
* for the basemap's own points of interest,
* seeded from the settings store and saved back in one patch.
*/
export function useMapSettingsForm({ mirrorStyleBeforeSave = false }: MapSettingsFormOptions = {}) {
@@ -48,6 +49,7 @@ export function useMapSettingsForm({ mirrorStyleBeforeSave = false }: MapSetting
);
const [mapbox3d, setMapbox3d] = useState<boolean>(settings.mapbox_3d_enabled !== false);
const [mapboxQuality, setMapboxQuality] = useState<boolean>(settings.mapbox_quality_mode === true);
const [hideBasemapPois, setHideBasemapPois] = useState<boolean>(settings.map_hide_basemap_pois === true);
useEffect(() => {
const nextProvider = normalizeProvider(settings.map_provider);
@@ -58,6 +60,7 @@ export function useMapSettingsForm({ mirrorStyleBeforeSave = false }: MapSetting
setMapboxStyle(styleForProvider(nextProvider, slotStyle(nextProvider, settings)));
setMapbox3d(settings.mapbox_3d_enabled !== false);
setMapboxQuality(settings.mapbox_quality_mode === true);
setHideBasemapPois(settings.map_hide_basemap_pois === true);
}, [settings]);
const previewPlaces = useMemo((): Place[] => [previewPlace()], []);
@@ -82,6 +85,7 @@ export function useMapSettingsForm({ mirrorStyleBeforeSave = false }: MapSetting
...stylePatch,
mapbox_3d_enabled: mapbox3d,
mapbox_quality_mode: mapboxQuality,
map_hide_basemap_pois: hideBasemapPois,
});
// Only mirror the normalized style into the form once it is actually persisted.
if (!mirrorStyleBeforeSave) setMapboxStyle(glStyle);
@@ -121,6 +125,8 @@ export function useMapSettingsForm({ mirrorStyleBeforeSave = false }: MapSetting
setMapbox3d,
mapboxQuality,
setMapboxQuality,
hideBasemapPois,
setHideBasemapPois,
previewPlaces,
glPreview,
webgl2Missing,