maplibre-gl 6.0.0 → 6.2.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 (181) hide show
  1. package/build/readme.md +0 -2
  2. package/dist/maplibre-gl-dev.mjs +433 -573
  3. package/dist/maplibre-gl-dev.mjs.map +1 -1
  4. package/dist/maplibre-gl-shared-dev.mjs +984 -850
  5. package/dist/maplibre-gl-shared-dev.mjs.map +1 -1
  6. package/dist/maplibre-gl-shared.mjs +2 -2
  7. package/dist/maplibre-gl-shared.mjs.map +1 -1
  8. package/dist/maplibre-gl-worker-dev.mjs +14 -12
  9. package/dist/maplibre-gl-worker-dev.mjs.map +1 -1
  10. package/dist/maplibre-gl-worker.mjs +2 -2
  11. package/dist/maplibre-gl-worker.mjs.map +1 -1
  12. package/dist/maplibre-gl.css +1 -1
  13. package/dist/maplibre-gl.d.ts +119 -42
  14. package/dist/maplibre-gl.mjs +22 -22
  15. package/dist/maplibre-gl.mjs.map +1 -1
  16. package/package.json +20 -22
  17. package/src/css/maplibre-gl.css +4 -0
  18. package/src/data/bucket/circle_bucket.ts +3 -2
  19. package/src/data/bucket/fill_bucket.ts +3 -2
  20. package/src/data/bucket/fill_extrusion_bucket.test.ts +22 -0
  21. package/src/data/bucket/fill_extrusion_bucket.ts +17 -4
  22. package/src/data/bucket/line_bucket.test.ts +5 -5
  23. package/src/data/bucket/line_bucket.ts +3 -2
  24. package/src/data/bucket/round_polygon_corners.test.ts +159 -0
  25. package/src/data/bucket/round_polygon_corners.ts +121 -0
  26. package/src/data/bucket/symbol_bucket.test.ts +7 -7
  27. package/src/data/dem_data.test.ts +23 -23
  28. package/src/data/feature_position_map.test.ts +1 -1
  29. package/src/data/segment.test.ts +14 -14
  30. package/src/geo/bounds.test.ts +4 -4
  31. package/src/geo/lng_lat_bounds.test.ts +1 -1
  32. package/src/geo/projection/covering_tiles.bench.ts +39 -0
  33. package/src/geo/projection/covering_tiles.test.ts +3 -7
  34. package/src/geo/projection/covering_tiles.ts +37 -2
  35. package/src/geo/projection/globe_covering_tiles_details_provider.ts +4 -4
  36. package/src/geo/projection/globe_projection.test.ts +2 -2
  37. package/src/geo/projection/globe_projection.ts +6 -15
  38. package/src/geo/projection/globe_transform.test.ts +3 -6
  39. package/src/geo/projection/globe_transform.ts +4 -7
  40. package/src/geo/projection/mercator_covering_tiles_details_provider.ts +4 -4
  41. package/src/geo/projection/mercator_projection.ts +1 -13
  42. package/src/geo/projection/mercator_transform.test.ts +1 -1
  43. package/src/geo/projection/mercator_transform.ts +2 -1
  44. package/src/geo/projection/mercator_utils.test.ts +8 -8
  45. package/src/geo/projection/projection.ts +0 -27
  46. package/src/geo/projection/projection_data.ts +8 -0
  47. package/src/geo/projection/projection_factory.ts +3 -3
  48. package/src/geo/projection/vertical_perspective_projection.ts +3 -60
  49. package/src/geo/projection/vertical_perspective_transform.ts +16 -23
  50. package/src/geo/transform_interface.ts +1 -2
  51. package/src/index.test.ts +7 -12
  52. package/src/index.ts +4 -2
  53. package/src/render/glyph_manager.test.ts +7 -22
  54. package/src/render/painter.test.ts +2 -0
  55. package/src/render/painter.ts +8 -11
  56. package/src/render/subdivision.bench.ts +39 -0
  57. package/src/render/subdivision.test.ts +22 -23
  58. package/src/render/subdivision.ts +46 -0
  59. package/src/render/terrain.test.ts +68 -34
  60. package/src/render/terrain.ts +69 -26
  61. package/src/shaders/glsl/_projection_globe.fragment.glsl +12 -0
  62. package/src/shaders/glsl/_projection_globe.fragment.glsl.g.ts +2 -0
  63. package/src/shaders/glsl/_projection_globe.vertex.glsl +29 -10
  64. package/src/shaders/glsl/_projection_globe.vertex.glsl.g.ts +1 -1
  65. package/src/shaders/glsl/_projection_mercator.fragment.glsl +4 -0
  66. package/src/shaders/glsl/_projection_mercator.fragment.glsl.g.ts +2 -0
  67. package/src/shaders/glsl/line.fragment.glsl +2 -0
  68. package/src/shaders/glsl/line.fragment.glsl.g.ts +1 -1
  69. package/src/shaders/glsl/line_gradient.fragment.glsl +2 -0
  70. package/src/shaders/glsl/line_gradient.fragment.glsl.g.ts +1 -1
  71. package/src/shaders/glsl/line_gradient_sdf.fragment.glsl +2 -0
  72. package/src/shaders/glsl/line_gradient_sdf.fragment.glsl.g.ts +1 -1
  73. package/src/shaders/glsl/line_pattern.fragment.glsl +2 -0
  74. package/src/shaders/glsl/line_pattern.fragment.glsl.g.ts +1 -1
  75. package/src/shaders/glsl/line_sdf.fragment.glsl +2 -0
  76. package/src/shaders/glsl/line_sdf.fragment.glsl.g.ts +1 -1
  77. package/src/shaders/shaders.ts +4 -6
  78. package/src/source/canvas_source.test.ts +1 -1
  79. package/src/source/geojson_source.test.ts +32 -4
  80. package/src/source/geojson_source.ts +41 -0
  81. package/src/source/geojson_source_diff.test.ts +2 -2
  82. package/src/source/geojson_worker_source.test.ts +9 -5
  83. package/src/source/image_source.test.ts +137 -62
  84. package/src/source/image_source.ts +49 -12
  85. package/src/source/raster_dem_tile_source.test.ts +2 -2
  86. package/src/source/raster_tile_source.test.ts +64 -9
  87. package/src/source/raster_tile_source.ts +2 -1
  88. package/src/source/rtl_text_plugin_main_thread.test.ts +14 -14
  89. package/src/source/source.test.ts +8 -8
  90. package/src/source/vector_tile_source.test.ts +1 -1
  91. package/src/source/vector_tile_worker_source.test.ts +7 -5
  92. package/src/source/video_source.test.ts +1 -1
  93. package/src/source/worker.test.ts +1 -1
  94. package/src/source/worker_tile.test.ts +10 -8
  95. package/src/style/light.test.ts +9 -9
  96. package/src/style/light.ts +3 -3
  97. package/src/style/load_glyph_range.test.ts +8 -8
  98. package/src/style/load_sprite.test.ts +1 -1
  99. package/src/style/properties.test.ts +94 -2
  100. package/src/style/properties.ts +30 -1
  101. package/src/style/sky.test.ts +9 -9
  102. package/src/style/sky.ts +2 -2
  103. package/src/style/style.test.ts +38 -36
  104. package/src/style/style.ts +3 -3
  105. package/src/style/style_layer/color_relief_style_layer.test.ts +1 -1
  106. package/src/style/style_layer/fill_extrusion_style_layer.ts +6 -3
  107. package/src/style/style_layer/fill_extrusion_style_layer_properties.g.ts +14 -1
  108. package/src/style/style_layer/raster_style_layer.test.ts +2 -2
  109. package/src/style/style_layer.test.ts +5 -51
  110. package/src/style/validate_style.test.ts +1 -1
  111. package/src/symbol/collision_index.test.ts +1 -1
  112. package/src/symbol/grid_index.test.ts +1 -1
  113. package/src/tile/terrain_tile_manager.test.ts +2 -2
  114. package/src/tile/tile_id.test.ts +5 -5
  115. package/src/tile/tile_manager.test.ts +113 -72
  116. package/src/tile/tile_manager.ts +2 -2
  117. package/src/tile/tile_manager_in_view_tiles.test.ts +2 -2
  118. package/src/ui/camera.test.ts +138 -135
  119. package/src/ui/control/geolocate_control.test.ts +7 -30
  120. package/src/ui/handler/dblclick_zoom.test.ts +2 -2
  121. package/src/ui/handler/mouse.ts +15 -7
  122. package/src/ui/handler/mouse_handler_interface.test.ts +21 -1
  123. package/src/ui/handler/scroll_zoom.test.ts +2 -0
  124. package/src/ui/handler_manager.test.ts +7 -7
  125. package/src/ui/hash.test.ts +1 -0
  126. package/src/ui/map.ts +45 -20
  127. package/src/ui/map_tests/map_basic.test.ts +11 -23
  128. package/src/ui/map_tests/map_calculate_camera_options.test.ts +6 -6
  129. package/src/ui/map_tests/map_events.test.ts +5 -7
  130. package/src/ui/map_tests/map_global_state.test.ts +3 -3
  131. package/src/ui/map_tests/map_images.test.ts +4 -3
  132. package/src/ui/map_tests/map_is_moving.test.ts +1 -1
  133. package/src/ui/map_tests/map_is_rotating.test.ts +1 -1
  134. package/src/ui/map_tests/map_layer.test.ts +2 -1
  135. package/src/ui/map_tests/map_options.test.ts +1 -5
  136. package/src/ui/map_tests/map_pitch.test.ts +6 -6
  137. package/src/ui/map_tests/map_refresh_tiles.test.ts +2 -2
  138. package/src/ui/map_tests/map_render.test.ts +1 -1
  139. package/src/ui/map_tests/map_set_lod_params.test.ts +1 -1
  140. package/src/ui/map_tests/map_style.test.ts +9 -1
  141. package/src/ui/map_tests/map_terrain.test.ts +41 -1
  142. package/src/ui/map_tests/map_zoom.test.ts +15 -15
  143. package/src/ui/marker.test.ts +71 -14
  144. package/src/ui/marker.ts +30 -6
  145. package/src/ui/popup.test.ts +3 -3
  146. package/src/util/actor.test.ts +6 -6
  147. package/src/util/ajax.test.ts +27 -39
  148. package/src/util/browser.test.ts +7 -9
  149. package/src/util/create_tile_mesh.test.ts +2 -2
  150. package/src/util/dispatcher.test.ts +1 -1
  151. package/src/util/evented.test.ts +4 -1
  152. package/src/util/fast_maths.test.ts +4 -4
  153. package/src/util/image_request.test.ts +6 -4
  154. package/src/util/primitives/bounding_volume_cache.ts +3 -1
  155. package/src/util/struct_array.test.ts +2 -2
  156. package/src/util/task_queue.test.ts +1 -1
  157. package/src/util/test/util.ts +1 -0
  158. package/src/util/time_control.test.ts +2 -2
  159. package/src/util/transferable_grid_index.test.ts +1 -1
  160. package/src/util/util.test.ts +27 -13
  161. package/src/util/verticalize_punctuation.test.ts +4 -4
  162. package/src/util/web_worker_transfer.test.ts +5 -5
  163. package/src/webgl/draw/draw_custom.test.ts +13 -13
  164. package/src/webgl/draw/draw_debug.test.ts +1 -1
  165. package/src/webgl/draw/draw_fill.test.ts +13 -12
  166. package/src/webgl/draw/draw_symbol.test.ts +17 -16
  167. package/src/webgl/program/program_uniforms.ts +0 -3
  168. package/src/webgl/program/projection_program.ts +12 -10
  169. package/src/webgl/program/terrain_program.test.ts +2 -2
  170. package/src/webgl/program.ts +6 -4
  171. package/src/webgl/render_to_texture.test.ts +5 -5
  172. package/src/webgl/state.test.ts +1 -1
  173. package/src/webgl/texture.test.ts +3 -3
  174. package/src/webgl/vertex_buffer.test.ts +1 -1
  175. package/build/rolldown_plugins.ts +0 -18
  176. package/src/geo/projection/globe_projection_error_measurement.ts +0 -229
  177. package/src/shaders/glsl/projection_error_measurement.fragment.glsl +0 -5
  178. package/src/shaders/glsl/projection_error_measurement.fragment.glsl.g.ts +0 -2
  179. package/src/shaders/glsl/projection_error_measurement.vertex.glsl +0 -22
  180. package/src/shaders/glsl/projection_error_measurement.vertex.glsl.g.ts +0 -2
  181. package/src/webgl/program/projection_error_measurement_program.ts +0 -23
