Skip to content

Commit

Permalink
ensure all possible icons for line-pattern camera funcs are added to …
Browse files Browse the repository at this point in the history
…the icon atlas
  • Loading branch information
Molly Lloyd committed Mar 23, 2018
1 parent 03828ea commit ca66d46
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/data/bucket/line_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ class LineBucket implements Bucket {
if (linePattern.value.kind === "source" || linePattern.value.kind === "composite") {
dataDrivenPatternLayers.push(layer);
} else {
// add all icons needed for this tile to the tile's IconAtlas dependencies
// add all icons needed for this layer to the tile's IconAtlas dependencies
// for non-data-driven line-pattern properties
const image = linePattern.constantOr(null);
if (image) {
icons[image.min] = true;
icons[image.mid] = true;
icons[image.max] = true;
const images = linePattern.property.getPossibleOutputs();
for (let i = 0; i < images.length; i++){
// https://github.com/facebook/flow/issues/4310
icons[(images[i]: any)] = true;

}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/style-spec/validate/validate_expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export default function validateExpression(options: any) {
});
}

if (options.expressionContext === 'property' && options.propertyKey === 'text-font' &&
if (options.expressionContext === 'property' && (options.propertyKey === 'text-font' || options.propertyKey === 'line-pattern') &&
(expression.value: any)._styleExpression.expression.possibleOutputs().indexOf(undefined) !== -1) {
return [new ValidationError(options.key, options.value, 'Invalid data expression for "text-font". Output values must be contained as literals within the expression.')];
return [new ValidationError(options.key, options.value, `Invalid data expression for ${options.propertyKey}. Output values must be contained as literals within the expression.`)];
}

return [];
Expand Down
10 changes: 10 additions & 0 deletions src/style/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ export class DataDrivenProperty<T> implements Property<T, PossiblyEvaluatedPrope
return value.evaluate(globals, feature);
}
}

getPossibleOutputs(){ return []; }
}

/**
Expand All @@ -584,13 +586,18 @@ export class DataDrivenProperty<T> implements Property<T, PossiblyEvaluatedPrope
*/

export class CrossFadedDataDrivenProperty<T> extends DataDrivenProperty<?CrossFaded<T>> {
possibleOutputs: Array<T>;

possiblyEvaluate(value: PropertyValue<?CrossFaded<T>, PossiblyEvaluatedPropertyValue<?CrossFaded<T>>>, parameters: EvaluationParameters): PossiblyEvaluatedPropertyValue<?CrossFaded<T>> {
this.possibleOutputs = [];
if (value.value === undefined) {
return new PossiblyEvaluatedPropertyValue(this, {kind: 'constant', value: undefined}, parameters);
} else if (value.expression.kind === 'constant') {
const constant = value.expression.evaluate(parameters);
this.possibleOutputs.push(constant);
return new PossiblyEvaluatedPropertyValue(this, {kind: 'constant', value: this._calculate(constant, constant, constant, parameters)}, parameters);
} else if (value.expression.kind === 'camera') {
this.possibleOutputs = (value.expression: any)._styleExpression.expression.possibleOutputs();
const cameraVal = this._calculate(
value.expression.evaluate({zoom: parameters.zoom - 1.0}),
value.expression.evaluate({zoom: parameters.zoom}),
Expand All @@ -602,6 +609,9 @@ export class CrossFadedDataDrivenProperty<T> extends DataDrivenProperty<?CrossFa
}
}

getPossibleOutputs() {
return this.possibleOutputs;
}

evaluate(value: PossiblyEvaluatedValue<?CrossFaded<T>>, globals: EvaluationParameters, feature: Feature): ?CrossFaded<T> {
if (value.kind === 'source') {
Expand Down

0 comments on commit ca66d46

Please sign in to comment.