-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Impement FormatSectionOverride expression and use it for SymbolStyleL…
…ayer
- Loading branch information
1 parent
5a5bc24
commit 65bb6c9
Showing
12 changed files
with
208 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/style-spec/expression/definitions/format_section_override.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// @flow | ||
|
||
import assert from 'assert'; | ||
import type { Expression } from '../expression'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type { Value } from '../values'; | ||
import type { Type } from '../types'; | ||
import type { ZoomConstantExpression } from '../../expression'; | ||
import { NullType } from '../types'; | ||
import { PossiblyEvaluatedPropertyValue } from '../../../style/properties'; | ||
import { register } from '../../../util/web_worker_transfer'; | ||
|
||
export default class FormatSectionOverride<T> implements Expression { | ||
type: Type; | ||
defaultValue: PossiblyEvaluatedPropertyValue<T>; | ||
|
||
constructor(defaultValue: PossiblyEvaluatedPropertyValue<T>) { | ||
assert(defaultValue.property.overrides !== undefined); | ||
this.type = defaultValue.property.overrides ? defaultValue.property.overrides.runtimeType : NullType; | ||
this.defaultValue = defaultValue; | ||
} | ||
|
||
evaluate(ctx: EvaluationContext) { | ||
if (ctx.formattedSection) { | ||
const overrides = this.defaultValue.property.overrides; | ||
if (overrides && overrides.hasOverride(ctx.formattedSection)) { | ||
return overrides.getOverride(ctx.formattedSection); | ||
} | ||
} | ||
|
||
if (ctx.feature && ctx.featureState) { | ||
return this.defaultValue.evaluate(ctx.feature, ctx.featureState); | ||
} | ||
return null; | ||
} | ||
|
||
eachChild(fn: (Expression) => void) { | ||
if (!this.defaultValue.isConstant()) { | ||
const expr: ZoomConstantExpression<'source'> = ((this.defaultValue.value): any); | ||
fn(expr._styleExpression.expression); | ||
} | ||
} | ||
|
||
// Cannot be statically evaluated, as the output depends on the evaluation context. | ||
possibleOutputs(): Array<Value | void> { | ||
return [undefined]; | ||
} | ||
|
||
serialize() { | ||
return null; | ||
} | ||
} | ||
|
||
register('FormatSectionOverride', FormatSectionOverride, {omit: ['defaultValue']}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.