@mapwhit/tilerenderer 1.0.0 → 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 (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 +105 -47
  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 +58 -33
  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 +53 -33
  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
@@ -1,4 +1,4 @@
1
- const EXTENT = require('../data/extent');
1
+ import EXTENT from '../data/extent.js';
2
2
 
3
3
  /**
4
4
  * Converts a pixel value at a the given zoom level to tile units.
@@ -12,6 +12,6 @@ const EXTENT = require('../data/extent');
12
12
  * @returns value in tile units
13
13
  * @private
14
14
  */
15
- module.exports = function (tile, pixelValue, z) {
15
+ export default function (tile, pixelValue, z) {
16
16
  return pixelValue * (EXTENT / (tile.tileSize * 2 ** (z - tile.tileID.overscaledZ)));
17
- };
17
+ }
@@ -1,11 +1,7 @@
1
- const assert = require('assert');
2
- const { mat4 } = require('@mapbox/gl-matrix');
1
+ import glMatrix from '@mapbox/gl-matrix';
2
+ import assert from 'assert';
3
3
 
4
- module.exports = {
5
- queryRenderedFeatures,
6
- queryRenderedSymbols,
7
- querySourceFeatures
8
- };
4
+ const { mat4 } = glMatrix;
9
5
 
10
6
  /*
11
7
  * Returns a matrix that can be used to convert from tile coordinates to viewport pixel coordinates.
@@ -35,7 +31,7 @@ function queryIncludes3DLayer(layers, styleLayers, sourceID) {
35
31
  return false;
36
32
  }
37
33
 
38
- function queryRenderedFeatures(sourceCache, styleLayers, queryGeometry, params, transform) {
34
+ export function queryRenderedFeatures(sourceCache, styleLayers, queryGeometry, params, transform) {
39
35
  const has3DLayer = queryIncludes3DLayer(params?.layers, styleLayers, sourceCache.id);
40
36
  const maxPitchScaleFactor = transform.maxPitchScaleFactor();
41
37
  const tilesIn = sourceCache.tilesIn(queryGeometry, maxPitchScaleFactor, has3DLayer);
@@ -77,7 +73,14 @@ function queryRenderedFeatures(sourceCache, styleLayers, queryGeometry, params,
77
73
  return result;
78
74
  }
79
75
 
80
- function queryRenderedSymbols(styleLayers, sourceCaches, queryGeometry, params, collisionIndex, retainedQueryData) {
76
+ export function queryRenderedSymbols(
77
+ styleLayers,
78
+ sourceCaches,
79
+ queryGeometry,
80
+ params,
81
+ collisionIndex,
82
+ retainedQueryData
83
+ ) {
81
84
  const result = {};
82
85
  const renderedSymbols = collisionIndex.queryRenderedSymbols(queryGeometry);
83
86
  const bucketQueryData = [];
@@ -141,7 +144,7 @@ function queryRenderedSymbols(styleLayers, sourceCaches, queryGeometry, params,
141
144
  return result;
142
145
  }
143
146
 
144
- function querySourceFeatures(sourceCache, params) {
147
+ export function querySourceFeatures(sourceCache, params) {
145
148
  const tiles = sourceCache.getRenderableIds().map(id => {
146
149
  return sourceCache.getTileByID(id);
147
150
  });
@@ -1,10 +1,10 @@
1
- const browser = require('../util/browser');
2
- const loadImage = require('../util/loader/image');
3
- const { calculateKey } = require('./tile_id');
4
- const RasterTileSource = require('./raster_tile_source');
5
- const DEMData = require('../data/dem_data');
1
+ import DEMData from '../data/dem_data.js';
2
+ import browser from '../util/browser.js';
3
+ import loadImage from '../util/loader/image.js';
4
+ import RasterTileSource from './raster_tile_source.js';
5
+ import { calculateKey } from './tile_id.js';
6
6
 
7
- class RasterDEMTileSource extends RasterTileSource {
7
+ export default class RasterDEMTileSource extends RasterTileSource {
8
8
  constructor(id, options, eventedParent) {
9
9
  super(id, options, eventedParent);
10
10
  this.type = 'raster-dem';
@@ -54,12 +54,16 @@ class RasterDEMTileSource extends RasterTileSource {
54
54
  }
55
55
 
56
56
  unloadTile(tile) {
57
- if (tile.demTexture) this.map.painter.saveTileTexture(tile.demTexture);
57
+ if (tile.demTexture) {
58
+ this.map.painter.saveTileTexture(tile.demTexture);
59
+ }
58
60
  if (tile.fbo) {
59
61
  tile.fbo.destroy();
60
62
  delete tile.fbo;
61
63
  }
62
- if (tile.dem) delete tile.dem;
64
+ if (tile.dem) {
65
+ delete tile.dem;
66
+ }
63
67
  delete tile.neighboringTiles;
64
68
 
65
69
  tile.state = 'unloaded';
@@ -71,8 +75,6 @@ async function loadDEMTile({ uid, rawImageData, encoding }) {
71
75
  return new DEMData(uid, rawImageData, encoding);
72
76
  }
73
77
 
74
- module.exports = RasterDEMTileSource;
75
-
76
78
  function getNeighboringTiles(tileID) {
77
79
  const {
78
80
  canonical: { x, y, z },
@@ -1,9 +1,9 @@
1
- const { pick } = require('../util/object');
2
- const loadImage = require('../util/loader/image');
3
- const { Event, ErrorEvent, Evented } = require('@mapwhit/events');
4
- const loadTileJSON = require('./load_tilejson');
5
- const TileBounds = require('./tile_bounds');
6
- const Texture = require('../render/texture');
1
+ import { ErrorEvent, Event, Evented } from '@mapwhit/events';
2
+ import Texture from '../render/texture.js';
3
+ import loadImage from '../util/loader/image.js';
4
+ import { pick } from '../util/object.js';
5
+ import loadTileJSON from './load_tilejson.js';
6
+ import TileBounds from './tile_bounds.js';
7
7
 
8
8
  class RasterTileSource extends Evented {
9
9
  constructor(id, options, eventedParent) {
@@ -28,7 +28,9 @@ class RasterTileSource extends Evented {
28
28
  try {
29
29
  const tileJSON = await loadTileJSON(this._options);
30
30
  Object.assign(this, tileJSON);
31
- if (tileJSON.bounds) this.tileBounds = new TileBounds(tileJSON.bounds, this.minzoom, this.maxzoom);
31
+ if (tileJSON.bounds) {
32
+ this.tileBounds = new TileBounds(tileJSON.bounds, this.minzoom, this.maxzoom);
33
+ }
32
34
 
33
35
  // `content` is included here to prevent a race condition where `Style#_updateSources` is called
34
36
  // before the TileJSON arrives. this makes sure the tiles needed are loaded once TileJSON arrives
@@ -101,7 +103,9 @@ class RasterTileSource extends Evented {
101
103
  }
102
104
 
103
105
  unloadTile(tile) {
104
- if (tile.texture) this.map.painter.saveTileTexture(tile.texture);
106
+ if (tile.texture) {
107
+ this.map.painter.saveTileTexture(tile.texture);
108
+ }
105
109
  }
106
110
 
107
111
  hasTransition() {
@@ -109,4 +113,4 @@ class RasterTileSource extends Evented {
109
113
  }
110
114
  }
111
115
 
112
- module.exports = RasterTileSource;
116
+ export default RasterTileSource;
@@ -1,6 +1,5 @@
1
- const parseGlyphPBF = require('../../style/parse_glyph_pbf');
2
-
3
- module.exports = glyphCache;
1
+ import parseGlyphPBF from '../../style/parse_glyph_pbf.js';
2
+ export default glyphCache;
4
3
 
5
4
  const MAX_GLYPH_ID = 65535;
6
5
 
@@ -1,8 +1,6 @@
1
- const makeGlyphs = require('./glyphs');
1
+ import makeGlyphs from './glyphs.js';
2
2
 
3
- module.exports = { resources };
4
-
5
- function resources(opts) {
3
+ export function resources(opts) {
6
4
  const glyphs = makeGlyphs(opts);
7
5
 
8
6
  return {
@@ -1,5 +1,5 @@
1
- const dynload = require('dynload');
2
- const browser = require('../util/browser');
1
+ import dynload from 'dynload';
2
+ import browser from '../util/browser.js';
3
3
 
4
4
  let pluginRequested = false;
5
5
  let pluginURL;
@@ -15,7 +15,7 @@ const rtlPlugin = {
15
15
  setRTLTextPlugin
16
16
  };
17
17
 
18
- function registerForPluginAvailability(callback) {
18
+ export function registerForPluginAvailability(callback) {
19
19
  if (plugin.isLoaded()) {
20
20
  callback();
21
21
  return;
@@ -25,13 +25,13 @@ function registerForPluginAvailability(callback) {
25
25
  return () => _loadedCallbacks.splice(_loadedCallbacks.indexOf(callback), 1);
26
26
  }
27
27
 
28
- function clearRTLTextPlugin() {
28
+ export function clearRTLTextPlugin() {
29
29
  _loadedCallbacks.length = 0;
30
30
  pluginRequested = false;
31
31
  pluginURL = undefined;
32
32
  }
33
33
 
34
- function setRTLTextPlugin(url, callback) {
34
+ export function setRTLTextPlugin(url, callback) {
35
35
  if (pluginRequested) {
36
36
  throw new Error('setRTLTextPlugin cannot be called multiple times.');
37
37
  }
@@ -74,7 +74,7 @@ function registerRTLTextPlugin(loadedPlugin) {
74
74
 
75
75
  globalThis.registerRTLTextPlugin ??= registerRTLTextPlugin;
76
76
 
77
- async function loadScript(url) {
77
+ function loadScript(url) {
78
78
  const { promise, resolve, reject } = Promise.withResolvers();
79
79
  const s = dynload(url);
80
80
  s.onload = () => resolve();
@@ -82,11 +82,11 @@ async function loadScript(url) {
82
82
  return promise;
83
83
  }
84
84
 
85
- const plugin = (rtlPlugin.plugin = {
85
+ export const plugin = (rtlPlugin.plugin = {
86
86
  applyArabicShaping: null,
87
87
  processBidirectionalText: null,
88
88
  processStyledBidirectionalText: null,
89
89
  isLoaded: () => plugin.applyArabicShaping != null
90
90
  });
91
91
 
92
- module.exports = rtlPlugin;
92
+ export default rtlPlugin;
@@ -1,4 +1,4 @@
1
- const { bindAll } = require('../util/object');
1
+ import { bindAll } from '../util/object.js';
2
2
 
3
3
  /**
4
4
  * The `Source` interface must be implemented by each source type, including "core" types (`vector`, `raster`,
@@ -24,11 +24,11 @@ const { bindAll } = require('../util/object');
24
24
  * if they are floor-ed to the nearest integer.
25
25
  */
26
26
 
27
- const vector = require('./vector_tile_source');
28
- const raster = require('./raster_tile_source');
29
- const rasterDem = require('./raster_dem_tile_source');
30
- const geojson = require('./geojson_source');
31
- const image = require('./image_source');
27
+ import geojson from './geojson_source.js';
28
+ import image from './image_source.js';
29
+ import rasterDem from './raster_dem_tile_source.js';
30
+ import raster from './raster_tile_source.js';
31
+ import vector from './vector_tile_source.js';
32
32
 
33
33
  const sourceTypes = {
34
34
  vector,
@@ -47,7 +47,7 @@ const sourceTypes = {
47
47
  * with that type's requirements.
48
48
  * @returns {Source}
49
49
  */
50
- function create(id, specification, eventedParent, { resources, layerIndex, showTileBoundaries }) {
50
+ export function create(id, specification, eventedParent, { resources, layerIndex, showTileBoundaries }) {
51
51
  const source = new sourceTypes[specification.type](id, specification, eventedParent, {
52
52
  resources,
53
53
  layerIndex,
@@ -58,16 +58,10 @@ function create(id, specification, eventedParent, { resources, layerIndex, showT
58
58
  return source;
59
59
  }
60
60
 
61
- function getType(name) {
61
+ export function getType(name) {
62
62
  return sourceTypes[name];
63
63
  }
64
64
 
65
- function setType(name, type) {
65
+ export function setType(name, type) {
66
66
  sourceTypes[name] = type;
67
67
  }
68
-
69
- module.exports = {
70
- create,
71
- getType,
72
- setType
73
- };
@@ -1,13 +1,13 @@
1
- const { create: createSource } = require('./source');
2
- const Tile = require('./tile');
3
- const { Event, ErrorEvent, Evented } = require('@mapwhit/events');
4
- const TileCache = require('./tile_cache');
5
- const Coordinate = require('../geo/coordinate');
6
- const EXTENT = require('../data/extent');
7
- const { default: Point } = require('@mapbox/point-geometry');
8
- const browser = require('../util/browser');
9
- const { OverscaledTileID } = require('./tile_id');
10
- const SourceFeatureState = require('./source_state');
1
+ import Point from '@mapbox/point-geometry';
2
+ import { ErrorEvent, Event, Evented } from '@mapwhit/events';
3
+ import EXTENT from '../data/extent.js';
4
+ import Coordinate from '../geo/coordinate.js';
5
+ import browser from '../util/browser.js';
6
+ import { create as createSource } from './source.js';
7
+ import SourceFeatureState from './source_state.js';
8
+ import Tile from './tile.js';
9
+ import TileCache from './tile_cache.js';
10
+ import { OverscaledTileID } from './tile_id.js';
11
11
 
12
12
  /**
13
13
  * `SourceCache` is responsible for
@@ -34,14 +34,20 @@ class SourceCache extends Evented {
34
34
  this.id = id;
35
35
 
36
36
  this.on('data', e => {
37
- if (e.dataType !== 'source') return;
38
- if (e.sourceDataType === 'metadata') this.#sourceLoaded = true;
37
+ if (e.dataType !== 'source') {
38
+ return;
39
+ }
40
+ if (e.sourceDataType === 'metadata') {
41
+ this.#sourceLoaded = true;
42
+ }
39
43
 
40
44
  // for sources with mutable data, this event fires when the underlying data
41
45
  // to a source is changed. (i.e. GeoJSONSource#setData and ImageSource#serCoordinates)
42
46
  if (this.#sourceLoaded && !this.#paused && e.sourceDataType === 'content') {
43
47
  this.reload();
44
- if (this.transform) this.update(this.transform);
48
+ if (this.transform) {
49
+ this.update(this.transform);
50
+ }
45
51
  }
46
52
  });
47
53
 
@@ -73,12 +79,18 @@ class SourceCache extends Evented {
73
79
  * an additional API call is received.
74
80
  */
75
81
  loaded() {
76
- if (this.#sourceErrored) return true;
82
+ if (this.#sourceErrored) {
83
+ return true;
84
+ }
77
85
 
78
- if (!this.#sourceLoaded) return false;
86
+ if (!this.#sourceLoaded) {
87
+ return false;
88
+ }
79
89
 
80
90
  for (const tile of this._tiles.values()) {
81
- if (tile.state !== 'loaded' && tile.state !== 'errored') return false;
91
+ if (tile.state !== 'loaded' && tile.state !== 'errored') {
92
+ return false;
93
+ }
82
94
  }
83
95
  return true;
84
96
  }
@@ -92,12 +104,18 @@ class SourceCache extends Evented {
92
104
  }
93
105
 
94
106
  resume() {
95
- if (!this.#paused) return;
107
+ if (!this.#paused) {
108
+ return;
109
+ }
96
110
  const shouldReload = this.#shouldReloadOnResume;
97
111
  this.#paused = false;
98
112
  this.#shouldReloadOnResume = false;
99
- if (shouldReload) this.reload();
100
- if (this.transform) this.update(this.transform);
113
+ if (shouldReload) {
114
+ this.reload();
115
+ }
116
+ if (this.transform) {
117
+ this.update(this.transform);
118
+ }
101
119
  }
102
120
 
103
121
  _loadTile(tile) {
@@ -170,7 +188,9 @@ class SourceCache extends Evented {
170
188
  this._cache.reset();
171
189
 
172
190
  this._tiles.forEach(tile => {
173
- if (tile.state !== 'errored') this._reloadTile(tile, 'reloading');
191
+ if (tile.state !== 'errored') {
192
+ this._reloadTile(tile, 'reloading');
193
+ }
174
194
  });
175
195
  }
176
196
 
@@ -191,15 +211,23 @@ class SourceCache extends Evented {
191
211
  _tileLoadError(tile, err) {
192
212
  tile.state = 'errored';
193
213
  // ignore do nothing strategy
194
- if (err.doNothing) return;
195
- if (err.status !== 404) this._source.fire(new ErrorEvent(err, { tile }));
214
+ if (err.doNothing) {
215
+ return;
216
+ }
217
+ if (err.status !== 404) {
218
+ this._source.fire(new ErrorEvent(err, { tile }));
219
+ }
196
220
  // continue to try loading parent/children tiles if a tile doesn't exist (404)
197
- else this.update(this.transform);
221
+ else {
222
+ this.update(this.transform);
223
+ }
198
224
  }
199
225
 
200
226
  _tileLoaded(tile, err) {
201
227
  tile.timeAdded = browser.now();
202
- if (this.getSource().type === 'raster-dem' && tile.dem) this._backfillDEM(tile);
228
+ if (this.getSource().type === 'raster-dem' && tile.dem) {
229
+ this._backfillDEM(tile);
230
+ }
203
231
  this._state.initializeTileState(tile, this.map ? this.map.painter : null);
204
232
 
205
233
  this._source.fire(new Event('data', { dataType: 'source', tile: tile, coord: tile.tileID }));
@@ -226,7 +254,9 @@ class SourceCache extends Evented {
226
254
  const dy = borderTile.tileID.canonical.y - tile.tileID.canonical.y;
227
255
  const dim = 2 ** tile.tileID.canonical.z;
228
256
  const borderId = borderTile.tileID.key;
229
- if (dx === 0 && dy === 0) return;
257
+ if (dx === 0 && dy === 0) {
258
+ return;
259
+ }
230
260
 
231
261
  if (Math.abs(dy) > 1) {
232
262
  return;
@@ -239,9 +269,13 @@ class SourceCache extends Evented {
239
269
  dx -= dim;
240
270
  }
241
271
  }
242
- if (!borderTile.dem || !tile.dem) return;
272
+ if (!borderTile.dem || !tile.dem) {
273
+ return;
274
+ }
243
275
  tile.dem.backfillBorder(borderTile.dem, dx, dy);
244
- if (tile.neighboringTiles?.[borderId]) tile.neighboringTiles[borderId].backfilled = true;
276
+ if (tile.neighboringTiles?.[borderId]) {
277
+ tile.neighboringTiles[borderId].backfilled = true;
278
+ }
245
279
  }
246
280
  }
247
281
  /**
@@ -277,8 +311,9 @@ class SourceCache extends Evented {
277
311
  !tile.hasData() ||
278
312
  tile.tileID.overscaledZ <= zoom ||
279
313
  tile.tileID.overscaledZ > maxCoveringZoom
280
- )
314
+ ) {
281
315
  continue;
316
+ }
282
317
 
283
318
  // loop through parents and retain the topmost loaded one if found
284
319
  let topmostLoadedID = tile.tileID;
@@ -311,7 +346,9 @@ class SourceCache extends Evented {
311
346
  findLoadedParent(tileID, minCoveringZoom) {
312
347
  for (let z = tileID.overscaledZ - 1; z >= minCoveringZoom; z--) {
313
348
  const parent = tileID.scaledTo(z);
314
- if (!parent) return;
349
+ if (!parent) {
350
+ return;
351
+ }
315
352
  const tile = this._tiles.get(parent.key);
316
353
  if (tile?.hasData()) {
317
354
  return tile;
@@ -434,7 +471,9 @@ class SourceCache extends Evented {
434
471
  const fadingTiles = new Set();
435
472
  for (const [id, tileID] of retain) {
436
473
  const tile = this._tiles.get(id);
437
- if (!tile || (tile.fadeEndTime && tile.fadeEndTime <= browser.now())) continue;
474
+ if (!tile || (tile.fadeEndTime && tile.fadeEndTime <= browser.now())) {
475
+ continue;
476
+ }
438
477
 
439
478
  // if the tile is loaded but still fading in, find parents to cross-fade with it
440
479
  const parentTile = this.findLoadedParent(tileID, minCoveringZoom);
@@ -466,7 +505,9 @@ class SourceCache extends Evented {
466
505
 
467
506
  // Remove the tiles we don't need anymore.
468
507
  for (const [id, tile] of this._tiles) {
469
- if (retain.has(id)) continue;
508
+ if (retain.has(id)) {
509
+ continue;
510
+ }
470
511
  if (tile.hasSymbolBuckets && !tile.holdingForFade()) {
471
512
  tile.setHoldDuration(this.map._fadeDuration);
472
513
  } else if (!tile.hasSymbolBuckets || tile.symbolFadeFinished()) {
@@ -496,7 +537,9 @@ class SourceCache extends Evented {
496
537
  // retain the tile even if it's not loaded because it's an ideal tile.
497
538
  retain.set(tileID.key, tileID);
498
539
 
499
- if (tile.hasData()) continue;
540
+ if (tile.hasData()) {
541
+ continue;
542
+ }
500
543
 
501
544
  if (zoom < this._source.maxzoom) {
502
545
  // save missing tiles that potentially have loaded children
@@ -510,7 +553,9 @@ class SourceCache extends Evented {
510
553
  for (const tileID of idealTileIDs) {
511
554
  let tile = this._tiles.get(tileID.key);
512
555
 
513
- if (tile.hasData()) continue;
556
+ if (tile.hasData()) {
557
+ continue;
558
+ }
514
559
 
515
560
  // The tile we require is not yet loaded or does not exist;
516
561
  // Attempt to find children that fully cover it.
@@ -532,8 +577,9 @@ class SourceCache extends Evented {
532
577
  retain.has(children[1].key) &&
533
578
  retain.has(children[2].key) &&
534
579
  retain.has(children[3].key)
535
- )
580
+ ) {
536
581
  continue; // tile is covered by children
582
+ }
537
583
  }
538
584
 
539
585
  // We couldn't find child tiles that entirely cover the ideal tile; look for parents now.
@@ -547,7 +593,9 @@ class SourceCache extends Evented {
547
593
  const parentId = tileID.scaledTo(overscaledZ);
548
594
 
549
595
  // Break parent tile ascent if this route has been previously checked by another child.
550
- if (checked.has(parentId.key)) break;
596
+ if (checked.has(parentId.key)) {
597
+ break;
598
+ }
551
599
  checked.add(parentId.key);
552
600
 
553
601
  tile = this.getTile(parentId);
@@ -559,7 +607,9 @@ class SourceCache extends Evented {
559
607
  // Save the current values, since they're the parent of the next iteration
560
608
  // of the parent tile ascent loop.
561
609
  parentWasRequested = tile.wasRequested();
562
- if (tile.hasData()) break;
610
+ if (tile.hasData()) {
611
+ break;
612
+ }
563
613
  }
564
614
  }
565
615
  }
@@ -573,7 +623,9 @@ class SourceCache extends Evented {
573
623
  */
574
624
  _addTile(tileID) {
575
625
  let tile = this._tiles.get(tileID.key);
576
- if (tile) return tile;
626
+ if (tile) {
627
+ return tile;
628
+ }
577
629
 
578
630
  tile = this._cache.getAndRemove(tileID);
579
631
  if (tile) {
@@ -590,13 +642,11 @@ class SourceCache extends Evented {
590
642
  err => this._tileLoadError(tile, err)
591
643
  );
592
644
  }
593
-
594
- // Impossible, but silence flow.
595
- if (!tile) return null;
596
-
597
645
  tile.uses++;
598
646
  this._tiles.set(tileID.key, tile);
599
- if (!cached) this._source.fire(new Event('dataloading', { tile: tile, coord: tile.tileID, dataType: 'source' }));
647
+ if (!cached) {
648
+ this._source.fire(new Event('dataloading', { tile: tile, coord: tile.tileID, dataType: 'source' }));
649
+ }
600
650
 
601
651
  return tile;
602
652
  }
@@ -607,12 +657,16 @@ class SourceCache extends Evented {
607
657
  */
608
658
  _removeTile(id) {
609
659
  const tile = this._tiles.get(id);
610
- if (!tile) return;
660
+ if (!tile) {
661
+ return;
662
+ }
611
663
 
612
664
  tile.uses--;
613
665
  this._tiles.delete(id);
614
666
 
615
- if (tile.uses > 0) return;
667
+ if (tile.uses > 0) {
668
+ return;
669
+ }
616
670
 
617
671
  if (tile.hasData()) {
618
672
  this._cache.add(tile);
@@ -630,7 +684,9 @@ class SourceCache extends Evented {
630
684
  this.#shouldReloadOnResume = false;
631
685
  this.#paused = false;
632
686
 
633
- for (const id of this._tiles.keys()) this._removeTile(id);
687
+ for (const id of this._tiles.keys()) {
688
+ this._removeTile(id);
689
+ }
634
690
 
635
691
  this._cache.reset();
636
692
  }
@@ -645,7 +701,9 @@ class SourceCache extends Evented {
645
701
  const tileResults = [];
646
702
 
647
703
  const transform = this.transform;
648
- if (!transform) return tileResults;
704
+ if (!transform) {
705
+ return tileResults;
706
+ }
649
707
 
650
708
  const cameraPointQueryGeometry = has3DLayer
651
709
  ? transform.getCameraQueryGeometry(pointQueryGeometry)
@@ -777,4 +835,4 @@ function isRasterType(type) {
777
835
  return type === 'raster' || type === 'image';
778
836
  }
779
837
 
780
- module.exports = SourceCache;
838
+ export default SourceCache;