@mapbox/mapbox-gl-style-spec 13.24.0-alpha.6 → 13.24.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +10 -0
- package/CHANGELOG.md +10 -4
- package/bin/gl-style-composite.js +6 -2
- package/bin/gl-style-format.js +6 -2
- package/bin/gl-style-migrate.js +6 -2
- package/bin/gl-style-validate.js +5 -1
- package/dist/index.cjs +41 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +41 -23
- package/dist/index.es.js.map +1 -1
- package/expression/compound_expression.js +2 -2
- package/expression/definitions/assertion.js +3 -3
- package/expression/definitions/at.js +5 -5
- package/expression/definitions/case.js +4 -4
- package/expression/definitions/coalesce.js +4 -4
- package/expression/definitions/coercion.js +3 -3
- package/expression/definitions/collator.js +4 -4
- package/expression/definitions/comparison.js +22 -22
- package/expression/definitions/format.js +4 -4
- package/expression/definitions/image.js +4 -4
- package/expression/definitions/in.js +5 -5
- package/expression/definitions/index_of.js +5 -5
- package/expression/definitions/interpolate.js +6 -5
- package/expression/definitions/length.js +5 -5
- package/expression/definitions/let.js +5 -5
- package/expression/definitions/literal.js +5 -5
- package/expression/definitions/match.js +4 -4
- package/expression/definitions/number_format.js +4 -4
- package/expression/definitions/slice.js +5 -5
- package/expression/definitions/step.js +4 -4
- package/expression/definitions/var.js +4 -4
- package/expression/definitions/within.js +16 -8
- package/expression/evaluation_context.js +8 -8
- package/expression/expression.js +1 -1
- package/expression/index.js +4 -4
- package/expression/is_constant.js +3 -3
- package/expression/parsing_context.js +1 -1
- package/expression/runtime_error.js +1 -1
- package/expression/scope.js +1 -1
- package/expression/stops.js +1 -1
- package/expression/values.js +1 -1
- package/feature_filter/index.js +1 -1
- package/function/convert.js +4 -4
- package/migrate/expressions.js +1 -1
- package/package.json +1 -1
- package/reference/latest.js +4 -0
- package/reference/v8.json +1 -4
- package/types.js +1 -1
- package/validate/validate.js +13 -1
- package/validate/validate_array.js +10 -2
- package/validate/validate_boolean.js +4 -1
- package/validate/validate_color.js +4 -1
- package/validate/validate_enum.js +4 -1
- package/validate/validate_expression.js +5 -2
- package/validate/validate_filter.js +12 -4
- package/validate/validate_fog.js +4 -1
- package/validate/validate_formatted.js +5 -1
- package/validate/validate_function.js +24 -15
- package/validate/validate_glyphs_url.js +4 -1
- package/validate/validate_image.js +5 -1
- package/validate/validate_layer.js +15 -2
- package/validate/validate_layout_property.js +5 -1
- package/validate/validate_light.js +4 -1
- package/validate/validate_number.js +8 -1
- package/validate/validate_object.js +12 -2
- package/validate/validate_paint_property.js +5 -1
- package/validate/validate_projection.js +5 -1
- package/validate/validate_property.js +9 -1
- package/validate/validate_source.js +4 -1
- package/validate/validate_string.js +4 -1
- package/validate/validate_terrain.js +5 -2
- package/validate_style.min.js +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import {StringType, NumberType} from '../types.js';
|
|
4
4
|
|
|
5
|
-
import type {Expression} from '../expression.js';
|
|
5
|
+
import type {Expression, SerializedExpression} from '../expression.js';
|
|
6
6
|
import type EvaluationContext from '../evaluation_context.js';
|
|
7
7
|
import type ParsingContext from '../parsing_context.js';
|
|
8
8
|
import type {Type} from '../types.js';
|
|
@@ -93,7 +93,7 @@ export default class NumberFormat implements Expression {
|
|
|
93
93
|
return new NumberFormat(number, locale, currency, minFractionDigits, maxFractionDigits);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
evaluate(ctx: EvaluationContext) {
|
|
96
|
+
evaluate(ctx: EvaluationContext): string {
|
|
97
97
|
return new Intl.NumberFormat(this.locale ? this.locale.evaluate(ctx) : [],
|
|
98
98
|
{
|
|
99
99
|
style: this.currency ? "currency" : "decimal",
|
|
@@ -119,11 +119,11 @@ export default class NumberFormat implements Expression {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
outputDefined() {
|
|
122
|
+
outputDefined(): boolean {
|
|
123
123
|
return false;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
serialize() {
|
|
126
|
+
serialize(): SerializedExpression {
|
|
127
127
|
const options = {};
|
|
128
128
|
if (this.locale) {
|
|
129
129
|
options['locale'] = this.locale.serialize();
|
|
@@ -4,7 +4,7 @@ import {ValueType, NumberType, StringType, array, toString, isValidType, isValid
|
|
|
4
4
|
import RuntimeError from '../runtime_error.js';
|
|
5
5
|
import {typeOf} from '../values.js';
|
|
6
6
|
|
|
7
|
-
import type {Expression} from '../expression.js';
|
|
7
|
+
import type {Expression, SerializedExpression} from '../expression.js';
|
|
8
8
|
import type ParsingContext from '../parsing_context.js';
|
|
9
9
|
import type EvaluationContext from '../evaluation_context.js';
|
|
10
10
|
import type {Type} from '../types.js';
|
|
@@ -23,7 +23,7 @@ class Slice implements Expression {
|
|
|
23
23
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
|
|
26
|
+
static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Slice {
|
|
27
27
|
if (args.length <= 2 || args.length >= 5) {
|
|
28
28
|
return context.error(`Expected 3 or 4 arguments, but found ${args.length - 1} instead.`);
|
|
29
29
|
}
|
|
@@ -46,7 +46,7 @@ class Slice implements Expression {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
evaluate(ctx: EvaluationContext) {
|
|
49
|
+
evaluate(ctx: EvaluationContext): any {
|
|
50
50
|
const input = (this.input.evaluate(ctx): any);
|
|
51
51
|
const beginIndex = (this.beginIndex.evaluate(ctx): number);
|
|
52
52
|
|
|
@@ -70,11 +70,11 @@ class Slice implements Expression {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
outputDefined() {
|
|
73
|
+
outputDefined(): boolean {
|
|
74
74
|
return false;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
serialize() {
|
|
77
|
+
serialize(): SerializedExpression {
|
|
78
78
|
if (this.endIndex != null && this.endIndex !== undefined) {
|
|
79
79
|
const endIndex = this.endIndex.serialize();
|
|
80
80
|
return ["slice", this.input.serialize(), this.beginIndex.serialize(), endIndex];
|
|
@@ -5,7 +5,7 @@ import {NumberType} from '../types.js';
|
|
|
5
5
|
import {findStopLessThanOrEqualTo} from '../stops.js';
|
|
6
6
|
|
|
7
7
|
import type {Stops} from '../stops.js';
|
|
8
|
-
import type {Expression} from '../expression.js';
|
|
8
|
+
import type {Expression, SerializedExpression} from '../expression.js';
|
|
9
9
|
import type ParsingContext from '../parsing_context.js';
|
|
10
10
|
import type EvaluationContext from '../evaluation_context.js';
|
|
11
11
|
import type {Type} from '../types.js';
|
|
@@ -29,7 +29,7 @@ class Step implements Expression {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
|
|
32
|
+
static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Step {
|
|
33
33
|
if (args.length - 1 < 4) {
|
|
34
34
|
return context.error(`Expected at least 4 arguments, but found only ${args.length - 1}.`);
|
|
35
35
|
}
|
|
@@ -72,7 +72,7 @@ class Step implements Expression {
|
|
|
72
72
|
return new Step(outputType, input, stops);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
evaluate(ctx: EvaluationContext) {
|
|
75
|
+
evaluate(ctx: EvaluationContext): any {
|
|
76
76
|
const labels = this.labels;
|
|
77
77
|
const outputs = this.outputs;
|
|
78
78
|
|
|
@@ -105,7 +105,7 @@ class Step implements Expression {
|
|
|
105
105
|
return this.outputs.every(out => out.outputDefined());
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
serialize() {
|
|
108
|
+
serialize(): SerializedExpression {
|
|
109
109
|
const serialized = ["step", this.input.serialize()];
|
|
110
110
|
for (let i = 0; i < this.labels.length; i++) {
|
|
111
111
|
if (i > 0) {
|
|
@@ -16,7 +16,7 @@ class Var implements Expression {
|
|
|
16
16
|
this.boundExpression = boundExpression;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
|
|
19
|
+
static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): void | Var {
|
|
20
20
|
if (args.length !== 2 || typeof args[1] !== 'string')
|
|
21
21
|
return context.error(`'var' expression requires exactly one string literal argument.`);
|
|
22
22
|
|
|
@@ -28,17 +28,17 @@ class Var implements Expression {
|
|
|
28
28
|
return new Var(name, context.scope.get(name));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
evaluate(ctx: EvaluationContext) {
|
|
31
|
+
evaluate(ctx: EvaluationContext): any {
|
|
32
32
|
return this.boundExpression.evaluate(ctx);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
eachChild() {}
|
|
36
36
|
|
|
37
|
-
outputDefined() {
|
|
37
|
+
outputDefined(): boolean {
|
|
38
38
|
return false;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
serialize() {
|
|
41
|
+
serialize(): Array<string> {
|
|
42
42
|
return ["var", this.name];
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {isValue} from '../values.js';
|
|
4
4
|
import type {Type} from '../types.js';
|
|
5
5
|
import {BooleanType} from '../types.js';
|
|
6
|
-
import type {Expression} from '../expression.js';
|
|
6
|
+
import type {Expression, SerializedExpression} from '../expression.js';
|
|
7
7
|
import type ParsingContext from '../parsing_context.js';
|
|
8
8
|
import type EvaluationContext from '../evaluation_context.js';
|
|
9
9
|
import type {GeoJSON, GeoJSONPolygon, GeoJSONMultiPolygon} from '@mapbox/geojson-types';
|
|
@@ -148,7 +148,7 @@ function lineStringWithinPolygons(line, polygons) {
|
|
|
148
148
|
return false;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
function getTilePolygon(coordinates, bbox, canonical) {
|
|
151
|
+
function getTilePolygon(coordinates, bbox: BBox, canonical: CanonicalTileID) {
|
|
152
152
|
const polygon = [];
|
|
153
153
|
for (let i = 0; i < coordinates.length; i++) {
|
|
154
154
|
const ring = [];
|
|
@@ -162,7 +162,7 @@ function getTilePolygon(coordinates, bbox, canonical) {
|
|
|
162
162
|
return polygon;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
function getTilePolygons(coordinates, bbox, canonical) {
|
|
165
|
+
function getTilePolygons(coordinates, bbox, canonical: CanonicalTileID) {
|
|
166
166
|
const polygons = [];
|
|
167
167
|
for (let i = 0; i < coordinates.length; i++) {
|
|
168
168
|
const polygon = getTilePolygon(coordinates[i], bbox, canonical);
|
|
@@ -188,10 +188,11 @@ function resetBBox(bbox) {
|
|
|
188
188
|
bbox[2] = bbox[3] = -Infinity;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
function getTilePoints(geometry, pointBBox, polyBBox, canonical) {
|
|
191
|
+
function getTilePoints(geometry, pointBBox, polyBBox, canonical: CanonicalTileID) {
|
|
192
192
|
const worldSize = Math.pow(2, canonical.z) * EXTENT;
|
|
193
193
|
const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
|
|
194
194
|
const tilePoints = [];
|
|
195
|
+
if (!geometry) return tilePoints;
|
|
195
196
|
for (const points of geometry) {
|
|
196
197
|
for (const point of points) {
|
|
197
198
|
const p = [point.x + shifts[0], point.y + shifts[1]];
|
|
@@ -202,10 +203,11 @@ function getTilePoints(geometry, pointBBox, polyBBox, canonical) {
|
|
|
202
203
|
return tilePoints;
|
|
203
204
|
}
|
|
204
205
|
|
|
205
|
-
function getTileLines(geometry, lineBBox, polyBBox, canonical) {
|
|
206
|
+
function getTileLines(geometry, lineBBox, polyBBox, canonical: CanonicalTileID) {
|
|
206
207
|
const worldSize = Math.pow(2, canonical.z) * EXTENT;
|
|
207
208
|
const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
|
|
208
209
|
const tileLines = [];
|
|
210
|
+
if (!geometry) return tileLines;
|
|
209
211
|
for (const line of geometry) {
|
|
210
212
|
const tileLine = [];
|
|
211
213
|
for (const point of line) {
|
|
@@ -231,6 +233,9 @@ function pointsWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPo
|
|
|
231
233
|
const polyBBox = [Infinity, Infinity, -Infinity, -Infinity];
|
|
232
234
|
|
|
233
235
|
const canonical = ctx.canonicalID();
|
|
236
|
+
if (!canonical) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
234
239
|
|
|
235
240
|
if (polygonGeometry.type === 'Polygon') {
|
|
236
241
|
const tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
|
|
@@ -259,6 +264,9 @@ function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPol
|
|
|
259
264
|
const polyBBox = [Infinity, Infinity, -Infinity, -Infinity];
|
|
260
265
|
|
|
261
266
|
const canonical = ctx.canonicalID();
|
|
267
|
+
if (!canonical) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
262
270
|
|
|
263
271
|
if (polygonGeometry.type === 'Polygon') {
|
|
264
272
|
const tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
|
|
@@ -292,7 +300,7 @@ class Within implements Expression {
|
|
|
292
300
|
this.geometries = geometries;
|
|
293
301
|
}
|
|
294
302
|
|
|
295
|
-
static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
|
|
303
|
+
static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Within {
|
|
296
304
|
if (args.length !== 2)
|
|
297
305
|
return context.error(`'within' expression requires exactly one argument, but found ${args.length - 1} instead.`);
|
|
298
306
|
if (isValue(args[1])) {
|
|
@@ -316,7 +324,7 @@ class Within implements Expression {
|
|
|
316
324
|
return context.error(`'within' expression requires valid geojson object that contains polygon geometry type.`);
|
|
317
325
|
}
|
|
318
326
|
|
|
319
|
-
evaluate(ctx: EvaluationContext) {
|
|
327
|
+
evaluate(ctx: EvaluationContext): boolean {
|
|
320
328
|
if (ctx.geometry() != null && ctx.canonicalID() != null) {
|
|
321
329
|
if (ctx.geometryType() === 'Point') {
|
|
322
330
|
return pointsWithinPolygons(ctx, this.geometries);
|
|
@@ -333,7 +341,7 @@ class Within implements Expression {
|
|
|
333
341
|
return true;
|
|
334
342
|
}
|
|
335
343
|
|
|
336
|
-
serialize():
|
|
344
|
+
serialize(): SerializedExpression {
|
|
337
345
|
return ["within", this.geojson];
|
|
338
346
|
}
|
|
339
347
|
|
|
@@ -16,7 +16,7 @@ class EvaluationContext {
|
|
|
16
16
|
featureState: ?FeatureState;
|
|
17
17
|
formattedSection: ?FormattedSection;
|
|
18
18
|
availableImages: ?Array<string>;
|
|
19
|
-
canonical:
|
|
19
|
+
canonical: null | CanonicalTileID;
|
|
20
20
|
featureTileCoord: ?Point;
|
|
21
21
|
featureDistanceData: ?FeatureDistanceData;
|
|
22
22
|
|
|
@@ -34,27 +34,27 @@ class EvaluationContext {
|
|
|
34
34
|
this.featureDistanceData = null;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
id() {
|
|
38
|
-
return this.feature && 'id' in this.feature ? this.feature.id : null;
|
|
37
|
+
id(): number | null {
|
|
38
|
+
return this.feature && 'id' in this.feature && this.feature.id ? this.feature.id : null;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
geometryType() {
|
|
41
|
+
geometryType(): null | string {
|
|
42
42
|
return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
geometry() {
|
|
45
|
+
geometry(): ?Array<Array<Point>> {
|
|
46
46
|
return this.feature && 'geometry' in this.feature ? this.feature.geometry : null;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
canonicalID() {
|
|
49
|
+
canonicalID(): null | CanonicalTileID {
|
|
50
50
|
return this.canonical;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
properties() {
|
|
53
|
+
properties(): {[string]: any} {
|
|
54
54
|
return (this.feature && this.feature.properties) || {};
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
distanceFromCenter() {
|
|
57
|
+
distanceFromCenter(): number {
|
|
58
58
|
if (this.featureTileCoord && this.featureDistanceData) {
|
|
59
59
|
|
|
60
60
|
const c = this.featureDistanceData.center;
|
package/expression/expression.js
CHANGED
|
@@ -4,7 +4,7 @@ import type {Type} from './types.js';
|
|
|
4
4
|
import type ParsingContext from './parsing_context.js';
|
|
5
5
|
import type EvaluationContext from './evaluation_context.js';
|
|
6
6
|
|
|
7
|
-
type SerializedExpression = Array<mixed> | string | number | boolean | null;
|
|
7
|
+
export type SerializedExpression = Array<mixed> | Array<string> | string | number | boolean | null;
|
|
8
8
|
|
|
9
9
|
export interface Expression {
|
|
10
10
|
+type: Type;
|
package/expression/index.js
CHANGED
|
@@ -31,7 +31,7 @@ import type {FeatureDistanceData} from '../feature_filter/index.js';
|
|
|
31
31
|
|
|
32
32
|
export type Feature = {
|
|
33
33
|
+type: 1 | 2 | 3 | 'Unknown' | 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon',
|
|
34
|
-
+id?:
|
|
34
|
+
+id?: number | null,
|
|
35
35
|
+properties: {[_: string]: any},
|
|
36
36
|
+patterns?: {[_: string]: {"min": string, "mid": string, "max": string}},
|
|
37
37
|
+geometry?: Array<Array<Point>>
|
|
@@ -69,7 +69,7 @@ export class StyleExpression {
|
|
|
69
69
|
this._evaluator.globals = globals;
|
|
70
70
|
this._evaluator.feature = feature;
|
|
71
71
|
this._evaluator.featureState = featureState;
|
|
72
|
-
this._evaluator.canonical = canonical;
|
|
72
|
+
this._evaluator.canonical = canonical || null;
|
|
73
73
|
this._evaluator.availableImages = availableImages || null;
|
|
74
74
|
this._evaluator.formattedSection = formattedSection;
|
|
75
75
|
this._evaluator.featureTileCoord = featureTileCoord || null;
|
|
@@ -82,7 +82,7 @@ export class StyleExpression {
|
|
|
82
82
|
this._evaluator.globals = globals;
|
|
83
83
|
this._evaluator.feature = feature || null;
|
|
84
84
|
this._evaluator.featureState = featureState || null;
|
|
85
|
-
this._evaluator.canonical = canonical;
|
|
85
|
+
this._evaluator.canonical = canonical || null;
|
|
86
86
|
this._evaluator.availableImages = availableImages || null;
|
|
87
87
|
this._evaluator.formattedSection = formattedSection || null;
|
|
88
88
|
this._evaluator.featureTileCoord = featureTileCoord || null;
|
|
@@ -110,7 +110,7 @@ export class StyleExpression {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
export function isExpression(expression: mixed) {
|
|
113
|
+
export function isExpression(expression: mixed): boolean {
|
|
114
114
|
return Array.isArray(expression) && expression.length > 0 &&
|
|
115
115
|
typeof expression[0] === 'string' && expression[0] in definitions;
|
|
116
116
|
}
|
|
@@ -4,7 +4,7 @@ import CompoundExpression from './compound_expression.js';
|
|
|
4
4
|
import Within from './definitions/within.js';
|
|
5
5
|
import type {Expression} from './expression.js';
|
|
6
6
|
|
|
7
|
-
function isFeatureConstant(e: Expression) {
|
|
7
|
+
function isFeatureConstant(e: Expression): boolean {
|
|
8
8
|
if (e instanceof CompoundExpression) {
|
|
9
9
|
if (e.name === 'get' && e.args.length === 1) {
|
|
10
10
|
return false;
|
|
@@ -34,7 +34,7 @@ function isFeatureConstant(e: Expression) {
|
|
|
34
34
|
return result;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function isStateConstant(e: Expression) {
|
|
37
|
+
function isStateConstant(e: Expression): boolean {
|
|
38
38
|
if (e instanceof CompoundExpression) {
|
|
39
39
|
if (e.name === 'feature-state') {
|
|
40
40
|
return false;
|
|
@@ -47,7 +47,7 @@ function isStateConstant(e: Expression) {
|
|
|
47
47
|
return result;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
function isGlobalPropertyConstant(e: Expression, properties: Array<string>) {
|
|
50
|
+
function isGlobalPropertyConstant(e: Expression, properties: Array<string>): boolean {
|
|
51
51
|
if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) { return false; }
|
|
52
52
|
let result = true;
|
|
53
53
|
e.eachChild((arg) => {
|
|
@@ -155,7 +155,7 @@ class ParsingContext {
|
|
|
155
155
|
* parsing, is copied by reference rather than cloned.
|
|
156
156
|
* @private
|
|
157
157
|
*/
|
|
158
|
-
concat(index: number, expectedType?: ?Type, bindings?: Array<[string, Expression]>) {
|
|
158
|
+
concat(index: number, expectedType?: ?Type, bindings?: Array<[string, Expression]>): ParsingContext {
|
|
159
159
|
const path = typeof index === 'number' ? this.path.concat(index) : this.path;
|
|
160
160
|
const scope = bindings ? this.scope.concat(bindings) : this.scope;
|
|
161
161
|
return new ParsingContext(
|
package/expression/scope.js
CHANGED
package/expression/stops.js
CHANGED
|
@@ -10,7 +10,7 @@ export type Stops = Array<[number, Expression]>;
|
|
|
10
10
|
* Returns the index of the last stop <= input, or 0 if it doesn't exist.
|
|
11
11
|
* @private
|
|
12
12
|
*/
|
|
13
|
-
export function findStopLessThanOrEqualTo(stops: Array<number>, input: number) {
|
|
13
|
+
export function findStopLessThanOrEqualTo(stops: Array<number>, input: number): number {
|
|
14
14
|
const lastIndex = stops.length - 1;
|
|
15
15
|
let lowerIndex = 0;
|
|
16
16
|
let upperIndex = lastIndex;
|
package/expression/values.js
CHANGED
package/feature_filter/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export type FeatureFilter = {filter: FilterExpression, dynamicFilter?: FilterExp
|
|
|
15
15
|
export default createFilter;
|
|
16
16
|
export {isExpressionFilter, isDynamicFilter, extractStaticFilter};
|
|
17
17
|
|
|
18
|
-
function isExpressionFilter(filter: any) {
|
|
18
|
+
function isExpressionFilter(filter: any): boolean {
|
|
19
19
|
if (filter === true || filter === false) {
|
|
20
20
|
return true;
|
|
21
21
|
}
|
package/function/convert.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
3
|
import assert from 'assert';
|
|
4
|
-
import type {StylePropertySpecification} from '../style-spec.js';
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
import type {StylePropertySpecification} from '../style-spec.js';
|
|
6
|
+
import type {ExpressionSpecification} from '../types.js';
|
|
7
7
|
|
|
8
8
|
function convertLiteral(value) {
|
|
9
9
|
return typeof value === 'object' ? ['literal', value] : value;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
function convertFunction(parameters: any, propertySpec: StylePropertySpecification) {
|
|
12
|
+
export default function convertFunction(parameters: any, propertySpec: StylePropertySpecification): ExpressionSpecification {
|
|
13
13
|
let stops = parameters.stops;
|
|
14
14
|
if (!stops) {
|
|
15
15
|
// identity function
|
|
@@ -244,7 +244,7 @@ function getFunctionType(parameters, propertySpec) {
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
// "String with {name} token" => ["concat", "String with ", ["get", "name"], " token"]
|
|
247
|
-
export function convertTokenString(s: string) {
|
|
247
|
+
export function convertTokenString(s: string): string | ExpressionSpecification {
|
|
248
248
|
const result = ['concat'];
|
|
249
249
|
const re = /{([^{}]+)}/g;
|
|
250
250
|
let pos = 0;
|
package/migrate/expressions.js
CHANGED
|
@@ -15,7 +15,7 @@ import type {StyleSpecification} from '../types.js';
|
|
|
15
15
|
* this will convert (a) "stop" functions, and (b) legacy filters to their
|
|
16
16
|
* expression equivalents.
|
|
17
17
|
*/
|
|
18
|
-
export default function(style: StyleSpecification) {
|
|
18
|
+
export default function(style: StyleSpecification): StyleSpecification {
|
|
19
19
|
const converted = [];
|
|
20
20
|
|
|
21
21
|
eachLayer(style, (layer) => {
|
package/package.json
CHANGED
package/reference/latest.js
CHANGED
package/reference/v8.json
CHANGED
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
},
|
|
97
97
|
"projection": {
|
|
98
98
|
"type": "projection",
|
|
99
|
-
"doc": "The projection the map should be rendered in. Supported projections are Albers, Equal Earth, Equirectangular (WGS84), Lambert conformal conic, Mercator, Natural Earth,
|
|
99
|
+
"doc": "The projection the map should be rendered in. Supported projections are Albers, Equal Earth, Equirectangular (WGS84), Lambert conformal conic, Mercator, Natural Earth, and Winkel Tripel. Terrain, fog, sky and CustomLayerInterface are not supported for projections other than mercator.",
|
|
100
100
|
"example": {
|
|
101
101
|
"name": "albers",
|
|
102
102
|
"center": [-154, 50],
|
|
@@ -3991,9 +3991,6 @@
|
|
|
3991
3991
|
},
|
|
3992
3992
|
"winkelTripel": {
|
|
3993
3993
|
"doc": "A Winkel Tripel projection."
|
|
3994
|
-
},
|
|
3995
|
-
"globe": {
|
|
3996
|
-
"doc": "A globe projection."
|
|
3997
3994
|
}
|
|
3998
3995
|
},
|
|
3999
3996
|
"default": "mercator",
|
package/types.js
CHANGED
|
@@ -95,7 +95,7 @@ export type FogSpecification = {|
|
|
|
95
95
|
|}
|
|
96
96
|
|
|
97
97
|
export type ProjectionSpecification = {|
|
|
98
|
-
"name": "albers" | "equalEarth" | "equirectangular" | "lambertConformalConic" | "mercator" | "naturalEarth" | "winkelTripel"
|
|
98
|
+
"name": "albers" | "equalEarth" | "equirectangular" | "lambertConformalConic" | "mercator" | "naturalEarth" | "winkelTripel",
|
|
99
99
|
"center"?: [number, number],
|
|
100
100
|
"parallels"?: [number, number]
|
|
101
101
|
|}
|
package/validate/validate.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
|
|
2
3
|
import extend from '../util/extend.js';
|
|
3
4
|
import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint.js';
|
|
@@ -23,6 +24,10 @@ import validateFormatted from './validate_formatted.js';
|
|
|
23
24
|
import validateImage from './validate_image.js';
|
|
24
25
|
import validateProjection from './validate_projection.js';
|
|
25
26
|
|
|
27
|
+
import type {StyleReference} from '../reference/latest.js';
|
|
28
|
+
import type {StyleSpecification} from '../types.js';
|
|
29
|
+
import type ValidationError from '../error/validation_error.js';
|
|
30
|
+
|
|
26
31
|
const VALIDATORS = {
|
|
27
32
|
'*'() {
|
|
28
33
|
return [];
|
|
@@ -55,8 +60,15 @@ const VALIDATORS = {
|
|
|
55
60
|
// scalar value.
|
|
56
61
|
// - valueSpec: current spec being evaluated. Tracks value.
|
|
57
62
|
// - styleSpec: current full spec being evaluated.
|
|
63
|
+
export type ValidationOptions = {
|
|
64
|
+
key: string;
|
|
65
|
+
value: Object;
|
|
66
|
+
valueSpec: Object;
|
|
67
|
+
style: $Shape<StyleSpecification>;
|
|
68
|
+
styleSpec: StyleReference;
|
|
69
|
+
}
|
|
58
70
|
|
|
59
|
-
export default function validate(options) {
|
|
71
|
+
export default function validate(options: ValidationOptions): Array<ValidationError> {
|
|
60
72
|
const value = options.value;
|
|
61
73
|
const valueSpec = options.valueSpec;
|
|
62
74
|
const styleSpec = options.styleSpec;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
|
|
2
3
|
import getType from '../util/get_type.js';
|
|
3
4
|
import validate from './validate.js';
|
|
4
5
|
import ValidationError from '../error/validation_error.js';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
import type {ValidationOptions} from './validate.js';
|
|
8
|
+
|
|
9
|
+
type Options = ValidationOptions & {
|
|
10
|
+
arrayElementValidator: Function;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default function validateArray(options: Options): Array<ValidationError> {
|
|
7
14
|
const array = options.value;
|
|
8
15
|
const arraySpec = options.valueSpec;
|
|
9
16
|
const style = options.style;
|
|
@@ -27,7 +34,8 @@ export default function validateArray(options) {
|
|
|
27
34
|
"type": arraySpec.value,
|
|
28
35
|
"values": arraySpec.values,
|
|
29
36
|
"minimum": arraySpec.minimum,
|
|
30
|
-
"maximum": arraySpec.maximum
|
|
37
|
+
"maximum": arraySpec.maximum,
|
|
38
|
+
function: undefined
|
|
31
39
|
};
|
|
32
40
|
|
|
33
41
|
if (styleSpec.$version < 7) {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
|
|
2
3
|
import getType from '../util/get_type.js';
|
|
3
4
|
import ValidationError from '../error/validation_error.js';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
import type {ValidationOptions} from './validate.js';
|
|
7
|
+
|
|
8
|
+
export default function validateBoolean(options: ValidationOptions): Array<ValidationError> {
|
|
6
9
|
const value = options.value;
|
|
7
10
|
const key = options.key;
|
|
8
11
|
const type = getType(value);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
|
|
2
3
|
import ValidationError from '../error/validation_error.js';
|
|
3
4
|
import getType from '../util/get_type.js';
|
|
4
5
|
import {parseCSSColor} from 'csscolorparser';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
import type {ValidationOptions} from './validate.js';
|
|
8
|
+
|
|
9
|
+
export default function validateColor(options: ValidationOptions): Array<ValidationError> {
|
|
7
10
|
const key = options.key;
|
|
8
11
|
const value = options.value;
|
|
9
12
|
const type = getType(value);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
|
|
2
3
|
import ValidationError from '../error/validation_error.js';
|
|
3
4
|
import {unbundle} from '../util/unbundle_jsonlint.js';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
import type {ValidationOptions} from './validate.js';
|
|
7
|
+
|
|
8
|
+
export default function validateEnum(options: ValidationOptions): Array<ValidationError> {
|
|
6
9
|
const key = options.key;
|
|
7
10
|
const value = options.value;
|
|
8
11
|
const valueSpec = options.valueSpec;
|
|
@@ -52,8 +52,11 @@ export function disallowedFilterParameters(e: Expression, options: any): Array<V
|
|
|
52
52
|
'pitch',
|
|
53
53
|
'distance-from-center'
|
|
54
54
|
]);
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
|
|
56
|
+
if (options.valueSpec && options.valueSpec.expression) {
|
|
57
|
+
for (const param of options.valueSpec.expression.parameters) {
|
|
58
|
+
disallowedParameters.delete(param);
|
|
59
|
+
}
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
if (disallowedParameters.size === 0) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
|
|
2
3
|
import ValidationError from '../error/validation_error.js';
|
|
3
4
|
import validateExpression from './validate_expression.js';
|
|
@@ -7,13 +8,20 @@ import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint.js';
|
|
|
7
8
|
import extend from '../util/extend.js';
|
|
8
9
|
import {isExpressionFilter} from '../feature_filter/index.js';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
import type {ValidationOptions} from './validate.js';
|
|
12
|
+
|
|
13
|
+
type Options = ValidationOptions & {
|
|
14
|
+
layerType: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default function validateFilter(options: Options): Array<ValidationError> {
|
|
11
18
|
if (isExpressionFilter(deepUnbundle(options.value))) {
|
|
12
|
-
|
|
19
|
+
// We default to a layerType of `fill` because that points to a non-dynamic filter definition within the style-spec.
|
|
20
|
+
const layerType = options.layerType || 'fill';
|
|
21
|
+
|
|
13
22
|
return validateExpression(extend({}, options, {
|
|
14
23
|
expressionContext: 'filter',
|
|
15
|
-
|
|
16
|
-
valueSpec: options.styleSpec[`filter_${layerType || 'fill'}`]
|
|
24
|
+
valueSpec: options.styleSpec[`filter_${layerType}`]
|
|
17
25
|
}));
|
|
18
26
|
} else {
|
|
19
27
|
return validateNonExpressionFilter(options);
|