@@ -40,20 +40,18 @@ function buildStyle(): Promise<StyleSpecification> {
4040 promise = fetch ( VECTOR_SOURCE_URL )
4141 . then ( ( r ) => r . json ( ) )
4242 . then ( ( style : StyleSpecification ) => {
43- // Insert satellite imagery above fill/background layers but below
44- // labels and lines. The fills act as a loading placeholder so there
45- // is no white flash while satellite tiles load.
46- const firstSymbolIdx = style . layers . findIndex (
47- ( l : LayerSpecification ) => l . type === "symbol" || l . type === "line" ,
43+ // Partition layers: fills/backgrounds below satellite as a loading
44+ // placeholder (avoids white flash), everything else on top.
45+ const fills = style . layers . filter (
46+ ( l : LayerSpecification ) =>
47+ l . type === "background" || l . type === "fill" ,
48+ ) ;
49+ const rest = style . layers . filter (
50+ ( l : LayerSpecification ) =>
51+ l . type !== "background" && l . type !== "fill" ,
4852 ) ;
49- const insertAt =
50- firstSymbolIdx === - 1 ? style . layers . length : firstSymbolIdx ;
5153
52- const layers = [
53- ...style . layers . slice ( 0 , insertAt ) ,
54- SATELLITE_LAYER ,
55- ...style . layers . slice ( insertAt ) ,
56- ] ;
54+ const layers = [ ...fills , SATELLITE_LAYER , ...rest ] ;
5755
5856 const composite : StyleSpecification = {
5957 ...style ,
0 commit comments