Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(layer-dialog): sort entries by layer config order #877

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 65 additions & 22 deletions app/component/MapLayersDialogContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ class MapLayersDialogContent extends React.Component {
(l.category === undefined || l.category === category),
)
.map(layer => {
const key = layer.id || layer.url;
const id = layer.id || layer.url;
return {
key,
key: layer.code || id,
checked:
(layer.isOffByDefault && geoJson[key] === true) ||
(!layer.isOffByDefault && geoJson[key] !== false), // todo: is active?
(layer.isOffByDefault && geoJson[id] === true) ||
(!layer.isOffByDefault && geoJson[id] !== false), // todo: is active?
defaultMessage: layer.name?.[lang] || layer.defaultMessage,
labelId: layer.labelId, // todo: rename?
icon: layer.icon,
settings: { geoJson: key },
settings: { geoJson: id },
};
}) || []
);
Expand Down Expand Up @@ -211,7 +211,7 @@ class MapLayersDialogContent extends React.Component {
return {
checked,
label: translations[intl.locale],
key: `map-layer-${code}`,
key: code,
categories: categories?.map(category => ({
...category,
settings: category.code,
Expand Down Expand Up @@ -242,6 +242,24 @@ class MapLayersDialogContent extends React.Component {
({ code }) => code === 'health_and_social_services',
);

const sortLayersByKey = (a, b) => {
// Retrieve the order of the layers from the configuration.
// Top- and Sub-level category codes are considered.
const layerOrder =
config.layers
?.flatMap(category => category.categories || category)
.map(category => [
category.code,
// Retrieve order of sub-categories if they exist
...(category.categories
? category.categories.map(({ code }) => code)
: []),
])
.flat() || [];

return layerOrder.indexOf(a.key) - layerOrder.indexOf(b.key);
};

return (
<>
<button
Expand Down Expand Up @@ -276,20 +294,23 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Bus stop',
labelId: 'map-layer-stop-bus',
icon: 'icon-icon_stop_bus',
key: 'bus',
settings: { stop: 'bus' },
},
isTransportModeEnabled(transportModes.subway) && {
checked: terminal.subway,
defaultMessage: 'Subway station',
labelId: 'map-layer-terminal-subway',
icon: 'icon-icon_stop_subway',
key: 'subway',
settings: { stop: 'subway', terminal: 'subway' },
},
isTransportModeEnabled(transportModes.rail) && {
checked: terminal.rail,
defaultMessage: 'Railway station',
labelId: 'map-layer-terminal-rail',
icon: 'icon-icon_stop_rail',
key: 'rail',
settings: { stop: 'rail', terminal: 'rail' },
},
isTransportModeEnabled(transportModes.tram) && {
Expand All @@ -298,6 +319,7 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Tram stop',
labelId: 'map-layer-stop-tram',
icon: 'icon-icon_stop_tram',
key: 'tram',
settings: { stop: 'tram' },
},
isTransportModeEnabled(transportModes.ferry) && {
Expand All @@ -306,6 +328,7 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Ferry',
labelId: 'map-layer-stop-ferry',
icon: 'icon-icon_stop_ferry',
key: 'ferry',
settings: { stop: 'ferry' },
},
this.context.config.vehicles && {
Expand All @@ -314,9 +337,10 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Moving vehicles',
labelId: 'map-layer-vehicles',
icon: 'icon-icon_moving_bus',
key: 'vehicles',
settings: 'vehicles',
},
]}
].sort(sortLayersByKey)}
/>
<LayerCategoryDropdown
icon="icon-icon_bike_car"
Expand All @@ -332,6 +356,7 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Bike parks',
labelId: 'map-layer-bike-parks', // todo: rename?
icon: 'icon-bike-park',
key: 'parkAndRideForBikes',
settings: 'parkAndRideForBikes',
},
]
Expand All @@ -350,6 +375,7 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Roadworks',
labelId: 'map-layer-roadworks',
icon: 'icon-icon_roadworks',
key: 'roadworks',
settings: 'roadworks',
},
this.context.config.weatherStations &&
Expand All @@ -358,6 +384,7 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Road weather',
labelId: 'map-layer-weather-stations',
icon: 'icon-icon_stop_monitor',
key: 'weatherStations',
settings: 'weatherStations',
},
this.context.config.parkAndRide &&
Expand All @@ -368,6 +395,7 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Park &amp; ride',
labelId: 'map-layer-park-and-ride',
icon: 'icon-icon_open_carpark',
key: 'parkAndRide',
settings: 'parkAndRide',
},
this.context.config.chargingStations &&
Expand All @@ -376,6 +404,7 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Charging stations',
labelId: 'map-layer-charging-stations',
icon: 'icon-icon_stop_car_charging_station',
key: 'chargingStations',
settings: 'chargingStations',
},
])
Expand All @@ -388,7 +417,8 @@ class MapLayersDialogContent extends React.Component {
),
)
.concat(datahubBicycleLayers)
.concat(getPoiLayers(bikeCarLayer))}
.concat(getPoiLayers(bikeCarLayer))
.sort(sortLayersByKey)}
/>
<LayerCategoryDropdown
icon="icon-icon_material_bike_scooter"
Expand All @@ -405,6 +435,7 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Rental Bikes',
labelId: 'map-layer-sharing-bicycle',
icon: 'icon-icon_rental_bicycle',
key: 'bicycle',
settings: { rental: 'bicycle' },
},
this.context.config?.cityBike?.showCityBikes &&
Expand All @@ -414,6 +445,7 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Rental Scooters',
labelId: 'map-layer-sharing-scooter',
icon: 'icon-icon_rental_scooter',
key: 'scooter',
settings: { rental: 'scooter' },
},
this.context.config?.cityBike?.showCityBikes &&
Expand All @@ -423,6 +455,7 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Rental Cargo-Bikes',
labelId: 'map-layer-sharing-cargo_bicycle',
icon: 'icon-icon_rental_cargo_bicycle',
key: 'cargo_bicycle',
settings: { rental: 'cargo_bicycle' },
},
this.context.config?.cityBike?.showCityBikes &&
Expand All @@ -432,16 +465,20 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Rental Cars',
labelId: 'map-layer-sharing-car',
icon: 'icon-icon_rental_car',
key: 'car',
settings: { rental: 'car' },
},
isTransportModeEnabled(transportModes.carpool) && {
checked: terminal.carpool,
defaultMessage: 'Carpool stops',
labelId: 'map-layer-carpool',
icon: 'icon-icon_carpool_stops',
key: 'carpool',
settings: { stop: 'carpool', terminal: 'carpool' },
},
].concat(getPoiLayers(sharingServicesLayer))}
]
.concat(getPoiLayers(sharingServicesLayer))
.sort(sortLayersByKey)}
/>
<LayerCategoryDropdown
icon="icon-icon_leisure_tourism"
Expand All @@ -450,16 +487,16 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Leisure & Tourism',
})}
onChange={this.updateSetting}
options={[]
.concat(getPoiLayers(leisureAndTourismLayer))
options={getPoiLayers(leisureAndTourismLayer)
.concat(
this.layerOptionsByCategory(
'leisure_and_tourism',
config.geoJson?.layers,
geoJson,
this.props.lang,
),
)}
)
.sort(sortLayersByKey)}
/>
<LayerCategoryDropdown
icon="icon-icon_shopping_services"
Expand All @@ -468,7 +505,9 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Shopping & Services',
})}
onChange={this.updateSetting}
options={getPoiLayers(shoppingAndServicesLayer)}
options={getPoiLayers(shoppingAndServicesLayer).sort(
sortLayersByKey,
)}
/>
<LayerCategoryDropdown
icon="icon-icon_public_facilities"
Expand All @@ -477,7 +516,9 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Public Facilities',
})}
onChange={this.updateSetting}
options={getPoiLayers(publicFacilitiesLayer)}
options={getPoiLayers(publicFacilitiesLayer).sort(
sortLayersByKey,
)}
/>
<LayerCategoryDropdown
icon="icon-icon_health_social_services"
Expand All @@ -486,14 +527,16 @@ class MapLayersDialogContent extends React.Component {
defaultMessage: 'Health & Social Services',
})}
onChange={this.updateSetting}
options={getPoiLayers(healthAndSocialServicesLayer).concat(
this.layerOptionsByCategory(
'health_and_social_services',
config.geoJson?.layers,
geoJson,
this.props.lang,
),
)}
options={getPoiLayers(healthAndSocialServicesLayer)
.concat(
this.layerOptionsByCategory(
'health_and_social_services',
config.geoJson?.layers,
geoJson,
this.props.lang,
),
)
.sort(sortLayersByKey)}
/>
</div>

