@maptalks/function-type
Advanced tools
+38
-13
@@ -7,4 +7,4 @@ /*eslint-disable no-var, prefer-const*/ | ||
| fun = function () { return parameters; }; | ||
| // fun.isFeatureConstant = true; | ||
| // fun.isZoomConstant = true; | ||
| fun.isFeatureConstant = true; | ||
| fun.isZoomConstant = true; | ||
@@ -51,19 +51,22 @@ } else { | ||
| fun = function (zoom, feature) { | ||
| return evaluateExponentialFunction({ stops: featureFunctionStops, base: parameters.base }, zoom)(zoom, feature); | ||
| const value = evaluateExponentialFunction({ stops: featureFunctionStops, base: parameters.base }, zoom)(zoom, feature); | ||
| return typeof value === 'function' ? value(zoom, feature) : value; | ||
| }; | ||
| // fun.isFeatureConstant = false; | ||
| // fun.isZoomConstant = false; | ||
| fun.isFeatureConstant = false; | ||
| fun.isZoomConstant = false; | ||
| } else if (zoomDependent) { | ||
| fun = function (zoom) { | ||
| return innerFun(parameters, zoom); | ||
| const value = innerFun(parameters, zoom); | ||
| return typeof value === 'function' ? value(zoom) : value; | ||
| }; | ||
| // fun.isFeatureConstant = true; | ||
| // fun.isZoomConstant = false; | ||
| fun.isFeatureConstant = true; | ||
| fun.isZoomConstant = false; | ||
| } else { | ||
| fun = function (zoom, feature) { | ||
| return innerFun(parameters, feature ? feature[parameters.property] : null); | ||
| const value = innerFun(parameters, feature ? feature[parameters.property] : null); | ||
| return typeof value === 'function' ? value(zoom, feature) : value; | ||
| }; | ||
| // fun.isFeatureConstant = false; | ||
| // fun.isZoomConstant = true; | ||
| fun.isFeatureConstant = false; | ||
| fun.isZoomConstant = true; | ||
| } | ||
@@ -192,3 +195,3 @@ } | ||
| export function interpolated(parameters) { | ||
| return createFunction(parameters, 'exponential'); | ||
| return createFunction1(parameters, 'exponential'); | ||
| } | ||
@@ -198,3 +201,3 @@ | ||
| export function piecewiseConstant(parameters) { | ||
| return createFunction(parameters, 'interval'); | ||
| return createFunction1(parameters, 'interval'); | ||
| } | ||
@@ -284,1 +287,23 @@ | ||
| /*eslint-enable no-var, prefer-const*/ | ||
| function createFunction1(parameters, defaultType) { | ||
| if (!isFunctionDefinition(parameters)) { | ||
| return function () { return parameters; }; | ||
| } | ||
| parameters = JSON.parse(JSON.stringify(parameters)); | ||
| let isZoomConstant = true; | ||
| let isFeatureConstant = true; | ||
| const stops = parameters.stops; | ||
| for (let i = 0; i < stops.length; i++) { | ||
| if (isFunctionDefinition(stops[i][1])) { | ||
| const fn = createFunction(stops[i][1], defaultType); | ||
| isZoomConstant = isZoomConstant && fn.isZoomConstant; | ||
| isFeatureConstant = isFeatureConstant && fn.isFeatureConstant; | ||
| stops[i] = [stops[i][0], fn]; | ||
| } | ||
| } | ||
| const fn = createFunction(parameters, defaultType); | ||
| fn.isZoomConstant = isZoomConstant && fn.isZoomConstant; | ||
| fn.isFeatureConstant = isFeatureConstant && fn.isFeatureConstant; | ||
| return fn; | ||
| } |
+1
-1
| { | ||
| "name": "@maptalks/function-type", | ||
| "version": "1.1.1", | ||
| "version": "1.2.0", | ||
| "main": "./index.js", | ||
@@ -5,0 +5,0 @@ "module": "./index.js", |
13746
9.03%273
9.64%