@mapwhit/tilerenderer 0.52.1 → 1.1.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.
Files changed (249) hide show
  1. package/README.md +7 -0
  2. package/build/min/package.json +2 -1
  3. package/build/min/src/shaders/_prelude.fragment.glsl.js +2 -2
  4. package/build/min/src/shaders/_prelude.vertex.glsl.js +2 -2
  5. package/build/min/src/shaders/background.fragment.glsl.js +2 -2
  6. package/build/min/src/shaders/background.vertex.glsl.js +1 -1
  7. package/build/min/src/shaders/background_pattern.fragment.glsl.js +2 -2
  8. package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -1
  9. package/build/min/src/shaders/circle.fragment.glsl.js +2 -2
  10. package/build/min/src/shaders/circle.vertex.glsl.js +2 -2
  11. package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -1
  12. package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -1
  13. package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -1
  14. package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -1
  15. package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -1
  16. package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -1
  17. package/build/min/src/shaders/debug.fragment.glsl.js +1 -1
  18. package/build/min/src/shaders/debug.vertex.glsl.js +1 -1
  19. package/build/min/src/shaders/fill.fragment.glsl.js +2 -2
  20. package/build/min/src/shaders/fill.vertex.glsl.js +2 -2
  21. package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +2 -2
  22. package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +2 -2
  23. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +2 -2
  24. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +2 -2
  25. package/build/min/src/shaders/fill_outline.fragment.glsl.js +2 -2
  26. package/build/min/src/shaders/fill_outline.vertex.glsl.js +2 -2
  27. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +2 -2
  28. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +2 -2
  29. package/build/min/src/shaders/fill_pattern.fragment.glsl.js +2 -2
  30. package/build/min/src/shaders/fill_pattern.vertex.glsl.js +2 -2
  31. package/build/min/src/shaders/heatmap.fragment.glsl.js +2 -2
  32. package/build/min/src/shaders/heatmap.vertex.glsl.js +2 -2
  33. package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +2 -2
  34. package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -1
  35. package/build/min/src/shaders/hillshade.fragment.glsl.js +2 -2
  36. package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -1
  37. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +2 -2
  38. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -1
  39. package/build/min/src/shaders/line.fragment.glsl.js +2 -2
  40. package/build/min/src/shaders/line.vertex.glsl.js +2 -2
  41. package/build/min/src/shaders/line_gradient.fragment.glsl.js +2 -2
  42. package/build/min/src/shaders/line_gradient.vertex.glsl.js +2 -2
  43. package/build/min/src/shaders/line_pattern.fragment.glsl.js +2 -2
  44. package/build/min/src/shaders/line_pattern.vertex.glsl.js +2 -2
  45. package/build/min/src/shaders/line_sdf.fragment.glsl.js +2 -2
  46. package/build/min/src/shaders/line_sdf.vertex.glsl.js +2 -2
  47. package/build/min/src/shaders/raster.fragment.glsl.js +2 -2
  48. package/build/min/src/shaders/raster.vertex.glsl.js +1 -1
  49. package/build/min/src/shaders/symbol_icon.fragment.glsl.js +2 -2
  50. package/build/min/src/shaders/symbol_icon.vertex.glsl.js +2 -2
  51. package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +2 -2
  52. package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +2 -2
  53. package/package.json +5 -4
  54. package/src/data/array_types.js +55 -117
  55. package/src/data/bucket/circle_attributes.js +2 -4
  56. package/src/data/bucket/circle_bucket.js +19 -16
  57. package/src/data/bucket/fill_attributes.js +2 -4
  58. package/src/data/bucket/fill_bucket.js +38 -27
  59. package/src/data/bucket/fill_extrusion_attributes.js +2 -4
  60. package/src/data/bucket/fill_extrusion_bucket.js +56 -37
  61. package/src/data/bucket/heatmap_bucket.js +2 -11
  62. package/src/data/bucket/line_attributes.js +2 -4
  63. package/src/data/bucket/line_bucket.js +208 -163
  64. package/src/data/bucket/pattern_attributes.js +2 -4
  65. package/src/data/bucket/pattern_bucket_features.js +7 -9
  66. package/src/data/bucket/symbol_attributes.js +12 -26
  67. package/src/data/bucket/symbol_bucket.js +174 -323
  68. package/src/data/bucket/symbol_buffers.js +62 -0
  69. package/src/data/bucket/symbol_collision_buffers.js +33 -0
  70. package/src/data/bucket.js +26 -25
  71. package/src/data/dem_data.js +11 -10
  72. package/src/data/extent.js +1 -1
  73. package/src/data/feature_index.js +38 -28
  74. package/src/data/index_array_type.js +1 -6
  75. package/src/data/load_geometry.js +6 -9
  76. package/src/data/pos_attributes.js +2 -3
  77. package/src/data/program_configuration.js +47 -38
  78. package/src/data/raster_bounds_attributes.js +2 -2
  79. package/src/data/segment.js +4 -7
  80. package/src/geo/coordinate.js +1 -1
  81. package/src/geo/lng_lat.js +3 -3
  82. package/src/geo/lng_lat_bounds.js +8 -4
  83. package/src/geo/transform.js +69 -30
  84. package/src/gl/color_mode.js +2 -2
  85. package/src/gl/context.js +28 -29
  86. package/src/gl/cull_face_mode.js +1 -1
  87. package/src/gl/depth_mode.js +1 -1
  88. package/src/gl/framebuffer.js +8 -4
  89. package/src/gl/index_buffer.js +2 -2
  90. package/src/gl/stencil_mode.js +1 -1
  91. package/src/gl/value.js +33 -68
  92. package/src/gl/vertex_buffer.js +2 -2
  93. package/src/index.js +49 -25
  94. package/src/render/draw_background.js +17 -12
  95. package/src/render/draw_circle.js +15 -12
  96. package/src/render/draw_collision_debug.js +11 -8
  97. package/src/render/draw_debug.js +16 -14
  98. package/src/render/draw_fill.js +27 -20
  99. package/src/render/draw_fill_extrusion.js +20 -17
  100. package/src/render/draw_heatmap.js +21 -16
  101. package/src/render/draw_hillshade.js +12 -9
  102. package/src/render/draw_line.js +36 -22
  103. package/src/render/draw_raster.js +22 -18
  104. package/src/render/draw_symbol.js +38 -33
  105. package/src/render/glyph_atlas.js +9 -8
  106. package/src/render/glyph_manager.js +2 -3
  107. package/src/render/image_atlas.js +4 -11
  108. package/src/render/image_manager.js +39 -28
  109. package/src/render/line_atlas.js +2 -2
  110. package/src/render/painter.js +78 -61
  111. package/src/render/program/background_program.js +6 -13
  112. package/src/render/program/circle_program.js +8 -10
  113. package/src/render/program/clipping_mask_program.js +3 -5
  114. package/src/render/program/collision_program.js +4 -6
  115. package/src/render/program/debug_program.js +3 -5
  116. package/src/render/program/fill_extrusion_program.js +9 -15
  117. package/src/render/program/fill_program.js +10 -21
  118. package/src/render/program/heatmap_program.js +9 -15
  119. package/src/render/program/hillshade_program.js +16 -22
  120. package/src/render/program/line_program.js +14 -25
  121. package/src/render/program/pattern.js +5 -7
  122. package/src/render/program/program_uniforms.js +13 -20
  123. package/src/render/program/raster_program.js +9 -11
  124. package/src/render/program/symbol_program.js +5 -7
  125. package/src/render/program.js +5 -6
  126. package/src/render/texture.js +1 -1
  127. package/src/render/tile_mask.js +6 -4
  128. package/src/render/uniform_binding.js +9 -20
  129. package/src/render/vertex_array_object.js +5 -3
  130. package/src/shaders/encode_attribute.js +2 -6
  131. package/src/shaders/index.js +103 -51
  132. package/src/source/geojson_source.js +25 -30
  133. package/src/source/geojson_worker_source.js +46 -74
  134. package/src/source/geojson_wrapper.js +13 -5
  135. package/src/source/image_source.js +17 -28
  136. package/src/source/load_tilejson.js +3 -3
  137. package/src/source/pixels_to_tile_units.js +3 -3
  138. package/src/source/query_features.js +17 -15
  139. package/src/source/raster_dem_tile_source.js +54 -71
  140. package/src/source/raster_tile_source.js +14 -15
  141. package/src/source/resources/glyphs.js +4 -5
  142. package/src/source/resources/index.js +4 -12
  143. package/src/source/rtl_text_plugin.js +62 -35
  144. package/src/source/source.js +14 -22
  145. package/src/source/source_cache.js +221 -179
  146. package/src/source/source_state.js +125 -13
  147. package/src/source/tile.js +67 -66
  148. package/src/source/tile_bounds.js +36 -29
  149. package/src/source/tile_cache.js +2 -2
  150. package/src/source/tile_id.js +30 -26
  151. package/src/source/vector_tile_source.js +23 -21
  152. package/src/source/vector_tile_worker_source.js +22 -26
  153. package/src/source/worker_tile.js +139 -134
  154. package/src/style/create_style_layer.js +11 -11
  155. package/src/style/evaluation_parameters.js +4 -6
  156. package/src/style/light.js +5 -5
  157. package/src/style/load_sprite.js +6 -6
  158. package/src/style/parse_glyph_pbf.js +21 -17
  159. package/src/style/pauseable_placement.js +7 -9
  160. package/src/style/properties.js +21 -51
  161. package/src/style/query_utils.js +7 -13
  162. package/src/style/style.js +314 -221
  163. package/src/style/style_layer/background_style_layer.js +3 -4
  164. package/src/style/style_layer/background_style_layer_properties.js +2 -2
  165. package/src/style/style_layer/circle_style_layer.js +25 -20
  166. package/src/style/style_layer/circle_style_layer_properties.js +2 -2
  167. package/src/style/style_layer/fill_extrusion_style_layer.js +55 -37
  168. package/src/style/style_layer/fill_extrusion_style_layer_properties.js +2 -2
  169. package/src/style/style_layer/fill_style_layer.js +11 -12
  170. package/src/style/style_layer/fill_style_layer_properties.js +2 -2
  171. package/src/style/style_layer/heatmap_style_layer.js +6 -7
  172. package/src/style/style_layer/heatmap_style_layer_properties.js +2 -2
  173. package/src/style/style_layer/hillshade_style_layer.js +4 -5
  174. package/src/style/style_layer/hillshade_style_layer_properties.js +2 -2
  175. package/src/style/style_layer/line_style_layer.js +33 -30
  176. package/src/style/style_layer/line_style_layer_properties.js +5 -5
  177. package/src/style/style_layer/raster_style_layer.js +3 -4
  178. package/src/style/style_layer/raster_style_layer_properties.js +2 -2
  179. package/src/style/style_layer/symbol_style_layer.js +20 -21
  180. package/src/style/style_layer/symbol_style_layer_properties.js +2 -2
  181. package/src/style/style_layer.js +66 -47
  182. package/src/style/style_layer_index.js +17 -42
  183. package/src/style/zoom_history.js +1 -1
  184. package/src/style-spec/error/parsing_error.js +1 -1
  185. package/src/style-spec/error/validation_error.js +5 -3
  186. package/src/style-spec/feature_filter/convert.js +17 -9
  187. package/src/style-spec/feature_filter/index.js +13 -9
  188. package/src/style-spec/util/eval_support.js +2 -2
  189. package/src/style-spec/util/ref_properties.js +1 -1
  190. package/src/symbol/anchor.js +2 -6
  191. package/src/symbol/check_max_angle.js +13 -5
  192. package/src/symbol/clip_line.js +2 -3
  193. package/src/symbol/collision_feature.js +8 -4
  194. package/src/symbol/collision_index.js +5 -7
  195. package/src/symbol/cross_tile_symbol_index.js +7 -10
  196. package/src/symbol/get_anchors.js +15 -8
  197. package/src/symbol/grid_index.js +5 -3
  198. package/src/symbol/mergelines.js +2 -2
  199. package/src/symbol/opacity_state.js +1 -5
  200. package/src/symbol/placement.js +28 -23
  201. package/src/symbol/projection.js +29 -28
  202. package/src/symbol/quads.js +14 -16
  203. package/src/symbol/shaping.js +27 -19
  204. package/src/symbol/symbol_layout.js +24 -28
  205. package/src/symbol/symbol_size.js +13 -12
  206. package/src/symbol/transform_text.js +4 -4
  207. package/src/ui/camera.js +34 -18
  208. package/src/ui/map.js +102 -44
  209. package/src/util/async.js +11 -5
  210. package/src/util/browser.js +1 -1
  211. package/src/util/callback.js +3 -9
  212. package/src/util/classify_rings.js +13 -8
  213. package/src/util/color_ramp.js +3 -3
  214. package/src/util/config.js +4 -4
  215. package/src/util/dictionary_coder.js +2 -3
  216. package/src/util/dom.js +7 -3
  217. package/src/util/find_pole_of_inaccessibility.js +29 -14
  218. package/src/util/group_layers.js +41 -0
  219. package/src/util/image.js +3 -13
  220. package/src/util/interpolate.js +1 -1
  221. package/src/util/intersection_tests.js +80 -42
  222. package/src/util/is_char_in_unicode_block.js +1 -1
  223. package/src/util/key.js +25 -0
  224. package/src/util/loader/image.js +1 -1
  225. package/src/util/object.js +33 -76
  226. package/src/util/script_detection.js +212 -91
  227. package/src/util/struct_array.js +8 -40
  228. package/src/util/task_queue.js +11 -7
  229. package/src/util/throttle.js +2 -2
  230. package/src/util/tile_cover.js +8 -5
  231. package/src/util/token.js +1 -1
  232. package/src/util/unique_id.js +2 -2
  233. package/src/util/util.js +21 -29
  234. package/src/util/vectortile_to_geojson.js +4 -2
  235. package/src/util/verticalize_punctuation.js +3 -7
  236. package/src/util/warn.js +4 -4
  237. package/src/util/web_worker.js +3 -3
  238. package/src/worker.js +1 -4
  239. package/src/source/resources/images.js +0 -68
  240. package/src/source/worker.js +0 -110
  241. package/src/source/worker_source.js +0 -14
  242. package/src/style-spec/deref.js +0 -51
  243. package/src/style-spec/group_by_layout.js +0 -46
  244. package/src/util/actor.js +0 -108
  245. package/src/util/dispatcher.js +0 -65
  246. package/src/util/global_worker_pool.js +0 -15
  247. package/src/util/transfer_registry.js +0 -168
  248. package/src/util/web_worker_transfer.js +0 -43
  249. package/src/util/worker_pool.js +0 -41
