diff --git a/app/component/MapLayersDialogContent.js b/app/component/MapLayersDialogContent.js index ad17049d13..e65c2fa9cc 100644 --- a/app/component/MapLayersDialogContent.js +++ b/app/component/MapLayersDialogContent.js @@ -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 }, }; }) || [] ); @@ -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, @@ -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 ( <>