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
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * MapLibre GL JS
3
- * @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v6.0.0/LICENSE.txt
3
+ * @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v6.2.0/LICENSE.txt
4
4
  */
5
- import { $n as findLineIntersection, $r as normalize, $t as validateStyle, A as earthRadius, Ai as rotate, Ar as warnOnce, At as SegmentVector, B as evaluateSizeForFeature, Bn as createMat4f64, Br as zero, Bt as isRasterStyleLayer, C as altitudeFromMercatorZ, Ci as rotateZ, Cn as addProtocol, Cr as rollPitchBearingToQuat, Ct as Uniform2f, D as mercatorYfromLat, Di as fromRotation, Dn as AbortError, Dr as threePlaneIntersection, Dt as UniformColorArray, E as mercatorXfromLng, Ei as create$4, En as config, Er as subscribe, Et as UniformColor, F as isBackgroundStyleLayer, Fn as bezier, Fr as create$3, Ft as PosArray, G as ImagePosition, Gn as degreesToRadians, Gr as transformMat4, Gt as EvaluationParameters, Hn as createVec4f64, Hr as slerp, Ht as Properties, I as isSymbolStyleLayer, In as clamp, Ir as length, It as QuadTriangleArray, J as parseGlyphPbf, Jn as easeCubicInOut, Jr as cross, Jt as ZoomHistory, K as potpack, Kn as differenceOfAnglesDegrees, Kr as add, L as SymbolBucket, Ln as clone$2, Lr as scale$1, Lt as RasterBoundsArray, M as createStyleLayer, Mi as offscreenCanvasSupported, Mn as angleToRotateBetweenVectors2D, Mr as zoomScale, Mt as CollisionCircleLayoutArray, N as isCustomStyleLayer, Ni as Point, Nn as arrayBufferToImage, Nr as pixelsToTileUnits, Nt as LineStripIndexArray, O as mercatorZfromAltitude, Oi as create$2, On as isAbortError, Or as translatePosition, Ot as UniformFloatArray, P as validateCustomStyleLayer, Pn as arrayBufferToImageBitmap, Pr as EXTENT, Pt as Pos3dArray, Qn as filterObject, Qr as negate, Qt as validateAndEmit, R as addDynamicAttributes, Rn as createIdentityMat4f32, Rr as sqrLen, Rt as TriangleIndexArray, S as MercatorCoordinate, Si as rotateY$1, Sn as sameOrigin, Sr as rollPitchBearingEqual, St as Uniform1i, T as lngFromMercatorX, Ti as translate, Tn as removeProtocol, Tr as sphericalToCartesian, Tt as Uniform4f, U as getAnchorAlignment, Un as deepEqual, Ur as mul, Ut as TRANSITION_SUFFIX, V as evaluateSizeForZoom, Vn as createVec3f64, Vr as fromEuler, Vt as DataConstantProperty, Wn as defaultEasing, Wr as scale$3, Wt as Transitionable, X as collisionCircleLayout, Xn as evaluateZoomSnap, Xr as len, Xt as SPEC_SOURCE_TYPES, Yn as ensureError, Yr as dot, Z as isLineStyleLayer, Zn as extend, Zr as length$1, Zt as emitValidationErrors, _ as OverscaledTileID, _i as invert$1, _n as getArrayBuffer, _r as pointPlaneSignedDistance, _t as RGBAImage, a as clipLine, ai as sub, an as derefLayers, ar as isImageBitmap, at as NORTH_POLE_Y, b as compareTileId, bi as perspective, bn as getVideo, br as readImageUsingVideoFrame, bt as toEvaluationFeature, ci as transformQuat, cn as featureFilter, cr as isTouchableEvent, ct as SubdivisionGranularitySetting, di as copy, dn as latest, dr as lerp, dt as Texture, ei as rotateX$1, en as validateStyleAndEmit, er as getAABB, et as isFillExtrusionStyleLayer, f as GEOJSON_TILE_LAYER_NAME, fi as create$1, fn as ErrorEvent, fr as mapObject, ft as isHillshadeStyleLayer, g as CanonicalTileID, gi as identity, gn as GLOBAL_DISPATCHER_ID, gr as pick, gt as AlphaImage, h as Bounds, hi as fromScaling, hn as AJAXError, hr as parseCacheControl, ht as renderColorRamp, ii as scaleAndAdd, ir as getRollPitchBearing, j as Actor, ji as isOffscreenCanvasDistorted, jn as MAX_VALID_LATITUDE, jr as wrap, jt as CollisionBoxArray, k as LngLat, ki as invert, kn as throwIfAborted, kr as uniqueId, kt as UniformMatrix4f, li as zero$1, lr as isTouchableOrPointableType, lt as isColorReliefStyleLayer, mi as exactEquals, mn as Evented, mr as nextPowerOfTwo, mt as isHeatmapStyleLayer, ni as rotateZ$1, nn as ProjectionDefinition, nr as getEdgeTiles, oi as transformMat3, on as diff, or as isPointableEvent, ot as SOUTH_POLE_Y, pi as equals, pn as Event, pr as mod, pt as HEATMAP_FULL_RENDER_FBO_KEY, q as renderStyleImage, qn as distanceOfAnglesRadians, qr as clone, qt as codePointUsesLocalIdeographFontFamily, r as TextAnchorEnum, ri as scale$2, rn as ValidationError, rt as isFillStyleLayer, s as TileCache, si as transformMat4$1, sn as emptyStyle, sr as isSafari, st as SubdivisionGranularityExpression, t as getAnchorJustification, ti as rotateY, tn as Color, tr as getAngleDelta, u as GeoJSONFeature, ui as clone$1, un as interpolateFactory, ur as isWorker, v as UnwrappedTileID, vi as multiply, vn as getJSON, vr as radiansToDegrees, vt as isCircleStyleLayer, w as latFromMercatorY, wi as scale, wn as getProtocol, wr as scaleZoom, wt as Uniform3f, x as isInBoundsForZoomLngLat, xi as rotateX, xn as makeRequest, xr as remapSaturate, xt as Uniform1f, y as calculateTileKey, yi as ortho, yn as getReferrer, yr as rayPlaneIntersection, yt as polygonIntersectsPolygon, z as getOverlapMode, zn as createIdentityMat4f64, zr as transformMat4$2, zt as createLayout } from "./maplibre-gl-shared-dev.mjs";
5
+ import { $ as tileCoordinatesToMercatorCoordinates, $n as degreesToRadians, $r as clone, $t as EvaluationParameters, A as getOverlapMode, Ai as scale, An as sameOrigin, Ar as rollPitchBearingToQuat, At as Uniform1i, Bn as angleToRotateBetweenVectors2D, Br as pixelsToTileUnits, Bt as CollisionCircleLayoutArray, C as createStyleLayer, Ci as invert$1, Cn as AJAXError, Cr as pick, Ct as renderColorRamp, D as isSymbolStyleLayer, Di as rotateX, Dn as getReferrer, Dr as readImageUsingVideoFrame, Dt as polygonIntersectsPolygon, E as isBackgroundStyleLayer, Ei as perspective, En as getJSON, Er as rayPlaneIntersection, Et as isCircleStyleLayer, Fi as invert, Fn as AbortError, Fr as translatePosition, Ft as UniformColorArray, G as isFillExtrusionStyleLayer, Gn as clone$2, Gr as sqrLen, Gt as RasterBoundsArray, H as isLineStyleLayer, Hn as arrayBufferToImageBitmap, Hr as create$3, Ht as Pos3dArray, I as ImagePosition, Ii as rotate, In as isAbortError, Ir as uniqueId, It as UniformFloatArray, J as cameraDirectionFromPitchBearing, Jn as createMat4f64, Jr as slerp, Jt as isRasterStyleLayer, Kn as createIdentityMat4f32, Kr as zero, Kt as TriangleIndexArray, L as potpack, Li as isOffscreenCanvasDistorted, Ln as throwIfAborted, Lr as warnOnce, Lt as UniformMatrix4f, M as evaluateSizeForZoom, Mi as create$4, Mn as getProtocol, Mr as sphericalToCartesian, Mt as Uniform3f, Ni as fromRotation, Nn as removeProtocol, Nr as subscribe, Nt as Uniform4f, O as SymbolBucket, Oi as rotateY$1, On as getVideo, Or as remapSaturate, Ot as toEvaluationFeature, P as getAnchorAlignment, Pi as create$2, Pn as config, Pr as threePlaneIntersection, Pt as UniformColor, Q as projectToWorldCoordinates, Qn as defaultEasing, Qr as add, Qt as Transitionable, R as renderStyleImage, Ri as offscreenCanvasSupported, Rr as wrap, Rt as SegmentVector, S as Actor, Si as identity, Sn as Evented, Sr as parseCacheControl, St as isHeatmapStyleLayer, T as validateCustomStyleLayer, Ti as ortho, Tn as getArrayBuffer, Tr as radiansToDegrees, Tt as RGBAImage, Un as bezier, Ur as length, Ut as PosArray, V as collisionCircleLayout, Vn as arrayBufferToImage, Vr as EXTENT, Vt as LineStripIndexArray, Wn as clamp, Wr as scale$1, Wt as QuadTriangleArray, X as getMercatorHorizon, Xn as createVec4f64, Xr as scale$3, Xt as Properties, Y as cameraMercatorCoordinateFromCenterAndRotation, Yn as createVec3f64, Yr as mul, Yt as DataConstantProperty, Z as maxMercatorHorizonAngle, Zn as deepEqual, Zr as transformMat4, Zt as TRANSITION_SUFFIX, _ as OverscaledTileID, _i as copy, _r as isWorker, _t as isColorReliefStyleLayer, a as clipLine, ai as normalize, an as emitValidationErrors, ar as filterObject, at as mercatorXfromLng, b as compareTileId, bi as exactEquals, bn as ErrorEvent, br as mod, bt as isHillshadeStyleLayer, ci as rotateZ$1, cn as validateStyleAndEmit, cr as getAngleDelta, ct as LngLat, di as sub, dn as ValidationError, dr as getRollPitchBearing, dt as isFillStyleLayer, ei as cross, er as differenceOfAnglesDegrees, et as unprojectFromWorldCoordinates, f as GEOJSON_TILE_LAYER_NAME, fi as transformMat3, fr as isImageBitmap, g as CanonicalTileID, gi as clone$1, gn as featureFilter, gr as isTouchableOrPointableType, gt as SubdivisionGranularitySetting, h as Bounds, hi as zero$1, hn as emptyStyle, hr as isTouchableEvent, ht as SubdivisionGranularityExpression, ii as negate, in as SPEC_SOURCE_TYPES, ir as extend, it as lngFromMercatorX, j as evaluateSizeForFeature, ji as translate, jn as addProtocol, jr as scaleZoom, jt as Uniform2f, k as addDynamicAttributes, ki as rotateZ, kn as makeRequest, kr as rollPitchBearingEqual, kt as Uniform1f, li as scale$2, ln as Color, lr as getEdgeTiles, lt as earthRadius, mi as transformQuat, mn as diff, mr as isSafari, mt as SOUTH_POLE_Y, ni as len, nn as ZoomHistory, nr as ensureError, nt as altitudeFromMercatorZ, oi as rotateX$1, on as validateAndEmit, or as findLineIntersection, ot as mercatorYfromLat, pi as transformMat4$1, pn as derefLayers, pr as isPointableEvent, pt as NORTH_POLE_Y, q as calculateTileMatrix, qn as createIdentityMat4f64, qr as fromEuler, qt as createLayout, r as TextAnchorEnum, ri as length$1, rr as evaluateZoomSnap, rt as latFromMercatorY, s as TileCache, si as rotateY, sn as validateStyle, sr as getAABB, st as mercatorZfromAltitude, t as getAnchorJustification, ti as dot, tn as codePointUsesLocalIdeographFontFamily, tr as distanceOfAnglesRadians, tt as MercatorCoordinate, u as GeoJSONFeature, ui as scaleAndAdd, un as ProjectionDefinition, v as UnwrappedTileID, vi as create$1, vn as interpolateFactory, vr as lerp, w as isCustomStyleLayer, wi as multiply, wn as GLOBAL_DISPATCHER_ID, wr as pointPlaneSignedDistance, wt as AlphaImage, x as isInBoundsForZoomLngLat, xi as fromScaling, xn as Event, xr as nextPowerOfTwo, xt as HEATMAP_FULL_RENDER_FBO_KEY, y as calculateTileKey, yi as equals, yn as latest, yr as mapObject, yt as Texture, z as parseGlyphPbf, zi as Point, zn as MAX_VALID_LATITUDE, zr as zoomScale, zt as CollisionBoxArray } from "./maplibre-gl-shared-dev.mjs";
6
6
  //#region package.json
7
- var version$2 = "6.0.0";
7
+ var version$2 = "6.2.0";
8
8
  //#endregion
9
9
  //#region src/util/browser.ts
10
10
  let linkEl;