@@ -1,14 +1,11 @@
1
- const { normalizePropertyExpression } = require('@mapwhit/style-expressions');
2
-
3
- const interpolate = require('../util/interpolate');
4
- const { clamp } = require('../util/util');
5
- const EvaluationParameters = require('../style/evaluation_parameters');
6
-
7
- module.exports = { getSizeData, evaluateSizeForFeature, evaluateSizeForZoom };
1
+ import { normalizePropertyExpression } from '@mapwhit/style-expressions';
2
+ import EvaluationParameters from '../style/evaluation_parameters.js';
3
+ import interpolate from '../util/interpolate.js';
4
+ import { clamp } from '../util/util.js';
8
5
 
9
6
  // For {text,icon}-size, get the bucket-level data that will be needed by
10
7
  // the painter to set symbol-size-related uniforms
11
- function getSizeData(tileZoom, value) {
8
+ export function getSizeData(tileZoom, value) {
12
9
  const { expression } = value;
13
10
  if (expression.kind === 'constant') {
14
11
  return {
@@ -25,10 +22,14 @@ function getSizeData(tileZoom, value) {
25
22
  const levels = expression.zoomStops;
26
23
 
27
24
  let lower = 0;
28
- while (lower < levels.length && levels[lower] <= tileZoom) lower++;
25
+ while (lower < levels.length && levels[lower] <= tileZoom) {
26
+ lower++;
27
+ }
29
28
  lower = Math.max(0, lower - 1);
30
29
  let upper = lower;
31
- while (upper < levels.length && levels[upper] < tileZoom + 1) upper++;
30
+ while (upper < levels.length && levels[upper] < tileZoom + 1) {
31
+ upper++;
32
+ }
32
33
  upper = Math.min(levels.length - 1, upper);
33
34
 
34
35
  const zoomRange = {
@@ -60,7 +61,7 @@ function getSizeData(tileZoom, value) {
60
61
  };
61
62
  }
62
63
 
63
- function evaluateSizeForFeature(sizeData, partiallyEvaluatedSize, symbol) {
64
+ export function evaluateSizeForFeature(sizeData, partiallyEvaluatedSize, symbol) {
64
65
  const part = partiallyEvaluatedSize;
65
66
  if (sizeData.functionType === 'source') {
66
67
  return symbol.lowerSize / 10;
@@ -71,7 +72,7 @@ function evaluateSizeForFeature(sizeData, partiallyEvaluatedSize, symbol) {
71
72
  return part.uSize;
72
73
  }
73
74
 
74
- function evaluateSizeForZoom(sizeData, currentZoom, property) {
75
+ export function evaluateSizeForZoom(sizeData, currentZoom, property) {
75
76
  if (sizeData.functionType === 'constant') {
76
77
  return {
77
78
  uSizeT: 0,
@@ -1,7 +1,7 @@
1
- const { plugin: rtlTextPlugin } = require('../source/rtl_text_plugin');
1
+ import { plugin as rtlTextPlugin } from '../source/rtl_text_plugin.js';
2
2
 
3
3
  function transformText(text, layer, feature) {
4
- const transform = layer.layout.get('text-transform').evaluate(feature, {});
4
+ const transform = layer._layout.get('text-transform').evaluate(feature, {});
5
5
  if (transform === 'uppercase') {
6
6
  text = text.toLocaleUpperCase();
7
7
  } else if (transform === 'lowercase') {
@@ -15,9 +15,9 @@ function transformText(text, layer, feature) {
15
15
  return text;
16
16
  }
17
17
 
18
- module.exports = function (text, layer, feature) {
18
+ export default function (text, layer, feature) {
19
19
  text.sections.forEach(section => {
20
20
  section.text = transformText(section.text, layer, feature);
21
21
  });
22
22
  return text;
23
- };
23
+ }
package/src/ui/camera.js CHANGED
@@ -1,12 +1,12 @@
1
- const { deepEqual } = require('../util/object');
2
- const { clamp, wrap, ease: defaultEasing } = require('../util/util');
3
- const warn = require('../util/warn');
4
- const interpolate = require('../util/interpolate');
5
- const browser = require('../util/browser');
6
- const LngLat = require('../geo/lng_lat');
7
- const LngLatBounds = require('../geo/lng_lat_bounds');
8
- const { default: Point } = require('@mapbox/point-geometry');
9
- const { Event, Evented } = require('@mapwhit/events');
1
+ import Point from '@mapbox/point-geometry';
2
+ import { Event, Evented } from '@mapwhit/events';
3
+ import LngLat from '../geo/lng_lat.js';
4
+ import LngLatBounds from '../geo/lng_lat_bounds.js';
5
+ import browser from '../util/browser.js';
6
+ import interpolate from '../util/interpolate.js';
7
+ import { deepEqual } from '../util/object.js';
8
+ import { clamp, ease as defaultEasing, wrap } from '../util/util.js';
9
+ import warn from '../util/warn.js';
10
10
 
11
11
  /**
12
12
  * Options common to {@link Map#jumpTo}, {@link Map#easeTo}, and {@link Map#flyTo}, controlling the desired location,
@@ -354,8 +354,12 @@ class Camera extends Evented {
354
354
  if (
355
355
  !deepEqual(
356
356
  Object.keys(options.padding).sort((a, b) => {
357
- if (a < b) return -1;
358
- if (a > b) return 1;
357
+ if (a < b) {
358
+ return -1;
359
+ }
360
+ if (a > b) {
361
+ return 1;
362
+ }
359
363
  return 0;
360
364
  }),
361
365
  ['bottom', 'left', 'right', 'top']
@@ -429,7 +433,9 @@ class Camera extends Evented {
429
433
  const calculatedOptions = this.cameraForBounds(bounds, options);
430
434
 
431
435
  // cameraForBounds warns + returns undefined if unable to fit:
432
- if (!calculatedOptions) return this;
436
+ if (!calculatedOptions) {
437
+ return this;
438
+ }
433
439
 
434
440
  options = Object.assign(calculatedOptions, options);
435
441
 
@@ -542,7 +548,9 @@ class Camera extends Evented {
542
548
  ...options
543
549
  };
544
550
 
545
- if (options.animate === false) options.duration = 0;
551
+ if (options.animate === false) {
552
+ options.duration = 0;
553
+ }
546
554
 
547
555
  const tr = this.transform;
548
556
  const startZoom = this.getZoom();
@@ -820,7 +828,9 @@ class Camera extends Evented {
820
828
  // When u₀ = u₁, the optimal path doesn’t require both ascent and descent.
821
829
  if (Math.abs(u1) < 0.000001 || !Number.isFinite(S)) {
822
830
  // Perform a more or less instantaneous transition if the path is too short.
823
- if (Math.abs(w0 - w1) < 0.000001) return this.easeTo(options, eventData);
831
+ if (Math.abs(w0 - w1) < 0.000001) {
832
+ return this.easeTo(options, eventData);
833
+ }
824
834
 
825
835
  const k = w1 < w0 ? -1 : 1;
826
836
  S = Math.abs(Math.log(w1 / w0)) / rho;
@@ -932,8 +942,12 @@ class Camera extends Evented {
932
942
  _normalizeBearing(bearing, currentBearing) {
933
943
  bearing = wrap(bearing, -180, 180);
934
944
  const diff = Math.abs(bearing - currentBearing);
935
- if (Math.abs(bearing - 360 - currentBearing) < diff) bearing -= 360;
936
- if (Math.abs(bearing + 360 - currentBearing) < diff) bearing += 360;
945
+ if (Math.abs(bearing - 360 - currentBearing) < diff) {
946
+ bearing -= 360;
947
+ }
948
+ if (Math.abs(bearing + 360 - currentBearing) < diff) {
949
+ bearing += 360;
950
+ }
937
951
  return bearing;
938
952
  }
939
953
 
@@ -941,11 +955,13 @@ class Camera extends Evented {
941
955
  // interpolating between the two endpoints will cross it.
942
956
  _normalizeCenter(center) {
943
957
  const tr = this.transform;
944
- if (!tr.renderWorldCopies || tr.lngRange) return;
958
+ if (!tr.renderWorldCopies || tr.lngRange) {
959
+ return;
960
+ }
945
961
 
946
962
  const delta = center.lng - tr.center.lng;
947
963
  center.lng += delta > 180 ? -360 : delta < -180 ? 360 : 0;
948
964
  }
949
965
  }
950
966
 
951
- module.exports = Camera;
967
+ export default Camera;
package/src/ui/map.js CHANGED
@@ -1,21 +1,19 @@
1
- const { bindAll } = require('../util/object');
2
- const warn = require('../util/warn');
3
-
4
- const browser = require('../util/browser');
5
- const DOM = require('../util/dom');
6
- const loadImage = require('../util/loader/image');
7
-
8
- const Style = require('../style/style');
9
- const EvaluationParameters = require('../style/evaluation_parameters');
10
- const Painter = require('../render/painter');
11
- const Transform = require('../geo/transform');
12
- const Camera = require('./camera');
13
- const LngLat = require('../geo/lng_lat');
14
- const LngLatBounds = require('../geo/lng_lat_bounds');
15
- const { default: Point } = require('@mapbox/point-geometry');
16
- const { RGBAImage } = require('../util/image');
17
- const { Event, ErrorEvent } = require('@mapwhit/events');
18
- const taskQueue = require('../util/task_queue');
1
+ import Point from '@mapbox/point-geometry';
2
+ import { ErrorEvent, Event } from '@mapwhit/events';
3
+ import LngLat from '../geo/lng_lat.js';
4
+ import LngLatBounds from '../geo/lng_lat_bounds.js';
5
+ import Transform from '../geo/transform.js';
6
+ import Painter from '../render/painter.js';
7
+ import EvaluationParameters from '../style/evaluation_parameters.js';
8
+ import Style from '../style/style.js';
9
+ import browser from '../util/browser.js';
10
+ import DOM from '../util/dom.js';
11
+ import { RGBAImage } from '../util/image.js';
12
+ import loadImage from '../util/loader/image.js';
13
+ import { bindAll } from '../util/object.js';
14
+ import taskQueue from '../util/task_queue.js';
15
+ import warn from '../util/warn.js';
16
+ import Camera from './camera.js';
19
17
 
20
18
  const defaultMinZoom = 0;
21
19
  const defaultMaxZoom = 22;
@@ -41,10 +39,6 @@ const defaultOptions = {
41
39
 
42
40
  renderWorldCopies: true,
43
41
 
44
- refreshExpiredTiles: true,
45
-
46
- maxTileCacheSize: null,
47
-
48
42
  transformRequest: null,
49
43
  fadeDuration: 300,
50
44
  crossSourceCollisions: true
@@ -98,7 +92,6 @@ const defaultOptions = {
98
92
  * @param {number} [options.bearing=0] The initial bearing (rotation) of the map, measured in degrees counter-clockwise from north. If `bearing` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
99
93
  * @param {number} [options.pitch=0] The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-60). If `pitch` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
100
94
  * @param {boolean} [options.renderWorldCopies=true] If `true`, multiple copies of the world will be rendered, when zoomed out.
101
- * @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport.
102
95
  * @param {number} [options.fadeDuration=300] Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading.
103
96
  * @param {boolean} [options.crossSourceCollisions=true] If `true`, symbols from multiple sources can collide with each other during collision detection. If `false`, collision detection is run separately for the symbols in each source.
104
97
  * @example
@@ -125,7 +118,6 @@ class Map extends Camera {
125
118
  this.loadImage = loadImage;
126
119
 
127
120
  this._interactive = options.interactive;
128
- this._maxTileCacheSize = options.maxTileCacheSize;
129
121
  this._failIfMajorPerformanceCaveat = options.failIfMajorPerformanceCaveat;
130
122
  this._preserveDrawingBuffer = options.preserveDrawingBuffer;
131
123
  this._trackResize = options.trackResize;
@@ -189,7 +181,9 @@ class Map extends Camera {
189
181
 
190
182
  this.resize();
191
183
 
192
- if (options.style) this.setStyle(options.style);
184
+ if (options.style) {
185
+ this.setStyle(options.style);
186
+ }
193
187
 
194
188
  this.on('style.load', function () {
195
189
  if (this.transform.unmodified) {
@@ -365,7 +359,9 @@ class Map extends Camera {
365
359
  this.transform.minZoom = minZoom;
366
360
  this._update();
367
361
 
368
- if (this.getZoom() < minZoom) this.setZoom(minZoom);
362
+ if (this.getZoom() < minZoom) {
363
+ this.setZoom(minZoom);
364
+ }
369
365
 
370
366
  return this;
371
367
  }
@@ -397,7 +393,9 @@ class Map extends Camera {
397
393
  this.transform.maxZoom = maxZoom;
398
394
  this._update();
399
395
 
400
- if (this.getZoom() > maxZoom) this.setZoom(maxZoom);
396
+ if (this.getZoom() > maxZoom) {
397
+ this.setZoom(maxZoom);
398
+ }
401
399
 
402
400
  return this;
403
401
  }
@@ -560,8 +558,6 @@ class Map extends Camera {
560
558
  // queryRenderedFeatures(geometry: PointLike | [PointLike, PointLike], options?: Object)
561
559
  // queryRenderedFeatures(options?: Object)
562
560
  //
563
- // There no way to express that in a way that's compatible with both flow and documentation.js.
564
- // Related: https://github.com/facebook/flow/issues/1556
565
561
  if (arguments.length === 2) {
566
562
  geometry = arguments[0];
567
563
  options = arguments[1];
@@ -687,7 +683,7 @@ class Map extends Camera {
687
683
  */
688
684
  getStyle() {
689
685
  if (this.style) {
690
- return this.style.serialize();
686
+ return this.style.serialize?.() ?? this.style;
691
687
  }
692
688
  }
693
689
 
@@ -697,7 +693,9 @@ class Map extends Camera {
697
693
  * @returns {boolean} A Boolean indicating whether the style is fully loaded.
698
694
  */
699
695
  isStyleLoaded() {
700
- if (!this.style) return warn.once('There is no style added to the map.');
696
+ if (!this.style) {
697
+ return warn.once('There is no style added to the map.');
698
+ }
701
699
  return this.style.loaded();
702
700
  }
703
701
 
@@ -727,7 +725,7 @@ class Map extends Camera {
727
725
  * @returns {boolean} A Boolean indicating whether the source is loaded.
728
726
  */
729
727
  isSourceLoaded(id) {
730
- const source = this.style?.sourceCaches[id];
728
+ const source = this.style?._sources[id];
731
729
  if (source === undefined) {
732
730
  this.fire(new ErrorEvent(new Error(`There is no source with ID '${id}'`)));
733
731
  return;
@@ -743,13 +741,14 @@ class Map extends Camera {
743
741
  */
744
742
 
745
743
  areTilesLoaded() {
746
- const sources = this.style?.sourceCaches;
744
+ const sources = this.style?._sources;
747
745
  for (const id in sources) {
748
746
  const source = sources[id];
749
747
  const tiles = source._tiles;
750
- for (const t in tiles) {
751
- const tile = tiles[t];
752
- if (!(tile.state === 'loaded' || tile.state === 'errored')) return false;
748
+ for (const tile of tiles.values()) {
749
+ if (!(tile.state === 'loaded' || tile.state === 'errored')) {
750
+ return false;
751
+ }
753
752
  }
754
753
  }
755
754
  return true;
@@ -798,6 +797,16 @@ class Map extends Camera {
798
797
  */
799
798
  addImage(id, image, { pixelRatio = 1, sdf = false } = {}) {
800
799
  if (image instanceof HTMLImageElement) {
800
+ if (!image.complete) {
801
+ const promise = new Promise(resolve => {
802
+ image.decode().then(() => {
803
+ const { width, height, data } = browser.getImageData(image);
804
+ resolve({ data: new RGBAImage({ width, height }, data), pixelRatio, sdf });
805
+ });
806
+ });
807
+ this.style.addImage(id, { promise });
808
+ return;
809
+ }
801
810
  const { width, height, data } = browser.getImageData(image);
802
811
  this.style.addImage(id, { data: new RGBAImage({ width, height }, data), pixelRatio, sdf });
803
812
  } else if (image.width === undefined || image.height === undefined) {
@@ -819,6 +828,23 @@ class Map extends Camera {
819
828
  }
820
829
  }
821
830
 
831
+ /**
832
+ * Returns an image, specified by ID, currently available in the map.
833
+ * This includes both images from the style's original sprite
834
+ * and any images that have been added at runtime using {@link Map.addImage}.
835
+ *
836
+ * @param id - The ID of the image.
837
+ * @returns An image in the map with the specified ID.
838
+ *
839
+ * @example
840
+ * ```js
841
+ * let coffeeShopIcon = map.getImage("coffee_cup");
842
+ * ```
843
+ */
844
+ getImage(id) {
845
+ return this.style.getImage(id);
846
+ }
847
+
822
848
  /**
823
849
  * Define wether the image has been added or not
824
850
  *
@@ -1054,6 +1080,24 @@ class Map extends Camera {
1054
1080
  this._update();
1055
1081
  }
1056
1082
 
1083
+ /**
1084
+ * Removes feature state, setting it back to the default behavior. If only
1085
+ * source is specified, removes all states of that source. If
1086
+ * target.id is also specified, removes all keys for that feature's state.
1087
+ * If key is also specified, removes that key from that feature's state.
1088
+ *
1089
+ * @param {Object} target Identifier of where to set state: can be a source, a feature, or a specific key of feature.
1090
+ * Feature objects returned from {@link Map#queryRenderedFeatures} or event handlers can be used as feature identifiers.
1091
+ * @param {string | number} target.id (optional) Unique id of the feature. Optional if key is not specified.
1092
+ * @param {string} target.source The Id of the vector source or GeoJSON source for the feature.
1093
+ * @param {string} [target.sourceLayer] (optional) *For vector tile sources, the sourceLayer is
1094
+ * required.*
1095
+ * @param {string} key (optional) The key in the feature state to reset.
1096
+ */
1097
+ removeFeatureState(target, key) {
1098
+ this.style.removeFeatureState(target, key);
1099
+ return this._update();
1100
+ }
1057
1101
  /**
1058
1102
  * Gets the state of a feature.
1059
1103
  *
@@ -1204,8 +1248,12 @@ class Map extends Camera {
1204
1248
  * @returns {boolean} A Boolean indicating whether the map is fully loaded.
1205
1249
  */
1206
1250
  loaded() {
1207
- if (this._styleDirty || this._sourcesDirty) return false;
1208
- if (!this.style || !this.style.loaded()) return false;
1251
+ if (this._styleDirty || this._sourcesDirty) {
1252
+ return false;
1253
+ }
1254
+ if (!this.style || !this.style.loaded()) {
1255
+ return false;
1256
+ }
1209
1257
  return true;
1210
1258
  }
1211
1259
 
@@ -1218,7 +1266,9 @@ class Map extends Camera {
1218
1266
  * @private
1219
1267
  */
1220
1268
  _update(updateStyle) {
1221
- if (!this.style) return;
1269
+ if (!this.style) {
1270
+ return;
1271
+ }
1222
1272
 
1223
1273
  this._styleDirty = this._styleDirty || updateStyle;
1224
1274
  this._sourcesDirty = true;
@@ -1357,7 +1407,9 @@ class Map extends Camera {
1357
1407
  window.removeEventListener('online', this._onWindowOnline, false);
1358
1408
  }
1359
1409
  const extension = this.painter.context.gl.getExtension('WEBGL_lose_context');
1360
- if (extension) extension.loseContext();
1410
+ if (extension) {
1411
+ extension.loseContext();
1412
+ }
1361
1413
  removeNode(this._canvasContainer);
1362
1414
  removeNode(this._controlContainer);
1363
1415
  this._container.classList.remove('mapboxgl-map');
@@ -1396,7 +1448,9 @@ class Map extends Camera {
1396
1448
  return !!this._showTileBoundaries;
1397
1449
  }
1398
1450
  set showTileBoundaries(value) {
1399
- if (this._showTileBoundaries === value) return;
1451
+ if (this._showTileBoundaries === value) {
1452
+ return;
1453
+ }
1400
1454
  this._showTileBoundaries = value;
1401
1455
  this._update();
1402
1456
  }
@@ -1416,7 +1470,9 @@ class Map extends Camera {
1416
1470
  return !!this._showCollisionBoxes;
1417
1471
  }
1418
1472
  set showCollisionBoxes(value) {
1419
- if (this._showCollisionBoxes === value) return;
1473
+ if (this._showCollisionBoxes === value) {
1474
+ return;
1475
+ }
1420
1476
  this._showCollisionBoxes = value;
1421
1477
  if (value) {
1422
1478
  // When we turn collision boxes on we have to generate them for existing tiles
@@ -1444,7 +1500,9 @@ class Map extends Camera {
1444
1500
  return !!this._showOverdrawInspector;
1445
1501
  }
1446
1502
  set showOverdrawInspector(value) {
1447
- if (this._showOverdrawInspector === value) return;
1503
+ if (this._showOverdrawInspector === value) {
1504
+ return;
1505
+ }
1448
1506
  this._showOverdrawInspector = value;
1449
1507
  this._update();
1450
1508
  }
@@ -1485,7 +1543,7 @@ class Map extends Camera {
1485
1543
  }
1486
1544
  }
1487
1545
 
1488
- module.exports = Map;
1546
+ export default Map;
1489
1547
 
1490
1548
  function removeNode(node) {
1491
1549
  if (node.parentNode) {
package/src/util/async.js CHANGED
@@ -8,16 +8,22 @@
8
8
  * called with an array, containing the results of each async call.
9
9
  * @private
10
10
  */
11
- exports.all = function (array, fn, callback) {
12
- if (!array.length) return callback(null, []);
11
+ export function all(array, fn, callback) {
12
+ if (!array.length) {
13
+ return callback(null, []);
14
+ }
13
15
  let remaining = array.length;
14
16
  const results = new Array(array.length);
15
17
  let error = null;
16
18
  array.forEach((item, i) => {
17
19
  fn(item, (err, result) => {
18
- if (err) error = err;
20
+ if (err) {
21
+ error = err;
22
+ }
19
23
  results[i] = result;
20
- if (--remaining === 0) callback(error, results);
24
+ if (--remaining === 0) {
25
+ callback(error, results);
26
+ }
21
27
  });
22
28
  });
23
- };
29
+ }
@@ -49,4 +49,4 @@ const exported = {
49
49
  }
50
50
  };
51
51
 
52
- module.exports = exported;
52
+ export default exported;
@@ -1,24 +1,18 @@
1
- module.exports = {
2
- callback,
3
- callbackWithSpread,
4
- callbackWithNoResult
5
- };
6
-
7
- function callback(fn, promise) {
1
+ export function callback(fn, promise) {
8
2
  if (fn) {
9
3
  promise.then(result => fn(null, result), fn);
10
4
  }
11
5
  return promise;
12
6
  }
13
7
 
14
- function callbackWithSpread(fn, promise) {
8
+ export function callbackWithSpread(fn, promise) {
15
9
  if (fn) {
16
10
  promise.then(result => fn(null, ...result), fn);
17
11
  }
18
12
  return promise;
19
13
  }
20
14
 
21
- function callbackWithNoResult(fn, promise) {
15
+ export function callbackWithNoResult(fn, promise) {
22
16
  if (fn) {
23
17
  promise.then(() => fn(null), fn);
24
18
  }
@@ -1,10 +1,11 @@
1
- const { default: quickselect } = require('quickselect');
2
-
3
- const { calculateSignedArea } = require('./util');
1
+ import quickselect from 'quickselect';
2
+ import { calculateSignedArea } from './util.js';
4
3
 
5
4
  // classifies an array of rings into polygons with outer rings and holes
6
- module.exports = function classifyRings(rings, maxRings) {
7
- if (rings.length <= 1) return [rings];
5
+ export default function classifyRings(rings, maxRings) {
6
+ if (rings.length <= 1) {
7
+ return [rings];
8
+ }
8
9
 
9
10
  const polygons = [];
10
11
  let polygon;
@@ -12,11 +13,15 @@ module.exports = function classifyRings(rings, maxRings) {
12
13
 
13
14
  for (const ring of rings) {
14
15
  const area = calculateSignedArea(ring);
15
- if (area === 0) continue;
16
+ if (area === 0) {
17
+ continue;
18
+ }
16
19
 
17
20
  ring.area = Math.abs(area);
18
21
 
19
- if (ccw === undefined) ccw = area < 0;
22
+ if (ccw === undefined) {
23
+ ccw = area < 0;
24
+ }
20
25
 
21
26
  if (ccw === area < 0) {
22
27
  append(polygon);
@@ -40,4 +45,4 @@ module.exports = function classifyRings(rings, maxRings) {
40
45
  }
41
46
  polygons.push(polygon);
42
47
  }
43
- };
48
+ }
@@ -1,4 +1,4 @@
1
- const { RGBAImage } = require('./image');
1
+ import { RGBAImage } from './image.js';
2
2
 
3
3
  /**
4
4
  * Given an expression that should evaluate to a color ramp, return
@@ -6,7 +6,7 @@ const { RGBAImage } = require('./image');
6
6
  *
7
7
  * @private
8
8
  */
9
- module.exports = function renderColorRamp(expression, colorRampEvaluationParameter) {
9
+ export default function renderColorRamp(expression, colorRampEvaluationParameter) {
10
10
  const colorRampData = new Uint8Array(256 * 4);
11
11
  const evaluationGlobals = {};
12
12
  for (let i = 0, j = 0; i < 256; i++, j += 4) {
@@ -21,4 +21,4 @@ module.exports = function renderColorRamp(expression, colorRampEvaluationParamet
21
21
  }
22
22
 
23
23
  return new RGBAImage({ width: 256, height: 1 }, colorRampData);
24
- };
24
+ }
@@ -1,12 +1,14 @@
1
- const { Evented } = require('@mapwhit/events');
1
+ import { Evented } from '@mapwhit/events';
2
+ import browser from './browser.js';
2
3
 
3
4
  function getDefaultWorkerCount() {
4
- const browser = require('./browser');
5
5
  return Math.max(Math.floor(browser.hardwareConcurrency / 2), 1);
6
6
  }
7
7
 
8
8
  const config = new Evented();
9
9
 
10
+ export default config;
11
+
10
12
  config.set = function set(c) {
11
13
  Object.assign(config, c);
12
14
  config.notify();
@@ -20,5 +22,3 @@ config.set({
20
22
  WORKER_COUNT: getDefaultWorkerCount(),
21
23
  WORKER_URL: ''
22
24
  });
23
-
24
- module.exports = config;
@@ -1,6 +1,5 @@
1
- const assert = require('assert');
2
-
3
- module.exports = dictionaryCoder;
1
+ import assert from 'assert';
2
+ export default dictionaryCoder;
4
3
 
5
4
  function dictionaryCoder(strings) {
6
5
  const numberToString = strings.sort();
package/src/util/dom.js CHANGED
@@ -1,10 +1,14 @@
1
1
  const DOM = {};
2
- module.exports = DOM;
2
+ export default DOM;
3
3
 
4
4
  DOM.create = function (tagName, className, container) {
5
5
  const el = window.document.createElement(tagName);
6
- if (className) el.className = className;
7
- if (container) container.appendChild(el);
6
+ if (className) {
7
+ el.className = className;
8
+ }
9
+ if (container) {
10
+ container.appendChild(el);
11
+ }
8
12
  return el;
9
13
  };
10
14