Expand Down
6 changes: 6 additions & 0 deletions app/configurations/config.herrenberg.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ export default configMerger(parentConfig, {
layers: [
// bicycleinfrastructure includes shops, repair stations,
{
code: 'bike_repair',
name: {
fi: '',
en: 'Service stations and stores',
Expand All @@ -365,6 +366,7 @@ export default configMerger(parentConfig, {
},
// Bicycle network layer
{
code: 'cycle_network',
name: {
fi: '',
en: "Bicycle network",
Expand All @@ -381,6 +383,7 @@ export default configMerger(parentConfig, {
},
// LoRaWan map layer
{
code: 'loarawan_gateways',
name: {
fi: '',
en: 'LoRaWAN Gateways',
Expand All @@ -393,6 +396,7 @@ export default configMerger(parentConfig, {
},
// Nette Toilette layer
{
code: 'friendly_toilet',
name: {
fi: '',
en: 'Public Toilets',
Expand All @@ -404,6 +408,7 @@ export default configMerger(parentConfig, {
icon: 'icon-icon_public_toilets',
},
{
code: 'sights',
name: {
fi: '',
en: 'sights',
Expand All @@ -415,6 +420,7 @@ export default configMerger(parentConfig, {
icon: 'icon-icon_sights',
},
{
code: 'school_route_map',
name: {
fi: '',
en: 'School route map',
Expand Down
Loading