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('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) {

View File

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