diff --git a/build/generate-flow-typed-style-spec.js b/build/generate-flow-typed-style-spec.js index 6f2e71cd93b..bab7b6a405d 100644 --- a/build/generate-flow-typed-style-spec.js +++ b/build/generate-flow-typed-style-spec.js @@ -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] diff --git a/src/data/bucket/symbol_bucket.js b/src/data/bucket/symbol_bucket.js index 7f7e48f09f1..4746935a53c 100644 --- a/src/data/bucket/symbol_bucket.js +++ b/src/data/bucket/symbol_bucket.js @@ -433,8 +433,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); } diff --git a/src/style-spec/expression/definitions/coalesce.js b/src/style-spec/expression/definitions/coalesce.js index 788b8a3e4d1..31a0598e195 100644 --- a/src/style-spec/expression/definitions/coalesce.js +++ b/src/style-spec/expression/definitions/coalesce.js @@ -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) { diff --git a/src/style-spec/expression/definitions/coercion.js b/src/style-spec/expression/definitions/coercion.js index 9001e60f9ae..9f30b0722b0 100644 --- a/src/style-spec/expression/definitions/coercion.js +++ b/src/style-spec/expression/definitions/coercion.js @@ -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)); } @@ -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(); } diff --git a/src/style-spec/expression/definitions/image.js b/src/style-spec/expression/definitions/image.js index f02e8ff78ff..c4fd9387ee5 100644 --- a/src/style-spec/expression/definitions/image.js +++ b/src/style-spec/expression/definitions/image.js @@ -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'; @@ -12,7 +13,7 @@ export default class ImageExpression implements Expression { input: Expression; constructor(input: Expression) { - this.type = ImageType; + this.type = ResolvedImageType; this.input = input; } @@ -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) { diff --git a/src/style-spec/expression/definitions/index.js b/src/style-spec/expression/definitions/index.js index e4e53171b24..1eded2452fa 100644 --- a/src/style-spec/expression/definitions/index.js +++ b/src/style-spec/expression/definitions/index.js @@ -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'; @@ -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, diff --git a/src/style-spec/expression/index.js b/src/style-spec/expression/index.js index 7f6ae543f7c..02c2163c9a7 100644 --- a/src/style-spec/expression/index.js +++ b/src/style-spec/expression/index.js @@ -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 = { @@ -360,7 +360,7 @@ function getExpectedType(spec: StylePropertySpecification): Type { enum: StringType, boolean: BooleanType, formatted: FormattedType, - image: ImageType + resolvedImage: ResolvedImageType }; if (spec.type === 'array') { diff --git a/src/style-spec/expression/parsing_context.js b/src/style-spec/expression/parsing_context.js index cb2a1e7ee05..e08fa11ff66 100644 --- a/src/style-spec/expression/parsing_context.js +++ b/src/style-spec/expression/parsing_context.js @@ -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; @@ -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)); diff --git a/src/style-spec/expression/types.js b/src/style-spec/expression/types.js index 6e89a87dc3d..c088b87041c 100644 --- a/src/style-spec/expression/types.js +++ b/src/style-spec/expression/types.js @@ -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'; @@ -26,7 +26,7 @@ export type Type = ErrorTypeT | CollatorTypeT | FormattedTypeT | - ImageTypeT + ResolvedImageTypeT export type ArrayType = { kind: 'array', @@ -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 { @@ -74,7 +74,7 @@ const valueMemberTypes = [ FormattedType, ObjectType, array(ValueType), - ImageType + ResolvedImageType ]; /** diff --git a/src/style-spec/expression/types/resolved_image.js b/src/style-spec/expression/types/resolved_image.js index 1da2107f569..2919b1e8a5b 100644 --- a/src/style-spec/expression/types/resolved_image.js +++ b/src/style-spec/expression/types/resolved_image.js @@ -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 { diff --git a/src/style-spec/expression/values.js b/src/style-spec/expression/values.js index 56aa68b5cae..6b5539f89fa 100644 --- a/src/style-spec/expression/values.js +++ b/src/style-spec/expression/values.js @@ -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'; @@ -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; diff --git a/src/style-spec/function/index.js b/src/style-spec/function/index.js index 3d2da186117..a78b575f734 100644 --- a/src/style-spec/function/index.js +++ b/src/style-spec/function/index.js @@ -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; } diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index c9102eed2b1..aae6bc2c5d2 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -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": { @@ -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": { @@ -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": { @@ -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": { @@ -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": { diff --git a/src/style-spec/types.js b/src/style-spec/types.js index 3416f7c9fd2..6be4d498266 100644 --- a/src/style-spec/types.js +++ b/src/style-spec/types.js @@ -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] @@ -168,7 +168,7 @@ export type FillLayerSpecification = {| "fill-outline-color"?: DataDrivenPropertyValueSpecification, "fill-translate"?: PropertyValueSpecification<[number, number]>, "fill-translate-anchor"?: PropertyValueSpecification<"map" | "viewport">, - "fill-pattern"?: DataDrivenPropertyValueSpecification + "fill-pattern"?: DataDrivenPropertyValueSpecification |} |} @@ -199,7 +199,7 @@ export type LineLayerSpecification = {| "line-offset"?: DataDrivenPropertyValueSpecification, "line-blur"?: DataDrivenPropertyValueSpecification, "line-dasharray"?: PropertyValueSpecification>, - "line-pattern"?: DataDrivenPropertyValueSpecification, + "line-pattern"?: DataDrivenPropertyValueSpecification, "line-gradient"?: ExpressionSpecification |} |} @@ -226,7 +226,7 @@ export type SymbolLayerSpecification = {| "icon-size"?: DataDrivenPropertyValueSpecification, "icon-text-fit"?: PropertyValueSpecification<"none" | "width" | "height" | "both">, "icon-text-fit-padding"?: PropertyValueSpecification<[number, number, number, number]>, - "icon-image"?: DataDrivenPropertyValueSpecification, + "icon-image"?: DataDrivenPropertyValueSpecification, "icon-rotate"?: DataDrivenPropertyValueSpecification, "icon-padding"?: PropertyValueSpecification, "icon-keep-upright"?: PropertyValueSpecification, @@ -341,7 +341,7 @@ export type FillExtrusionLayerSpecification = {| "fill-extrusion-color"?: DataDrivenPropertyValueSpecification, "fill-extrusion-translate"?: PropertyValueSpecification<[number, number]>, "fill-extrusion-translate-anchor"?: PropertyValueSpecification<"map" | "viewport">, - "fill-extrusion-pattern"?: DataDrivenPropertyValueSpecification, + "fill-extrusion-pattern"?: DataDrivenPropertyValueSpecification, "fill-extrusion-height"?: DataDrivenPropertyValueSpecification, "fill-extrusion-base"?: DataDrivenPropertyValueSpecification, "fill-extrusion-vertical-gradient"?: PropertyValueSpecification @@ -405,7 +405,7 @@ export type BackgroundLayerSpecification = {| |}, "paint"?: {| "background-color"?: PropertyValueSpecification, - "background-pattern"?: PropertyValueSpecification, + "background-pattern"?: PropertyValueSpecification, "background-opacity"?: PropertyValueSpecification |} |} diff --git a/src/style-spec/validate/validate.js b/src/style-spec/validate/validate.js index de8c6d16954..2c2c8aaaa1e 100644 --- a/src/style-spec/validate/validate.js +++ b/src/style-spec/validate/validate.js @@ -39,7 +39,7 @@ const VALIDATORS = { 'light': validateLight, 'string': validateString, 'formatted': validateFormatted, - 'image': validateImage + 'resolvedImage': validateImage }; // Main recursive validation function. Tracks: diff --git a/src/style/properties.js b/src/style/properties.js index f9411ee002d..99311fc78d7 100644 --- a/src/style/properties.js +++ b/src/style/properties.js @@ -600,7 +600,7 @@ export class CrossFadedDataDrivenProperty extends DataDrivenProperty