@mapbox/mapbox-gl-style-spec 13.28.0 → 14.0.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.
Files changed (62) hide show
  1. package/bin/gl-style-composite.js +2 -2
  2. package/bin/gl-style-format.js +2 -2
  3. package/bin/gl-style-migrate.js +2 -2
  4. package/bin/gl-style-validate.js +2 -2
  5. package/data/extent.js +18 -0
  6. package/deref.js +1 -1
  7. package/diff.js +36 -15
  8. package/dist/index.cjs +5810 -1995
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.es.js +5808 -1991
  11. package/dist/index.es.js.map +1 -1
  12. package/expression/compound_expression.js +2 -1
  13. package/expression/definitions/assertion.js +2 -2
  14. package/expression/definitions/coercion.js +54 -15
  15. package/expression/definitions/comparison.js +2 -0
  16. package/expression/definitions/distance.js +597 -0
  17. package/expression/definitions/format.js +2 -2
  18. package/expression/definitions/image.js +34 -14
  19. package/expression/definitions/index.js +122 -8
  20. package/expression/definitions/interpolate.js +1 -1
  21. package/expression/definitions/match.js +2 -2
  22. package/expression/definitions/within.js +21 -92
  23. package/expression/evaluation_context.js +12 -1
  24. package/expression/index.js +74 -43
  25. package/expression/is_constant.js +19 -1
  26. package/expression/parsing_context.js +20 -16
  27. package/expression/types/formatted.js +2 -2
  28. package/expression/types/resolved_image.js +19 -8
  29. package/expression/types.js +2 -1
  30. package/expression/values.js +25 -0
  31. package/feature_filter/convert.js +1 -1
  32. package/feature_filter/index.js +4 -4
  33. package/flow-typed/cheap-ruler.js +25 -0
  34. package/flow-typed/geojson.js +8 -7
  35. package/flow-typed/gl-matrix.js +4 -2
  36. package/flow-typed/kdbush.js +9 -0
  37. package/function/convert.js +23 -12
  38. package/group_by_layout.js +2 -2
  39. package/migrate/expressions.js +3 -0
  40. package/package.json +5 -2
  41. package/reference/v8.json +1772 -112
  42. package/style-spec.js +4 -3
  43. package/types.js +190 -24
  44. package/util/color.js +31 -0
  45. package/util/geometry_util.js +145 -0
  46. package/util/properties.js +10 -2
  47. package/util/random.js +12 -0
  48. package/validate/validate.js +17 -7
  49. package/validate/validate_array.js +1 -1
  50. package/validate/validate_filter.js +4 -12
  51. package/validate/validate_function.js +2 -2
  52. package/validate/validate_import.js +31 -0
  53. package/validate/validate_layer.js +3 -2
  54. package/validate/validate_lights.js +84 -0
  55. package/validate/validate_model.js +38 -0
  56. package/validate/validate_property.js +17 -3
  57. package/validate/validate_source.js +3 -2
  58. package/validate/validate_style.js +29 -0
  59. package/validate_mapbox_api_supported.js +55 -11
  60. package/validate_style.js +4 -0
  61. package/validate_style.min.js +11 -19
  62. package/visit.js +3 -2
package/style-spec.js CHANGED
@@ -1,11 +1,12 @@
1
1
  // @flow
2
2
 
3
3
  type ExpressionType = 'data-driven' | 'color-ramp' | 'data-constant' | 'constant';
4
- type ExpressionParameters = Array<'zoom' | 'feature' | 'feature-state' | 'heatmap-density' | 'line-progress' | 'sky-radial-progress' | 'pitch' | 'distance-from-center'>;
4
+ type ExpressionParameters = Array<'zoom' | 'feature' | 'feature-state' | 'heatmap-density' | 'line-progress' | 'raster-value' | 'sky-radial-progress' | 'pitch' | 'distance-from-center'>;
5
5
 