@@ -709,7 +709,8 @@ async function loadSprite(originalSprite, requestManager, pixelRatio, abortContr
709
709
  const jsonsMap = {};
710
710
  const imagesMap = {};
711
711
  for (const { id, url } of spriteArray) {
712
- jsonsMap[id] = getJSON(await requestManager.transformRequest(normalizeSpriteURL(url, format, ".json"), "SpriteJSON"), abortController);
712
+ const jsonRequestParameters = await requestManager.transformRequest(normalizeSpriteURL(url, format, ".json"), "SpriteJSON");
713
+ jsonsMap[id] = getJSON(jsonRequestParameters, abortController);
713
714
  const imageRequestParameters = await requestManager.transformRequest(normalizeSpriteURL(url, format, ".png"), "SpriteImage");
714
715
  imagesMap[id] = ImageRequest.getImage(imageRequestParameters, abortController);
715
716
  }
@@ -940,8 +941,8 @@ var ImageManager = class extends Evented {
940
941
  if (pattern && pattern.position.version === image.version) return pattern.position;
941
942
  if (!pattern) {
942
943
  const bin = {
943
- w: image.data.width + padding * 2,
944
- h: image.data.height + padding * 2,
944
+ w: image.data.width + 2,
945
+ h: image.data.height + 2,
945
946
  x: 0,
946
947
  y: 0
947
948
  };
@@ -1061,7 +1062,8 @@ var ImageManager = class extends Evented {
1061
1062
  async function loadGlyphRange(fontstack, range, urlTemplate, requestManager) {
1062
1063
  const begin = range * 256;
1063
1064
  const end = begin + 255;
1064
- const response = await getArrayBuffer(await requestManager.transformRequest(urlTemplate.replace("{fontstack}", fontstack).replace("{range}", `${begin}-${end}`), "Glyphs"), new AbortController());
1065
+ const request = await requestManager.transformRequest(urlTemplate.replace("{fontstack}", fontstack).replace("{range}", `${begin}-${end}`), "Glyphs");
1066
+ const response = await getArrayBuffer(request, new AbortController());
1065
1067
  if (!response?.data) throw new Error(`Could not load glyph range. range: ${range}, ${begin}-${end}`);
1066
1068
  const glyphs = {};
1067
1069
  for (const glyph of parseGlyphPbf(response.data)) glyphs[glyph.id] = glyph;
@@ -1280,7 +1282,9 @@ var GlyphManager = class GlyphManager {
1280
1282
  }
1281
1283
  _warnOnMissingGlyphRange(glyph, range, id, err) {
1282
1284
  const begin = range * 256;
1283
- warnOnce(`Unable to load glyph range ${range}, ${begin}-${begin + 255}. Rendering codepoint U+${id.toString(16).padStart(4, "0").toUpperCase()} locally instead. ${err}`);
1285
+ const end = begin + 255;
1286
+ const codePoint = id.toString(16).padStart(4, "0").toUpperCase();
1287
+ warnOnce(`Unable to load glyph range ${range}, ${begin}-${end}. Rendering codepoint U+${codePoint} locally instead. ${err}`);
1284
1288
  }
1285
1289
  /**
1286
1290
  * Returns whether the given codepoint should be rendered locally.
@@ -1315,8 +1319,8 @@ var GlyphManager = class GlyphManager {
1315
1319
  return {
1316
1320
  id,
1317
1321
  bitmap: new AlphaImage({
1318
- width: char.width || 30 * textureScale,
1319
- height: char.height || 30 * textureScale
1322
+ width: char.width || 60,
1323
+ height: char.height || 60
1320
1324
  }, char.data),
1321
1325
  metrics: {
1322
1326
  width: isControl ? 0 : char.glyphWidth / textureScale || 24,
@@ -1332,7 +1336,7 @@ var GlyphManager = class GlyphManager {
1332
1336
  const fontFamilies = stack ? stack.split(",") : [];
1333
1337
  fontFamilies.push(defaultGenericFontFamily);
1334
1338
  const fontFamily = fontFamilies.map((fontName) => /[-\w]+/.test(fontName) ? fontName : `'${CSS.escape(fontName)}'`).join(",");
1335
- const fontSize = 24 * textureScale;
1339
+ const fontSize = 48;
1336
1340
  const fontWeight = this._fontWeight(fontFamilies[0]);
1337
1341
  const fontStyle = this._fontStyle(fontFamilies[0]);
1338
1342
  if (typeof document !== "undefined" && document.fonts?.load) try {
@@ -1342,8 +1346,8 @@ var GlyphManager = class GlyphManager {
1342
1346
  }
1343
1347
  return new GlyphManager.TinySDF({
1344
1348
  fontSize,
1345
- buffer: 3 * textureScale,
1346
- radius: 8 * textureScale,
1349
+ buffer: 6,
1350
+ radius: 16,
1347
1351
  cutoff: .25,
1348
1352
  fontFamily,
1349
1353
  fontWeight,
@@ -1410,9 +1414,9 @@ const getProperties$2 = () => properties$2 = properties$2 || new Properties({
1410
1414
  //#endregion
1411
1415
  //#region src/style/light.ts
1412
1416
  var Light = class extends Evented {
1413
- constructor(lightOptions) {
1417
+ constructor(lightOptions, globalState) {
1414
1418
  super();
1415
- this._transitionable = new Transitionable(getProperties$2(), "light", void 0);
1419
+ this._transitionable = new Transitionable(getProperties$2(), "light", globalState);
1416
1420
  this.setLight(lightOptions);
1417
1421
  this._transitioning = this._transitionable.untransitioned();
1418
1422
  }
@@ -1461,9 +1465,9 @@ const getProperties$1 = () => properties$1 = properties$1 || new Properties({
1461
1465
  //#endregion
1462
1466
  //#region src/style/sky.ts
1463
1467
  var Sky = class extends Evented {
1464
- constructor(sky) {
1468
+ constructor(sky, globalState) {
1465
1469
  super();
1466
- this._transitionable = new Transitionable(getProperties$1(), "sky", void 0);
1470
+ this._transitionable = new Transitionable(getProperties$1(), "sky", globalState);
1467
1471
  this.setSky(sky);
1468
1472
  this._transitioning = this._transitionable.untransitioned();
1469
1473
  this.recalculate(new EvaluationParameters(0));
@@ -2777,9 +2781,10 @@ var RasterTileSource = class extends Evented {
2777
2781
  const url = tile.tileID.canonical.url(this.tiles, this.map.getPixelRatio(), this.scheme);
2778
2782
  const premultiply = this._premultiplyAlpha;
2779
2783
  const imageBitmapOptions = premultiply ? void 0 : { premultiplyAlpha: "none" };
2784
+ const request = await this.map._requestManager.transformRequest(url, "Tile");
2780
2785
  tile.abortController = new AbortController();
2781
2786
  try {
2782
- const response = await ImageRequest.getImage(await this.map._requestManager.transformRequest(url, "Tile"), tile.abortController, this.map._refreshExpiredTiles, imageBitmapOptions);
2787
+ const response = await ImageRequest.getImage(request, tile.abortController, this.map._refreshExpiredTiles, imageBitmapOptions);
2783
2788
  delete tile.abortController;
2784
2789
  if (tile.aborted) {
2785
2790
  tile.state = "unloaded";
@@ -3184,9 +3189,7 @@ function getGeoJSONBounds(data) {
3184
3189
  case "Feature":
3185
3190
  coordinates = getCoordinatesFromGeometry(data.geometry);
3186
3191
  break;
3187
- default:
3188
- coordinates = getCoordinatesFromGeometry(data);
3189
- break;
3192
+ default: coordinates = getCoordinatesFromGeometry(data);
3190
3193
  }
3191
3194
  if (coordinates.length === 0) return bounds;
3192
3195
  for (const coordinate of coordinates) {
@@ -3314,6 +3317,9 @@ var GeoJSONSource = class extends Evented {
3314
3317
  _pixelsToTileUnits(pixelValue) {
3315
3318
  return pixelValue * (EXTENT / this.tileSize);
3316
3319
  }
3320
+ _tileUnitsToPixels(tileUnitValue) {
3321
+ return tileUnitValue / (EXTENT / this.tileSize);
3322
+ }
3317
3323
  _getClusterMaxZoom(clusterMaxZoom) {
3318
3324
  const effectiveClusterMaxZoom = clusterMaxZoom ? Math.round(clusterMaxZoom) : this.maxzoom - 1;
3319
3325
  if (!(Number.isInteger(clusterMaxZoom) || clusterMaxZoom === void 0)) warnOnce(`Integer expected for option 'clusterMaxZoom': provided value "${clusterMaxZoom}" rounded to "${effectiveClusterMaxZoom}"`);
@@ -3392,6 +3398,24 @@ var GeoJSONSource = class extends Evented {
3392
3398
  return this._updateWorkerData();
3393
3399
  }
3394
3400
  /**
3401
+ * Gets the cluster options currently configured on the source.
3402
+ * The returned values mirror the options accepted by `setClusterOptions`.
3403
+ *
3404
+ * @returns the source's current cluster options
3405
+ * @example
3406
+ * ```ts
3407
+ * const {cluster, clusterMaxZoom, clusterRadius} = map.getSource('some id').getClusterOptions();
3408
+ * ```
3409
+ */
3410
+ getClusterOptions() {
3411
+ const { cluster, clusterOptions } = this.workerOptions.geojsonVtOptions;
3412
+ return {
3413
+ cluster,
3414
+ clusterMaxZoom: clusterOptions.maxZoom,
3415
+ clusterRadius: this._tileUnitsToPixels(clusterOptions.radius)
3416
+ };
3417
+ }
3418
+ /**
3395
3419
  * For clustered sources, fetches the zoom at which the given cluster expands.
3396
3420
  *
3397
3421
  * @param clusterId - The value of the cluster's `cluster_id` property.
@@ -3714,6 +3738,10 @@ var GeoJSONSource = class extends Evented {
3714
3738
  * ]
3715
3739
  * })
3716
3740
  *
3741
+ * // update with an already-decoded image (no network request)
3742
+ * const bitmap = await createImageBitmap(myCanvas);
3743
+ * mySource.updateImage({image: bitmap});
3744
+ *
3717
3745
  * map.removeSource('some id'); // remove
3718
3746
  * ```
3719
3747
  */
@@ -3738,9 +3766,10 @@ var ImageSource = class extends Evented {
3738
3766
  this._loaded = false;
3739
3767
  this.fire(new MapSourceDataEvent("dataloading"));
3740
3768
  this.url = this.options.url;
3769
+ const request = await this.map._requestManager.transformRequest(this.url, "Image");
3741
3770
  this._request = new AbortController();
3742
3771
  try {
3743
- const image = await ImageRequest.getImage(await this.map._requestManager.transformRequest(this.url, "Image"), this._request);
3772
+ const image = await ImageRequest.getImage(request, this._request);
3744
3773
  this._request = null;
3745
3774
  this._loaded = true;
3746
3775
  if (image?.data) {
@@ -3758,17 +3787,29 @@ var ImageSource = class extends Evented {
3758
3787
  return this._loaded;
3759
3788
  }
3760
3789
  /**
3761
- * Updates the image URL and, optionally, the coordinates. To avoid having the image flash after changing,
3790
+ * Updates the image and, optionally, the coordinates. To avoid having the image flash after changing,
3762
3791
  * set the `raster-fade-duration` paint property on the raster layer to 0.
3763
3792
  *
3793
+ * Provide exactly one of `url` (to fetch a new image over the network) or `image` (an
3794
+ * already-decoded `HTMLImageElement`, `HTMLCanvasElement`, `ImageBitmap` or `ImageData` to
3795
+ * display directly, without a network request).
3796
+ *
3764
3797
  * @param options - The options object.
3765
3798
  */
3766
3799
  updateImage(options) {
3767
- if (!options.url) return this;
3768
3800
  if (this._request) {
3769
3801
  this._request.abort();
3770
3802
  this._request = null;
3771
3803
  }
3804
+ if ("image" in options) {
3805
+ this._loaded = true;
3806
+ this.image = options.image;
3807
+ if (options.coordinates) this.coordinates = options.coordinates;
3808
+ this.texture = null;
3809
+ this._finishLoading();
3810
+ return this;
3811
+ }
3812
+ if (!options.url) return this;
3772
3813
  this.options.url = options.url;
3773
3814
  this.load(options.coordinates).finally(() => this.texture = null);
3774
3815
  return this;
@@ -3863,9 +3904,11 @@ var ImageSource = class extends Evented {
3863
3904
  const maxTileY = Math.floor(maxY * tilesAtZoom);
3864
3905
  const minTileXWrapped = (minTileX % tilesAtZoom + tilesAtZoom) % tilesAtZoom;
3865
3906
  const maxTileXWrapped = maxTileX % tilesAtZoom;
3907
+ const minWrap = Math.floor(minTileX / tilesAtZoom);
3908
+ const maxWrap = Math.floor(maxTileX / tilesAtZoom);
3866
3909
  ranges[z] = {
3867
- minWrap: Math.floor(minTileX / tilesAtZoom),
3868
- maxWrap: Math.floor(maxTileX / tilesAtZoom),
3910
+ minWrap,
3911
+ maxWrap,
3869
3912
  minTileXWrapped,
3870
3913
  maxTileXWrapped,
3871
3914
  minTileY,
@@ -4525,7 +4568,8 @@ var Tile = class {
4525
4568
  const evaluationFeature = toEvaluationFeature(feature, true);
4526
4569
  if (!filter.filter(new EvaluationParameters(this.tileID.overscaledZ), evaluationFeature, this.tileID.canonical)) continue;
4527
4570
  } else if (!filter.filter(new EvaluationParameters(this.tileID.overscaledZ), feature)) continue;
4528
- const geojsonFeature = new GeoJSONFeature(feature, z, x, y, featureIndex.getId(feature, sourceLayer));
4571
+ const id = featureIndex.getId(feature, sourceLayer);
4572
+ const geojsonFeature = new GeoJSONFeature(feature, z, x, y, id);
4529
4573
  geojsonFeature.tile = coord;
4530
4574
  result.push(geojsonFeature);
4531
4575
  }
@@ -4716,86 +4760,6 @@ var SourceFeatureState = class {
4716
4760
  }
4717
4761
  };
4718
4762
  //#endregion
4719
- //#region src/geo/projection/mercator_utils.ts
4720
- const maxMercatorHorizonAngle = 89.25;
4721
- /**
4722
- * Returns mercator coordinates in range 0..1 for given coordinates inside a specified tile.
4723
- * @param inTileX - X coordinate in tile units - range [0..EXTENT].
4724
- * @param inTileY - Y coordinate in tile units - range [0..EXTENT].
4725
- * @param canonicalTileID - Tile canonical ID - mercator X, Y and zoom.
4726
- * @returns Mercator coordinates of the specified point in range [0..1].
4727
- */
4728
- function tileCoordinatesToMercatorCoordinates(inTileX, inTileY, canonicalTileID) {
4729
- const scale = 1 / (1 << canonicalTileID.z);
4730
- return new MercatorCoordinate(inTileX / EXTENT * scale + canonicalTileID.x * scale, inTileY / EXTENT * scale + canonicalTileID.y * scale);
4731
- }
4732
- /**
4733
- * Convert from LngLat to world coordinates (Mercator coordinates scaled by world size).
4734
- * @param worldSize - Mercator world size computed from zoom level and tile size.
4735
- * @param lnglat - The location to convert.
4736
- * @returns Point
4737
- */
4738
- function projectToWorldCoordinates(worldSize, lnglat) {
4739
- const lat = clamp(lnglat.lat, -MAX_VALID_LATITUDE, MAX_VALID_LATITUDE);
4740
- return new Point(mercatorXfromLng(lnglat.lng) * worldSize, mercatorYfromLat(lat) * worldSize);
4741
- }
4742
- /**
4743
- * Convert from world coordinates (mercator coordinates scaled by world size) to LngLat.
4744
- * @param worldSize - Mercator world size computed from zoom level and tile size.
4745
- * @param point - World coordinate.
4746
- * @returns LngLat
4747
- */
4748
- function unprojectFromWorldCoordinates(worldSize, point) {
4749
- return new MercatorCoordinate(point.x / worldSize, point.y / worldSize).toLngLat();
4750
- }
4751
- /**
4752
- * Calculate pixel height of the visible horizon in relation to map-center (e.g. height/2),
4753
- * multiplied by a static factor to simulate the earth-radius.
4754
- * The calculated value is the horizontal line from the camera-height to sea-level.
4755
- * @returns Horizon above center in pixels.
4756
- */
4757
- function getMercatorHorizon(transform) {
4758
- return transform.cameraToCenterDistance * Math.min(Math.tan(degreesToRadians(90 - transform.pitch)) * .85, Math.tan(degreesToRadians(maxMercatorHorizonAngle - transform.pitch)));
4759
- }
4760
- function calculateTileMatrix(unwrappedTileID, worldSize) {
4761
- const canonical = unwrappedTileID.canonical;
4762
- const scale$5 = worldSize / zoomScale(canonical.z);
4763
- const unwrappedX = canonical.x + Math.pow(2, canonical.z) * unwrappedTileID.wrap;
4764
- const worldMatrix = /* @__PURE__ */ new Float64Array(16);
4765
- identity(worldMatrix);
4766
- translate(worldMatrix, worldMatrix, [
4767
- unwrappedX * scale$5,
4768
- canonical.y * scale$5,
4769
- 0
4770
- ]);
4771
- scale(worldMatrix, worldMatrix, [
4772
- scale$5 / EXTENT,
4773
- scale$5 / EXTENT,
4774
- 1
4775
- ]);
4776
- return worldMatrix;
4777
- }
4778
- function cameraMercatorCoordinateFromCenterAndRotation(center, elevation, pitch, bearing, distance) {
4779
- const centerMercator = MercatorCoordinate.fromLngLat(center, elevation);
4780
- const dMercator = distance * mercatorZfromAltitude(1, center.lat);
4781
- const { x, y, z } = cameraDirectionFromPitchBearing(pitch, bearing);
4782
- const dxMercator = dMercator * -x;
4783
- const dyMercator = dMercator * -y;
4784
- const dzMercator = dMercator * -z;
4785
- return new MercatorCoordinate(centerMercator.x + dxMercator, centerMercator.y + dyMercator, centerMercator.z + dzMercator);
4786
- }
4787
- function cameraDirectionFromPitchBearing(pitch, bearing) {
4788
- const pitchRadians = degreesToRadians(pitch);
4789
- const bearingRadians = degreesToRadians(bearing);
4790
- const z = Math.cos(-pitchRadians);
4791
- const h = Math.sin(pitchRadians);
4792
- return {
4793
- x: h * Math.sin(bearingRadians),
4794
- y: -h * Math.cos(bearingRadians),
4795
- z
4796
- };
4797
- }
4798
- //#endregion
4799
4763
  //#region src/geo/projection/covering_tiles.ts
4800
4764
  /**
4801
4765
  * A simple/heuristic function that returns whether the tile is visible under the current transform.
@@ -4861,6 +4825,35 @@ function coveringZoomLevel(transform, options) {
4861
4825
  return Math.max(0, z);
4862
4826
  }
4863
4827
  /**
4828
+ * Without terrain, `getTileBoundingVolume` has no knowledge of extruded features
4829
+ * (eg. 3D buildings): every tile's bounding box is flat at the camera's `elevation`.
4830
+ * That's a fine approximation of what's visible for most views, but it breaks down
4831
+ * as the frustum's bottom edge approaches horizontal (which depends on both `pitch`
4832
+ * and `fov`, not pitch alone) - a tall building can still be poking up into view
4833
+ * long after its tile's ground point has dropped out of the frustum.
4834
+ *
4835
+ * This is an assumed upper bound on real-world feature height (in metres), used to
4836
+ * grow the elevation used for tile culling as that bottom edge nears horizontal, so
4837
+ * such tiles are not dropped too early. It has no effect away from that edge case.
4838
+ */
4839
+ const ASSUMED_MAX_FEATURE_HEIGHT_METERS = 500;
4840
+ /**
4841
+ * Angle between the frustum's bottom edge and the mercator horizon below which
4842
+ * the culling elevation starts to grow.
4843
+ */
4844
+ const TILE_CULLING_HORIZON_ONSET_DEGREES = 15;
4845
+ /**
4846
+ * Returns the elevation to use when computing tile bounding volumes for culling:
4847
+ * `transform.elevation`, growing by up to `ASSUMED_MAX_FEATURE_HEIGHT_METERS` as
4848
+ * the frustum's bottom edge approaches the horizon, where a ground-level bounding
4849
+ * box would cull tiles whose extruded features are still visible.
4850
+ */
4851
+ function getElevationForTileCulling(transform) {
4852
+ const bottomEdgeDegreesAboveHorizontal = maxMercatorHorizonAngle - transform.pitch - transform.fov / 2;
4853
+ const proximityToHorizon = clamp((TILE_CULLING_HORIZON_ONSET_DEGREES - bottomEdgeDegreesAboveHorizontal) / TILE_CULLING_HORIZON_ONSET_DEGREES, 0, 1);
4854
+ return transform.elevation + proximityToHorizon * ASSUMED_MAX_FEATURE_HEIGHT_METERS;
4855
+ }
4856
+ /**
4864
4857
  * Returns a list of tiles that optimally covers the screen. Adapted for globe projection.
4865
4858
  * Correctly handles LOD when moving over the antimeridian.
4866
4859
  * @param transform - The transform instance.
@@ -4878,6 +4871,7 @@ function coveringTiles(transform, options) {
4878
4871
  const cameraCoord = transform.screenPointToMercatorCoordinate(transform.getCameraPoint());
4879
4872
  const centerCoord = MercatorCoordinate.fromLngLat(transform.center, transform.elevation);
4880
4873
  cameraCoord.z = centerCoord.z + Math.cos(transform.pitchInRadians) * transform.cameraToCenterDistance / transform.worldSize;
4874
+ const elevationForTileCulling = getElevationForTileCulling(transform);
4881
4875
  const detailsProvider = transform.getCoveringTilesDetailsProvider();
4882
4876
  const allowVariableZoom = detailsProvider.allowVariableZoom(transform, options);
4883
4877
  const desiredZ = coveringZoomLevel(transform, options);
@@ -4924,7 +4918,7 @@ function coveringTiles(transform, options) {
4924
4918
  y,
4925
4919
  z: it.zoom
4926
4920
  };
4927
- const boundingVolume = detailsProvider.getTileBoundingVolume(tileID, it.wrap, transform.elevation, options);
4921
+ const boundingVolume = detailsProvider.getTileBoundingVolume(tileID, it.wrap, elevationForTileCulling, options);
4928
4922
  if (!fullyVisible) {
4929
4923
  const intersectResult = isTileVisible(frustum, boundingVolume, plane);
4930
4924
  if (intersectResult === 0) continue;
@@ -5339,7 +5333,7 @@ var TileManager = class TileManager extends Evented {
5339
5333
  }
5340
5334
  /**
5341
5335
  * Reload tiles based on the current state of the source.
5342
- * @param sourceDataChanged - If `true`, reload all tiles using a state of 'expired', otherwise reload only non-errored tiles using state of 'reloading'.
5336
+ * @param sourceDataChanged - If `true`, reload all tiles using a state of 'expired' (errored tiles use 'loading' since they have nothing to show yet), otherwise reload only non-errored tiles using state of 'reloading'.
5343
5337
  * @param shouldReloadTileOptions - Set of options associated with a `MapSourceDataChangedEvent` that can be passed back to the associated `Source` determine whether a tile should be reloaded.
5344
5338
  */
5345
5339
  reload(sourceDataChanged, shouldReloadTileOptions = void 0) {
@@ -5351,7 +5345,7 @@ var TileManager = class TileManager extends Evented {
5351
5345
  for (const id of this._inViewTiles.getAllIds()) {
5352
5346
  const tile = this._inViewTiles.getTileById(id);
5353
5347
  if (shouldReloadTileOptions && !this._source.shouldReloadTile(tile, shouldReloadTileOptions)) continue;
5354
- else if (sourceDataChanged) this._reloadTile(id, "expired");
5348
+ else if (sourceDataChanged) this._reloadTile(id, tile.state === "errored" ? "loading" : "expired");
5355
5349
  else if (tile.state !== "errored") this._reloadTile(id, "reloading");
5356
5350
  }
5357
5351
  }
@@ -6843,12 +6837,13 @@ var CollisionIndex = class {
6843
6837
  const featureKey = feature.key;
6844
6838
  if (seenFeatures[featureKey.bucketInstanceId] === void 0) seenFeatures[featureKey.bucketInstanceId] = {};
6845
6839
  if (seenFeatures[featureKey.bucketInstanceId][featureKey.featureIndex]) continue;
6846
- if (!polygonIntersectsPolygon(query, [
6840
+ const bbox = [
6847
6841
  new Point(feature.x1, feature.y1),
6848
6842
  new Point(feature.x2, feature.y1),
6849
6843
  new Point(feature.x2, feature.y2),
6850
6844
  new Point(feature.x1, feature.y2)
6851
- ])) continue;
6845
+ ];
6846
+ if (!polygonIntersectsPolygon(query, bbox)) continue;
6852
6847
  seenFeatures[featureKey.bucketInstanceId][featureKey.featureIndex] = true;
6853
6848
  if (result[featureKey.bucketInstanceId] === void 0) result[featureKey.bucketInstanceId] = [];
6854
6849
  result[featureKey.bucketInstanceId].push(featureKey.featureIndex);
@@ -6971,7 +6966,8 @@ var CollisionIndex = class {
6971
6966
  distanceMultiplier = Math.pow(2, -zoomFraction);
6972
6967
  distanceMultiplier *= this.transform.getPitchedTextCorrection(translatedAnchorX, translatedAnchorY, unwrappedTileID);
6973
6968
  if (!shift) {
6974
- const perspectiveRatio = clamp(.5 + .5 * (projectedPoint.signedDistanceFromCamera / this.transform.cameraToCenterDistance), 0, 4);
6969
+ const distanceRatio = projectedPoint.signedDistanceFromCamera / this.transform.cameraToCenterDistance;
6970
+ const perspectiveRatio = clamp(.5 + .5 * distanceRatio, 0, 4);
6975
6971
  distanceMultiplier *= perspectiveRatio;
6976
6972
  }
6977
6973
  }
@@ -7829,7 +7825,7 @@ var KDBush = class KDBush {
7829
7825
  this.coords = new ArrayType(data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
7830
7826
  this._pos = 0;
7831
7827
  this._finished = false;
7832
- new Uint8Array(data, 0, 2).set([219, (VERSION << 4) + arrayTypeIndex]);
7828
+ new Uint8Array(data, 0, 2).set([219, 16 + arrayTypeIndex]);
7833
7829
  new Uint16Array(data, 2, 1)[0] = nodeSize;
7834
7830
  new Uint32Array(data, 4, 1)[0] = numItems;
7835
7831
  }
@@ -8267,8 +8263,8 @@ var clipping_mask_fragment_glsl_g_default = "void main() {fragColor=vec4(1.0);}"
8267
8263
  //#region src/shaders/shaders.ts
8268
8264
  const shaders = {
8269
8265
  prelude: prepare(_prelude_fragment_glsl_g_default, _prelude_vertex_glsl_g_default),
8270
- projectionMercator: prepare("", "float projectLineThickness(float tileY) {return 1.0;}float projectCircleRadius(float tileY) {return 1.0;}vec4 projectTile(vec2 p) {vec4 result=u_projection_matrix*vec4(p,0.0,1.0);return result;}vec4 projectTile(vec2 p,vec2 rawPos) {vec4 result=u_projection_matrix*vec4(p,0.0,1.0);if (rawPos.y <-32767.5 || rawPos.y > 32766.5) {result.z=-10000000.0;}return result;}vec4 projectTileWithElevation(vec2 posInTile,float elevation) {return u_projection_matrix*vec4(posInTile,elevation,1.0);}vec4 projectTileFor3D(vec2 posInTile,float elevation) {return projectTileWithElevation(posInTile,elevation);}"),
8271
- projectionGlobe: prepare("", "#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);}"),
8266
+ projectionMercator: prepare("\nvoid clipAntimeridian() {}", "float projectLineThickness(float tileY) {return 1.0;}float projectCircleRadius(float tileY) {return 1.0;}vec4 projectTile(vec2 p) {vec4 result=u_projection_matrix*vec4(p,0.0,1.0);return result;}vec4 projectTile(vec2 p,vec2 rawPos) {vec4 result=u_projection_matrix*vec4(p,0.0,1.0);if (rawPos.y <-32767.5 || rawPos.y > 32766.5) {result.z=-10000000.0;}return result;}vec4 projectTileWithElevation(vec2 posInTile,float elevation) {return u_projection_matrix*vec4(posInTile,elevation,1.0);}vec4 projectTileFor3D(vec2 posInTile,float elevation) {return projectTileWithElevation(posInTile,elevation);}"),
8267
+ projectionGlobe: prepare("uniform bool u_projection_clip_antimeridian;in highp float v_projection_tile_x;void clipAntimeridian() {if (u_projection_clip_antimeridian && (v_projection_tile_x < 0.0 || v_projection_tile_x >=8192.0)) {discard;}}", "#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);}"),
8272
8268
  background: prepare(background_fragment_glsl_g_default, background_vertex_glsl_g_default),
8273
8269
  backgroundPattern: prepare(background_pattern_fragment_glsl_g_default, background_pattern_vertex_glsl_g_default),
8274
8270
  circle: prepare(circle_fragment_glsl_g_default, circle_vertex_glsl_g_default),
@@ -8288,11 +8284,11 @@ const shaders = {
8288
8284
  fillExtrusionPattern: prepare("uniform vec2 u_texsize;uniform float u_fade;uniform sampler2D u_image;in vec2 v_pos_a;in vec2 v_pos_b;in vec4 v_lighting;\n#pragma maplibre: define lowp float base\n#pragma maplibre: define lowp float height\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\nvoid main() {\n#pragma maplibre: initialize lowp float base\n#pragma maplibre: initialize lowp float height\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\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;vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,imagecoord);vec4 color1=texture(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture(u_image,pos2);vec4 mixedColor=mix(color1,color2,u_fade);fragColor=mixedColor*v_lighting;\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}", "uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform float u_height_factor;uniform vec3 u_scale;uniform float u_vertical_gradient;uniform lowp float u_opacity;uniform vec2 u_fill_translate;uniform vec3 u_lightcolor;uniform lowp vec3 u_lightpos;uniform lowp vec3 u_lightpos_globe;uniform lowp float u_lightintensity;layout(location=0) in vec2 a_pos;layout(location=1) in vec4 a_normal_ed;\n#ifdef TERRAIN3D\nlayout(location=2) in vec2 a_centroid;\n#endif\n#ifdef GLOBE\nout vec3 v_sphere_pos;\n#endif\nout vec2 v_pos_a;out vec2 v_pos_b;out vec4 v_lighting;\n#pragma maplibre: define lowp float base\n#pragma maplibre: define lowp float height\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\nvoid main() {\n#pragma maplibre: initialize lowp float base\n#pragma maplibre: initialize lowp float height\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\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 tileRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec3 normal=a_normal_ed.xyz;float edgedistance=a_normal_ed.w;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;\n#ifdef TERRAIN3D\nfloat height_terrain3d_offset=get_elevation(a_centroid);float base_terrain3d_offset=height_terrain3d_offset-(base > 0.0 ? 0.0 : 10.0);\n#else\nfloat height_terrain3d_offset=0.0;float base_terrain3d_offset=0.0;\n#endif\nbase=max(0.0,base)+base_terrain3d_offset;height=max(0.0,height)+height_terrain3d_offset;float t=mod(normal.x,2.0);float elevation=t > 0.0 ? height : base;vec2 posInTile=a_pos+u_fill_translate;\n#ifdef GLOBE\nvec3 spherePos=projectToSphere(posInTile,a_pos);vec3 elevatedPos=spherePos*(1.0+elevation/GLOBE_RADIUS);v_sphere_pos=elevatedPos;gl_Position=interpolateProjectionFor3D(posInTile,spherePos,elevation);\n#else\ngl_Position=u_projection_matrix*vec4(posInTile,elevation,1.0);\n#endif\nvec2 pos=normal.x==1.0 && normal.y==0.0 && normal.z==16384.0\n? a_pos\n: vec2(edgedistance,elevation*u_height_factor);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileRatio,pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileRatio,pos);v_lighting=vec4(0.0,0.0,0.0,1.0);float directional=clamp(dot(normal/16383.0,u_lightpos),0.0,1.0);directional=mix((1.0-u_lightintensity),max((0.5+u_lightintensity),1.0),directional);if (normal.y !=0.0) {directional*=((1.0-u_vertical_gradient)+(u_vertical_gradient*clamp((t+base)*pow(height/150.0,0.5),mix(0.7,0.98,1.0-u_lightintensity),1.0)));}v_lighting.rgb+=clamp(directional*u_lightcolor,mix(vec3(0.0),vec3(0.3),1.0-u_lightcolor),vec3(1.0));v_lighting*=u_opacity;}"),
8289
8285
  hillshadePrepare: prepare("#ifdef GL_ES\nprecision highp float;\n#endif\nuniform sampler2D u_image;in vec2 v_pos;uniform vec2 u_dimension;uniform float u_zoom;uniform vec4 u_unpack;float getElevation(vec2 coord,float bias) {vec4 data=texture(u_image,coord)*255.0;data.a=-1.0;return dot(data,u_unpack);}void main() {vec2 epsilon=1.0/u_dimension;float tileSize=u_dimension.x-2.0;float a=getElevation(v_pos+vec2(-epsilon.x,-epsilon.y),0.0);float b=getElevation(v_pos+vec2(0,-epsilon.y),0.0);float c=getElevation(v_pos+vec2(epsilon.x,-epsilon.y),0.0);float d=getElevation(v_pos+vec2(-epsilon.x,0),0.0);float e=getElevation(v_pos,0.0);float f=getElevation(v_pos+vec2(epsilon.x,0),0.0);float g=getElevation(v_pos+vec2(-epsilon.x,epsilon.y),0.0);float h=getElevation(v_pos+vec2(0,epsilon.y),0.0);float i=getElevation(v_pos+vec2(epsilon.x,epsilon.y),0.0);float exaggerationFactor=u_zoom < 2.0 ? 0.4 : u_zoom < 4.5 ? 0.35 : 0.3;float exaggeration=u_zoom < 15.0 ? (u_zoom-15.0)*exaggerationFactor : 0.0;vec2 deriv=vec2((c+f+f+i)-(a+d+d+g),(g+h+h+i)-(a+b+b+c))*tileSize/pow(2.0,exaggeration+(28.2562-u_zoom));fragColor=clamp(vec4(deriv.x/8.0+0.5,deriv.y/8.0+0.5,1.0,1.0),0.0,1.0);\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}", "uniform mat4 u_matrix;uniform vec2 u_dimension;layout(location=0) in vec2 a_pos;layout(location=1) in vec2 a_texture_pos;out vec2 v_pos;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);highp vec2 epsilon=1.0/u_dimension;float scale=(u_dimension.x-2.0)/u_dimension.x;v_pos=(a_texture_pos/8192.0)*scale+epsilon;}"),
8290
8286
  hillshade: prepare("uniform sampler2D u_image;in vec2 v_pos;uniform vec2 u_latrange;uniform float u_exaggeration;uniform vec4 u_accent;uniform int u_method;uniform float u_altitudes[NUM_ILLUMINATION_SOURCES];uniform float u_azimuths[NUM_ILLUMINATION_SOURCES];uniform vec4 u_shadows[NUM_ILLUMINATION_SOURCES];uniform vec4 u_highlights[NUM_ILLUMINATION_SOURCES];\n#define PI 3.141592653589793\n#define STANDARD 0\n#define COMBINED 1\n#define IGOR 2\n#define MULTIDIRECTIONAL 3\n#define BASIC 4\nfloat get_aspect(vec2 deriv){return deriv.x !=0.0 ? atan(deriv.y,-deriv.x) : PI/2.0*(deriv.y > 0.0 ? 1.0 :-1.0);}void igor_hillshade(vec2 deriv){deriv=deriv*u_exaggeration*2.0;float aspect=get_aspect(deriv);float azimuth=u_azimuths[0]+PI;float slope_stength=atan(length(deriv))*2.0/PI;float aspect_strength=1.0-abs(mod((aspect+azimuth)/PI+0.5,2.0)-1.0);float shadow_strength=slope_stength*aspect_strength;float highlight_strength=slope_stength*(1.0-aspect_strength);fragColor=u_shadows[0]*shadow_strength+u_highlights[0]*highlight_strength;}void standard_hillshade(vec2 deriv){float azimuth=u_azimuths[0]+PI;float slope=atan(0.625*length(deriv));float aspect=get_aspect(deriv);float intensity=u_exaggeration;float base=1.875-intensity*1.75;float maxValue=0.5*PI;float scaledSlope=intensity !=0.5 ? ((pow(base,slope)-1.0)/(pow(base,maxValue)-1.0))*maxValue : slope;float accent=cos(scaledSlope);vec4 accent_color=(1.0-accent)*u_accent*clamp(intensity*2.0,0.0,1.0);float shade=abs(mod((aspect+azimuth)/PI+0.5,2.0)-1.0);vec4 shade_color=mix(u_shadows[0],u_highlights[0],shade)*sin(scaledSlope)*clamp(intensity*2.0,0.0,1.0);fragColor=accent_color*(1.0-shade_color.a)+shade_color;}void basic_hillshade(vec2 deriv){deriv=deriv*u_exaggeration*2.0;float azimuth=u_azimuths[0]+PI;float cos_az=cos(azimuth);float sin_az=sin(azimuth);float cos_alt=cos(u_altitudes[0]);float sin_alt=sin(u_altitudes[0]);float cang=(sin_alt-(deriv.y*cos_az*cos_alt-deriv.x*sin_az*cos_alt))/sqrt(1.0+dot(deriv,deriv));float shade=clamp(cang,0.0,1.0);if(shade > 0.5){fragColor=u_highlights[0]*(2.0*shade-1.0);}else\n{fragColor=u_shadows[0]*(1.0-2.0*shade);}}void multidirectional_hillshade(vec2 deriv){deriv=deriv*u_exaggeration*2.0;fragColor=vec4(0,0,0,0);for(int i=0; i < NUM_ILLUMINATION_SOURCES; i++){float cos_alt=cos(u_altitudes[i]);float sin_alt=sin(u_altitudes[i]);float cos_az=-cos(u_azimuths[i]);float sin_az=-sin(u_azimuths[i]);float cang=(sin_alt-(deriv.y*cos_az*cos_alt-deriv.x*sin_az*cos_alt))/sqrt(1.0+dot(deriv,deriv));float shade=clamp(cang,0.0,1.0);if(shade > 0.5){fragColor+=u_highlights[i]*(2.0*shade-1.0)/float(NUM_ILLUMINATION_SOURCES);}else\n{fragColor+=u_shadows[i]*(1.0-2.0*shade)/float(NUM_ILLUMINATION_SOURCES);}}}void combined_hillshade(vec2 deriv){deriv=deriv*u_exaggeration*2.0;float azimuth=u_azimuths[0]+PI;float cos_az=cos(azimuth);float sin_az=sin(azimuth);float cos_alt=cos(u_altitudes[0]);float sin_alt=sin(u_altitudes[0]);float cang=acos((sin_alt-(deriv.y*cos_az*cos_alt-deriv.x*sin_az*cos_alt))/sqrt(1.0+dot(deriv,deriv)));cang=clamp(cang,0.0,PI/2.0);float shade=cang*atan(length(deriv))*4.0/PI/PI;float highlight=(PI/2.0-cang)*atan(length(deriv))*4.0/PI/PI;fragColor=u_shadows[0]*shade+u_highlights[0]*highlight;}void main() {vec4 pixel=texture(u_image,v_pos);float scaleFactor=cos(radians((u_latrange[0]-u_latrange[1])*(1.0-v_pos.y)+u_latrange[1]));vec2 deriv=((pixel.rg*8.0)-4.0)/scaleFactor;if (u_method==BASIC) {basic_hillshade(deriv);} else if (u_method==COMBINED) {combined_hillshade(deriv);} else if (u_method==IGOR) {igor_hillshade(deriv);} else if (u_method==MULTIDIRECTIONAL) {multidirectional_hillshade(deriv);} else if (u_method==STANDARD) {standard_hillshade(deriv);} else {standard_hillshade(deriv);}\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}", "uniform mat4 u_matrix;layout(location=0) in vec2 a_pos;out vec2 v_pos;void main() {gl_Position=projectTile(a_pos,a_pos);v_pos=a_pos/8192.0;if (a_pos.y <-32767.5) {v_pos.y=0.0;}if (a_pos.y > 32766.5) {v_pos.y=1.0;}}"),
8291
- line: prepare("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}", "\n#define scale 0.015873016\nlayout(location=0) in vec2 a_pos_normal;layout(location=1) in vec4 a_data;uniform vec2 u_translation;uniform mediump float u_ratio;uniform vec2 u_units_to_pixels;uniform lowp float u_device_pixel_ratio;out vec2 v_normal;flat out vec2 v_width2;out float v_gamma_scale;out highp float v_linesofar;\n#ifdef GLOBE\nout 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 gapwidth\n#pragma maplibre: define lowp float offset\n#pragma maplibre: define mediump float width\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 gapwidth\n#pragma maplibre: initialize lowp float offset\n#pragma maplibre: initialize mediump float width\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;v_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*2.0;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nv_width2=vec2(outset,inset);}"),
8292
- lineGradient: prepare("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}", "\n#define scale 0.015873016\nlayout(location=0) in vec2 a_pos_normal;layout(location=1) in vec4 a_data;layout(location=2) in float a_uv_x;layout(location=3) in float a_split_index;uniform vec2 u_translation;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_units_to_pixels;uniform float u_image_height;out vec2 v_normal;flat out vec2 v_width2;out float v_gamma_scale;out highp vec2 v_uv;\n#ifdef GLOBE\nout 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 gapwidth\n#pragma maplibre: define lowp float offset\n#pragma maplibre: define mediump float width\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float gapwidth\n#pragma maplibre: initialize lowp float offset\n#pragma maplibre: initialize mediump float width\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;highp float texel_height=1.0/u_image_height;highp float half_texel_height=0.5*texel_height;v_uv=vec2(a_uv_x,a_split_index*texel_height-half_texel_height);vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nv_width2=vec2(outset,inset);}"),
8293
- linePattern: prepare("#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}", "\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nlayout(location=0) in vec2 a_pos_normal;layout(location=1) in vec4 a_data;uniform vec2 u_translation;uniform vec2 u_units_to_pixels;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;out vec2 v_normal;flat out vec2 v_width2;out float v_linesofar;out float v_gamma_scale;flat out float v_width;\n#ifdef GLOBE\nout float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define lowp float offset\n#pragma maplibre: define mediump float gapwidth\n#pragma maplibre: define mediump float width\n#pragma maplibre: define lowp float floorwidth\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\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize lowp float offset\n#pragma maplibre: initialize mediump float gapwidth\n#pragma maplibre: initialize mediump float width\n#pragma maplibre: initialize lowp float floorwidth\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\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nv_linesofar=a_linesofar;v_width2=vec2(outset,inset);v_width=floorwidth;}"),
8294
- lineSDF: prepare("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}", "\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nlayout(location=0) in vec2 a_pos_normal;layout(location=1) in vec4 a_data;uniform vec2 u_translation;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_units_to_pixels;uniform float u_tileratio;uniform float u_crossfade_from;uniform float u_crossfade_to;uniform float u_lineatlas_height;out vec2 v_normal;flat out vec2 v_width2;out vec2 v_tex_a;out vec2 v_tex_b;out float v_gamma_scale;\n#ifdef GLOBE\nout 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 gapwidth\n#pragma maplibre: define lowp float offset\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 gapwidth\n#pragma maplibre: initialize lowp float offset\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\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nfloat u_patternscale_a_x=u_tileratio/dasharray_from.w/u_crossfade_from;float u_patternscale_a_y=-dasharray_from.z/2.0/u_lineatlas_height;float u_patternscale_b_x=u_tileratio/dasharray_to.w/u_crossfade_to;float u_patternscale_b_y=-dasharray_to.z/2.0/u_lineatlas_height;v_tex_a=vec2(a_linesofar*u_patternscale_a_x/floorwidth,normal.y*u_patternscale_a_y+(float(dasharray_from.y)+0.5)/u_lineatlas_height);v_tex_b=vec2(a_linesofar*u_patternscale_b_x/floorwidth,normal.y*u_patternscale_b_y+(float(dasharray_to.y)+0.5)/u_lineatlas_height);v_width2=vec2(outset,inset);}"),
8295
- lineGradientSDF: prepare("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}", "\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nlayout(location=0) in vec2 a_pos_normal;layout(location=1) in vec4 a_data;layout(location=2) in float a_uv_x;layout(location=3) in float a_split_index;uniform vec2 u_translation;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_units_to_pixels;uniform float u_image_height;uniform float u_tileratio;uniform float u_crossfade_from;uniform float u_crossfade_to;uniform float u_lineatlas_height;out vec2 v_normal;flat out vec2 v_width2;out float v_gamma_scale;out highp vec2 v_uv;out vec2 v_tex_a;out vec2 v_tex_b;\n#ifdef GLOBE\nout 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 gapwidth\n#pragma maplibre: define lowp float offset\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 gapwidth\n#pragma maplibre: initialize lowp float offset\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\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;float texel_height=1.0/u_image_height;float half_texel_height=0.5*texel_height;v_uv=vec2(a_uv_x,a_split_index*texel_height-half_texel_height);vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nfloat u_patternscale_a_x=u_tileratio/dasharray_from.w/u_crossfade_from;float u_patternscale_a_y=-dasharray_from.z/2.0/u_lineatlas_height;float u_patternscale_b_x=u_tileratio/dasharray_to.w/u_crossfade_to;float u_patternscale_b_y=-dasharray_to.z/2.0/u_lineatlas_height;v_tex_a=vec2(a_linesofar*u_patternscale_a_x/floorwidth,normal.y*u_patternscale_a_y+(float(dasharray_from.y)+0.5)/u_lineatlas_height);v_tex_b=vec2(a_linesofar*u_patternscale_b_x/floorwidth,normal.y*u_patternscale_b_y+(float(dasharray_to.y)+0.5)/u_lineatlas_height);v_width2=vec2(outset,inset);}"),
8287
+ line: prepare("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}", "\n#define scale 0.015873016\nlayout(location=0) in vec2 a_pos_normal;layout(location=1) in vec4 a_data;uniform vec2 u_translation;uniform mediump float u_ratio;uniform vec2 u_units_to_pixels;uniform lowp float u_device_pixel_ratio;out vec2 v_normal;flat out vec2 v_width2;out float v_gamma_scale;out highp float v_linesofar;\n#ifdef GLOBE\nout 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 gapwidth\n#pragma maplibre: define lowp float offset\n#pragma maplibre: define mediump float width\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 gapwidth\n#pragma maplibre: initialize lowp float offset\n#pragma maplibre: initialize mediump float width\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;v_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*2.0;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nv_width2=vec2(outset,inset);}"),
8288
+ lineGradient: prepare("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}", "\n#define scale 0.015873016\nlayout(location=0) in vec2 a_pos_normal;layout(location=1) in vec4 a_data;layout(location=2) in float a_uv_x;layout(location=3) in float a_split_index;uniform vec2 u_translation;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_units_to_pixels;uniform float u_image_height;out vec2 v_normal;flat out vec2 v_width2;out float v_gamma_scale;out highp vec2 v_uv;\n#ifdef GLOBE\nout 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 gapwidth\n#pragma maplibre: define lowp float offset\n#pragma maplibre: define mediump float width\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float gapwidth\n#pragma maplibre: initialize lowp float offset\n#pragma maplibre: initialize mediump float width\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;highp float texel_height=1.0/u_image_height;highp float half_texel_height=0.5*texel_height;v_uv=vec2(a_uv_x,a_split_index*texel_height-half_texel_height);vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nv_width2=vec2(outset,inset);}"),
8289
+ linePattern: prepare("#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}", "\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nlayout(location=0) in vec2 a_pos_normal;layout(location=1) in vec4 a_data;uniform vec2 u_translation;uniform vec2 u_units_to_pixels;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;out vec2 v_normal;flat out vec2 v_width2;out float v_linesofar;out float v_gamma_scale;flat out float v_width;\n#ifdef GLOBE\nout float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define lowp float offset\n#pragma maplibre: define mediump float gapwidth\n#pragma maplibre: define mediump float width\n#pragma maplibre: define lowp float floorwidth\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\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize lowp float offset\n#pragma maplibre: initialize mediump float gapwidth\n#pragma maplibre: initialize mediump float width\n#pragma maplibre: initialize lowp float floorwidth\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\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nv_linesofar=a_linesofar;v_width2=vec2(outset,inset);v_width=floorwidth;}"),
8290
+ lineSDF: prepare("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}", "\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nlayout(location=0) in vec2 a_pos_normal;layout(location=1) in vec4 a_data;uniform vec2 u_translation;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_units_to_pixels;uniform float u_tileratio;uniform float u_crossfade_from;uniform float u_crossfade_to;uniform float u_lineatlas_height;out vec2 v_normal;flat out vec2 v_width2;out vec2 v_tex_a;out vec2 v_tex_b;out float v_gamma_scale;\n#ifdef GLOBE\nout 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 gapwidth\n#pragma maplibre: define lowp float offset\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 gapwidth\n#pragma maplibre: initialize lowp float offset\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\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nfloat u_patternscale_a_x=u_tileratio/dasharray_from.w/u_crossfade_from;float u_patternscale_a_y=-dasharray_from.z/2.0/u_lineatlas_height;float u_patternscale_b_x=u_tileratio/dasharray_to.w/u_crossfade_to;float u_patternscale_b_y=-dasharray_to.z/2.0/u_lineatlas_height;v_tex_a=vec2(a_linesofar*u_patternscale_a_x/floorwidth,normal.y*u_patternscale_a_y+(float(dasharray_from.y)+0.5)/u_lineatlas_height);v_tex_b=vec2(a_linesofar*u_patternscale_b_x/floorwidth,normal.y*u_patternscale_b_y+(float(dasharray_to.y)+0.5)/u_lineatlas_height);v_width2=vec2(outset,inset);}"),
8291
+ lineGradientSDF: prepare("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}", "\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nlayout(location=0) in vec2 a_pos_normal;layout(location=1) in vec4 a_data;layout(location=2) in float a_uv_x;layout(location=3) in float a_split_index;uniform vec2 u_translation;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_units_to_pixels;uniform float u_image_height;uniform float u_tileratio;uniform float u_crossfade_from;uniform float u_crossfade_to;uniform float u_lineatlas_height;out vec2 v_normal;flat out vec2 v_width2;out float v_gamma_scale;out highp vec2 v_uv;out vec2 v_tex_a;out vec2 v_tex_b;\n#ifdef GLOBE\nout 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 gapwidth\n#pragma maplibre: define lowp float offset\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 gapwidth\n#pragma maplibre: initialize lowp float offset\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\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;float texel_height=1.0/u_image_height;float half_texel_height=0.5*texel_height;v_uv=vec2(a_uv_x,a_split_index*texel_height-half_texel_height);vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nfloat u_patternscale_a_x=u_tileratio/dasharray_from.w/u_crossfade_from;float u_patternscale_a_y=-dasharray_from.z/2.0/u_lineatlas_height;float u_patternscale_b_x=u_tileratio/dasharray_to.w/u_crossfade_to;float u_patternscale_b_y=-dasharray_to.z/2.0/u_lineatlas_height;v_tex_a=vec2(a_linesofar*u_patternscale_a_x/floorwidth,normal.y*u_patternscale_a_y+(float(dasharray_from.y)+0.5)/u_lineatlas_height);v_tex_b=vec2(a_linesofar*u_patternscale_b_x/floorwidth,normal.y*u_patternscale_b_y+(float(dasharray_to.y)+0.5)/u_lineatlas_height);v_width2=vec2(outset,inset);}"),
8296
8292
  layerOpacity: prepare("uniform sampler2D u_image;uniform float u_opacity;in vec2 v_pos;void main() {fragColor=texture(u_image,v_pos)*u_opacity;\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(0.0);\n#endif\n}", "layout(location=0) in vec2 a_pos;out vec2 v_pos;void main() {gl_Position=vec4(a_pos.x*2.0-1.0,1.0-a_pos.y*2.0,0.0,1.0);v_pos.x=a_pos.x;v_pos.y=1.0-a_pos.y;}"),
8297
8293
  raster: prepare("uniform float u_fade_t;uniform float u_opacity;uniform sampler2D u_image0;uniform sampler2D u_image1;in vec2 v_pos0;in vec2 v_pos1;uniform float u_brightness_low;uniform float u_brightness_high;uniform float u_saturation_factor;uniform float u_contrast_factor;uniform vec3 u_spin_weights;void main() {vec4 color0=texture(u_image0,v_pos0);vec4 color1=texture(u_image1,v_pos1);if (color0.a > 0.0) {color0.rgb=color0.rgb/color0.a;}if (color1.a > 0.0) {color1.rgb=color1.rgb/color1.a;}vec4 color=mix(color0,color1,u_fade_t);color.a*=u_opacity;vec3 rgb=color.rgb;rgb=vec3(dot(rgb,u_spin_weights.xyz),dot(rgb,u_spin_weights.zxy),dot(rgb,u_spin_weights.yzx));float average=(color.r+color.g+color.b)/3.0;rgb+=(average-rgb)*u_saturation_factor;rgb=(rgb-0.5)*u_contrast_factor+0.5;vec3 u_high_vec=vec3(u_brightness_low,u_brightness_low,u_brightness_low);vec3 u_low_vec=vec3(u_brightness_high,u_brightness_high,u_brightness_high);fragColor=vec4(mix(u_high_vec,u_low_vec,rgb)*color.a,color.a);\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}", "uniform vec2 u_tl_parent;uniform float u_scale_parent;uniform float u_buffer_scale;uniform vec4 u_coords_top;uniform vec4 u_coords_bottom;layout(location=0) in vec2 a_pos;out vec2 v_pos0;out vec2 v_pos1;void main() {vec2 fractionalPos=a_pos/8192.0;vec2 position=mix(mix(u_coords_top.xy,u_coords_top.zw,fractionalPos.x),mix(u_coords_bottom.xy,u_coords_bottom.zw,fractionalPos.x),fractionalPos.y);gl_Position=projectTile(position,position);v_pos0=((fractionalPos-0.5)/u_buffer_scale)+0.5;\n#ifdef GLOBE\nif (a_pos.y <-32767.5) {v_pos0.y=0.0;}if (a_pos.y > 32766.5) {v_pos0.y=1.0;}\n#endif\nv_pos1=(v_pos0*u_scale_parent)+u_tl_parent;}"),
8298
8294
  symbolIcon: prepare("uniform sampler2D u_texture;in vec2 v_tex;flat in float v_total_opacity;void main() {fragColor=texture(u_texture,v_tex)*v_total_opacity;\n#ifdef OVERDRAW_INSPECTOR\nfragColor=vec4(1.0);\n#endif\n}", "layout(location=0) in vec4 a_pos_offset;layout(location=1) in vec4 a_data;layout(location=2) in vec4 a_pixeloffset;layout(location=3) in vec3 a_projected_pos;layout(location=4) in float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform highp float u_camera_to_center_distance;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform float u_fade_change;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform vec2 u_texsize;uniform bool u_is_along_line;uniform bool u_is_variable_anchor;uniform vec2 u_translation;uniform float u_pitched_scale;uniform bool u_is_offset;out vec2 v_tex;flat out float v_total_opacity;\n#pragma maplibre: define lowp float opacity\nvoid main() {\n#pragma maplibre: initialize lowp float opacity\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;float a_size_min=floor(a_size[0]*0.5);vec2 a_pxoffset=a_pixeloffset.xy;vec2 a_minFontScale=a_pixeloffset.zw/256.0;float ele=get_elevation(a_pos);highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size_min,a_size[1],u_size_t)/128.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size_min/128.0;} else {size=u_size;}vec2 translated_a_pos=a_pos+u_translation;vec4 projectedPoint=projectTileWithElevation(translated_a_pos,ele);vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;float visibility=calculate_visibility(projectedPoint);v_total_opacity=opacity*max(0.0,min(visibility,fade_opacity[0]+fade_change));if (v_total_opacity < 0.1){gl_Position=vec4(-2.,-2.,-2.,1.);return;}highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\ncamera_to_anchor_distance/u_camera_to_center_distance :\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);if (!u_is_offset) {size*=perspective_ratio;}float fontScale=u_is_text ? size/24.0 : size;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=projectTileWithElevation(translated_a_pos+vec2(1,0),ele);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos;if (u_is_along_line || u_is_variable_anchor) {projected_pos=vec4(a_projected_pos.xy,ele,1.0);} else if (u_pitch_with_map) {projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy+u_translation,ele,1.0);} else {projected_pos=u_label_plane_matrix*projectTileWithElevation(a_projected_pos.xy+u_translation,ele);}float z=float(u_pitch_with_map)*projected_pos.z/projected_pos.w;float projectionScaling=1.0;\n#ifdef GLOBE\nif(u_pitch_with_map) {float anchor_pos_tile_y=(u_coord_matrix*vec4(projected_pos.xy/projected_pos.w,z,1.0)).y;projectionScaling=mix(projectionScaling,1.0/circumferenceRatioAtTileY(anchor_pos_tile_y)*u_pitched_scale,u_projection_transition);}\n#endif\nvec4 finalPos=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*max(a_minFontScale,fontScale)+a_pxoffset/16.0)*projectionScaling,z,1.0);if(u_pitch_with_map) {finalPos=projectTileWithElevation(finalPos.xy,finalPos.z);}gl_Position=finalPos;v_tex=a_tex/u_texsize;}"),
@@ -8301,7 +8297,6 @@ const shaders = {
8301
8297
  terrain: prepare("uniform sampler2D u_texture;uniform vec4 u_fog_color;uniform vec4 u_horizon_color;uniform float u_fog_ground_blend;uniform float u_fog_ground_blend_opacity;uniform float u_horizon_fog_blend;uniform bool u_is_globe_mode;in vec2 v_texture_pos;in float v_fog_depth;const float gamma=2.2;vec4 gammaToLinear(vec4 color) {return pow(color,vec4(gamma));}vec4 linearToGamma(vec4 color) {return pow(color,vec4(1.0/gamma));}void main() {vec4 surface_color=texture(u_texture,vec2(v_texture_pos.x,1.0-v_texture_pos.y));if (!u_is_globe_mode && u_fog_ground_blend_opacity > 0.0 && v_fog_depth > u_fog_ground_blend) {vec4 surface_color_linear=gammaToLinear(surface_color);float blend_color=smoothstep(0.0,1.0,max((v_fog_depth-u_horizon_fog_blend)/(1.0-u_horizon_fog_blend),0.0));vec4 fog_horizon_color_linear=mix(gammaToLinear(u_fog_color),gammaToLinear(u_horizon_color),blend_color);float factor_fog=max(v_fog_depth-u_fog_ground_blend,0.0)/(1.0-u_fog_ground_blend);fragColor=linearToGamma(mix(surface_color_linear,fog_horizon_color_linear,pow(factor_fog,2.0)*u_fog_ground_blend_opacity));} else {fragColor=surface_color;}}", "layout(location=0) in vec3 a_pos3d;uniform mat4 u_fog_matrix;uniform float u_ele_delta;out vec2 v_texture_pos;out float v_fog_depth;void main() {float ele=get_elevation(a_pos3d.xy);float ele_delta=a_pos3d.z==1.0 ? u_ele_delta : 0.0;v_texture_pos=a_pos3d.xy/8192.0;gl_Position=projectTileFor3D(a_pos3d.xy,ele-ele_delta);vec4 pos=u_fog_matrix*vec4(a_pos3d.xy,ele,1.0);v_fog_depth=pos.z/pos.w*0.5+0.5;}"),
8302
8298
  terrainDepth: prepare("in float v_depth;const highp vec4 bitSh=vec4(256.*256.*256.,256.*256.,256.,1.);const highp vec4 bitMsk=vec4(0.,vec3(1./256.0));highp vec4 pack(highp float value) {highp vec4 comp=fract(value*bitSh);comp-=comp.xxyz*bitMsk;return comp;}void main() {fragColor=pack(v_depth);}", "layout(location=0) in vec3 a_pos3d;uniform float u_ele_delta;out float v_depth;void main() {float ele=get_elevation(a_pos3d.xy);float ele_delta=a_pos3d.z==1.0 ? u_ele_delta : 0.0;gl_Position=projectTileFor3D(a_pos3d.xy,ele-ele_delta);v_depth=gl_Position.z/gl_Position.w;}"),
8303
8299
  terrainCoords: prepare("precision mediump float;uniform sampler2D u_texture;uniform float u_terrain_coords_id;in vec2 v_texture_pos;void main() {vec4 rgba=texture(u_texture,v_texture_pos);fragColor=vec4(rgba.r,rgba.g,rgba.b,u_terrain_coords_id);}", "layout(location=0) in vec3 a_pos3d;uniform float u_ele_delta;out vec2 v_texture_pos;void main() {float ele=get_elevation(a_pos3d.xy);float ele_delta=a_pos3d.z==1.0 ? u_ele_delta : 0.0;v_texture_pos=a_pos3d.xy/8192.0;gl_Position=projectTileFor3D(a_pos3d.xy,ele-ele_delta);}"),
8304
- projectionErrorMeasurement: prepare("flat in vec4 v_output_error_encoded;void main() {fragColor=v_output_error_encoded;}", "layout(location=0) in vec2 a_pos;uniform highp float u_input;uniform highp float u_output_expected;flat out vec4 v_output_error_encoded;void main() {float real_output=2.0*atan(exp(PI-(u_input*PI*2.0)))-PI*0.5;float error=real_output-u_output_expected;float abs_error=abs(error)*128.0;v_output_error_encoded.x=min(floor(abs_error*256.0),255.0)/255.0;abs_error-=v_output_error_encoded.x;v_output_error_encoded.y=min(floor(abs_error*65536.0),255.0)/255.0;abs_error-=v_output_error_encoded.x/255.0;v_output_error_encoded.z=min(floor(abs_error*16777216.0),255.0)/255.0;v_output_error_encoded.w=error >=0.0 ? 1.0 : 0.0;gl_Position=vec4(a_pos,0.0,1.0);}"),
8305
8300
  atmosphere: prepare("#ifdef GL_ES\nprecision highp float;\n#endif\nin vec3 view_direction;uniform vec3 u_sun_pos;uniform vec3 u_globe_position;uniform float u_globe_radius;uniform float u_atmosphere_blend;/**Shader use from https:*Made some change to adapt to MapLibre Globe geometry*/const float PI=3.141592653589793;const int iSteps=5;const int jSteps=3;/*radius of the planet*/const float EARTH_RADIUS=6371e3;/*radius of the atmosphere*/const float ATMOS_RADIUS=6471e3;vec2 rsi(vec3 r0,vec3 rd,float sr) {float a=dot(rd,rd);float b=2.0*dot(rd,r0);float c=dot(r0,r0)-(sr*sr);float d=(b*b)-4.0*a*c;if (d < 0.0) return vec2(1e5,-1e5);return vec2((-b-sqrt(d))/(2.0*a),(-b+sqrt(d))/(2.0*a));}vec4 atmosphere(vec3 r,vec3 r0,vec3 pSun,float iSun,float rPlanet,float rAtmos,vec3 kRlh,float kMie,float shRlh,float shMie,float g) {pSun=normalize(pSun);r=normalize(r);vec2 p=rsi(r0,r,rAtmos);if (p.x > p.y) {return vec4(0.0,0.0,0.0,1.0);}if (p.x < 0.0) {p.x=0.0;}vec3 pos=r0+r*p.x;vec2 p2=rsi(r0,r,rPlanet);if (p2.x <=p2.y && p2.x > 0.0) {p.y=min(p.y,p2.x);}float iStepSize=(p.y-p.x)/float(iSteps);float iTime=p.x+iStepSize*0.5;vec3 totalRlh=vec3(0,0,0);vec3 totalMie=vec3(0,0,0);float iOdRlh=0.0;float iOdMie=0.0;float mu=dot(r,pSun);float mumu=mu*mu;float gg=g*g;float pRlh=3.0/(16.0*PI)*(1.0+mumu);float pMie=3.0/(8.0*PI)*((1.0-gg)*(mumu+1.0))/(pow(1.0+gg-2.0*mu*g,1.5)*(2.0+gg));for (int i=0; i < iSteps; i++) {vec3 iPos=r0+r*iTime;float iHeight=length(iPos)-rPlanet;float odStepRlh=exp(-iHeight/shRlh)*iStepSize;float odStepMie=exp(-iHeight/shMie)*iStepSize;iOdRlh+=odStepRlh;iOdMie+=odStepMie;float jStepSize=rsi(iPos,pSun,rAtmos).y/float(jSteps);float jTime=jStepSize*0.5;float jOdRlh=0.0;float jOdMie=0.0;for (int j=0; j < jSteps; j++) {vec3 jPos=iPos+pSun*jTime;float jHeight=length(jPos)-rPlanet;jOdRlh+=exp(-jHeight/shRlh)*jStepSize;jOdMie+=exp(-jHeight/shMie)*jStepSize;jTime+=jStepSize;}vec3 attn=exp(-(kMie*(iOdMie+jOdMie)+kRlh*(iOdRlh+jOdRlh)));totalRlh+=odStepRlh*attn;totalMie+=odStepMie*attn;iTime+=iStepSize;}float opacity=exp(-(length(kRlh)*length(totalRlh)+kMie*length(totalMie)));vec3 color=iSun*(pRlh*kRlh*totalRlh+pMie*kMie*totalMie);return vec4(color,opacity);}void main() {vec3 scale_camera_pos=-u_globe_position*EARTH_RADIUS/u_globe_radius;vec4 color=atmosphere(normalize(view_direction),scale_camera_pos,u_sun_pos,22.0,EARTH_RADIUS,ATMOS_RADIUS,vec3(5.5e-6,13.0e-6,22.4e-6),21e-6,8e3,1.2e3,0.758\n);color.rgb=1.0-exp(-1.0*color.rgb);color=pow(color,vec4(1.0/2.2));fragColor=vec4(color.rgb,1.0-color.a)*u_atmosphere_blend;}", "layout(location=0) in vec2 a_pos;uniform mat4 u_inv_proj_matrix;out vec3 view_direction;void main() {view_direction=(u_inv_proj_matrix*vec4(a_pos,0.0,1.0)).xyz;gl_Position=vec4(a_pos,0.0,1.0);}"),
8306
8301
  sky: prepare("uniform vec4 u_sky_color;uniform vec4 u_horizon_color;uniform vec2 u_horizon;uniform vec2 u_horizon_normal;uniform float u_sky_horizon_blend;uniform float u_sky_blend;void main() {float x=gl_FragCoord.x;float y=gl_FragCoord.y;float blend=(y-u_horizon.y)*u_horizon_normal.y+(x-u_horizon.x)*u_horizon_normal.x;if (blend > 0.0) {if (blend < u_sky_horizon_blend) {fragColor=mix(u_sky_color,u_horizon_color,pow(1.0-blend/u_sky_horizon_blend,2.0));} else {fragColor=u_sky_color;}}fragColor=mix(fragColor,vec4(vec3(0.0),0.0),u_sky_blend);}", "layout(location=0) in vec2 a_pos;void main() {gl_Position=vec4(a_pos,1.0,1.0);}")
8307
8302
  };
@@ -8444,11 +8439,7 @@ var MercatorProjection = class {
8444
8439
  get transitionState() {
8445
8440
  return 0;
8446
8441
  }
8447
- get latitudeErrorCorrectionRadians() {
8448
- return 0;
8449
- }
8450
8442
  destroy() {}
8451
- updateGPUdependent(_) {}
8452
8443
  getMeshFromTileID(context, _tileID, _hasBorder, _allowPoles, _usage) {
8453
8444
  if (this._cachedMesh) return this._cachedMesh;
8454
8445
  const tileExtentArray = new PosArray();
@@ -8469,7 +8460,6 @@ var MercatorProjection = class {
8469
8460
  hasTransition() {
8470
8461
  return false;
8471
8462
  }
8472
- setErrorQueryLatitudeDegrees(_value) {}
8473
8463
  };
8474
8464
  //#endregion
8475
8465
  //#region src/geo/edge_insets.ts
@@ -8512,7 +8502,9 @@ var EdgeInsets = class EdgeInsets {
8512
8502
  * @returns the point
8513
8503
  */
8514
8504
  getCenter(width, height) {
8515
- return new Point(clamp((this.left + width - this.right) / 2, 0, width), clamp((this.top + height - this.bottom) / 2, 0, height));
8505
+ const x = clamp((this.left + width - this.right) / 2, 0, width);
8506
+ const y = clamp((this.top + height - this.bottom) / 2, 0, height);
8507
+ return new Point(x, y);
8516
8508
  }
8517
8509
  equals(other) {
8518
8510
  return this.top === other.top && this.bottom === other.bottom && this.left === other.left && this.right === other.right;
@@ -9164,13 +9156,13 @@ var MercatorCoveringTilesDetailsProvider = class {
9164
9156
  * @param tileID - Tile x, y and z for zoom.
9165
9157
  */
9166
9158
  getTileBoundingVolume(tileID, wrap, elevation, options) {
9167
- let minElevation = 0;
9168
- let maxElevation = 0;
9159
+ let minElevation = Math.min(0, elevation);
9160
+ let maxElevation = Math.max(0, elevation);
9169
9161
  if (options?.terrain) {
9170
9162
  const overscaledTileID = new OverscaledTileID(tileID.z, wrap, tileID.z, tileID.x, tileID.y);
9171
9163
  const minMax = options.terrain.getMinMaxElevation(overscaledTileID);
9172
- minElevation = minMax.minElevation ?? Math.min(0, elevation);
9173
- maxElevation = minMax.maxElevation ?? Math.max(0, elevation);
9164
+ minElevation = minMax.minElevation ?? minElevation;
9165
+ maxElevation = minMax.maxElevation ?? maxElevation;
9174
9166
  }
9175
9167
  const numTiles = 1 << tileID.z;
9176
9168
  return new Aabb([
@@ -9184,7 +9176,8 @@ var MercatorCoveringTilesDetailsProvider = class {
9184
9176
  ]);
9185
9177
  }
9186
9178
  allowVariableZoom(transform, options) {
9187
- const maxConstantZoomPitch = clamp(78.5 - transform.fov * (Math.abs(Math.cos(transform.rollInRadians)) * transform.height + Math.abs(Math.sin(transform.rollInRadians)) * transform.width) / transform.height / 2, 0, 60);
9179
+ const zfov = transform.fov * (Math.abs(Math.cos(transform.rollInRadians)) * transform.height + Math.abs(Math.sin(transform.rollInRadians)) * transform.width) / transform.height;
9180
+ const maxConstantZoomPitch = clamp(78.5 - zfov / 2, 0, 60);
9188
9181
  return !!options.terrain || transform.pitch > maxConstantZoomPitch;
9189
9182
  }
9190
9183
  allowWorldCopies() {
@@ -9318,7 +9311,9 @@ var Frustum = class Frustum {
9318
9311
  const frustumCoords = clipSpaceCorners.map((v) => unprojectClipSpacePoint(v, invProj, worldSize, scale));
9319
9312
  if (horizonPlane) adjustFarPlaneByHorizonPlane(frustumCoords, frustumPlanePointIndices[0], horizonPlane, flippedNearFar);
9320
9313
  const frustumPlanes = frustumPlanePointIndices.map((p) => {
9321
- const n = normalize([], cross([], sub([], frustumCoords[p[0]], frustumCoords[p[1]]), sub([], frustumCoords[p[2]], frustumCoords[p[1]])));
9314
+ const a = sub([], frustumCoords[p[0]], frustumCoords[p[1]]);
9315
+ const b = sub([], frustumCoords[p[2]], frustumCoords[p[1]]);
9316
+ const n = normalize([], cross([], a, b));
9322
9317
  const d = -dot(n, frustumCoords[p[1]]);
9323
9318
  return n.concat(d);
9324
9319
  });
@@ -9412,12 +9407,15 @@ function getNormalizedNearPlane(frustumCoords, nearPlanePointsIndices) {
9412
9407
  * Returns the ideal distance between the frustum's near and far plane so that the far plane only lies as far as the horizon.
9413
9408
  */
9414
9409
  function getIdealNearFarPlaneDistance(horizonPlane, nearPlaneNormalized) {
9415
- const normalizedHorizonPlane = scale$3([], horizonPlane, 1 / len(horizonPlane));
9410
+ const horizonPlaneLen = len(horizonPlane);
9411
+ const normalizedHorizonPlane = scale$3([], horizonPlane, 1 / horizonPlaneLen);
9416
9412
  const projectedViewDirection = sub([], nearPlaneNormalized, scale$2([], normalizedHorizonPlane, dot(nearPlaneNormalized, normalizedHorizonPlane)));
9417
9413
  const projectedViewLength = len(projectedViewDirection);
9418
9414
  if (projectedViewLength > 0) {
9419
9415
  const horizonCircleRadius = Math.sqrt(1 - normalizedHorizonPlane[3] * normalizedHorizonPlane[3]);
9420
- return pointPlaneSignedDistance(nearPlaneNormalized, add([], scale$2([], normalizedHorizonPlane, -normalizedHorizonPlane[3]), scale$2([], projectedViewDirection, horizonCircleRadius / projectedViewLength)));
9416
+ const horizonCircleCenter = scale$2([], normalizedHorizonPlane, -normalizedHorizonPlane[3]);
9417
+ const pointFurthestOnHorizonCircle = add([], horizonCircleCenter, scale$2([], projectedViewDirection, horizonCircleRadius / projectedViewLength));
9418
+ return pointPlaneSignedDistance(nearPlaneNormalized, pointFurthestOnHorizonCircle);
9421
9419
  } else return null;
9422
9420
  }
9423
9421
  //#endregion
@@ -9612,7 +9610,7 @@ var MercatorTransform = class MercatorTransform {
9612
9610
  get autoCalculateNearFarZ() {
9613
9611
  return this._helper.autoCalculateNearFarZ;
9614
9612
  }
9615
- setTransitionState(_value, _error) {}
9613
+ setTransitionState(_value) {}
9616
9614
  constructor(options) {
9617
9615
  this._posMatrixCache = /* @__PURE__ */ new Map();
9618
9616
  this._alignedPosMatrixCache = /* @__PURE__ */ new Map();
@@ -9624,7 +9622,7 @@ var MercatorTransform = class MercatorTransform {
9624
9622
  zoom
9625
9623
  };
9626
9624
  let lngRange = this._helper._lngRange;
9627
- if (!this._helper._renderWorldCopies && lngRange === null) lngRange = [-179.9999999999, 179.9999999999];
9625
+ if (!this._helper._renderWorldCopies && lngRange === null) lngRange = [-179.9999999999, 180 - 1e-10];
9628
9626
  const worldSize = this.tileSize * zoomScale(result.zoom);
9629
9627
  let minY = 0;
9630
9628
  let maxY = worldSize;
@@ -9649,7 +9647,8 @@ var MercatorTransform = class MercatorTransform {
9649
9647
  let modifiedX, modifiedY;
9650
9648
  const scale = Math.max(scaleX || 0, scaleY || 0);
9651
9649
  if (scale) {
9652
- result.center = unprojectFromWorldCoordinates(worldSize, new Point(scaleX ? (maxX + minX) / 2 : originalX, scaleY ? (maxY + minY) / 2 : originalY)).wrap();
9650
+ const newPoint = new Point(scaleX ? (maxX + minX) / 2 : originalX, scaleY ? (maxY + minY) / 2 : originalY);
9651
+ result.center = unprojectFromWorldCoordinates(worldSize, newPoint).wrap();
9653
9652
  result.zoom += scaleZoom(scale);
9654
9653
  return result;
9655
9654
  }
@@ -9666,7 +9665,10 @@ var MercatorTransform = class MercatorTransform {
9666
9665
  if (wrappedX - w2 < minX) modifiedX = minX + w2;
9667
9666
  if (wrappedX + w2 > maxX) modifiedX = maxX - w2;
9668
9667
  }
9669
- if (modifiedX !== void 0 || modifiedY !== void 0) result.center = unprojectFromWorldCoordinates(worldSize, new Point(modifiedX ?? originalX, modifiedY ?? originalY)).wrap();
9668
+ if (modifiedX !== void 0 || modifiedY !== void 0) {
9669
+ const newPoint = new Point(modifiedX ?? originalX, modifiedY ?? originalY);
9670
+ result.center = unprojectFromWorldCoordinates(worldSize, newPoint).wrap();
9671
+ }
9670
9672
  return result;
9671
9673
  };
9672
9674
  this.applyConstrain = (lngLat, zoom) => {
@@ -10020,7 +10022,8 @@ var MercatorTransform = class MercatorTransform {
10020
10022
  0
10021
10023
  ],
10022
10024
  projectionTransition: 0,
10023
- fallbackMatrix: mainMatrix
10025
+ fallbackMatrix: mainMatrix,
10026
+ clipAntimeridian: false
10024
10027
  };
10025
10028
  }
10026
10029
  isLocationOccluded(_) {
@@ -10159,7 +10162,9 @@ function cameraForBoxAndBearing(options, padding, bounds, bearing, tr) {
10159
10162
  }
10160
10163
  const zoom = Math.min(scaleZoom(tr.scale * Math.min(scaleX, scaleY)), options.maxZoom);
10161
10164
  const offset = Point.convert(options.offset);
10162
- const rotatedPaddingOffset = new Point((padding.left - padding.right) / 2, (padding.top - padding.bottom) / 2).rotate(degreesToRadians(bearing));
10165
+ const paddingOffsetX = (padding.left - padding.right) / 2;
10166
+ const paddingOffsetY = (padding.top - padding.bottom) / 2;
10167
+ const rotatedPaddingOffset = new Point(paddingOffsetX, paddingOffsetY).rotate(degreesToRadians(bearing));
10163
10168
  const offsetAtFinalZoom = offset.add(rotatedPaddingOffset).mult(tr.scale / zoomScale(zoom));
10164
10169
  return {
10165
10170
  center: unprojectFromWorldCoordinates(tr.worldSize, nwWorld.add(seWorld).div(2).sub(offsetAtFinalZoom)),
@@ -10290,238 +10295,6 @@ var MercatorCameraHelper = class {
10290
10295
  let properties;
10291
10296
  const getProperties = () => properties = properties || new Properties({ "type": new DataConstantProperty(latest["projection"]["type"], "type") });
10292
10297
  //#endregion
10293
- //#region src/webgl/color_mode.ts
10294
- const ZERO = 0;
10295
- const ONE = 1;
10296
- const ONE_MINUS_SRC_ALPHA = 771;
10297
- var ColorMode = class {
10298
- constructor(blendFunction, blendColor, mask) {
10299
- this.blendFunction = blendFunction;
10300
- this.blendColor = blendColor;
10301
- this.mask = mask;
10302
- }
10303
- };
10304
- ColorMode.Replace = [ONE, ZERO];
10305
- ColorMode.disabled = new ColorMode(ColorMode.Replace, Color.transparent, [
10306
- false,
10307
- false,
10308
- false,
10309
- false
10310
- ]);
10311
- ColorMode.unblended = new ColorMode(ColorMode.Replace, Color.transparent, [
10312
- true,
10313
- true,
10314
- true,
10315
- true
10316
- ]);
10317
- ColorMode.alphaBlended = new ColorMode([ONE, ONE_MINUS_SRC_ALPHA], Color.transparent, [
10318
- true,
10319
- true,
10320
- true,
10321
- true
10322
- ]);
10323
- //#endregion
10324
- //#region src/webgl/cull_face_mode.ts
10325
- const FRONT = 1028;
10326
- const BACK = 1029;
10327
- const CCW = 2305;
10328
- var CullFaceMode = class {
10329
- constructor(enable, mode, frontFace) {
10330
- this.enable = enable;
10331
- this.mode = mode;
10332
- this.frontFace = frontFace;
10333
- }
10334
- };
10335
- CullFaceMode.disabled = new CullFaceMode(false, BACK, CCW);
10336
- CullFaceMode.backCCW = new CullFaceMode(true, BACK, CCW);
10337
- CullFaceMode.frontCCW = new CullFaceMode(true, FRONT, CCW);
10338
- //#endregion
10339
- //#region src/webgl/depth_mode.ts
10340
- const ALWAYS$1 = 519;
10341
- var DepthMode = class {
10342
- constructor(depthFunc, depthMask, depthRange) {
10343
- this.func = depthFunc;
10344
- this.mask = depthMask;
10345
- this.range = depthRange;
10346
- }
10347
- };
10348
- DepthMode.ReadOnly = false;
10349
- DepthMode.ReadWrite = true;
10350
- DepthMode.disabled = new DepthMode(ALWAYS$1, DepthMode.ReadOnly, [0, 1]);
10351
- //#endregion
10352
- //#region src/webgl/stencil_mode.ts
10353
- const ALWAYS = 519;
10354
- const KEEP = 7680;
10355
- var StencilMode = class {
10356
- constructor(test, ref, mask, fail, depthFail, pass) {
10357
- this.test = test;
10358
- this.ref = ref;
10359
- this.mask = mask;
10360
- this.fail = fail;
10361
- this.depthFail = depthFail;
10362
- this.pass = pass;
10363
- }
10364
- };
10365
- StencilMode.disabled = new StencilMode({
10366
- func: ALWAYS,
10367
- mask: 0
10368
- }, 0, 0, KEEP, KEEP, KEEP);
10369
- //#endregion
10370
- //#region src/webgl/program/projection_error_measurement_program.ts
10371
- const projectionErrorMeasurementUniforms = (context, locations) => ({
10372
- "u_input": new Uniform1f(context, locations.u_input),
10373
- "u_output_expected": new Uniform1f(context, locations.u_output_expected)
10374
- });
10375
- const projectionErrorMeasurementUniformValues = (input, outputExpected) => ({
10376
- "u_input": input,
10377
- "u_output_expected": outputExpected
10378
- });
10379
- //#endregion
10380
- //#region src/geo/projection/globe_projection_error_measurement.ts
10381
- /**
10382
- * For vector globe the vertex shader projects mercator coordinates to angular coordinates on a sphere.
10383
- * This projection requires some inverse trigonometry `atan(exp(...))`, which is inaccurate on some GPUs (mainly on AMD and Nvidia).
10384
- * The inaccuracy is severe enough to require a workaround. The uncorrected map is shifted north-south by up to several hundred meters in some latitudes.
10385
- * Since the inaccuracy is hardware-dependant and may change in the future, we need to measure the error at runtime.
10386
- *
10387
- * Our approach relies on several assumptions:
10388
- *
10389
- * - the error is only present in the "latitude" component (longitude doesn't need any inverse trigonometry)
10390
- * - the error is continuous and changes slowly with latitude
10391
- * - at zoom levels where the error is noticeable, the error is more-or-less the same across the entire visible map area (and thus can be described with a single number)
10392
- *
10393
- * Solution:
10394
- *
10395
- * Every few frames, launch a GPU shader that measures the error for the current map center latitude, and writes it to a 1x1 texture.
10396
- * Read back that texture, and offset the globe projection matrix according to the error (interpolating smoothly from old error to new error if needed).
10397
- * The texture readback is done asynchronously using Pixel Pack Buffers (WebGL2) when possible, and has a few frames of latency, but that should not be a problem.
10398
- *
10399
- * General operation of this class each frame is:
10400
- *
10401
- * - render the error shader into a fbo, read that pixel into a PBO, place a fence
10402
- * - wait a few frames to allow the GPU (and driver) to actually execute the shader
10403
- * - wait for the fence to be signalled (guaranteeing the shader to actually be executed)
10404
- * - read back the PBO's contents
10405
- * - wait a few more frames
10406
- * - repeat
10407
- */
10408
- var ProjectionErrorMeasurement = class ProjectionErrorMeasurement {
10409
- get awaitingQuery() {
10410
- return !!this._readbackQueue;
10411
- }
10412
- constructor(renderContext) {
10413
- this._readbackWaitFrames = 4;
10414
- this._measureWaitFrames = 6;
10415
- this._texWidth = 1;
10416
- this._texHeight = 1;
10417
- this._measuredError = 0;
10418
- this._updateCount = 0;
10419
- this._lastReadbackFrame = -1e3;
10420
- this._readbackQueue = null;
10421
- this._cachedRenderContext = renderContext;
10422
- const context = renderContext.context;
10423
- const gl = context.gl;
10424
- this._texFormat = gl.RGBA;
10425
- this._texType = gl.UNSIGNED_BYTE;
10426
- const vertexArray = new PosArray();
10427
- vertexArray.emplaceBack(-1, -1);
10428
- vertexArray.emplaceBack(2, -1);
10429
- vertexArray.emplaceBack(-1, 2);
10430
- const indexArray = new TriangleIndexArray();
10431
- indexArray.emplaceBack(0, 1, 2);
10432
- this._fullscreenTriangle = new Mesh(context.createVertexBuffer(vertexArray, posAttributes.members), context.createIndexBuffer(indexArray), SegmentVector.simpleSegment(0, 0, vertexArray.length, indexArray.length));
10433
- this._resultBuffer = /* @__PURE__ */ new Uint8Array(4);
10434
- context.activeTexture.set(gl.TEXTURE1);
10435
- const texture = gl.createTexture();
10436
- gl.bindTexture(gl.TEXTURE_2D, texture);
10437
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
10438
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
10439
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
10440
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
10441
- gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA8, this._texWidth, this._texHeight);
10442
- this._fbo = context.createFramebuffer(this._texWidth, this._texHeight, false, false);
10443
- this._fbo.colorAttachment.set(texture);
10444
- this._pbo = gl.createBuffer();
10445
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, this._pbo);
10446
- gl.bufferData(gl.PIXEL_PACK_BUFFER, 4, gl.STREAM_READ);
10447
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
10448
- }
10449
- destroy() {
10450
- const gl = this._cachedRenderContext.context.gl;
10451
- this._fullscreenTriangle.destroy();
10452
- this._fbo.destroy();
10453
- gl.deleteBuffer(this._pbo);
10454
- this._fullscreenTriangle = null;
10455
- this._fbo = null;
10456
- this._pbo = null;
10457
- this._resultBuffer = null;
10458
- }
10459
- updateErrorLoop(normalizedMercatorY, expectedAngleY) {
10460
- const currentFrame = this._updateCount;
10461
- if (this._readbackQueue) {
10462
- if (currentFrame >= this._readbackQueue.frameNumberIssued + this._readbackWaitFrames) this._tryReadback();
10463
- } else if (currentFrame >= this._lastReadbackFrame + this._measureWaitFrames) this._renderErrorTexture(normalizedMercatorY, expectedAngleY);
10464
- this._updateCount++;
10465
- return this._measuredError;
10466
- }
10467
- _bindFramebuffer() {
10468
- const context = this._cachedRenderContext.context;
10469
- const gl = context.gl;
10470
- context.activeTexture.set(gl.TEXTURE1);
10471
- gl.bindTexture(gl.TEXTURE_2D, this._fbo.colorAttachment.get());
10472
- context.bindFramebuffer.set(this._fbo.framebuffer);
10473
- }
10474
- _renderErrorTexture(input, outputExpected) {
10475
- const context = this._cachedRenderContext.context;
10476
- const gl = context.gl;
10477
- this._bindFramebuffer();
10478
- context.viewport.set([
10479
- 0,
10480
- 0,
10481
- this._texWidth,
10482
- this._texHeight
10483
- ]);
10484
- context.clear({ color: Color.transparent });
10485
- this._cachedRenderContext.useProgram("projectionErrorMeasurement").draw(context, gl.TRIANGLES, DepthMode.disabled, StencilMode.disabled, ColorMode.unblended, CullFaceMode.disabled, projectionErrorMeasurementUniformValues(input, outputExpected), null, null, "$clipping", this._fullscreenTriangle.vertexBuffer, this._fullscreenTriangle.indexBuffer, this._fullscreenTriangle.segments);
10486
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, this._pbo);
10487
- gl.readBuffer(gl.COLOR_ATTACHMENT0);
10488
- gl.readPixels(0, 0, this._texWidth, this._texHeight, this._texFormat, this._texType, 0);
10489
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
10490
- const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
10491
- gl.flush();
10492
- this._readbackQueue = {
10493
- frameNumberIssued: this._updateCount,
10494
- sync
10495
- };
10496
- }
10497
- _tryReadback() {
10498
- const gl = this._cachedRenderContext.context.gl;
10499
- if (!this._readbackQueue) return;
10500
- const waitResult = gl.clientWaitSync(this._readbackQueue.sync, 0, 0);
10501
- if (waitResult === gl.WAIT_FAILED) {
10502
- warnOnce("WebGL2 clientWaitSync failed.");
10503
- this._readbackQueue = null;
10504
- this._lastReadbackFrame = this._updateCount;
10505
- return;
10506
- }
10507
- if (waitResult === gl.TIMEOUT_EXPIRED) return;
10508
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, this._pbo);
10509
- gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, this._resultBuffer, 0, 4);
10510
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
10511
- this._readbackQueue = null;
10512
- this._measuredError = ProjectionErrorMeasurement._parseRGBA8float(this._resultBuffer);
10513
- this._lastReadbackFrame = this._updateCount;
10514
- }
10515
- static _parseRGBA8float(buffer) {
10516
- let result = 0;
10517
- result += buffer[0] / 256;
10518
- result += buffer[1] / 65536;
10519
- result += buffer[2] / 16777216;
10520
- if (buffer[3] < 127) result = -result;
10521
- return result / 128;
10522
- }
10523
- };
10524
- //#endregion
10525
10298
  //#region src/util/create_tile_mesh.ts
10526
10299
  /**
10527
10300
  * The size of border region for stencil masks, in internal tile coordinates.
@@ -10622,7 +10395,6 @@ function createTileMesh(options, forceIndicesSize) {
10622
10395
  //#region src/geo/projection/vertical_perspective_projection.ts
10623
10396
  const VerticalPerspectiveShaderDefine = "#define GLOBE";
10624
10397
  const VerticalPerspectiveShaderVariantKey = "globe";
10625
- const globeConstants = { errorTransitionTimeSeconds: .5 };
10626
10398
  const granularitySettingsGlobe = new SubdivisionGranularitySetting({
10627
10399
  fill: new SubdivisionGranularityExpression(128, 2),
10628
10400
  line: new SubdivisionGranularityExpression(512, 0),
@@ -10633,10 +10405,6 @@ const granularitySettingsGlobe = new SubdivisionGranularitySetting({
10633
10405
  var VerticalPerspectiveProjection = class {
10634
10406
  constructor() {
10635
10407
  this._tileMeshCache = {};
10636
- this._errorCorrectionUsable = 0;
10637
- this._errorMeasurementLastValue = 0;
10638
- this._errorCorrectionPreviousValue = 0;
10639
- this._errorMeasurementLastChangeTime = -1e3;
10640
10408
  }
10641
10409
  get name() {
10642
10410
  return "vertical-perspective";
@@ -10665,35 +10433,7 @@ var VerticalPerspectiveProjection = class {
10665
10433
  get useGlobeControls() {
10666
10434
  return true;
10667
10435
  }
10668
- /**
10669
- * @internal
10670
- * Globe projection periodically measures the error of the GPU's
10671
- * projection from mercator to globe and computes how much to correct
10672
- * the globe's latitude alignment.
10673
- * This stores the correction that should be applied to the projection matrix.
10674
- */
10675
- get latitudeErrorCorrectionRadians() {
10676
- return this._errorCorrectionUsable;
10677
- }
10678
- destroy() {
10679
- if (this._errorMeasurement) this._errorMeasurement.destroy();
10680
- }
10681
- updateGPUdependent(renderContext) {
10682
- this._errorMeasurement ||= new ProjectionErrorMeasurement(renderContext);
10683
- const mercatorY = mercatorYfromLat(this._errorQueryLatitudeDegrees);
10684
- const expectedResult = 2 * Math.atan(Math.exp(Math.PI - mercatorY * Math.PI * 2)) - Math.PI * .5;
10685
- const newValue = this._errorMeasurement.updateErrorLoop(mercatorY, expectedResult);
10686
- const currentTime = now();
10687
- if (newValue !== this._errorMeasurementLastValue) {
10688
- this._errorCorrectionPreviousValue = this._errorCorrectionUsable;
10689
- this._errorMeasurementLastValue = newValue;
10690
- this._errorMeasurementLastChangeTime = currentTime;
10691
- }
10692
- const sinceUpdateSeconds = (currentTime - this._errorMeasurementLastChangeTime) / 1e3;
10693
- const mix = Math.min(Math.max(sinceUpdateSeconds / globeConstants.errorTransitionTimeSeconds, 0), 1);
10694
- const newCorrection = -this._errorMeasurementLastValue;
10695
- this._errorCorrectionUsable = lerp(this._errorCorrectionPreviousValue, newCorrection, easeCubicInOut(mix));
10696
- }
10436
+ destroy() {}
10697
10437
  _getMeshKey(options) {
10698
10438
  return `${options.granularity.toString(36)}_${options.generateBorders ? "b" : ""}${options.extendToNorthPole ? "n" : ""}${options.extendToSouthPole ? "s" : ""}`;
10699
10439
  }
@@ -10717,22 +10457,15 @@ var VerticalPerspectiveProjection = class {
10717
10457
  }
10718
10458
  recalculate(_params) {}
10719
10459
  hasTransition() {
10720
- const currentTime = now();
10721
- let dirty = false;
10722
- dirty ||= (currentTime - this._errorMeasurementLastChangeTime) / 1e3 < globeConstants.errorTransitionTimeSeconds + .2;
10723
- dirty ||= this._errorMeasurement?.awaitingQuery;
10724
- return dirty;
10725
- }
10726
- setErrorQueryLatitudeDegrees(value) {
10727
- this._errorQueryLatitudeDegrees = value;
10460
+ return false;
10728
10461
  }
10729
10462
  };
10730
10463
  //#endregion
10731
10464
  //#region src/geo/projection/globe_projection.ts
10732
10465
  var GlobeProjection = class extends Evented {
10733
- constructor(projection) {
10466
+ constructor(projection, globalState) {
10734
10467
  super();
10735
- this._transitionable = new Transitionable(getProperties(), "projection", void 0);
10468
+ this._transitionable = new Transitionable(getProperties(), "projection", globalState);
10736
10469
  this.setProjection(projection);
10737
10470
  this._transitioning = this._transitionable.untransitioned();
10738
10471
  this.recalculate(new EvaluationParameters(0));
@@ -10744,6 +10477,7 @@ var GlobeProjection = class extends Evented {
10744
10477
  if (typeof currentProjectionSpecValue === "string" && currentProjectionSpecValue === "mercator") return 0;
10745
10478
  if (typeof currentProjectionSpecValue === "string" && currentProjectionSpecValue === "vertical-perspective") return 1;
10746
10479
  if (currentProjectionSpecValue instanceof ProjectionDefinition) {
10480
+ if (currentProjectionSpecValue.from === currentProjectionSpecValue.to) return currentProjectionSpecValue.from === "mercator" ? 0 : 1;
10747
10481
  if (currentProjectionSpecValue.from === "vertical-perspective" && currentProjectionSpecValue.to === "mercator") return 1 - currentProjectionSpecValue.transition;
10748
10482
  if (currentProjectionSpecValue.from === "mercator" && currentProjectionSpecValue.to === "vertical-perspective") return currentProjectionSpecValue.transition;
10749
10483
  }
@@ -10752,9 +10486,6 @@ var GlobeProjection = class extends Evented {
10752
10486
  get useGlobeRendering() {
10753
10487
  return this.transitionState > 0;
10754
10488
  }
10755
- get latitudeErrorCorrectionRadians() {
10756
- return this._verticalPerspectiveProjection.latitudeErrorCorrectionRadians;
10757
- }
10758
10489
  get currentProjection() {
10759
10490
  return this.useGlobeRendering ? this._verticalPerspectiveProjection : this._mercatorProjection;
10760
10491
  }
@@ -10786,10 +10517,6 @@ var GlobeProjection = class extends Evented {
10786
10517
  this._mercatorProjection.destroy();
10787
10518
  this._verticalPerspectiveProjection.destroy();
10788
10519
  }
10789
- updateGPUdependent(context) {
10790
- this._mercatorProjection.updateGPUdependent(context);
10791
- this._verticalPerspectiveProjection.updateGPUdependent(context);
10792
- }
10793
10520
  getMeshFromTileID(context, _tileID, _hasBorder, _allowPoles, _usage) {
10794
10521
  return this.currentProjection.getMeshFromTileID(context, _tileID, _hasBorder, _allowPoles, _usage);
10795
10522
  }
@@ -10805,10 +10532,6 @@ var GlobeProjection = class extends Evented {
10805
10532
  recalculate(parameters) {
10806
10533
  this.properties = this._transitioning.possiblyEvaluate(parameters);
10807
10534
  }
10808
- setErrorQueryLatitudeDegrees(value) {
10809
- this._verticalPerspectiveProjection.setErrorQueryLatitudeDegrees(value);
10810
- this._mercatorProjection.setErrorQueryLatitudeDegrees(value);
10811
- }
10812
10535
  };
10813
10536
  //#endregion
10814
10537
  //#region src/geo/projection/globe_utils.ts
@@ -10817,7 +10540,9 @@ function getGlobeCircumferencePixels(transform) {
10817
10540
  return 2 * Math.PI * radius;
10818
10541
  }
10819
10542
  function globeDistanceOfLocationsPixels(transform, a, b) {
10820
- const dot$2 = dot(angularCoordinatesToSurfaceVector(a), angularCoordinatesToSurfaceVector(b));
10543
+ const vecA = angularCoordinatesToSurfaceVector(a);
10544
+ const vecB = angularCoordinatesToSurfaceVector(b);
10545
+ const dot$2 = dot(vecA, vecB);
10821
10546
  const radians = Math.acos(dot$2);
10822
10547
  const circumference = getGlobeCircumferencePixels(transform);
10823
10548
  return radians / (2 * Math.PI) * circumference;
@@ -10883,7 +10608,8 @@ function sphereSurfacePointToCoordinates(surface) {
10883
10608
  const projX = surface[0] / lengthXZ;
10884
10609
  const projZ = surface[2] / lengthXZ;
10885
10610
  const acosZ = Math.acos(projZ);
10886
- return new LngLat(wrap((projX > 0 ? acosZ : -acosZ) / Math.PI * 180, -180, 180), latDegrees);
10611
+ const lngDegrees = (projX > 0 ? acosZ : -acosZ) / Math.PI * 180;
10612
+ return new LngLat(wrap(lngDegrees, -180, 180), latDegrees);
10887
10613
  } else return new LngLat(0, latDegrees);
10888
10614
  }
10889
10615
  /**
@@ -10929,7 +10655,8 @@ function planetScaleAtLatitude(latitudeDegrees) {
10929
10655
  */
10930
10656
  function getZoomAdjustment(oldLat, newLat) {
10931
10657
  const oldCircumference = planetScaleAtLatitude(oldLat);
10932
- return scaleZoom(planetScaleAtLatitude(newLat) / oldCircumference);
10658
+ const newCircumference = planetScaleAtLatitude(newLat);
10659
+ return scaleZoom(newCircumference / oldCircumference);
10933
10660
  }
10934
10661
  function getDegreesPerPixel(worldSize, lat) {
10935
10662
  return 360 / getGlobeCircumferencePixels({
@@ -10977,8 +10704,12 @@ function interpolateLngLatForGlobe(start, deltaLng, deltaLat, t) {
10977
10704
  const valueStart = integrateSecX(samplePointStart);
10978
10705
  const valueEnd = integrateSecX(samplePointEnd);
10979
10706
  const newT = (valueT - valueStart) / (valueEnd - valueStart);
10980
- return new LngLat(start.lng + deltaLng * newT, interpolatedLat);
10981
- } else return new LngLat(start.lng + deltaLng * t, interpolatedLat);
10707
+ const interpolatedLng = start.lng + deltaLng * newT;
10708
+ return new LngLat(interpolatedLng, interpolatedLat);
10709
+ } else {
10710
+ const interpolatedLng = start.lng + deltaLng * t;
10711
+ return new LngLat(interpolatedLng, interpolatedLat);
10712
+ }
10982
10713
  }
10983
10714
  //#endregion
10984
10715
  //#region src/util/primitives/bounding_volume_cache.ts
@@ -11006,7 +10737,7 @@ var BoundingVolumeCache = class {
11006
10737
  * @param tileID - Tile x, y and z for zoom.
11007
10738
  */
11008
10739
  getTileBoundingVolume(tileID, wrap, elevation, options) {
11009
- const key = `${tileID.z}_${tileID.x}_${tileID.y}_${options?.terrain ? "t" : ""}`;
10740
+ const key = `${tileID.z}_${tileID.x}_${tileID.y}_${options?.terrain ? "t" : ""}_${Math.round(elevation)}`;
11010
10741
  const cached = this._cache.get(key);
11011
10742
  if (cached) return cached;
11012
10743
  const cachedPrevious = this._cachePrevious.get(key);
@@ -11244,9 +10975,8 @@ var GlobeCoveringTilesDetailsProvider = class {
11244
10975
  const tileMercatorSize = 1 / scale;
11245
10976
  const tileCornerX = tileID.x / scale;
11246
10977
  const tileCornerY = tileID.y / scale;
11247
- const worldSize = 1;
11248
- const halfWorld = .5 * worldSize;
11249
- let smallestDistance = 2 * worldSize;
10978
+ const halfWorld = .5;
10979
+ let smallestDistance = 2;
11250
10980
  smallestDistance = Math.min(smallestDistance, distanceToTileWrapX(pointX, pointY, tileCornerX, tileCornerY, tileMercatorSize));
11251
10981
  smallestDistance = Math.min(smallestDistance, distanceToTileWrapX(pointX, pointY, tileCornerX + halfWorld, -tileCornerY - tileMercatorSize, tileMercatorSize));
11252
10982
  smallestDistance = Math.min(smallestDistance, distanceToTileWrapX(pointX, pointY, tileCornerX + halfWorld, 2 - tileCornerY - tileMercatorSize, tileMercatorSize));
@@ -11277,13 +11007,13 @@ var GlobeCoveringTilesDetailsProvider = class {
11277
11007
  return this._boundingVolumeCache.getTileBoundingVolume(tileID, wrap, elevation, options);
11278
11008
  }
11279
11009
  _computeTileBoundingVolume(tileID, wrap, elevation, options) {
11280
- let minElevation = 0;
11281
- let maxElevation = 0;
11010
+ let minElevation = Math.min(0, elevation);
11011
+ let maxElevation = Math.max(0, elevation);
11282
11012
  if (options?.terrain) {
11283
11013
  const overscaledTileID = new OverscaledTileID(tileID.z, wrap, tileID.z, tileID.x, tileID.y);
11284
11014
  const minMax = options.terrain.getMinMaxElevation(overscaledTileID);
11285
- minElevation = minMax.minElevation ?? Math.min(0, elevation);
11286
- maxElevation = minMax.maxElevation ?? Math.max(0, elevation);
11015
+ minElevation = minMax.minElevation ?? minElevation;
11016
+ maxElevation = minMax.maxElevation ?? maxElevation;
11287
11017
  }
11288
11018
  minElevation /= earthRadius;
11289
11019
  maxElevation /= earthRadius;
@@ -11608,11 +11338,10 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
11608
11338
  this._cachedClippingPlane = createVec4f64();
11609
11339
  this._projectionMatrix = createIdentityMat4f64();
11610
11340
  this._globeViewProjMatrix32f = createIdentityMat4f32();
11611
- this._globeViewProjMatrixNoCorrection = createIdentityMat4f64();
11612
- this._globeViewProjMatrixNoCorrectionInverted = createIdentityMat4f64();
11341
+ this._globeViewProjMatrixF64 = createIdentityMat4f64();
11342
+ this._globeViewProjMatrixF64Inverted = createIdentityMat4f64();
11613
11343
  this._globeProjMatrixInverted = createIdentityMat4f64();
11614
11344
  this._cameraPosition = createVec3f64();
11615
- this._globeLatitudeErrorCorrectionRadians = 0;
11616
11345
  this.defaultConstrain = (lngLat, zoom) => {
11617
11346
  const constrainedLat = clamp(lngLat.lat, -MAX_VALID_LATITUDE, MAX_VALID_LATITUDE);
11618
11347
  const constrainedZoom = clamp(+zoom, this.minZoom + getZoomAdjustment(0, constrainedLat), this.maxZoom);
@@ -11637,15 +11366,14 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
11637
11366
  clone.apply(this, false);
11638
11367
  return clone;
11639
11368
  }
11640
- apply(that, constrain, globeLatitudeErrorCorrectionRadians) {
11641
- this._globeLatitudeErrorCorrectionRadians = globeLatitudeErrorCorrectionRadians || 0;
11369
+ apply(that, constrain) {
11642
11370
  this._helper.apply(that, constrain);
11643
11371
  }
11644
11372
  get projectionMatrix() {
11645
11373
  return this._projectionMatrix;
11646
11374
  }
11647
11375
  get modelViewProjectionMatrix() {
11648
- return this._globeViewProjMatrixNoCorrection;
11376
+ return this._globeViewProjMatrixF64;
11649
11377
  }
11650
11378
  get inverseProjectionMatrix() {
11651
11379
  return this._globeProjMatrixInverted;
@@ -11668,7 +11396,8 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
11668
11396
  tileMercatorCoords: mercatorTileCoordinates,
11669
11397
  clippingPlane: this._cachedClippingPlane,
11670
11398
  projectionTransition: applyGlobeMatrix ? 1 : 0,
11671
- fallbackMatrix: this._globeViewProjMatrix32f
11399
+ fallbackMatrix: this._globeViewProjMatrix32f,
11400
+ clipAntimeridian: overscaledTileID?.canonical.z === 0
11672
11401
  };
11673
11402
  }
11674
11403
  _computeClippingPlane(globeRadiusPixels) {
@@ -11766,7 +11495,7 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
11766
11495
  spherePos[2] * vectorMultiplier,
11767
11496
  1
11768
11497
  ];
11769
- transformMat4(pos, pos, this._globeViewProjMatrixNoCorrection);
11498
+ transformMat4(pos, pos, this._globeViewProjMatrixF64);
11770
11499
  const plane = this._cachedClippingPlane;
11771
11500
  const isOccluded = plane[0] * spherePos[0] + plane[1] * spherePos[1] + plane[2] * spherePos[2] + plane[3] < 0;
11772
11501
  return {
@@ -11779,7 +11508,6 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
11779
11508
  if (!this._helper._width || !this._helper._height) return;
11780
11509
  const globeRadiusPixels = getGlobeRadiusPixels(this.worldSize, this.center.lat);
11781
11510
  const globeMatrix = createMat4f64();
11782
- const globeMatrixUncorrected = createMat4f64();
11783
11511
  if (this._helper.autoCalculateNearFarZ) {
11784
11512
  this._helper._nearZ = .5;
11785
11513
  this._helper._farZ = this.cameraToCenterDistance + globeRadiusPixels * 2;
@@ -11808,16 +11536,13 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
11808
11536
  scaleVec[0] = globeRadiusPixels;
11809
11537
  scaleVec[1] = globeRadiusPixels;
11810
11538
  scaleVec[2] = globeRadiusPixels;
11811
- rotateX(globeMatrixUncorrected, globeMatrix, this.center.lat * Math.PI / 180);
11812
- rotateY$1(globeMatrixUncorrected, globeMatrixUncorrected, -this.center.lng * Math.PI / 180);
11813
- scale(globeMatrixUncorrected, globeMatrixUncorrected, scaleVec);
11814
- this._globeViewProjMatrixNoCorrection = globeMatrixUncorrected;
11815
- rotateX(globeMatrix, globeMatrix, this.center.lat * Math.PI / 180 - this._globeLatitudeErrorCorrectionRadians);
11539
+ rotateX(globeMatrix, globeMatrix, this.center.lat * Math.PI / 180);
11816
11540
  rotateY$1(globeMatrix, globeMatrix, -this.center.lng * Math.PI / 180);
11817
11541
  scale(globeMatrix, globeMatrix, scaleVec);
11542
+ this._globeViewProjMatrixF64 = globeMatrix;
11818
11543
  this._globeViewProjMatrix32f = new Float32Array(globeMatrix);
11819
- this._globeViewProjMatrixNoCorrectionInverted = createMat4f64();
11820
- invert$1(this._globeViewProjMatrixNoCorrectionInverted, globeMatrixUncorrected);
11544
+ this._globeViewProjMatrixF64Inverted = createMat4f64();
11545
+ invert$1(this._globeViewProjMatrixF64Inverted, globeMatrix);
11821
11546
  const zero = createVec3f64();
11822
11547
  this._cameraPosition = createVec3f64();
11823
11548
  this._cameraPosition[2] = this.cameraToCenterDistance / globeRadiusPixels;
@@ -11832,7 +11557,7 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
11832
11557
  rotateX$1(this._cameraPosition, this._cameraPosition, zero, -this.center.lat * Math.PI / 180);
11833
11558
  rotateY(this._cameraPosition, this._cameraPosition, zero, this.center.lng * Math.PI / 180);
11834
11559
  this._cachedClippingPlane = this._computeClippingPlane(globeRadiusPixels);
11835
- const matrix = clone$1(this._globeViewProjMatrixNoCorrectionInverted);
11560
+ const matrix = clone$1(this._globeViewProjMatrixF64Inverted);
11836
11561
  scale(matrix, matrix, [
11837
11562
  1,
11838
11563
  1,
@@ -11878,7 +11603,7 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
11878
11603
  return this._helper.getCameraLngLat();
11879
11604
  }
11880
11605
  lngLatToCameraDepth(lngLat, elevation) {
11881
- if (!this._globeViewProjMatrixNoCorrection) return 1;
11606
+ if (!this._globeViewProjMatrixF64) return 1;
11882
11607
  const vec = angularCoordinatesToSurfaceVector(lngLat);
11883
11608
  scale$2(vec, vec, 1 + elevation / earthRadius);
11884
11609
  const result = createVec4f64();
@@ -11887,7 +11612,7 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
11887
11612
  vec[1],
11888
11613
  vec[2],
11889
11614
  1
11890
- ], this._globeViewProjMatrixNoCorrection);
11615
+ ], this._globeViewProjMatrixF64);
11891
11616
  return result[2] / result[3];
11892
11617
  }
11893
11618
  populateCache(_coords) {}
@@ -12004,7 +11729,10 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
12004
11729
  }
12005
11730
  locationToScreenPoint(lnglat, terrain) {
12006
11731
  const pos = angularCoordinatesToSurfaceVector(lnglat);
12007
- if (terrain) scale$2(pos, pos, 1 + terrain.getElevationForLngLatZoom(lnglat, this._helper._tileZoom) / earthRadius);
11732
+ if (terrain) {
11733
+ const elevation = terrain.getElevationForLngLatZoom(lnglat, this._helper._tileZoom);
11734
+ scale$2(pos, pos, 1 + elevation / earthRadius);
11735
+ }
12008
11736
  return this._projectSurfacePointToScreen(pos);
12009
11737
  }
12010
11738
  /**
@@ -12013,7 +11741,7 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
12013
11741
  */
12014
11742
  _projectSurfacePointToScreen(pos) {
12015
11743
  const projected = createVec4f64();
12016
- transformMat4(projected, [...pos, 1], this._globeViewProjMatrixNoCorrection);
11744
+ transformMat4(projected, [...pos, 1], this._globeViewProjMatrixF64);
12017
11745
  projected[0] /= projected[3];
12018
11746
  projected[1] /= projected[3];
12019
11747
  return new Point((projected[0] * .5 + .5) * this.width, (-projected[1] * .5 + .5) * this.height);
@@ -12042,7 +11770,7 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
12042
11770
  pos[1] = (p.y / this.height * 2 - 1) * -1;
12043
11771
  pos[2] = 1;
12044
11772
  pos[3] = 1;
12045
- transformMat4(pos, pos, this._globeViewProjMatrixNoCorrectionInverted);
11773
+ transformMat4(pos, pos, this._globeViewProjMatrixF64Inverted);
12046
11774
  pos[0] /= pos[3];
12047
11775
  pos[1] /= pos[3];
12048
11776
  pos[2] /= pos[3];
@@ -12069,7 +11797,7 @@ var VerticalPerspectiveTransform = class VerticalPerspectiveTransform {
12069
11797
  isSurfacePointOnScreen(vec) {
12070
11798
  if (!this.isSurfacePointVisible(vec)) return false;
12071
11799
  const projected = createVec4f64();
12072
- transformMat4(projected, [...vec, 1], this._globeViewProjMatrixNoCorrection);
11800
+ transformMat4(projected, [...vec, 1], this._globeViewProjMatrixF64);
12073
11801
  projected[0] /= projected[3];
12074
11802
  projected[1] /= projected[3];
12075
11803
  projected[2] /= projected[3];
@@ -12370,9 +12098,8 @@ var GlobeTransform = class GlobeTransform {
12370
12098
  get isGlobeRendering() {
12371
12099
  return this._globeness > 0;
12372
12100
  }
12373
- setTransitionState(globeness, errorCorrectionValue) {
12101
+ setTransitionState(globeness) {
12374
12102
  this._globeness = globeness;
12375
- this._globeLatitudeErrorCorrectionRadians = errorCorrectionValue;
12376
12103
  this._calcMatrices();
12377
12104
  this._verticalPerspectiveTransform.getCoveringTilesDetailsProvider().prepareNextFrame();
12378
12105
  this._mercatorTransform.getCoveringTilesDetailsProvider().prepareNextFrame();
@@ -12381,7 +12108,6 @@ var GlobeTransform = class GlobeTransform {
12381
12108
  return this.isGlobeRendering ? this._verticalPerspectiveTransform : this._mercatorTransform;
12382
12109
  }
12383
12110
  constructor(options) {
12384
- this._globeLatitudeErrorCorrectionRadians = 0;
12385
12111
  this._globeness = 1;
12386
12112
  this.defaultConstrain = (lngLat, zoom) => {
12387
12113
  return this.currentTransform.defaultConstrain(lngLat, zoom);
@@ -12402,14 +12128,13 @@ var GlobeTransform = class GlobeTransform {
12402
12128
  clone() {
12403
12129
  const clone = new GlobeTransform();
12404
12130
  clone._globeness = this._globeness;
12405
- clone._globeLatitudeErrorCorrectionRadians = this._globeLatitudeErrorCorrectionRadians;
12406
12131
  clone.apply(this, false);
12407
12132
  return clone;
12408
12133
  }
12409
12134
  apply(that, constrain) {
12410
12135
  this._helper.apply(that, constrain);
12411
12136
  this._mercatorTransform.apply(this, false);
12412
- this._verticalPerspectiveTransform.apply(this, false, this._globeLatitudeErrorCorrectionRadians);
12137
+ this._verticalPerspectiveTransform.apply(this, false);
12413
12138
  }
12414
12139
  get projectionMatrix() {
12415
12140
  return this.currentTransform.projectionMatrix;
@@ -12431,7 +12156,8 @@ var GlobeTransform = class GlobeTransform {
12431
12156
  clippingPlane: verticalPerspectiveProjectionData.clippingPlane,
12432
12157
  tileMercatorCoords: verticalPerspectiveProjectionData.tileMercatorCoords,
12433
12158
  projectionTransition: params.applyGlobeMatrix ? this._globeness : 0,
12434
- fallbackMatrix: mercatorProjectionData.fallbackMatrix
12159
+ fallbackMatrix: mercatorProjectionData.fallbackMatrix,
12160
+ clipAntimeridian: verticalPerspectiveProjectionData.clipAntimeridian
12435
12161
  };
12436
12162
  }
12437
12163
  isLocationOccluded(location) {
@@ -12447,14 +12173,16 @@ var GlobeTransform = class GlobeTransform {
12447
12173
  return lerp(this._mercatorTransform.getCircleRadiusCorrection(), this._verticalPerspectiveTransform.getCircleRadiusCorrection(), this._globeness);
12448
12174
  }
12449
12175
  getPitchedTextCorrection(textAnchorX, textAnchorY, tileID) {
12450
- return lerp(this._mercatorTransform.getPitchedTextCorrection(textAnchorX, textAnchorY, tileID), this._verticalPerspectiveTransform.getPitchedTextCorrection(textAnchorX, textAnchorY, tileID), this._globeness);
12176
+ const mercatorCorrection = this._mercatorTransform.getPitchedTextCorrection(textAnchorX, textAnchorY, tileID);
12177
+ const verticalCorrection = this._verticalPerspectiveTransform.getPitchedTextCorrection(textAnchorX, textAnchorY, tileID);
12178
+ return lerp(mercatorCorrection, verticalCorrection, this._globeness);
12451
12179
  }
12452
12180
  projectTileCoordinates(x, y, unwrappedTileID, getElevation) {
12453
12181
  return this.currentTransform.projectTileCoordinates(x, y, unwrappedTileID, getElevation);
12454
12182
  }
12455
12183
  _calcMatrices() {
12456
12184
  if (!this._helper._width || !this._helper._height) return;
12457
- this._verticalPerspectiveTransform.apply(this, false, this._globeLatitudeErrorCorrectionRadians);
12185
+ this._verticalPerspectiveTransform.apply(this, false);
12458
12186
  this._helper._nearZ = this._verticalPerspectiveTransform.nearZ;
12459
12187
  this._helper._farZ = this._verticalPerspectiveTransform.farZ;
12460
12188
  this._mercatorTransform.apply(this, true, this.isGlobeRendering);
@@ -12760,7 +12488,8 @@ var VerticalPerspectiveCameraHelper = class VerticalPerspectiveCameraHelper {
12760
12488
  const requestedMinZoom = typeof options.minZoom === "number" ? +options.minZoom : tr.minZoom;
12761
12489
  const normalizedEffectiveMinZoom = Math.max(requestedMinZoom, tr.minZoom) + getZoomAdjustment(targetCenter.lat, 0);
12762
12490
  const minZoomPreConstrain = Math.min(normalizedEffectiveMinZoom, normalizedStartZoom, normalizedTargetZoom) + getZoomAdjustment(0, targetCenter.lat);
12763
- const scaleOfMinZoom = zoomScale(tr.applyConstrain(targetCenter, minZoomPreConstrain).zoom + getZoomAdjustment(targetCenter.lat, 0) - normalizedStartZoom);
12491
+ const normalizedMinZoom = tr.applyConstrain(targetCenter, minZoomPreConstrain).zoom + getZoomAdjustment(targetCenter.lat, 0);
12492
+ const scaleOfMinZoom = zoomScale(normalizedMinZoom - normalizedStartZoom);
12764
12493
  const deltaLng = differenceOfAnglesDegrees(startCenter.lng, targetCenter.lng);
12765
12494
  const deltaLat = differenceOfAnglesDegrees(startCenter.lat, targetCenter.lat);
12766
12495
  const easeFunc = (k, scale, centerFactor, _pointAtOffset) => {
@@ -12875,10 +12604,10 @@ var GlobeCameraHelper = class {
12875
12604
  };
12876
12605
  //#endregion
12877
12606
  //#region src/geo/projection/projection_factory.ts
12878
- function createProjectionFromName(name, transformConstrain) {
12607
+ function createProjectionFromName(name, transformConstrain, globalState) {
12879
12608
  const transformOptions = { constrainOverride: transformConstrain };
12880
12609
  if (Array.isArray(name)) {
12881
- const globeProjection = new GlobeProjection({ type: name });
12610
+ const globeProjection = new GlobeProjection({ type: name }, globalState);
12882
12611
  return {
12883
12612
  projection: globeProjection,
12884
12613
  transform: new GlobeTransform(transformOptions),
@@ -12900,7 +12629,7 @@ function createProjectionFromName(name, transformConstrain) {
12900
12629
  "vertical-perspective",
12901
12630
  12,
12902
12631
  "mercator"
12903
- ] });
12632
+ ] }, {});
12904
12633
  return {
12905
12634
  projection: globeProjection,
12906
12635
  transform: new GlobeTransform(transformOptions),
@@ -13090,9 +12819,9 @@ var Style = class extends Evented {
13090
12819
  else this.imageManager.setLoaded(true);
13091
12820
  this.glyphManager.setURL(nextState.glyphs);
13092
12821
  this._createLayers();
13093
- this.light = new Light(this.stylesheet.light);
12822
+ this.light = new Light(this.stylesheet.light ?? {}, this._globalState);
13094
12823
  this._setProjectionInternal(this.stylesheet.projection?.type || "mercator");
13095
- this.sky = new Sky(this.stylesheet.sky);
12824
+ this.sky = new Sky(this.stylesheet.sky, this._globalState);
13096
12825
  this.map.setTerrain(this.stylesheet.terrain ?? null, { validate: false });
13097
12826
  this.fire(new MapStyleDataEvent("data"));
13098
12827
  this.fire(new MapStyleLoadEvent());
@@ -13384,9 +13113,7 @@ var Style = class extends Evented {
13384
13113
  case "setTransition":
13385
13114
  operations.push(() => {});
13386
13115
  break;
13387
- default:
13388
- unimplemented.push(op.command);
13389
- break;
13116
+ default: unimplemented.push(op.command);
13390
13117
  }
13391
13118
  return {
13392
13119
  operations,
@@ -13938,7 +13665,7 @@ var Style = class extends Evented {
13938
13665
  this.sky.updateTransitions(parameters);
13939
13666
  }
13940
13667
  _setProjectionInternal(name) {
13941
- const projectionObjects = createProjectionFromName(name, this.map._camera?.transform.constrainOverride);
13668
+ const projectionObjects = createProjectionFromName(name, this.map._camera?.transform.constrainOverride, this._globalState);
13942
13669
  this.projection = projectionObjects.projection;
13943
13670
  this.map.migrateProjection(projectionObjects.transform, projectionObjects.cameraHelper);
13944
13671
  for (const key in this.tileManagers) this.tileManagers[key].reload();
@@ -14309,18 +14036,20 @@ const projectionUniforms = (context, locations) => ({
14309
14036
  "u_projection_tile_mercator_coords": new Uniform4f(context, locations.u_projection_tile_mercator_coords),
14310
14037
  "u_projection_clipping_plane": new Uniform4f(context, locations.u_projection_clipping_plane),
14311
14038
  "u_projection_transition": new Uniform1f(context, locations.u_projection_transition),
14312
- "u_projection_fallback_matrix": new UniformMatrix4f(context, locations.u_projection_fallback_matrix)
14039
+ "u_projection_fallback_matrix": new UniformMatrix4f(context, locations.u_projection_fallback_matrix),
14040
+ "u_projection_clip_antimeridian": new Uniform1i(context, locations.u_projection_clip_antimeridian)
14313
14041
  });
14314
14042
  /**
14315
- * Maps a field name in {@link ProjectionData} to its corresponding uniform name in {@link ProjectionPreludeUniformsType}.
14043
+ * Converts a {@link ProjectionData} object into the values expected by the projection prelude's uniforms.
14316
14044
  */
14317
- const projectionObjectToUniformMap = {
14318
- mainMatrix: "u_projection_matrix",
14319
- tileMercatorCoords: "u_projection_tile_mercator_coords",
14320
- clippingPlane: "u_projection_clipping_plane",
14321
- projectionTransition: "u_projection_transition",
14322
- fallbackMatrix: "u_projection_fallback_matrix"
14323
- };
14045
+ const projectionUniformValues = (projectionData) => ({
14046
+ "u_projection_matrix": projectionData.mainMatrix,
14047
+ "u_projection_tile_mercator_coords": projectionData.tileMercatorCoords,
14048
+ "u_projection_clipping_plane": projectionData.clippingPlane,
14049
+ "u_projection_transition": projectionData.projectionTransition,
14050
+ "u_projection_fallback_matrix": projectionData.fallbackMatrix,
14051
+ "u_projection_clip_antimeridian": projectionData.clipAntimeridian ? 1 : 0
14052
+ });
14324
14053
  //#endregion
14325
14054
  //#region src/webgl/program.ts
14326
14055
  function getTokenizedAttributesAndUniforms(array) {
@@ -14384,6 +14113,7 @@ var Program = class {
14384
14113
  for (const name in this.attributes) {
14385
14114
  const actual = gl.getAttribLocation(this.program, name);
14386
14115
  if (actual >= 0) this.attributes[name] = actual;
14116
+ else delete this.attributes[name];
14387
14117
  }
14388
14118
  if (!gl.getProgramParameter(this.program, gl.LINK_STATUS)) throw new Error(`Program failed to link: ${gl.getProgramInfoLog(this.program)}`);
14389
14119
  gl.deleteShader(vertexShader);
@@ -14412,9 +14142,9 @@ var Program = class {
14412
14142
  gl.bindTexture(gl.TEXTURE_2D, terrain.texture);
14413
14143
  for (const name in this.terrainUniforms) this.terrainUniforms[name].set(terrain[name]);
14414
14144
  }
14415
- if (projectionData) for (const fieldName in projectionData) {
14416
- const uniformName = projectionObjectToUniformMap[fieldName];
14417
- this.projectionUniforms[uniformName].set(projectionData[fieldName]);
14145
+ if (projectionData) {
14146
+ const values = projectionUniformValues(projectionData);
14147
+ for (const name in this.projectionUniforms) this.projectionUniforms[name].set(values[name]);
14418
14148
  }
14419
14149
  if (uniformValues) for (const name in this.fixedUniforms) this.fixedUniforms[name].set(uniformValues[name]);
14420
14150
  if (configuration) configuration.setUniforms(context, this.binderUniforms, currentProperties, { zoom });
@@ -14426,9 +14156,7 @@ var Program = class {
14426
14156
  case gl.TRIANGLES:
14427
14157
  primitiveSize = 3;
14428
14158
  break;
14429
- case gl.LINE_STRIP:
14430
- primitiveSize = 1;
14431
- break;
14159
+ case gl.LINE_STRIP: primitiveSize = 1;
14432
14160
  }
14433
14161
  for (const segment of segments.get()) {
14434
14162
  segment.vaos ||= {};
@@ -14695,9 +14423,7 @@ const hillshadeUniformValues = (painter, tile, layer) => {
14695
14423
  case "multidirectional":
14696
14424
  method = 3;
14697
14425
  break;
14698
- default:
14699
- method = 0;
14700
- break;
14426
+ default: method = 0;
14701
14427
  }
14702
14428
  const illumination = layer.getIlluminationProperties();
14703
14429
  for (let i = 0; i < illumination.directionRadians.length; i++) if (layer.paint.get("hillshade-illumination-anchor") === "viewport") illumination.directionRadians[i] += painter.transform.bearingInRadians;
@@ -15173,7 +14899,6 @@ const programUniforms = {
15173
14899
  terrain: terrainUniforms,
15174
14900
  terrainDepth: terrainDepthUniforms,
15175
14901
  terrainCoords: terrainCoordsUniforms,
15176
- projectionErrorMeasurement: projectionErrorMeasurementUniforms,
15177
14902
  atmosphere: atmosphereUniforms,
15178
14903
  sky: skyUniforms
15179
14904
  };
@@ -15762,6 +15487,37 @@ var Framebuffer = class {
15762
15487
  }
15763
15488
  };
15764
15489
  //#endregion
15490
+ //#region src/webgl/color_mode.ts
15491
+ const ZERO = 0;
15492
+ const ONE = 1;
15493
+ const ONE_MINUS_SRC_ALPHA = 771;
15494
+ var ColorMode = class {
15495
+ constructor(blendFunction, blendColor, mask) {
15496
+ this.blendFunction = blendFunction;
15497
+ this.blendColor = blendColor;
15498
+ this.mask = mask;
15499
+ }
15500
+ };
15501
+ ColorMode.Replace = [ONE, ZERO];
15502
+ ColorMode.disabled = new ColorMode(ColorMode.Replace, Color.transparent, [
15503
+ false,
15504
+ false,
15505
+ false,
15506
+ false
15507
+ ]);
15508
+ ColorMode.unblended = new ColorMode(ColorMode.Replace, Color.transparent, [
15509
+ true,
15510
+ true,
15511
+ true,
15512
+ true
15513
+ ]);
15514
+ ColorMode.alphaBlended = new ColorMode([ONE, ONE_MINUS_SRC_ALPHA], Color.transparent, [
15515
+ true,
15516
+ true,
15517
+ true,
15518
+ true
15519
+ ]);
15520
+ //#endregion
15765
15521
  //#region src/webgl/context.ts
15766
15522
  /**
15767
15523
  * @internal
@@ -15965,6 +15721,52 @@ var Context = class {
15965
15721
  }
15966
15722
  };
15967
15723
  //#endregion
15724
+ //#region src/webgl/depth_mode.ts
15725
+ const ALWAYS$1 = 519;
15726
+ var DepthMode = class {
15727
+ constructor(depthFunc, depthMask, depthRange) {
15728
+ this.func = depthFunc;
15729
+ this.mask = depthMask;
15730
+ this.range = depthRange;
15731
+ }
15732
+ };
15733
+ DepthMode.ReadOnly = false;
15734
+ DepthMode.ReadWrite = true;
15735
+ DepthMode.disabled = new DepthMode(ALWAYS$1, DepthMode.ReadOnly, [0, 1]);
15736
+ //#endregion
15737
+ //#region src/webgl/stencil_mode.ts
15738
+ const ALWAYS = 519;
15739
+ const KEEP = 7680;
15740
+ var StencilMode = class {
15741
+ constructor(test, ref, mask, fail, depthFail, pass) {
15742
+ this.test = test;
15743
+ this.ref = ref;
15744
+ this.mask = mask;
15745
+ this.fail = fail;
15746
+ this.depthFail = depthFail;
15747
+ this.pass = pass;
15748
+ }
15749
+ };
15750
+ StencilMode.disabled = new StencilMode({
15751
+ func: ALWAYS,
15752
+ mask: 0
15753
+ }, 0, 0, KEEP, KEEP, KEEP);
15754
+ //#endregion
15755
+ //#region src/webgl/cull_face_mode.ts
15756
+ const FRONT = 1028;
15757
+ const BACK = 1029;
15758
+ const CCW = 2305;
15759
+ var CullFaceMode = class {
15760
+ constructor(enable, mode, frontFace) {
15761
+ this.enable = enable;
15762
+ this.mode = mode;
15763
+ this.frontFace = frontFace;
15764
+ }
15765
+ };
15766
+ CullFaceMode.disabled = new CullFaceMode(false, BACK, CCW);
15767
+ CullFaceMode.backCCW = new CullFaceMode(true, BACK, CCW);
15768
+ CullFaceMode.frontCCW = new CullFaceMode(true, FRONT, CCW);
15769
+ //#endregion
15968
15770
  //#region src/webgl/draw/draw_collision_debug.ts
15969
15771
  let quadTriangles;
15970
15772
  function drawCollisionDebug(painter, tileManager, layer, coords, isText) {
@@ -16314,7 +16116,9 @@ function drawCircles(painter, tileManager, layer, coords, renderOptions) {
16314
16116
  const tile = tileManager.getTile(coord);
16315
16117
  const bucket = tile.getBucket(layer);
16316
16118
  if (!bucket) continue;
16317
- const translateForUniforms = translatePosition(transform, tile, layer.paint.get("circle-translate"), layer.paint.get("circle-translate-anchor"));
16119
+ const styleTranslate = layer.paint.get("circle-translate");
16120
+ const styleTranslateAnchor = layer.paint.get("circle-translate-anchor");
16121
+ const translateForUniforms = translatePosition(transform, tile, styleTranslate, styleTranslateAnchor);
16318
16122
  const programConfiguration = bucket.programConfigurations.get(layer.id);
16319
16123
  const program = painter.useProgram("circle", programConfiguration);
16320
16124
  const layoutVertexBuffer = bucket.layoutVertexBuffer;
@@ -16594,7 +16398,8 @@ function updateGradientTexture(painter, tileManager, context, gl, layer, bucket,
16594
16398
  if (layer.stepInterpolant) {
16595
16399
  const sourceMaxZoom = tileManager.getSource().maxzoom;
16596
16400
  const potentialOverzoom = coord.canonical.z === sourceMaxZoom ? Math.ceil(1 << painter.transform.maxZoom - coord.canonical.z) : 1;
16597
- textureResolution = clamp(nextPowerOfTwo(bucket.maxLineLength / EXTENT * 1024 * potentialOverzoom), 256, context.maxTextureSize);
16401
+ const maxTextureCoverage = bucket.maxLineLength / EXTENT * 1024 * potentialOverzoom;
16402
+ textureResolution = clamp(nextPowerOfTwo(maxTextureCoverage), 256, context.maxTextureSize);
16598
16403
  }
16599
16404
  layerGradient.gradient = renderColorRamp({
16600
16405
  expression: layer.gradientExpression(),
@@ -17187,7 +16992,8 @@ function getCrossFadeValues(tile, parentTile, fadeDuration) {
17187
16992
  * Simple fade-in values for tile without a parent (i.e. edge tiles)
17188
16993
  */
17189
16994
  function getSelfFadeValues(tile, fadeDuration) {
17190
- const tileOpacity = clamp((now() - tile.timeAdded) / fadeDuration, 0, 1);
16995
+ const timeSinceTile = (now() - tile.timeAdded) / fadeDuration;
16996
+ const tileOpacity = clamp(timeSinceTile, 0, 1);
17191
16997
  return {
17192
16998
  tileOpacity,
17193
16999
  fadeMix: {
@@ -17733,7 +17539,8 @@ var Painter = class Painter {
17733
17539
  0
17734
17540
  ],
17735
17541
  projectionTransition: 0,
17736
- fallbackMatrix: matrix
17542
+ fallbackMatrix: matrix,
17543
+ clipAntimeridian: false
17737
17544
  };
17738
17545
  this.useProgram("clippingMask", null, true).draw(context, gl.TRIANGLES, DepthMode.disabled, this.stencilClearMode, ColorMode.disabled, CullFaceMode.disabled, null, null, projectionData, "$clipping", this.viewportBuffer, this.quadTriangleIndexBuffer, this.viewportSegments);
17739
17546
  }
@@ -17746,7 +17553,7 @@ var Painter = class Painter {
17746
17553
  context.setDepthMode(DepthMode.disabled);
17747
17554
  const stencilRefs = {};
17748
17555
  for (const tileID of tileIDs) stencilRefs[tileID.key] = this.nextStencilID++;
17749
- this._renderTileMasks(stencilRefs, tileIDs, renderToTexture, true);
17556
+ if (this.style.projection.useSubdivision) this._renderTileMasks(stencilRefs, tileIDs, renderToTexture, true);
17750
17557
  this._renderTileMasks(stencilRefs, tileIDs, renderToTexture, false);
17751
17558
  this._tileClippingMaskIDs = stencilRefs;
17752
17559
  }
@@ -17942,10 +17749,6 @@ var Painter = class Painter {
17942
17749
  if (layer.type !== "custom" && !coords.length) continue;
17943
17750
  this.renderLayer(this, tileManagers[layer.source], layer, coords, renderOptions);
17944
17751
  }
17945
- this.style.projection?.updateGPUdependent({
17946
- context: this.context,
17947
- useProgram: (name) => this.useProgram(name)
17948
- });
17949
17752
  this.context.viewport.set([
17950
17753
  0,
17951
17754
  0,
@@ -18302,7 +18105,7 @@ var Hash = class {
18302
18105
  location = location.replace("&&", "&");
18303
18106
  window.history.replaceState(window.history.state, null, location);
18304
18107
  };
18305
- this._updateHash = throttle(this._updateHashUnthrottled, 30 * 1e3 / 100);
18108
+ this._updateHash = throttle(this._updateHashUnthrottled, 3e4 / 100);
18306
18109
  this._hashName = hashName && encodeURIComponent(hashName);
18307
18110
  }
18308
18111
  /**
@@ -19037,13 +18840,13 @@ function generateMousePanHandler({ enable, clickTolerance }) {
19037
18840
  assignEvents
19038
18841
  });
19039
18842
  }
19040
- function generateMouseRotationHandler({ enable, clickTolerance, aroundCenter = true, minPixelCenterThreshold = 100, rotateDegreesPerPixelMoved = .8 }, getCenter) {
18843
+ function generateMouseRotationHandler({ enable, clickTolerance, aroundCenter = true, minPixelCenterThreshold = 100, rotateSpeed = .8 }, getCenter) {
19041
18844
  return new DragHandler({
19042
18845
  clickTolerance,
19043
18846
  move: (lastPoint, currentPoint) => {
19044
18847
  const center = getCenter();
19045
18848
  if (aroundCenter && Math.abs(center.y - lastPoint.y) > minPixelCenterThreshold) return { bearingDelta: getAngleDelta(new Point(lastPoint.x, currentPoint.y), currentPoint, center) };
19046
- let bearingDelta = (currentPoint.x - lastPoint.x) * rotateDegreesPerPixelMoved;
18849
+ let bearingDelta = (currentPoint.x - lastPoint.x) * rotateSpeed;
19047
18850
  if (aroundCenter && currentPoint.y < center.y) bearingDelta = -bearingDelta;
19048
18851
  return { bearingDelta };
19049
18852
  },
@@ -19052,10 +18855,10 @@ function generateMouseRotationHandler({ enable, clickTolerance, aroundCenter = t
19052
18855
  assignEvents
19053
18856
  });
19054
18857
  }
19055
- function generateMousePitchHandler({ enable, clickTolerance, pitchDegreesPerPixelMoved = -.5 }) {
18858
+ function generateMousePitchHandler({ enable, clickTolerance, pitchSpeed = -.5 }) {
19056
18859
  return new DragHandler({
19057
18860
  clickTolerance,
19058
- move: (lastPoint, point) => ({ pitchDelta: (point.y - lastPoint.y) * pitchDegreesPerPixelMoved }),
18861
+ move: (lastPoint, point) => ({ pitchDelta: (point.y - lastPoint.y) * pitchSpeed }),
19059
18862
  moveStateManager: new MouseMoveStateManager({ checkCorrectEvent: (e) => e.button === LEFT_BUTTON && e.ctrlKey || e.button === RIGHT_BUTTON }),
19060
18863
  enable,
19061
18864
  assignEvents
@@ -19781,7 +19584,8 @@ var ScrollZoomHandler = class {
19781
19584
  const t = (now() - currentEase.start) / currentEase.duration;
19782
19585
  const speed = currentEase.easing(t + .01) - currentEase.easing(t);
19783
19586
  const x = .27 / Math.sqrt(speed * speed + 1e-4) * .01;
19784
- easing = bezier(x, Math.sqrt(.27 * .27 - x * x), .25, 1);
19587
+ const y = Math.sqrt(.0729 - x * x);
19588
+ easing = bezier(x, y, .25, 1);
19785
19589
  }
19786
19590
  this._prevEase = {
19787
19591
  start: now(),
@@ -21925,7 +21729,8 @@ var Terrain = class {
21925
21729
  this._terrainSkirtLength = terrainSkirtLength;
21926
21730
  this.qualityFactor = 2;
21927
21731
  this.meshSize = 128;
21928
- this._demMatrixCache = {};
21732
+ this._demMatrixCache = /* @__PURE__ */ new Map();
21733
+ this._elevationSamplerCache = /* @__PURE__ */ new Map();
21929
21734
  this.coordsIndex = [];
21930
21735
  this._coordsTextureSize = 1024;
21931
21736
  }
@@ -21971,12 +21776,8 @@ var Terrain = class {
21971
21776
  getDEMElevation(tileID, x, y, extent = EXTENT) {
21972
21777
  const normalized = tileID.normalizeCoordinates(x, y, extent);
21973
21778
  if (!normalized) return 0;
21974
- const terrain = this.getTerrainData(normalized.tileID);
21975
- const dem = terrain.tile?.dem;
21976
- if (!dem) return 0;
21977
- const pos = transformMat4$2([], [normalized.x / extent * EXTENT, normalized.y / extent * EXTENT], terrain.u_terrain_matrix);
21978
- const coord = [pos[0] * dem.dim, pos[1] * dem.dim];
21979
- return dem.sampleBilinear(coord[0], coord[1]);
21779
+ const sampler = this._getElevationSampler(normalized.tileID);
21780
+ return sampler ? sampler(normalized.x, normalized.y, extent) : 0;
21980
21781
  }
21981
21782
  /**
21982
21783
  * Get the elevation for given {@link LngLat} in respect of exaggeration.
@@ -22018,6 +21819,55 @@ var Terrain = class {
22018
21819
  return this.getDEMElevation(tileID, x, y, extent) * this.exaggeration;
22019
21820
  }
22020
21821
  /**
21822
+ * Clear CPU elevation samplers that may retain a previously selected DEM tile.
21823
+ * @internal
21824
+ */
21825
+ resetElevationCache() {
21826
+ this._elevationSamplerCache.clear();
21827
+ }
21828
+ _getElevationSampler(tileID) {
21829
+ const key = tileID.key;
21830
+ const cachedSampler = this._elevationSamplerCache.get(key);
21831
+ if (cachedSampler) return cachedSampler;
21832
+ const sourceTile = this.tileManager.getSourceTile(tileID, true);
21833
+ const dem = sourceTile?.dem;
21834
+ if (!sourceTile || !dem) return null;
21835
+ const matrix = this._getDEMTileMatrix(tileID, sourceTile);
21836
+ const demPixelScaleX = matrix[0] * dem.dim;
21837
+ const demPixelScaleY = matrix[5] * dem.dim;
21838
+ const demPixelOffsetX = matrix[12] * dem.dim;
21839
+ const demPixelOffsetY = matrix[13] * dem.dim;
21840
+ const sampler = (x, y, extent) => {
21841
+ const extentScale = extent === 8192 ? 1 : EXTENT / extent;
21842
+ return dem.sampleBilinear(x * extentScale * demPixelScaleX + demPixelOffsetX, y * extentScale * demPixelScaleY + demPixelOffsetY);
21843
+ };
21844
+ this._elevationSamplerCache.set(key, sampler);
21845
+ return sampler;
21846
+ }
21847
+ _getDEMTileMatrix(tileID, sourceTile) {
21848
+ const matrixKey = `${sourceTile.tileID.key}/${tileID.key}`;
21849
+ const cachedMatrix = this._demMatrixCache.get(matrixKey);
21850
+ if (cachedMatrix) return cachedMatrix;
21851
+ const maxzoom = this.tileManager.getSource().maxzoom;
21852
+ let dz = tileID.canonical.z - sourceTile.tileID.canonical.z;
21853
+ if (tileID.overscaledZ > tileID.canonical.z) if (tileID.canonical.z >= maxzoom) dz = tileID.canonical.z - maxzoom;
21854
+ else warnOnce("cannot calculate elevation if elevation maxzoom > source.maxzoom");
21855
+ const dx = tileID.canonical.x - (tileID.canonical.x >> dz << dz);
21856
+ const dy = tileID.canonical.y - (tileID.canonical.y >> dz << dz);
21857
+ const demMatrix = fromScaling(/* @__PURE__ */ new Float64Array(16), [
21858
+ 1 / (EXTENT << dz),
21859
+ 1 / (EXTENT << dz),
21860
+ 0
21861
+ ]);
21862
+ translate(demMatrix, demMatrix, [
21863
+ dx * EXTENT,
21864
+ dy * EXTENT,
21865
+ 0
21866
+ ]);
21867
+ this._demMatrixCache.set(matrixKey, demMatrix);
21868
+ return demMatrix;
21869
+ }
21870
+ /**
22021
21871
  * returns a Terrain Object for a tile. Unless the tile corresponds to data (e.g. tile is loading), return a flat dem object
22022
21872
  * @param tileID - the tile to get the terrain for
22023
21873
  * @returns the terrain data to use in the program
@@ -22052,34 +21902,12 @@ var Terrain = class {
22052
21902
  sourceTile.demTexture.bind(context.gl.NEAREST, context.gl.CLAMP_TO_EDGE);
22053
21903
  sourceTile.needsTerrainPrepare = false;
22054
21904
  }
22055
- const matrixKey = sourceTile && sourceTile.toString() + sourceTile.tileID.key + tileID.key;
22056
- if (matrixKey && !this._demMatrixCache[matrixKey]) {
22057
- const maxzoom = this.tileManager.getSource().maxzoom;
22058
- let dz = tileID.canonical.z - sourceTile.tileID.canonical.z;
22059
- if (tileID.overscaledZ > tileID.canonical.z) if (tileID.canonical.z >= maxzoom) dz = tileID.canonical.z - maxzoom;
22060
- else warnOnce("cannot calculate elevation if elevation maxzoom > source.maxzoom");
22061
- const dx = tileID.canonical.x - (tileID.canonical.x >> dz << dz);
22062
- const dy = tileID.canonical.y - (tileID.canonical.y >> dz << dz);
22063
- const demMatrix = fromScaling(/* @__PURE__ */ new Float64Array(16), [
22064
- 1 / (EXTENT << dz),
22065
- 1 / (EXTENT << dz),
22066
- 0
22067
- ]);
22068
- translate(demMatrix, demMatrix, [
22069
- dx * EXTENT,
22070
- dy * EXTENT,
22071
- 0
22072
- ]);
22073
- this._demMatrixCache[matrixKey] = {
22074
- matrix: demMatrix,
22075
- coord: tileID
22076
- };
22077
- }
21905
+ const terrainMatrix = sourceTile ? this._getDEMTileMatrix(tileID, sourceTile) : this._emptyDemMatrix;
22078
21906
  return {
22079
21907
  "u_depth": 2,
22080
21908
  "u_terrain": 3,
22081
21909
  "u_terrain_dim": sourceTile?.dem?.dim || 1,
22082
- "u_terrain_matrix": matrixKey ? this._demMatrixCache[matrixKey].matrix : this._emptyDemMatrix,
21910
+ "u_terrain_matrix": terrainMatrix,
22083
21911
  "u_terrain_unpack": sourceTile?.dem?.getUnpackVector() || this._emptyDemUnpack,
22084
21912
  "u_terrain_exaggeration": this.exaggeration,
22085
21913
  texture: (sourceTile?.demTexture || this._emptyDemTexture).texture,
@@ -22147,10 +21975,11 @@ var Terrain = class {
22147
21975
  data[i + 2] = x >> 8 << 4 | y >> 8;
22148
21976
  data[i + 3] = 0;
22149
21977
  }
22150
- const texture = new Texture(context, new RGBAImage({
21978
+ const image = new RGBAImage({
22151
21979
  width: this._coordsTextureSize,
22152
21980
  height: this._coordsTextureSize
22153
- }, new Uint8Array(data.buffer)), context.gl.RGBA, { premultiply: false });
21981
+ }, new Uint8Array(data.buffer));
21982
+ const texture = new Texture(context, image, context.gl.RGBA, { premultiply: false });
22154
21983
  texture.bind(context.gl.NEAREST, context.gl.CLAMP_TO_EDGE);
22155
21984
  this._coordsTexture = texture;
22156
21985
  return texture;
@@ -22191,7 +22020,7 @@ var Terrain = class {
22191
22020
  context.bindFramebuffer.set(this.getFramebuffer("depth").framebuffer);
22192
22021
  gl.readPixels(p.x, this.painter.height / devicePixelRatio - p.y - 1, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, rgba);
22193
22022
  context.bindFramebuffer.set(null);
22194
- return (rgba[0] / (256 * 256 * 256) + rgba[1] / (256 * 256) + rgba[2] / 256 + rgba[3]) / 256;
22023
+ return (rgba[0] / 16777216 + rgba[1] / 65536 + rgba[2] / 256 + rgba[3]) / 256;
22195
22024
  }
22196
22025
  /**
22197
22026
  * create a regular mesh which will be used by all terrain-tiles
@@ -22258,8 +22087,9 @@ var Terrain = class {
22258
22087
  const worldSize = (1 << zoom) * EXTENT;
22259
22088
  const mercatorX = mercatorCoordinate.x * worldSize;
22260
22089
  const mercatorY = mercatorCoordinate.y * worldSize;
22090
+ const tileX = Math.floor(mercatorX / EXTENT), tileY = Math.floor(mercatorY / EXTENT);
22261
22091
  return {
22262
- tileID: new OverscaledTileID(zoom, 0, zoom, Math.floor(mercatorX / EXTENT), Math.floor(mercatorY / EXTENT)),
22092
+ tileID: new OverscaledTileID(zoom, 0, zoom, tileX, tileY),
22263
22093
  mercatorX,
22264
22094
  mercatorY
22265
22095
  };
@@ -22508,6 +22338,8 @@ const defaultOptions$4 = {
22508
22338
  localIdeographFontFamily: "sans-serif",
22509
22339
  pitchWithRotate: true,
22510
22340
  rollEnabled: false,
22341
+ rotateSpeed: .8,
22342
+ pitchSpeed: -.5,
22511
22343
  reduceMotion: void 0,
22512
22344
  validateStyle: true,
22513
22345
  /**Because GL MAX_TEXTURE_SIZE is usually at least 4096px. */
@@ -24439,27 +24271,36 @@ var Map$1 = class extends Evented {
24439
24271
  if (thisLayer.type === "hillshade" && thisLayer.source === options.source) warnOnce("You are using the same source for a hillshade layer and for 3D terrain. Please consider using two separate sources to improve rendering quality.");
24440
24272
  if (thisLayer.type === "color-relief" && thisLayer.source === options.source) warnOnce("You are using the same source for a color-relief layer and for 3D terrain. Please consider using two separate sources to improve rendering quality.");
24441
24273
  }
24274
+ if (this.terrain) this.terrain.destroy();
24442
24275
  this.terrain = new Terrain(this.painter, tileManager, options, this._terrainSkirtLength);
24443
24276
  this.painter.renderToTexture = new RenderToTexture(this.painter, this.terrain);
24444
24277
  this._camera.terrain = this.terrain;
24445
24278
  this._camera.transform.setMinElevationForCurrentTile(this.terrain.getMinTileElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
24446
24279
  this._camera.transform.setElevation(this.terrain.getElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
24447
- this._terrainDataCallback = (e) => {
24448
- if (e.dataType === "style") this.terrain.tileManager.releaseAllRTT();
24449
- else if (e.dataType === "source" && e.tile) {
24450
- if (e.sourceId === options.source && !this._camera.elevationFreeze) {
24451
- this._camera.transform.setMinElevationForCurrentTile(this.terrain.getMinTileElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
24452
- if (this.getCenterClampedToGround()) this._camera.transform.setElevation(this.terrain.getElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
24453
- }
24454
- if (e.source?.type === "image") this.terrain.tileManager.releaseAllRTT();
24455
- else this.terrain.tileManager.releaseRTT(e.tile.tileID);
24456
- }
24457
- };
24280
+ this._terrainDataCallback = (e) => this._handleTerrainDataEvent(e, options.source);
24458
24281
  this.style.on("data", this._terrainDataCallback);
24459
24282
  }
24460
24283
  this.fire(new MapTerrainEvent({ terrain: options }));
24461
24284
  return this;
24462
24285
  }
24286
+ _handleTerrainDataEvent(event, terrainSourceId) {
24287
+ if (event.dataType === "style") {
24288
+ this.terrain.tileManager.releaseAllRTT();
24289
+ return;
24290
+ }
24291
+ const isTerrainSourceEvent = event.sourceId === terrainSourceId;
24292
+ if (isTerrainSourceEvent) this.terrain.resetElevationCache();
24293
+ if (isTerrainSourceEvent && event.tile && !this._camera.elevationFreeze) {
24294
+ this._camera.transform.setMinElevationForCurrentTile(this.terrain.getMinTileElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
24295
+ if (this.getCenterClampedToGround()) this._camera.transform.setElevation(this.terrain.getElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
24296
+ }
24297
+ if (!event.tile) return;
24298
+ if (event.source?.type === "image") {
24299
+ this.terrain.tileManager.releaseAllRTT();
24300
+ return;
24301
+ }
24302
+ this.terrain.tileManager.releaseRTT(event.tile.tileID);
24303
+ }
24463
24304
  /**
24464
24305
  * Get the terrain-options if terrain is loaded
24465
24306
  * @returns the TerrainSpecification passed to setTerrain
@@ -25546,14 +25387,14 @@ var Map$1 = class extends Evented {
25546
25387
  this.style.update(parameters);
25547
25388
  }
25548
25389
  const globeRenderingChanged = this.style.projection?.transitionState > 0 !== isGlobeRendering;
25549
- this.style.projection?.setErrorQueryLatitudeDegrees(this._camera.transform.center.lat);
25550
- this._camera.transform.setTransitionState(this.style.projection?.transitionState, this.style.projection?.latitudeErrorCorrectionRadians);
25390
+ this._camera.transform.setTransitionState(this.style.projection?.transitionState);
25551
25391
  if (this.style && (this._sourcesDirty || globeRenderingChanged)) {
25552
25392
  this._sourcesDirty = false;
25553
25393
  this.style._updateSources(this._camera.transform);
25554
25394
  }
25555
25395
  if (this.terrain) {
25556
25396
  this.terrain.tileManager.update(this._camera.transform, this.terrain);
25397
+ this.terrain.resetElevationCache();
25557
25398
  this._camera.transform.setMinElevationForCurrentTile(this.terrain.getMinTileElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
25558
25399
  if (!this._camera.elevationFreeze && this.getCenterClampedToGround()) this._camera.transform.setElevation(this.terrain.getElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
25559
25400
  } else {
@@ -26203,6 +26044,7 @@ var Marker = class extends Evented {
26203
26044
  this._clickTolerance = options?.clickTolerance || 0;
26204
26045
  this._subpixelPositioning = options?.subpixelPositioning || false;
26205
26046
  this._isDragging = false;
26047
+ this._roleManaged = false;
26206
26048
  this._state = "inactive";
26207
26049
  this._rotation = options?.rotation || 0;
26208
26050
  this._rotationAlignment = options?.rotationAlignment || "auto";
@@ -26337,8 +26179,8 @@ var Marker = class extends Evented {
26337
26179
  addTo(map) {
26338
26180
  this.remove();
26339
26181
  this._map = map;
26340
- if (!this._element.hasAttribute("aria-label")) this._element.setAttribute("aria-label", map._getUIString("Marker.Title"));
26341
- if (!this._element.hasAttribute("role")) this._element.setAttribute("role", "button");
26182
+ if (this._defaultMarker && !this._element.hasAttribute("aria-label")) this._element.setAttribute("aria-label", map._getUIString("Marker.Title"));
26183
+ this._updateAccessibilityRole();
26342
26184
  map.getCanvasContainer().appendChild(this._element);
26343
26185
  map.on("move", this._update);
26344
26186
  map.on("moveend", this._update);
@@ -26451,7 +26293,6 @@ var Marker = class extends Evented {
26451
26293
  }
26452
26294
  if (popup) {
26453
26295
  if (!("offset" in popup.options)) {
26454
- const markerHeight = 41 - 5.8 / 2;
26455
26296
  const markerRadius = 13.5;
26456
26297
  const linearOffset = Math.abs(markerRadius) / Math.SQRT2;
26457
26298
  popup.options.offset = this._defaultMarker ? {
@@ -26459,10 +26300,10 @@ var Marker = class extends Evented {
26459
26300
  "top-left": [0, 0],
26460
26301
  "top-right": [0, 0],
26461
26302
  "bottom": [0, -38.1],
26462
- "bottom-left": [linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
26463
- "bottom-right": [-linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
26464
- "left": [markerRadius, (markerHeight - markerRadius) * -1],
26465
- "right": [-13.5, (markerHeight - markerRadius) * -1]
26303
+ "bottom-left": [linearOffset, (24.6 + linearOffset) * -1],
26304
+ "bottom-right": [-linearOffset, (24.6 + linearOffset) * -1],
26305
+ "left": [markerRadius, -24.6],
26306
+ "right": [-13.5, -24.6]
26466
26307
  } : this._offset;
26467
26308
  }
26468
26309
  this._popup = popup;
@@ -26470,6 +26311,7 @@ var Marker = class extends Evented {
26470
26311
  if (!this._originalTabIndex) this._element.setAttribute("tabindex", "0");
26471
26312
  this._element.addEventListener("keypress", this._onKeyPress);
26472
26313
  }
26314
+ this._updateAccessibilityRole();
26473
26315
  return this;
26474
26316
  }
26475
26317
  /**
@@ -26628,6 +26470,7 @@ var Marker = class extends Evented {
26628
26470
  */
26629
26471
  setDraggable(shouldBeDraggable) {
26630
26472
  this._draggable = !!shouldBeDraggable;
26473
+ this._element.classList.toggle("maplibregl-marker-draggable", this._draggable);
26631
26474
  if (this._map) if (shouldBeDraggable) {
26632
26475
  this._map.on("mousedown", this._addDragHandler);
26633
26476
  this._map.on("touchstart", this._addDragHandler);
@@ -26635,6 +26478,7 @@ var Marker = class extends Evented {
26635
26478
  this._map.off("mousedown", this._addDragHandler);
26636
26479
  this._map.off("touchstart", this._addDragHandler);
26637
26480
  }
26481
+ this._updateAccessibilityRole();
26638
26482
  return this;
26639
26483
  }
26640
26484
  /**
@@ -26645,6 +26489,21 @@ var Marker = class extends Evented {
26645
26489
  return this._draggable;
26646
26490
  }
26647
26491
  /**
26492
+ * Keep the default marker role aligned with interactivity.
26493
+ * Default markers need a role because `aria-label` is set in {@link Marker.addTo}.
26494
+ * Non-interactive markers use `role=img`; interactive ones (draggable or with a popup) use `role=button`.
26495
+ * Click listeners are application-owned and do not automatically change the role.
26496
+ * Custom marker elements are left alone so applications own their a11y tree.
26497
+ * Explicit roles set by the application are preserved.
26498
+ */
26499
+ _updateAccessibilityRole() {
26500
+ if (!this._defaultMarker) return;
26501
+ if (this._element.hasAttribute("role") && !this._roleManaged) return;
26502
+ const role = this._draggable || !!this._popup ? "button" : "img";
26503
+ this._element.setAttribute("role", role);
26504
+ this._roleManaged = true;
26505
+ }
26506
+ /**
26648
26507
  * Sets the `rotation` property of the marker.
26649
26508
  * @param rotation - The rotation angle of the marker (clockwise, in degrees), relative to its respective {@link Marker.setRotationAlignment} setting.
26650
26509
  */
@@ -26970,7 +26829,8 @@ var GeolocateControl = class extends Evented {
26970
26829
  this._updateCamera = (position) => {
26971
26830
  const center = new LngLat(position.coords.longitude, position.coords.latitude);
26972
26831
  const radius = position.coords.accuracy;
26973
- const options = extend({ bearing: this._map.getBearing() }, this.options.fitBoundsOptions);
26832
+ const bearing = this._map.getBearing();
26833
+ const options = extend({ bearing }, this.options.fitBoundsOptions);
26974
26834
  const newBounds = LngLatBounds.fromLngLat(center, radius);
26975
26835
  this._map.fitBounds(newBounds, options, { geolocateSource: true });
26976
26836
  };