Skip to content

Commit 620d7dd

Browse files
Merge branch 'master' into ftr/reorganize--page-objects
2 parents 4872d33 + b7c5350 commit 620d7dd

File tree

3 files changed

+52
-80
lines changed

3 files changed

+52
-80
lines changed

x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,23 @@ function getSymbolSizeIcons() {
4343
}
4444

4545
export class DynamicSizeProperty extends DynamicStyleProperty {
46+
constructor(options, styleName, field, getFieldMeta, getFieldFormatter, isSymbolizedAsIcon) {
47+
super(options, styleName, field, getFieldMeta, getFieldFormatter);
48+
this._isSymbolizedAsIcon = isSymbolizedAsIcon;
49+
}
50+
4651
supportsFeatureState() {
47-
return this.getStyleName() !== VECTOR_STYLES.LABEL_SIZE;
52+
// mb style "icon-size" does not support feature state
53+
if (this.getStyleName() === VECTOR_STYLES.ICON_SIZE && this._isSymbolizedAsIcon) {
54+
return false;
55+
}
56+
57+
// mb style "text-size" does not support feature state
58+
if (this.getStyleName() === VECTOR_STYLES.LABEL_SIZE) {
59+
return false;
60+
}
61+
62+
return true;
4863
}
4964

5065
syncHaloWidthWithMb(mbLayerId, mbMap) {

x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { AbstractStyleProperty } from './style_property';
99
import { DEFAULT_SIGMA } from '../vector_style_defaults';
1010
import { STYLE_TYPE } from '../../../../../common/constants';
1111
import { DynamicLegendRow } from './components/dynamic_legend_row';
12+
import { scaleValue } from '../style_util';
1213
import React from 'react';
1314

1415
export class DynamicStyleProperty extends AbstractStyleProperty {
@@ -119,13 +120,28 @@ export class DynamicStyleProperty extends AbstractStyleProperty {
119120
}
120121

121122
formatField(value) {
122-
if (this.getField()) {
123-
const fieldName = this.getField().getName();
124-
const fieldFormatter = this._getFieldFormatter(fieldName);
125-
return fieldFormatter ? fieldFormatter(value) : value;
126-
} else {
123+
if (!this.getField()) {
127124
return value;
128125
}
126+
127+
const fieldName = this.getField().getName();
128+
const fieldFormatter = this._getFieldFormatter(fieldName);
129+
return fieldFormatter ? fieldFormatter(value) : value;
130+
}
131+
132+
getMbValue(value) {
133+
if (!this.isOrdinal()) {
134+
return this.formatField(value);
135+
}
136+
137+
const valueAsFloat = parseFloat(value);
138+
if (this.isScaled()) {
139+
return scaleValue(valueAsFloat, this.getFieldMeta());
140+
}
141+
if (isNaN(valueAsFloat)) {
142+
return 0;
143+
}
144+
return valueAsFloat;
129145
}
130146

131147
renderLegendDetailRow() {

x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js

Lines changed: 15 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { VectorStyleLegend } from './components/legend/vector_style_legend';
2727
import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types';
2828
import { SYMBOLIZE_AS_CIRCLE, SYMBOLIZE_AS_ICON } from './vector_constants';
2929
import { getMakiSymbolAnchor } from './symbol_utils';
30-
import { getComputedFieldName, isOnlySingleFeatureType, scaleValue } from './style_util';
30+
import { getComputedFieldName, isOnlySingleFeatureType } from './style_util';
3131
import { StaticStyleProperty } from './properties/static_style_property';
3232
import { DynamicStyleProperty } from './properties/dynamic_style_property';
3333
import { 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

Comments
 (0)