From 13a22e45d721c0d3e392bb1cd5d148333be46251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B8ran=20Dalum?= Date: Tue, 21 Jul 2026 11:40:04 +0200 Subject: [PATCH 1/2] feat: Add zoom buttons to map --- src/components/map/map.module.css | 20 ++++++++- src/components/map/map.tsx | 52 +++++++++++++++++----- src/components/map/use-map-interactions.ts | 5 ++- src/translations/components/map.ts | 2 + 4 files changed, 67 insertions(+), 12 deletions(-) diff --git a/src/components/map/map.module.css b/src/components/map/map.module.css index 1285d69d..8fcc4394 100644 --- a/src/components/map/map.module.css +++ b/src/components/map/map.module.css @@ -77,9 +77,27 @@ .buttonsContainer { position: absolute; - right: token('spacing.xLarge'); + right: token('spacing.large'); bottom: 3rem; z-index: 250; + display: flex; + flex-direction: column; + align-items: flex-end; + gap: token('spacing.small'); +} + +.zoomControl { + display: flex; + flex-direction: column; +} + +.zoomControl__button { + justify-content: center; +} + +.zoomControl__button__divider { + box-shadow: inset 0 token('border.width.slim') 0 + token('color.border.primary.background'); } .pinSvg__fill { diff --git a/src/components/map/map.tsx b/src/components/map/map.tsx index 30bd82ab..d42b47d9 100644 --- a/src/components/map/map.tsx +++ b/src/components/map/map.tsx @@ -113,7 +113,10 @@ function MapWithStyle({ return () => resizeObserver.disconnect(); }, []); - const { centerMap } = useMapInteractions(map, onSelectStopPlace); + const { centerMap, zoomIn, zoomOut } = useMapInteractions( + map, + onSelectStopPlace, + ); useMapPin(map, position, layer); useMapLegs(map, mapLegs); useMapFareZones(map); @@ -133,15 +136,44 @@ function MapWithStyle({
{interactive && ( -
+
)}
mapRef.current?.zoomIn(); + const zoomOut = () => mapRef.current?.zoomOut(); + + return { centerMap, zoomIn, zoomOut }; } diff --git a/src/translations/components/map.ts b/src/translations/components/map.ts index d17cc266..49df0cca 100644 --- a/src/translations/components/map.ts +++ b/src/translations/components/map.ts @@ -16,6 +16,8 @@ export const Map = { 'Reset map view', 'Tilbakestill kartvisning', ), + zoomInButton: _('Zoom inn', 'Zoom in', 'Zoom inn'), + zoomOutButton: _('Zoom ut', 'Zoom out', 'Zoom ut'), startPoint: _('Start', 'Start', 'Start'), endPoint: _('Slutt', 'End', 'Slutt'), }, From 7919a67992363ad1cc809a532585e58f318b6c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B8ran=20Dalum?= Date: Tue, 21 Jul 2026 12:07:32 +0200 Subject: [PATCH 2/2] zoom fix --- src/components/map/map.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/map/map.tsx b/src/components/map/map.tsx index d42b47d9..e0ac8c89 100644 --- a/src/components/map/map.tsx +++ b/src/components/map/map.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useEffect, useCallback } from 'react'; +import React, { useRef, useEffect, useCallback, useMemo } from 'react'; import mapboxgl, { type StyleSpecification } from 'mapbox-gl'; import style from './map.module.css'; import 'mapbox-gl/dist/mapbox-gl.css'; @@ -58,10 +58,13 @@ export default function Map(props: MapProps) { // mapRef.current undefined and never re-run. const mapboxJsonStyle = useMapboxJsonStyle(); const [isDarkMode] = useDarkMode(); + const { language } = useTranslation(); if (!mapboxJsonStyle) return ; return ( @@ -98,6 +101,8 @@ function MapWithStyle({ zoom: initialZoom, bounds, interactive, + // Let the scroll wheel scroll the page instead of zooming the map. + cooperativeGestures: interactive, }); }, [position, initialZoom, bounds, mapboxJsonStyle, interactive]);