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

cherry pick resolvedImage changes to release branch #8906

Merged
merged 1 commit into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion build/generate-flow-typed-style-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export type ColorSpecification = string;

export type FormattedSpecification = string;

export type ImageSpecification = string;
export type ResolvedImageSpecification = string;

export type FilterSpecification =
| ['has', string]
Expand Down
2 changes: 0 additions & 2 deletions src/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,6 @@ class SymbolBucket implements Bucket {
const resolvedTokens = layer.getValueAndResolveTokens('icon-image', feature, availableImages);
if (resolvedTokens instanceof ResolvedImage) {
icon = resolvedTokens;
} else if (!resolvedTokens || typeof resolvedTokens === 'string') {
icon = ResolvedImage.fromString({name: resolvedTokens, available: false});
} else {
icon = ResolvedImage.fromString(resolvedTokens);
}
Expand Down
2 changes: 1 addition & 1 deletion src/style-spec/expression/definitions/coalesce.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Coalesce implements Expression {
result = arg.evaluate(ctx);
// we need to keep track of the first requested image in a coalesce statement
// if coalesce can't find a valid image, we return the first image name so styleimagemissing can fire
if (arg.type.kind === 'image' && !result.available) {
if (arg.type.kind === 'resolvedImage' && !result.available) {
if (!requestedImageName) requestedImageName = arg.evaluate(ctx).name;
result = null;
if (argCount === this.args.length) {
Expand Down
7 changes: 3 additions & 4 deletions src/style-spec/expression/definitions/coercion.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ class Coercion implements Expression {
// There is no explicit 'to-formatted' but this coercion can be implicitly
// created by properties that expect the 'formatted' type.
return Formatted.fromString(valueToString(this.args[0].evaluate(ctx)));
} else if (this.type.kind === 'image') {
const name = this.args[0].evaluate(ctx);
return typeof name === 'string' ? ResolvedImage.fromString({name, available: false}) : name;
} else if (this.type.kind === 'resolvedImage') {
return ResolvedImage.fromString(valueToString(this.args[0].evaluate(ctx)));
} else {
return valueToString(this.args[0].evaluate(ctx));
}
Expand All @@ -122,7 +121,7 @@ class Coercion implements Expression {
return new FormatExpression([{text: this.args[0], scale: null, font: null, textColor: null}]).serialize();
}

if (this.type.kind === 'image') {
if (this.type.kind === 'resolvedImage') {
return new ImageExpression(this.args[0]).serialize();
}

Expand Down
7 changes: 4 additions & 3 deletions src/style-spec/expression/definitions/image.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

import {ImageType, StringType} from '../types';
import {ResolvedImageType, StringType} from '../types';
import ResolvedImage from '../types/resolved_image';

import type {Expression} from '../expression';
import type EvaluationContext from '../evaluation_context';
Expand All @@ -12,7 +13,7 @@ export default class ImageExpression implements Expression {
input: Expression;

constructor(input: Expression) {
this.type = ImageType;
this.type = ResolvedImageType;
this.input = input;
}

Expand All @@ -35,7 +36,7 @@ export default class ImageExpression implements Expression {
available = true;
}

return {name: evaluatedImageName, available};
return new ResolvedImage({name: evaluatedImageName, available});
}

eachChild(fn: (Expression) => void) {
Expand Down
4 changes: 2 additions & 2 deletions src/style-spec/expression/definitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
import CollatorExpression from './collator';
import NumberFormat from './number_format';
import FormatExpression from './format';
import Image from './image';
import ImageExpression from './image';
import Length from './length';

import type {Varargs} from '../compound_expression';
Expand All @@ -60,7 +60,7 @@ const expressions: ExpressionRegistry = {
'coalesce': Coalesce,
'collator': CollatorExpression,
'format': FormatExpression,
'image': Image,
'image': ImageExpression,
'interpolate': Interpolate,
'interpolate-hcl': Interpolate,
'interpolate-lab': Interpolate,
Expand Down
4 changes: 2 additions & 2 deletions src/style-spec/expression/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function findZoomCurve(expression: Expression): Step | Interpolate | ParsingErro
return result;
}

import {ColorType, StringType, NumberType, BooleanType, ValueType, FormattedType, ImageType, array} from './types';
import {ColorType, StringType, NumberType, BooleanType, ValueType, FormattedType, ResolvedImageType, array} from './types';

function getExpectedType(spec: StylePropertySpecification): Type {
const types = {
Expand All @@ -360,7 +360,7 @@ function getExpectedType(spec: StylePropertySpecification): Type {
enum: StringType,
boolean: BooleanType,
formatted: FormattedType,
image: ImageType
resolvedImage: ResolvedImageType
};

if (spec.type === 'array') {
Expand Down
4 changes: 2 additions & 2 deletions src/style-spec/expression/parsing_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ParsingContext {
//
if ((expected.kind === 'string' || expected.kind === 'number' || expected.kind === 'boolean' || expected.kind === 'object' || expected.kind === 'array') && actual.kind === 'value') {
parsed = annotate(parsed, expected, options.typeAnnotation || 'assert');
} else if ((expected.kind === 'color' || expected.kind === 'formatted' || expected.kind === 'image') && (actual.kind === 'value' || actual.kind === 'string')) {
} else if ((expected.kind === 'color' || expected.kind === 'formatted' || expected.kind === 'resolvedImage') && (actual.kind === 'value' || actual.kind === 'string')) {
parsed = annotate(parsed, expected, options.typeAnnotation || 'coerce');
} else if (this.checkSubtype(expected, actual)) {
return null;
Expand All @@ -123,7 +123,7 @@ class ParsingContext {
// it immediately and replace it with a literal value in the
// parsed/compiled result. Expressions that expect an image should
// not be resolved here so we can later get the available images.
if (!(parsed instanceof Literal) && (parsed.type.kind !== 'image') && isConstant(parsed)) {
if (!(parsed instanceof Literal) && (parsed.type.kind !== 'resolvedImage') && isConstant(parsed)) {
const ec = new EvaluationContext();
try {
parsed = new Literal(parsed.type, parsed.evaluate(ec));
Expand Down
8 changes: 4 additions & 4 deletions src/style-spec/expression/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type ValueTypeT = { kind: 'value' };
export type ErrorTypeT = { kind: 'error' };
export type CollatorTypeT = { kind: 'collator' };
export type FormattedTypeT = { kind: 'formatted' };
export type ImageTypeT = { kind: 'image' };
export type ResolvedImageTypeT = { kind: 'resolvedImage' };

export type EvaluationKind = 'constant' | 'source' | 'camera' | 'composite';

Expand All @@ -26,7 +26,7 @@ export type Type =
ErrorTypeT |
CollatorTypeT |
FormattedTypeT |
ImageTypeT
ResolvedImageTypeT

export type ArrayType = {
kind: 'array',
Expand All @@ -44,7 +44,7 @@ export const ValueType = {kind: 'value'};
export const ErrorType = {kind: 'error'};
export const CollatorType = {kind: 'collator'};
export const FormattedType = {kind: 'formatted'};
export const ImageType = {kind: 'image'};
export const ResolvedImageType = {kind: 'resolvedImage'};

export function array(itemType: Type, N: ?number): ArrayType {
return {
Expand Down Expand Up @@ -74,7 +74,7 @@ const valueMemberTypes = [
FormattedType,
ObjectType,
array(ValueType),
ImageType
ResolvedImageType
];

/**
Expand Down
4 changes: 2 additions & 2 deletions src/style-spec/expression/types/resolved_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default class ResolvedImage {
return this.name;
}

static fromString(options: ResolvedImageOptions): ResolvedImage {
return new ResolvedImage(options);
static fromString(name: string): ResolvedImage {
return new ResolvedImage({name, available: false});
}

serialize(): Array<mixed> {
Expand Down
4 changes: 2 additions & 2 deletions src/style-spec/expression/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Color from '../util/color';
import Collator from './types/collator';
import Formatted from './types/formatted';
import ResolvedImage from './types/resolved_image';
import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ImageType, array} from './types';
import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array} from './types';

import type {Type} from './types';

Expand Down Expand Up @@ -83,7 +83,7 @@ export function typeOf(value: Value): Type {
} else if (value instanceof Formatted) {
return FormattedType;
} else if (value instanceof ResolvedImage) {
return ImageType;
return ResolvedImageType;
} else if (Array.isArray(value)) {
const length = value.length;
let itemType: ?Type;
Expand Down
4 changes: 2 additions & 2 deletions src/style-spec/function/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ function evaluateIdentityFunction(parameters, propertySpec, input) {
input = Color.parse(input);
} else if (propertySpec.type === 'formatted') {
input = Formatted.fromString(input.toString());
} else if (propertySpec.type === 'image') {
input = ResolvedImage.fromString({name: input.toString(), available: false});
} else if (propertySpec.type === 'resolvedImage') {
input = ResolvedImage.fromString(input.toString());
} else if (getType(input) !== propertySpec.type && (propertySpec.type !== 'enum' || !propertySpec.values[input])) {
input = undefined;
}
Expand Down
10 changes: 5 additions & 5 deletions src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@
"property-type": "data-constant"
},
"icon-image": {
"type": "image",
"type": "resolvedImage",
"doc": "Name of image in sprite to use for drawing an image background.",
"tokens": true,
"sdk-support": {
Expand Down Expand Up @@ -3797,7 +3797,7 @@
"property-type": "data-constant"
},
"fill-pattern": {
"type": "image",
"type": "resolvedImage",
"transition": true,
"doc": "Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.",
"sdk-support": {
Expand Down Expand Up @@ -3943,7 +3943,7 @@
"property-type": "data-constant"
},
"fill-extrusion-pattern": {
"type": "image",
"type": "resolvedImage",
"transition": true,
"doc": "Name of image in sprite to use for drawing images on extruded fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.",
"sdk-support": {
Expand Down Expand Up @@ -4332,7 +4332,7 @@
"property-type": "cross-faded"
},
"line-pattern": {
"type": "image",
"type": "resolvedImage",
"transition": true,
"doc": "Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.",
"sdk-support": {
Expand Down Expand Up @@ -5712,7 +5712,7 @@
"property-type": "data-constant"
},
"background-pattern": {
"type": "image",
"type": "resolvedImage",
"transition": true,
"doc": "Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.",
"sdk-support": {
Expand Down
12 changes: 6 additions & 6 deletions src/style-spec/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type ColorSpecification = string;

export type FormattedSpecification = string;

export type ImageSpecification = string;
export type ResolvedImageSpecification = string;

export type FilterSpecification =
| ['has', string]
Expand Down Expand Up @@ -168,7 +168,7 @@ export type FillLayerSpecification = {|
"fill-outline-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>,
"fill-translate"?: PropertyValueSpecification<[number, number]>,
"fill-translate-anchor"?: PropertyValueSpecification<"map" | "viewport">,
"fill-pattern"?: DataDrivenPropertyValueSpecification<ImageSpecification>
"fill-pattern"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>
|}
|}

Expand Down Expand Up @@ -199,7 +199,7 @@ export type LineLayerSpecification = {|
"line-offset"?: DataDrivenPropertyValueSpecification<number>,
"line-blur"?: DataDrivenPropertyValueSpecification<number>,
"line-dasharray"?: PropertyValueSpecification<Array<number>>,
"line-pattern"?: DataDrivenPropertyValueSpecification<ImageSpecification>,
"line-pattern"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>,
"line-gradient"?: ExpressionSpecification
|}
|}
Expand All @@ -226,7 +226,7 @@ export type SymbolLayerSpecification = {|
"icon-size"?: DataDrivenPropertyValueSpecification<number>,
"icon-text-fit"?: PropertyValueSpecification<"none" | "width" | "height" | "both">,
"icon-text-fit-padding"?: PropertyValueSpecification<[number, number, number, number]>,
"icon-image"?: DataDrivenPropertyValueSpecification<ImageSpecification>,
"icon-image"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>,
"icon-rotate"?: DataDrivenPropertyValueSpecification<number>,
"icon-padding"?: PropertyValueSpecification<number>,
"icon-keep-upright"?: PropertyValueSpecification<boolean>,
Expand Down Expand Up @@ -341,7 +341,7 @@ export type FillExtrusionLayerSpecification = {|
"fill-extrusion-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>,
"fill-extrusion-translate"?: PropertyValueSpecification<[number, number]>,
"fill-extrusion-translate-anchor"?: PropertyValueSpecification<"map" | "viewport">,
"fill-extrusion-pattern"?: DataDrivenPropertyValueSpecification<ImageSpecification>,
"fill-extrusion-pattern"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>,
"fill-extrusion-height"?: DataDrivenPropertyValueSpecification<number>,
"fill-extrusion-base"?: DataDrivenPropertyValueSpecification<number>,
"fill-extrusion-vertical-gradient"?: PropertyValueSpecification<boolean>
Expand Down Expand Up @@ -405,7 +405,7 @@ export type BackgroundLayerSpecification = {|
|},
"paint"?: {|
"background-color"?: PropertyValueSpecification<ColorSpecification>,
"background-pattern"?: PropertyValueSpecification<ImageSpecification>,
"background-pattern"?: PropertyValueSpecification<ResolvedImageSpecification>,
"background-opacity"?: PropertyValueSpecification<number>
|}
|}
Expand Down
2 changes: 1 addition & 1 deletion src/style-spec/validate/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const VALIDATORS = {
'light': validateLight,
'string': validateString,
'formatted': validateFormatted,
'image': validateImage
'resolvedImage': validateImage
};

// Main recursive validation function. Tracks:
Expand Down
2 changes: 1 addition & 1 deletion src/style/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ export class CrossFadedDataDrivenProperty<T> extends DataDrivenProperty<?CrossFa
return new PossiblyEvaluatedPropertyValue(this, {kind: 'constant', value: undefined}, parameters);
} else if (value.expression.kind === 'constant') {
const evaluatedValue = value.expression.evaluate(parameters, (null: any), {}, availableImages);
const isImageExpression = value.property.specification.type === 'image';
const isImageExpression = value.property.specification.type === 'resolvedImage';
const constantValue = isImageExpression && typeof evaluatedValue !== 'string' ? evaluatedValue.name : evaluatedValue;
const constant = this._calculate(constantValue, constantValue, constantValue, parameters);
return new PossiblyEvaluatedPropertyValue(this, {kind: 'constant', value: constant}, parameters);
Expand Down
2 changes: 1 addition & 1 deletion test/integration/expression-tests/image/basic/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"result": "success",
"isFeatureConstant": true,
"isZoomConstant": true,
"type": "image"
"type": "resolvedImage"
},
"outputs": [
{"name":"monument-15","available":true}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/expression-tests/image/coalesce/test.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"expression": ["coalesce", ["image", "foo"], ["image", "bar"], ["image", "monument-15"]],
"propertySpec": {
"type": "image"
"type": "resolvedImage"
},
"inputs": [
[{}, {}]
Expand All @@ -11,7 +11,7 @@
"result": "success",
"isFeatureConstant": true,
"isZoomConstant": true,
"type": "image"
"type": "resolvedImage"
},
"outputs": [
{"name":"monument-15","available":true}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/expression-tests/image/compound/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"result": "success",
"isFeatureConstant": false,
"isZoomConstant": true,
"type": "image"
"type": "resolvedImage"
},
"outputs": [
{"name":"monument-15","available":true}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"expression": ["number", ["get", "icon"]],
"propertySpec": {
"type": "image"
"type": "resolvedImage"
},
"expected": {
"compiled": {
"result": "error",
"errors": [
{"key": "", "error": "Expected image but found number instead."}
{"key": "", "error": "Expected resolvedImage but found number instead."}
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/style-spec/spec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function validSchema(k, t, obj, ref, version, kind) {
'visibility-enum',
'property-type',
'formatted',
'image'
'resolvedImage'
]);
const keys = [
'default',
Expand Down