@mapwhit/tilerenderer 1.0.0 → 1.1.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 (236) hide show
  1. package/build/min/package.json +2 -1
  2. package/build/min/src/shaders/_prelude.fragment.glsl.js +1 -1
  3. package/build/min/src/shaders/_prelude.vertex.glsl.js +1 -1
  4. package/build/min/src/shaders/background.fragment.glsl.js +1 -1
  5. package/build/min/src/shaders/background.vertex.glsl.js +1 -1
  6. package/build/min/src/shaders/background_pattern.fragment.glsl.js +1 -1
  7. package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -1
  8. package/build/min/src/shaders/circle.fragment.glsl.js +1 -1
  9. package/build/min/src/shaders/circle.vertex.glsl.js +1 -1
  10. package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -1
  11. package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -1
  12. package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -1
  13. package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -1
  14. package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -1
  15. package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -1
  16. package/build/min/src/shaders/debug.fragment.glsl.js +1 -1
  17. package/build/min/src/shaders/debug.vertex.glsl.js +1 -1
  18. package/build/min/src/shaders/fill.fragment.glsl.js +1 -1
  19. package/build/min/src/shaders/fill.vertex.glsl.js +1 -1
  20. package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +1 -1
  21. package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +1 -1
  22. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +1 -1
  23. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +1 -1
  24. package/build/min/src/shaders/fill_outline.fragment.glsl.js +1 -1
  25. package/build/min/src/shaders/fill_outline.vertex.glsl.js +1 -1
  26. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +1 -1
  27. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +1 -1
  28. package/build/min/src/shaders/fill_pattern.fragment.glsl.js +1 -1
  29. package/build/min/src/shaders/fill_pattern.vertex.glsl.js +1 -1
  30. package/build/min/src/shaders/heatmap.fragment.glsl.js +1 -1
  31. package/build/min/src/shaders/heatmap.vertex.glsl.js +1 -1
  32. package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +1 -1
  33. package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -1
  34. package/build/min/src/shaders/hillshade.fragment.glsl.js +1 -1
  35. package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -1
  36. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +1 -1
  37. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -1
  38. package/build/min/src/shaders/line.fragment.glsl.js +1 -1
  39. package/build/min/src/shaders/line.vertex.glsl.js +1 -1
  40. package/build/min/src/shaders/line_gradient.fragment.glsl.js +1 -1
  41. package/build/min/src/shaders/line_gradient.vertex.glsl.js +1 -1
  42. package/build/min/src/shaders/line_pattern.fragment.glsl.js +1 -1
  43. package/build/min/src/shaders/line_pattern.vertex.glsl.js +1 -1
  44. package/build/min/src/shaders/line_sdf.fragment.glsl.js +1 -1
  45. package/build/min/src/shaders/line_sdf.vertex.glsl.js +1 -1
  46. package/build/min/src/shaders/raster.fragment.glsl.js +1 -1
  47. package/build/min/src/shaders/raster.vertex.glsl.js +1 -1
  48. package/build/min/src/shaders/symbol_icon.fragment.glsl.js +1 -1
  49. package/build/min/src/shaders/symbol_icon.vertex.glsl.js +1 -1
  50. package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +1 -1
  51. package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +1 -1
  52. package/package.json +3 -2
  53. package/src/data/array_types.js +54 -81
  54. package/src/data/bucket/circle_attributes.js +2 -4
  55. package/src/data/bucket/circle_bucket.js +19 -13
  56. package/src/data/bucket/fill_attributes.js +2 -4
  57. package/src/data/bucket/fill_bucket.js +38 -24
  58. package/src/data/bucket/fill_extrusion_attributes.js +2 -4
  59. package/src/data/bucket/fill_extrusion_bucket.js +56 -34
  60. package/src/data/bucket/heatmap_bucket.js +2 -7
  61. package/src/data/bucket/line_attributes.js +2 -4
  62. package/src/data/bucket/line_bucket.js +207 -159
  63. package/src/data/bucket/pattern_attributes.js +2 -4
  64. package/src/data/bucket/pattern_bucket_features.js +5 -7
  65. package/src/data/bucket/symbol_attributes.js +12 -26
  66. package/src/data/bucket/symbol_bucket.js +111 -221
  67. package/src/data/bucket/symbol_buffers.js +62 -0
  68. package/src/data/bucket/symbol_collision_buffers.js +33 -0
  69. package/src/data/bucket.js +2 -6
  70. package/src/data/dem_data.js +11 -7
  71. package/src/data/extent.js +1 -1
  72. package/src/data/feature_index.js +35 -20
  73. package/src/data/index_array_type.js +1 -6
  74. package/src/data/load_geometry.js +6 -9
  75. package/src/data/pos_attributes.js +2 -3
  76. package/src/data/program_configuration.js +44 -26
  77. package/src/data/raster_bounds_attributes.js +2 -2
  78. package/src/data/segment.js +4 -3
  79. package/src/geo/coordinate.js +1 -1
  80. package/src/geo/lng_lat.js +3 -3
  81. package/src/geo/lng_lat_bounds.js +8 -4
  82. package/src/geo/transform.js +69 -30
  83. package/src/gl/color_mode.js +2 -2
  84. package/src/gl/context.js +28 -29
  85. package/src/gl/cull_face_mode.js +1 -1
  86. package/src/gl/depth_mode.js +1 -1
  87. package/src/gl/framebuffer.js +8 -4
  88. package/src/gl/index_buffer.js +2 -2
  89. package/src/gl/stencil_mode.js +1 -1
  90. package/src/gl/value.js +33 -68
  91. package/src/gl/vertex_buffer.js +2 -2
  92. package/src/index.js +49 -25
  93. package/src/render/draw_background.js +14 -9
  94. package/src/render/draw_circle.js +11 -8
  95. package/src/render/draw_collision_debug.js +11 -8
  96. package/src/render/draw_debug.js +16 -14
  97. package/src/render/draw_fill.js +19 -12
  98. package/src/render/draw_fill_extrusion.js +12 -9
  99. package/src/render/draw_heatmap.js +17 -12
  100. package/src/render/draw_hillshade.js +12 -9
  101. package/src/render/draw_line.js +30 -16
  102. package/src/render/draw_raster.js +17 -13
  103. package/src/render/draw_symbol.js +22 -17
  104. package/src/render/glyph_atlas.js +9 -5
  105. package/src/render/glyph_manager.js +1 -1
  106. package/src/render/image_atlas.js +4 -7
  107. package/src/render/image_manager.js +6 -9
  108. package/src/render/line_atlas.js +2 -2
  109. package/src/render/painter.js +65 -47
  110. package/src/render/program/background_program.js +6 -13
  111. package/src/render/program/circle_program.js +4 -6
  112. package/src/render/program/clipping_mask_program.js +3 -5
  113. package/src/render/program/collision_program.js +4 -6
  114. package/src/render/program/debug_program.js +3 -5
  115. package/src/render/program/fill_extrusion_program.js +8 -14
  116. package/src/render/program/fill_program.js +10 -21
  117. package/src/render/program/heatmap_program.js +8 -14
  118. package/src/render/program/hillshade_program.js +10 -16
  119. package/src/render/program/line_program.js +11 -22
  120. package/src/render/program/pattern.js +5 -7
  121. package/src/render/program/program_uniforms.js +13 -20
  122. package/src/render/program/raster_program.js +3 -5
  123. package/src/render/program/symbol_program.js +5 -7
  124. package/src/render/program.js +5 -6
  125. package/src/render/texture.js +1 -1
  126. package/src/render/tile_mask.js +6 -4
  127. package/src/render/uniform_binding.js +9 -20
  128. package/src/render/vertex_array_object.js +5 -3
  129. package/src/shaders/encode_attribute.js +2 -6
  130. package/src/shaders/index.js +103 -51
  131. package/src/source/geojson_source.js +11 -7
  132. package/src/source/geojson_worker_source.js +7 -7
  133. package/src/source/geojson_wrapper.js +4 -4
  134. package/src/source/image_source.js +11 -12
  135. package/src/source/load_tilejson.js +3 -3
  136. package/src/source/pixels_to_tile_units.js +3 -3
  137. package/src/source/query_features.js +13 -10
  138. package/src/source/raster_dem_tile_source.js +12 -10
  139. package/src/source/raster_tile_source.js +13 -9
  140. package/src/source/resources/glyphs.js +2 -3
  141. package/src/source/resources/index.js +2 -4
  142. package/src/source/rtl_text_plugin.js +8 -8
  143. package/src/source/source.js +9 -15
  144. package/src/source/source_cache.js +114 -49
  145. package/src/source/source_state.js +37 -14
  146. package/src/source/tile.js +38 -23
  147. package/src/source/tile_bounds.js +15 -8
  148. package/src/source/tile_cache.js +2 -2
  149. package/src/source/tile_id.js +30 -23
  150. package/src/source/vector_tile_source.js +10 -8
  151. package/src/source/vector_tile_worker_source.js +4 -4
  152. package/src/source/worker_tile.js +24 -22
  153. package/src/style/create_style_layer.js +11 -11
  154. package/src/style/evaluation_parameters.js +4 -6
  155. package/src/style/light.js +5 -5
  156. package/src/style/load_sprite.js +6 -6
  157. package/src/style/parse_glyph_pbf.js +21 -17
  158. package/src/style/pauseable_placement.js +3 -4
  159. package/src/style/properties.js +21 -44
  160. package/src/style/query_utils.js +4 -10
  161. package/src/style/style.js +64 -34
  162. package/src/style/style_layer/background_style_layer.js +3 -4
  163. package/src/style/style_layer/background_style_layer_properties.js +2 -2
  164. package/src/style/style_layer/circle_style_layer.js +12 -9
  165. package/src/style/style_layer/circle_style_layer_properties.js +2 -2
  166. package/src/style/style_layer/fill_extrusion_style_layer.js +16 -13
  167. package/src/style/style_layer/fill_extrusion_style_layer_properties.js +2 -2
  168. package/src/style/style_layer/fill_style_layer.js +6 -7
  169. package/src/style/style_layer/fill_style_layer_properties.js +2 -2
  170. package/src/style/style_layer/heatmap_style_layer.js +5 -6
  171. package/src/style/style_layer/heatmap_style_layer_properties.js +2 -2
  172. package/src/style/style_layer/hillshade_style_layer.js +3 -4
  173. package/src/style/style_layer/hillshade_style_layer_properties.js +2 -2
  174. package/src/style/style_layer/line_style_layer.js +10 -11
  175. package/src/style/style_layer/line_style_layer_properties.js +5 -5
  176. package/src/style/style_layer/raster_style_layer.js +3 -4
  177. package/src/style/style_layer/raster_style_layer_properties.js +2 -2
  178. package/src/style/style_layer/symbol_style_layer.js +7 -8
  179. package/src/style/style_layer/symbol_style_layer_properties.js +2 -2
  180. package/src/style/style_layer.js +21 -20
  181. package/src/style/style_layer_index.js +2 -2
  182. package/src/style/zoom_history.js +1 -1
  183. package/src/style-spec/error/parsing_error.js +1 -1
  184. package/src/style-spec/error/validation_error.js +5 -3
  185. package/src/style-spec/feature_filter/convert.js +17 -9
  186. package/src/style-spec/feature_filter/index.js +13 -9
  187. package/src/style-spec/util/eval_support.js +2 -2
  188. package/src/style-spec/util/ref_properties.js +1 -1
  189. package/src/symbol/anchor.js +2 -2
  190. package/src/symbol/check_max_angle.js +13 -5
  191. package/src/symbol/clip_line.js +2 -3
  192. package/src/symbol/collision_feature.js +8 -4
  193. package/src/symbol/collision_index.js +5 -7
  194. package/src/symbol/cross_tile_symbol_index.js +5 -5
  195. package/src/symbol/get_anchors.js +15 -8
  196. package/src/symbol/grid_index.js +5 -3
  197. package/src/symbol/mergelines.js +2 -2
  198. package/src/symbol/opacity_state.js +1 -1
  199. package/src/symbol/placement.js +25 -20
  200. package/src/symbol/projection.js +29 -28
  201. package/src/symbol/quads.js +10 -12
  202. package/src/symbol/shaping.js +27 -19
  203. package/src/symbol/symbol_layout.js +17 -21
  204. package/src/symbol/symbol_size.js +13 -12
  205. package/src/symbol/transform_text.js +3 -3
  206. package/src/ui/camera.js +34 -18
  207. package/src/ui/map.js +54 -34
  208. package/src/util/async.js +11 -5
  209. package/src/util/browser.js +1 -1
  210. package/src/util/callback.js +3 -9
  211. package/src/util/classify_rings.js +13 -8
  212. package/src/util/color_ramp.js +3 -3
  213. package/src/util/config.js +4 -4
  214. package/src/util/dictionary_coder.js +2 -3
  215. package/src/util/dom.js +7 -3
  216. package/src/util/find_pole_of_inaccessibility.js +29 -14
  217. package/src/util/group_layers.js +1 -1
  218. package/src/util/image.js +3 -8
  219. package/src/util/interpolate.js +1 -1
  220. package/src/util/intersection_tests.js +80 -42
  221. package/src/util/is_char_in_unicode_block.js +1 -1
  222. package/src/util/key.js +7 -3
  223. package/src/util/loader/image.js +1 -1
  224. package/src/util/object.js +25 -23
  225. package/src/util/script_detection.js +212 -91
  226. package/src/util/struct_array.js +8 -40
  227. package/src/util/task_queue.js +11 -7
  228. package/src/util/throttle.js +2 -2
  229. package/src/util/tile_cover.js +8 -5
  230. package/src/util/token.js +1 -1
  231. package/src/util/unique_id.js +2 -2
  232. package/src/util/util.js +21 -29
  233. package/src/util/vectortile_to_geojson.js +4 -2
  234. package/src/util/verticalize_punctuation.js +3 -7
  235. package/src/util/warn.js +4 -4
  236. package/src/util/web_worker.js +3 -3
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;
@@ -183,7 +181,9 @@ class Map extends Camera {
183
181
 
184
182
  this.resize();
185
183
 
186
- if (options.style) this.setStyle(options.style);
184
+ if (options.style) {
185
+ this.setStyle(options.style);
186
+ }
187
187
 
188
188
  this.on('style.load', function () {
189
189
  if (this.transform.unmodified) {
@@ -359,7 +359,9 @@ class Map extends Camera {
359
359
  this.transform.minZoom = minZoom;
360
360
  this._update();
361
361
 
362
- if (this.getZoom() < minZoom) this.setZoom(minZoom);
362
+ if (this.getZoom() < minZoom) {
363
+ this.setZoom(minZoom);
364
+ }
363
365
 
364
366
  return this;
365
367
  }
@@ -391,7 +393,9 @@ class Map extends Camera {
391
393
  this.transform.maxZoom = maxZoom;
392
394
  this._update();
393
395
 
394
- if (this.getZoom() > maxZoom) this.setZoom(maxZoom);
396
+ if (this.getZoom() > maxZoom) {
397
+ this.setZoom(maxZoom);
398
+ }
395
399
 
396
400
  return this;
397
401
  }
@@ -554,8 +558,6 @@ class Map extends Camera {
554
558
  // queryRenderedFeatures(geometry: PointLike | [PointLike, PointLike], options?: Object)
555
559
  // queryRenderedFeatures(options?: Object)
556
560
  //
557
- // There no way to express that in a way that's compatible with both flow and documentation.js.
558
- // Related: https://github.com/facebook/flow/issues/1556
559
561
  if (arguments.length === 2) {
560
562
  geometry = arguments[0];
561
563
  options = arguments[1];
@@ -691,8 +693,10 @@ class Map extends Camera {
691
693
  * @returns {boolean} A Boolean indicating whether the style is fully loaded.
692
694
  */
693
695
  isStyleLoaded() {
694
- if (!this.style) return warn.once('There is no style added to the map.');
695
- return this.style.loaded();
696
+ if (!this.style) {
697
+ return warn.once('There is no style added to the map.');
698
+ }
699
+ return this.style.loaded(true);
696
700
  }
697
701
 
698
702
  /**
@@ -742,7 +746,9 @@ class Map extends Camera {
742
746
  const source = sources[id];
743
747
  const tiles = source._tiles;
744
748
  for (const tile of tiles.values()) {
745
- if (!(tile.state === 'loaded' || tile.state === 'errored')) return false;
749
+ if (!(tile.state === 'loaded' || tile.state === 'errored')) {
750
+ return false;
751
+ }
746
752
  }
747
753
  }
748
754
  return true;
@@ -1242,8 +1248,12 @@ class Map extends Camera {
1242
1248
  * @returns {boolean} A Boolean indicating whether the map is fully loaded.
1243
1249
  */
1244
1250
  loaded() {
1245
- if (this._styleDirty || this._sourcesDirty) return false;
1246
- 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
+ }
1247
1257
  return true;
1248
1258
  }
1249
1259
 
@@ -1256,7 +1266,9 @@ class Map extends Camera {
1256
1266
  * @private
1257
1267
  */
1258
1268
  _update(updateStyle) {
1259
- if (!this.style) return;
1269
+ if (!this.style) {
1270
+ return;
1271
+ }
1260
1272
 
1261
1273
  this._styleDirty = this._styleDirty || updateStyle;
1262
1274
  this._sourcesDirty = true;
@@ -1395,7 +1407,9 @@ class Map extends Camera {
1395
1407
  window.removeEventListener('online', this._onWindowOnline, false);
1396
1408
  }
1397
1409
  const extension = this.painter.context.gl.getExtension('WEBGL_lose_context');
1398
- if (extension) extension.loseContext();
1410
+ if (extension) {
1411
+ extension.loseContext();
1412
+ }
1399
1413
  removeNode(this._canvasContainer);
1400
1414
  removeNode(this._controlContainer);
1401
1415
  this._container.classList.remove('mapboxgl-map');
@@ -1434,7 +1448,9 @@ class Map extends Camera {
1434
1448
  return !!this._showTileBoundaries;
1435
1449
  }
1436
1450
  set showTileBoundaries(value) {
1437
- if (this._showTileBoundaries === value) return;
1451
+ if (this._showTileBoundaries === value) {
1452
+ return;
1453
+ }
1438
1454
  this._showTileBoundaries = value;
1439
1455
  this._update();
1440
1456
  }
@@ -1454,7 +1470,9 @@ class Map extends Camera {
1454
1470
  return !!this._showCollisionBoxes;
1455
1471
  }
1456
1472
  set showCollisionBoxes(value) {
1457
- if (this._showCollisionBoxes === value) return;
1473
+ if (this._showCollisionBoxes === value) {
1474
+ return;
1475
+ }
1458
1476
  this._showCollisionBoxes = value;
1459
1477
  if (value) {
1460
1478
  // When we turn collision boxes on we have to generate them for existing tiles
@@ -1482,7 +1500,9 @@ class Map extends Camera {
1482
1500
  return !!this._showOverdrawInspector;
1483
1501
  }
1484
1502
  set showOverdrawInspector(value) {
1485
- if (this._showOverdrawInspector === value) return;
1503
+ if (this._showOverdrawInspector === value) {
1504
+ return;
1505
+ }
1486
1506
  this._showOverdrawInspector = value;
1487
1507
  this._update();
1488
1508
  }
@@ -1523,7 +1543,7 @@ class Map extends Camera {
1523
1543
  }
1524
1544
  }
1525
1545
 
1526
- module.exports = Map;
1546
+ export default Map;
1527
1547
 
1528
1548
  function removeNode(node) {
1529
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
 
@@ -1,7 +1,6 @@
1
- const { default: Queue } = require('tinyqueue');
2
-
3
- const { default: Point } = require('@mapbox/point-geometry');
4
- const { distToSegmentSquared } = require('./intersection_tests');
1
+ import Point from '@mapbox/point-geometry';
2
+ import Queue from 'tinyqueue';
3
+ import { distToSegmentSquared } from './intersection_tests.js';
5
4
 
6
5
  /**
7
6
  * Finds an approximation of a polygon's Pole Of Inaccessibiliy https://en.wikipedia.org/wiki/Pole_of_inaccessibility
@@ -13,7 +12,7 @@ const { distToSegmentSquared } = require('./intersection_tests');
13
12
  * @returns Pole of Inaccessibiliy.
14
13
  * @private
15
14
  */
16
- module.exports = function (polygonRings, precision = 1, debug = false) {
15
+ export default function (polygonRings, precision = 1, debug = false) {
17
16
  // find the bounding box of the outer ring
18
17
  let minX = Number.POSITIVE_INFINITY;
19
18
  let minY = Number.POSITIVE_INFINITY;
@@ -22,10 +21,18 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
22
21
  const outerRing = polygonRings[0];
23
22
  for (let i = 0; i < outerRing.length; i++) {
24
23
  const p = outerRing[i];
25
- if (!i || p.x < minX) minX = p.x;
26
- if (!i || p.y < minY) minY = p.y;
27
- if (!i || p.x > maxX) maxX = p.x;
28
- if (!i || p.y > maxY) maxY = p.y;
24
+ if (!i || p.x < minX) {
25
+ minX = p.x;
26
+ }
27
+ if (!i || p.y < minY) {
28
+ minY = p.y;
29
+ }
30
+ if (!i || p.x > maxX) {
31
+ maxX = p.x;
32
+ }
33
+ if (!i || p.y > maxY) {
34
+ maxY = p.y;
35
+ }
29
36
  }
30
37
 
31
38
  const width = maxX - minX;
@@ -36,7 +43,9 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
36
43
  // a priority queue of cells in order of their "potential" (max distance to polygon)
37
44
  const cellQueue = new Queue(undefined, compareMax);
38
45
 
39
- if (cellSize === 0) return new Point(minX, minY);
46
+ if (cellSize === 0) {
47
+ return new Point(minX, minY);
48
+ }
40
49
 
41
50
  // cover polygon with initial cells
42
51
  for (let x = minX; x < maxX; x += cellSize) {
@@ -56,11 +65,15 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
56
65
  // update the best cell if we found a better one
57
66
  if (cell.d > bestCell.d || !bestCell.d) {
58
67
  bestCell = cell;
59
- if (debug) console.log('found best %d after %d probes', Math.round(1e4 * cell.d) / 1e4, numProbes);
68
+ if (debug) {
69
+ console.log('found best %d after %d probes', Math.round(1e4 * cell.d) / 1e4, numProbes);
70
+ }
60
71
  }
61
72
 
62
73
  // do not drill down further if there's no chance of a better solution
63
- if (cell.max - bestCell.d <= precision) continue;
74
+ if (cell.max - bestCell.d <= precision) {
75
+ continue;
76
+ }
64
77
 
65
78
  // split the cell into four cells
66
79
  h = cell.h / 2;
@@ -77,7 +90,7 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
77
90
  }
78
91
 
79
92
  return bestCell.p;
80
- };
93
+ }
81
94
 
82
95
  function compareMax(a, b) {
83
96
  return b.max - a.max;
@@ -102,7 +115,9 @@ function pointToPolygonDist(p, polygon) {
102
115
  const a = ring[i];
103
116
  const b = ring[j];
104
117
 
105
- if (a.y > p.y !== b.y > p.y && p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y) + a.x) inside = !inside;
118
+ if (a.y > p.y !== b.y > p.y && p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y) + a.x) {
119
+ inside = !inside;
120
+ }
106
121
 
107
122
  minDistSq = Math.min(minDistSq, distToSegmentSquared(p, a, b));
108
123
  }
@@ -1,4 +1,4 @@
1
- module.exports = groupBySource;
1
+ export default groupBySource;
2
2
 
3
3
  /**
4
4
  * Given an collection of layers, divide them by property 'source', then by 'source-layer',
package/src/util/image.js CHANGED
@@ -1,4 +1,4 @@
1
- const assert = require('assert');
1
+ import assert from 'assert';
2
2
 
3
3
  function createImage(image, { width, height }, channels, data) {
4
4
  if (!data) {
@@ -75,7 +75,7 @@ function copyImage(srcImg, dstImg, srcPt, dstPt, size, channels) {
75
75
  return dstImg;
76
76
  }
77
77
 
78
- class AlphaImage {
78
+ export class AlphaImage {
79
79
  constructor(size, data) {
80
80
  createImage(this, size, 1, data);
81
81
  }
@@ -95,7 +95,7 @@ class AlphaImage {
95
95
 
96
96
  // Not premultiplied, because ImageData is not premultiplied.
97
97
  // UNPACK_PREMULTIPLY_ALPHA_WEBGL must be used when uploading to a texture.
98
- class RGBAImage {
98
+ export class RGBAImage {
99
99
  constructor(size, data) {
100
100
  createImage(this, size, 4, data);
101
101
  }
@@ -112,8 +112,3 @@ class RGBAImage {
112
112
  copyImage(srcImg, dstImg, srcPt, dstPt, size, 4);
113
113
  }
114
114
  }
115
-
116
- module.exports = {
117
- AlphaImage,
118
- RGBAImage
119
- };
@@ -1,4 +1,4 @@
1
- module.exports = interpolate;
1
+ export default interpolate;
2
2
 
3
3
  function interpolate(a, b, t) {
4
4
  return a * (1 - t) + b * t;