@mapwhit/tilerenderer 0.52.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/README.md +7 -0
  2. package/build/min/package.json +2 -1
  3. package/build/min/src/shaders/_prelude.fragment.glsl.js +2 -2
  4. package/build/min/src/shaders/_prelude.vertex.glsl.js +2 -2
  5. package/build/min/src/shaders/background.fragment.glsl.js +2 -2
  6. package/build/min/src/shaders/background.vertex.glsl.js +1 -1
  7. package/build/min/src/shaders/background_pattern.fragment.glsl.js +2 -2
  8. package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -1
  9. package/build/min/src/shaders/circle.fragment.glsl.js +2 -2
  10. package/build/min/src/shaders/circle.vertex.glsl.js +2 -2
  11. package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -1
  12. package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -1
  13. package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -1
  14. package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -1
  15. package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -1
  16. package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -1
  17. package/build/min/src/shaders/debug.fragment.glsl.js +1 -1
  18. package/build/min/src/shaders/debug.vertex.glsl.js +1 -1
  19. package/build/min/src/shaders/fill.fragment.glsl.js +2 -2
  20. package/build/min/src/shaders/fill.vertex.glsl.js +2 -2
  21. package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +2 -2
  22. package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +2 -2
  23. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +2 -2
  24. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +2 -2
  25. package/build/min/src/shaders/fill_outline.fragment.glsl.js +2 -2
  26. package/build/min/src/shaders/fill_outline.vertex.glsl.js +2 -2
  27. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +2 -2
  28. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +2 -2
  29. package/build/min/src/shaders/fill_pattern.fragment.glsl.js +2 -2
  30. package/build/min/src/shaders/fill_pattern.vertex.glsl.js +2 -2
  31. package/build/min/src/shaders/heatmap.fragment.glsl.js +2 -2
  32. package/build/min/src/shaders/heatmap.vertex.glsl.js +2 -2
  33. package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +2 -2
  34. package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -1
  35. package/build/min/src/shaders/hillshade.fragment.glsl.js +2 -2
  36. package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -1
  37. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +2 -2
  38. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -1
  39. package/build/min/src/shaders/line.fragment.glsl.js +2 -2
  40. package/build/min/src/shaders/line.vertex.glsl.js +2 -2
  41. package/build/min/src/shaders/line_gradient.fragment.glsl.js +2 -2
  42. package/build/min/src/shaders/line_gradient.vertex.glsl.js +2 -2
  43. package/build/min/src/shaders/line_pattern.fragment.glsl.js +2 -2
  44. package/build/min/src/shaders/line_pattern.vertex.glsl.js +2 -2
  45. package/build/min/src/shaders/line_sdf.fragment.glsl.js +2 -2
  46. package/build/min/src/shaders/line_sdf.vertex.glsl.js +2 -2
  47. package/build/min/src/shaders/raster.fragment.glsl.js +2 -2
  48. package/build/min/src/shaders/raster.vertex.glsl.js +1 -1
  49. package/build/min/src/shaders/symbol_icon.fragment.glsl.js +2 -2
  50. package/build/min/src/shaders/symbol_icon.vertex.glsl.js +2 -2
  51. package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +2 -2
  52. package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +2 -2
  53. package/package.json +5 -4
  54. package/src/data/array_types.js +55 -117
  55. package/src/data/bucket/circle_attributes.js +2 -4
  56. package/src/data/bucket/circle_bucket.js +19 -16
  57. package/src/data/bucket/fill_attributes.js +2 -4
  58. package/src/data/bucket/fill_bucket.js +38 -27
  59. package/src/data/bucket/fill_extrusion_attributes.js +2 -4
  60. package/src/data/bucket/fill_extrusion_bucket.js +56 -37
  61. package/src/data/bucket/heatmap_bucket.js +2 -11
  62. package/src/data/bucket/line_attributes.js +2 -4
  63. package/src/data/bucket/line_bucket.js +208 -163
  64. package/src/data/bucket/pattern_attributes.js +2 -4
  65. package/src/data/bucket/pattern_bucket_features.js +7 -9
  66. package/src/data/bucket/symbol_attributes.js +12 -26
  67. package/src/data/bucket/symbol_bucket.js +174 -323
  68. package/src/data/bucket/symbol_buffers.js +62 -0
  69. package/src/data/bucket/symbol_collision_buffers.js +33 -0
  70. package/src/data/bucket.js +26 -25
  71. package/src/data/dem_data.js +11 -10
  72. package/src/data/extent.js +1 -1
  73. package/src/data/feature_index.js +38 -28
  74. package/src/data/index_array_type.js +1 -6
  75. package/src/data/load_geometry.js +6 -9
  76. package/src/data/pos_attributes.js +2 -3
  77. package/src/data/program_configuration.js +47 -38
  78. package/src/data/raster_bounds_attributes.js +2 -2
  79. package/src/data/segment.js +4 -7
  80. package/src/geo/coordinate.js +1 -1
  81. package/src/geo/lng_lat.js +3 -3
  82. package/src/geo/lng_lat_bounds.js +8 -4
  83. package/src/geo/transform.js +69 -30
  84. package/src/gl/color_mode.js +2 -2
  85. package/src/gl/context.js +28 -29
  86. package/src/gl/cull_face_mode.js +1 -1
  87. package/src/gl/depth_mode.js +1 -1
  88. package/src/gl/framebuffer.js +8 -4
  89. package/src/gl/index_buffer.js +2 -2
  90. package/src/gl/stencil_mode.js +1 -1
  91. package/src/gl/value.js +33 -68
  92. package/src/gl/vertex_buffer.js +2 -2
  93. package/src/index.js +49 -25
  94. package/src/render/draw_background.js +17 -12
  95. package/src/render/draw_circle.js +15 -12
  96. package/src/render/draw_collision_debug.js +11 -8
  97. package/src/render/draw_debug.js +16 -14
  98. package/src/render/draw_fill.js +27 -20
  99. package/src/render/draw_fill_extrusion.js +20 -17
  100. package/src/render/draw_heatmap.js +21 -16
  101. package/src/render/draw_hillshade.js +12 -9
  102. package/src/render/draw_line.js +36 -22
  103. package/src/render/draw_raster.js +22 -18
  104. package/src/render/draw_symbol.js +38 -33
  105. package/src/render/glyph_atlas.js +9 -8
  106. package/src/render/glyph_manager.js +2 -3
  107. package/src/render/image_atlas.js +4 -11
  108. package/src/render/image_manager.js +39 -28
  109. package/src/render/line_atlas.js +2 -2
  110. package/src/render/painter.js +78 -61
  111. package/src/render/program/background_program.js +6 -13
  112. package/src/render/program/circle_program.js +8 -10
  113. package/src/render/program/clipping_mask_program.js +3 -5
  114. package/src/render/program/collision_program.js +4 -6
  115. package/src/render/program/debug_program.js +3 -5
  116. package/src/render/program/fill_extrusion_program.js +9 -15
  117. package/src/render/program/fill_program.js +10 -21
  118. package/src/render/program/heatmap_program.js +9 -15
  119. package/src/render/program/hillshade_program.js +16 -22
  120. package/src/render/program/line_program.js +14 -25
  121. package/src/render/program/pattern.js +5 -7
  122. package/src/render/program/program_uniforms.js +13 -20
  123. package/src/render/program/raster_program.js +9 -11
  124. package/src/render/program/symbol_program.js +5 -7
  125. package/src/render/program.js +5 -6
  126. package/src/render/texture.js +1 -1
  127. package/src/render/tile_mask.js +6 -4
  128. package/src/render/uniform_binding.js +9 -20
  129. package/src/render/vertex_array_object.js +5 -3
  130. package/src/shaders/encode_attribute.js +2 -6
  131. package/src/shaders/index.js +103 -51
  132. package/src/source/geojson_source.js +25 -30
  133. package/src/source/geojson_worker_source.js +46 -74
  134. package/src/source/geojson_wrapper.js +13 -5
  135. package/src/source/image_source.js +17 -28
  136. package/src/source/load_tilejson.js +3 -3
  137. package/src/source/pixels_to_tile_units.js +3 -3
  138. package/src/source/query_features.js +17 -15
  139. package/src/source/raster_dem_tile_source.js +54 -71
  140. package/src/source/raster_tile_source.js +14 -15
  141. package/src/source/resources/glyphs.js +4 -5
  142. package/src/source/resources/index.js +4 -12
  143. package/src/source/rtl_text_plugin.js +62 -35
  144. package/src/source/source.js +14 -22
  145. package/src/source/source_cache.js +221 -179
  146. package/src/source/source_state.js +125 -13
  147. package/src/source/tile.js +67 -66
  148. package/src/source/tile_bounds.js +36 -29
  149. package/src/source/tile_cache.js +2 -2
  150. package/src/source/tile_id.js +30 -26
  151. package/src/source/vector_tile_source.js +23 -21
  152. package/src/source/vector_tile_worker_source.js +22 -26
  153. package/src/source/worker_tile.js +139 -134
  154. package/src/style/create_style_layer.js +11 -11
  155. package/src/style/evaluation_parameters.js +4 -6
  156. package/src/style/light.js +5 -5
  157. package/src/style/load_sprite.js +6 -6
  158. package/src/style/parse_glyph_pbf.js +21 -17
  159. package/src/style/pauseable_placement.js +7 -9
  160. package/src/style/properties.js +21 -51
  161. package/src/style/query_utils.js +7 -13
  162. package/src/style/style.js +314 -221
  163. package/src/style/style_layer/background_style_layer.js +3 -4
  164. package/src/style/style_layer/background_style_layer_properties.js +2 -2
  165. package/src/style/style_layer/circle_style_layer.js +25 -20
  166. package/src/style/style_layer/circle_style_layer_properties.js +2 -2
  167. package/src/style/style_layer/fill_extrusion_style_layer.js +55 -37
  168. package/src/style/style_layer/fill_extrusion_style_layer_properties.js +2 -2
  169. package/src/style/style_layer/fill_style_layer.js +11 -12
  170. package/src/style/style_layer/fill_style_layer_properties.js +2 -2
  171. package/src/style/style_layer/heatmap_style_layer.js +6 -7
  172. package/src/style/style_layer/heatmap_style_layer_properties.js +2 -2
  173. package/src/style/style_layer/hillshade_style_layer.js +4 -5
  174. package/src/style/style_layer/hillshade_style_layer_properties.js +2 -2
  175. package/src/style/style_layer/line_style_layer.js +33 -30
  176. package/src/style/style_layer/line_style_layer_properties.js +5 -5
  177. package/src/style/style_layer/raster_style_layer.js +3 -4
  178. package/src/style/style_layer/raster_style_layer_properties.js +2 -2
  179. package/src/style/style_layer/symbol_style_layer.js +20 -21
  180. package/src/style/style_layer/symbol_style_layer_properties.js +2 -2
  181. package/src/style/style_layer.js +66 -47
  182. package/src/style/style_layer_index.js +17 -42
  183. package/src/style/zoom_history.js +1 -1
  184. package/src/style-spec/error/parsing_error.js +1 -1
  185. package/src/style-spec/error/validation_error.js +5 -3
  186. package/src/style-spec/feature_filter/convert.js +17 -9
  187. package/src/style-spec/feature_filter/index.js +13 -9
  188. package/src/style-spec/util/eval_support.js +2 -2
  189. package/src/style-spec/util/ref_properties.js +1 -1
  190. package/src/symbol/anchor.js +2 -6
  191. package/src/symbol/check_max_angle.js +13 -5
  192. package/src/symbol/clip_line.js +2 -3
  193. package/src/symbol/collision_feature.js +8 -4
  194. package/src/symbol/collision_index.js +5 -7
  195. package/src/symbol/cross_tile_symbol_index.js +7 -10
  196. package/src/symbol/get_anchors.js +15 -8
  197. package/src/symbol/grid_index.js +5 -3
  198. package/src/symbol/mergelines.js +2 -2
  199. package/src/symbol/opacity_state.js +1 -5
  200. package/src/symbol/placement.js +28 -23
  201. package/src/symbol/projection.js +29 -28
  202. package/src/symbol/quads.js +14 -16
  203. package/src/symbol/shaping.js +27 -19
  204. package/src/symbol/symbol_layout.js +24 -28
  205. package/src/symbol/symbol_size.js +13 -12
  206. package/src/symbol/transform_text.js +4 -4
  207. package/src/ui/camera.js +34 -18
  208. package/src/ui/map.js +102 -44
  209. package/src/util/async.js +11 -5
  210. package/src/util/browser.js +1 -1
  211. package/src/util/callback.js +3 -9
  212. package/src/util/classify_rings.js +13 -8
  213. package/src/util/color_ramp.js +3 -3
  214. package/src/util/config.js +4 -4
  215. package/src/util/dictionary_coder.js +2 -3
  216. package/src/util/dom.js +7 -3
  217. package/src/util/find_pole_of_inaccessibility.js +29 -14
  218. package/src/util/group_layers.js +41 -0
  219. package/src/util/image.js +3 -13
  220. package/src/util/interpolate.js +1 -1
  221. package/src/util/intersection_tests.js +80 -42
  222. package/src/util/is_char_in_unicode_block.js +1 -1
  223. package/src/util/key.js +25 -0
  224. package/src/util/loader/image.js +1 -1
  225. package/src/util/object.js +33 -76
  226. package/src/util/script_detection.js +212 -91
  227. package/src/util/struct_array.js +8 -40
  228. package/src/util/task_queue.js +11 -7
  229. package/src/util/throttle.js +2 -2
  230. package/src/util/tile_cover.js +8 -5
  231. package/src/util/token.js +1 -1
  232. package/src/util/unique_id.js +2 -2
  233. package/src/util/util.js +21 -29
  234. package/src/util/vectortile_to_geojson.js +4 -2
  235. package/src/util/verticalize_punctuation.js +3 -7
  236. package/src/util/warn.js +4 -4
  237. package/src/util/web_worker.js +3 -3
  238. package/src/worker.js +1 -4
  239. package/src/source/resources/images.js +0 -68
  240. package/src/source/worker.js +0 -110
  241. package/src/source/worker_source.js +0 -14
  242. package/src/style-spec/deref.js +0 -51
  243. package/src/style-spec/group_by_layout.js +0 -46
  244. package/src/util/actor.js +0 -108
  245. package/src/util/dispatcher.js +0 -65
  246. package/src/util/global_worker_pool.js +0 -15
  247. package/src/util/transfer_registry.js +0 -168
  248. package/src/util/web_worker_transfer.js +0 -43
  249. package/src/util/worker_pool.js +0 -41
