@mapbox/mapbox-gl-style-spec 14.12.0-beta.1 → 14.13.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/composite.ts +2 -0
- package/deref.ts +5 -5
- package/diff.ts +21 -21
- package/dist/index.cjs +455 -241
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +64 -30
- package/dist/index.es.js +455 -241
- package/dist/index.es.js.map +1 -1
- package/error/validation_error.ts +1 -3
- package/expression/definitions/assertion.ts +2 -1
- package/expression/definitions/at.ts +1 -1
- package/expression/definitions/at_interpolated.ts +1 -1
- package/expression/definitions/case.ts +3 -1
- package/expression/definitions/coalesce.ts +1 -0
- package/expression/definitions/coercion.ts +3 -1
- package/expression/definitions/collator.ts +2 -1
- package/expression/definitions/comparison.ts +15 -1
- package/expression/definitions/config.ts +33 -10
- package/expression/definitions/distance.ts +6 -4
- package/expression/definitions/format.ts +3 -2
- package/expression/definitions/index.ts +29 -3
- package/expression/definitions/index_of.ts +1 -0
- package/expression/definitions/interpolate.ts +5 -1
- package/expression/definitions/let.ts +1 -0
- package/expression/definitions/literal.ts +3 -3
- package/expression/definitions/match.ts +5 -3
- package/expression/definitions/number_format.ts +3 -4
- package/expression/definitions/slice.ts +1 -0
- package/expression/definitions/step.ts +1 -0
- package/expression/definitions/var.ts +1 -0
- package/expression/definitions/within.ts +6 -2
- package/expression/expression.ts +3 -0
- package/expression/index.ts +18 -3
- package/expression/is_constant.ts +4 -0
- package/expression/parsing_context.ts +1 -1
- package/expression/types/formatted.ts +1 -1
- package/expression/types/image_variant.ts +2 -2
- package/expression/types.ts +9 -0
- package/expression/values.ts +1 -3
- package/feature_filter/convert.ts +13 -6
- package/feature_filter/index.ts +16 -0
- package/format.ts +1 -0
- package/function/convert.ts +5 -1
- package/function/index.ts +28 -0
- package/group_by_layout.ts +17 -8
- package/migrate/expressions.ts +2 -2
- package/migrate/v8.ts +9 -0
- package/migrate/v9.ts +1 -0
- package/migrate.ts +1 -0
- package/package.json +1 -1
- package/read_style.ts +1 -0
- package/reference/latest.ts +1 -0
- package/reference/v8.json +209 -21
- package/types.ts +21 -2
- package/union-to-intersection.ts +1 -1
- package/util/color.ts +85 -69
- package/util/extend.ts +1 -0
- package/util/geometry_util.ts +7 -8
- package/util/interpolate.ts +0 -4
- package/validate/validate.ts +6 -0
- package/validate/validate_array.ts +2 -0
- package/validate/validate_enum.ts +1 -0
- package/validate/validate_expression.ts +4 -0
- package/validate/validate_filter.ts +4 -2
- package/validate/validate_fog.ts +3 -0
- package/validate/validate_function.ts +7 -2
- package/validate/validate_iconset.ts +1 -0
- package/validate/validate_layer.ts +1 -0
- package/validate/validate_light.ts +3 -0
- package/validate/validate_lights.ts +27 -21
- package/validate/validate_model.ts +4 -0
- package/validate/validate_object.ts +2 -2
- package/validate/validate_projection.ts +1 -0
- package/validate/validate_property.ts +4 -0
- package/validate/validate_rain.ts +3 -0
- package/validate/validate_snow.ts +3 -0
- package/validate/validate_source.ts +8 -6
- package/validate/validate_terrain.ts +4 -0
- package/validate_mapbox_api_supported.ts +30 -19
- package/validate_style.ts +1 -0
- package/visit.ts +3 -1
|
@@ -85,6 +85,7 @@ function getTilePolygon(coordinates: Array<Array<GeoJSON.Position>>, bbox: BBox,
|
|
|
85
85
|
}
|
|
86
86
|
polygon.push(ring);
|
|
87
87
|
}
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
88
89
|
return polygon;
|
|
89
90
|
}
|
|
90
91
|
|
|
@@ -94,6 +95,7 @@ function getTilePolygons(coordinates: Array<Array<Array<GeoJSON.Position>>>, bbo
|
|
|
94
95
|
const polygon = getTilePolygon(coordinates[i], bbox, canonical);
|
|
95
96
|
polygons.push(polygon);
|
|
96
97
|
}
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
97
99
|
return polygons;
|
|
98
100
|
}
|
|
99
101
|
|
|
@@ -118,6 +120,7 @@ function getTilePoints(geometry: Array<Array<Point>> | null | undefined, pointBB
|
|
|
118
120
|
const worldSize = Math.pow(2, canonical.z) * EXTENT;
|
|
119
121
|
const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
|
|
120
122
|
const tilePoints = [];
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
121
124
|
if (!geometry) return tilePoints;
|
|
122
125
|
for (const points of geometry) {
|
|
123
126
|
for (const point of points) {
|
|
@@ -126,6 +129,7 @@ function getTilePoints(geometry: Array<Array<Point>> | null | undefined, pointBB
|
|
|
126
129
|
tilePoints.push(p);
|
|
127
130
|
}
|
|
128
131
|
}
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
129
133
|
return tilePoints;
|
|
130
134
|
}
|
|
131
135
|
|
|
@@ -230,12 +234,12 @@ class Within implements Expression {
|
|
|
230
234
|
if (args.length !== 2)
|
|
231
235
|
return context.error(`'within' expression requires exactly one argument, but found ${args.length - 1} instead.`);
|
|
232
236
|
if (isValue(args[1])) {
|
|
233
|
-
const geojson =
|
|
237
|
+
const geojson = args[1] as GeoJSON.GeoJSON;
|
|
234
238
|
if (geojson.type === 'FeatureCollection') {
|
|
235
239
|
for (let i = 0; i < geojson.features.length; ++i) {
|
|
236
240
|
const type = geojson.features[i].geometry.type;
|
|
237
241
|
if (type === 'Polygon' || type === 'MultiPolygon') {
|
|
238
|
-
return new Within(geojson, geojson.features[i].geometry);
|
|
242
|
+
return new Within(geojson, geojson.features[i].geometry as GeoJSONPolygons);
|
|
239
243
|
}
|
|
240
244
|
}
|
|
241
245
|
} else if (geojson.type === 'Feature') {
|
package/expression/expression.ts
CHANGED
|
@@ -6,7 +6,9 @@ export type SerializedExpression = Array<unknown> | Array<string> | string | num
|
|
|
6
6
|
|
|
7
7
|
export interface Expression {
|
|
8
8
|
readonly type: Type;
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
10
|
value?: any;
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
12
|
evaluate: (ctx: EvaluationContext) => any;
|
|
11
13
|
eachChild: (fn: (arg1: Expression) => void) => void;
|
|
12
14
|
/**
|
|
@@ -20,6 +22,7 @@ export interface Expression {
|
|
|
20
22
|
export type ExpressionParser = (args: ReadonlyArray<unknown>, context: ParsingContext) => Expression | void;
|
|
21
23
|
|
|
22
24
|
export type ExpressionRegistration = {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
26
|
new(...args: any[]): Expression;
|
|
24
27
|
readonly parse: ExpressionParser;
|
|
25
28
|
_classRegistryKey?: string;
|
package/expression/index.ts
CHANGED
|
@@ -41,7 +41,7 @@ export interface Feature {
|
|
|
41
41
|
readonly type: 0 | 1 | 2 | 3 | 'Unknown' | 'Point' | 'LineString' | 'Polygon';
|
|
42
42
|
readonly id?: string | number | null;
|
|
43
43
|
readonly properties: Record<PropertyKey, unknown>;
|
|
44
|
-
readonly patterns?: Record<PropertyKey, string>;
|
|
44
|
+
readonly patterns?: Record<PropertyKey, string[]>;
|
|
45
45
|
readonly geometry?: Array<Array<Point>>;
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -60,6 +60,7 @@ export interface GlobalProperties {
|
|
|
60
60
|
readonly isSupportedScript?: (_: string) => boolean;
|
|
61
61
|
accumulated?: Value;
|
|
62
62
|
brightness?: number;
|
|
63
|
+
worldview?: string;
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
export class StyleExpression {
|
|
@@ -89,6 +90,7 @@ export class StyleExpression {
|
|
|
89
90
|
formattedSection?: FormattedSection,
|
|
90
91
|
featureTileCoord?: Point,
|
|
91
92
|
featureDistanceData?: FeatureDistanceData,
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
94
|
): any {
|
|
93
95
|
this._evaluator.globals = globals;
|
|
94
96
|
this._evaluator.feature = feature;
|
|
@@ -111,6 +113,7 @@ export class StyleExpression {
|
|
|
111
113
|
formattedSection?: FormattedSection,
|
|
112
114
|
featureTileCoord?: Point,
|
|
113
115
|
featureDistanceData?: FeatureDistanceData,
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
114
117
|
): any {
|
|
115
118
|
this._evaluator.globals = globals;
|
|
116
119
|
this._evaluator.feature = feature || null;
|
|
@@ -201,6 +204,7 @@ export class ZoomConstantExpression<Kind extends EvaluationKind> {
|
|
|
201
204
|
canonical?: CanonicalTileID,
|
|
202
205
|
availableImages?: ImageId[],
|
|
203
206
|
formattedSection?: FormattedSection,
|
|
207
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
204
208
|
): any {
|
|
205
209
|
return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
206
210
|
}
|
|
@@ -212,6 +216,7 @@ export class ZoomConstantExpression<Kind extends EvaluationKind> {
|
|
|
212
216
|
canonical?: CanonicalTileID,
|
|
213
217
|
availableImages?: ImageId[],
|
|
214
218
|
formattedSection?: FormattedSection,
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
215
220
|
): any {
|
|
216
221
|
return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
217
222
|
}
|
|
@@ -246,6 +251,7 @@ export class ZoomDependentExpression<Kind extends EvaluationKind> {
|
|
|
246
251
|
canonical?: CanonicalTileID,
|
|
247
252
|
availableImages?: ImageId[],
|
|
248
253
|
formattedSection?: FormattedSection,
|
|
254
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
249
255
|
): any {
|
|
250
256
|
return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
251
257
|
}
|
|
@@ -257,6 +263,7 @@ export class ZoomDependentExpression<Kind extends EvaluationKind> {
|
|
|
257
263
|
canonical?: CanonicalTileID,
|
|
258
264
|
availableImages?: ImageId[],
|
|
259
265
|
formattedSection?: FormattedSection,
|
|
266
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
260
267
|
): any {
|
|
261
268
|
return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
262
269
|
}
|
|
@@ -279,6 +286,7 @@ export type ConstantExpression = {
|
|
|
279
286
|
featureState?: FeatureState,
|
|
280
287
|
canonical?: CanonicalTileID,
|
|
281
288
|
availableImages?: ImageId[],
|
|
289
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
282
290
|
) => any;
|
|
283
291
|
};
|
|
284
292
|
|
|
@@ -295,6 +303,7 @@ export type SourceExpression = {
|
|
|
295
303
|
canonical?: CanonicalTileID,
|
|
296
304
|
availableImages?: ImageId[],
|
|
297
305
|
formattedSection?: FormattedSection,
|
|
306
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
298
307
|
) => any;
|
|
299
308
|
};
|
|
300
309
|
|
|
@@ -308,6 +317,7 @@ export type CameraExpression = {
|
|
|
308
317
|
featureState?: FeatureState,
|
|
309
318
|
canonical?: CanonicalTileID,
|
|
310
319
|
availableImages?: ImageId[],
|
|
320
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
311
321
|
) => any;
|
|
312
322
|
readonly interpolationFactor: (input: number, lower: number, upper: number) => number;
|
|
313
323
|
zoomStops: Array<number>;
|
|
@@ -327,6 +337,7 @@ export interface CompositeExpression {
|
|
|
327
337
|
canonical?: CanonicalTileID,
|
|
328
338
|
availableImages?: ImageId[],
|
|
329
339
|
formattedSection?: FormattedSection,
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
330
341
|
) => any;
|
|
331
342
|
readonly interpolationFactor: (input: number, lower: number, upper: number) => number;
|
|
332
343
|
zoomStops: Array<number>;
|
|
@@ -336,6 +347,7 @@ export interface CompositeExpression {
|
|
|
336
347
|
export type StylePropertyExpression = ConstantExpression | SourceExpression | CameraExpression | CompositeExpression;
|
|
337
348
|
|
|
338
349
|
export function createPropertyExpression(
|
|
350
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
339
351
|
expression: any,
|
|
340
352
|
propertySpec: StylePropertySpecification,
|
|
341
353
|
scope?: string | null,
|
|
@@ -343,6 +355,7 @@ export function createPropertyExpression(
|
|
|
343
355
|
): Result<StylePropertyExpression, Array<ParsingError>> {
|
|
344
356
|
expression = createExpression(expression, propertySpec, scope, options);
|
|
345
357
|
if (expression.result === 'error') {
|
|
358
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
346
359
|
return expression;
|
|
347
360
|
}
|
|
348
361
|
|
|
@@ -398,6 +411,7 @@ export class StylePropertyFunction<T> {
|
|
|
398
411
|
_specification: StylePropertySpecification;
|
|
399
412
|
|
|
400
413
|
kind: EvaluationKind;
|
|
414
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
401
415
|
evaluate: (globals: GlobalProperties, feature?: Feature) => any;
|
|
402
416
|
interpolationFactor: (input: number, lower: number, upper: number) => number | null | undefined;
|
|
403
417
|
zoomStops: Array<number> | null | undefined;
|
|
@@ -435,7 +449,7 @@ export function normalizePropertyExpression<T>(
|
|
|
435
449
|
options?: ConfigOptions | null,
|
|
436
450
|
): StylePropertyExpression {
|
|
437
451
|
if (isFunction(value)) {
|
|
438
|
-
return new StylePropertyFunction(value, specification) as
|
|
452
|
+
return new StylePropertyFunction(value, specification) as unknown as StylePropertyExpression;
|
|
439
453
|
|
|
440
454
|
} else if (isExpression(value) || (Array.isArray(value) && value.length > 0)) {
|
|
441
455
|
const expression = createPropertyExpression(value, specification, scope, options);
|
|
@@ -446,7 +460,7 @@ export function normalizePropertyExpression<T>(
|
|
|
446
460
|
return expression.value;
|
|
447
461
|
|
|
448
462
|
} else {
|
|
449
|
-
let constant
|
|
463
|
+
let constant = value as Color;
|
|
450
464
|
if (typeof value === 'string' && specification.type === 'color') {
|
|
451
465
|
constant = Color.parse(value);
|
|
452
466
|
}
|
|
@@ -494,6 +508,7 @@ function findZoomCurve(expression: Expression): Step | Interpolate | ParsingErro
|
|
|
494
508
|
}
|
|
495
509
|
});
|
|
496
510
|
|
|
511
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
497
512
|
return result;
|
|
498
513
|
}
|
|
499
514
|
|
|
@@ -271,5 +271,5 @@ function isConstant(expression: Expression) {
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
return isFeatureConstant(expression) &&
|
|
274
|
-
isGlobalPropertyConstant(expression, ['zoom', 'heatmap-density', 'line-progress', 'raster-value', 'sky-radial-progress', 'accumulated', 'is-supported-script', 'pitch', 'distance-from-center', 'measure-light', 'raster-particle-speed']);
|
|
274
|
+
isGlobalPropertyConstant(expression, ['zoom', 'heatmap-density', 'worldview', 'line-progress', 'raster-value', 'sky-radial-progress', 'accumulated', 'is-supported-script', 'pitch', 'distance-from-center', 'measure-light', 'raster-particle-speed']);
|
|
275
275
|
}
|
|
@@ -70,7 +70,7 @@ export default class Formatted {
|
|
|
70
70
|
options["font-scale"] = section.scale;
|
|
71
71
|
}
|
|
72
72
|
if (section.textColor) {
|
|
73
|
-
options["text-color"] = (["rgba"] as Array<unknown>).concat(section.textColor.
|
|
73
|
+
options["text-color"] = (["rgba"] as Array<unknown>).concat(section.textColor.toNonPremultipliedRenderColor(null).toArray());
|
|
74
74
|
}
|
|
75
75
|
serialized.push(options);
|
|
76
76
|
}
|
|
@@ -72,8 +72,8 @@ export class ImageVariant {
|
|
|
72
72
|
return new ImageVariant({name, iconsetId}, {params, transform: new DOMMatrix([a, b, c, d, e, f])});
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
scaleSelf(factor: number): this {
|
|
76
|
-
this.options.transform.scaleSelf(factor);
|
|
75
|
+
scaleSelf(factor: number, yFactor?: number): this {
|
|
76
|
+
this.options.transform.scaleSelf(factor, yFactor);
|
|
77
77
|
return this;
|
|
78
78
|
}
|
|
79
79
|
}
|
package/expression/types.ts
CHANGED
|
@@ -120,6 +120,7 @@ export function isValidType(provided: Type, allowedTypes: Array<Type>): boolean
|
|
|
120
120
|
return allowedTypes.some(t => t.kind === provided.kind);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
124
|
export function isValidNativeType(provided: any, allowedTypes: Array<NativeType>): boolean {
|
|
124
125
|
return allowedTypes.some(t => {
|
|
125
126
|
if (t === 'null') {
|
|
@@ -133,3 +134,11 @@ export function isValidNativeType(provided: any, allowedTypes: Array<NativeType>
|
|
|
133
134
|
}
|
|
134
135
|
});
|
|
135
136
|
}
|
|
137
|
+
|
|
138
|
+
export function typeEquals(a: Type, b: Type): boolean {
|
|
139
|
+
if (a.kind === 'array' && b.kind === 'array') {
|
|
140
|
+
return a.N === b.N && typeEquals(a.itemType, b.itemType);
|
|
141
|
+
} else {
|
|
142
|
+
return a.kind === b.kind;
|
|
143
|
+
}
|
|
144
|
+
}
|
package/expression/values.ts
CHANGED
|
@@ -135,9 +135,7 @@ export function toString(value: Value): string {
|
|
|
135
135
|
return '';
|
|
136
136
|
} else if (type === 'string' || type === 'number' || type === 'boolean') {
|
|
137
137
|
return String(value as string | number | boolean);
|
|
138
|
-
} else if (value instanceof Color) {
|
|
139
|
-
return value.toStringPremultipliedAlpha();
|
|
140
|
-
} else if (value instanceof Formatted || value instanceof ResolvedImage) {
|
|
138
|
+
} else if (value instanceof Formatted || value instanceof ResolvedImage || value instanceof Color) {
|
|
141
139
|
return value.toString();
|
|
142
140
|
} else {
|
|
143
141
|
return JSON.stringify(value);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {isExpressionFilter} from './index';
|
|
2
2
|
|
|
3
|
-
import type {FilterSpecification} from '../types';
|
|
3
|
+
import type {FilterSpecification, ExpressionSpecification} from '../types';
|
|
4
4
|
|
|
5
5
|
type ExpectedTypes = {
|
|
6
6
|
[_: string]: 'string' | 'number' | 'boolean';
|
|
@@ -80,17 +80,19 @@ function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedType
|
|
|
80
80
|
op === '<=' ||
|
|
81
81
|
op === '>='
|
|
82
82
|
) {
|
|
83
|
-
const [, property, value] =
|
|
83
|
+
const [, property, value] = filter;
|
|
84
84
|
converted = convertComparisonOp(property, value, op, expectedTypes);
|
|
85
85
|
} else if (op === 'any') {
|
|
86
|
-
const children =
|
|
86
|
+
const children = filter.slice(1).map(f => {
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
88
|
const types: Record<string, any> = {};
|
|
88
89
|
const child = _convertFilter(f, types);
|
|
89
90
|
const typechecks = runtimeTypeChecks(types);
|
|
90
91
|
return typechecks === true ? child : ['case', typechecks, child, false];
|
|
91
|
-
});
|
|
92
|
+
}) as ExpressionSpecification;
|
|
92
93
|
return ['any'].concat(children);
|
|
93
94
|
} else if (op === 'all') {
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
96
|
const children: any[] = (filter).slice(1).map(f => _convertFilter(f, expectedTypes));
|
|
95
97
|
return children.length > 1 ? ['all'].concat(children) : [].concat(...children);
|
|
96
98
|
} else if (op === 'none') {
|
|
@@ -125,13 +127,16 @@ function runtimeTypeChecks(expectedTypes: ExpectedTypes) {
|
|
|
125
127
|
conditions.push(['==', ['typeof', get], expectedTypes[property]]);
|
|
126
128
|
}
|
|
127
129
|
if (conditions.length === 0) return true;
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
128
131
|
if (conditions.length === 1) return conditions[0];
|
|
129
132
|
return ['all'].concat(conditions);
|
|
130
133
|
}
|
|
131
134
|
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
132
136
|
function convertComparisonOp(property: string, value: any, op: string, expectedTypes?: ExpectedTypes | null) {
|
|
133
137
|
let get;
|
|
134
138
|
if (property === '$type') {
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
135
140
|
return [op, ['geometry-type'], value];
|
|
136
141
|
} else if (property === '$id') {
|
|
137
142
|
get = ['id'];
|
|
@@ -140,7 +145,7 @@ function convertComparisonOp(property: string, value: any, op: string, expectedT
|
|
|
140
145
|
}
|
|
141
146
|
|
|
142
147
|
if (expectedTypes && value !== null) {
|
|
143
|
-
const type =
|
|
148
|
+
const type = typeof value as 'string' | 'number' | 'boolean';
|
|
144
149
|
expectedTypes[property] = type;
|
|
145
150
|
}
|
|
146
151
|
|
|
@@ -158,10 +163,11 @@ function convertComparisonOp(property: string, value: any, op: string, expectedT
|
|
|
158
163
|
];
|
|
159
164
|
}
|
|
160
165
|
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
161
167
|
return [op, get, value];
|
|
162
168
|
}
|
|
163
169
|
|
|
164
|
-
function convertInOp(property: string, values: Array<
|
|
170
|
+
function convertInOp(property: string, values: Array<unknown>, negate: boolean = false) {
|
|
165
171
|
if (values.length === 0) return negate;
|
|
166
172
|
|
|
167
173
|
let get: string[];
|
|
@@ -193,6 +199,7 @@ function convertInOp(property: string, values: Array<any>, negate: boolean = fal
|
|
|
193
199
|
}
|
|
194
200
|
|
|
195
201
|
return [negate ? 'all' : 'any'].concat(
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
196
203
|
values.map(v => [negate ? '!=' : '==', get, v]) as any[]
|
|
197
204
|
);
|
|
198
205
|
}
|
package/feature_filter/index.ts
CHANGED
|
@@ -121,6 +121,7 @@ ${JSON.stringify(filterExp, null, 2)}
|
|
|
121
121
|
if (compiledStaticFilter.result === 'error') {
|
|
122
122
|
throw new Error(compiledStaticFilter.value.map(err => `${err.key}: ${err.message}`).join(', '));
|
|
123
123
|
} else {
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
124
125
|
filterFunc = (globalProperties: GlobalProperties, feature: Feature, canonical?: CanonicalTileID) => compiledStaticFilter.value.evaluate(globalProperties, feature, {}, canonical);
|
|
125
126
|
}
|
|
126
127
|
}
|
|
@@ -135,6 +136,7 @@ ${JSON.stringify(filterExp, null, 2)}
|
|
|
135
136
|
if (compiledDynamicFilter.result === 'error') {
|
|
136
137
|
throw new Error(compiledDynamicFilter.value.map(err => `${err.key}: ${err.message}`).join(', '));
|
|
137
138
|
} else {
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
138
140
|
dynamicFilterFunc = (globalProperties: GlobalProperties, feature: Feature, canonical?: CanonicalTileID, featureTileCoord?: Point, featureDistanceData?: FeatureDistanceData) => compiledDynamicFilter.value.evaluate(globalProperties, feature, {}, canonical, undefined, undefined, featureTileCoord, featureDistanceData);
|
|
139
141
|
needFeature = !isFeatureConstant(compiledDynamicFilter.value.expression);
|
|
140
142
|
}
|
|
@@ -151,6 +153,7 @@ ${JSON.stringify(filterExp, null, 2)}
|
|
|
151
153
|
};
|
|
152
154
|
}
|
|
153
155
|
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
157
|
function extractStaticFilter(filter: any): any {
|
|
155
158
|
if (!isDynamicFilter(filter)) {
|
|
156
159
|
return filter;
|
|
@@ -168,6 +171,7 @@ function extractStaticFilter(filter: any): any {
|
|
|
168
171
|
return result;
|
|
169
172
|
}
|
|
170
173
|
|
|
174
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
171
175
|
function collapseDynamicBooleanExpressions(expression: any): any {
|
|
172
176
|
if (!Array.isArray(expression)) {
|
|
173
177
|
return expression;
|
|
@@ -177,6 +181,7 @@ function collapseDynamicBooleanExpressions(expression: any): any {
|
|
|
177
181
|
if (collapsed === true) {
|
|
178
182
|
return collapsed;
|
|
179
183
|
} else {
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
180
185
|
return collapsed.map((subExpression) => collapseDynamicBooleanExpressions(subExpression));
|
|
181
186
|
}
|
|
182
187
|
}
|
|
@@ -190,6 +195,7 @@ function collapseDynamicBooleanExpressions(expression: any): any {
|
|
|
190
195
|
*
|
|
191
196
|
* @param {Array<any>} filter the filter expression mutated in-place.
|
|
192
197
|
*/
|
|
198
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
193
199
|
function unionDynamicBranches(filter: any) {
|
|
194
200
|
let isBranchingDynamically = false;
|
|
195
201
|
const branches = [];
|
|
@@ -227,6 +233,7 @@ function unionDynamicBranches(filter: any) {
|
|
|
227
233
|
}
|
|
228
234
|
}
|
|
229
235
|
|
|
236
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
230
237
|
function isDynamicFilter(filter: any): boolean {
|
|
231
238
|
// Base Cases
|
|
232
239
|
if (!Array.isArray(filter)) {
|
|
@@ -262,6 +269,7 @@ const dynamicConditionExpressions = new Set([
|
|
|
262
269
|
'to-boolean'
|
|
263
270
|
]);
|
|
264
271
|
|
|
272
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
265
273
|
function collapsedExpression(expression: any): any {
|
|
266
274
|
if (dynamicConditionExpressions.has(expression[0])) {
|
|
267
275
|
|
|
@@ -280,6 +288,7 @@ function compare(a: number, b: number) {
|
|
|
280
288
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
281
289
|
}
|
|
282
290
|
|
|
291
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
283
292
|
function geometryNeeded(filter: Array<any> | boolean) {
|
|
284
293
|
if (!Array.isArray(filter)) return false;
|
|
285
294
|
if (filter[0] === 'within' || filter[0] === 'distance') return true;
|
|
@@ -289,6 +298,7 @@ function geometryNeeded(filter: Array<any> | boolean) {
|
|
|
289
298
|
return false;
|
|
290
299
|
}
|
|
291
300
|
|
|
301
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
292
302
|
function convertFilter(filter?: Array<any> | null): unknown {
|
|
293
303
|
if (!filter) return true;
|
|
294
304
|
const op = filter[0];
|
|
@@ -313,22 +323,28 @@ function convertFilter(filter?: Array<any> | null): unknown {
|
|
|
313
323
|
return converted;
|
|
314
324
|
}
|
|
315
325
|
|
|
326
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
316
327
|
function convertComparisonOp(property: string, value: any, op: string) {
|
|
317
328
|
switch (property) {
|
|
318
329
|
case '$type':
|
|
330
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
319
331
|
return [`filter-type-${op}`, value];
|
|
320
332
|
case '$id':
|
|
333
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
321
334
|
return [`filter-id-${op}`, value];
|
|
322
335
|
default:
|
|
336
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
323
337
|
return [`filter-${op}`, property, value];
|
|
324
338
|
}
|
|
325
339
|
}
|
|
326
340
|
|
|
341
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
327
342
|
function convertDisjunctionOp(filters: Array<Array<any>>) {
|
|
328
343
|
// @ts-expect-error - TS2769 - No overload matches this call.
|
|
329
344
|
return ['any'].concat(filters.map(convertFilter));
|
|
330
345
|
}
|
|
331
346
|
|
|
347
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
332
348
|
function convertInOp(property: string, values: Array<any>) {
|
|
333
349
|
if (values.length === 0) { return false; }
|
|
334
350
|
switch (property) {
|
package/format.ts
CHANGED
|
@@ -5,6 +5,7 @@ import reference from './reference/latest';
|
|
|
5
5
|
import stringifyPretty from 'json-stringify-pretty-compact';
|
|
6
6
|
|
|
7
7
|
function sortKeysBy(obj, reference) {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
9
|
const result: Record<string, any> = {};
|
|
9
10
|
for (const key in reference) {
|
|
10
11
|
if (obj[key] !== undefined) {
|
package/function/convert.ts
CHANGED
|
@@ -33,6 +33,7 @@ export default function convertFunction<T>(parameters: FunctionSpecification<T>,
|
|
|
33
33
|
if (zoomAndFeatureDependent) {
|
|
34
34
|
return convertZoomAndPropertyFunction(parameters, propertySpec, stops as Array<ZoomAndPropertyFunctionStop<T>>);
|
|
35
35
|
} else if (zoomDependent) {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
36
37
|
return convertZoomFunction(parameters, propertySpec, stops as PropertyFunctionStop<T>[]);
|
|
37
38
|
} else {
|
|
38
39
|
return convertPropertyFunction(parameters, propertySpec, stops as PropertyFunctionStop<T>[]);
|
|
@@ -76,7 +77,9 @@ function convertZoomAndPropertyFunction<T>(
|
|
|
76
77
|
propertySpec: StylePropertySpecification,
|
|
77
78
|
stops: Array<ZoomAndPropertyFunctionStop<T>>,
|
|
78
79
|
): ExpressionSpecification {
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
81
|
const featureFunctionParameters: Record<string, any> = {};
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
83
|
const featureFunctionStops: Record<string, any> = {};
|
|
81
84
|
const zoomStops = [];
|
|
82
85
|
for (let s = 0; s < stops.length; s++) {
|
|
@@ -221,6 +224,7 @@ function convertZoomFunction<T>(parameters: FunctionSpecification<T>, propertySp
|
|
|
221
224
|
|
|
222
225
|
fixupDegenerateStepCurve(expression);
|
|
223
226
|
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
224
228
|
return expression;
|
|
225
229
|
}
|
|
226
230
|
|
|
@@ -250,7 +254,7 @@ function getFunctionType<T>(parameters: FunctionSpecification<T>, propertySpec:
|
|
|
250
254
|
return parameters.type;
|
|
251
255
|
} else {
|
|
252
256
|
assert(propertySpec.expression);
|
|
253
|
-
return
|
|
257
|
+
return propertySpec.expression.interpolated ? 'exponential' : 'interval';
|
|
254
258
|
}
|
|
255
259
|
}
|
|
256
260
|
|
package/function/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export function isFunction(value) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function identityFunction(x) {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
20
21
|
return x;
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -32,6 +33,7 @@ export function createFunction(parameters, propertySpec) {
|
|
|
32
33
|
|
|
33
34
|
if (parameters.stops) {
|
|
34
35
|
parameters.stops = parameters.stops.map((stop) => {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
35
37
|
return [stop[0], Color.parse(stop[1])];
|
|
36
38
|
});
|
|
37
39
|
}
|
|
@@ -73,6 +75,7 @@ export function createFunction(parameters, propertySpec) {
|
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
if (zoomAndFeatureDependent) {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
79
|
const featureFunctions: Record<string, any> = {};
|
|
77
80
|
const zoomStops = [];
|
|
78
81
|
for (let s = 0; s < parameters.stops.length; s++) {
|
|
@@ -101,8 +104,10 @@ export function createFunction(parameters, propertySpec) {
|
|
|
101
104
|
kind: 'composite',
|
|
102
105
|
interpolationType,
|
|
103
106
|
interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType),
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
104
108
|
zoomStops: featureFunctionStops.map(s => s[0]),
|
|
105
109
|
evaluate({zoom}, properties) {
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
106
111
|
return evaluateExponentialFunction({
|
|
107
112
|
stops: featureFunctionStops,
|
|
108
113
|
base: parameters.base
|
|
@@ -116,7 +121,9 @@ export function createFunction(parameters, propertySpec) {
|
|
|
116
121
|
kind: 'camera',
|
|
117
122
|
interpolationType,
|
|
118
123
|
interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType),
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
119
125
|
zoomStops: parameters.stops.map(s => s[0]),
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
120
127
|
evaluate: ({zoom}) => innerFun(parameters, propertySpec, zoom, hashedStops, categoricalKeyType)
|
|
121
128
|
};
|
|
122
129
|
} else {
|
|
@@ -125,8 +132,10 @@ export function createFunction(parameters, propertySpec) {
|
|
|
125
132
|
evaluate(_, feature) {
|
|
126
133
|
const value = feature && feature.properties ? feature.properties[parameters.property] : undefined;
|
|
127
134
|
if (value === undefined) {
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
128
136
|
return coalesce(parameters.default, propertySpec.default);
|
|
129
137
|
}
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
130
139
|
return innerFun(parameters, propertySpec, value, hashedStops, categoricalKeyType);
|
|
131
140
|
}
|
|
132
141
|
};
|
|
@@ -134,26 +143,36 @@ export function createFunction(parameters, propertySpec) {
|
|
|
134
143
|
}
|
|
135
144
|
|
|
136
145
|
function coalesce(a, b, c) {
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
137
147
|
if (a !== undefined) return a;
|
|
148
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
138
149
|
if (b !== undefined) return b;
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
139
151
|
if (c !== undefined) return c;
|
|
140
152
|
}
|
|
141
153
|
|
|
142
154
|
function evaluateCategoricalFunction(parameters, propertySpec, input, hashedStops, keyType) {
|
|
143
155
|
const evaluated = typeof input === keyType ? hashedStops[input] : undefined; // Enforce strict typing on input
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
144
157
|
return coalesce(evaluated, parameters.default, propertySpec.default);
|
|
145
158
|
}
|
|
146
159
|
|
|
147
160
|
function evaluateIntervalFunction(parameters, propertySpec, input) {
|
|
148
161
|
// Edge cases
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
149
163
|
if (getType(input) !== 'number') return coalesce(parameters.default, propertySpec.default);
|
|
150
164
|
const n = parameters.stops.length;
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
151
166
|
if (n === 1) return parameters.stops[0][1];
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
152
168
|
if (input <= parameters.stops[0][0]) return parameters.stops[0][1];
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
153
170
|
if (input >= parameters.stops[n - 1][0]) return parameters.stops[n - 1][1];
|
|
154
171
|
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
155
173
|
const index = findStopLessThanOrEqualTo(parameters.stops.map((stop) => stop[0]), input);
|
|
156
174
|
|
|
175
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
157
176
|
return parameters.stops[index][1];
|
|
158
177
|
}
|
|
159
178
|
|
|
@@ -161,12 +180,17 @@ function evaluateExponentialFunction(parameters, propertySpec, input) {
|
|
|
161
180
|
const base = parameters.base !== undefined ? parameters.base : 1;
|
|
162
181
|
|
|
163
182
|
// Edge cases
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
164
184
|
if (getType(input) !== 'number') return coalesce(parameters.default, propertySpec.default);
|
|
165
185
|
const n = parameters.stops.length;
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
166
187
|
if (n === 1) return parameters.stops[0][1];
|
|
188
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
167
189
|
if (input <= parameters.stops[0][0]) return parameters.stops[0][1];
|
|
190
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
168
191
|
if (input >= parameters.stops[n - 1][0]) return parameters.stops[n - 1][1];
|
|
169
192
|
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
170
194
|
const index = findStopLessThanOrEqualTo(parameters.stops.map((stop) => stop[0]), input);
|
|
171
195
|
const t = interpolationFactor(
|
|
172
196
|
input, base,
|
|
@@ -179,6 +203,7 @@ function evaluateExponentialFunction(parameters, propertySpec, input) {
|
|
|
179
203
|
|
|
180
204
|
if (parameters.colorSpace && parameters.colorSpace !== 'rgb') {
|
|
181
205
|
const colorspace = colorSpaces[parameters.colorSpace];
|
|
206
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
182
207
|
interp = (a, b) => colorspace.reverse(colorspace.interpolate(colorspace.forward(a), colorspace.forward(b), t));
|
|
183
208
|
}
|
|
184
209
|
|
|
@@ -191,11 +216,13 @@ function evaluateExponentialFunction(parameters, propertySpec, input) {
|
|
|
191
216
|
if (evaluatedLower === undefined || evaluatedUpper === undefined) {
|
|
192
217
|
return undefined;
|
|
193
218
|
}
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
194
220
|
return interp(evaluatedLower, evaluatedUpper, t);
|
|
195
221
|
}
|
|
196
222
|
};
|
|
197
223
|
}
|
|
198
224
|
|
|
225
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
199
226
|
return interp(outputLower, outputUpper, t);
|
|
200
227
|
}
|
|
201
228
|
|
|
@@ -209,6 +236,7 @@ function evaluateIdentityFunction(parameters, propertySpec, input) {
|
|
|
209
236
|
} else if (getType(input) !== propertySpec.type && (propertySpec.type !== 'enum' || !propertySpec.values[input])) {
|
|
210
237
|
input = undefined;
|
|
211
238
|
}
|
|
239
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
212
240
|
return coalesce(input, parameters.default, propertySpec.default);
|
|
213
241
|
}
|
|
214
242
|
|