From e058a470b19d659d3dc686bb3f4bfbdb375a0b8b Mon Sep 17 00:00:00 2001 From: Brandon Bloom Date: Tue, 13 Jun 2017 18:15:59 -0700 Subject: [PATCH] Eval hack until arbitrary expressions are supported. Ideally this will no longer be necessary after this happens: https://github.com/mapbox/mapbox-gl-js/pull/4777 --- src/style-spec/function/index.js | 25 ++++++++++++++++++------- src/style-spec/reference/v8.json | 4 ++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/style-spec/function/index.js b/src/style-spec/function/index.js index 7a22b919cbe..ae11f614541 100644 --- a/src/style-spec/function/index.js +++ b/src/style-spec/function/index.js @@ -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; } diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index 74da0b212f0..6b99e676984 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -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.",