@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,16 +1,16 @@
1
- const { LineLayoutArray } = require('../array_types');
2
-
3
- const { members: layoutAttributes } = require('./line_attributes');
4
- const SegmentVector = require('../segment');
5
- const { ProgramConfigurationSet } = require('../program_configuration');
6
- const { TriangleIndexArray } = require('../index_array_type');
7
- const EXTENT = require('../extent');
8
- const mvt = require('@mapwhit/vector-tile');
9
- const vectorTileFeatureTypes = mvt.VectorTileFeature.types;
10
- const { register } = require('../../util/transfer_registry');
11
- const { hasPattern, addPatternDependencies } = require('./pattern_bucket_features');
12
- const loadGeometry = require('../load_geometry');
13
- const EvaluationParameters = require('../../style/evaluation_parameters');
1
+ import { VectorTileFeature } from '@mapwhit/vector-tile';
2
+ import EvaluationParameters from '../../style/evaluation_parameters.js';
3
+ import { LineLayoutArray } from '../array_types.js';
4
+ import EXTENT from '../extent.js';
5
+ import { TriangleIndexArray } from '../index_array_type.js';
6
+ import loadGeometry from '../load_geometry.js';
7
+ import { ProgramConfigurationSet } from '../program_configuration.js';
8
+ import SegmentVector from '../segment.js';
9
+ import layout from './line_attributes.js';
10
+ import { addPatternDependencies, hasPattern } from './pattern_bucket_features.js';
11
+
12
+ const layoutAttributes = layout.members;
13
+ const vectorTileFeatureTypes = VectorTileFeature.types;
14
14
 
15
15
  // NOTE ON EXTRUDE SCALE:
16
16
  // scale the extrusion vector so that the normal length is this value.
