-
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.
Allow overriding SymbolLayer's paint properties using format expressi…
…on options (#8068) * Add text color option to format expression * Update text-shaping and format expression's unit tests * Impement FormatSectionOverride expression and use it for SymbolStyleLayer * Unskip format expression's "text-color" render tests * Update documentation * Add unit test for SymbolStyleLayer::has/setPaintOverrides * Add unit test for FormatSectionOverride expression * fix paint property overrides in expressions The previous way of checking for paint overrides didn't properly handle the case where there might be multiple cases with some not having overrides. * move setPaintOverrides to recalculate This seems more robust because it changes the calculated values consistently after they are calculated instead of just in some cases. This makes it a bit easier to understand what state the style layer is in.
- Loading branch information
1 parent
4b6784f
commit b4fd6ee
Showing
37 changed files
with
674 additions
and
143 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
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
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
// @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 this.defaultValue.property.specification.default; | ||
} | ||
|
||
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
Oops, something went wrong.