@@ -5,6 +5,9 @@ uniform highp vec4 u_projection_clipping_plane;
5
5
  uniform highp float u_projection_transition;
6
6
  uniform mat4 u_projection_fallback_matrix;
7
7
 
8
+ // The in-tile X coordinate of the projected vertex, used by clipAntimeridian() in the fragment shader (see _projection_globe.fragment.glsl).
9
+ out highp float v_projection_tile_x;
10
+
8
11
  vec3 globeRotateVector(vec3 vec, vec2 angles) {
9
12
  vec3 axisRight = vec3(vec.z, 0.0, -vec.x); // Equivalent to cross(vec3(0.0, 1.0, 0.0), vec)
10
13
  vec3 axisUp = cross(axisRight, vec);
@@ -30,12 +33,13 @@ mat3 globeGetRotationMatrix(vec3 spherePos) {
30
33
  // Use `projectLineThickness` or `projectCircleRadius` instead.
31
34
  float circumferenceRatioAtTileY(float tileY) {
32
35
  float mercator_pos_y = u_projection_tile_mercator_coords.y + u_projection_tile_mercator_coords.w * tileY;
33
- float spherical_y = 2.0 * atan(exp(PI - (mercator_pos_y * PI * 2.0))) - PI * 0.5;
34
- return cos(spherical_y);
36
+ // cos(spherical_y) derived algebraically from exp(), see projectToSphere below.
37
+ float t = exp(PI - (mercator_pos_y * PI * 2.0));
38
+ return (2.0 * t) / (t * t + 1.0);
35
39
  }
36
40
 
37
41
  float projectLineThickness(float tileY) {
38
- float thickness = 1.0 / circumferenceRatioAtTileY(tileY);
42
+ float thickness = 1.0 / circumferenceRatioAtTileY(tileY);
39
43
  if (u_projection_transition < 0.999) {
40
44
  return mix(1.0, thickness, u_projection_transition);
41
45
  } else {
@@ -52,15 +56,28 @@ vec3 projectToSphere(vec2 translatedPos, vec2 rawPos) {
52
56
  vec2 mercator_pos = u_projection_tile_mercator_coords.xy + u_projection_tile_mercator_coords.zw * translatedPos;
53
57
 
54
58
  // Now compute angular coordinates on the surface of a perfect sphere
55
- vec2 spherical;
56
- spherical.x = mercator_pos.x * PI * 2.0 + PI;
57
- spherical.y = 2.0 * atan(exp(PI - (mercator_pos.y * PI * 2.0))) - PI * 0.5;
59
+ float spherical_x = mercator_pos.x * PI * 2.0 + PI;
60
+
61
+ // sin_sy/cos_sy are sin(spherical_y)/cos(spherical_y), where
62
+ // spherical_y = 2*atan(exp(PI - mercator_pos.y*2*PI)) - PI/2 (the Gudermannian
63
+ // function, converting mercator Y to latitude). The direct formula subtracts
64
+ // PI/2 from a value near PI/2, destroying most float32 mantissa bits near the
65
+ // equator, and some GPUs (e.g. Mali) have imprecise atan/sin/cos besides.
66
+ // Substituting t = exp(PI - mercator_pos.y*2*PI) and expanding via the
67
+ // tangent half-angle (Weierstrass) identities eliminates atan, sin and cos
68
+ // entirely, leaving only exp() and rational arithmetic:
69
+ // sin(2*atan(t) - PI/2) = (t^2 - 1) / (t^2 + 1)
70
+ // cos(2*atan(t) - PI/2) = 2*t / (t^2 + 1)
71
+ float t = exp(PI - (mercator_pos.y * PI * 2.0));
72
+ float t2 = t * t;
73
+ float denom = t2 + 1.0;
74
+ float sin_sy = (t2 - 1.0) / denom;
75
+ float cos_sy = (2.0 * t) / denom;
58
76
 
59
- float len = cos(spherical.y);
60
77
  vec3 pos = vec3(
61
- sin(spherical.x) * len,
62
- sin(spherical.y),
63
- cos(spherical.x) * len
78
+ sin(spherical_x) * cos_sy,
79
+ sin_sy,
80
+ cos(spherical_x) * cos_sy
64
81
  );
65
82
 
66
83
  // North pole
@@ -84,6 +101,7 @@ float globeComputeClippingZ(vec3 spherePos) {
84
101
  }
85
102
 
86
103
  vec4 interpolateProjection(vec2 posInTile, vec3 spherePos, float elevation) {
104
+ v_projection_tile_x = posInTile.x;
87
105
  vec3 elevatedPos = spherePos * (1.0 + elevation / GLOBE_RADIUS);
88
106
  vec4 globePosition = u_projection_matrix * vec4(elevatedPos, 1.0);
89
107
  // Z is overwritten by glDepthRange anyway - use a custom z value to clip geometry on the invisible side of the sphere.
@@ -113,6 +131,7 @@ vec4 interpolateProjection(vec2 posInTile, vec3 spherePos, float elevation) {
113
131
 
114
132
  // Unlike interpolateProjection, this variant of the function preserves the Z value of the final vector.
115
133
  vec4 interpolateProjectionFor3D(vec2 posInTile, vec3 spherePos, float elevation) {
134
+ v_projection_tile_x = posInTile.x;
116
135
  vec3 elevatedPos = spherePos * (1.0 + elevation / GLOBE_RADIUS);
117
136
  vec4 globePosition = u_projection_matrix * vec4(elevatedPos, 1.0);
118
137
 
@@ -1,2 +1,2 @@
1
1
  // This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
2
- export default '#define GLOBE_RADIUS 6371008.8\nuniform highp vec4 u_projection_tile_mercator_coords;uniform highp vec4 u_projection_clipping_plane;uniform highp float u_projection_transition;uniform mat4 u_projection_fallback_matrix;vec3 globeRotateVector(vec3 vec,vec2 angles) {vec3 axisRight=vec3(vec.z,0.0,-vec.x);vec3 axisUp=cross(axisRight,vec);axisRight=normalize(axisRight);axisUp=normalize(axisUp);vec2 t=tan(angles);return normalize(vec+axisRight*t.x+axisUp*t.y);}mat3 globeGetRotationMatrix(vec3 spherePos) {vec3 axisRight=vec3(spherePos.z,0.0,-spherePos.x);vec3 axisDown=cross(axisRight,spherePos);axisRight=normalize(axisRight);axisDown=normalize(axisDown);return mat3(axisRight,axisDown,spherePos\n);}float circumferenceRatioAtTileY(float tileY) {float mercator_pos_y=u_projection_tile_mercator_coords.y+u_projection_tile_mercator_coords.w*tileY;float spherical_y=2.0*atan(exp(PI-(mercator_pos_y*PI*2.0)))-PI*0.5;return cos(spherical_y);}float projectLineThickness(float tileY) {float thickness=1.0/circumferenceRatioAtTileY(tileY); \nif (u_projection_transition < 0.999) {return mix(1.0,thickness,u_projection_transition);} else {return thickness;}}vec3 projectToSphere(vec2 translatedPos,vec2 rawPos) {vec2 mercator_pos=u_projection_tile_mercator_coords.xy+u_projection_tile_mercator_coords.zw*translatedPos;vec2 spherical;spherical.x=mercator_pos.x*PI*2.0+PI;spherical.y=2.0*atan(exp(PI-(mercator_pos.y*PI*2.0)))-PI*0.5;float len=cos(spherical.y);vec3 pos=vec3(sin(spherical.x)*len,sin(spherical.y),cos(spherical.x)*len\n);if (rawPos.y <-32767.5) {pos=vec3(0.0,1.0,0.0);}if (rawPos.y > 32766.5) {pos=vec3(0.0,-1.0,0.0);}return pos;}vec3 projectToSphere(vec2 posInTile) {return projectToSphere(posInTile,vec2(0.0,0.0));}float globeComputeClippingZ(vec3 spherePos) {return (1.0-(dot(spherePos,u_projection_clipping_plane.xyz)+u_projection_clipping_plane.w));}vec4 interpolateProjection(vec2 posInTile,vec3 spherePos,float elevation) {vec3 elevatedPos=spherePos*(1.0+elevation/GLOBE_RADIUS);vec4 globePosition=u_projection_matrix*vec4(elevatedPos,1.0);globePosition.z=globeComputeClippingZ(elevatedPos)*globePosition.w;if (u_projection_transition > 0.999) {return globePosition;}vec4 flatPosition=u_projection_fallback_matrix*vec4(posInTile,elevation,1.0);const float z_globeness_threshold=0.2;vec4 result=globePosition;result.z=mix(0.0,globePosition.z,clamp((u_projection_transition-z_globeness_threshold)/(1.0-z_globeness_threshold),0.0,1.0));result.xyw=mix(flatPosition.xyw,globePosition.xyw,u_projection_transition);if ((posInTile.y <-32767.5) || (posInTile.y > 32766.5)) {result=globePosition;const float poles_hidden_anim_percentage=0.02;result.z=mix(globePosition.z,100.0,pow(max((1.0-u_projection_transition)/poles_hidden_anim_percentage,0.0),8.0));}return result;}vec4 interpolateProjectionFor3D(vec2 posInTile,vec3 spherePos,float elevation) {vec3 elevatedPos=spherePos*(1.0+elevation/GLOBE_RADIUS);vec4 globePosition=u_projection_matrix*vec4(elevatedPos,1.0);if (u_projection_transition > 0.999) {return globePosition;}vec4 fallbackPosition=u_projection_fallback_matrix*vec4(posInTile,elevation,1.0);return mix(fallbackPosition,globePosition,u_projection_transition);}vec4 projectTile(vec2 posInTile) {return interpolateProjection(posInTile,projectToSphere(posInTile),0.0);}vec4 projectTile(vec2 posInTile,vec2 rawPos) {return interpolateProjection(posInTile,projectToSphere(posInTile,rawPos),0.0);}vec4 projectTileWithElevation(vec2 posInTile,float elevation) {return interpolateProjection(posInTile,projectToSphere(posInTile),elevation);}vec4 projectTileFor3D(vec2 posInTile,float elevation) {vec3 spherePos=projectToSphere(posInTile,posInTile);return interpolateProjectionFor3D(posInTile,spherePos,elevation);}';
2
+ export default '#define GLOBE_RADIUS 6371008.8\nuniform highp vec4 u_projection_tile_mercator_coords;uniform highp vec4 u_projection_clipping_plane;uniform highp float u_projection_transition;uniform mat4 u_projection_fallback_matrix;out highp float v_projection_tile_x;vec3 globeRotateVector(vec3 vec,vec2 angles) {vec3 axisRight=vec3(vec.z,0.0,-vec.x);vec3 axisUp=cross(axisRight,vec);axisRight=normalize(axisRight);axisUp=normalize(axisUp);vec2 t=tan(angles);return normalize(vec+axisRight*t.x+axisUp*t.y);}mat3 globeGetRotationMatrix(vec3 spherePos) {vec3 axisRight=vec3(spherePos.z,0.0,-spherePos.x);vec3 axisDown=cross(axisRight,spherePos);axisRight=normalize(axisRight);axisDown=normalize(axisDown);return mat3(axisRight,axisDown,spherePos\n);}float circumferenceRatioAtTileY(float tileY) {float mercator_pos_y=u_projection_tile_mercator_coords.y+u_projection_tile_mercator_coords.w*tileY;float t=exp(PI-(mercator_pos_y*PI*2.0));return (2.0*t)/(t*t+1.0);}float projectLineThickness(float tileY) {float thickness=1.0/circumferenceRatioAtTileY(tileY);if (u_projection_transition < 0.999) {return mix(1.0,thickness,u_projection_transition);} else {return thickness;}}vec3 projectToSphere(vec2 translatedPos,vec2 rawPos) {vec2 mercator_pos=u_projection_tile_mercator_coords.xy+u_projection_tile_mercator_coords.zw*translatedPos;float spherical_x=mercator_pos.x*PI*2.0+PI;float t=exp(PI-(mercator_pos.y*PI*2.0));float t2=t*t;float denom=t2+1.0;float sin_sy=(t2-1.0)/denom;float cos_sy=(2.0*t)/denom;vec3 pos=vec3(sin(spherical_x)*cos_sy,sin_sy,cos(spherical_x)*cos_sy\n);if (rawPos.y <-32767.5) {pos=vec3(0.0,1.0,0.0);}if (rawPos.y > 32766.5) {pos=vec3(0.0,-1.0,0.0);}return pos;}vec3 projectToSphere(vec2 posInTile) {return projectToSphere(posInTile,vec2(0.0,0.0));}float globeComputeClippingZ(vec3 spherePos) {return (1.0-(dot(spherePos,u_projection_clipping_plane.xyz)+u_projection_clipping_plane.w));}vec4 interpolateProjection(vec2 posInTile,vec3 spherePos,float elevation) {v_projection_tile_x=posInTile.x;vec3 elevatedPos=spherePos*(1.0+elevation/GLOBE_RADIUS);vec4 globePosition=u_projection_matrix*vec4(elevatedPos,1.0);globePosition.z=globeComputeClippingZ(elevatedPos)*globePosition.w;if (u_projection_transition > 0.999) {return globePosition;}vec4 flatPosition=u_projection_fallback_matrix*vec4(posInTile,elevation,1.0);const float z_globeness_threshold=0.2;vec4 result=globePosition;result.z=mix(0.0,globePosition.z,clamp((u_projection_transition-z_globeness_threshold)/(1.0-z_globeness_threshold),0.0,1.0));result.xyw=mix(flatPosition.xyw,globePosition.xyw,u_projection_transition);if ((posInTile.y <-32767.5) || (posInTile.y > 32766.5)) {result=globePosition;const float poles_hidden_anim_percentage=0.02;result.z=mix(globePosition.z,100.0,pow(max((1.0-u_projection_transition)/poles_hidden_anim_percentage,0.0),8.0));}return result;}vec4 interpolateProjectionFor3D(vec2 posInTile,vec3 spherePos,float elevation) {v_projection_tile_x=posInTile.x;vec3 elevatedPos=spherePos*(1.0+elevation/GLOBE_RADIUS);vec4 globePosition=u_projection_matrix*vec4(elevatedPos,1.0);if (u_projection_transition > 0.999) {return globePosition;}vec4 fallbackPosition=u_projection_fallback_matrix*vec4(posInTile,elevation,1.0);return mix(fallbackPosition,globePosition,u_projection_transition);}vec4 projectTile(vec2 posInTile) {return interpolateProjection(posInTile,projectToSphere(posInTile),0.0);}vec4 projectTile(vec2 posInTile,vec2 rawPos) {return interpolateProjection(posInTile,projectToSphere(posInTile,rawPos),0.0);}vec4 projectTileWithElevation(vec2 posInTile,float elevation) {return interpolateProjection(posInTile,projectToSphere(posInTile),elevation);}vec4 projectTileFor3D(vec2 posInTile,float elevation) {vec3 spherePos=projectToSphere(posInTile,posInTile);return interpolateProjectionFor3D(posInTile,spherePos,elevation);}';
@@ -0,0 +1,4 @@
1
+ // Under mercator projection tile buffer geometry never wraps around the planet,
2
+ // so no fragments need to be discarded. See _projection_globe.fragment.glsl.
3
+ void clipAntimeridian() {
4
+ }
@@ -0,0 +1,2 @@
1
+ // This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
2
+ export default '\nvoid clipAntimeridian() {}';
@@ -16,6 +16,8 @@ void main() {
16
16
  #pragma maplibre: initialize lowp float blur
17
17
  #pragma maplibre: initialize lowp float opacity
18
18
 
19
+ clipAntimeridian();
20
+
19
21
  // Calculate the distance of the pixel from the line in pixels.
20
22
  float dist = length(v_normal) * v_width2.s;
21
23
 
@@ -1,2 +1,2 @@
1
1
  // This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
2
- export default 'uniform lowp float u_device_pixel_ratio;flat in vec2 v_width2;in vec2 v_normal;in float v_gamma_scale;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define highp vec4 color\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize highp vec4 color\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);fragColor=color*(alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
2
+ export default 'uniform lowp float u_device_pixel_ratio;flat in vec2 v_width2;in vec2 v_normal;in float v_gamma_scale;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define highp vec4 color\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize highp vec4 color\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\nclipAntimeridian();float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);fragColor=color*(alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
@@ -16,6 +16,8 @@ void main() {
16
16
  #pragma maplibre: initialize lowp float blur
17
17
  #pragma maplibre: initialize lowp float opacity
18
18
 
19
+ clipAntimeridian();
20
+
19
21
  // Calculate the distance of the pixel from the line in pixels.
20
22
  float dist = length(v_normal) * v_width2.s;
21
23
 
@@ -1,2 +1,2 @@
1
1
  // This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
2
- export default 'uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;flat in vec2 v_width2;in vec2 v_normal;in float v_gamma_scale;in highp vec2 v_uv;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);vec4 color=texture(u_image,v_uv);fragColor=color*(alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
2
+ export default 'uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;flat in vec2 v_width2;in vec2 v_normal;in float v_gamma_scale;in highp vec2 v_uv;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\nclipAntimeridian();float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);vec4 color=texture(u_image,v_uv);fragColor=color*(alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
@@ -29,6 +29,8 @@ void main() {
29
29
  #pragma maplibre: initialize mediump vec4 dasharray_from
30
30
  #pragma maplibre: initialize mediump vec4 dasharray_to
31
31
 
32
+ clipAntimeridian();
33
+
32
34
  // Calculate the distance of the pixel from the line in pixels.
33
35
  float dist = length(v_normal) * v_width2.s;
34
36
 
@@ -1,2 +1,2 @@
1
1
  // This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
2
- export default 'uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;uniform sampler2D u_image_dash;uniform float u_mix;uniform lowp float u_lineatlas_width;in vec2 v_normal;flat in vec2 v_width2;in vec2 v_tex_a;in vec2 v_tex_b;in float v_gamma_scale;in highp vec2 v_uv;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define mediump float width\n#pragma maplibre: define lowp float floorwidth\n#pragma maplibre: define mediump vec4 dasharray_from\n#pragma maplibre: define mediump vec4 dasharray_to\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float width\n#pragma maplibre: initialize lowp float floorwidth\n#pragma maplibre: initialize mediump vec4 dasharray_from\n#pragma maplibre: initialize mediump vec4 dasharray_to\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);vec4 color=texture(u_image,v_uv);float sdfdist_a=texture(u_image_dash,v_tex_a).a;float sdfdist_b=texture(u_image_dash,v_tex_b).a;float sdfdist=mix(sdfdist_a,sdfdist_b,u_mix);float sdfgamma=(u_lineatlas_width/256.0)/min(dasharray_from.w,dasharray_to.w);float dash_alpha=smoothstep(0.5-sdfgamma/floorwidth,0.5+sdfgamma/floorwidth,sdfdist);fragColor=color*(alpha*dash_alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
2
+ export default 'uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;uniform sampler2D u_image_dash;uniform float u_mix;uniform lowp float u_lineatlas_width;in vec2 v_normal;flat in vec2 v_width2;in vec2 v_tex_a;in vec2 v_tex_b;in float v_gamma_scale;in highp vec2 v_uv;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define mediump float width\n#pragma maplibre: define lowp float floorwidth\n#pragma maplibre: define mediump vec4 dasharray_from\n#pragma maplibre: define mediump vec4 dasharray_to\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float width\n#pragma maplibre: initialize lowp float floorwidth\n#pragma maplibre: initialize mediump vec4 dasharray_from\n#pragma maplibre: initialize mediump vec4 dasharray_to\nclipAntimeridian();float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);vec4 color=texture(u_image,v_uv);float sdfdist_a=texture(u_image_dash,v_tex_a).a;float sdfdist_b=texture(u_image_dash,v_tex_b).a;float sdfdist=mix(sdfdist_a,sdfdist_b,u_mix);float sdfgamma=(u_lineatlas_width/256.0)/min(dasharray_from.w,dasharray_to.w);float dash_alpha=smoothstep(0.5-sdfgamma/floorwidth,0.5+sdfgamma/floorwidth,sdfdist);fragColor=color*(alpha*dash_alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
@@ -33,6 +33,8 @@ void main() {
33
33
  #pragma maplibre: initialize lowp float blur
34
34
  #pragma maplibre: initialize lowp float opacity
35
35
 
36
+ clipAntimeridian();
37
+
36
38
  vec2 pattern_tl_a = pattern_from.xy;
37
39
  vec2 pattern_br_a = pattern_from.zw;
38
40
  vec2 pattern_tl_b = pattern_to.xy;
@@ -1,2 +1,2 @@
1
1
  // This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
2
- export default '#ifdef GL_ES\nprecision highp float;\n#endif\nuniform lowp float u_device_pixel_ratio;uniform vec2 u_texsize;uniform float u_fade;uniform mediump vec3 u_scale;uniform sampler2D u_image;in vec2 v_normal;flat in vec2 v_width2;in float v_linesofar;in float v_gamma_scale;flat in float v_width;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp vec4 pattern_from\n#pragma maplibre: define lowp vec4 pattern_to\n#pragma maplibre: define lowp float pixel_ratio_from\n#pragma maplibre: define lowp float pixel_ratio_to\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize mediump vec4 pattern_from\n#pragma maplibre: initialize mediump vec4 pattern_to\n#pragma maplibre: initialize lowp float pixel_ratio_from\n#pragma maplibre: initialize lowp float pixel_ratio_to\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileZoomRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;vec2 pattern_size_a=vec2(display_size_a.x*fromScale/tileZoomRatio,display_size_a.y);vec2 pattern_size_b=vec2(display_size_b.x*toScale/tileZoomRatio,display_size_b.y);float aspect_a=display_size_a.y/v_width;float aspect_b=display_size_b.y/v_width;float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float x_a=mod(v_linesofar/pattern_size_a.x*aspect_a,1.0);float x_b=mod(v_linesofar/pattern_size_b.x*aspect_b,1.0);float y=0.5*v_normal.y+0.5;vec2 texel_size=1.0/u_texsize;vec2 pos_a=mix(pattern_tl_a*texel_size-texel_size,pattern_br_a*texel_size+texel_size,vec2(x_a,y));vec2 pos_b=mix(pattern_tl_b*texel_size-texel_size,pattern_br_b*texel_size+texel_size,vec2(x_b,y));vec4 color=mix(texture(u_image,pos_a),texture(u_image,pos_b),u_fade);fragColor=color*alpha*opacity;\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
2
+ export default '#ifdef GL_ES\nprecision highp float;\n#endif\nuniform lowp float u_device_pixel_ratio;uniform vec2 u_texsize;uniform float u_fade;uniform mediump vec3 u_scale;uniform sampler2D u_image;in vec2 v_normal;flat in vec2 v_width2;in float v_linesofar;in float v_gamma_scale;flat in float v_width;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define lowp vec4 pattern_from\n#pragma maplibre: define lowp vec4 pattern_to\n#pragma maplibre: define lowp float pixel_ratio_from\n#pragma maplibre: define lowp float pixel_ratio_to\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize mediump vec4 pattern_from\n#pragma maplibre: initialize mediump vec4 pattern_to\n#pragma maplibre: initialize lowp float pixel_ratio_from\n#pragma maplibre: initialize lowp float pixel_ratio_to\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\nclipAntimeridian();vec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileZoomRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;vec2 pattern_size_a=vec2(display_size_a.x*fromScale/tileZoomRatio,display_size_a.y);vec2 pattern_size_b=vec2(display_size_b.x*toScale/tileZoomRatio,display_size_b.y);float aspect_a=display_size_a.y/v_width;float aspect_b=display_size_b.y/v_width;float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float x_a=mod(v_linesofar/pattern_size_a.x*aspect_a,1.0);float x_b=mod(v_linesofar/pattern_size_b.x*aspect_b,1.0);float y=0.5*v_normal.y+0.5;vec2 texel_size=1.0/u_texsize;vec2 pos_a=mix(pattern_tl_a*texel_size-texel_size,pattern_br_a*texel_size+texel_size,vec2(x_a,y));vec2 pos_b=mix(pattern_tl_b*texel_size-texel_size,pattern_br_b*texel_size+texel_size,vec2(x_b,y));vec4 color=mix(texture(u_image,pos_a),texture(u_image,pos_b),u_fade);fragColor=color*alpha*opacity;\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
@@ -30,6 +30,8 @@ void main() {
30
30
  #pragma maplibre: initialize mediump vec4 dasharray_from
31
31
  #pragma maplibre: initialize mediump vec4 dasharray_to
32
32
 
33
+ clipAntimeridian();
34
+
33
35
  // Calculate the distance of the pixel from the line in pixels.
34
36
  float dist = length(v_normal) * v_width2.s;
35
37
 
@@ -1,2 +1,2 @@
1
1
  // This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
2
- export default 'uniform lowp float u_device_pixel_ratio;uniform lowp float u_lineatlas_width;uniform sampler2D u_image;uniform float u_mix;in vec2 v_normal;flat in vec2 v_width2;in vec2 v_tex_a;in vec2 v_tex_b;in float v_gamma_scale;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define highp vec4 color\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define mediump float width\n#pragma maplibre: define lowp float floorwidth\n#pragma maplibre: define mediump vec4 dasharray_from\n#pragma maplibre: define mediump vec4 dasharray_to\nvoid main() {\n#pragma maplibre: initialize highp vec4 color\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float width\n#pragma maplibre: initialize lowp float floorwidth\n#pragma maplibre: initialize mediump vec4 dasharray_from\n#pragma maplibre: initialize mediump vec4 dasharray_to\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float sdfdist_a=texture(u_image,v_tex_a).a;float sdfdist_b=texture(u_image,v_tex_b).a;float sdfdist=mix(sdfdist_a,sdfdist_b,u_mix);float sdfgamma=(u_lineatlas_width/256.0/u_device_pixel_ratio)/min(dasharray_from.w,dasharray_to.w);alpha*=smoothstep(0.5-sdfgamma/floorwidth,0.5+sdfgamma/floorwidth,sdfdist);fragColor=color*(alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
2
+ export default 'uniform lowp float u_device_pixel_ratio;uniform lowp float u_lineatlas_width;uniform sampler2D u_image;uniform float u_mix;in vec2 v_normal;flat in vec2 v_width2;in vec2 v_tex_a;in vec2 v_tex_b;in float v_gamma_scale;\n#ifdef GLOBE\nin float v_depth;\n#endif\n#pragma maplibre: define highp vec4 color\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define mediump float width\n#pragma maplibre: define lowp float floorwidth\n#pragma maplibre: define mediump vec4 dasharray_from\n#pragma maplibre: define mediump vec4 dasharray_to\nvoid main() {\n#pragma maplibre: initialize highp vec4 color\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float width\n#pragma maplibre: initialize lowp float floorwidth\n#pragma maplibre: initialize mediump vec4 dasharray_from\n#pragma maplibre: initialize mediump vec4 dasharray_to\nclipAntimeridian();float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float sdfdist_a=texture(u_image,v_tex_a).a;float sdfdist_b=texture(u_image,v_tex_b).a;float sdfdist=mix(sdfdist_a,sdfdist_b,u_mix);float sdfgamma=(u_lineatlas_width/256.0/u_device_pixel_ratio)/min(dasharray_from.w,dasharray_to.w);alpha*=smoothstep(0.5-sdfgamma/floorwidth,0.5+sdfgamma/floorwidth,sdfdist);fragColor=color*(alpha*opacity);\n#ifdef GLOBE\nif (v_depth > 1.0) {discard;}\n#endif\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}';
@@ -65,10 +65,10 @@ import terrainFrag from './glsl/terrain.fragment.glsl.g.ts';
65
65
  import terrainVert from './glsl/terrain.vertex.glsl.g.ts';
66
66
  import terrainVertDepth from './glsl/terrain_depth.vertex.glsl.g.ts';
67
67
  import terrainVertCoords from './glsl/terrain_coords.vertex.glsl.g.ts';
68
- import projectionErrorMeasurementVert from './glsl/projection_error_measurement.vertex.glsl.g.ts';
69
- import projectionErrorMeasurementFrag from './glsl/projection_error_measurement.fragment.glsl.g.ts';
70
68
  import projectionMercatorVert from './glsl/_projection_mercator.vertex.glsl.g.ts';
69
+ import projectionMercatorFrag from './glsl/_projection_mercator.fragment.glsl.g.ts';
71
70
  import projectionGlobeVert from './glsl/_projection_globe.vertex.glsl.g.ts';
71
+ import projectionGlobeFrag from './glsl/_projection_globe.fragment.glsl.g.ts';
72
72
  import atmosphereFrag from './glsl/atmosphere.fragment.glsl.g.ts';
73
73
  import atmosphereVert from './glsl/atmosphere.vertex.glsl.g.ts';
74
74
  import skyFrag from './glsl/sky.fragment.glsl.g.ts';
@@ -117,13 +117,12 @@ export const shaders: {
117
117
  terrain: PreparedShader;
118
118
  terrainDepth: PreparedShader;
119
119
  terrainCoords: PreparedShader;
120
- projectionErrorMeasurement: PreparedShader;
121
120
  atmosphere: PreparedShader;
122
121
  sky: PreparedShader;
123
122
  } = {
124
123
  prelude: prepare(preludeFrag, preludeVert),
125
- projectionMercator: prepare('', projectionMercatorVert),
126
- projectionGlobe: prepare('', projectionGlobeVert),
124
+ projectionMercator: prepare(projectionMercatorFrag, projectionMercatorVert),
125
+ projectionGlobe: prepare(projectionGlobeFrag, projectionGlobeVert),
127
126
  background: prepare(backgroundFrag, backgroundVert),
128
127
  backgroundPattern: prepare(backgroundPatternFrag, backgroundPatternVert),
129
128
  circle: prepare(circleFrag, circleVert),
@@ -156,7 +155,6 @@ export const shaders: {
156
155
  terrain: prepare(terrainFrag, terrainVert),
157
156
  terrainDepth: prepare(terrainDepthFrag, terrainVertDepth),
158
157
  terrainCoords: prepare(terrainCoordsFrag, terrainVertCoords),
159
- projectionErrorMeasurement: prepare(projectionErrorMeasurementFrag, projectionErrorMeasurementVert),
160
158
  atmosphere: prepare(atmosphereFrag, atmosphereVert),
161
159
  sky: prepare(skyFrag, skyVert),
162
160
  };
@@ -69,7 +69,7 @@ describe('CanvasSource', () => {
69
69
  source.onAdd(map);
70
70
  await promise;
71
71
 
72
- expect(typeof source.play).toBe('function');
72
+ expect(source.play).toBeTypeOf('function');
73
73
  });
74
74
 
75
75
  describe('Validations', () => {
@@ -102,10 +102,11 @@ describe('GeoJSONSource.setData', () => {
102
102
  const source = createSource();
103
103
  const loadPromise = source.once('data');
104
104
  source.load();
105
- await loadPromise;
105
+ await expect(loadPromise).resolves.toBeDefined();
106
+
106
107
  const setDataPromise = source.once('data');
107
108
  source.setData({} as GeoJSON.GeoJSON);
108
- await setDataPromise;
109
+ await expect(setDataPromise).resolves.toBeDefined();
109
110
  });
110
111
 
111
112
  test('fires "dataloading" event', async () => {
@@ -545,8 +546,8 @@ describe('GeoJSONSource.update', () => {
545
546
  expect(spy.mock.calls[0][0].data.geojsonVtOptions.cluster).toBe(false);
546
547
  expect(spy.mock.calls[0][0].data.dataDiff).toEqual(diff);
547
548
  expect(spy.mock.calls[1][0].data.geojsonVtOptions.cluster).toBe(true);
548
- expect(spy.mock.calls[1][0].data.data).not.toBeDefined();
549
- expect(spy.mock.calls[1][0].data.dataDiff).not.toBeDefined();
549
+ expect(spy.mock.calls[1][0].data.data).toBeUndefined();
550
+ expect(spy.mock.calls[1][0].data.dataDiff).toBeUndefined();
550
551
  });
551
552
 
552
553
  test('forwards Supercluster options with worker request, ignore max zoom of source', async () => {
@@ -1312,3 +1313,30 @@ describe('GeoJSONSource.getClusterLeaves', () => {
1312
1313
  vi.resetAllMocks();
1313
1314
  });
1314
1315
  });
1316
+
1317
+ describe('GeoJSONSource.getClusterOptions', () => {
1318
+ test('returns the cluster options configured on the source', () => {
1319
+ const source = new GeoJSONSource('id', {
1320
+ type: 'geojson',
1321
+ data: {} as GeoJSON.GeoJSON,
1322
+ cluster: true,
1323
+ clusterMaxZoom: 12,
1324
+ clusterRadius: 80
1325
+ }, mockDispatcher, undefined);
1326
+
1327
+ expect(source.getClusterOptions()).toEqual({cluster: true, clusterMaxZoom: 12, clusterRadius: 80});
1328
+ });
1329
+
1330
+ test('reflects options updated via setClusterOptions', async () => {
1331
+ const source = new GeoJSONSource('id', {
1332
+ type: 'geojson',
1333
+ data: {} as GeoJSON.GeoJSON,
1334
+ cluster: false
1335
+ }, mockDispatcher, undefined);
1336
+
1337
+ const options = {cluster: true, clusterMaxZoom: 9, clusterRadius: 40};
1338
+ await source.setClusterOptions(options);
1339
+
1340
+ expect(source.getClusterOptions()).toEqual(options);
1341
+ });
1342
+ });
@@ -69,6 +69,24 @@ export type SetClusterOptions = {
69
69
  clusterRadius?: number;
70
70
  };
71
71
 
72
+ /**
73
+ * The cluster options currently configured on a source, as returned by `getClusterOptions`
74
+ */
75
+ export type GetClusterOptions = {
76
+ /**
77
+ * Whether or not the source is clustered
78
+ */
79
+ cluster: boolean;
80
+ /**
81
+ * The cluster's max zoom
82
+ */
83
+ clusterMaxZoom: number;
84
+ /**
85
+ * The cluster's radius, in pixels
86
+ */
87
+ clusterRadius: number;
88
+ };
89
+
72
90
  /**
73
91
  * A source containing GeoJSON.
74
92
  * (See the [Style Specification](https://maplibre.org/maplibre-style-spec/#sources-geojson) for detailed documentation of options.)
@@ -226,6 +244,10 @@ export class GeoJSONSource extends Evented<SourceEventType> implements Source {
226
244
  return pixelValue * (EXTENT / this.tileSize);
227
245
  }
228
246
 
247
+ private _tileUnitsToPixels(tileUnitValue: number): number {
248
+ return tileUnitValue / (EXTENT / this.tileSize);
249
+ }
250
+
229
251
  private _getClusterMaxZoom(clusterMaxZoom: number): number {
230
252
  const effectiveClusterMaxZoom = clusterMaxZoom ? Math.round(clusterMaxZoom) : this.maxzoom - 1;
231
253
  if (!(Number.isInteger(clusterMaxZoom) || clusterMaxZoom === undefined)) {
@@ -321,6 +343,25 @@ export class GeoJSONSource extends Evented<SourceEventType> implements Source {
321
343
  return this._updateWorkerData();
322
344
  }
323
345
 
346
+ /**
347
+ * Gets the cluster options currently configured on the source.
348
+ * The returned values mirror the options accepted by `setClusterOptions`.
349
+ *
350
+ * @returns the source's current cluster options
351
+ * @example
352
+ * ```ts
353
+ * const {cluster, clusterMaxZoom, clusterRadius} = map.getSource('some id').getClusterOptions();
354
+ * ```
355
+ */
356
+ getClusterOptions(): GetClusterOptions {
357
+ const {cluster, clusterOptions} = this.workerOptions.geojsonVtOptions;
358
+ return {
359
+ cluster,
360
+ clusterMaxZoom: clusterOptions.maxZoom,
361
+ clusterRadius: this._tileUnitsToPixels(clusterOptions.radius)
362
+ };
363
+ }
364
+
324
365
  /**
325
366
  * For clustered sources, fetches the zoom at which the given cluster expands.
326
367
  *
@@ -562,7 +562,7 @@ describe('mergeSourceDiffs', () => {
562
562
  } satisfies GeoJSONSourceDiff;
563
563
 
564
564
  const merged = mergeSourceDiffs(diff1, diff2);
565
- expect(merged.update.length).toBe(1);
565
+ expect(merged.update).toHaveLength(1);
566
566
  expect(merged.update[0].removeAllProperties).toBe(true);
567
567
  expect(merged.update[0].removeProperties).toBeUndefined();
568
568
  expect(merged.update[0].addOrUpdateProperties).toEqual([{key: 'fresh', value: 2}]);
@@ -604,7 +604,7 @@ describe('mergeSourceDiffs', () => {
604
604
 
605
605
  const merged = mergeSourceDiffs(diff1, diff2, 'promoted');
606
606
  expect(merged.add).toBeDefined();
607
- expect(merged.add.length).toBe(2);
607
+ expect(merged.add).toHaveLength(2);
608
608
  });
609
609
 
610
610
  test('merges two diffs update feature then remove', () => {
@@ -118,12 +118,13 @@ describe('geojson tile worker source', () => {
118
118
 
119
119
  await source.loadData({source: 'source', data: geoJson, geojsonVtOptions: {}} as LoadGeoJSONParameters);
120
120
 
121
+ const onSettled = vi.fn();
121
122
  source.loadTile({
122
123
  source: 'source',
123
124
  uid: 0,
124
125
  tileID: {overscaledZ: 0, wrap: 0, canonical: {x: 0, y: 0, z: 0, w: 0}},
125
126
  subdivisionGranularity: SubdivisionGranularitySetting.noSubdivision,
126
- } as any as WorkerTileParameters).then(() => expect(false).toBeTruthy());
127
+ } as any as WorkerTileParameters).then(onSettled, onSettled);
127
128
 
128
129
  // allow promise to run
129
130
  await sleep(0);
@@ -135,6 +136,7 @@ describe('geojson tile worker source', () => {
135
136
  subdivisionGranularity: SubdivisionGranularitySetting.noSubdivision,
136
137
  } as any as WorkerTileParameters) as WorkerTileWithData;
137
138
 
139
+ expect(onSettled).not.toHaveBeenCalled();
138
140
  expect(res).toBeDefined();
139
141
  expect(res.rawTileData).toBeDefined();
140
142
  });
@@ -187,12 +189,13 @@ describe('geojson tile worker source', () => {
187
189
 
188
190
  await source.loadData({source: 'source', data: geoJson, geojsonVtOptions: {}} as LoadGeoJSONParameters);
189
191
 
192
+ const onSettled = vi.fn();
190
193
  source.loadTile({
191
194
  source: 'source',
192
195
  uid: 0,
193
196
  tileID: {overscaledZ: 0, wrap: 0, canonical: {x: 0, y: 0, z: 0, w: 0}},
194
197
  subdivisionGranularity: SubdivisionGranularitySetting.noSubdivision,
195
- } as any as WorkerTileParameters).then(() => expect(false).toBeTruthy());
198
+ } as any as WorkerTileParameters).then(onSettled, onSettled);
196
199
 
197
200
  // allow promise to run
198
201
  await sleep(0);
@@ -211,6 +214,7 @@ describe('geojson tile worker source', () => {
211
214
  subdivisionGranularity: SubdivisionGranularitySetting.noSubdivision,
212
215
  } as any as WorkerTileParameters) as WorkerTileWithData;
213
216
 
217
+ expect(onSettled).not.toHaveBeenCalled();
214
218
  expect(res).toBeDefined();
215
219
  expect(res.rawTileData).toBeDefined();
216
220
  });
@@ -235,7 +239,7 @@ describe('geojson tile worker source', () => {
235
239
  source: 'source',
236
240
  uid: 0,
237
241
  tileID: {overscaledZ: 0, wrap: 0, canonical: {x: 0, y: 0, z: 0, w: 0}},
238
- } as any as WorkerTileParameters)).rejects.toThrowError(/Unable to parse the data into a cluster or geojson/);
242
+ } as any as WorkerTileParameters)).rejects.toThrow(/Unable to parse the data into a cluster or geojson/);
239
243
  });
240
244
 
241
245
  test('GeoJSONWorkerSource.abortTile aborts tile state', async () => {
@@ -434,8 +438,8 @@ describe('resourceTiming', () => {
434
438
  });
435
439
  return null;
436
440
  });
437
- vi.spyOn(performance, 'clearMarks').mockImplementation(() => null);
438
- vi.spyOn(performance, 'clearMeasures').mockImplementation(() => null);
441
+ vi.spyOn(performance, 'clearMarks').mockReturnValue(null);
442
+ vi.spyOn(performance, 'clearMeasures').mockReturnValue(null);
439
443
 
440
444
  const layerIndex = new StyleLayerIndex(layers);
441
445
  const source = new GeoJSONWorkerSource(actor, layerIndex, []);