Skip to content

Commit

Permalink
Merge pull request #884 from stadtnavi/fix/map-layer-stops-locked
Browse files Browse the repository at this point in the history
fix(map-layers): stop layers shown even if disabled
  • Loading branch information
andreashelms authored Feb 6, 2025
2 parents dcb52eb + 5f56cfa commit d095802
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 32 deletions.
24 changes: 16 additions & 8 deletions app/component/ItineraryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,9 @@ class ItineraryPage extends React.Component {
]?.legs.some(leg => leg.from?.vehicleRentalStation);

const mapLayerOptions = itineraryContainsDepartureFromVehicleRentalStation
? addBikeStationMapForRentalVehicleItineraries(itineraries)
? addBikeStationMapForRentalVehicleItineraries(
this.context.config.enableLockedMapLayers,
)
: this.props.mapLayerOptions;

const objectsToHide = getRentalStationsToHideOnMap(
Expand Down Expand Up @@ -1650,26 +1652,32 @@ class ItineraryPage extends React.Component {
}
}

const ItineraryPageWithBreakpoint = withBreakpoint(props => (
const ItineraryPageWithBreakpoint = withBreakpoint((props, context) => (
<ReactRelayContext.Consumer>
{({ environment }) => (
<ItineraryPage {...props} relayEnvironment={environment} />
<ItineraryPage {...props} {...context} relayEnvironment={environment} />
)}
</ReactRelayContext.Consumer>
));

const ItineraryPageWithStores = connectToStores(
ItineraryPageWithBreakpoint,
['MapLayerStore'],
({ getStore }) => ({
({ config, getStore }) => ({
mapLayers: getStore('MapLayerStore').getMapLayers({
notThese: ['stop', 'citybike', 'vehicles'],
}),
mapLayerOptions: getMapLayerOptions({
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles'],
}),
mapLayerOptions: getMapLayerOptions(
{
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles'],
},
config.enableLockedMapLayers,
),
}),
{
config: PropTypes.object,
},
);

const containerComponent = createRefetchContainer(
Expand Down
15 changes: 10 additions & 5 deletions app/component/ItineraryPageUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,16 @@ export function updateClient(itineraryTopics, context) {
startClient(itineraryTopics, context);
}

export function addBikeStationMapForRentalVehicleItineraries() {
return getMapLayerOptions({
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', 'citybike'],
});
export function addBikeStationMapForRentalVehicleItineraries(
enableLockedMapLayers,
) {
return getMapLayerOptions(
{
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', 'citybike'],
},
enableLockedMapLayers,
);
}

/**
Expand Down
22 changes: 14 additions & 8 deletions app/component/StopsNearYouPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ class StopsNearYouPage extends React.Component {
const showCityBikeTeaser = !readMessageIds.includes('citybike_teaser');
if (this.context.config.map.showLayerSelector) {
const { mode } = this.props.match.params;
const mapLayerOptions = getMapLayerOptions({
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', mode.toLowerCase()],
});
const mapLayerOptions = getMapLayerOptions(
{
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', mode.toLowerCase()],
},
this.context.config.enableLockedMapLayers,
);
this.setState({ showCityBikeTeaser, mapLayerOptions });
} else {
this.setState({ showCityBikeTeaser });
Expand Down Expand Up @@ -197,10 +200,13 @@ class StopsNearYouPage extends React.Component {

setMapLayerOptions = () => {
const { mode } = this.props.match.params;
const mapLayerOptions = getMapLayerOptions({
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', mode.toLowerCase()],
});
const mapLayerOptions = getMapLayerOptions(
{
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', mode.toLowerCase()],
},
this.context.config.enableLockedMapLayers,
);
this.setState({ mapLayerOptions });
};

Expand Down
16 changes: 11 additions & 5 deletions app/component/map/RoutePageMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,17 @@ class RoutePageMap extends React.Component {
const RoutePageMapWithVehicles = connectToStores(
withBreakpoint(RoutePageMap),
['RealTimeInformationStore', 'MapLayerStore'],
({ getStore }, { trip }) => {
({ config, getStore }, { trip }) => {
const mapLayers = getStore('MapLayerStore').getMapLayers({
notThese: ['stop', 'vehicles'],
});
const mapLayerOptions = getMapLayerOptions({
lockedMapLayers: ['vehicles', 'stop', 'citybike'],
selectedMapLayers: ['vehicles'],
});
const mapLayerOptions = getMapLayerOptions(
{
lockedMapLayers: ['vehicles', 'stop', 'citybike'],
selectedMapLayers: ['vehicles'],
},
config.enableLockedMapLayers,
);
if (trip) {
const { vehicles } = getStore('RealTimeInformationStore');
const tripStart = getStartTime(
Expand Down Expand Up @@ -227,6 +230,9 @@ const RoutePageMapWithVehicles = connectToStores(
}
return { mapLayers, mapLayerOptions };
},
{
config: PropTypes.object,
},
);

export default createFragmentContainer(RoutePageMapWithVehicles, {
Expand Down
11 changes: 7 additions & 4 deletions app/component/map/StopPageMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,13 @@ const StopPageMapWithStores = connectToStores(
}
const mapLayers = getStore(MapLayerStore).getMapLayers(ml);
const mode = getModeFromProps(props);
const mapLayerOptions = getMapLayerOptions({
lockedMapLayers: ['vehicles', mode],
selectedMapLayers: ['vehicles', mode],
});
const mapLayerOptions = getMapLayerOptions(
{
lockedMapLayers: ['vehicles', mode],
selectedMapLayers: ['vehicles', mode],
},
config.enableLockedMapLayers,
);
return {
locationState,
currentTime,
Expand Down
2 changes: 2 additions & 0 deletions app/configurations/config.herrenberg.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ export default configMerger(parentConfig, {

layers,

enableLockedMapLayers: false,

staticMessagesUrl: STATIC_MESSAGE_URL,

featuresUrl: FEATURES_URL,
Expand Down
7 changes: 5 additions & 2 deletions app/util/mapLayerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export const isFeatureLayerEnabled = (
return isLayerEnabled(layerName, mapLayers);
};

export const getMapLayerOptions = (options = {}) => {
export const getMapLayerOptions = (
options = {},
enableLockedMapLayers = true,
) => {
const layerOptions = {
parkAndRide: {
isLocked: false,
Expand Down Expand Up @@ -147,7 +150,7 @@ export const getMapLayerOptions = (options = {}) => {
};
lockedMapLayers.forEach(key => {
// Stop keyword locks every mode
if (key === 'stop') {
if (enableLockedMapLayers && key === 'stop') {
Object.keys(layerOptions[key]).forEach(subKey => {
if (layerOptions[key][subKey]) {
layerOptions[key][subKey].isLocked = true;
Expand Down

0 comments on commit d095802

Please sign in to comment.