@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
package/src/util/util.js CHANGED
@@ -1,6 +1,5 @@
1
- const UnitBezier = require('@mapbox/unitbezier');
2
-
3
- const Coordinate = require('../geo/coordinate');
1
+ import UnitBezier from '@mapbox/unitbezier';
2
+ import Coordinate from '../geo/coordinate.js';
4
3
 
5
4
  /**
6
5
  * @module util
@@ -14,9 +13,13 @@ const Coordinate = require('../geo/coordinate');
14
13
  *
15
14
  * @private
16
15
  */
17
- function easeCubicInOut(t) {
18
- if (t <= 0) return 0;
19
- if (t >= 1) return 1;
16
+ export function easeCubicInOut(t) {
17
+ if (t <= 0) {
18
+ return 0;
19
+ }
20
+ if (t >= 1) {
21
+ return 1;
22
+ }
20
23
  const t2 = t * t;
21
24
  const t3 = t2 * t;
22
25
  return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75);
@@ -32,7 +35,7 @@ function easeCubicInOut(t) {
32
35
  * @param p2y control point 2 y coordinate
33
36
  * @private
34
37
  */
35
- function bezier(p1x, p1y, p2x, p2y) {
38
+ export function bezier(p1x, p1y, p2x, p2y) {
36
39
  const bezier = new UnitBezier(p1x, p1y, p2x, p2y);
37
40
  return function (t) {
38
41
  return bezier.solve(t);
@@ -45,7 +48,7 @@ function bezier(p1x, p1y, p2x, p2y) {
45
48
  *
46
49
  * @private
47
50
  */
48
- const ease = bezier(0.25, 0.1, 0.25, 1);
51
+ export const ease = bezier(0.25, 0.1, 0.25, 1);
49
52
 
50
53
  /**
51
54
  * constrain n to the given range via min + max
@@ -56,7 +59,7 @@ const ease = bezier(0.25, 0.1, 0.25, 1);
56
59
  * @returns the clamped value
57
60
  * @private
58
61
  */
59
- function clamp(n, min, max) {
62
+ export function clamp(n, min, max) {
60
63
  return Math.min(max, Math.max(min, n));
61
64
  }
62
65
 
@@ -69,7 +72,7 @@ function clamp(n, min, max) {
69
72
  * @returns constrained number
70
73
  * @private
71
74
  */
72
- function wrap(n, min, max) {
75
+ export function wrap(n, min, max) {
73
76
  const d = max - min;
74
77
  const w = ((((n - min) % d) + d) % d) + min;
75
78
  return w === min ? max : w;
@@ -81,7 +84,7 @@ function wrap(n, min, max) {
81
84
  * @returns centerpoint
82
85
  * @private
83
86
  */
84
- function getCoordinatesCenter(coords) {
87
+ export function getCoordinatesCenter(coords) {
85
88
  let minX = Number.POSITIVE_INFINITY;
86
89
  let minY = Number.POSITIVE_INFINITY;
87
90
  let maxX = Number.NEGATIVE_INFINITY;
@@ -108,7 +111,7 @@ function getCoordinatesCenter(coords) {
108
111
  * @returns true for a counter clockwise set of points
109
112
  */
110
113
  // http://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
111
- function isCounterClockwise(a, b, c) {
114
+ export function isCounterClockwise(a, b, c) {
112
115
  return (c.y - a.y) * (b.x - a.x) > (b.y - a.y) * (c.x - a.x);
113
116
  }
114
117
 
@@ -120,7 +123,7 @@ function isCounterClockwise(a, b, c) {
120
123
  * @private
121
124
  * @param ring Exterior or interior ring
122
125
  */
123
- function calculateSignedArea(ring) {
126
+ export function calculateSignedArea(ring) {
124
127
  let sum = 0;
125
128
  const len = ring.length;
126
129
  let p2 = ring[len - 1]; // last point
@@ -138,10 +141,12 @@ function calculateSignedArea(ring) {
138
141
  * @param points array of points
139
142
  * @return true if the points are a closed polygon
140
143
  */
141
- function isClosedPolygon(points) {
144
+ export function isClosedPolygon(points) {
142
145
  // If it is 2 points that are the same then it is a point
143
146
  // If it is 3 points with start and end the same then it is a line
144
- if (points.length < 4) return false;
147
+ if (points.length < 4) {
148
+ return false;
149
+ }
145
150
 
146
151
  const p1 = points[0];
147
152
  const p2 = points[points.length - 1];
@@ -162,7 +167,7 @@ function isClosedPolygon(points) {
162
167
  * @return cartesian coordinates in [x, y, z]
163
168
  */
164
169
 
165
- function sphericalToCartesian([r, azimuthal, polar]) {
170
+ export function sphericalToCartesian([r, azimuthal, polar]) {
166
171
  // We abstract "north"/"up" (compass-wise) to be 0° when really this is 90° (π/2):
167
172
  // correct for that here
168
173
  azimuthal += 90;
@@ -177,16 +182,3 @@ function sphericalToCartesian([r, azimuthal, polar]) {
177
182
  z: r * Math.cos(polar)
178
183
  };
179
184
  }
180
-
181
- module.exports = {
182
- easeCubicInOut,
183
- bezier,
184
- ease,
185
- clamp,
186
- wrap,
187
- getCoordinatesCenter,
188
- isCounterClockwise,
189
- calculateSignedArea,
190
- isClosedPolygon,
191
- sphericalToCartesian
192
- };
@@ -34,11 +34,13 @@ class Feature {
34
34
  geometry: this.geometry
35
35
  };
36
36
  for (const i in this) {
37
- if (i === '_geometry' || i === '_vectorTileFeature') continue;
37
+ if (i === '_geometry' || i === '_vectorTileFeature') {
38
+ continue;
39
+ }
38
40
  json[i] = this[i];
39
41
  }
40
42
  return json;
41
43
  }
42
44
  }
43
45
 
44
- module.exports = Feature;
46
+ export default Feature;
@@ -1,6 +1,6 @@
1
- const { charHasRotatedVerticalOrientation } = require('./script_detection');
1
+ import { charHasRotatedVerticalOrientation } from './script_detection.js';
2
2
 
3
- const verticalizedCharacterMap = {
3
+ export const verticalizedCharacterMap = {
4
4
  '!': '︕',
5
5
  '#': '#',
6
6
  $: '$',
@@ -86,7 +86,7 @@ const verticalizedCharacterMap = {
86
86
  '」': '﹂'
87
87
  };
88
88
 
89
- function verticalizePunctuation(input) {
89
+ export default function verticalizePunctuation(input) {
90
90
  let output = '';
91
91
 
92
92
  for (let i = 0; i < input.length; i++) {
@@ -106,7 +106,3 @@ function verticalizePunctuation(input) {
106
106
 
107
107
  return output;
108
108
  }
109
-
110
- verticalizePunctuation.verticalizedCharacterMap = verticalizedCharacterMap;
111
-
112
- module.exports = verticalizePunctuation;
package/src/util/warn.js CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
  const warnOnceHistory = {};
8
8
 
9
- function once(message) {
9
+ function warnOnce(message) {
10
10
  if (!warnOnceHistory[message]) {
11
11
  console.warn(message);
12
12
  warnOnceHistory[message] = true;
@@ -15,7 +15,7 @@ function once(message) {
15
15
 
16
16
  function noop() {}
17
17
 
18
+ const once = typeof console !== 'undefined' ? warnOnce : noop;
19
+
18
20
  // console isn't defined in some WebWorkers, see #2558
19
- module.exports = {
20
- once: typeof console !== 'undefined' ? once : noop
21
- };
21
+ export default { once };
@@ -1,5 +1,5 @@
1
- const config = require('./config');
1
+ import config from './config.js';
2
2
 
3
- module.exports = function () {
3
+ export default function () {
4
4
  return new window.Worker(config.WORKER_URL);
5
- };
5
+ }
package/src/worker.js CHANGED
@@ -1,4 +1 @@
1
- const worker = require('./source/worker');
2
-
3
- /* global self */
4
- worker(self);
1
+ /* intentionaly empty for now */
@@ -1,68 +0,0 @@
1
- module.exports = images;
2
-
3
- function images({ actor, mapId }) {
4
- const cache = new Map(); // id -> image
5
- const inProgress = new Map(); // id -> promise
6
-
7
- return {
8
- getImages
9
- };
10
-
11
- async function getImages({ icons }) {
12
- const missing = new Set();
13
- const result = {};
14
- for (const id of icons) {
15
- if (cache.has(id)) {
16
- const image = cache.get(id);
17
- if (image) {
18
- result[id] = image;
19
- }
20
- } else {
21
- missing.add(id);
22
- }
23
- }
24
- if (missing.size === 0) {
25
- // All images are already in the cache
26
- return result;
27
- }
28
- const active = new Set();
29
- const needed = [...missing];
30
- // Check if any of the missing images are already being fetched
31
- for (const id of missing) {
32
- if (inProgress.has(id)) {
33
- active.add(inProgress.get(id));
34
- missing.delete(id);
35
- }
36
- }
37
- if (missing.size > 0) {
38
- // Fetch the remaining images
39
- await fetchMissing([...missing]);
40
- }
41
- if (active.size > 0) {
42
- await Promise.all(active);
43
- }
44
- for (const id of needed) {
45
- const image = cache.get(id);
46
- if (image) {
47
- result[id] = image;
48
- }
49
- }
50
- return result;
51
- }
52
-
53
- async function fetchMissing(icons) {
54
- const promise = actor.send('getImages', { icons }, mapId);
55
- for (const id of icons) {
56
- inProgress.set(id, promise);
57
- }
58
- const result = await promise;
59
- // Add the fetched images to the cache
60
- for (const id of icons) {
61
- cache.set(id, result[id]);
62
- }
63
- // Remove the fetched images from the inProgress set
64
- for (const id of icons) {
65
- inProgress.delete(id);
66
- }
67
- }
68
- }
@@ -1,110 +0,0 @@
1
- require('../util/polyfill');
2
-
3
- const Actor = require('../util/actor');
4
-
5
- const StyleLayerIndex = require('../style/style_layer_index');
6
- const VectorTileWorkerSource = require('./vector_tile_worker_source');
7
- const GeoJSONWorkerSource = require('./geojson_worker_source');
8
- const assert = require('assert');
9
- const { plugin: globalRTLTextPlugin } = require('./rtl_text_plugin');
10
- const DEMData = require('../data/dem_data');
11
- const { resources } = require('./resources');
12
-
13
- class Worker {
14
- #resources = {};
15
-
16
- constructor(self) {
17
- this.self = self;
18
- this.actor = new Actor(self, this);
19
-
20
- this.actors = {};
21
- this.layerIndexes = {};
22
-
23
- this.workerSourceTypes = {
24
- vector: VectorTileWorkerSource,
25
- geojson: GeoJSONWorkerSource
26
- };
27
-
28
- // [mapId][sourceType][sourceName] => worker source instance
29
- this.workerSources = {};
30
-
31
- this.self.registerWorkerSource = (name, WorkerSource) => {
32
- if (this.workerSourceTypes[name]) {
33
- throw new Error(`Worker source with name "${name}" already registered.`);
34
- }
35
- this.workerSourceTypes[name] = WorkerSource;
36
- };
37
-
38
- this.self.registerRTLTextPlugin = rtlTextPlugin => {
39
- if (globalRTLTextPlugin.isLoaded()) {
40
- throw new Error('RTL text plugin already registered.');
41
- }
42
- globalRTLTextPlugin['applyArabicShaping'] = rtlTextPlugin.applyArabicShaping;
43
- globalRTLTextPlugin['processBidirectionalText'] = rtlTextPlugin.processBidirectionalText;
44
- globalRTLTextPlugin['processStyledBidirectionalText'] = rtlTextPlugin.processStyledBidirectionalText;
45
- };
46
- }
47
-
48
- setLayers(mapId, layers) {
49
- this.getLayerIndex(mapId).replace(layers);
50
- }
51
-
52
- updateLayers(mapId, params) {
53
- this.getLayerIndex(mapId).update(params.layers, params.removedIds);
54
- }
55
-
56
- loadTile(mapId, params) {
57
- assert(params.type);
58
- return this.getWorkerSource(mapId, params.type, params.source).loadTile(params);
59
- }
60
-
61
- loadDEMTile(mapId, params) {
62
- const { uid, rawImageData, encoding } = params;
63
- return new DEMData(uid, rawImageData, encoding);
64
- }
65
-
66
- removeSource(mapId, params) {
67
- const { type, source } = params;
68
- assert(type);
69
- assert(source);
70
-
71
- const worker = this.workerSources?.[mapId]?.[type]?.[source];
72
- if (worker) {
73
- delete this.workerSources[mapId][type][source];
74
- worker.removeSource?.(params);
75
- }
76
- }
77
-
78
- loadRTLTextPlugin(map, pluginURL) {
79
- if (!globalRTLTextPlugin.isLoaded()) {
80
- this.self.importScripts(pluginURL);
81
- if (!globalRTLTextPlugin.isLoaded()) {
82
- throw new Error(`RTL Text Plugin failed to import scripts from ${pluginURL}`);
83
- }
84
- }
85
- }
86
-
87
- getLayerIndex(mapId) {
88
- return (this.layerIndexes[mapId] ??= new StyleLayerIndex());
89
- }
90
-
91
- getResources(mapId) {
92
- return (this.#resources[mapId] ??= resources(this.actor, mapId));
93
- }
94
-
95
- getWorkerSource(mapId, type, source) {
96
- this.workerSources[mapId] ??= {};
97
- this.workerSources[mapId][type] ??= {};
98
-
99
- return (this.workerSources[mapId][type][source] ??= this.createWorkerSource(type, mapId));
100
- }
101
-
102
- createWorkerSource(type, mapId) {
103
- const WorkerSource = this.workerSourceTypes[type];
104
- return new WorkerSource(this.getResources(mapId), this.getLayerIndex(mapId));
105
- }
106
- }
107
-
108
- module.exports = function createWorker(self) {
109
- return new Worker(self);
110
- };
@@ -1,14 +0,0 @@
1
- /**
2
- * May be implemented by custom source types to provide code that can be run on
3
- * the WebWorkers. In addition to providing a custom
4
- * {@link WorkerSource#loadTile}, any other methods attached to a `WorkerSource`
5
- * implementation may also be targeted by the {@link Source} via
6
- * `dispatcher.send('source-type.methodname', params, callback)`.
7
- *
8
- * @see {@link Map#addSourceType}
9
- * @private
10
- *
11
- * @class WorkerSource
12
- * @param actor
13
- * @param layerIndex
14
- */
@@ -1,51 +0,0 @@
1
- const refProperties = require('./util/ref_properties');
2
-
3
- function deref(layer, parent) {
4
- const result = {};
5
-
6
- for (const k in layer) {
7
- if (k !== 'ref') {
8
- result[k] = layer[k];
9
- }
10
- }
11
-
12
- refProperties.forEach(k => {
13
- if (k in parent) {
14
- result[k] = parent[k];
15
- }
16
- });
17
-
18
- return result;
19
- }
20
-
21
- module.exports = derefLayers;
22
-
23
- /**
24
- * Given an array of layers, some of which may contain `ref` properties
25
- * whose value is the `id` of another property, return a new array where
26
- * such layers have been augmented with the 'type', 'source', etc. properties
27
- * from the parent layer, and the `ref` property has been removed.
28
- *
29
- * The input is not modified. The output may contain references to portions
30
- * of the input.
31
- *
32
- * @private
33
- * @param {Array<Layer>} layers
34
- * @returns {Array<Layer>}
35
- */
36
- function derefLayers(layers) {
37
- layers = layers.slice();
38
-
39
- const map = Object.create(null);
40
- for (let i = 0; i < layers.length; i++) {
41
- map[layers[i].id] = layers[i];
42
- }
43
-
44
- for (let i = 0; i < layers.length; i++) {
45
- if ('ref' in layers[i]) {
46
- layers[i] = deref(layers[i], map[layers[i].ref]);
47
- }
48
- }
49
-
50
- return layers;
51
- }
@@ -1,46 +0,0 @@
1
- const refProperties = require('./util/ref_properties');
2
-
3
- function stringify(obj) {
4
- if (obj == null) return 'null';
5
- const type = typeof obj;
6
- if (type === 'number' || type === 'boolean' || type === 'string') return obj;
7
-
8
- if (Array.isArray(obj)) {
9
- return '[' + obj.map(val => stringify(val)).join(',') + ']';
10
- }
11
-
12
- const keys = Object.keys(obj).sort();
13
- return '{' + keys.map(key => `${key}:${stringify(obj[key])}`).join(',') + '}';
14
- }
15
-
16
- function getKey(layer) {
17
- return refProperties.map(k => stringify(layer[k])).join('/');
18
- }
19
-
20
- module.exports = groupByLayout;
21
-
22
- /**
23
- * Given an array of layers, return an array of arrays of layers where all
24
- * layers in each group have identical layout-affecting properties. These
25
- * are the properties that were formerly used by explicit `ref` mechanism
26
- * for layers: 'type', 'source', 'source-layer', 'minzoom', 'maxzoom',
27
- * 'filter', and 'layout'.
28
- *
29
- * The input is not modified. The output layers are references to the
30
- * input layers.
31
- *
32
- * @private
33
- * @param {Array<Layer>} layers
34
- * @returns {Array<Array<Layer>>}
35
- */
36
- function groupByLayout(layers) {
37
- const groups = {};
38
-
39
- for (const l of layers) {
40
- const k = getKey(l);
41
- const group = (groups[k] ??= []);
42
- group.push(l);
43
- }
44
-
45
- return Object.values(groups);
46
- }
package/src/util/actor.js DELETED
@@ -1,108 +0,0 @@
1
- const { serialize, deserialize } = require('./web_worker_transfer');
2
-
3
- module.exports = actor;
4
-
5
- /**
6
- * An implementation of the [Actor design pattern](http://en.wikipedia.org/wiki/Actor_model)
7
- * that maintains the relationship between asynchronous tasks and the objects
8
- * that spin them off - in this case, tasks like parsing parts of styles,
9
- * owned by the styles
10
- *
11
- * @param {WebWorker} target
12
- * @param {WebWorker} parent
13
- * @param {string|number} mapId A unique identifier for the Map instance using this Actor.
14
- * @private
15
- */
16
-
17
- function actor(target, parent, mapId, name) {
18
- const promises = new Map();
19
- let callbackID = Number.MIN_SAFE_INTEGER;
20
- target.addEventListener('message', receive, false);
21
-
22
- return {
23
- send,
24
- receive,
25
- remove,
26
- name
27
- };
28
-
29
- /**
30
- * Sends a message from a main-thread map to a Worker or from a Worker back to
31
- * a main-thread map instance.
32
- *
33
- * @param type The name of the target method to invoke or '[source-type].[source-name].name' for a method on a WorkerSource.
34
- * @param targetMapId A particular mapId to which to send this message.
35
- * @private
36
- */
37
- function send(type, data, targetMapId) {
38
- const id = `${mapId}:${callbackID++}`;
39
- const p = Promise.withResolvers();
40
- promises.set(id, p);
41
- postMessage(targetMapId, id, type, data);
42
- return p.promise;
43
- }
44
-
45
- async function receive(message) {
46
- const { data } = message;
47
- const { id, type, targetMapId } = data;
48
-
49
- if (targetMapId && mapId !== targetMapId) return;
50
-
51
- if (type === '<response>') {
52
- const p = promises.get(id);
53
- if (p) {
54
- promises.delete(id);
55
- if (data.error) {
56
- p.reject(deserialize(data.error));
57
- } else {
58
- p.resolve(deserialize(data.data));
59
- }
60
- }
61
- return;
62
- }
63
-
64
- if (typeof id !== 'undefined') {
65
- let perform;
66
- if (parent[type]) {
67
- // data.type == 'loadTile' etc.
68
- perform = () => parent[type](data.sourceMapId, deserialize(data.data));
69
- } else if (parent.getWorkerSource) {
70
- // data.type == sourcetype.method
71
- const [sourcetype, method] = type.split('.');
72
- const params = deserialize(data.data);
73
- const workerSource = parent.getWorkerSource(data.sourceMapId, sourcetype, params.source);
74
- perform = () => workerSource[method](params);
75
- } else {
76
- return;
77
- }
78
- try {
79
- const result = await perform();
80
- postMessage(data.sourceMapId, id, '<response>', result);
81
- } catch (err) {
82
- postMessage(data.sourceMapId, id, '<response>', undefined, err);
83
- }
84
- return;
85
- }
86
-
87
- parent[type](deserialize(data.data));
88
- }
89
-
90
- function remove() {
91
- target.removeEventListener('message', receive, false);
92
- }
93
-
94
- function postMessage(targetMapId, id, type, data, err) {
95
- const buffers = [];
96
- const payload = {
97
- targetMapId,
98
- sourceMapId: mapId,
99
- type,
100
- id,
101
- data: serialize(data, buffers)
102
- };
103
- if (err) {
104
- payload.error = serialize(err);
105
- }
106
- target.postMessage(payload, buffers);
107
- }
108
- }
@@ -1,65 +0,0 @@
1
- const uniqueId = require('./unique_id');
2
- const actor = require('./actor');
3
-
4
- module.exports = dispatcher;
5
-
6
- /**
7
- * Responsible for sending messages from a {@link Source} to an associated
8
- * {@link WorkerSource}.
9
- *
10
- * @private
11
- */
12
- function dispatcher(workerPool, parent, makeActor = actor) {
13
- // exposed to allow stubbing in unit tests
14
-
15
- let currentActor = -1;
16
- const id = uniqueId();
17
- const workers = workerPool.acquire(id);
18
- const actors = workers.map((worker, i) => makeActor(worker, parent, id, `Worker ${i}`));
19
-
20
- /**
21
- * Broadcast a message to all Workers.
22
- */
23
- function broadcast(type, data) {
24
- const tasks = actors.map(actor => actor.send(type, data));
25
- return Promise.all(tasks);
26
- }
27
-
28
- // Use round robin to send requests to web workers.
29
- function nextActorId() {
30
- currentActor += 1;
31
- if (currentActor === actors.length) {
32
- currentActor = 0;
33
- }
34
- return currentActor;
35
- }
36
-
37
- /**
38
- * Send a message to a Worker.
39
- * @param targetID The ID of the Worker to which to send this message. Omit to allow the dispatcher to choose.
40
- * @returns The ID of the worker to which the message was sent.
41
- */
42
- function send(type, data, targetID = nextActorId()) {
43
- return actors[targetID]?.send(type, data) ?? Promise.resolve();
44
- }
45
-
46
- function remove() {
47
- actors.forEach(actor => actor.remove());
48
- actors.length = 0;
49
- workerPool.release(id);
50
- }
51
-
52
- function nextWorkerId(workerId = nextActorId()) {
53
- return workerId;
54
- }
55
-
56
- return {
57
- get id() {
58
- return id;
59
- },
60
- broadcast,
61
- send,
62
- nextWorkerId,
63
- remove
64
- };
65
- }
@@ -1,15 +0,0 @@
1
- const workerPool = require('./worker_pool');
2
-
3
- let globalWorkerPool;
4
-
5
- /**
6
- * Creates (if necessary) and returns the single, global WorkerPool instance
7
- * to be shared across each Map
8
- * @private
9
- */
10
- module.exports = function getGlobalWorkerPool() {
11
- if (!globalWorkerPool) {
12
- globalWorkerPool = workerPool();
13
- }
14
- return globalWorkerPool;
15
- };