@@ -11,14 +11,16 @@ import {OverscaledTileID} from '../source/tile_id';
1111import { fakeServer , type FakeServer } from 'nise' ;
1212
1313import { type EvaluationParameters } from './evaluation_parameters' ;
14- import { type LayerSpecification , type GeoJSONSourceSpecification , type FilterSpecification , type SourceSpecification , type StyleSpecification , type SymbolLayerSpecification , type SkySpecification } from '@maplibre/maplibre-gl-style-spec' ;
14+ import { type Feature , type LayerSpecification , type GeoJSONSourceSpecification , type FilterSpecification , type SourceSpecification , type StyleSpecification , type SymbolLayerSpecification , type SkySpecification } from '@maplibre/maplibre-gl-style-spec' ;
1515import { type GeoJSONSource } from '../source/geojson_source' ;
1616import { StubMap , sleep , waitForEvent } from '../util/test/util' ;
1717import { RTLPluginLoadedEventName } from '../source/rtl_text_plugin_status' ;
1818import { MessageType } from '../util/actor_messages' ;
1919import { MercatorTransform } from '../geo/projection/mercator_transform' ;
2020import { type Tile } from '../source/tile' ;
2121import type Point from '@mapbox/point-geometry' ;
22+ import { type PossiblyEvaluated } from './properties' ;
23+ import { type SymbolLayoutProps , type SymbolLayoutPropsPossiblyEvaluated } from './style_layer/symbol_style_layer_properties.g' ;
2224
2325function createStyleJSON ( properties ?) : StyleSpecification {
2426 return extend ( {
@@ -469,6 +471,37 @@ describe('Style.loadJSON', () => {
469471 expect ( style . stylesheet . layers [ 0 ] . id ) . toBe ( previousStyle . layers [ 0 ] . id ) ;
470472 expect ( style . stylesheet . layers ) . toHaveLength ( 1 ) ;
471473 } ) ;
474+
475+ test ( 'propagates global state object to layers' , async ( ) => {
476+ const style = new Style ( getStubMap ( ) ) ;
477+ style . loadJSON (
478+ createStyleJSON ( {
479+ sources : {
480+ 'source-id' : createGeoJSONSource ( )
481+ } ,
482+ layers : [
483+ {
484+ id : 'layer-id' ,
485+ type : 'symbol' ,
486+ source : 'source-id' ,
487+ layout : {
488+ 'text-size' : [ 'global-state' , 'size' ]
489+ }
490+ }
491+ ]
492+ } )
493+ ) ;
494+ await style . once ( 'style.load' ) ;
495+ // tests that reference to globalState is propagated to layers
496+ // by changing globalState property and checking if the changed value
497+ // was used when evaluating the layer
498+ const globalState = style . getGlobalState ( ) ;
499+ globalState . size = 12 ;
500+ const layer = style . getLayer ( 'layer-id' ) ;
501+ layer . recalculate ( { } as EvaluationParameters , [ ] ) ;
502+ const layout = layer . layout as PossiblyEvaluated < SymbolLayoutProps , SymbolLayoutPropsPossiblyEvaluated > ;
503+ expect ( layout . get ( 'text-size' ) . evaluate ( { } as Feature , { } ) ) . toBe ( 12 ) ;
504+ } ) ;
472505} ) ;
473506
474507describe ( 'Style._load' , ( ) => {
@@ -1090,7 +1123,7 @@ describe('Style.removeSource', () => {
10901123 } ]
10911124 } ) ) ;
10921125 await style . once ( 'style.load' ) ;
1093- style . update ( 1 as any as EvaluationParameters ) ;
1126+ style . update ( { zoom : 1 } as EvaluationParameters ) ;
10941127 return style ;
10951128 }
10961129
@@ -2344,7 +2377,7 @@ describe('Style.setPaintProperty', () => {
23442377 tr . resize ( 512 , 512 ) ;
23452378
23462379 await style . once ( 'style.load' ) ;
2347- style . update ( tr . zoom as any as EvaluationParameters ) ;
2380+ style . update ( { zoom : tr . zoom } as EvaluationParameters ) ;
23482381 const sourceCache = style . sourceCaches [ 'geojson' ] ;
23492382 const source = style . getSource ( 'geojson' ) as GeoJSONSource ;
23502383
@@ -2739,7 +2772,7 @@ describe('Style.setLayerZoomRange', () => {
27392772 vi . spyOn ( style , '_reloadSource' ) ;
27402773
27412774 style . setLayerZoomRange ( 'raster' , 5 , 12 ) ;
2742- style . update ( 0 as any as EvaluationParameters ) ;
2775+ style . update ( { zoom : 0 } as EvaluationParameters ) ;
27432776 expect ( style . _reloadSource ) . not . toHaveBeenCalled ( ) ;
27442777 } ) ;
27452778} ) ;
@@ -2888,7 +2921,7 @@ describe('Style.queryRenderedFeatures', () => {
28882921 style . sourceCaches . mapLibre . transform = transform ;
28892922 style . sourceCaches . other . transform = transform ;
28902923
2891- style . update ( 0 as any as EvaluationParameters ) ;
2924+ style . update ( { zoom : 0 } as EvaluationParameters ) ;
28922925 style . _updateSources ( transform ) ;
28932926 callback ( ) ;
28942927 } ) ;
0 commit comments