From ea85f433c077e321d71ef48ac473fef9871743d4 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sat, 21 May 2022 01:50:55 +0200 Subject: [PATCH] Sort themes using layer --- Customizations/AllKnownLayouts.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Customizations/AllKnownLayouts.ts b/Customizations/AllKnownLayouts.ts index 037176e90..82e969564 100644 --- a/Customizations/AllKnownLayouts.ts +++ b/Customizations/AllKnownLayouts.ts @@ -46,8 +46,16 @@ export class AllKnownLayouts { return allLayers } + /** + * Returns all themes which use the given layer, reverse sorted by minzoom. This sort maximizes the chances that the layer is prominently featured on the first theme + */ public static themesUsingLayer(id: string, publicOnly = true): LayoutConfig[] { - return AllKnownLayouts.layoutsList.filter(l => !(publicOnly && l.hideFromOverview) && l.id !== "personal" && l.layers.some(layer => layer.id === id)) + const themes = AllKnownLayouts.layoutsList + .filter(l => !(publicOnly && l.hideFromOverview) && l.id !== "personal") + .map(theme => ({theme, minzoom: theme.layers.find(layer => layer.id === id)?.minzoom})) + .filter(obj => obj.minzoom !== undefined) + themes.sort((th0, th1) => th1.minzoom - th0.minzoom) + return themes.map(th => th.theme); } /**