Skip to content

Commit

Permalink
remove dupes
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Aug 4, 2020
1 parent b691504 commit 4ac2740
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DynamicStyleProperty } from './dynamic_style_property';
import { makeMbClampedNumberExpression, dynamicRound } from '../style_util';
import { getOrdinalMbColorRampStops, getColorPalette } from '../../color_palettes';
import React from 'react';
import { COLOR_MAP_TYPE, MB_LOOKUP_FUNCTION } from '../../../../../common/constants';
import { COLOR_MAP_TYPE } from '../../../../../common/constants';
import {
isCategoricalStopsInvalid,
getOtherCategoryLabel,
Expand Down Expand Up @@ -114,12 +114,9 @@ export class DynamicColorProperty extends DynamicStyleProperty {
}, []);
const firstStopValue = colorStops[0];
const lessThanFirstStopValue = firstStopValue - 1;
const mbLookupFunction = this.supportsMbFeatureState()
? MB_LOOKUP_FUNCTION.FEATURE_STATE
: MB_LOOKUP_FUNCTION.GET;
return [
'step',
['coalesce', [mbLookupFunction, targetName], lessThanFirstStopValue],
['coalesce', [this.getMbLookupFunction(), targetName], lessThanFirstStopValue],
RGBA_0000, // MB will assign the base value to any features that is below the first stop value
...colorStops,
];
Expand All @@ -139,16 +136,13 @@ export class DynamicColorProperty extends DynamicStyleProperty {
}

const lessThanFirstStopValue = rangeFieldMeta.min - 1;
const mbLookupFunction = this.supportsMbFeatureState()
? MB_LOOKUP_FUNCTION.FEATURE_STATE
: MB_LOOKUP_FUNCTION.GET;
return [
'interpolate',
['linear'],
makeMbClampedNumberExpression({
minValue: rangeFieldMeta.min,
maxValue: rangeFieldMeta.max,
lookupFunction: mbLookupFunction,
lookupFunction: this.getMbLookupFunction(),
fallback: lessThanFirstStopValue,
fieldName: targetName,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,13 @@ export class DynamicSizeProperty extends DynamicStyleProperty {
}

_getMbDataDrivenSize({ targetName, minSize, maxSize, minValue, maxValue }) {
const lookup = this.supportsMbFeatureState()
? MB_LOOKUP_FUNCTION.FEATURE_STATE
: MB_LOOKUP_FUNCTION.GET;

const stops =
minValue === maxValue ? [maxValue, maxSize] : [minValue, minSize, maxValue, maxSize];
return [
'interpolate',
['linear'],
makeMbClampedNumberExpression({
lookupFunction: lookup,
lookupFunction: this.getMbLookupFunction(),
maxValue,
minValue,
fieldName: targetName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ import { Feature } from 'geojson';
import { AbstractStyleProperty, IStyleProperty } from './style_property';
import { DEFAULT_SIGMA } from '../vector_style_defaults';
import {
STYLE_TYPE,
SOURCE_META_DATA_REQUEST_ID,
FIELD_ORIGIN,
MB_LOOKUP_FUNCTION,
SOURCE_META_DATA_REQUEST_ID,
STYLE_TYPE,
VECTOR_STYLES,
} from '../../../../../common/constants';
import { OrdinalFieldMetaPopover } from '../components/field_meta/ordinal_field_meta_popover';
import { CategoricalFieldMetaPopover } from '../components/field_meta/categorical_field_meta_popover';
import {
CategoryFieldMeta,
FieldMetaOptions,
StyleMetaData,
RangeFieldMeta,
StyleMetaData,
} from '../../../../../common/descriptor_types';
import { IField } from '../../../fields/field';
import { IVectorLayer } from '../../../layers/vector_layer/vector_layer';
Expand All @@ -41,6 +42,7 @@ export interface IDynamicStyleProperty<T> extends IStyleProperty<T> {
supportsFieldMeta(): boolean;
getFieldMetaRequest(): Promise<unknown>;
supportsMbFeatureState(): boolean;
getMbLookupFunction(): MB_LOOKUP_FUNCTION;
pluckOrdinalStyleMetaFromFeatures(features: Feature[]): RangeFieldMeta | null;
pluckCategoricalStyleMetaFromFeatures(features: Feature[]): CategoryFieldMeta | null;
getValueSuggestions(query: string): Promise<string[]>;
Expand Down Expand Up @@ -196,6 +198,12 @@ export class DynamicStyleProperty<T> extends AbstractStyleProperty<T>
return !!this._field && this._field.canReadFromGeoJson();
}

getMbLookupFunction(): MB_LOOKUP_FUNCTION {
return this.supportsMbFeatureState()
? MB_LOOKUP_FUNCTION.FEATURE_STATE
: MB_LOOKUP_FUNCTION.GET;
}

getFieldMetaOptions() {
return _.get(this.getOptions(), 'fieldMetaOptions', { isEnabled: true });
}
Expand Down

0 comments on commit 4ac2740

Please sign in to comment.