-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expression kinds #5628
Expression kinds #5628
Conversation
|
||
type ConstantExpression = { | ||
kind: 'constant', | ||
evaluate: (globals: GlobalProperties, feature?: Feature) => any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not feasible yet, but I hope to be able to specialize the evaluate
method appropriately for the various kinds in a later commit. For example, constant expression evaluation should require no arguments, and the Feature
argument should not be optional for source and composite expression evaluation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once this happens, we'll need a way to heatmap-color.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
|
||
type ConstantExpression = { | ||
kind: 'constant', | ||
evaluate: (globals: GlobalProperties, feature?: Feature) => any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once this happens, we'll need a way to heatmap-color.
src/style-spec/expression/index.js
Outdated
type SourceExpression = { | ||
result: 'source', | ||
evaluate: (globals: GlobalProperties, feature?: Feature) => any, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about FeatureExpression
? Seems more direct to me, but maybe there was a reason we opted for SourceFunction
over FeatureFunction
before...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#5531 suggests DataExpression
-- let's hash out terminology there. For now, I'm happy just getting JS consistent with current native terms. 😄
return isFeatureConstant ? { | ||
functionType: 'constant', | ||
layoutSize: layer.getLayoutValue(sizeProperty, {zoom: tileZoom + 1}) | ||
} : { functionType: 'source' }; | ||
} | ||
|
||
// calculate covering zoom stops for zoom-dependent values | ||
const levels = declaration.expression.zoomStops; | ||
const levels = (declaration.expression: any).zoomStops; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This any
cast is justified by the !declaration || declaration.isZoomConstant()
check above, right? Let's include a line comment indicating that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. For #2739 this code is going to get rewritten in cases over expression.kind
, without any casts required, so I'm just going to leave it for now.
7349eab
to
bfd4257
Compare
Introduce the same sort of discriminated union as is used in native: an expression (or function, or generally, any property value) has one of the following kinds:
constant
,camera
,source
,composite
.This is a prerequisite for #2739 / #3044.