Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Sep 14, 2020
1 parent 4d45113 commit 9b092a6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
*/

import { Map as MbMap } from 'mapbox-gl';
import { DynamicStyleProperty, getNumericalMbFeatureStateValue } from './dynamic_style_property';
import {
DynamicStyleProperty,
getNumericalMbFeatureStateValue,
RawValue,
} from './dynamic_style_property';
import { OrientationDynamicOptions } from '../../../../../common/descriptor_types';

export class DynamicOrientationProperty extends DynamicStyleProperty<OrientationDynamicOptions> {
syncIconRotationWithMb(symbolLayerId: string, mbMap: MbMap) {
if (this._field && this._field.isValid()) {
const targetName = this.getMbPropertyName();
mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', ['coalesce', ['get', targetName], 0]);
mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', [
'coalesce',
[this.getMbLookupFunction(), targetName],
0,
]);
} else {
mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', 0);
}
Expand All @@ -22,9 +30,7 @@ export class DynamicOrientationProperty extends DynamicStyleProperty<Orientation
return false;
}

getMbPropertyValue(
rawValue: string | number | null | undefined
): string | number | null | undefined {
getMbPropertyValue(rawValue: RawValue): RawValue {
return getNumericalMbFeatureStateValue(rawValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { IJoin } from '../../../joins/join';
import { IVectorStyle } from '../vector_style';
import { getComputedFieldName } from '../style_util';

export type RawValue = string | number | undefined | null;

export interface IDynamicStyleProperty<T> extends IStyleProperty<T> {
getFieldMetaOptions(): FieldMetaOptions;
getField(): IField | null;
Expand All @@ -55,7 +57,7 @@ export interface IDynamicStyleProperty<T> extends IStyleProperty<T> {
// The combination of both will inform what field-name (e.g. the "raw" field name from the properties, the "computed field-name" for an on-the-fly created property (e.g. for feature-state or field-formatting).
// todo: There is an existing limitation to .mvt backed sources, where the field-formatters are not applied. Here, the raw-data needs to be accessed.
getMbPropertyName(): string;
getMbPropertyValue(value: string | number | null | undefined): string | number | null | undefined;
getMbPropertyValue(value: RawValue): RawValue;
}

export type FieldFormatter = (value: string | number | undefined) => string | number;
Expand Down Expand Up @@ -367,23 +369,19 @@ export class DynamicStyleProperty<T>
// They just re-use the original property-name
targetName = this._field.getName();
} else {
if (this._field.canReadFromGeoJson()) {
if (this._field.canReadFromGeoJson() && this._field.supportsAutoDomain()) {
// Geojson-sources can support rewrite
// e.g. field-formatters will create duplicate field
targetName = this._field.supportsAutoDomain()
? getComputedFieldName(this.getStyleName(), this._field.getName())
: this._field.getName();
targetName = getComputedFieldName(this.getStyleName(), this._field.getName());
} else {
// Non-geojson sources (e.g. mvt)
// Non-geojson sources (e.g. 3rd party mvt or ES-source as mvt)
targetName = this._field.getName();
}
}
return targetName;
}

getMbPropertyValue(
rawValue: string | number | null | undefined
): string | number | null | undefined {
getMbPropertyValue(rawValue: RawValue): RawValue {
return this.supportsMbFeatureState() ? getNumericalMbFeatureStateValue(rawValue) : rawValue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
*/

import { Map as MbMap } from 'mapbox-gl';
import { DynamicStyleProperty } from './dynamic_style_property';
import { DynamicStyleProperty, RawValue } from './dynamic_style_property';
import { LabelDynamicOptions } from '../../../../../common/descriptor_types';

export class DynamicTextProperty extends DynamicStyleProperty<LabelDynamicOptions> {
syncTextFieldWithMb(mbLayerId: string, mbMap: MbMap) {
if (this._field && this._field.isValid()) {
const targetName = this.getMbPropertyName();
mbMap.setLayoutProperty(mbLayerId, 'text-field', ['coalesce', ['get', targetName], '']);
mbMap.setLayoutProperty(mbLayerId, 'text-field', [
'coalesce',
[this.getMbLookupFunction(), targetName],
'',
]);
} else {
mbMap.setLayoutProperty(mbLayerId, 'text-field', null);
}
Expand All @@ -30,9 +34,7 @@ export class DynamicTextProperty extends DynamicStyleProperty<LabelDynamicOption
return false;
}

getMbPropertyValue(
rawValue: string | number | null | undefined
): string | number | null | undefined {
getMbPropertyValue(rawValue: RawValue): RawValue {
return this.formatField(rawValue);
}
}

0 comments on commit 9b092a6

Please sign in to comment.