6
- type ExpressionSpecification = {
6
+ export type ExpressionSpecification = {
7
7
  interpolated: boolean,
8
- parameters: ExpressionParameters
8
+ parameters: ExpressionParameters,
9
+ relaxZoomRestriction: boolean
9
10
  }
10
11
 
11
12
  export type StylePropertySpecification = {
package/types.js CHANGED
@@ -59,6 +59,7 @@ export type DataDrivenPropertyValueSpecification<T> =
59
59
 
60
60
  export type StyleSpecification = {|
61
61
  "version": 8,
62
+ "fragment"?: boolean,
62
63
  "name"?: string,
63
64
  "metadata"?: mixed,
64
65
  "center"?: Array<number>,
@@ -66,16 +67,29 @@ export type StyleSpecification = {|
66
67
  "bearing"?: number,
67
68
  "pitch"?: number,
68
69
  "light"?: LightSpecification,
70
+ "lights"?: Array<LightsSpecification>,
69
71
  "terrain"?: TerrainSpecification,
70
72
  "fog"?: FogSpecification,
71
- "sources": {[_: string]: SourceSpecification},
73
+ "camera"?: CameraSpecification,
74
+ "imports"?: Array<ImportSpecification>,
75
+ "schema"?: SchemaSpecification,
76
+ "sources": SourcesSpecification,
72
77
  "sprite"?: string,
73
78
  "glyphs"?: string,
74
79
  "transition"?: TransitionSpecification,
75
80
  "projection"?: ProjectionSpecification,
76
- "layers": Array<LayerSpecification>
81
+ "layers": Array<LayerSpecification>,
82
+ "models"?: ModelsSpecification
77
83
  |}
78
84
 
85
+ export type SourcesSpecification = {
86
+ [_: string]: SourceSpecification
87
+ }
88
+
89
+ export type ModelsSpecification = {
90
+ [_: string]: ModelSpecification
91
+ }
92
+
79
93
  export type LightSpecification = {|
80
94
  "anchor"?: PropertyValueSpecification<"map" | "viewport">,
81
95
  "position"?: PropertyValueSpecification<[number, number, number]>,
@@ -97,12 +111,42 @@ export type FogSpecification = {|
97
111
  "star-intensity"?: PropertyValueSpecification<number>
98
112
  |}
99
113
 
114
+ export type CameraSpecification = {|
115
+ "camera-projection"?: PropertyValueSpecification<"perspective" | "orthographic">
116
+ |}
117
+
100
118
  export type ProjectionSpecification = {|
101
119
  "name": "albers" | "equalEarth" | "equirectangular" | "lambertConformalConic" | "mercator" | "naturalEarth" | "winkelTripel" | "globe",
102
120
  "center"?: [number, number],
103
121
  "parallels"?: [number, number]
104
122
  |}
105
123
 
124
+ export type ImportSpecification = {|
125
+ "id": string,
126
+ "url": string,
127
+ "config"?: ConfigSpecification,
128
+ "data"?: StyleSpecification
129
+ |}
130
+
131
+ export type ConfigSpecification = {
132
+ [_: string]: mixed
133
+ }
134
+
135
+ export type SchemaSpecification = {
136
+ [_: string]: OptionSpecification
137
+ }
138
+
139
+ export type OptionSpecification = {|
140
+ "default": mixed,
141
+ "type"?: "string" | "number" | "boolean" | "color",
142
+ "array"?: boolean,
143
+ "minValue"?: number,
144
+ "maxValue"?: number,
145
+ "stepValue"?: number,
146
+ "values"?: Array<mixed>,
147
+ "metadata"?: mixed
148
+ |}
149
+
106
150
  export type VectorSourceSpecification = {
107
151
  "type": "vector",
108
152
  "url"?: string,
@@ -113,7 +157,8 @@ export type VectorSourceSpecification = {
113
157
  "maxzoom"?: number,
114
158
  "attribution"?: string,
115
159
  "promoteId"?: PromoteIdSpecification,
116
- "volatile"?: boolean
160
+ "volatile"?: boolean,
161
+ [_: string]: mixed
117
162
  }
118
163
 
119
164
  export type RasterSourceSpecification = {
@@ -126,7 +171,8 @@ export type RasterSourceSpecification = {
126
171
  "tileSize"?: number,
127
172
  "scheme"?: "xyz" | "tms",
128
173
  "attribution"?: string,
129
- "volatile"?: boolean
174
+ "volatile"?: boolean,
175
+ [_: string]: mixed
130
176
  }
131
177
 
132
178
  export type RasterDEMSourceSpecification = {
@@ -139,7 +185,8 @@ export type RasterDEMSourceSpecification = {
139
185
  "tileSize"?: number,
140
186
  "attribution"?: string,
141
187
  "encoding"?: "terrarium" | "mapbox",
142
- "volatile"?: boolean
188
+ "volatile"?: boolean,
189
+ [_: string]: mixed
143
190
  }
144
191
 
145
192
  export type GeoJSONSourceSpecification = {|
@@ -172,6 +219,13 @@ export type ImageSourceSpecification = {|
172
219
  "coordinates": [[number, number], [number, number], [number, number], [number, number]]
173
220
  |}
174
221
 
222
+ export type ModelSourceSpecification = {|
223
+ "type": "model" | "batched-model",
224
+ "maxzoom"?: number,
225
+ "minzoom"?: number,
226
+ "tiles"?: Array<string>
227
+ |}
228
+
175
229
  export type SourceSpecification =
176
230
  | VectorSourceSpecification
177
231
  | RasterSourceSpecification
@@ -179,6 +233,46 @@ export type SourceSpecification =
179
233
  | GeoJSONSourceSpecification
180
234
  | VideoSourceSpecification
181
235
  | ImageSourceSpecification
236
+ | ModelSourceSpecification
237
+
238
+ export type ModelSpecification = string;
239
+
240
+ export type AmbientLightSpecification = {|
241
+ "id": string,
242
+ "properties"?: {|
243
+ "color"?: PropertyValueSpecification<ColorSpecification>,
244
+ "intensity"?: PropertyValueSpecification<number>
245
+ |},
246
+ "type": "ambient"
247
+ |}
248
+
249
+ export type DirectionalLightSpecification = {|
250
+ "id": string,
251
+ "properties"?: {|
252
+ "direction"?: PropertyValueSpecification<[number, number]>,
253
+ "color"?: PropertyValueSpecification<ColorSpecification>,
254
+ "intensity"?: PropertyValueSpecification<number>,
255
+ "cast-shadows"?: ExpressionSpecification,
256
+ "shadow-intensity"?: PropertyValueSpecification<number>
257
+ |},
258
+ "type": "directional"
259
+ |}
260
+
261
+ export type FlatLightSpecification = {|
262
+ "id": string,
263
+ "properties"?: {|
264
+ "anchor"?: PropertyValueSpecification<"map" | "viewport">,
265
+ "position"?: PropertyValueSpecification<[number, number, number]>,
266
+ "color"?: PropertyValueSpecification<ColorSpecification>,
267
+ "intensity"?: PropertyValueSpecification<number>
268
+ |},
269
+ "type": "flat"
270
+ |}
271
+
272
+ export type LightsSpecification =
273
+ | AmbientLightSpecification
274
+ | DirectionalLightSpecification
275
+ | FlatLightSpecification;
182
276
 
183
277
  export type FillLayerSpecification = {|
184
278
  "id": string,
@@ -186,12 +280,13 @@ export type FillLayerSpecification = {|
186
280
  "metadata"?: mixed,
187
281
  "source": string,
188
282
  "source-layer"?: string,
283
+ "slot"?: string,
189
284
  "minzoom"?: number,
190
285
  "maxzoom"?: number,
191
286
  "filter"?: FilterSpecification,
192
287
  "layout"?: {|
193
288
  "fill-sort-key"?: DataDrivenPropertyValueSpecification<number>,
194
- "visibility"?: "visible" | "none"
289
+ "visibility"?: ExpressionSpecification
195
290
  |},
196
291
  "paint"?: {|
197
292
  "fill-antialias"?: PropertyValueSpecification<boolean>,
@@ -200,7 +295,8 @@ export type FillLayerSpecification = {|
200
295
  "fill-outline-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>,
201
296
  "fill-translate"?: PropertyValueSpecification<[number, number]>,
202
297
  "fill-translate-anchor"?: PropertyValueSpecification<"map" | "viewport">,
203
- "fill-pattern"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>
298
+ "fill-pattern"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>,
299
+ "fill-emissive-strength"?: PropertyValueSpecification<number>
204
300
  |}
205
301
  |}
206
302
 
@@ -210,6 +306,7 @@ export type LineLayerSpecification = {|
210
306
  "metadata"?: mixed,
211
307
  "source": string,
212
308
  "source-layer"?: string,
309
+ "slot"?: string,
213
310
  "minzoom"?: number,
214
311
  "maxzoom"?: number,
215
312
  "filter"?: FilterSpecification,
@@ -219,7 +316,7 @@ export type LineLayerSpecification = {|
219
316
  "line-miter-limit"?: PropertyValueSpecification<number>,
220
317
  "line-round-limit"?: PropertyValueSpecification<number>,
221
318
  "line-sort-key"?: DataDrivenPropertyValueSpecification<number>,
222
- "visibility"?: "visible" | "none"
319
+ "visibility"?: ExpressionSpecification
223
320
  |},
224
321
  "paint"?: {|
225
322
  "line-opacity"?: DataDrivenPropertyValueSpecification<number>,
@@ -233,7 +330,10 @@ export type LineLayerSpecification = {|
233
330
  "line-dasharray"?: DataDrivenPropertyValueSpecification<Array<number>>,
234
331
  "line-pattern"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>,
235
332
  "line-gradient"?: ExpressionSpecification,
236
- "line-trim-offset"?: [number, number]
333
+ "line-trim-offset"?: [number, number],
334
+ "line-emissive-strength"?: PropertyValueSpecification<number>,
335
+ "line-border-width"?: DataDrivenPropertyValueSpecification<number>,
336
+ "line-border-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>
237
337
  |}
238
338
  |}
239
339
 
@@ -243,6 +343,7 @@ export type SymbolLayerSpecification = {|
243
343
  "metadata"?: mixed,
244
344
  "source": string,
245
345
  "source-layer"?: string,
346
+ "slot"?: string,
246
347
  "minzoom"?: number,
247
348
  "maxzoom"?: number,
248
349
  "filter"?: FilterSpecification,
@@ -257,8 +358,8 @@ export type SymbolLayerSpecification = {|
257
358
  "icon-optional"?: PropertyValueSpecification<boolean>,
258
359
  "icon-rotation-alignment"?: PropertyValueSpecification<"map" | "viewport" | "auto">,
259
360
  "icon-size"?: DataDrivenPropertyValueSpecification<number>,
260
- "icon-text-fit"?: PropertyValueSpecification<"none" | "width" | "height" | "both">,
261
- "icon-text-fit-padding"?: PropertyValueSpecification<[number, number, number, number]>,
361
+ "icon-text-fit"?: DataDrivenPropertyValueSpecification<"none" | "width" | "height" | "both">,
362
+ "icon-text-fit-padding"?: DataDrivenPropertyValueSpecification<[number, number, number, number]>,
262
363
  "icon-image"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>,
263
364
  "icon-rotate"?: DataDrivenPropertyValueSpecification<number>,
264
365
  "icon-padding"?: PropertyValueSpecification<number>,
@@ -288,16 +389,19 @@ export type SymbolLayerSpecification = {|
288
389
  "text-allow-overlap"?: PropertyValueSpecification<boolean>,
289
390
  "text-ignore-placement"?: PropertyValueSpecification<boolean>,
290
391
  "text-optional"?: PropertyValueSpecification<boolean>,
291
- "visibility"?: "visible" | "none"
392
+ "visibility"?: ExpressionSpecification
292
393
  |},
293
394
  "paint"?: {|
294
395
  "icon-opacity"?: DataDrivenPropertyValueSpecification<number>,
396
+ "icon-emissive-strength"?: DataDrivenPropertyValueSpecification<number>,
397
+ "text-emissive-strength"?: DataDrivenPropertyValueSpecification<number>,
295
398
  "icon-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>,
296
399
  "icon-halo-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>,
297
400
  "icon-halo-width"?: DataDrivenPropertyValueSpecification<number>,
298
401
  "icon-halo-blur"?: DataDrivenPropertyValueSpecification<number>,
299
402
  "icon-translate"?: PropertyValueSpecification<[number, number]>,
300
403
  "icon-translate-anchor"?: PropertyValueSpecification<"map" | "viewport">,
404
+ "icon-image-cross-fade"?: DataDrivenPropertyValueSpecification<number>,
301
405
  "text-opacity"?: DataDrivenPropertyValueSpecification<number>,
302
406
  "text-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>,
303
407
  "text-halo-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>,
@@ -314,12 +418,13 @@ export type CircleLayerSpecification = {|
314
418
  "metadata"?: mixed,
315
419
  "source": string,
316
420
  "source-layer"?: string,
421
+ "slot"?: string,
317
422
  "minzoom"?: number,
318
423
  "maxzoom"?: number,
319
424
  "filter"?: FilterSpecification,
320
425
  "layout"?: {|
321
426
  "circle-sort-key"?: DataDrivenPropertyValueSpecification<number>,
322
- "visibility"?: "visible" | "none"
427
+ "visibility"?: ExpressionSpecification
323
428
  |},
324
429
  "paint"?: {|
325
430
  "circle-radius"?: DataDrivenPropertyValueSpecification<number>,
@@ -332,7 +437,8 @@ export type CircleLayerSpecification = {|
332
437
  "circle-pitch-alignment"?: PropertyValueSpecification<"map" | "viewport">,
333
438
  "circle-stroke-width"?: DataDrivenPropertyValueSpecification<number>,
334
439
  "circle-stroke-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>,
335
- "circle-stroke-opacity"?: DataDrivenPropertyValueSpecification<number>
440
+ "circle-stroke-opacity"?: DataDrivenPropertyValueSpecification<number>,
441
+ "circle-emissive-strength"?: PropertyValueSpecification<number>
336
442
  |}
337
443
  |}
338
444
 
@@ -342,11 +448,12 @@ export type HeatmapLayerSpecification = {|
342
448
  "metadata"?: mixed,
343
449
  "source": string,
344
450
  "source-layer"?: string,
451
+ "slot"?: string,
345
452
  "minzoom"?: number,
346
453
  "maxzoom"?: number,
347
454
  "filter"?: FilterSpecification,
348
455
  "layout"?: {|
349
- "visibility"?: "visible" | "none"
456
+ "visibility"?: ExpressionSpecification
350
457
  |},
351
458
  "paint"?: {|
352
459
  "heatmap-radius"?: DataDrivenPropertyValueSpecification<number>,
@@ -363,12 +470,13 @@ export type FillExtrusionLayerSpecification = {|
363
470
  "metadata"?: mixed,
364
471
  "source": string,
365
472
  "source-layer"?: string,
473
+ "slot"?: string,
366
474
  "minzoom"?: number,
367
475
  "maxzoom"?: number,
368
476
  "filter"?: FilterSpecification,
369
477
  "layout"?: {|
370
- "visibility"?: "visible" | "none",
371
- "fill-extrusion-edge-radius"?: number
478
+ "visibility"?: ExpressionSpecification,
479
+ "fill-extrusion-edge-radius"?: ExpressionSpecification
372
480
  |},
373
481
  "paint"?: {|
374
482
  "fill-extrusion-opacity"?: PropertyValueSpecification<number>,
@@ -380,7 +488,17 @@ export type FillExtrusionLayerSpecification = {|
380
488
  "fill-extrusion-base"?: DataDrivenPropertyValueSpecification<number>,
381
489
  "fill-extrusion-vertical-gradient"?: PropertyValueSpecification<boolean>,
382
490
  "fill-extrusion-ambient-occlusion-intensity"?: PropertyValueSpecification<number>,
383
- "fill-extrusion-ambient-occlusion-radius"?: PropertyValueSpecification<number>
491
+ "fill-extrusion-ambient-occlusion-radius"?: PropertyValueSpecification<number>,
492
+ "fill-extrusion-ambient-occlusion-wall-radius"?: PropertyValueSpecification<number>,
493
+ "fill-extrusion-ambient-occlusion-ground-radius"?: PropertyValueSpecification<number>,
494
+ "fill-extrusion-ambient-occlusion-ground-attenuation"?: PropertyValueSpecification<number>,
495
+ "fill-extrusion-flood-light-color"?: PropertyValueSpecification<ColorSpecification>,
496
+ "fill-extrusion-flood-light-intensity"?: PropertyValueSpecification<number>,
497
+ "fill-extrusion-flood-light-wall-radius"?: DataDrivenPropertyValueSpecification<number>,
498
+ "fill-extrusion-flood-light-ground-radius"?: DataDrivenPropertyValueSpecification<number>,
499
+ "fill-extrusion-flood-light-ground-attenuation"?: PropertyValueSpecification<number>,
500
+ "fill-extrusion-vertical-scale"?: PropertyValueSpecification<number>,
501
+ "fill-extrusion-rounded-roof"?: PropertyValueSpecification<boolean>
384
502
  |}
385
503
  |}
386
504
 
@@ -390,14 +508,18 @@ export type RasterLayerSpecification = {|
390
508
  "metadata"?: mixed,
391
509
  "source": string,
392
510
  "source-layer"?: string,
511
+ "slot"?: string,
393
512
  "minzoom"?: number,
394
513
  "maxzoom"?: number,
395
514
  "filter"?: FilterSpecification,
396
515
  "layout"?: {|
397
- "visibility"?: "visible" | "none"
516
+ "visibility"?: ExpressionSpecification
398
517
  |},
399
518
  "paint"?: {|
400
519
  "raster-opacity"?: PropertyValueSpecification<number>,
520
+ "raster-color"?: ExpressionSpecification,
521
+ "raster-color-mix"?: PropertyValueSpecification<[number, number, number, number]>,
522
+ "raster-color-range"?: PropertyValueSpecification<[number, number]>,
401
523
  "raster-hue-rotate"?: PropertyValueSpecification<number>,
402
524
  "raster-brightness-min"?: PropertyValueSpecification<number>,
403
525
  "raster-brightness-max"?: PropertyValueSpecification<number>,
@@ -414,11 +536,12 @@ export type HillshadeLayerSpecification = {|
414
536
  "metadata"?: mixed,
415
537
  "source": string,
416
538
  "source-layer"?: string,
539
+ "slot"?: string,
417
540
  "minzoom"?: number,
418
541
  "maxzoom"?: number,
419
542
  "filter"?: FilterSpecification,
420
543
  "layout"?: {|
421
- "visibility"?: "visible" | "none"
544
+ "visibility"?: ExpressionSpecification
422
545
  |},
423
546
  "paint"?: {|
424
547
  "hillshade-illumination-direction"?: PropertyValueSpecification<number>,
@@ -430,19 +553,52 @@ export type HillshadeLayerSpecification = {|
430
553
  |}
431
554
  |}
432
555
 
556
+ export type ModelLayerSpecification = {|
557
+ "id": string,
558
+ "type": "model",
559
+ "metadata"?: mixed,
560
+ "source": string,
561
+ "source-layer"?: string,
562
+ "slot"?: string,
563
+ "minzoom"?: number,
564
+ "maxzoom"?: number,
565
+ "filter"?: FilterSpecification,
566
+ "layout"?: {|
567
+ "visibility"?: ExpressionSpecification,
568
+ "model-id"?: DataDrivenPropertyValueSpecification<string>
569
+ |},
570
+ "paint"?: {|
571
+ "model-opacity"?: PropertyValueSpecification<number>,
572
+ "model-rotation"?: DataDrivenPropertyValueSpecification<[number, number, number]>,
573
+ "model-scale"?: DataDrivenPropertyValueSpecification<[number, number, number]>,
574
+ "model-translation"?: DataDrivenPropertyValueSpecification<[number, number, number]>,
575
+ "model-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>,
576
+ "model-color-mix-intensity"?: DataDrivenPropertyValueSpecification<number>,
577
+ "model-type"?: "common-3d" | "location-indicator",
578
+ "model-cast-shadows"?: ExpressionSpecification,
579
+ "model-receive-shadows"?: ExpressionSpecification,
580
+ "model-ambient-occlusion-intensity"?: PropertyValueSpecification<number>,
581
+ "model-emissive-strength"?: DataDrivenPropertyValueSpecification<number>,
582
+ "model-roughness"?: DataDrivenPropertyValueSpecification<number>,
583
+ "model-height-based-emissive-strength-multiplier"?: DataDrivenPropertyValueSpecification<[number, number, number, number, number]>
584
+ |}
585
+ |}
586
+
433
587
  export type BackgroundLayerSpecification = {|
434
588
  "id": string,
435
589
  "type": "background",
436
590
  "metadata"?: mixed,
591
+ "slot"?: string,
437
592
  "minzoom"?: number,
438
593
  "maxzoom"?: number,
439
594
  "layout"?: {|
440
- "visibility"?: "visible" | "none"
595
+ "visibility"?: ExpressionSpecification
441
596
  |},
442
597
  "paint"?: {|
443
598
  "background-color"?: PropertyValueSpecification<ColorSpecification>,
444
599
  "background-pattern"?: PropertyValueSpecification<ResolvedImageSpecification>,
445
- "background-opacity"?: PropertyValueSpecification<number>
600
+ "background-opacity"?: PropertyValueSpecification<number>,
601
+ "background-emissive-strength"?: PropertyValueSpecification<number>
446
602
  |}
447
603
  |}
448
604
 
@@ -450,10 +606,11 @@ export type SkyLayerSpecification = {|
450
606
  "id": string,
451
607
  "type": "sky",
452
608
  "metadata"?: mixed,
609
+ "slot"?: string,
453
610
  "minzoom"?: number,
454
611
  "maxzoom"?: number,
455
612
  "layout"?: {|
456
- "visibility"?: "visible" | "none"
613
+ "visibility"?: ExpressionSpecification
457
614
  |},
458
615
  "paint"?: {|
459
616
  "sky-type"?: PropertyValueSpecification<"gradient" | "atmosphere">,
@@ -468,6 +625,13 @@ export type SkyLayerSpecification = {|
468
625
  |}
469
626
  |}
470
627
 
628
+ export type SlotLayerSpecification = {|
629
+ "id": string,
630
+ "type": "slot",
631
+ "metadata"?: mixed,
632
+ "slot"?: string
633
+ |}
634
+
471
635
  export type LayerSpecification =
472
636
  | FillLayerSpecification
473
637
  | LineLayerSpecification
@@ -477,6 +641,8 @@ export type LayerSpecification =
477
641
  | FillExtrusionLayerSpecification
478
642
  | RasterLayerSpecification
479
643
  | HillshadeLayerSpecification
644
+ | ModelLayerSpecification
480
645
  | BackgroundLayerSpecification
481
- | SkyLayerSpecification;
646
+ | SkyLayerSpecification
647
+ | SlotLayerSpecification;
482
648
 
package/util/color.js CHANGED
@@ -107,6 +107,21 @@ class Color {
107
107
  ];
108
108
  }
109
109
 
110
+ /**
111
+ * Returns an RGB array of values representing the color, unpremultiplied by A and multiplied by a scalar.
112
+ *
113
+ * @param {number} scale A scale to apply to the unpremultiplied-alpha values.
114
+ * @returns An array of RGB color values in the range [0, 1].
115
+ */
116
+ toArray01Scaled(scale: number): [number, number, number] {
117
+ const {r, g, b, a} = this;
118
+ return a === 0 ? [0, 0, 0] : [
119
+ (r / a) * scale,
120
+ (g / a) * scale,
121
+ (b / a) * scale
122
+ ];
123
+ }
124
+
110
125
  /**
111
126
  * Returns an RGBA array of values representing the color, premultiplied by A.
112
127
  *
@@ -121,6 +136,22 @@ class Color {
121
136
  a
122
137
  ];
123
138
  }
139
+
140
+ /**
141
+ * Returns an RGBA array of values representing the color, unpremultiplied by A, and converted to linear color space.
142
+ * The color is defined by sRGB primaries, but the sRGB transfer function is reversed to obtain linear energy.
143
+ *
144
+ * @returns An array of RGBA color values in the range [0, 1].
145
+ */
146
+ toArray01Linear(): [number, number, number, number] {
147
+ const {r, g, b, a} = this;
148
+ return a === 0 ? [0, 0, 0, 0] : [
149
+ Math.pow((r / a), 2.2),
150
+ Math.pow((g / a), 2.2),
151
+ Math.pow((b / a), 2.2),
152
+ a
153
+ ];
154
+ }
124
155
  }
125
156
 
126
157
  Color.black = new Color(0, 0, 0, 1);
@@ -0,0 +1,145 @@
1
+ // @flow
2
+ import type Point from '@mapbox/point-geometry';
3
+ import quickselect from 'quickselect';
4
+
5
+ type GeoJSONPosition = [number, number] | [number, number, number];
6
+
7
+ // minX, minY, maxX, maxY
8
+ export type BBox = [number, number, number, number];
9
+
10
+ /**
11
+ * Returns the signed area for the polygon ring. Postive areas are exterior rings and
12
+ * have a clockwise winding. Negative areas are interior rings and have a counter clockwise
13
+ * ordering.
14
+ */
15
+ function calculateSignedArea(ring: Array<Point>): number {
16
+ let sum = 0;
17
+ for (let i = 0, len = ring.length, j = len - 1, p1, p2; i < len; j = i++) {
18
+ p1 = ring[i];
19
+ p2 = ring[j];
20
+ sum += (p2.x - p1.x) * (p1.y + p2.y);
21
+ }
22
+ return sum;
23
+ }
24
+
25
+ function compareAreas(a: {area: number}, b: {area: number}) {
26
+ return b.area - a.area;
27
+ }
28
+
29
+ // classifies an array of rings into polygons with outer rings and holes
30
+ export function classifyRings(rings: Array<Array<Point>>, maxRings: number): Array<Array<Array<Point>>> {
31
+ const len = rings.length;
32
+
33
+ if (len <= 1) return [rings];
34
+
35
+ const polygons = [];
36
+ let polygon,
37
+ ccw;
38
+
39
+ for (let i = 0; i < len; i++) {
40
+ const area = calculateSignedArea(rings[i]);
41
+ if (area === 0) continue;
42
+
43
+ (rings[i]: any).area = Math.abs(area);
44
+
45
+ if (ccw === undefined) ccw = area < 0;
46
+
47
+ if (ccw === area < 0) {
48
+ if (polygon) polygons.push(polygon);
49
+ polygon = [rings[i]];
50
+
51
+ } else {
52
+ (polygon: any).push(rings[i]);
53
+ }
54
+ }
55
+ if (polygon) polygons.push(polygon);
56
+
57
+ // Earcut performance degrades with the # of rings in a polygon. For this
58
+ // reason, we limit strip out all but the `maxRings` largest rings.
59
+ if (maxRings > 1) {
60
+ for (let j = 0; j < polygons.length; j++) {
61
+ if (polygons[j].length <= maxRings) continue;
62
+ quickselect(polygons[j], maxRings, 1, polygons[j].length - 1, compareAreas);
63
+ polygons[j] = polygons[j].slice(0, maxRings);
64
+ }
65
+ }
66
+
67
+ return polygons;
68
+ }
69
+
70
+ export function updateBBox(bbox: BBox, coord: GeoJSONPosition) {
71
+ bbox[0] = Math.min(bbox[0], coord[0]);
72
+ bbox[1] = Math.min(bbox[1], coord[1]);
73
+ bbox[2] = Math.max(bbox[2], coord[0]);
74
+ bbox[3] = Math.max(bbox[3], coord[1]);
75
+ }
76
+
77
+ export function boxWithinBox(bbox1: BBox, bbox2: BBox): boolean {
78
+ if (bbox1[0] <= bbox2[0]) return false;
79
+ if (bbox1[2] >= bbox2[2]) return false;
80
+ if (bbox1[1] <= bbox2[1]) return false;
81
+ if (bbox1[3] >= bbox2[3]) return false;
82
+ return true;
83
+ }
84
+
85
+ function onBoundary(p: GeoJSONPosition, p1: GeoJSONPosition, p2: GeoJSONPosition) {
86
+ const x1 = p[0] - p1[0];
87
+ const y1 = p[1] - p1[1];
88
+ const x2 = p[0] - p2[0];
89
+ const y2 = p[1] - p2[1];
90
+ return (x1 * y2 - x2 * y1 === 0) && (x1 * x2 <= 0) && (y1 * y2 <= 0);
91
+ }
92
+
93
+ function rayIntersect(p: GeoJSONPosition, p1: GeoJSONPosition, p2: GeoJSONPosition) {
94
+ return ((p1[1] > p[1]) !== (p2[1] > p[1])) && (p[0] < (p2[0] - p1[0]) * (p[1] - p1[1]) / (p2[1] - p1[1]) + p1[0]);
95
+ }
96
+
97
+ // ray casting algorithm for detecting if point is in polygon
98
+ export function pointWithinPolygon(point: GeoJSONPosition, rings: Array<Array<GeoJSONPosition>>, trueOnBoundary: boolean = false): boolean {
99
+ let inside = false;
100
+ for (let i = 0, len = rings.length; i < len; i++) {
101
+ const ring = rings[i];
102
+ for (let j = 0, len2 = ring.length, k = len2 - 1; j < len2; k = j++) {
103
+ const q1 = ring[k];
104
+ const q2 = ring[j];
105
+ if (onBoundary(point, q1, q2)) return trueOnBoundary;
106
+ if (rayIntersect(point, q1, q2)) inside = !inside;
107
+ }
108
+ }
109
+ return inside;
110
+ }
111
+
112
+ function perp(v1: GeoJSONPosition, v2: GeoJSONPosition) {
113
+ return v1[0] * v2[1] - v1[1] * v2[0];
114
+ }
115
+
116
+ // check if p1 and p2 are in different sides of line segment q1->q2
117
+ function twoSided(p1: GeoJSONPosition, p2: GeoJSONPosition, q1: GeoJSONPosition, q2: GeoJSONPosition) {
118
+ // q1->p1 (x1, y1), q1->p2 (x2, y2), q1->q2 (x3, y3)
119
+ const x1 = p1[0] - q1[0];
120
+ const y1 = p1[1] - q1[1];
121
+ const x2 = p2[0] - q1[0];
122
+ const y2 = p2[1] - q1[1];
123
+ const x3 = q2[0] - q1[0];
124
+ const y3 = q2[1] - q1[1];
125
+ const det1 = x1 * y3 - x3 * y1;
126
+ const det2 = x2 * y3 - x3 * y2;
127
+ if ((det1 > 0 && det2 < 0) || (det1 < 0 && det2 > 0)) return true;
128
+ return false;
129
+ }
130
+ // a, b are end points for line segment1, c and d are end points for line segment2
131
+ export function segmentIntersectSegment(a: GeoJSONPosition, b: GeoJSONPosition, c: GeoJSONPosition, d: GeoJSONPosition): boolean {
132
+ // check if two segments are parallel or not
133
+ // precondition is end point a, b is inside polygon, if line a->b is
134
+ // parallel to polygon edge c->d, then a->b won't intersect with c->d
135
+ const vectorP = [b[0] - a[0], b[1] - a[1]];
136
+ const vectorQ = [d[0] - c[0], d[1] - c[1]];
137
+ if (perp(vectorQ, vectorP) === 0) return false;
138
+
139
+ // If lines are intersecting with each other, the relative location should be:
140
+ // a and b lie in different sides of segment c->d
141
+ // c and d lie in different sides of segment a->b
142
+ if (twoSided(a, b, c, d) && twoSided(c, d, a, b)) return true;
143
+ return false;
144
+ }
145
+