1 | import assert from 'assert';
|
2 | import type {Expression} from '../style-spec/expression/expression';
|
3 | import type EvaluationContext from '../style-spec/expression/evaluation_context';
|
4 | import type {Type} from '../style-spec/expression/types';
|
5 | import type {ZoomConstantExpression} from '../style-spec/expression';
|
6 | import {NullType} from '../style-spec/expression/types';
|
7 | import {PossiblyEvaluatedPropertyValue} from './properties';
|
8 | import {register} from '../util/web_worker_transfer';
|
9 |
|
10 |
|
11 |
|
12 | export default class FormatSectionOverride<T> implements Expression {
|
13 | type: Type;
|
14 | defaultValue: PossiblyEvaluatedPropertyValue<T>;
|
15 |
|
16 | constructor(defaultValue: PossiblyEvaluatedPropertyValue<T>) {
|
17 | assert(defaultValue.property.overrides !== undefined);
|
18 | this.type = defaultValue.property.overrides ? defaultValue.property.overrides.runtimeType : NullType;
|
19 | this.defaultValue = defaultValue;
|
20 | }
|
21 |
|
22 | evaluate(ctx: EvaluationContext) {
|
23 | if (ctx.formattedSection) {
|
24 | const overrides = this.defaultValue.property.overrides;
|
25 | if (overrides && overrides.hasOverride(ctx.formattedSection)) {
|
26 | return overrides.getOverride(ctx.formattedSection);
|
27 | }
|
28 | }
|
29 |
|
30 | if (ctx.feature && ctx.featureState) {
|
31 | return this.defaultValue.evaluate(ctx.feature, ctx.featureState);
|
32 | }
|
33 |
|
34 | return this.defaultValue.property.specification.default;
|
35 | }
|
36 |
|
37 | eachChild(fn: (_: Expression) => void) {
|
38 | if (!this.defaultValue.isConstant()) {
|
39 | const expr: ZoomConstantExpression<'source'> = (this.defaultValue.value as any);
|
40 | fn(expr._styleExpression.expression);
|
41 | }
|
42 | }
|
43 |
|
44 |
|
45 | outputDefined() {
|
46 | return false;
|
47 | }
|
48 |
|
49 | serialize() {
|
50 | return null;
|
51 | }
|
52 | }
|
53 |
|
54 | register('FormatSectionOverride', FormatSectionOverride, {omit: ['defaultValue']});
|