From 8379a894d0fc826e33d24d05b3e44852556a60b1 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 7 Jun 2023 14:34:58 +0200 Subject: [PATCH] Fix: ordering of baselayers --- UI/Map/MapLibreAdaptor.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/UI/Map/MapLibreAdaptor.ts b/UI/Map/MapLibreAdaptor.ts index 40835e49f..4d7e2b677 100644 --- a/UI/Map/MapLibreAdaptor.ts +++ b/UI/Map/MapLibreAdaptor.ts @@ -376,16 +376,23 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap { map.addSource(background.id, MapLibreAdaptor.prepareWmsSource(background)) map.resize() + + let addLayerBeforeId = "aeroway_fill"// this is the first non-landuse item in the stylesheet, we add the raster layer before the roads but above the landuse + if(background.category === "osmbasedmap" || background.category === "map"){ + // The background layer is already an OSM-based map or another map, so we don't want anything from the baselayer + let layers = map.getStyle().layers + // THe last index of the maptiler layers + let lastIndex = layers.findIndex(layer => layer.id === "housenumber") + addLayerBeforeId = layers[lastIndex + 1]?.id ?? "housenumber" + } + map.addLayer( { id: background.id, type: "raster", source: background.id, paint: {}, - }, - background.category === "osmbasedmap" || background.category === "map" - ? undefined - : "aeroway_fill" + },addLayerBeforeId ) await this.awaitStyleIsLoaded() this.removeCurrentLayer(map)