-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add "default" property for functions #4175
Conversation
19b4d67
to
a90eaeb
Compare
definition, and an object defining a style spec property. It handles color parsing and validation of feature values | ||
internally. | ||
* Functions now support a "default" property. | ||
* `parseColor` was promoted from gl-js. |
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.
@@ -20,15 +28,38 @@ function createFunction(parameters, defaultType) { | |||
const zoomAndFeatureDependent = parameters.stops && typeof parameters.stops[0][0] === 'object'; | |||
const featureDependent = zoomAndFeatureDependent || parameters.property !== undefined; | |||
const zoomDependent = zoomAndFeatureDependent || !featureDependent; | |||
const type = parameters.type || defaultType || 'exponential'; | |||
const type = parameters.type || (propertySpec.function === 'interpolated' ? 'exponential' : 'interval'); |
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.
Have you thought about renaming the propertySpec.function
"enum" values now that this is part of our public API?
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.
Filed #4194 for what I think we should do there.
} | ||
fun = function(zoom, feature) { | ||
return outputFunction(evaluateExponentialFunction({ | ||
stops: featureFunctionStops, | ||
base: parameters.base | ||
}, zoom)(zoom, feature)); | ||
}, propertySpec, zoom)(zoom, feature)); |
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.
Why do you need to pass propertySpec
to evaluateExponentialFunction
both as an argument and embedded within featureFunctionStops
?
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.
Ah. I misread the code. This is 👍
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.
Where is it embedded within featureFunctionStops
?
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.
Oop, didn't see your followup comment. 👍
// Special case for fill-outline-color, which has no spec default. | ||
if (evaluatedLower === undefined || evaluatedUpper === undefined) { | ||
return undefined; | ||
} |
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.
ref #4088
package.json
Outdated
@@ -16,8 +16,6 @@ | |||
"@mapbox/unitbezier": "^0.0.0", | |||
"brfs": "^1.4.0", | |||
"bubleify": "^0.5.1", | |||
"csscolorparser": "^1.0.2", | |||
"csscolorparser": "~1.0.2", |
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.
We don't currently install the dependencies
from js/style-spec/package.json
so this may still be needed
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.
Isn't that what this does?
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.
Ah. Yes. The postinstall hook. 🚢
* No more than one level of nesting * Remove nonsensical or redundant tests * Use correct terminology * Test identity functions properly * Complete test coverage
a90eaeb
to
90a5d3d
Compare
If the text-field property is data-driven, the value of layout['text-field'] is not defined.
It is used in the following circumstances: * In categorical functions, when the feature value does not match any of the stop domain values. * In property and zoom-and-property functions, when a feature does not contain a value for the specified property. * In identity functions, when the feature value is not valid for the style property (for example, if the function is being used for a `circle-color` property but the feature property value is not a string or not a valid color). * In interval or exponential property and zoom-and-property functions, when the feature value is not numeric. If no default is provided, the style property's default is used in these circumstances. Implementing this required breaking changes to the function API in mapbox-gl-style-spec. The export is now a function which accepts the function definition and the spec JSON for a style property. It handles color parsing and validation of feature values internally.
90a5d3d
to
5e61f88
Compare
const textFont = layout['text-font']; | ||
const iconImage = layout['icon-image']; | ||
|
||
const hasText = layout['text-field'] && textFont; | ||
const hasText = textFont && (!layer.isLayoutValueFeatureConstant('text-field') || layout['text-field']); |
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.
FYI @anandthakker.
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.
If the text-field property is data-driven, the value of layout['text-field'] is not defined.
@jfirebaugh ah, whoops - I made the bad assumption that layout
contained the style JSON.
It is used in the following circumstances:
circle-color
property but the feature property value is not a string or not a valid color).If no default is provided, the style property's default is used in these circumstances.
Implementing this required breaking changes to the function API in mapbox-gl-style-spec. The export is now a function which accepts the function definition and the spec JSON for a style property. It handles color parsing and validation of feature values internally.
Fixes #4124
Fixes #4144
Fixes #4146
Fixes #4150
Fixes #4018
Launch Checklist