@mapbox/mapbox-gl-style-spec 14.4.0 → 14.5.0
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/bin/gl-style-composite.js +0 -5
- package/bin/gl-style-format.js +0 -5
- package/bin/gl-style-migrate.js +0 -5
- package/bin/gl-style-validate.js +0 -5
- package/{composite.js → composite.ts} +1 -1
- package/data/{extent.js → extent.ts} +0 -2
- package/{deref.js → deref.ts} +7 -9
- package/{diff.js → diff.ts} +44 -21
- package/dist/index.cjs +794 -1226
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1746 -0
- package/dist/index.es.js +794 -1226
- package/dist/index.es.js.map +1 -1
- package/{empty.js → empty.ts} +1 -2
- package/error/{parsing_error.js → parsing_error.ts} +0 -2
- package/error/{validation_error.js → validation_error.ts} +5 -5
- package/expression/{compound_expression.js → compound_expression.ts} +29 -19
- package/expression/definitions/{assertion.js → assertion.ts} +16 -13
- package/expression/definitions/{at.js → at.ts} +12 -13
- package/expression/definitions/{case.js → case.ts} +12 -11
- package/expression/definitions/{coalesce.js → coalesce.ts} +11 -11
- package/expression/definitions/{coercion.js → coercion.ts} +21 -20
- package/expression/definitions/{collator.js → collator.ts} +11 -11
- package/expression/definitions/{comparison.js → comparison.ts} +30 -24
- package/expression/definitions/{config.js → config.ts} +16 -16
- package/expression/definitions/{distance.js → distance.ts} +60 -52
- package/expression/definitions/{format.js → format.ts} +26 -15
- package/expression/definitions/{image.js → image.ts} +12 -12
- package/expression/definitions/{in.js → in.ts} +22 -13
- package/expression/definitions/{index.js → index.ts} +70 -83
- package/expression/definitions/{index_of.js → index_of.ts} +24 -15
- package/expression/definitions/{interpolate.js → interpolate.ts} +44 -25
- package/expression/definitions/{length.js → length.ts} +11 -10
- package/expression/definitions/{let.js → let.ts} +10 -7
- package/expression/definitions/{literal.js → literal.ts} +11 -12
- package/expression/definitions/{match.js → match.ts} +25 -15
- package/expression/definitions/{number_format.js → number_format.ts} +10 -10
- package/expression/definitions/{slice.js → slice.ts} +23 -15
- package/expression/definitions/{step.js → step.ts} +14 -12
- package/expression/definitions/{var.js → var.ts} +5 -7
- package/expression/definitions/{within.js → within.ts} +41 -29
- package/expression/{evaluation_context.js → evaluation_context.ts} +26 -23
- package/expression/expression.ts +29 -0
- package/expression/{index.js → index.ts} +208 -110
- package/expression/{is_constant.js → is_constant.ts} +5 -7
- package/expression/{parsing_context.js → parsing_context.ts} +47 -34
- package/expression/{parsing_error.js → parsing_error.ts} +0 -2
- package/expression/{runtime_error.js → runtime_error.ts} +0 -2
- package/expression/{scope.js → scope.ts} +5 -5
- package/expression/{stops.js → stops.ts} +2 -4
- package/expression/types/{collator.js → collator.ts} +1 -3
- package/expression/types/{formatted.js → formatted.ts} +8 -7
- package/expression/types/{resolved_image.js → resolved_image.ts} +5 -7
- package/expression/{types.js → types.ts} +53 -45
- package/expression/{values.js → values.ts} +12 -12
- package/feature_filter/{convert.js → convert.ts} +19 -18
- package/feature_filter/{index.js → index.ts} +39 -21
- package/{format.js → format.ts} +3 -3
- package/function/{convert.js → convert.ts} +44 -44
- package/function/{index.js → index.ts} +12 -12
- package/{group_by_layout.js → group_by_layout.ts} +11 -8
- package/migrate/{expressions.js → expressions.ts} +7 -16
- package/migrate/{v8.js → v8.ts} +2 -2
- package/migrate/{v9.js → v9.ts} +2 -2
- package/{migrate.js → migrate.ts} +3 -3
- package/package.json +19 -18
- package/{read_style.js → read_style.ts} +5 -4
- package/reference/latest.ts +5 -0
- package/reference/v8.json +264 -7
- package/rollup.config.js +6 -24
- package/{style-spec.js → style-spec.ts} +41 -36
- package/test.js +3 -2
- package/types/config_options.ts +13 -0
- package/types/lut.ts +7 -0
- package/types/tile_id.ts +5 -0
- package/{types.js → types.ts} +527 -165
- package/util/{color.js → color.ts} +89 -3
- package/util/{color_spaces.js → color_spaces.ts} +12 -14
- package/util/{deep_equal.js → deep_equal.ts} +1 -3
- package/util/{extend.js → extend.ts} +1 -3
- package/util/{geometry_util.js → geometry_util.ts} +23 -11
- package/util/{get_type.js → get_type.ts} +1 -3
- package/util/{interpolate.js → interpolate.ts} +1 -3
- package/util/{properties.js → properties.ts} +5 -4
- package/util/{random.js → random.ts} +0 -2
- package/util/{ref_properties.js → ref_properties.ts} +0 -1
- package/util/{result.js → result.ts} +7 -5
- package/util/{unbundle_jsonlint.js → unbundle_jsonlint.ts} +5 -5
- package/validate/{validate.js → validate.ts} +33 -35
- package/validate/{validate_array.js → validate_array.ts} +5 -7
- package/validate/{validate_boolean.js → validate_boolean.ts} +3 -5
- package/validate/{validate_color.js → validate_color.ts} +3 -5
- package/validate/{validate_enum.js → validate_enum.ts} +4 -5
- package/validate/{validate_expression.js → validate_expression.ts} +7 -9
- package/validate/{validate_filter.js → validate_filter.ts} +16 -12
- package/validate/{validate_fog.js → validate_fog.ts} +4 -6
- package/validate/validate_formatted.ts +13 -0
- package/validate/{validate_function.js → validate_function.ts} +14 -16
- package/validate/{validate_glyphs_url.js → validate_glyphs_url.ts} +3 -5
- package/validate/validate_image.ts +13 -0
- package/validate/{validate_import.js → validate_import.ts} +6 -8
- package/validate/{validate_layer.js → validate_layer.ts} +17 -15
- package/validate/{validate_layout_property.js → validate_layout_property.ts} +3 -5
- package/validate/{validate_light.js → validate_light.ts} +4 -6
- package/validate/{validate_lights.js → validate_lights.ts} +7 -9
- package/validate/{validate_model.js → validate_model.ts} +4 -6
- package/validate/{validate_number.js → validate_number.ts} +4 -6
- package/validate/{validate_object.js → validate_object.ts} +5 -8
- package/validate/{validate_paint_property.js → validate_paint_property.ts} +3 -5
- package/validate/{validate_projection.js → validate_projection.ts} +4 -6
- package/validate/{validate_property.js → validate_property.ts} +15 -15
- package/validate/{validate_source.js → validate_source.ts} +16 -13
- package/validate/validate_string.ts +16 -0
- package/validate/validate_style.ts +33 -0
- package/validate/{validate_terrain.js → validate_terrain.ts} +5 -7
- package/{validate_mapbox_api_supported.js → validate_mapbox_api_supported.ts} +22 -18
- package/{validate_style.min.js → validate_style.min.ts} +20 -21
- package/{validate_style.js → validate_style.ts} +9 -9
- package/{visit.js → visit.ts} +22 -17
- package/.eslintrc +0 -10
- package/expression/expression.js +0 -28
- package/flow-typed/cheap-ruler.js +0 -25
- package/flow-typed/geojson.js +0 -44
- package/flow-typed/gl-matrix.js +0 -119
- package/flow-typed/gl.js +0 -5
- package/flow-typed/intl.js +0 -58
- package/flow-typed/kdbush.js +0 -9
- package/flow-typed/mapbox-gl-supported.js +0 -16
- package/flow-typed/mapbox-unitbezier.js +0 -14
- package/flow-typed/offscreen-canvas.js +0 -9
- package/flow-typed/pbf.js +0 -26
- package/flow-typed/point-geometry.js +0 -46
- package/flow-typed/potpack.js +0 -13
- package/flow-typed/tiny-sdf.js +0 -31
- package/flow-typed/tracked_parameters_proxy.js +0 -82
- package/flow-typed/vector-tile.js +0 -49
- package/flow-typed/webgl2.js +0 -41
- package/reference/latest.js +0 -7
- package/validate/validate_formatted.js +0 -15
- package/validate/validate_image.js +0 -15
- package/validate/validate_string.js +0 -18
- package/validate/validate_style.js +0 -29
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
6
|
-
import type
|
|
7
|
-
import type ParsingContext from '../parsing_context.js';
|
|
8
|
-
import type EvaluationContext from '../evaluation_context.js';
|
|
1
|
+
import {isValue} from '../values';
|
|
2
|
+
import type {Type} from '../types';
|
|
3
|
+
import {BooleanType} from '../types';
|
|
4
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
5
|
+
import type ParsingContext from '../parsing_context';
|
|
6
|
+
import type EvaluationContext from '../evaluation_context';
|
|
9
7
|
import type Point from '@mapbox/point-geometry';
|
|
10
|
-
import type {
|
|
11
|
-
import type {CanonicalTileID} from '../../../source/tile_id.js';
|
|
12
|
-
import {updateBBox, boxWithinBox, pointWithinPolygon, segmentIntersectSegment} from '../../util/geometry_util.js';
|
|
13
|
-
import type {BBox} from '../../util/geometry_util.js';
|
|
8
|
+
import type {CanonicalTileID} from '../../types/tile_id';
|
|
14
9
|
|
|
15
|
-
|
|
10
|
+
import {updateBBox, boxWithinBox, pointWithinPolygon, segmentIntersectSegment} from '../../util/geometry_util';
|
|
11
|
+
import type {BBox} from '../../util/geometry_util';
|
|
12
|
+
|
|
13
|
+
type GeoJSONPolygons = GeoJSON.Polygon | GeoJSON.MultiPolygon;
|
|
16
14
|
|
|
17
15
|
const EXTENT = 8192;
|
|
18
16
|
|
|
@@ -24,21 +22,21 @@ function mercatorYfromLat(lat: number) {
|
|
|
24
22
|
return (180 - (180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360)))) / 360;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
function getTileCoordinates(p:
|
|
25
|
+
function getTileCoordinates(p: GeoJSON.Position, canonical: CanonicalTileID) {
|
|
28
26
|
const x = mercatorXfromLng(p[0]);
|
|
29
27
|
const y = mercatorYfromLat(p[1]);
|
|
30
28
|
const tilesAtZoom = Math.pow(2, canonical.z);
|
|
31
29
|
return [Math.round(x * tilesAtZoom * EXTENT), Math.round(y * tilesAtZoom * EXTENT)];
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
function pointWithinPolygons(point:
|
|
32
|
+
function pointWithinPolygons(point: GeoJSON.Position, polygons: Array<Array<Array<GeoJSON.Position>>>) {
|
|
35
33
|
for (let i = 0; i < polygons.length; i++) {
|
|
36
34
|
if (pointWithinPolygon(point, polygons[i])) return true;
|
|
37
35
|
}
|
|
38
36
|
return false;
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
function lineIntersectPolygon(p1:
|
|
39
|
+
function lineIntersectPolygon(p1: GeoJSON.Position, p2: GeoJSON.Position, polygon: Array<Array<GeoJSON.Position>>) {
|
|
42
40
|
for (const ring of polygon) {
|
|
43
41
|
// loop through every edge of the ring
|
|
44
42
|
for (let j = 0, len = ring.length, k = len - 1; j < len; k = j++) {
|
|
@@ -52,7 +50,7 @@ function lineIntersectPolygon(p1: GeoJSONPosition, p2: GeoJSONPosition, polygon:
|
|
|
52
50
|
return false;
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
function lineStringWithinPolygon(line: Array<
|
|
53
|
+
function lineStringWithinPolygon(line: Array<GeoJSON.Position>, polygon: Array<Array<GeoJSON.Position>>) {
|
|
56
54
|
// First, check if geometry points of line segments are all inside polygon
|
|
57
55
|
for (let i = 0; i < line.length; ++i) {
|
|
58
56
|
if (!pointWithinPolygon(line[i], polygon)) {
|
|
@@ -69,14 +67,14 @@ function lineStringWithinPolygon(line: Array<GeoJSONPosition>, polygon: Array<Ar
|
|
|
69
67
|
return true;
|
|
70
68
|
}
|
|
71
69
|
|
|
72
|
-
function lineStringWithinPolygons(line: Array<
|
|
70
|
+
function lineStringWithinPolygons(line: Array<GeoJSON.Position>, polygons: Array<Array<Array<GeoJSON.Position>>>) {
|
|
73
71
|
for (let i = 0; i < polygons.length; i++) {
|
|
74
72
|
if (lineStringWithinPolygon(line, polygons[i])) return true;
|
|
75
73
|
}
|
|
76
74
|
return false;
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
function getTilePolygon(coordinates: Array<Array<
|
|
77
|
+
function getTilePolygon(coordinates: Array<Array<GeoJSON.Position>>, bbox: BBox, canonical: CanonicalTileID) {
|
|
80
78
|
const polygon = [];
|
|
81
79
|
for (let i = 0; i < coordinates.length; i++) {
|
|
82
80
|
const ring = [];
|
|
@@ -90,7 +88,7 @@ function getTilePolygon(coordinates: Array<Array<GeoJSONPosition>>, bbox: BBox,
|
|
|
90
88
|
return polygon;
|
|
91
89
|
}
|
|
92
90
|
|
|
93
|
-
function getTilePolygons(coordinates: Array<Array<Array<
|
|
91
|
+
function getTilePolygons(coordinates: Array<Array<Array<GeoJSON.Position>>>, bbox: BBox, canonical: CanonicalTileID) {
|
|
94
92
|
const polygons = [];
|
|
95
93
|
for (let i = 0; i < coordinates.length; i++) {
|
|
96
94
|
const polygon = getTilePolygon(coordinates[i], bbox, canonical);
|
|
@@ -99,7 +97,7 @@ function getTilePolygons(coordinates: Array<Array<Array<GeoJSONPosition>>>, bbox
|
|
|
99
97
|
return polygons;
|
|
100
98
|
}
|
|
101
99
|
|
|
102
|
-
function updatePoint(p:
|
|
100
|
+
function updatePoint(p: GeoJSON.Position, bbox: BBox, polyBBox: Array<number>, worldSize: number) {
|
|
103
101
|
if (p[0] < polyBBox[0] || p[0] > polyBBox[2]) {
|
|
104
102
|
const halfWorldSize = worldSize * 0.5;
|
|
105
103
|
let shift = (p[0] - polyBBox[0] > halfWorldSize) ? -worldSize : (polyBBox[0] - p[0] > halfWorldSize) ? worldSize : 0;
|
|
@@ -116,7 +114,7 @@ function resetBBox(bbox: BBox) {
|
|
|
116
114
|
bbox[2] = bbox[3] = -Infinity;
|
|
117
115
|
}
|
|
118
116
|
|
|
119
|
-
function getTilePoints(geometry:
|
|
117
|
+
function getTilePoints(geometry: Array<Array<Point>> | null | undefined, pointBBox: BBox, polyBBox: Array<number>, canonical: CanonicalTileID) {
|
|
120
118
|
const worldSize = Math.pow(2, canonical.z) * EXTENT;
|
|
121
119
|
const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
|
|
122
120
|
const tilePoints = [];
|
|
@@ -131,15 +129,15 @@ function getTilePoints(geometry: ?Array<Array<Point>>, pointBBox: BBox, polyBBox
|
|
|
131
129
|
return tilePoints;
|
|
132
130
|
}
|
|
133
131
|
|
|
134
|
-
function getTileLines(geometry:
|
|
132
|
+
function getTileLines(geometry: Array<Array<Point>> | null | undefined, lineBBox: BBox, polyBBox: Array<number>, canonical: CanonicalTileID) {
|
|
135
133
|
const worldSize = Math.pow(2, canonical.z) * EXTENT;
|
|
136
134
|
const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
|
|
137
|
-
const tileLines: Array<Array<
|
|
135
|
+
const tileLines: Array<Array<GeoJSON.Position>> = [];
|
|
138
136
|
if (!geometry) return tileLines;
|
|
139
137
|
for (const line of geometry) {
|
|
140
138
|
const tileLine = [];
|
|
141
139
|
for (const point of line) {
|
|
142
|
-
const p:
|
|
140
|
+
const p: GeoJSON.Position = [point.x + shifts[0], point.y + shifts[1]];
|
|
143
141
|
updateBBox(lineBBox, p);
|
|
144
142
|
tileLine.push(p);
|
|
145
143
|
}
|
|
@@ -166,8 +164,11 @@ function pointsWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPo
|
|
|
166
164
|
}
|
|
167
165
|
|
|
168
166
|
if (polygonGeometry.type === 'Polygon') {
|
|
167
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
169
168
|
const tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
|
|
169
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
170
170
|
const tilePoints = getTilePoints(ctx.geometry(), pointBBox, polyBBox, canonical);
|
|
171
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
171
172
|
if (!boxWithinBox(pointBBox, polyBBox)) return false;
|
|
172
173
|
|
|
173
174
|
for (const point of tilePoints) {
|
|
@@ -175,8 +176,11 @@ function pointsWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPo
|
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
if (polygonGeometry.type === 'MultiPolygon') {
|
|
179
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
178
180
|
const tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
|
|
181
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
179
182
|
const tilePoints = getTilePoints(ctx.geometry(), pointBBox, polyBBox, canonical);
|
|
183
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
180
184
|
if (!boxWithinBox(pointBBox, polyBBox)) return false;
|
|
181
185
|
|
|
182
186
|
for (const point of tilePoints) {
|
|
@@ -197,8 +201,11 @@ function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPol
|
|
|
197
201
|
}
|
|
198
202
|
|
|
199
203
|
if (polygonGeometry.type === 'Polygon') {
|
|
204
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
200
205
|
const tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
|
|
206
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
201
207
|
const tileLines = getTileLines(ctx.geometry(), lineBBox, polyBBox, canonical);
|
|
208
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
202
209
|
if (!boxWithinBox(lineBBox, polyBBox)) return false;
|
|
203
210
|
|
|
204
211
|
for (const line of tileLines) {
|
|
@@ -206,8 +213,11 @@ function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPol
|
|
|
206
213
|
}
|
|
207
214
|
}
|
|
208
215
|
if (polygonGeometry.type === 'MultiPolygon') {
|
|
216
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
209
217
|
const tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
|
|
218
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
210
219
|
const tileLines = getTileLines(ctx.geometry(), lineBBox, polyBBox, canonical);
|
|
220
|
+
// @ts-expect-error - TS2345 - Argument of type 'number[]' is not assignable to parameter of type 'BBox'.
|
|
211
221
|
if (!boxWithinBox(lineBBox, polyBBox)) return false;
|
|
212
222
|
|
|
213
223
|
for (const line of tileLines) {
|
|
@@ -219,20 +229,21 @@ function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPol
|
|
|
219
229
|
|
|
220
230
|
class Within implements Expression {
|
|
221
231
|
type: Type;
|
|
222
|
-
geojson: GeoJSON
|
|
232
|
+
geojson: GeoJSON.GeoJSON;
|
|
223
233
|
geometries: GeoJSONPolygons;
|
|
224
234
|
|
|
225
|
-
constructor(geojson: GeoJSON, geometries: GeoJSONPolygons) {
|
|
235
|
+
constructor(geojson: GeoJSON.GeoJSON, geometries: GeoJSONPolygons) {
|
|
226
236
|
this.type = BooleanType;
|
|
227
237
|
this.geojson = geojson;
|
|
228
238
|
this.geometries = geometries;
|
|
229
239
|
}
|
|
230
240
|
|
|
231
|
-
static parse(args:
|
|
241
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Within | null | undefined {
|
|
232
242
|
if (args.length !== 2)
|
|
243
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Within'.
|
|
233
244
|
return context.error(`'within' expression requires exactly one argument, but found ${args.length - 1} instead.`);
|
|
234
245
|
if (isValue(args[1])) {
|
|
235
|
-
const geojson = (args[1]
|
|
246
|
+
const geojson = (args[1] as any);
|
|
236
247
|
if (geojson.type === 'FeatureCollection') {
|
|
237
248
|
for (let i = 0; i < geojson.features.length; ++i) {
|
|
238
249
|
const type = geojson.features[i].geometry.type;
|
|
@@ -249,6 +260,7 @@ class Within implements Expression {
|
|
|
249
260
|
return new Within(geojson, geojson);
|
|
250
261
|
}
|
|
251
262
|
}
|
|
263
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Within'.
|
|
252
264
|
return context.error(`'within' expression requires valid geojson object that contains polygon geometry type.`);
|
|
253
265
|
}
|
|
254
266
|
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {Color} from './values.js';
|
|
1
|
+
import {Color} from './values';
|
|
4
2
|
|
|
5
3
|
import type Point from '@mapbox/point-geometry';
|
|
6
|
-
import type {FormattedSection} from './types/formatted
|
|
7
|
-
import type {GlobalProperties, Feature, FeatureState} from './index
|
|
8
|
-
import type {CanonicalTileID} from '
|
|
9
|
-
import type {FeatureDistanceData} from '../feature_filter/index
|
|
10
|
-
import type {ConfigOptions, ConfigOptionValue} from '
|
|
4
|
+
import type {FormattedSection} from './types/formatted';
|
|
5
|
+
import type {GlobalProperties, Feature, FeatureState} from './index';
|
|
6
|
+
import type {CanonicalTileID} from '../types/tile_id';
|
|
7
|
+
import type {FeatureDistanceData} from '../feature_filter/index';
|
|
8
|
+
import type {ConfigOptions, ConfigOptionValue} from '../types/config_options';
|
|
11
9
|
|
|
12
10
|
const geometryTypes = ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
13
11
|
|
|
14
12
|
class EvaluationContext {
|
|
15
13
|
globals: GlobalProperties;
|
|
16
|
-
feature:
|
|
17
|
-
featureState:
|
|
18
|
-
formattedSection:
|
|
19
|
-
availableImages:
|
|
14
|
+
feature: Feature | null | undefined;
|
|
15
|
+
featureState: FeatureState | null | undefined;
|
|
16
|
+
formattedSection: FormattedSection | null | undefined;
|
|
17
|
+
availableImages: Array<string> | null | undefined;
|
|
20
18
|
canonical: null | CanonicalTileID;
|
|
21
|
-
featureTileCoord:
|
|
22
|
-
featureDistanceData:
|
|
23
|
-
scope:
|
|
24
|
-
options:
|
|
19
|
+
featureTileCoord: Point | null | undefined;
|
|
20
|
+
featureDistanceData: FeatureDistanceData | null | undefined;
|
|
21
|
+
scope: string | null | undefined;
|
|
22
|
+
options: ConfigOptions | null | undefined;
|
|
25
23
|
|
|
26
|
-
_parseColorCache: {
|
|
24
|
+
_parseColorCache: {
|
|
25
|
+
[_: string]: Color | null | undefined;
|
|
26
|
+
};
|
|
27
27
|
|
|
28
|
-
constructor(scope
|
|
29
|
-
this.globals = (null
|
|
28
|
+
constructor(scope?: string | null, options?: ConfigOptions | null) {
|
|
29
|
+
this.globals = (null as any);
|
|
30
30
|
this.feature = null;
|
|
31
31
|
this.featureState = null;
|
|
32
32
|
this.formattedSection = null;
|
|
@@ -47,7 +47,7 @@ class EvaluationContext {
|
|
|
47
47
|
return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
geometry():
|
|
50
|
+
geometry(): Array<Array<Point>> | null | undefined {
|
|
51
51
|
return this.feature && 'geometry' in this.feature ? this.feature.geometry : null;
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -55,7 +55,9 @@ class EvaluationContext {
|
|
|
55
55
|
return this.canonical;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
properties(): {
|
|
58
|
+
properties(): {
|
|
59
|
+
[key: string]: any;
|
|
60
|
+
} {
|
|
59
61
|
return (this.feature && this.feature.properties) || {};
|
|
60
62
|
}
|
|
61
63
|
|
|
@@ -86,15 +88,16 @@ class EvaluationContext {
|
|
|
86
88
|
return 0;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
parseColor(input: string):
|
|
91
|
+
parseColor(input: string): Color | null | undefined {
|
|
90
92
|
let cached = this._parseColorCache[input];
|
|
91
93
|
if (!cached) {
|
|
94
|
+
// @ts-expect-error - TS2322 - Type 'void | Color' is not assignable to type 'Color'. | TS2322 - Type 'void | Color' is not assignable to type 'Color'.
|
|
92
95
|
cached = this._parseColorCache[input] = Color.parse(input);
|
|
93
96
|
}
|
|
94
97
|
return cached;
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
getConfig(id: string):
|
|
100
|
+
getConfig(id: string): ConfigOptionValue | null | undefined {
|
|
98
101
|
return this.options ? this.options.get(id) : null;
|
|
99
102
|
}
|
|
100
103
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type {Type} from './types';
|
|
2
|
+
import type ParsingContext from './parsing_context';
|
|
3
|
+
import type EvaluationContext from './evaluation_context';
|
|
4
|
+
|
|
5
|
+
export type SerializedExpression = Array<unknown> | Array<string> | string | number | boolean | null;
|
|
6
|
+
|
|
7
|
+
export interface Expression {
|
|
8
|
+
readonly type: Type;
|
|
9
|
+
value?: any;
|
|
10
|
+
evaluate(ctx: EvaluationContext): any;
|
|
11
|
+
eachChild(fn: (arg1: Expression) => void): void;
|
|
12
|
+
/**
|
|
13
|
+
* Statically analyze the expression, attempting to enumerate possible outputs. Returns
|
|
14
|
+
* false if the complete set of outputs is statically undecidable, otherwise true.
|
|
15
|
+
*/
|
|
16
|
+
outputDefined(): boolean;
|
|
17
|
+
serialize(): SerializedExpression;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type ExpressionParser = (args: ReadonlyArray<unknown>, context: ParsingContext) => Expression | void;
|
|
21
|
+
|
|
22
|
+
export type ExpressionRegistration = {
|
|
23
|
+
new(...args: any[]): Expression;
|
|
24
|
+
readonly parse: ExpressionParser;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type ExpressionRegistry = {
|
|
28
|
+
[_: string]: ExpressionRegistration;
|
|
29
|
+
};
|