Skip to content
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

Merged
merged 4 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions js/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ class SymbolBucket {
}

populate(features, options) {
const layout = this.layers[0].layout;
const layer = this.layers[0];
const layout = layer.layout;
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']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

const hasIcon = iconImage;

this.features = [];
Expand All @@ -137,13 +138,13 @@ class SymbolBucket {

for (let i = 0; i < features.length; i++) {
const feature = features[i];
if (!this.layers[0].filter(feature)) {
if (!layer.filter(feature)) {
continue;
}

let text;
if (hasText) {
text = resolveText(this.layers[0], {zoom: this.zoom}, feature.properties);
text = resolveText(layer, {zoom: this.zoom}, feature.properties);
if (rtlTextPlugin.applyArabicShaping) {
text = rtlTextPlugin.applyArabicShaping(text);
}
Expand Down
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
Loading