@@ -33,6 +33,7 @@ import VectorSource from 'ol/source/Vector.js';
3333import VectorTileSource , { defaultLoadFunction } from 'ol/source/VectorTile.js' ;
3434import TileGrid from 'ol/tilegrid/TileGrid.js' ;
3535import { createXYZ } from 'ol/tilegrid.js' ;
36+ import { cameraObj , styleConfig } from './expressions.js' ;
3637import {
3738 normalizeSourceUrl ,
3839 normalizeSpriteDefinition ,
@@ -41,7 +42,6 @@ import {
4142import { hillshade , raster as rasterShader } from './shaders.js' ;
4243import {
4344 _colorWithOpacity ,
44- cameraObj ,
4545 getValue ,
4646 styleFunctionArgs ,
4747 stylefunction as applyStylefunction ,
@@ -104,6 +104,17 @@ import {
104104 * specified for the source in the mapbox style definition.
105105 */
106106
107+ const SUPPORTED_LAYER_TYPES = [
108+ 'background' ,
109+ 'circle' ,
110+ 'fill' ,
111+ 'fill-extrusion' ,
112+ 'line' ,
113+ 'symbol' ,
114+ 'raster' ,
115+ 'hillshade' ,
116+ ] ;
117+
107118/**
108119 * @param {import("ol/proj/Projection.js").default } projection Projection.
109120 * @param {number } [tileSize] Tile size.
@@ -600,7 +611,6 @@ function getBackgroundColor(glLayer, resolution, options, functionCache) {
600611 id : glLayer . id ,
601612 type : glLayer . type ,
602613 } ;
603- const layout = glLayer . layout || { } ;
604614 const paint = glLayer . paint || { } ;
605615 background [ 'paint' ] = paint ;
606616 cameraObj . zoom = getZoomForResolution (
@@ -625,7 +635,13 @@ function getBackgroundColor(glLayer, resolution, options, functionCache) {
625635 functionCache ,
626636 ) ;
627637 }
628- return layout . visibility == 'none'
638+ return getValue (
639+ background ,
640+ 'layout' ,
641+ 'visibility' ,
642+ emptyObj ,
643+ functionCache ,
644+ ) === 'none'
629645 ? undefined
630646 : _colorWithOpacity ( bg , opacity ) ;
631647}
@@ -931,7 +947,7 @@ function updateRasterLayerProperties(glLayer, layer, zoom, functionCache) {
931947 layer . setOpacity ( opacity ) ;
932948}
933949
934- function manageVisibility ( layer , mapOrGroup ) {
950+ function manageVisibility ( layer , mapOrGroup , functionCache ) {
935951 function onChange ( ) {
936952 const glStyle = mapOrGroup . get ( 'mapbox-style' ) ;
937953 if ( ! glStyle ) {
@@ -946,8 +962,13 @@ function manageVisibility(layer, mapOrGroup) {
946962 . some ( function ( mapboxLayer ) {
947963 return (
948964 ! mapboxLayer . layout ||
949- ! mapboxLayer . layout . visibility ||
950- mapboxLayer . layout . visibility === 'visible'
965+ getValue (
966+ mapboxLayer ,
967+ 'layout' ,
968+ 'visibility' ,
969+ emptyObj ,
970+ functionCache ,
971+ ) === 'visible'
951972 ) ;
952973 } ) ;
953974 if ( layer . get ( 'visible' ) !== visible ) {
@@ -1039,7 +1060,10 @@ export function setupLayer(glStyle, styleUrl, glLayer, options) {
10391060 layer = setupRasterLayer ( glSource , styleUrl , options ) ;
10401061 }
10411062 layer . setVisible (
1042- glLayer . layout ? glLayer . layout . visibility !== 'none' : true ,
1063+ glLayer . layout
1064+ ? getValue ( glLayer , 'layout' , 'visibility' , emptyObj , functionCache ) !==
1065+ 'none'
1066+ : true ,
10431067 ) ;
10441068
10451069 layer . on ( 'prerender' , prerenderRasterLayer ( glLayer , layer , functionCache ) ) ;
@@ -1109,7 +1133,10 @@ export function setupLayer(glStyle, styleUrl, glLayer, options) {
11091133 }
11101134 } ) ;
11111135 layer . setVisible (
1112- glLayer . layout ? glLayer . layout . visibility !== 'none' : true ,
1136+ glLayer . layout
1137+ ? getValue ( glLayer , 'layout' , 'visibility' , emptyObj , functionCache ) !==
1138+ 'none'
1139+ : true ,
11131140 ) ;
11141141 }
11151142 if ( layer ) {
@@ -1126,6 +1153,15 @@ export function setupLayer(glStyle, styleUrl, glLayer, options) {
11261153 * @return {Promise } Promise that resolves when the style is loaded.
11271154 */
11281155function processStyle ( glStyle , mapOrGroup , styleUrl , options ) {
1156+ if ( glStyle . schema ) {
1157+ Object . assign (
1158+ styleConfig ,
1159+ Object . keys ( glStyle . schema ) . reduce ( ( config , key ) => {
1160+ config [ key ] = glStyle . schema [ key ] ?. default ;
1161+ return config ;
1162+ } , { } ) ,
1163+ ) ;
1164+ }
11291165 const promises = [ ] ;
11301166
11311167 let view = null ;
@@ -1172,10 +1208,10 @@ function processStyle(glStyle, mapOrGroup, styleUrl, options) {
11721208 for ( let i = 0 , ii = glLayers . length ; i < ii ; ++ i ) {
11731209 const glLayer = glLayers [ i ] ;
11741210 const type = glLayer . type ;
1175- if ( type == 'heatmap' ) {
1211+ if ( ! SUPPORTED_LAYER_TYPES . includes ( type ) ) {
11761212 //FIXME Unsupported layer type
11771213 // eslint-disable-next-line no-console
1178- console . debug ( `layers[${ i } ].type "${ type } " not supported` ) ;
1214+ console . warn ( `layers[${ i } ].type "${ type } " not supported` ) ;
11791215 continue ;
11801216 } else {
11811217 id = glLayer . source || getSourceIdByRef ( glLayers , glLayer . ref ) ;
@@ -1424,7 +1460,7 @@ export function finalizeLayer(
14241460 Object . assign ( { styleUrl : styleUrl } , options ) ,
14251461 )
14261462 . then ( function ( ) {
1427- manageVisibility ( layer , mapOrGroup ) ;
1463+ manageVisibility ( layer , mapOrGroup , getFunctionCache ( glStyle ) ) ;
14281464 resolve ( ) ;
14291465 } )
14301466 . catch ( reject ) ;
0 commit comments