Skip to content

Commit

Permalink
Eval hack until arbitrary expressions are supported.
Browse files Browse the repository at this point in the history
Ideally this will no longer be necessary after this happens:
mapbox#4777
  • Loading branch information
brandonbloom committed Jul 5, 2017
1 parent 943dc39 commit e058a47
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/style-spec/function/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,24 @@ function createFunction(parameters, propertySpec) {
fun.isFeatureConstant = true;
fun.isZoomConstant = false;
} else {
fun = function(zoom, feature) {
const value = feature[parameters.property];
if (value === undefined) {
return coalesce(parameters.default, propertySpec.default);
}
return outputFunction(innerFun(parameters, propertySpec, value, hashedStops, categoricalKeyType));
};
if (parameters.mdory) {
const fn = new Function(['feature'], `return (${parameters.mdory});`);
fun = function(zoom, feature) {
const value = fn(feature);
if (value === undefined || Number.isNaN(value)) {
return coalesce(parameters.default, propertySpec.default);
}
return outputFunction(innerFun(parameters, propertySpec, value, hashedStops, categoricalKeyType));
};
} else {
fun = function(zoom, feature) {
const value = feature[parameters.property];
if (value === undefined) {
return coalesce(parameters.default, propertySpec.default);
}
return outputFunction(innerFun(parameters, propertySpec, value, hashedStops, categoricalKeyType));
};
}
fun.isFeatureConstant = false;
fun.isZoomConstant = true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,10 @@
"doc": "The geometry type for the filter to select."
},
"function": {
"mdory": {
"type": "string",
"doc": "a eval hack for mdory until https://github.com/mapbox/mapbox-gl-js/pull/4777"
},
"stops": {
"type": "array",
"doc": "An array of stops.",
Expand Down

0 comments on commit e058a47

Please sign in to comment.