From 47a9d2e2cb745163a5621585b4d3c5aac565dcb6 Mon Sep 17 00:00:00 2001 From: Amy Corson <115499534+amy-corson-ibigroup@users.noreply.github.com> Date: Thu, 23 Oct 2025 08:37:27 -0400 Subject: [PATCH 1/2] Force geolocate control to update UI --- lib/actions/location.tsx | 1 + lib/components/map/default-map.tsx | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/actions/location.tsx b/lib/actions/location.tsx index c62e9b740..33aacf0ff 100644 --- a/lib/actions/location.tsx +++ b/lib/actions/location.tsx @@ -68,6 +68,7 @@ export function getCurrentPosition( newError.message = intl.formatMessage({ id: 'actions.location.userDeniedPermission' }) + newError.code = error.code } } dispatch(receivedPositionError({ error: newError })) diff --git a/lib/components/map/default-map.tsx b/lib/components/map/default-map.tsx index 0aaaaaa9a..d897adb67 100644 --- a/lib/components/map/default-map.tsx +++ b/lib/components/map/default-map.tsx @@ -160,8 +160,10 @@ class DefaultMap extends Component { this.state = { lat, lon, + mapLoad: false, zoom } + this.geolocateControlRef = React.createRef() } getNearbyViewFilteredOverlays = () => { @@ -299,8 +301,15 @@ class DefaultMap extends Component { } componentDidUpdate(prevProps) { + const { currentPositionError } = this.props // Check if any overlays should be toggled due to mode change this._handleQueryChange(prevProps.query, this.props.query) + + // HACK: react-map-gl's GeolocateControl doesn't always accurately reflect that the user has blocked their location, so if we know we don't have access, trigger the button in the background to update the UI to disabled. + currentPositionError?.code === 1 && + this.state.mapLoad && + // After the map has loaded, give the GeolocateControl a sec to render. + setTimeout(() => this.geolocateControlRef.current?.trigger(), 10) } render() { @@ -371,7 +380,12 @@ class DefaultMap extends Component { } baseLayerNames={baseLayerNames} center={[lat, lon]} - mapLibreProps={{ reuseMaps: true }} + mapLibreProps={{ + onLoad: () => { + return this.setState({ mapLoad: true }) + }, + reuseMaps: true + }} maxZoom={maxZoom} // In Leaflet, this was an onclick handler. Creating a click handler in // MapLibreGL would require writing a custom event handler for all mouse events @@ -400,6 +414,7 @@ class DefaultMap extends Component { getCurrentPosition(intl) }} position="top-left" + ref={this.geolocateControlRef} /> { const viewedRoute = state.otp?.ui?.viewedRoute?.routeId const activeNearbyFilters = state.otp?.ui?.nearbyView?.filters const nearbyFilters = state.otp.config?.nearbyView?.filters - const stops = state.otp.transitIndex.stops const nearbyViewerActive = state.otp.ui.mainPanelContent === MainPanelContent.NEARBY_VIEW + const currentPositionError = state.otp.location.currentPosition.error + const viewedRoutePatterns = Object.entries( state.otp?.transitIndex?.routes?.[viewedRoute]?.patterns || {} ) @@ -532,6 +548,7 @@ const mapStateToProps = (state) => { bikeRentalStations: state.otp.overlay.bikeRental.stations, carRentalStations: state.otp.overlay.carRental.stations, config: state.otp.config, + currentPositionError, feeds: state.otp.transitIndex.feeds, itinerary: getActiveItinerary(state), mapConfig: state.otp.config.map, From d06f1bcae7838100063cc3b506e8fbc5181f83c8 Mon Sep 17 00:00:00 2001 From: Amy Corson <115499534+amy-corson-ibigroup@users.noreply.github.com> Date: Mon, 10 Nov 2025 09:47:56 -0600 Subject: [PATCH 2/2] Add comment --- lib/components/map/default-map.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/components/map/default-map.tsx b/lib/components/map/default-map.tsx index d897adb67..3e0568e3e 100644 --- a/lib/components/map/default-map.tsx +++ b/lib/components/map/default-map.tsx @@ -382,6 +382,7 @@ class DefaultMap extends Component { center={[lat, lon]} mapLibreProps={{ onLoad: () => { + // Once this map has loaded, we subtly trigger the geolocate control to update its state. return this.setState({ mapLoad: true }) }, reuseMaps: true