@@ -75,7 +75,6 @@ class LineBucket {
75
75
  this.globalState = options.globalState;
76
76
  this.overscaling = options.overscaling;
77
77
  this.layers = options.layers;
78
- this.layerIds = this.layers.map(layer => layer.id);
79
78
  this.index = options.index;
80
79
  this.features = [];
81
80
  this.hasPattern = false;
@@ -93,8 +92,9 @@ class LineBucket {
93
92
  for (const { feature, index, sourceLayerIndex } of features) {
94
93
  if (
95
94
  !this.layers[0]._featureFilter(new EvaluationParameters(this.zoom, { globalState: this.globalState }), feature)
96
- )
95
+ ) {
97
96
  continue;
97
+ }
98
98
 
99
99
  const geometry = loadGeometry(feature);
100
100
 
@@ -112,7 +112,15 @@ class LineBucket {
112
112
  }
113
113
 
114
114
  if (this.hasPattern) {
115
- this.features.push(addPatternDependencies('line', this.layers, patternFeature, this.zoom, options));
115
+ this.features.push(
116
+ addPatternDependencies(
117
+ 'line',
118
+ this.layers,
119
+ patternFeature,
120
+ { zoom: this.zoom, globalState: this.globalState },
121
+ options
122
+ )
123
+ );
116
124
  } else {
117
125
  this.addFeature(patternFeature, geometry, index, {});
118
126
  }
@@ -122,7 +130,9 @@ class LineBucket {
122
130
  }
123
131
 
124
132
  update(states, vtLayer, imagePositions) {
125
- if (!this.stateDependentLayers.length) return;
133
+ if (!this.stateDependentLayers.length) {
134
+ return;
135
+ }
126
136
  this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, {
127
137
  imagePositions,
128
138
  globalState: this.globalState
@@ -154,7 +164,9 @@ class LineBucket {
154
164
  }
155
165
 
156
166
  destroy() {
157
- if (!this.layoutVertexBuffer) return;
167
+ if (!this.layoutVertexBuffer) {
168
+ return;
169
+ }
158
170
  this.layoutVertexBuffer.destroy();
159
171
  this.indexBuffer.destroy();
160
172
  this.programConfigurations.destroy();
@@ -162,7 +174,7 @@ class LineBucket {
162
174
  }
163
175
 
164
176
  addFeature(feature, geometry, index, imagePositions) {
165
- const layout = this.layers[0].layout;
177
+ const layout = this.layers[0]._layout;
166
178
  const join = layout.get('line-join').evaluate(feature, {});
167
179
  const cap = layout.get('line-cap');
168
180
  const miterLimit = layout.get('line-miter-limit');
@@ -190,28 +202,32 @@ class LineBucket {
190
202
  const isPolygon = vectorTileFeatureTypes[feature.type] === 'Polygon';
191
203
 
192
204
  // If the line has duplicate vertices at the ends, adjust start/length to remove them.
205
+ const firstVertex = vertices[0];
206
+ const lastVertex = vertices[vertices.length - 1];
193
207
  let len = vertices.length;
194
- while (len >= 2 && vertices[len - 1].equals(vertices[len - 2])) {
208
+ while (len >= 2 && lastVertex.equals(vertices[len - 2])) {
195
209
  len--;
196
210
  }
197
211
  let first = 0;
198
- while (first < len - 1 && vertices[first].equals(vertices[first + 1])) {
212
+ while (first < len - 1 && firstVertex.equals(vertices[first + 1])) {
199
213
  first++;
200
214
  }
201
215
 
202
216
  // Ignore invalid geometry.
203
- if (len < (isPolygon ? 3 : 2)) return;
217
+ if (len < (isPolygon ? 3 : 2)) {
218
+ return;
219
+ }
204
220
 
205
221
  if (lineDistances) {
206
222
  lineDistances.tileTotal = calculateFullDistance(vertices, first, len);
207
223
  }
208
224
 
209
- if (join === 'bevel') miterLimit = 1.05;
225
+ if (join === 'bevel') {
226
+ miterLimit = 1.05;
227
+ }
210
228
 
211
229
  const sharpCornerOffset = SHARP_CORNER_OFFSET * (EXTENT / (512 * this.overscaling));
212
230
 
213
- const firstVertex = vertices[first];
214
-
215
231
  // we could be more precise, but it would only save a negligible amount of space
216
232
  const segment = this.segments.prepareSegment(len * 10, this.layoutVertexArray, this.indexArray);
217
233
 
@@ -222,11 +238,8 @@ class LineBucket {
222
238
  let startOfLine = true;
223
239
  let currentVertex;
224
240
  let prevVertex;
225
- let nextVertex;
226
241
  let prevNormal;
227
242
  let nextNormal;
228
- let offsetA;
229
- let offsetB;
230
243
 
231
244
  // the last three vertices added
232
245
  this.e1 = this.e2 = this.e3 = -1;
@@ -237,17 +250,23 @@ class LineBucket {
237
250
  }
238
251
 
239
252
  for (let i = first; i < len; i++) {
240
- nextVertex =
253
+ const nextVertex =
241
254
  isPolygon && i === len - 1
242
255
  ? vertices[first + 1]
243
256
  : // if the line is closed, we treat the last vertex like the first
244
257
  vertices[i + 1]; // just the next vertex
245
258
 
246
259
  // if two consecutive vertices exist, skip the current one
247
- if (nextVertex && vertices[i].equals(nextVertex)) continue;
260
+ if (nextVertex && vertices[i].equals(nextVertex)) {
261
+ continue;
262
+ }
248
263
 
249
- if (nextNormal) prevNormal = nextNormal;
250
- if (currentVertex) prevVertex = currentVertex;
264
+ if (nextNormal) {
265
+ prevNormal = nextNormal;
266
+ }
267
+ if (currentVertex) {
268
+ prevVertex = currentVertex;
269
+ }
251
270
 
252
271
  currentVertex = vertices[i];
253
272
 
@@ -322,156 +341,179 @@ class LineBucket {
322
341
  if (currentJoin === 'bevel') {
323
342
  // The maximum extrude length is 128 / 63 = 2 times the width of the line
324
343
  // so if miterLength >= 2 we need to draw a different type of bevel here.
325
- if (miterLength > 2) currentJoin = 'flipbevel';
344
+ if (miterLength > 2) {
345
+ currentJoin = 'flipbevel';
346
+ }
326
347
 
327
348
  // If the miterLength is really small and the line bevel wouldn't be visible,
328
349
  // just draw a miter join to save a triangle.
329
- if (miterLength < miterLimit) currentJoin = 'miter';
350
+ if (miterLength < miterLimit) {
351
+ currentJoin = 'miter';
352
+ }
330
353
  }
331
354
 
332
355
  // Calculate how far along the line the currentVertex is
333
- if (prevVertex) this.distance += currentVertex.dist(prevVertex);
334
-
335
- if (currentJoin === 'miter') {
336
- joinNormal._mult(miterLength);
337
- this.addCurrentVertex(currentVertex, this.distance, joinNormal, 0, 0, false, segment, lineDistances);
338
- } else if (currentJoin === 'flipbevel') {
339
- // miter is too big, flip the direction to make a beveled join
340
-
341
- if (miterLength > 100) {
342
- // Almost parallel lines
343
- joinNormal = nextNormal.clone().mult(-1);
344
- } else {
345
- const direction = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0 ? -1 : 1;
346
- const bevelLength = (miterLength * prevNormal.add(nextNormal).mag()) / prevNormal.sub(nextNormal).mag();
347
- joinNormal._perp()._mult(bevelLength * direction);
348
- }
349
- this.addCurrentVertex(currentVertex, this.distance, joinNormal, 0, 0, false, segment, lineDistances);
350
- this.addCurrentVertex(currentVertex, this.distance, joinNormal.mult(-1), 0, 0, false, segment, lineDistances);
351
- } else if (currentJoin === 'bevel' || currentJoin === 'fakeround') {
352
- const lineTurnsLeft = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0;
353
- const offset = -Math.sqrt(miterLength * miterLength - 1);
354
- if (lineTurnsLeft) {
355
- offsetB = 0;
356
- offsetA = offset;
357
- } else {
358
- offsetA = 0;
359
- offsetB = offset;
360
- }
356
+ if (prevVertex) {
357
+ this.distance += currentVertex.dist(prevVertex);
358
+ }
361
359
 
362
- // Close previous segment with a bevel
363
- if (!startOfLine) {
364
- this.addCurrentVertex(
365
- currentVertex,
366
- this.distance,
367
- prevNormal,
368
- offsetA,
369
- offsetB,
370
- false,
371
- segment,
372
- lineDistances
373
- );
374
- }
360
+ switch (currentJoin) {
361
+ case 'miter':
362
+ joinNormal._mult(miterLength);
363
+ this.addCurrentVertex(currentVertex, this.distance, joinNormal, 0, 0, false, segment, lineDistances);
364
+ break;
365
+
366
+ case 'flipbevel':
367
+ // miter is too big, flip the direction to make a beveled join
368
+
369
+ if (miterLength > 100) {
370
+ // Almost parallel lines
371
+ joinNormal = nextNormal.clone().mult(-1);
372
+ } else {
373
+ const direction = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0 ? -1 : 1;
374
+ const bevelLength = (miterLength * prevNormal.add(nextNormal).mag()) / prevNormal.sub(nextNormal).mag();
375
+ joinNormal._perp()._mult(bevelLength * direction);
376
+ }
377
+ this.addCurrentVertex(currentVertex, this.distance, joinNormal, 0, 0, false, segment, lineDistances);
378
+ this.addCurrentVertex(currentVertex, this.distance, joinNormal.mult(-1), 0, 0, false, segment, lineDistances);
379
+ break;
380
+
381
+ case 'bevel':
382
+ case 'fakeround': {
383
+ const lineTurnsLeft = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0;
384
+ const offset = -Math.sqrt(miterLength * miterLength - 1);
385
+ let offsetA;
386
+ let offsetB;
387
+
388
+ if (lineTurnsLeft) {
389
+ offsetB = 0;
390
+ offsetA = offset;
391
+ } else {
392
+ offsetA = 0;
393
+ offsetB = offset;
394
+ }
375
395
 
376
- if (currentJoin === 'fakeround') {
377
- // The join angle is sharp enough that a round join would be visible.
378
- // Bevel joins fill the gap between segments with a single pie slice triangle.
379
- // Create a round join by adding multiple pie slices. The join isn't actually round, but
380
- // it looks like it is at the sizes we render lines at.
381
-
382
- // Add more triangles for sharper angles.
383
- // This math is just a good enough approximation. It isn't "correct".
384
- const n = Math.floor((0.5 - (cosHalfAngle - 0.5)) * 8);
385
- let approxFractionalJoinNormal;
386
-
387
- for (let m = 0; m < n; m++) {
388
- approxFractionalJoinNormal = nextNormal
389
- .mult((m + 1) / (n + 1))
390
- ._add(prevNormal)
391
- ._unit();
392
- this.addPieSliceVertex(
396
+ // Close previous segment with a bevel
397
+ if (!startOfLine) {
398
+ this.addCurrentVertex(
393
399
  currentVertex,
394
400
  this.distance,
395
- approxFractionalJoinNormal,
396
- lineTurnsLeft,
401
+ prevNormal,
402
+ offsetA,
403
+ offsetB,
404
+ false,
397
405
  segment,
398
406
  lineDistances
399
407
  );
400
408
  }
401
409
 
402
- this.addPieSliceVertex(currentVertex, this.distance, joinNormal, lineTurnsLeft, segment, lineDistances);
410
+ if (currentJoin === 'fakeround') {
411
+ // The join angle is sharp enough that a round join would be visible.
412
+ // Bevel joins fill the gap between segments with a single pie slice triangle.
413
+ // Create a round join by adding multiple pie slices. The join isn't actually round, but
414
+ // it looks like it is at the sizes we render lines at.
415
+
416
+ // Add more triangles for sharper angles.
417
+ // This math is just a good enough approximation. It isn't "correct".
418
+ const n = Math.floor((0.5 - (cosHalfAngle - 0.5)) * 8);
419
+ let approxFractionalJoinNormal;
420
+
421
+ for (let m = 0; m < n; m++) {
422
+ approxFractionalJoinNormal = nextNormal
423
+ .mult((m + 1) / (n + 1))
424
+ ._add(prevNormal)
425
+ ._unit();
426
+ this.addPieSliceVertex(
427
+ currentVertex,
428
+ this.distance,
429
+ approxFractionalJoinNormal,
430
+ lineTurnsLeft,
431
+ segment,
432
+ lineDistances
433
+ );
434
+ }
435
+
436
+ this.addPieSliceVertex(currentVertex, this.distance, joinNormal, lineTurnsLeft, segment, lineDistances);
437
+
438
+ for (let k = n - 1; k >= 0; k--) {
439
+ approxFractionalJoinNormal = prevNormal
440
+ .mult((k + 1) / (n + 1))
441
+ ._add(nextNormal)
442
+ ._unit();
443
+ this.addPieSliceVertex(
444
+ currentVertex,
445
+ this.distance,
446
+ approxFractionalJoinNormal,
447
+ lineTurnsLeft,
448
+ segment,
449
+ lineDistances
450
+ );
451
+ }
452
+ }
403
453
 
404
- for (let k = n - 1; k >= 0; k--) {
405
- approxFractionalJoinNormal = prevNormal
406
- .mult((k + 1) / (n + 1))
407
- ._add(nextNormal)
408
- ._unit();
409
- this.addPieSliceVertex(
454
+ // Start next segment
455
+ if (nextVertex) {
456
+ this.addCurrentVertex(
410
457
  currentVertex,
411
458
  this.distance,
412
- approxFractionalJoinNormal,
413
- lineTurnsLeft,
459
+ nextNormal,
460
+ -offsetA,
461
+ -offsetB,
462
+ false,
414
463
  segment,
415
464
  lineDistances
416
465
  );
417
466
  }
467
+ break;
418
468
  }
419
469
 
420
- // Start next segment
421
- if (nextVertex) {
422
- this.addCurrentVertex(
423
- currentVertex,
424
- this.distance,
425
- nextNormal,
426
- -offsetA,
427
- -offsetB,
428
- false,
429
- segment,
430
- lineDistances
431
- );
432
- }
433
- } else if (currentJoin === 'butt') {
434
- if (!startOfLine) {
435
- // Close previous segment with a butt
436
- this.addCurrentVertex(currentVertex, this.distance, prevNormal, 0, 0, false, segment, lineDistances);
437
- }
470
+ case 'butt':
471
+ if (!startOfLine) {
472
+ // Close previous segment with a butt
473
+ this.addCurrentVertex(currentVertex, this.distance, prevNormal, 0, 0, false, segment, lineDistances);
474
+ }
438
475
 
439
- // Start next segment with a butt
440
- if (nextVertex) {
441
- this.addCurrentVertex(currentVertex, this.distance, nextNormal, 0, 0, false, segment, lineDistances);
442
- }
443
- } else if (currentJoin === 'square') {
444
- if (!startOfLine) {
445
- // Close previous segment with a square cap
446
- this.addCurrentVertex(currentVertex, this.distance, prevNormal, 1, 1, false, segment, lineDistances);
476
+ // Start next segment with a butt
477
+ if (nextVertex) {
478
+ this.addCurrentVertex(currentVertex, this.distance, nextNormal, 0, 0, false, segment, lineDistances);
479
+ }
480
+ break;
447
481
 
448
- // The segment is done. Unset vertices to disconnect segments.
449
- this.e1 = this.e2 = -1;
450
- }
482
+ case 'square':
483
+ if (!startOfLine) {
484
+ // Close previous segment with a square cap
485
+ this.addCurrentVertex(currentVertex, this.distance, prevNormal, 1, 1, false, segment, lineDistances);
451
486
 
452
- // Start next segment
453
- if (nextVertex) {
454
- this.addCurrentVertex(currentVertex, this.distance, nextNormal, -1, -1, false, segment, lineDistances);
455
- }
456
- } else if (currentJoin === 'round') {
457
- if (!startOfLine) {
458
- // Close previous segment with butt
459
- this.addCurrentVertex(currentVertex, this.distance, prevNormal, 0, 0, false, segment, lineDistances);
487
+ // The segment is done. Unset vertices to disconnect segments.
488
+ this.e1 = this.e2 = -1;
489
+ }
460
490
 
461
- // Add round cap or linejoin at end of segment
462
- this.addCurrentVertex(currentVertex, this.distance, prevNormal, 1, 1, true, segment, lineDistances);
491
+ // Start next segment
492
+ if (nextVertex) {
493
+ this.addCurrentVertex(currentVertex, this.distance, nextNormal, -1, -1, false, segment, lineDistances);
494
+ }
495
+ break;
463
496
 
464
- // The segment is done. Unset vertices to disconnect segments.
465
- this.e1 = this.e2 = -1;
466
- }
497
+ case 'round':
498
+ if (!startOfLine) {
499
+ // Close previous segment with butt
500
+ this.addCurrentVertex(currentVertex, this.distance, prevNormal, 0, 0, false, segment, lineDistances);
467
501
 
468
- // Start next segment with a butt
469
- if (nextVertex) {
470
- // Add round cap before first segment
471
- this.addCurrentVertex(currentVertex, this.distance, nextNormal, -1, -1, true, segment, lineDistances);
502
+ // Add round cap or linejoin at end of segment
503
+ this.addCurrentVertex(currentVertex, this.distance, prevNormal, 1, 1, true, segment, lineDistances);
472
504
 
473
- this.addCurrentVertex(currentVertex, this.distance, nextNormal, 0, 0, false, segment, lineDistances);
474
- }
505
+ // The segment is done. Unset vertices to disconnect segments.
506
+ this.e1 = this.e2 = -1;
507
+ }
508
+
509
+ // Start next segment with a butt
510
+ if (nextVertex) {
511
+ // Add round cap before first segment
512
+ this.addCurrentVertex(currentVertex, this.distance, nextNormal, -1, -1, true, segment, lineDistances);
513
+
514
+ this.addCurrentVertex(currentVertex, this.distance, nextNormal, 0, 0, false, segment, lineDistances);
515
+ }
516
+ break;
475
517
  }
476
518
 
477
519
  if (isSharpCorner && i < len - 1) {
@@ -528,7 +570,9 @@ class LineBucket {
528
570
  }
529
571
 
530
572
  extrude = normal.clone();
531
- if (endLeft) extrude._sub(normal.perp()._mult(endLeft));
573
+ if (endLeft) {
574
+ extrude._sub(normal.perp()._mult(endLeft));
575
+ }
532
576
  addLineVertex(layoutVertexArray, currentVertex, extrude, round, false, endLeft, distance);
533
577
  this.e3 = segment.vertexLength++;
534
578
  if (this.e1 >= 0 && this.e2 >= 0) {
@@ -539,7 +583,9 @@ class LineBucket {
539
583
  this.e2 = this.e3;
540
584
 
541
585
  extrude = normal.mult(-1);
542
- if (endRight) extrude._sub(normal.perp()._mult(endRight));
586
+ if (endRight) {
587
+ extrude._sub(normal.perp()._mult(endRight));
588
+ }
543
589
  addLineVertex(layoutVertexArray, currentVertex, extrude, round, true, -endRight, distance);
544
590
  this.e3 = segment.vertexLength++;
545
591
  if (this.e1 >= 0 && this.e2 >= 0) {
@@ -574,7 +620,9 @@ class LineBucket {
574
620
  const layoutVertexArray = this.layoutVertexArray;
575
621
  const indexArray = this.indexArray;
576
622
 
577
- if (distancesForScaling) distance = scaleDistance(distance, distancesForScaling);
623
+ if (distancesForScaling) {
624
+ distance = scaleDistance(distance, distancesForScaling);
625
+ }
578
626
 
579
627
  addLineVertex(layoutVertexArray, currentVertex, extrude, false, lineTurnsLeft, 0, distance);
580
628
  this.e3 = segment.vertexLength++;
@@ -619,17 +667,14 @@ function scaleDistance(tileDistance, stats) {
619
667
  * @private
620
668
  */
621
669
  function calculateFullDistance(vertices, first, len) {
622
- let currentVertex;
623
- let nextVertex;
624
670
  let total = 0;
625
- for (let i = first; i < len - 1; i++) {
626
- currentVertex = vertices[i];
627
- nextVertex = vertices[i + 1];
628
- total += currentVertex.dist(nextVertex);
671
+ let prev = vertices[first];
672
+ for (let i = first + 1; i < len; i++) {
673
+ const next = vertices[i];
674
+ total += prev.dist(next);
675
+ prev = next;
629
676
  }
630
677
  return total;
631
678
  }
632
679
 
633
- register('LineBucket', LineBucket, { omit: ['layers', 'features'] });
634
-
635
- module.exports = LineBucket;
680
+ export default LineBucket;
@@ -1,9 +1,7 @@
1
- const { createLayout } = require('../../util/struct_array');
1
+ import { createLayout } from '../../util/struct_array.js';
2
2
 
3
- const layout = createLayout([
3
+ export default createLayout([
4
4
  // [tl.x, tl.y, br.x, br.y]
5
5
  { name: 'a_pattern_from', components: 4, type: 'Uint16' },
6
6
  { name: 'a_pattern_to', components: 4, type: 'Uint16' }
7
7
  ]);
8
-
9
- module.exports = layout;
@@ -1,9 +1,9 @@
1
- function hasPattern(type, layers, options) {
1
+ export function hasPattern(type, layers, options) {
2
2
  const patterns = options.patternDependencies;
3
3
  let hasPattern = false;
4
4
 
5
5
  for (const layer of layers) {
6
- const patternProperty = layer.paint.get(`${type}-pattern`);
6
+ const patternProperty = layer._paint.get(`${type}-pattern`);
7
7
  if (!patternProperty.isConstant()) {
8
8
  hasPattern = true;
9
9
  }
@@ -19,16 +19,16 @@ function hasPattern(type, layers, options) {
19
19
  return hasPattern;
20
20
  }
21
21
 
22
- function addPatternDependencies(type, layers, patternFeature, zoom, options) {
22
+ export function addPatternDependencies(type, layers, patternFeature, { zoom, globalState }, options) {
23
23
  const patterns = options.patternDependencies;
24
24
  for (const layer of layers) {
25
- const patternProperty = layer.paint.get(`${type}-pattern`);
25
+ const patternProperty = layer._paint.get(`${type}-pattern`);
26
26
 
27
27
  const patternPropertyValue = patternProperty.value;
28
28
  if (patternPropertyValue.kind !== 'constant') {
29
- const min = patternPropertyValue.evaluate({ zoom: zoom - 1 }, patternFeature, {});
30
- const mid = patternPropertyValue.evaluate({ zoom: zoom }, patternFeature, {});
31
- const max = patternPropertyValue.evaluate({ zoom: zoom + 1 }, patternFeature, {});
29
+ const min = patternPropertyValue.evaluate({ zoom: zoom - 1, globalState }, patternFeature, {});
30
+ const mid = patternPropertyValue.evaluate({ zoom: zoom, globalState }, patternFeature, {});
31
+ const max = patternPropertyValue.evaluate({ zoom: zoom + 1, globalState }, patternFeature, {});
32
32
  // add to patternDependencies
33
33
  patterns[min] = true;
34
34
  patterns[mid] = true;
@@ -40,5 +40,3 @@ function addPatternDependencies(type, layers, patternFeature, zoom, options) {
40
40
  }
41
41
  return patternFeature;
42
42
  }
43
-
44
- module.exports = { hasPattern, addPatternDependencies };
@@ -1,17 +1,17 @@
1
- const { createLayout } = require('../../util/struct_array');
1
+ import { createLayout } from '../../util/struct_array.js';
2
2
 
3
- const symbolLayoutAttributes = createLayout([
3
+ export const symbolLayoutAttributes = createLayout([
4
4
  { name: 'a_pos_offset', components: 4, type: 'Int16' },
5
5
  { name: 'a_data', components: 4, type: 'Uint16' }
6
6
  ]);
7
7
 
8
- const dynamicLayoutAttributes = createLayout([{ name: 'a_projected_pos', components: 3, type: 'Float32' }], 4);
8
+ export const dynamicLayoutAttributes = createLayout([{ name: 'a_projected_pos', components: 3, type: 'Float32' }], 4);
9
9
 
10
- const placementOpacityAttributes = createLayout([{ name: 'a_fade_opacity', components: 1, type: 'Uint32' }], 4);
10
+ export const placementOpacityAttributes = createLayout([{ name: 'a_fade_opacity', components: 1, type: 'Uint32' }], 4);
11
11
 
12
- const collisionVertexAttributes = createLayout([{ name: 'a_placed', components: 2, type: 'Uint8' }], 4);
12
+ export const collisionVertexAttributes = createLayout([{ name: 'a_placed', components: 2, type: 'Uint8' }], 4);
13
13
 
14
- const collisionBox = createLayout([
14
+ export const collisionBox = createLayout([
15
15
  // the box is centered around the anchor point
16
16
  { type: 'Int16', name: 'anchorPointX' },
17
17
  { type: 'Int16', name: 'anchorPointY' },
@@ -36,7 +36,7 @@ const collisionBox = createLayout([
36
36
  { type: 'Int16', name: 'signedDistanceFromAnchor' }
37
37
  ]);
38
38
 
39
- const collisionBoxLayout = createLayout(
39
+ export const collisionBoxLayout = createLayout(
40
40
  [
41
41
  // used to render collision boxes for debugging purposes
42
42
  { name: 'a_pos', components: 2, type: 'Int16' },
@@ -46,7 +46,7 @@ const collisionBoxLayout = createLayout(
46
46
  4
47
47
  );
48
48
 
49
- const collisionCircleLayout = createLayout(
49
+ export const collisionCircleLayout = createLayout(
50
50
  [
51
51
  // used to render collision circles for debugging purposes
52
52
  { name: 'a_pos', components: 2, type: 'Int16' },
@@ -56,7 +56,7 @@ const collisionCircleLayout = createLayout(
56
56
  4
57
57
  );
58
58
 
59
- const placement = createLayout([
59
+ export const placement = createLayout([
60
60
  { type: 'Int16', name: 'anchorX' },
61
61
  { type: 'Int16', name: 'anchorY' },
62
62
  { type: 'Uint16', name: 'glyphStartIndex' },
@@ -73,7 +73,7 @@ const placement = createLayout([
73
73
  { type: 'Uint8', name: 'hidden' }
74
74
  ]);
75
75
 
76
- const symbolInstance = createLayout([
76
+ export const symbolInstance = createLayout([
77
77
  { type: 'Int16', name: 'anchorX' },
78
78
  { type: 'Int16', name: 'anchorY' },
79
79
  { type: 'Int16', name: 'horizontalPlacedTextSymbolIndex' },
@@ -90,24 +90,10 @@ const symbolInstance = createLayout([
90
90
  { type: 'Uint32', name: 'crossTileID' }
91
91
  ]);
92
92
 
93
- const glyphOffset = createLayout([{ type: 'Float32', name: 'offsetX' }]);
93
+ export const glyphOffset = createLayout([{ type: 'Float32', name: 'offsetX' }]);
94
94
 
95
- const lineVertex = createLayout([
95
+ export const lineVertex = createLayout([
96
96
  { type: 'Int16', name: 'x' },
97
97
  { type: 'Int16', name: 'y' },
98
98
  { type: 'Int16', name: 'tileUnitDistanceFromAnchor' }
99
99
  ]);
100
-
101
- module.exports = {
102
- symbolLayoutAttributes,
103
- dynamicLayoutAttributes,
104
- placementOpacityAttributes,
105
- collisionVertexAttributes,
106
- collisionBox,
107
- collisionBoxLayout,
108
- collisionCircleLayout,
109
- placement,
110
- symbolInstance,
111
- glyphOffset,
112
- lineVertex
113
- };