@@ -27,7 +27,7 @@ import { VectorStyleLegend } from './components/legend/vector_style_legend';
2727import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types' ;
2828import { SYMBOLIZE_AS_CIRCLE , SYMBOLIZE_AS_ICON } from './vector_constants' ;
2929import { getMakiSymbolAnchor } from './symbol_utils' ;
30- import { getComputedFieldName , isOnlySingleFeatureType , scaleValue } from './style_util' ;
30+ import { getComputedFieldName , isOnlySingleFeatureType } from './style_util' ;
3131import { StaticStyleProperty } from './properties/static_style_property' ;
3232import { DynamicStyleProperty } from './properties/dynamic_style_property' ;
3333import { DynamicSizeProperty } from './properties/dynamic_size_property' ;
@@ -81,7 +81,8 @@ export class VectorStyle extends AbstractStyle {
8181 ) ;
8282 this . _iconSizeStyleProperty = this . _makeSizeProperty (
8383 this . _descriptor . properties [ VECTOR_STYLES . ICON_SIZE ] ,
84- VECTOR_STYLES . ICON_SIZE
84+ VECTOR_STYLES . ICON_SIZE ,
85+ this . _descriptor . properties [ VECTOR_STYLES . SYMBOL ] . options . symbolizeAs === SYMBOLIZE_AS_ICON
8586 ) ;
8687 this . _iconOrientationProperty = this . _makeOrientationProperty (
8788 this . _descriptor . properties [ VECTOR_STYLES . ICON_ORIENTATION ] ,
@@ -434,37 +435,6 @@ export class VectorStyle extends AbstractStyle {
434435 ) ;
435436 }
436437
437- _getFeatureStyleParams ( ) {
438- return this . getDynamicPropertiesArray ( ) . map ( styleProperty => {
439- // "feature-state" data expressions are not supported with layout properties.
440- // To work around this limitation, some styling values must fall back to geojson property values.
441- let supportsFeatureState ;
442- let isScaled ;
443- // TODO move first check into DynamicSizeProperty.supportsFeatureState
444- if (
445- styleProperty . getStyleName ( ) === VECTOR_STYLES . ICON_SIZE &&
446- this . _descriptor . properties . symbol . options . symbolizeAs === SYMBOLIZE_AS_ICON
447- ) {
448- supportsFeatureState = false ;
449- isScaled = true ;
450- } else {
451- supportsFeatureState = styleProperty . supportsFeatureState ( ) ;
452- isScaled = styleProperty . isScaled ( ) ;
453- }
454-
455- const field = styleProperty . getField ( ) ;
456- return {
457- supportsFeatureState,
458- isScaled,
459- isOrdinal : styleProperty . isOrdinal ( ) ,
460- name : field . getName ( ) ,
461- meta : this . _getFieldMeta ( field . getName ( ) ) ,
462- formatter : this . _getFieldFormatter ( field . getName ( ) ) ,
463- computedName : getComputedFieldName ( styleProperty . getStyleName ( ) , field . getName ( ) ) ,
464- } ;
465- } ) ;
466- }
467-
468438 clearFeatureState ( featureCollection , mbMap , sourceId ) {
469439 const tmpFeatureIdentifier = {
470440 source : null ,
@@ -478,27 +448,13 @@ export class VectorStyle extends AbstractStyle {
478448 }
479449 }
480450
481- _getOrdinalValue ( value , isScaled , range ) {
482- const valueAsFloat = parseFloat ( value ) ;
483-
484- if ( isScaled ) {
485- return scaleValue ( valueAsFloat , range ) ;
486- }
487-
488- if ( isNaN ( valueAsFloat ) ) {
489- return 0 ;
490- }
491-
492- return valueAsFloat ;
493- }
494-
495451 setFeatureStateAndStyleProps ( featureCollection , mbMap , mbSourceId ) {
496452 if ( ! featureCollection ) {
497453 return ;
498454 }
499455
500- const featureStateParams = this . _getFeatureStyleParams ( ) ;
501- if ( featureStateParams . length === 0 ) {
456+ const dynamicStyleProps = this . getDynamicPropertiesArray ( ) ;
457+ if ( dynamicStyleProps . length === 0 ) {
502458 return ;
503459 }
504460
@@ -508,31 +464,15 @@ export class VectorStyle extends AbstractStyle {
508464 } ;
509465 const tmpFeatureState = { } ;
510466
511- //scale to [0,1] domain
512467 for ( let i = 0 ; i < featureCollection . features . length ; i ++ ) {
513468 const feature = featureCollection . features [ i ] ;
514469
515- for ( let j = 0 ; j < featureStateParams . length ; j ++ ) {
516- const {
517- supportsFeatureState,
518- isScaled,
519- isOrdinal,
520- name,
521- meta : range ,
522- formatter,
523- computedName,
524- } = featureStateParams [ j ] ;
525-
526- let styleValue ;
527- if ( isOrdinal ) {
528- styleValue = this . _getOrdinalValue ( feature . properties [ name ] , isScaled , range ) ;
529- } else if ( formatter ) {
530- styleValue = formatter ( feature . properties [ name ] ) ;
531- } else {
532- styleValue = feature . properties [ name ] ;
533- }
534-
535- if ( supportsFeatureState ) {
470+ for ( let j = 0 ; j < dynamicStyleProps . length ; j ++ ) {
471+ const dynamicStyleProp = dynamicStyleProps [ j ] ;
472+ const name = dynamicStyleProp . getField ( ) . getName ( ) ;
473+ const computedName = getComputedFieldName ( dynamicStyleProp . getStyleName ( ) , name ) ;
474+ const styleValue = dynamicStyleProp . getMbValue ( feature . properties [ name ] ) ;
475+ if ( dynamicStyleProp . supportsFeatureState ( ) ) {
536476 tmpFeatureState [ computedName ] = styleValue ;
537477 } else {
538478 feature . properties [ computedName ] = styleValue ;
@@ -547,7 +487,7 @@ export class VectorStyle extends AbstractStyle {
547487 //this return-value is used in an optimization for style-updates with mapbox-gl.
548488 //`true` indicates the entire data needs to reset on the source (otherwise the style-rules will not be reapplied)
549489 //`false` indicates the data does not need to be reset on the store, because styles are re-evaluated if they use featureState
550- return featureStateParams . some ( ( { supportsFeatureState } ) => ! supportsFeatureState ) ;
490+ return dynamicStyleProps . some ( dynamicStyleProp => ! dynamicStyleProp . supportsFeatureState ( ) ) ;
551491 }
552492
553493 arePointsSymbolizedAsCircles ( ) {
@@ -614,7 +554,7 @@ export class VectorStyle extends AbstractStyle {
614554 }
615555 }
616556
617- _makeSizeProperty ( descriptor , styleName ) {
557+ _makeSizeProperty ( descriptor , styleName , isSymbolizedAsIcon ) {
618558 if ( ! descriptor || ! descriptor . options ) {
619559 return new StaticSizeProperty ( { size : 0 } , styleName ) ;
620560 } else if ( descriptor . type === StaticStyleProperty . type ) {
@@ -626,7 +566,8 @@ export class VectorStyle extends AbstractStyle {
626566 styleName ,
627567 field ,
628568 this . _getFieldMeta ,
629- this . _getFieldFormatter
569+ this . _getFieldFormatter ,
570+ isSymbolizedAsIcon
630571 ) ;
631572 } else {
632573 throw new Error ( `${ descriptor } not implemented` ) ;
0 commit comments