@@ -1,6 +1,4 @@
1
- const EXTENT = require('../data/extent');
2
-
3
- const { SymbolInstanceArray } = require('../data/array_types');
1
+ import EXTENT from '../data/extent.js';
4
2
 
5
3
  /*
6
4
  The CrossTileSymbolIndex generally works on the assumption that
@@ -240,7 +238,9 @@ class CrossTileSymbolIndex {
240
238
 
241
239
  for (const tile of tiles) {
242
240
  const symbolBucket = tile.getBucket(styleLayer);
243
- if (!symbolBucket || styleLayer.id !== symbolBucket.layerIds[0]) continue;
241
+ if (!symbolBucket || styleLayer.id !== symbolBucket.layers[0].id) {
242
+ continue;
243
+ }
244
244
 
245
245
  if (!symbolBucket.bucketInstanceId) {
246
246
  symbolBucket.bucketInstanceId = ++this.maxBucketInstanceId;
@@ -260,16 +260,13 @@ class CrossTileSymbolIndex {
260
260
  }
261
261
 
262
262
  pruneUnusedLayers(usedLayers) {
263
- const usedLayerMap = {};
264
- usedLayers.forEach(usedLayer => {
265
- usedLayerMap[usedLayer] = true;
266
- });
263
+ const usedLayersSet = new Set(usedLayers);
267
264
  for (const layerId in this.layerIndexes) {
268
- if (!usedLayerMap[layerId]) {
265
+ if (!usedLayersSet.has(layerId)) {
269
266
  delete this.layerIndexes[layerId];
270
267
  }
271
268
  }
272
269
  }
273
270
  }
274
271
 
275
- module.exports = CrossTileSymbolIndex;
272
+ export default CrossTileSymbolIndex;
@@ -1,9 +1,6 @@
1
- const interpolate = require('../util/interpolate');
2
-
3
- const Anchor = require('../symbol/anchor');
4
- const checkMaxAngle = require('./check_max_angle');
5
-
6
- module.exports = { getAnchors, getCenterAnchor };
1
+ import Anchor from '../symbol/anchor.js';
2
+ import interpolate from '../util/interpolate.js';
3
+ import checkMaxAngle from './check_max_angle.js';
7
4
 
8
5
  function getLineLength(line) {
9
6
  let lineLength = 0;
@@ -24,7 +21,7 @@ function getShapedLabelLength(shapedText, shapedIcon) {
24
21
  );
25
22
  }
26
23
 
27
- function getCenterAnchor(line, maxAngle, shapedText, shapedIcon, glyphSize, boxScale) {
24
+ export function getCenterAnchor(line, maxAngle, shapedText, shapedIcon, glyphSize, boxScale) {
28
25
  const angleWindowSize = getAngleWindowSize(shapedText, glyphSize, boxScale);
29
26
  const labelLength = getShapedLabelLength(shapedText, shapedIcon) * boxScale;
30
27
 
@@ -55,7 +52,17 @@ function getCenterAnchor(line, maxAngle, shapedText, shapedIcon, glyphSize, boxS
55
52
  }
56
53
  }
57
54
 
58
- function getAnchors(line, spacing, maxAngle, shapedText, shapedIcon, glyphSize, boxScale, overscaling, tileExtent) {
55
+ export function getAnchors(
56
+ line,
57
+ spacing,
58
+ maxAngle,
59
+ shapedText,
60
+ shapedIcon,
61
+ glyphSize,
62
+ boxScale,
63
+ overscaling,
64
+ tileExtent
65
+ ) {
59
66
  // Resample a line to get anchor points for labels and check that each
60
67
  // potential label passes text-max-angle check and has enough froom to fit
61
68
  // on the line.
@@ -1,4 +1,4 @@
1
- const { clamp } = require('../util/util');
1
+ import { clamp } from '../util/util.js';
2
2
 
3
3
  /**
4
4
  * GridIndex is a data structure for testing the intersection of
@@ -266,7 +266,9 @@ class GridIndex {
266
266
  for (let x = cx1; x <= cx2; x++) {
267
267
  for (let y = cy1; y <= cy2; y++) {
268
268
  const cellIndex = xCellCount * y + x;
269
- if (fn.call(this, x1, y1, x2, y2, cellIndex, ...args)) return;
269
+ if (fn.call(this, x1, y1, x2, y2, cellIndex, ...args)) {
270
+ return;
271
+ }
270
272
  }
271
273
  }
272
274
 
@@ -280,7 +282,7 @@ class GridIndex {
280
282
  }
281
283
  }
282
284
 
283
- module.exports = GridIndex;
285
+ export default GridIndex;
284
286
 
285
287
  function circlesCollide(x1, y1, r1, x2, y2, r2) {
286
288
  const dx = x2 - x1;
@@ -1,4 +1,4 @@
1
- module.exports = function (features) {
1
+ export default function (features) {
2
2
  const leftIndex = new Map();
3
3
  const rightIndex = new Map();
4
4
  const mergedFeatures = [];
@@ -73,4 +73,4 @@ module.exports = function (features) {
73
73
  const { x, y } = geom.at(onRight ? -1 : 0);
74
74
  return `${text}:${x}:${y}`;
75
75
  }
76
- };
76
+ }
@@ -1,5 +1,3 @@
1
- const { register } = require('../util/transfer_registry');
2
-
3
1
  class OpacityState {
4
2
  constructor() {
5
3
  this.opacity = 0;
@@ -16,6 +14,4 @@ class OpacityState {
16
14
  }
17
15
  }
18
16
 
19
- register('OpacityState', OpacityState);
20
-
21
- module.exports = OpacityState;
17
+ export default OpacityState;
@@ -1,12 +1,12 @@
1
- const CollisionIndex = require('./collision_index');
1
+ import assert from 'assert';
2
+ import EXTENT from '../data/extent.js';
3
+ import pixelsToTileUnits from '../source/pixels_to_tile_units.js';
4
+ import properties from '../style/style_layer/symbol_style_layer_properties.js';
5
+ import CollisionIndex from './collision_index.js';
6
+ import * as projection from './projection.js';
7
+ import * as symbolSize from './symbol_size.js';
2
8
 
3
- const EXTENT = require('../data/extent');
4
- const symbolSize = require('./symbol_size');
5
- const projection = require('./projection');
6
- const properties = require('../style/style_layer/symbol_style_layer_properties');
7
9
  const symbolLayoutProperties = properties.layout;
8
- const assert = require('assert');
9
- const pixelsToTileUnits = require('../source/pixels_to_tile_units');
10
10
 
11
11
  class OpacityState {
12
12
  constructor(prevState, increment, placed, skipFade) {
@@ -44,7 +44,7 @@ class JointPlacement {
44
44
  }
45
45
  }
46
46
 
47
- class RetainedQueryData {
47
+ export class RetainedQueryData {
48
48
  constructor(bucketInstanceId, featureIndex, sourceLayerIndex, bucketIndex, tileID) {
49
49
  this.bucketInstanceId = bucketInstanceId;
50
50
  this.featureIndex = featureIndex;
@@ -81,7 +81,7 @@ class CollisionGroups {
81
81
  }
82
82
  }
83
83
 
84
- class Placement {
84
+ export class Placement {
85
85
  constructor(transform, fadeDuration, crossSourceCollisions) {
86
86
  this.transform = transform.clone();
87
87
  this.collisionIndex = new CollisionIndex(this.transform);
@@ -96,11 +96,13 @@ class Placement {
96
96
  placeLayerTile(styleLayer, tile, showCollisionBoxes, seenCrossTileIDs) {
97
97
  const symbolBucket = tile.getBucket(styleLayer);
98
98
  const bucketFeatureIndex = tile.latestFeatureIndex;
99
- if (!symbolBucket || !bucketFeatureIndex || styleLayer.id !== symbolBucket.layerIds[0]) return;
99
+ if (!symbolBucket || !bucketFeatureIndex || styleLayer.id !== symbolBucket.layers[0].id) {
100
+ return;
101
+ }
100
102
 
101
103
  const collisionBoxArray = tile.collisionBoxArray;
102
104
 
103
- const layout = symbolBucket.layers[0].layout;
105
+ const layout = symbolBucket.layers[0]._layout;
104
106
 
105
107
  const scale = 2 ** (this.transform.zoom - tile.tileID.overscaledZ);
106
108
  const textPixelRatio = tile.tileSize / EXTENT;
@@ -159,7 +161,7 @@ class Placement {
159
161
  seenCrossTileIDs,
160
162
  collisionBoxArray
161
163
  ) {
162
- const layout = bucket.layers[0].layout;
164
+ const layout = bucket.layers[0]._layout;
163
165
 
164
166
  const partiallyEvaluatedTextSize = symbolSize.evaluateSizeForZoom(
165
167
  bucket.textSizeData,
@@ -399,19 +401,27 @@ class Placement {
399
401
 
400
402
  for (const tile of tiles) {
401
403
  const symbolBucket = tile.getBucket(styleLayer);
402
- if (symbolBucket && tile.latestFeatureIndex && styleLayer.id === symbolBucket.layerIds[0]) {
404
+ if (symbolBucket && tile.latestFeatureIndex && styleLayer.id === symbolBucket.layers[0].id) {
403
405
  this.updateBucketOpacities(symbolBucket, seenCrossTileIDs, tile.collisionBoxArray);
404
406
  }
405
407
  }
406
408
  }
407
409
 
408
410
  updateBucketOpacities(bucket, seenCrossTileIDs, collisionBoxArray) {
409
- if (bucket.hasTextData()) bucket.text.opacityVertexArray.clear();
410
- if (bucket.hasIconData()) bucket.icon.opacityVertexArray.clear();
411
- if (bucket.hasCollisionBoxData()) bucket.collisionBox.collisionVertexArray.clear();
412
- if (bucket.hasCollisionCircleData()) bucket.collisionCircle.collisionVertexArray.clear();
411
+ if (bucket.hasTextData()) {
412
+ bucket.text.opacityVertexArray.clear();
413
+ }
414
+ if (bucket.hasIconData()) {
415
+ bucket.icon.opacityVertexArray.clear();
416
+ }
417
+ if (bucket.hasCollisionBoxData()) {
418
+ bucket.collisionBox.collisionVertexArray.clear();
419
+ }
420
+ if (bucket.hasCollisionCircleData()) {
421
+ bucket.collisionCircle.collisionVertexArray.clear();
422
+ }
413
423
 
414
- const layout = bucket.layers[0].layout;
424
+ const layout = bucket.layers[0]._layout;
415
425
  const duplicateOpacityState = new JointOpacityState(null, 0, false, false, true);
416
426
  const textAllowOverlap = layout.get('text-allow-overlap');
417
427
  const iconAllowOverlap = layout.get('icon-allow-overlap');
@@ -579,8 +589,3 @@ function packOpacity(opacityState) {
579
589
  targetBit
580
590
  );
581
591
  }
582
-
583
- module.exports = {
584
- RetainedQueryData,
585
- Placement
586
- };
@@ -1,22 +1,13 @@
1
- const { default: Point } = require('@mapbox/point-geometry');
2
-
3
- const { mat4, vec4 } = require('@mapbox/gl-matrix');
4
- const symbolSize = require('./symbol_size');
5
- const { addDynamicAttributes } = require('../data/bucket/symbol_bucket');
6
- const properties = require('../style/style_layer/symbol_style_layer_properties');
1
+ import glMatrix from '@mapbox/gl-matrix';
2
+ import Point from '@mapbox/point-geometry';
3
+ import { addDynamicAttributes } from '../data/bucket/symbol_bucket.js';
4
+ import properties from '../style/style_layer/symbol_style_layer_properties.js';
5
+ import { WritingMode } from '../symbol/shaping.js';
6
+ import * as symbolSize from './symbol_size.js';
7
+
8
+ const { mat4, vec4 } = glMatrix;
7
9
  const symbolLayoutProperties = properties.layout;
8
10
 
9
- const { WritingMode } = require('../symbol/shaping');
10
-
11
- module.exports = {
12
- updateLineLabels,
13
- getLabelPlaneMatrix,
14
- getGlCoordMatrix,
15
- project,
16
- placeFirstAndLastGlyph,
17
- xyTransformMat4
18
- };
19
-
20
11
  /*
21
12
  * # Overview of coordinate spaces
22
13
  *
@@ -65,7 +56,7 @@ module.exports = {
65
56
  /*
66
57
  * Returns a matrix for converting from tile units to the correct label coordinate space.
67
58
  */
