overlays below traces

This commit is contained in:
vcoppe
2024-05-08 21:51:52 +02:00
parent f8056cee73
commit 510edcf344
2 changed files with 26 additions and 12 deletions

View File

@@ -100,6 +100,17 @@
newMap.on('style.load', toggleTerrain); newMap.on('style.load', toggleTerrain);
newMap.on('pitch', toggleTerrain); newMap.on('pitch', toggleTerrain);
newMap.on('style.load', () => {
// add dummy layer to place the overlay layers below
newMap.addLayer({
id: 'overlays',
type: 'background',
paint: {
'background-color': 'rgba(0, 0, 0, 0)'
}
});
});
}); });
$: if ($map) { $: if ($map) {

View File

@@ -69,18 +69,21 @@
if (!$map.getSource(id)) { if (!$map.getSource(id)) {
$map.addSource(id, overlays[id]); $map.addSource(id, overlays[id]);
} }
$map.addLayer({ $map.addLayer(
id, {
type: overlays[id].type === 'raster' ? 'raster' : 'line', id,
source: id, type: overlays[id].type === 'raster' ? 'raster' : 'line',
paint: { source: id,
...(id in opacities paint: {
? overlays[id].type === 'raster' ...(id in opacities
? { 'raster-opacity': opacities[id] } ? overlays[id].type === 'raster'
: { 'line-opacity': opacities[id] } ? { 'raster-opacity': opacities[id] }
: {}) : { 'line-opacity': opacities[id] }
} : {})
}); }
},
'overlays'
);
} catch (e) { } catch (e) {
// No reliable way to check if the map is ready to add sources and layers // No reliable way to check if the map is ready to add sources and layers
} }