Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Feb 3, 2017
1 parent f05bcd6 commit ee9a1d7
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions js/style-spec/function/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ function createFunction(parameters, defaultType) {
const type = parameters.type || defaultType || 'exponential';

let innerFun;
let hashedStops;
if (type === 'exponential') {
innerFun = evaluateExponentialFunction;
} else if (type === 'interval') {
innerFun = evaluateIntervalFunction;
} else if (type === 'categorical') {
innerFun = evaluateCategoricalFunction;

// For categorical functions, generate an Object as a hashmap of the stops for fast searching
hashedStops = Object.create(null);
for (const stop of parameters.stops) {
hashedStops[stop[0]] = stop[1];
}
} else if (type === 'identity') {
innerFun = evaluateIdentityFunction;
} else {
Expand Down Expand Up @@ -60,15 +67,6 @@ function createFunction(parameters, defaultType) {
outputFunction = identityFunction;
}


// For categorical functions, generate an Object as a hashmap of the stops for fast searching
const hashedStops = Object.create(null);
if (innerFun === evaluateCategoricalFunction) {
for (let i = 0; i < parameters.stops.length; i++) {
hashedStops[parameters.stops[i][0]] = parameters.stops[i][1];
}
}

if (zoomAndFeatureDependent) {
const featureFunctions = {};
const featureFunctionStops = [];
Expand Down Expand Up @@ -99,21 +97,13 @@ function createFunction(parameters, defaultType) {

} else if (zoomDependent) {
fun = function(zoom) {
if (innerFun === evaluateCategoricalFunction) {
return outputFunction(innerFun(parameters, zoom, hashedStops));
} else {
return outputFunction(innerFun(parameters, zoom));
}
return outputFunction(innerFun(parameters, zoom, hashedStops));
};
fun.isFeatureConstant = true;
fun.isZoomConstant = false;
} else {
fun = function(zoom, feature) {
if (innerFun === evaluateCategoricalFunction) {
return outputFunction(innerFun(parameters, feature[parameters.property], hashedStops));
} else {
return outputFunction(innerFun(parameters, feature[parameters.property]));
}
return outputFunction(innerFun(parameters, feature[parameters.property], hashedStops));
};
fun.isFeatureConstant = false;
fun.isZoomConstant = true;
Expand Down

0 comments on commit ee9a1d7

Please sign in to comment.