68
- function getLabelPlaneMatrix(posMatrix, pitchWithMap, rotateWithMap, transform, pixelsToTileUnits) {
59
+ export function getLabelPlaneMatrix(posMatrix, pitchWithMap, rotateWithMap, transform, pixelsToTileUnits) {
69
60
  const m = mat4.identity(new Float32Array(16));
70
61
  if (pitchWithMap) {
71
62
  mat4.identity(m);
@@ -84,7 +75,7 @@ function getLabelPlaneMatrix(posMatrix, pitchWithMap, rotateWithMap, transform,
84
75
  /*
85
76
  * Returns a matrix for converting from the correct label coordinate space to gl coords.
86
77
  */
87
- function getGlCoordMatrix(posMatrix, pitchWithMap, rotateWithMap, transform, pixelsToTileUnits) {
78
+ export function getGlCoordMatrix(posMatrix, pitchWithMap, rotateWithMap, transform, pixelsToTileUnits) {
88
79
  const m = mat4.identity(new Float32Array(16));
89
80
  if (pitchWithMap) {
90
81
  mat4.multiply(m, m, posMatrix);
@@ -100,7 +91,7 @@ function getGlCoordMatrix(posMatrix, pitchWithMap, rotateWithMap, transform, pix
100
91
  return m;
101
92
  }
102
93
 
103
- function project(point, matrix) {
94
+ export function project(point, matrix) {
104
95
  const pos = [point.x, point.y, 0, 1];
105
96
  xyTransformMat4(pos, pos, matrix);
106
97
  const w = pos[3];
@@ -122,7 +113,7 @@ function isVisible(anchorPos, clippingBuffer) {
122
113
  * Update the `dynamicLayoutVertexBuffer` for the buffer with the correct glyph positions for the current map view.
123
114
  * This is only run on labels that are aligned with lines. Horizontal labels are handled entirely in the shader.
124
115
  */
125
- function updateLineLabels(
116
+ export function updateLineLabels(
126
117
  bucket,
127
118
  posMatrix,
128
119
  painter,
@@ -233,7 +224,7 @@ function updateLineLabels(
233
224
  }
234
225
  }
235
226
 
236
- function placeFirstAndLastGlyph(
227
+ export function placeFirstAndLastGlyph(
237
228
  fontScale,
238
229
  glyphOffsetArray,
239
230
  lineOffsetX,
@@ -269,7 +260,9 @@ function placeFirstAndLastGlyph(
269
260
  projectionCache,
270
261
  returnTileDistance
271
262
  );
272
- if (!firstPlacedGlyph) return null;
263
+ if (!firstPlacedGlyph) {
264
+ return null;
265
+ }
273
266
 
274
267
  const lastPlacedGlyph = placeGlyphAlongLine(
275
268
  fontScale * lastGlyphOffset,
@@ -286,7 +279,9 @@ function placeFirstAndLastGlyph(
286
279
  projectionCache,
287
280
  returnTileDistance
288
281
  );
289
- if (!lastPlacedGlyph) return null;
282
+ if (!lastPlacedGlyph) {
283
+ return null;
284
+ }
290
285
 
291
286
  return { first: firstPlacedGlyph, last: lastPlacedGlyph };
292
287
  }
@@ -428,7 +423,9 @@ function placeGlyphsAlongLine(
428
423
  projectionCache,
429
424
  false
430
425
  );
431
- if (!singleGlyph) return { notEnoughRoom: true };
426
+ if (!singleGlyph) {
427
+ return { notEnoughRoom: true };
428
+ }
432
429
 
433
430
  placedGlyphs = [singleGlyph];
434
431
  }
@@ -486,7 +483,9 @@ function placeGlyphAlongLine(
486
483
  angle = Math.PI;
487
484
  }
488
485
 
489
- if (dir < 0) angle += Math.PI;
486
+ if (dir < 0) {
487
+ angle += Math.PI;
488
+ }
490
489
 
491
490
  let currentIndex = dir > 0 ? lineStartIndex + anchorSegment : lineStartIndex + anchorSegment + 1;
492
491
 
@@ -501,7 +500,9 @@ function placeGlyphAlongLine(
501
500
  currentIndex += dir;
502
501
 
503
502
  // offset does not fit on the projected line
504
- if (currentIndex < lineStartIndex || currentIndex >= lineEndIndex) return null;
503
+ if (currentIndex < lineStartIndex || currentIndex >= lineEndIndex) {
504
+ return null;
505
+ }
505
506
 
506
507
  prev = current;
507
508
 
@@ -591,7 +592,7 @@ function hideGlyphs(num, dynamicLayoutVertexArray) {
591
592
 
592
593
  // For line label layout, we're not using z output and our w input is always 1
593
594
  // This custom matrix transformation ignores those components to make projection faster
594
- function xyTransformMat4(out, a, m) {
595
+ export function xyTransformMat4(out, a, m) {
595
596
  const x = a[0];
596
597
  const y = a[1];
597
598
  out[0] = m[0] * x + m[4] * y + m[12];
@@ -1,6 +1,5 @@
1
- const { default: Point } = require('@mapbox/point-geometry');
2
-
3
- const { GLYPH_PBF_BORDER } = require('../style/parse_glyph_pbf');
1
+ import Point from '@mapbox/point-geometry';
2
+ import { GLYPH_PBF_BORDER } from '../style/parse_glyph_pbf.js';
4
3
 
5
4
  /**
6
5
  * A textured quad for rendering a single icon or glyph.
@@ -20,9 +19,9 @@ const { GLYPH_PBF_BORDER } = require('../style/parse_glyph_pbf');
20
19
  * Create the quads used for rendering an icon.
21
20
  * @private
22
21
  */
23
- function getIconQuads(anchor, shapedIcon, layer, alongLine, shapedText, feature) {
22
+ export function getIconQuads(anchor, shapedIcon, layer, alongLine, shapedText, feature) {
24
23
  const image = shapedIcon.image;
25
- const layout = layer.layout;
24
+ const layout = layer._layout;
26
25
 
27
26
  // If you have a 10px icon that isn't perfectly aligned to the pixel grid it will cover 11 actual
28
27
  // pixels. The quad needs to be padded to account for this, otherwise they'll look slightly clipped
@@ -71,7 +70,7 @@ function getIconQuads(anchor, shapedIcon, layer, alongLine, shapedText, feature)
71
70
  bl = new Point(left, bottom);
72
71
  }
73
72
 
74
- const angle = (layer.layout.get('icon-rotate').evaluate(feature, {}) * Math.PI) / 180;
73
+ const angle = (layer._layout.get('icon-rotate').evaluate(feature, {}) * Math.PI) / 180;
75
74
 
76
75
  if (angle) {
77
76
  const sin = Math.sin(angle);
@@ -92,10 +91,10 @@ function getIconQuads(anchor, shapedIcon, layer, alongLine, shapedText, feature)
92
91
  * Create the quads used for rendering a text label.
93
92
  * @private
94
93
  */
95
- function getGlyphQuads(anchor, shaping, layer, alongLine, feature, positions) {
94
+ export function getGlyphQuads(anchor, shaping, layer, alongLine, feature, positions) {
96
95
  const oneEm = 24;
97
- const textRotate = (layer.layout.get('text-rotate').evaluate(feature, {}) * Math.PI) / 180;
98
- const textOffset = layer.layout
96
+ const textRotate = (layer._layout.get('text-rotate').evaluate(feature, {}) * Math.PI) / 180;
97
+ const textOffset = layer._layout
99
98
  .get('text-offset')
100
99
  .evaluate(feature, {})
101
100
  .map(t => t * oneEm);
@@ -107,10 +106,14 @@ function getGlyphQuads(anchor, shaping, layer, alongLine, feature, positions) {
107
106
  const positionedGlyph = positionedGlyphs[k];
108
107
  const glyphPositions = positions[positionedGlyph.fontStack];
109
108
  const glyph = glyphPositions?.[positionedGlyph.glyph];
110
- if (!glyph) continue;
109
+ if (!glyph) {
110
+ continue;
111
+ }
111
112
 
112
113
  const rect = glyph.rect;
113
- if (!rect) continue;
114
+ if (!rect) {
115
+ continue;
116
+ }
114
117
 
115
118
  // The rects have an addditional buffer that is not included in their size.
116
119
  const glyphPadding = 1.0;
@@ -167,8 +170,3 @@ function getGlyphQuads(anchor, shaping, layer, alongLine, feature, positions) {
167
170
 
168
171
  return quads;
169
172
  }
170
-
171
- module.exports = {
172
- getIconQuads,
173
- getGlyphQuads
174
- };
@@ -1,19 +1,13 @@
1
- const { charHasUprightVerticalOrientation, charAllowsIdeographicBreaking } = require('../util/script_detection');
2
- const verticalizePunctuation = require('../util/verticalize_punctuation');
3
- const { plugin: rtlTextPlugin } = require('../source/rtl_text_plugin');
1
+ import { plugin as rtlTextPlugin } from '../source/rtl_text_plugin.js';
2
+ import { charAllowsIdeographicBreaking, charHasUprightVerticalOrientation } from '../util/script_detection.js';
3
+ import verticalizePunctuation from '../util/verticalize_punctuation.js';
4
4
 
5
- const WritingMode = {
5
+ export const WritingMode = {
6
6
  horizontal: 1,
7
7
  vertical: 2,
8
8
  horizontalOnly: 3
9
9
  };
10
10
 
11
- module.exports = {
12
- shapeText,
13
- shapeIcon,
14
- WritingMode
15
- };
16
-
17
11
  class TaggedString {
18
12
  constructor() {
19
13
  this.text = '';
@@ -98,7 +92,7 @@ function breakLines(input, lineBreakPoints) {
98
92
  return lines;
99
93
  }
100
94
 
101
- function shapeText(
95
+ export function shapeText(
102
96
  text,
103
97
  glyphs,
104
98
  defaultFontStack,
@@ -168,7 +162,9 @@ function shapeText(
168
162
 
169
163
  shapeLines(shaping, glyphs, lines, lineHeight, textAnchor, textJustify, writingMode, spacing, verticalHeight);
170
164
 
171
- if (!positionedGlyphs.length) return false;
165
+ if (!positionedGlyphs.length) {
166
+ return false;
167
+ }
172
168
 
173
169
  shaping.text = shaping.text.toString();
174
170
  return shaping;
@@ -210,7 +206,9 @@ function determineAverageLineWidth(logicalInput, spacing, maxWidth, glyphMap) {
210
206
  const section = logicalInput.getSection(index);
211
207
  const positions = glyphMap[section.fontStack];
212
208
  const glyph = positions?.[logicalInput.getCharCode(index)];
213
- if (!glyph) continue;
209
+ if (!glyph) {
210
+ continue;
211
+ }
214
212
  totalWidth += glyph.metrics.advance * section.scale + spacing;
215
213
  }
216
214
 
@@ -283,9 +281,13 @@ function leastBadBreaks(lastLineBreak) {
283
281
  }
284
282
 
285
283
  function determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap) {
286
- if (!maxWidth) return [];
284
+ if (!maxWidth) {
285
+ return [];
286
+ }
287
287
 
288
- if (!logicalInput) return [];
288
+ if (!logicalInput) {
289
+ return [];
290
+ }
289
291
 
290
292
  const potentialLineBreaks = [];
291
293
  const targetWidth = determineAverageLineWidth(logicalInput, spacing, maxWidth, glyphMap);
@@ -298,7 +300,9 @@ function determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap) {
298
300
  const positions = glyphMap[section.fontStack];
299
301
  const glyph = positions?.[codePoint];
300
302
 
301
- if (glyph && !whitespace[codePoint]) currentX += glyph.metrics.advance * section.scale + spacing;
303
+ if (glyph && !whitespace[codePoint]) {
304
+ currentX += glyph.metrics.advance * section.scale + spacing;
305
+ }
302
306
 
303
307
  // Ideographic characters, spaces, and word-breaking punctuation that often appear without
304
308
  // surrounding spaces.
@@ -395,7 +399,9 @@ function shapeLines(
395
399
  const positions = glyphMap[section.fontStack];
396
400
  const glyph = positions?.[codePoint];
397
401
 
398
- if (!glyph) continue;
402
+ if (!glyph) {
403
+ continue;
404
+ }
399
405
 
400
406
  if (!charHasUprightVerticalOrientation(codePoint) || writingMode === WritingMode.horizontal) {
401
407
  positionedGlyphs.push({
@@ -446,7 +452,9 @@ function shapeLines(
446
452
 
447
453
  // justify right = 1, left = 0, center = 0.5
448
454
  function justifyLine(positionedGlyphs, glyphMap, start, end, justify) {
449
- if (!justify) return;
455
+ if (!justify) {
456
+ return;
457
+ }
450
458
 
451
459
  const lastPositionedGlyph = positionedGlyphs[end];
452
460
  const positions = glyphMap[lastPositionedGlyph.fontStack];
@@ -471,7 +479,7 @@ function align(positionedGlyphs, justify, horizontalAlign, verticalAlign, maxLin
471
479
  }
472
480
  }
473
481
 
474
- function shapeIcon(image, iconOffset, iconAnchor) {
482
+ export function shapeIcon(image, iconOffset, iconAnchor) {
475
483
  const { horizontalAlign, verticalAlign } = getAnchorAlignment(iconAnchor);
476
484
  const dx = iconOffset[0];
477
485
  const dy = iconOffset[1];
@@ -1,18 +1,17 @@
1
- const Anchor = require('./anchor');
2
-
3
- const { getAnchors, getCenterAnchor } = require('./get_anchors');
4
- const clipLine = require('./clip_line');
5
- const { shapeText, shapeIcon, WritingMode } = require('./shaping');
6
- const { getGlyphQuads, getIconQuads } = require('./quads');
7
- const CollisionFeature = require('./collision_feature');
8
- const warn = require('../util/warn');
9
- const { allowsVerticalWritingMode, allowsLetterSpacing } = require('../util/script_detection');
10
- const findPoleOfInaccessibility = require('../util/find_pole_of_inaccessibility');
11
- const classifyRings = require('../util/classify_rings');
12
- const EXTENT = require('../data/extent');
13
- const SymbolBucket = require('../data/bucket/symbol_bucket');
14
- const EvaluationParameters = require('../style/evaluation_parameters');
15
- const murmur3 = require('murmurhash-js');
1
+ import murmur3 from 'murmurhash-js';
2
+ import SymbolBucket from '../data/bucket/symbol_bucket.js';
3
+ import EXTENT from '../data/extent.js';
4
+ import EvaluationParameters from '../style/evaluation_parameters.js';
5
+ import classifyRings from '../util/classify_rings.js';
6
+ import findPoleOfInaccessibility from '../util/find_pole_of_inaccessibility.js';
7
+ import { allowsLetterSpacing, allowsVerticalWritingMode } from '../util/script_detection.js';
8
+ import warn from '../util/warn.js';
9
+ import Anchor from './anchor.js';
10
+ import clipLine from './clip_line.js';
11
+ import CollisionFeature from './collision_feature.js';
12
+ import { getAnchors, getCenterAnchor } from './get_anchors.js';
13
+ import { getGlyphQuads, getIconQuads } from './quads.js';
14
+ import { shapeIcon, shapeText, WritingMode } from './shaping.js';
16
15
 
17
16
  // The symbol layout process needs `text-size` evaluated at up to five different zoom levels, and
18
17
  // `icon-size` at up to three:
@@ -26,10 +25,10 @@ const murmur3 = require('murmurhash-js');
26
25
  // 5. For composite `*-size` expressions: two zoom levels of curve stops that "cover" the zoom level of the
27
26
  // bucket. These go into a vertex buffer and are used by the shader to interpolate the size at render time.
28
27
  //
29
- // (1) and (2) are stored in `bucket.layers[0].layout`. The remainder are below.
28
+ // (1) and (2) are stored in `bucket.layers[0]._layout`. The remainder are below.
30
29
  //
31
30
 
32
- function performSymbolLayout(bucket, glyphMap, glyphPositions, imageMap, imagePositions, showCollisionBoxes) {
31
+ export function performSymbolLayout(bucket, glyphMap, glyphPositions, imageMap, imagePositions, showCollisionBoxes) {
33
32
  bucket.createArrays();
34
33
 
35
34
  const tileSize = 512 * bucket.overscaling;
@@ -37,7 +36,7 @@ function performSymbolLayout(bucket, glyphMap, glyphPositions, imageMap, imagePo
37
36
  bucket.compareText = {};
38
37
  bucket.iconsNeedLinear = false;
39
38
 
40
- const layout = bucket.layers[0].layout;
39
+ const layout = bucket.layers[0]._layout;
41
40
  const unevaluatedLayoutValues = bucket.layers[0]._unevaluatedLayout._values;
42
41
 
43
42
  const sizes = {};
@@ -172,7 +171,7 @@ function addFeature(bucket, feature, shapedTextOrientations, shapedIcon, glyphPo
172
171
  textMaxSize = layoutTextSize;
173
172
  }
174
173
 
175
- const layout = bucket.layers[0].layout;
174
+ const layout = bucket.layers[0]._layout;
176
175
  const textOffset = layout.get('text-offset').evaluate(feature, {});
177
176
  const iconOffset = layout.get('icon-offset').evaluate(feature, {});
178
177
 
@@ -301,7 +300,7 @@ function addTextVertices(
301
300
  let textSizeData = null;
302
301
 
303
302
  if (sizeData.functionType === 'source') {
304
- textSizeData = [10 * layer.layout.get('text-size').evaluate(feature, {})];
303
+ textSizeData = [10 * layer._layout.get('text-size').evaluate(feature, {})];
305
304
  } else if (sizeData.functionType === 'composite') {
306
305
  textSizeData = [
307
306
  10 * sizes.compositeTextSizes[0].evaluate(feature, {}),
@@ -370,7 +369,7 @@ function addSymbol(
370
369
  if (shapedTextOrientations.horizontal) {
371
370
  // As a collision approximation, we can use either the vertical or the horizontal version of the feature
372
371
  // We're counting on the two versions having similar dimensions
373
- const textRotate = layer.layout.get('text-rotate').evaluate(feature, {});
372
+ const textRotate = layer._layout.get('text-rotate').evaluate(feature, {});
374
373
  textCollisionFeature = new CollisionFeature(
375
374
  collisionBoxArray,
376
375
  line,
@@ -430,7 +429,7 @@ function addSymbol(
430
429
  shapedTextOrientations.horizontal,
431
430
  feature
432
431
  );
433
- const iconRotate = layer.layout.get('icon-rotate').evaluate(feature, {});
432
+ const iconRotate = layer._layout.get('icon-rotate').evaluate(feature, {});
434
433
  iconCollisionFeature = new CollisionFeature(
435
434
  collisionBoxArray,
436
435
  line,
@@ -452,7 +451,7 @@ function addSymbol(
452
451
  let iconSizeData = null;
453
452
 
454
453
  if (sizeData.functionType === 'source') {
455
- iconSizeData = [10 * layer.layout.get('icon-size').evaluate(feature, {})];
454
+ iconSizeData = [10 * layer._layout.get('icon-size').evaluate(feature, {})];
456
455
  } else if (sizeData.functionType === 'composite') {
457
456
  iconSizeData = [
458
457
  10 * sizes.compositeIconSizes[0].evaluate(feature, {}),
@@ -477,8 +476,9 @@ function addSymbol(
477
476
  const iconBoxStartIndex = iconCollisionFeature ? iconCollisionFeature.boxStartIndex : bucket.collisionBoxArray.length;
478
477
  const iconBoxEndIndex = iconCollisionFeature ? iconCollisionFeature.boxEndIndex : bucket.collisionBoxArray.length;
479
478
 
480
- if (bucket.glyphOffsetArray.length >= SymbolBucket.MAX_GLYPHS)
479
+ if (bucket.glyphOffsetArray.length >= SymbolBucket.MAX_GLYPHS) {
481
480
  warn.once('Too many glyphs being rendered in a tile. See https://github.com/mapbox/mapbox-gl-js/issues/2907');
481
+ }
482
482
 
483
483
  bucket.symbolInstances.emplaceBack(
484
484
  anchor.x,
@@ -515,7 +515,3 @@ function anchorIsTooClose(bucket, text, repeatDistance, anchor) {
515
515
  compareText[text].push(anchor);
516
516
  return false;
517
517
  }
518
-
519
- module.exports = {
520
- performSymbolLayout
521
- };