@@ -23,10 +23,9 @@ import type {
2323 Feature ,
2424 FeatureState ,
2525 GlobalProperties ,
26+ SourceExpression ,
2627 CompositeExpression ,
27- FormattedSection ,
28- ZoomConstantExpression ,
29- ZoomDependentExpression
28+ FormattedSection
3029} from '@maplibre/maplibre-gl-style-spec' ;
3130import type { FeatureStates } from '../source/source_state' ;
3231import type { DashEntry } from '../render/line_atlas' ;
@@ -57,20 +56,6 @@ type PaintOptions = {
5756 globalState ?: Record < string , any > ;
5857} ;
5958
60- type FillColorFallback = PossiblyEvaluatedPropertyValue < Color > [ 'value' ] | null ;
61-
62- type SourceExpressionWithRawEvaluation = ZoomConstantExpression < 'source' > ;
63-
64- type CompositeExpressionWithRawEvaluation = ZoomDependentExpression < 'composite' > ;
65-
66- function getFillColorFallback ( layer : TypedStyleLayer , property : string ) : FillColorFallback {
67- return property === 'fill-outline-color' ? ( layer . paint as any ) . get ( 'fill-color' ) . value : null ;
68- }
69-
70- function isNullColorEvaluationError ( error : unknown ) : boolean {
71- return error instanceof Error && error . message === 'Could not parse color from value \'null\'' ;
72- }
73-
7459/**
7560 * `Binder` is the interface definition for the strategies for constructing,
7661 * uploading, and binding paint property data as GLSL attributes. Most style-
@@ -209,42 +194,37 @@ class CrossFadedConstantBinder implements UniformBinder {
209194}
210195
211196class SourceExpressionBinder implements AttributeBinder {
212- expression : SourceExpressionWithRawEvaluation ;
197+ expression : SourceExpression ;
213198 type : string ;
214- zoom : number ;
215199 maxValue : number ;
216-
217- fillColorFallback : FillColorFallback ;
218200 paintVertexArray : StructArray ;
219201 paintVertexAttributes : StructArrayMember [ ] ;
220202 paintVertexBuffer : VertexBuffer ;
221203
222- constructor ( expression : SourceExpressionWithRawEvaluation , names : string [ ] , type : string , zoom : number , fillColorFallback : FillColorFallback , PaintVertexArray : {
204+ constructor ( expression : SourceExpression , names : string [ ] , type : string , PaintVertexArray : {
223205 new ( ...args : any ) : StructArray ;
224206 } ) {
225207 this . expression = expression ;
226208 this . type = type ;
227- this . zoom = zoom ;
228209 this . maxValue = 0 ;
229210 this . paintVertexAttributes = names . map ( ( name ) => ( {
230211 name : `a_${ name } ` ,
231212 type : 'Float32' ,
232213 components : type === 'color' ? 2 : 1 ,
233214 offset : 0
234215 } ) ) ;
235- this . fillColorFallback = fillColorFallback ;
236216 this . paintVertexArray = new PaintVertexArray ( ) ;
237217 }
238218
239219 populatePaintArray ( newLength : number , feature : Feature , options : PaintOptions ) {
240220 const start = this . paintVertexArray . length ;
241- const value = this . _evaluateValue ( feature , { } , options , options . canonical , options . formattedSection ) ;
221+ const value = this . expression . evaluate ( new EvaluationParameters ( 0 , options ) , feature , { } , options . canonical , [ ] , options . formattedSection ) ;
242222 this . paintVertexArray . resize ( newLength ) ;
243223 this . _setPaintValue ( start , newLength , value ) ;
244224 }
245225
246226 updatePaintArray ( start : number , end : number , feature : Feature , featureState : FeatureState , options : PaintOptions ) {
247- const value = this . _evaluateValue ( feature , featureState , options ) ;
227+ const value = this . expression . evaluate ( new EvaluationParameters ( 0 , options ) , feature , featureState ) ;
248228 this . _setPaintValue ( start , end , value ) ;
249229 }
250230
@@ -262,32 +242,6 @@ class SourceExpressionBinder implements AttributeBinder {
262242 }
263243 }
264244
265- _evaluateFillColorFallback ( feature : Feature , featureState : FeatureState , options : PaintOptions , canonical ?: CanonicalTileID , formattedSection ?: FormattedSection ) : Color | null | undefined {
266- if ( ! this . fillColorFallback ) return null ;
267- if ( this . fillColorFallback . kind === 'constant' ) {
268- return this . fillColorFallback . value ;
269- }
270- return this . fillColorFallback . evaluate ( new EvaluationParameters ( this . zoom , options ) , feature , featureState , canonical , [ ] , formattedSection ) ;
271- }
272-
273- _evaluateValue ( feature : Feature , featureState : FeatureState , options : PaintOptions , canonical ?: CanonicalTileID , formattedSection ?: FormattedSection ) {
274- if ( this . type !== 'color' || ! this . fillColorFallback ) {
275- return this . expression . evaluate ( new EvaluationParameters ( 0 , options ) , feature , featureState , canonical , [ ] , formattedSection ) ;
276- }
277-
278- try {
279- const value = this . expression . evaluateWithoutErrorHandling ( new EvaluationParameters ( 0 , options ) , feature , featureState , canonical , [ ] , formattedSection ) ;
280- return value == null ? this . _evaluateFillColorFallback ( feature , featureState , options , canonical , formattedSection ) : value ;
281- } catch ( error ) {
282- if ( isNullColorEvaluationError ( error ) ) {
283- return this . _evaluateFillColorFallback ( feature , featureState , options , canonical , formattedSection ) ;
284- }
285-
286- const value = this . expression . evaluate ( new EvaluationParameters ( 0 , options ) , feature , featureState , canonical , [ ] , formattedSection ) ;
287- return value == null ? this . _evaluateFillColorFallback ( feature , featureState , options , canonical , formattedSection ) : value ;
288- }
289- }
290-
291245 upload ( context : Context ) {
292246 if ( this . paintVertexArray ?. arrayBuffer . byteLength ) {
293247 if ( this . paintVertexBuffer ?. buffer ) {
@@ -306,19 +260,18 @@ class SourceExpressionBinder implements AttributeBinder {
306260}
307261
308262class CompositeExpressionBinder implements AttributeBinder , UniformBinder {
309- expression : CompositeExpressionWithRawEvaluation ;
263+ expression : CompositeExpression ;
310264 uniformNames : string [ ] ;
311265 type : string ;
312266 useIntegerZoom : boolean ;
313267 zoom : number ;
314268 maxValue : number ;
315269
316- fillColorFallback : FillColorFallback ;
317270 paintVertexArray : StructArray ;
318271 paintVertexAttributes : StructArrayMember [ ] ;
319272 paintVertexBuffer : VertexBuffer ;
320273
321- constructor ( expression : CompositeExpressionWithRawEvaluation , names : string [ ] , type : string , useIntegerZoom : boolean , zoom : number , fillColorFallback : FillColorFallback , PaintVertexArray : {
274+ constructor ( expression : CompositeExpression , names : string [ ] , type : string , useIntegerZoom : boolean , zoom : number , PaintVertexArray : {
322275 new ( ...args : any ) : StructArray ;
323276 } ) {
324277 this . expression = expression ;
@@ -327,7 +280,6 @@ class CompositeExpressionBinder implements AttributeBinder, UniformBinder {
327280 this . useIntegerZoom = useIntegerZoom ;
328281 this . zoom = zoom ;
329282 this . maxValue = 0 ;
330- this . fillColorFallback = fillColorFallback ;
331283 this . paintVertexAttributes = names . map ( ( name ) => ( {
332284 name : `a_${ name } ` ,
333285 type : 'Float32' ,
@@ -337,43 +289,17 @@ class CompositeExpressionBinder implements AttributeBinder, UniformBinder {
337289 this . paintVertexArray = new PaintVertexArray ( ) ;
338290 }
339291
340- _evaluateFillColorFallback ( zoom : number , feature : Feature , featureState : FeatureState , options : PaintOptions , canonical ?: CanonicalTileID , formattedSection ?: FormattedSection ) : Color | null | undefined {
341- if ( ! this . fillColorFallback ) return null ;
342- if ( this . fillColorFallback . kind === 'constant' ) {
343- return this . fillColorFallback . value ;
344- }
345- return this . fillColorFallback . evaluate ( new EvaluationParameters ( zoom , options ) , feature , featureState , canonical , [ ] , formattedSection ) ;
346- }
347-
348- _evaluateValue ( zoom : number , feature : Feature , featureState : FeatureState , options : PaintOptions , canonical ?: CanonicalTileID , formattedSection ?: FormattedSection ) {
349- if ( this . type !== 'color' || ! this . fillColorFallback ) {
350- return this . expression . evaluate ( new EvaluationParameters ( zoom , options ) , feature , featureState , canonical , [ ] , formattedSection ) ;
351- }
352-
353- try {
354- const value = this . expression . evaluateWithoutErrorHandling ( new EvaluationParameters ( zoom , options ) , feature , featureState , canonical , [ ] , formattedSection ) ;
355- return value == null ? this . _evaluateFillColorFallback ( zoom , feature , featureState , options , canonical , formattedSection ) : value ;
356- } catch ( error ) {
357- if ( isNullColorEvaluationError ( error ) ) {
358- return this . _evaluateFillColorFallback ( zoom , feature , featureState , options , canonical , formattedSection ) ;
359- }
360-
361- const value = this . expression . evaluate ( new EvaluationParameters ( zoom , options ) , feature , featureState , canonical , [ ] , formattedSection ) ;
362- return value == null ? this . _evaluateFillColorFallback ( zoom , feature , featureState , options , canonical , formattedSection ) : value ;
363- }
364- }
365-
366292 populatePaintArray ( newLength : number , feature : Feature , options : PaintOptions ) {
367- const min = this . _evaluateValue ( this . zoom , feature , { } , options , options . canonical , options . formattedSection ) ;
368- const max = this . _evaluateValue ( this . zoom + 1 , feature , { } , options , options . canonical , options . formattedSection ) ;
293+ const min = this . expression . evaluate ( new EvaluationParameters ( this . zoom , options ) , feature , { } , options . canonical , [ ] , options . formattedSection ) ;
294+ const max = this . expression . evaluate ( new EvaluationParameters ( this . zoom + 1 , options ) , feature , { } , options . canonical , [ ] , options . formattedSection ) ;
369295 const start = this . paintVertexArray . length ;
370296 this . paintVertexArray . resize ( newLength ) ;
371297 this . _setPaintValue ( start , newLength , min , max ) ;
372298 }
373299
374300 updatePaintArray ( start : number , end : number , feature : Feature , featureState : FeatureState , options : PaintOptions ) {
375- const min = this . _evaluateValue ( this . zoom , feature , featureState , options ) ;
376- const max = this . _evaluateValue ( this . zoom + 1 , feature , featureState , options ) ;
301+ const min = this . expression . evaluate ( new EvaluationParameters ( this . zoom , options ) , feature , featureState ) ;
302+ const max = this . expression . evaluate ( new EvaluationParameters ( this . zoom + 1 , options ) , feature , featureState ) ;
377303 this . _setPaintValue ( start , end , min , max ) ;
378304 }
379305
@@ -583,8 +509,6 @@ export class ProgramConfiguration {
583509 const useIntegerZoom = ( value . property as any ) . useIntegerZoom ;
584510 const propType = value . property . specification [ 'property-type' ] ;
585511 const isCrossFaded = propType === 'cross-faded' || propType === 'cross-faded-data-driven' ;
586- const fillColorFallback = getFillColorFallback ( layer , property ) ;
587-
588512 if ( expression . kind === 'constant' ) {
589513 this . binders [ property ] = isCrossFaded ?
590514 new CrossFadedConstantBinder ( expression . value , names ) :
@@ -596,11 +520,11 @@ export class ProgramConfiguration {
596520 property === 'line-dasharray' ?
597521 new CrossFadedDasharrayBinder ( expression as CompositeExpression , type , useIntegerZoom , zoom , StructArrayLayout , layer . id ) :
598522 new CrossFadedPatternBinder ( expression as CompositeExpression , type , useIntegerZoom , zoom , StructArrayLayout , layer . id ) :
599- new SourceExpressionBinder ( expression as SourceExpressionWithRawEvaluation , names , type , zoom , fillColorFallback , StructArrayLayout ) ;
523+ new SourceExpressionBinder ( expression as SourceExpression , names , type , StructArrayLayout ) ;
600524 keys . push ( `/a_${ property } ` ) ;
601525 } else {
602526 const StructArrayLayout = layoutType ( property , type , 'composite' ) ;
603- this . binders [ property ] = new CompositeExpressionBinder ( expression as CompositeExpressionWithRawEvaluation , names , type , useIntegerZoom , zoom , fillColorFallback , StructArrayLayout ) ;
527+ this . binders [ property ] = new CompositeExpressionBinder ( expression , names , type , useIntegerZoom , zoom , StructArrayLayout ) ;
604528 keys . push ( `/z_${ property } ` ) ;
605529 }
606530 }
@@ -656,9 +580,6 @@ export class ProgramConfiguration {
656580 binder instanceof CrossFadedBinder ) && binder . expression . isStateDependent === true ) {
657581 //AHM: Remove after https://github.com/mapbox/mapbox-gl-js/issues/6255
658582 const value = ( layer . paint as any ) . get ( property ) ;
659- if ( binder instanceof SourceExpressionBinder || binder instanceof CompositeExpressionBinder ) {
660- binder . fillColorFallback = getFillColorFallback ( layer , property ) ;
661- }
662583 binder . expression = value . value ;
663584 binder . updatePaintArray ( pos . start , pos . end , feature , featureStates [ id ] , options ) ;
664585 dirty = true ;
0 commit comments