@arcgis/core 4.25.0-next.20220818 → 4.25.0-next.20220821

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 (89) hide show
  1. package/analysis/LengthDimension.js +1 -1
  2. package/assets/esri/core/workers/RemoteClient.js +1 -1
  3. package/assets/esri/core/workers/chunks/0b1d39dc063c4c3385e2.js +1 -0
  4. package/assets/esri/core/workers/chunks/{59a04f1640cd2b710028.js → 0c625803648e554f1fcf.js} +1 -1
  5. package/assets/esri/core/workers/chunks/{50985ec72b9e4557d371.js → 0f1fae79b5311d55c0da.js} +1 -1
  6. package/assets/esri/core/workers/chunks/1a360d839c4eb83aaa02.js +1 -0
  7. package/assets/esri/core/workers/chunks/3381b5454cd530cf940a.js +1 -0
  8. package/assets/esri/core/workers/chunks/3900c702242358c5d00e.js +1 -0
  9. package/assets/esri/core/workers/chunks/43f84cb852c9ab5e742f.js +1 -0
  10. package/assets/esri/core/workers/chunks/4637bfd3deff50b03f2e.js +1 -0
  11. package/assets/esri/core/workers/chunks/4d5bdf18feeb9c8cb6ff.js +1 -0
  12. package/assets/esri/core/workers/chunks/5c2574365af4a484cd4b.js +1 -0
  13. package/assets/esri/core/workers/chunks/70179a003b5e52a99e10.js +1 -0
  14. package/assets/esri/core/workers/chunks/77a38124ef155a1b0f3e.js +1 -0
  15. package/assets/esri/core/workers/chunks/{ab0ce16ced3532f0e429.js → 81418b47acb4ef68daf7.js} +1 -1
  16. package/assets/esri/core/workers/chunks/88b5ce63c4706d0954dc.js +1 -0
  17. package/assets/esri/core/workers/chunks/{064a4baa576964efa238.js → 9809878b87595ac77dc4.js} +1 -1
  18. package/assets/esri/core/workers/chunks/9dbe94a70624a5592690.js +1 -0
  19. package/assets/esri/core/workers/chunks/{d013daa46de022f0db4d.js → a0750175b499a89fd07d.js} +1 -1
  20. package/assets/esri/core/workers/chunks/be4a8a4b2804188817b3.js +1 -0
  21. package/assets/esri/core/workers/chunks/da13db62d54cbca350c3.js +1 -0
  22. package/assets/esri/core/workers/chunks/e472e4f4a2f046846258.js +1 -0
  23. package/assets/esri/core/workers/chunks/f351cccf879ba295acbc.js +1 -0
  24. package/chunks/boundedPlane.js +1 -1
  25. package/chunks/pe.js +1 -1
  26. package/core/Identifiable.js +1 -1
  27. package/geometry/Circle.js +1 -1
  28. package/geometry/Extent.js +1 -1
  29. package/geometry/Mesh.js +1 -1
  30. package/geometry/Multipoint.js +1 -1
  31. package/geometry/Point.js +1 -1
  32. package/geometry/geometryEngine.js +1 -1
  33. package/geometry/geometryEngineAsync.js +1 -1
  34. package/geometry/projection.js +1 -1
  35. package/geometry/support/aaBoundingBox.js +1 -1
  36. package/geometry/support/boundsUtils.js +1 -1
  37. package/geometry/support/centroid.js +1 -1
  38. package/geometry/support/cut.js +1 -1
  39. package/geometry/support/extentUtils.js +1 -1
  40. package/geometry/support/geodesicUtils.js +1 -1
  41. package/geometry/support/heightModelInfoUtils.js +1 -1
  42. package/geometry/support/meshUtils/primitives.js +1 -1
  43. package/geometry/support/quantizationUtils.js +1 -1
  44. package/interfaces.d.ts +60 -84
  45. package/layers/DimensionLayer.js +1 -1
  46. package/layers/support/ExportImageServiceParameters.js +1 -1
  47. package/layers/support/imageryRendererUtils.js +1 -1
  48. package/package.json +1 -1
  49. package/renderers/support/rasterRendererHelper.js +1 -1
  50. package/support/revision.js +1 -1
  51. package/symbols/cim/CIMResourceManager.js +1 -1
  52. package/symbols/cim/cimAnalyzer.js +1 -1
  53. package/symbols/cim/quantizeTime.js +5 -0
  54. package/views/2d/engine/webgl/TextureManager.js +1 -1
  55. package/views/2d/engine/webgl/animatedFormats/AnimatableTextureResource.js +5 -0
  56. package/views/2d/engine/webgl/animatedFormats/apng.js +1 -1
  57. package/views/2d/engine/webgl/animatedFormats/gif.js +1 -1
  58. package/views/2d/engine/webgl/animatedFormats/utils.js +1 -1
  59. package/views/3d/analysis/Dimensioning/LengthDimensionComputation.js +1 -1
  60. package/views/3d/analysis/Dimensioning/LengthDimensionSubTool.js +1 -1
  61. package/views/3d/analysis/Dimensioning/LengthDimensionVisualization.js +1 -1
  62. package/views/3d/analysis/Dimensioning/lengthDimensionUtils.js +1 -1
  63. package/views/3d/analysis/DirectLineMeasurement/DirectLineMeasurementController.js +1 -1
  64. package/views/3d/analysis/support/measurementUtils.js +1 -1
  65. package/views/3d/terrain/PlanarPatch.js +1 -1
  66. package/views/3d/terrain/SphericalPatch.js +1 -1
  67. package/views/3d/terrain/TerrainSurface.js +1 -1
  68. package/views/3d/terrain/Tile.js +1 -1
  69. package/views/3d/terrain/interfaces.js +1 -1
  70. package/views/support/geodesicLengthMeasurementUtils.js +1 -1
  71. package/widgets/Bookmarks.js +1 -1
  72. package/widgets/Search/SearchViewModel.js +1 -1
  73. package/assets/esri/core/workers/chunks/229bfbf3faa789f40b7e.js +0 -1
  74. package/assets/esri/core/workers/chunks/2e715520e5badbe570ac.js +0 -1
  75. package/assets/esri/core/workers/chunks/40098b3be512ad8461f8.js +0 -1
  76. package/assets/esri/core/workers/chunks/420ae87ba8dc74fd05f5.js +0 -1
  77. package/assets/esri/core/workers/chunks/46c836fc575251f1ff34.js +0 -1
  78. package/assets/esri/core/workers/chunks/481532ce4871b0d94587.js +0 -1
  79. package/assets/esri/core/workers/chunks/5fa78a6745ef14c7c4d1.js +0 -1
  80. package/assets/esri/core/workers/chunks/606f45a93c707054c521.js +0 -1
  81. package/assets/esri/core/workers/chunks/78e59b29e59b10f64aa9.js +0 -1
  82. package/assets/esri/core/workers/chunks/7be7c53727cb1bc73a64.js +0 -1
  83. package/assets/esri/core/workers/chunks/8d3fba983c360e1fdabf.js +0 -1
  84. package/assets/esri/core/workers/chunks/a69d194526bdc489b30b.js +0 -1
  85. package/assets/esri/core/workers/chunks/b59855826d235cba0889.js +0 -1
  86. package/assets/esri/core/workers/chunks/bff5812e3797c8e42ac0.js +0 -1
  87. package/assets/esri/core/workers/chunks/d6e177749bde46ab57fc.js +0 -1
  88. package/assets/esri/core/workers/chunks/d9c8a8bed6b34ed57faf.js +0 -1
  89. package/views/2d/engine/webgl/animatedFormats/BaseAnimatableTextureResource.js +0 -5
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import i from"../../../../core/Handles.js";import o from"../../../../core/Logger.js";import{destroyMaybe as s,isNone as r,isSome as n}from"../../../../core/maybe.js";import{createQuantity as a}from"../../../../core/quantityUtils.js";import{watch as c,syncAndInitial as l}from"../../../../core/reactiveUtils.js";import{property as m}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/arrayUtils.js";import"../../../../core/has.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as p}from"../../../../core/accessorSupport/decorators/subclass.js";import{i as d}from"../../../../chunks/vec3.js";import{c as h}from"../../../../chunks/vec3f64.js";import{geodesicLength as u}from"../../../../geometry/geometryEngine.js";import v from"../../../../geometry/Polyline.js";import{canProjectWithoutEngine as f,projectPointToVector as j,projectPointToWGS84ComparableLonLat as _}from"../../../../geometry/projection.js";import{getSphericalPCPF as g,SphericalECEFSpatialReference as P,WGS84ECEFSpatialReference as y}from"../../../../geometry/projectionEllipsoid.js";import{isSupported as D,geodesicLengths as w,inverseGeodeticSolver as z}from"../../../../geometry/support/geodesicUtils.js";import{MeasurementMode as A}from"../interfaces.js";import{applyProjectionAndElevationAlignment as R,logFailedGeometryProjectionError as E}from"../support/projectionUtils.js";import{UnitNormalizer as b}from"../support/UnitNormalizer.js";const S="esri.views.3d.analysis.DirectLineMeasurement.DirectLineMeasurementController",U=o.getLogger(S),k=1e5;let C=class extends t{constructor(e){super(e),this._unitNormalizer=new b,this._handles=new i,this._tempStartPosition=h(),this._tempEndPosition=h(),this._tempCornerPosition=h()}initialize(){const e=this.view.spatialReference,t=g(e),i=t===P?y:t;this._sphericalPCPF=i;const o=f(e,i);this._unitNormalizer.spatialReference=o?i:e,this._handles.add([c((()=>({viewData:this.viewData,startPoint:this.analysis.startPoint})),(({viewData:e,startPoint:t})=>{e.elevationAlignedStartPoint=this._applyProjectionAndElevationAlignment(t)}),l),c((()=>({viewData:this.viewData,endPoint:this.analysis.endPoint})),(({viewData:e,endPoint:t})=>{e.elevationAlignedEndPoint=this._applyProjectionAndElevationAlignment(t)}),l),c((()=>({result:this._computedResult,viewData:this.viewData})),(({result:e,viewData:t})=>{t.result=e}),l)])}destroy(){this._handles=s(this._handles)}_applyProjectionAndElevationAlignment(e){if(r(e))return e;const t=R(e,this.view.spatialReference,this.view.elevationProvider);return r(t)?(E(this.analysis,e.spatialReference,U),null):t}get _computedResult(){const{elevationAlignedStartPoint:e,elevationAlignedEndPoint:t,measurementMode:i}=this.viewData;if(r(e)||r(t))return null;const o=this._euclideanDistances(e,t),s=this._geodesicDistance(e,t,o.horizontal.value),n=i===A.Geodesic||i===A.Auto&&o.horizontal.value>k?"geodesic":"euclidean";return{mode:n,distance:"euclidean"===n?o.direct:s,directDistance:o.direct,horizontalDistance:o.horizontal,verticalDistance:o.vertical,geodesicDistance:s}}_euclideanDistances(e,t){const i=e.clone();i.z=t.z;const o=this._tempStartPosition,s=this._tempEndPosition,r=this._tempCornerPosition,n=this.view.spatialReference,c=this._sphericalPCPF,l=f(n,c)?c:n;j(e,o,l),j(t,s,l),j(i,r,l);const m=d(o,s),p=d(r,s),h=Math.abs(t.z-e.z),u=e=>this._unitNormalizer.normalizeDistance(e),v=u(m),_=u(p),g=u(h);return{direct:a(v,"meters"),horizontal:a(_,"meters"),vertical:a(g,"meters")}}_geodesicDistance(e,t,i){const o=e.spatialReference,s=new v({spatialReference:o});s.addPath([e,t]);const r=o.isGeographic&&D(o)?w([s],"meters")[0]:o.isWebMercator?u(s,"meters"):null,c=n(r)?r:this._fallbackGeodesicDistance(e,t,i);return a(c,"meters")}_fallbackGeodesicDistance(e,t,i){if(_(e,M)&&_(t,G)){const e={distance:0};return z(e,M,G),e.distance}return i}};e([m()],C.prototype,"view",void 0),e([m()],C.prototype,"analysis",void 0),e([m()],C.prototype,"viewData",void 0),e([m()],C.prototype,"_computedResult",null),C=e([p(S)],C);const M=h(),G=h();export{C as DirectLineMeasurementController};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import i from"../../../../core/Handles.js";import o from"../../../../core/Logger.js";import{destroyMaybe as s,isNone as r,isSome as n}from"../../../../core/maybe.js";import{createQuantity as a}from"../../../../core/quantityUtils.js";import{watch as c,syncAndInitial as l}from"../../../../core/reactiveUtils.js";import{property as m}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/arrayUtils.js";import"../../../../core/has.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as p}from"../../../../core/accessorSupport/decorators/subclass.js";import{i as d}from"../../../../chunks/vec3.js";import{c as h}from"../../../../chunks/vec3f64.js";import{geodesicLength as u}from"../../../../geometry/geometryEngine.js";import v from"../../../../geometry/Polyline.js";import{canProjectWithoutEngine as f,projectPointToVector as j,projectPointToWGS84ComparableLonLat as _}from"../../../../geometry/projection.js";import{getSphericalPCPF as g,SphericalECEFSpatialReference as P,WGS84ECEFSpatialReference as y}from"../../../../geometry/projectionEllipsoid.js";import{isSupported as D,geodesicLengths as w,InverseGeodeticSolverResult as z,inverseGeodeticSolver as A}from"../../../../geometry/support/geodesicUtils.js";import{MeasurementMode as R}from"../interfaces.js";import{applyProjectionAndElevationAlignment as E,logFailedGeometryProjectionError as b}from"../support/projectionUtils.js";import{UnitNormalizer as S}from"../support/UnitNormalizer.js";const U="esri.views.3d.analysis.DirectLineMeasurement.DirectLineMeasurementController",k=o.getLogger(U),C=1e5;let M=class extends t{constructor(e){super(e),this._unitNormalizer=new S,this._handles=new i,this._tempStartPosition=h(),this._tempEndPosition=h(),this._tempCornerPosition=h()}initialize(){const e=this.view.spatialReference,t=g(e),i=t===P?y:t;this._sphericalPCPF=i;const o=f(e,i);this._unitNormalizer.spatialReference=o?i:e,this._handles.add([c((()=>({viewData:this.viewData,startPoint:this.analysis.startPoint})),(({viewData:e,startPoint:t})=>{e.elevationAlignedStartPoint=this._applyProjectionAndElevationAlignment(t)}),l),c((()=>({viewData:this.viewData,endPoint:this.analysis.endPoint})),(({viewData:e,endPoint:t})=>{e.elevationAlignedEndPoint=this._applyProjectionAndElevationAlignment(t)}),l),c((()=>({result:this._computedResult,viewData:this.viewData})),(({result:e,viewData:t})=>{t.result=e}),l)])}destroy(){this._handles=s(this._handles)}_applyProjectionAndElevationAlignment(e){if(r(e))return e;const t=E(e,this.view.spatialReference,this.view.elevationProvider);return r(t)?(b(this.analysis,e.spatialReference,k),null):t}get _computedResult(){const{elevationAlignedStartPoint:e,elevationAlignedEndPoint:t,measurementMode:i}=this.viewData;if(r(e)||r(t))return null;const o=this._euclideanDistances(e,t),s=this._geodesicDistance(e,t,o.horizontal.value),n=i===R.Geodesic||i===R.Auto&&o.horizontal.value>C?"geodesic":"euclidean";return{mode:n,distance:"euclidean"===n?o.direct:s,directDistance:o.direct,horizontalDistance:o.horizontal,verticalDistance:o.vertical,geodesicDistance:s}}_euclideanDistances(e,t){const i=e.clone();i.z=t.z;const o=this._tempStartPosition,s=this._tempEndPosition,r=this._tempCornerPosition,n=this.view.spatialReference,c=this._sphericalPCPF,l=f(n,c)?c:n;j(e,o,l),j(t,s,l),j(i,r,l);const m=d(o,s),p=d(r,s),h=Math.abs(t.z-e.z),u=e=>this._unitNormalizer.normalizeDistance(e),v=u(m),_=u(p),g=u(h);return{direct:a(v,"meters"),horizontal:a(_,"meters"),vertical:a(g,"meters")}}_geodesicDistance(e,t,i){const o=e.spatialReference,s=new v({spatialReference:o});s.addPath([e,t]);const r=o.isGeographic&&D(o)?w([s],"meters")[0]:o.isWebMercator?u(s,"meters"):null,c=n(r)?r:this._fallbackGeodesicDistance(e,t,i);return a(c,"meters")}_fallbackGeodesicDistance(e,t,i){if(_(e,G)&&_(t,L)){const e=new z;return A(e,G,L),e.distance}return i}};e([m()],M.prototype,"view",void 0),e([m()],M.prototype,"analysis",void 0),e([m()],M.prototype,"viewData",void 0),e([m()],M.prototype,"_computedResult",null),M=e([p(U)],M);const G=h(),L=h();export{M as DirectLineMeasurementController};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{s as t,a as e,g as n,d as r,e as o,i as s,c as i,n as f,f as u}from"../../../../chunks/vec3.js";import{c as a}from"../../../../chunks/vec3f64.js";import{geodesicArea as c}from"../../../../geometry/geometryEngine.js";import l from"../../../../geometry/Polygon.js";import{projectPointToVector as m,projectPointToWGS84ComparableLonLat as g,projectVectorToWGS84ComparableLonLat as p}from"../../../../geometry/projection.js";import h from"../../../../geometry/SpatialReference.js";import{inverseGeodeticSolver as j}from"../../../../geometry/support/geodesicUtils.js";import{planeFromPoints as d}from"../../support/mathUtils.js";function y(o,s){const i=s.center;t(i,0,0,0);for(let t=0;t<o.length;++t)e(i,i,o[t]);n(i,i,1/o.length);let f=0;for(let t=0;t<o.length;++t)f=Math.max(f,r(i,o[t]));s.radius=Math.sqrt(f)}function P(t,e){if(t.length<3)throw new Error("need at least 3 points to fit a plane");d(t[0],t[1],t[2],e)}function w(t,e){return o(t,e)+t[3]}function M(t,e,n){return m(t,E,n)&&m(e,R,n)?s(E,R):0}function b(t,e){if(!g(t,E)||!g(e,R))return 0;const n={distance:null};return j(n,[E[0],E[1]],[R[0],R[1]]),n.distance}function k(t,e,n){const r={distance:null};return j(r,[t[0],t[1]],[e[0],e[1]],n),r.distance}function q(t,e,n,r){const o=U;return p(t,r,E)&&p(e,r,R)&&p(n,r,S)?(o.setPoint(0,0,E),o.setPoint(0,1,R),o.setPoint(0,2,S),Math.abs(c(o,"square-meters"))):0}function v(n,r=null,s=!0){const a=1e-6,c=(t,e)=>{if(0===e[0]&&0===e[1]&&0===e[2])return!1;for(let n=0;n<t.length;++n)if(o(e,t[n])<-a)return!1;return!0};if(0===n.length)return!1;if(1===n.length)return r&&i(r,n[0]),!0;t(G,0,0,0);for(let t=0;t<n.length;++t)e(G,G,n[t]);if(f(G,G),c(n,G))return r&&i(r,G),!0;if(!s)return!1;for(let t=0;t<n.length;++t)for(let e=0;e<n.length;++e)if(t!==e&&(u(G,n[t],n[e]),f(G,G),c(n,G)))return r&&i(r,G),!0;return!1}function x(t){return"mouse"!==t.pointerType||0===t.button}const E=a(),R=a(),S=a(),U=new l({rings:[[E,R,S]],spatialReference:h.WGS84}),G=a();export{P as bestFitPlane,y as boundingSphere,v as fitHemisphere,x as isPrimaryPointerAction,w as planePointDistance,M as segmentLengthEuclidean,b as segmentLengthGeodesic,k as segmentLengthGeodesicVector,q as triangleAreaGeodesic};
5
+ import{s as t,a as e,g as r,d as n,e as o,i as s,c as i,n as f,f as u}from"../../../../chunks/vec3.js";import{c as a}from"../../../../chunks/vec3f64.js";import{geodesicArea as c}from"../../../../geometry/geometryEngine.js";import l from"../../../../geometry/Polygon.js";import{projectPointToVector as m,projectPointToWGS84ComparableLonLat as g,projectVectorToWGS84ComparableLonLat as p}from"../../../../geometry/projection.js";import h from"../../../../geometry/SpatialReference.js";import{InverseGeodeticSolverResult as j,inverseGeodeticSolver as y}from"../../../../geometry/support/geodesicUtils.js";import{planeFromPoints as d}from"../../support/mathUtils.js";function w(o,s){const i=s.center;t(i,0,0,0);for(let t=0;t<o.length;++t)e(i,i,o[t]);r(i,i,1/o.length);let f=0;for(let t=0;t<o.length;++t)f=Math.max(f,n(i,o[t]));s.radius=Math.sqrt(f)}function P(t,e){if(t.length<3)throw new Error("need at least 3 points to fit a plane");d(t[0],t[1],t[2],e)}function M(t,e){return o(t,e)+t[3]}function b(t,e,r){return m(t,R,r)&&m(e,S,r)?s(R,S):0}function k(t,e){if(!g(t,R)||!g(e,S))return 0;const r=new j;return y(r,[R[0],R[1]],[S[0],S[1]]),r.distance}function q(t,e,r){const n=new j;return y(n,[t[0],t[1]],[e[0],e[1]],r),n.distance}function v(t,e,r,n){const o=G;return p(t,n,R)&&p(e,n,S)&&p(r,n,U)?(o.setPoint(0,0,R),o.setPoint(0,1,S),o.setPoint(0,2,U),Math.abs(c(o,"square-meters"))):0}function x(r,n=null,s=!0){const a=1e-6,c=(t,e)=>{if(0===e[0]&&0===e[1]&&0===e[2])return!1;for(let r=0;r<t.length;++r)if(o(e,t[r])<-a)return!1;return!0};if(0===r.length)return!1;if(1===r.length)return n&&i(n,r[0]),!0;t(T,0,0,0);for(let t=0;t<r.length;++t)e(T,T,r[t]);if(f(T,T),c(r,T))return n&&i(n,T),!0;if(!s)return!1;for(let t=0;t<r.length;++t)for(let e=0;e<r.length;++e)if(t!==e&&(u(T,r[t],r[e]),f(T,T),c(r,T)))return n&&i(n,T),!0;return!1}function E(t){return"mouse"!==t.pointerType||0===t.button}const R=a(),S=a(),U=a(),G=new l({rings:[[R,S,U]],spatialReference:h.WGS84}),T=a();export{P as bestFitPlane,w as boundingSphere,x as fitHemisphere,E as isPrimaryPointerAction,M as planePointDistance,b as segmentLengthEuclidean,k as segmentLengthGeodesic,q as segmentLengthGeodesicVector,v as triangleAreaGeodesic};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{isSome as e}from"../../../core/maybe.js";import{f as t,c as r}from"../../../chunks/vec3f64.js";import{projectVectorToVector as i}from"../../../geometry/projection.js";import s from"../../../geometry/SpatialReference.js";import{wrap as a}from"../../../geometry/support/aaBoundingBox.js";import{create as o}from"../../../geometry/support/aaBoundingRect.js";import{intersectsAABB as n}from"../../../geometry/support/frustum.js";import{isPlateCarree as h}from"../../../geometry/support/spatialReferenceUtils.js";import{createPlanarGlobePatch as c,updateCornersPlanar as l,updateEdgesAndCornersPlanar as m}from"./PatchGeometryFactory.js";import{Tile as p,CenterPosition as d}from"./Tile.js";import{intersectAabbInvDirBefore as u}from"../webgl-engine/materials/internal/MaterialUtil.js";class f extends p{constructor(e,t,r){super(),this._horizontalScaleFactor=1,this._extentInRenderSR=o(),void 0!==e&&this.init(e,t,r)}init(r,a,o){super.init(r,a,o);const n=o.view.renderSpatialReference,c=o.spatialReference,l=e(n)&&h(n)&&e(c)&&c.isGeographic?this.ellipsoid.radius*Math.PI/180:1;this._horizontalScaleFactor=l;const m=this.surface.isWebMercatorOnPlateeCarree,p=this._extentInRenderSR,d=this.extent;if(m){const e=t(d[0],d[1],0);i(e,s.WebMercator,e,s.PlateCarree);const r=t(d[2],d[3],0);i(r,s.WebMercator,r,s.PlateCarree),p[0]=e[0],p[1]=e[1],p[2]=r[0],p[3]=r[1]}else for(let e=0;e<4;++e)p[e]=d[e]*l;this.centerAtSeaLevel[0]=.5*(p[0]+p[2]),this.centerAtSeaLevel[1]=.5*(p[1]+p[3]),this.centerAtSeaLevel[2]=0,this._edgeLen=Math.max(p[2]-p[0],p[3]-p[1]),this._edgeLen2=this._edgeLen*this._edgeLen,this.updateRadiusAndCenter()}updateRadiusAndCenter(){this._updateCenter();const e=this._extentInRenderSR,t=.5*(e[2]-e[0]),r=.5*(e[3]-e[1]),i=Math.sqrt(t*t+r*r),s=.5*(this.elevationBounds[0]-this.elevationBounds[1]),a=Math.max(i,s);this._center[d.MIDDLE][3]=a}_isVisible(e){return n(e,this._aabb())}_aabb(){const e=this._extentInRenderSR;return a(e[0],e[1],this.elevationBounds[0],e[2],e[3],this.elevationBounds[1])}intersectsRay(e,t,r,i){return _[0]=1/t[0],_[1]=1/t[1],_[2]=1/t[2],u(this._aabb(),e,_,r,i)}createGeometry(){c(this.renderData,this._horizontalScaleFactor),this.setMemoryDirty()}getDefaultVerticesPerRowOnLevel(){return this.level<9?3:2}updateCornerElevations(){l(this.renderData,this._horizontalScaleFactor)}updateEdgeElevations(){m(this.renderData,this._horizontalScaleFactor)}}const _=r();export{f as PlanarPatch};
5
+ import{isSome as e}from"../../../core/maybe.js";import{f as t,c as r}from"../../../chunks/vec3f64.js";import{projectVectorToVector as i}from"../../../geometry/projection.js";import s from"../../../geometry/SpatialReference.js";import{wrap as a}from"../../../geometry/support/aaBoundingBox.js";import{create as o}from"../../../geometry/support/aaBoundingRect.js";import{isPlateCarree as n}from"../../../geometry/support/spatialReferenceUtils.js";import{TileFrustumVisibility as c}from"./interfaces.js";import{createPlanarGlobePatch as l,updateCornersPlanar as h,updateEdgesAndCornersPlanar as m}from"./PatchGeometryFactory.js";import{Tile as d,CenterPosition as p}from"./Tile.js";import{intersectAabbInvDirBefore as u}from"../webgl-engine/materials/internal/MaterialUtil.js";class f extends d{constructor(e,t,r){super(),this._horizontalScaleFactor=1,this._extentInRenderSR=o(),void 0!==e&&this.init(e,t,r)}init(r,a,o){super.init(r,a,o);const c=o.view.renderSpatialReference,l=o.spatialReference,h=e(c)&&n(c)&&e(l)&&l.isGeographic?this.ellipsoid.radius*Math.PI/180:1;this._horizontalScaleFactor=h;const m=this.surface.isWebMercatorOnPlateeCarree,d=this._extentInRenderSR,p=this.extent;if(m){const e=t(p[0],p[1],0);i(e,s.WebMercator,e,s.PlateCarree);const r=t(p[2],p[3],0);i(r,s.WebMercator,r,s.PlateCarree),d[0]=e[0],d[1]=e[1],d[2]=r[0],d[3]=r[1]}else for(let e=0;e<4;++e)d[e]=p[e]*h;this.centerAtSeaLevel[0]=.5*(d[0]+d[2]),this.centerAtSeaLevel[1]=.5*(d[1]+d[3]),this.centerAtSeaLevel[2]=0,this._edgeLen=Math.max(d[2]-d[0],d[3]-d[1]),this._edgeLen2=this._edgeLen*this._edgeLen,this.updateRadiusAndCenter()}updateRadiusAndCenter(){this._updateCenter();const e=this._extentInRenderSR,t=.5*(e[2]-e[0]),r=.5*(e[3]-e[1]),i=Math.sqrt(t*t+r*r),s=.5*(this.elevationBounds[0]-this.elevationBounds[1]),a=Math.max(i,s);this._center[p.MIDDLE][3]=a}_calculateFrustumVisibilityStatus(e){const t=this._aabb(),r=t[0],i=t[1],s=t[2],a=t[3],o=t[4],n=t[5];let l=!0;for(let h=0;h<6;h++){const t=e[h],m=t[0],d=t[1],p=t[2],u=t[3];if(m*(m>0?r:a)+d*(d>0?i:o)+p*(p>0?s:n)+u>=0)return c.OUTSIDE;if(l=l&&m*(m<0?r:a)+d*(d<0?i:o)+p*(p<0?s:n)+u<=0,!l)break}return l?c.INSIDE:c.INTERSECTS}_aabb(){const e=this._extentInRenderSR;return a(e[0],e[1],this.elevationBounds[0],e[2],e[3],this.elevationBounds[1])}intersectsRay(e,t,r,i){return S[0]=1/t[0],S[1]=1/t[1],S[2]=1/t[2],u(this._aabb(),e,S,r,i)}createGeometry(){l(this.renderData,this._horizontalScaleFactor),this.setMemoryDirty()}getDefaultVerticesPerRowOnLevel(){return this.level<9?3:2}updateCornerElevations(){h(this.renderData,this._horizontalScaleFactor)}updateEdgeElevations(){m(this.renderData,this._horizontalScaleFactor)}}const S=r();export{f as PlanarPatch};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{lerp as t}from"../../../core/mathUtils.js";import{n as e,s as i,d as s}from"../../../chunks/vec3.js";import{c as r,d as o}from"../../../chunks/vec3f64.js";import{lonLatToSphericalPCPF as a}from"../../../geometry/projection.js";import{getReferenceEllipsoid as n}from"../../../geometry/projectionEllipsoid.js";import{intersectsSphere as h,NumPlanes as l,PlaneIndex as d}from"../../../geometry/support/frustum.js";import{create as c}from"../../../geometry/support/plane.js";import{PatchType as u}from"./interfaces.js";import{createSphericalGlobePatch as p,updateCornerSpherical as _,updateEdgesAndCornersSpherical as m}from"./PatchGeometryFactory.js";import{Tile as f}from"./Tile.js";class D extends f{constructor(t,e,i){super(),this._obb=new Array(8);for(let s=0;s<8;s++)this._obb[s]=r();void 0!==t&&this.init(t,e,i)}init(i,s,r){super.init(i,s,r);const n=this.ellipsoid.radius,h=this.extentInRadians[0],l=this.extentInRadians[1],d=this.extentInRadians[2],c=this.extentInRadians[3],u=i[0],p=t(l,c,.5),_=t(h,d,.5),m=0===u?0:Math.min(Math.abs(l),Math.abs(c));this._edgeLen=(d-h)*Math.cos(m)*n,this._edgeLen2=this._edgeLen*this._edgeLen,this._curvatureHeight=n-Math.sqrt(n*n-this._edgeLen2/4),a(this.centerAtSeaLevel,_,p,this.ellipsoid.radius);const f=o(this.centerAtSeaLevel);e(f,f),this.up=f,this._updateOBB(),this.updateRadiusAndCenter()}updateRadiusAndCenter(){if(0===this.lij[0])i(this._center[E.MIDDLE],0,0,0),i(this._center[E.TOP],0,0,0),i(this._center[E.BOTTOM],0,0,0),this.ellipsoid||(this.ellipsoid=n(this.surface.spatialReference)),this._center[E.MIDDLE][3]=this.ellipsoid.radius+this.elevationBounds[1];else{this._updateCenter();const t=Math.max(s(this._center[E.MIDDLE],this._obb[0]),s(this._center[E.MIDDLE],this._obb[1]));this._center[E.MIDDLE][3]=Math.sqrt(t)}}_isVisible(t){if(!h(t,this._center[E.MIDDLE]))return!1;if(this.lij[0]<10)return!0;const e=this._obb;for(let i=0;i<l.NUM;i++){const s=i===d.NEAR,r=t[i];s&&(O[0]=r[0],O[1]=r[1],O[2]=r[2],O[3]=r[3]-this.surface.view.state.camera.near);const o=s?O:r;let a;for(a=0;a<8;a++){const t=e[a];if(o[0]*t[0]+o[1]*t[1]+o[2]*t[2]+o[3]<0)break}if(8===a)return!1}return!0}computeElevationBounds(){super.computeElevationBounds(),this._updateOBB()}createGeometry(){const t=this._getPatchType(this.lij[1],this.lij[0]);p(this.renderData,t),this.setMemoryDirty()}_updateOBB(){const t=this.extentInRadians,e=this._obb;for(let i=0;i<2;i++){const s=this.elevationBounds[i];let r=4*i;a(e[r++],t[0],t[1],this.ellipsoid.radius+s),a(e[r++],t[0],t[3],this.ellipsoid.radius+s),a(e[r++],t[2],t[3],this.ellipsoid.radius+s),a(e[r++],t[2],t[1],this.ellipsoid.radius+s)}if(this.surface.isWebMercator)switch(this._getPatchType(this.lij[1],this.lij[0])){case u.HAS_NORTH_POLE:i(e[1],0,0,this.ellipsoid.radius),i(e[2],0,0,this.ellipsoid.radius),i(e[5],0,0,this.ellipsoid.radius),i(e[6],0,0,this.ellipsoid.radius);break;case u.HAS_SOUTH_POLE:i(e[0],0,0,-this.ellipsoid.radius),i(e[3],0,0,-this.ellipsoid.radius),i(e[4],0,0,-this.ellipsoid.radius),i(e[7],0,0,-this.ellipsoid.radius)}}_getPatchType(t,e){return t===(1<<e)-1?0===t?u.HAS_BOTH_POLES:u.HAS_SOUTH_POLE:0===t?u.HAS_NORTH_POLE:u.REGULAR}intersectsRay(t,e,i,s){const r=this._center[E.MIDDLE],o=r[3]+i,a=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=r[0]-t[0],h=r[1]-t[1],l=r[2]-t[2],d=(n*e[0]+h*e[1]+l*e[2])/a,c=e[0]*d-n,u=e[1]*d-h,p=e[2]*d-l;return c*c+u*u+p*p<o*o}getDefaultVerticesPerRowOnLevel(){return this.level<L.length?L[this.level]+1:2}updateCornerElevations(){_(this.renderData)}updateEdgeElevations(){m(this.renderData)}}const L=[128,64,32,16,16,8,8,4],O=c();var E;!function(t){t[t.TOP=0]="TOP",t[t.MIDDLE=1]="MIDDLE",t[t.BOTTOM=2]="BOTTOM"}(E||(E={}));export{E as CenterPosition,D as SphericalPatch};
5
+ import{lerp as t}from"../../../core/mathUtils.js";import{n as e,s as i,d as s}from"../../../chunks/vec3.js";import{c as r,d as a}from"../../../chunks/vec3f64.js";import{lonLatToSphericalPCPF as o}from"../../../geometry/projection.js";import{getReferenceEllipsoid as n}from"../../../geometry/projectionEllipsoid.js";import{intersectsSphere as h,NumPlanes as l,PlaneIndex as d}from"../../../geometry/support/frustum.js";import{TileFrustumVisibility as u,PatchType as c}from"./interfaces.js";import{createSphericalGlobePatch as p,updateCornerSpherical as _,updateEdgesAndCornersSpherical as m}from"./PatchGeometryFactory.js";import{Tile as f}from"./Tile.js";class E extends f{constructor(t,e,i){super(),this._obb=new Array(8);for(let s=0;s<8;s++)this._obb[s]=r();void 0!==t&&this.init(t,e,i)}init(i,s,r){super.init(i,s,r);const n=this.ellipsoid.radius,h=this.extentInRadians[0],l=this.extentInRadians[1],d=this.extentInRadians[2],u=this.extentInRadians[3],c=i[0],p=t(l,u,.5),_=t(h,d,.5),m=0===c?0:Math.min(Math.abs(l),Math.abs(u));this._edgeLen=(d-h)*Math.cos(m)*n,this._edgeLen2=this._edgeLen*this._edgeLen,this._curvatureHeight=n-Math.sqrt(n*n-this._edgeLen2/4),o(this.centerAtSeaLevel,_,p,this.ellipsoid.radius);const f=a(this.centerAtSeaLevel);e(f,f),this.up=f,this._updateOBB(),this.updateRadiusAndCenter()}updateRadiusAndCenter(){if(0===this.lij[0])i(this._center[O.MIDDLE],0,0,0),i(this._center[O.TOP],0,0,0),i(this._center[O.BOTTOM],0,0,0),this.ellipsoid||(this.ellipsoid=n(this.surface.spatialReference)),this._center[O.MIDDLE][3]=this.ellipsoid.radius+this.elevationBounds[1];else{this._updateCenter();const t=Math.max(s(this._center[O.MIDDLE],this._obb[0]),s(this._center[O.MIDDLE],this._obb[1]));this._center[O.MIDDLE][3]=Math.sqrt(t)}}_calculateFrustumVisibilityStatus(t){if(!h(t,this._center[O.MIDDLE]))return u.OUTSIDE;if(this.lij[0]<10)return u.INTERSECTS;const e=this._obb,i=this.surface.view.state.camera.near;let s=!0;for(let r=0;r<l.NUM;r++){const a=r===d.NEAR,o=t[r],n=o[0],h=o[1],l=o[2],c=o[3]-(a?i:0);let p=!1;for(let t=0;t<8;++t){const i=e[t];if(n*i[0]+h*i[1]+l*i[2]+c<0){if(p=!0,!s)break}else s=!1}if(!p)return u.OUTSIDE}return s?u.INSIDE:u.INTERSECTS}computeElevationBounds(){super.computeElevationBounds(),this._updateOBB()}createGeometry(){const t=this._getPatchType(this.lij[1],this.lij[0]);p(this.renderData,t),this.setMemoryDirty()}_updateOBB(){const t=this.extentInRadians,e=this._obb;for(let i=0;i<2;i++){const s=this.elevationBounds[i];let r=4*i;o(e[r++],t[0],t[1],this.ellipsoid.radius+s),o(e[r++],t[0],t[3],this.ellipsoid.radius+s),o(e[r++],t[2],t[3],this.ellipsoid.radius+s),o(e[r++],t[2],t[1],this.ellipsoid.radius+s)}if(this.surface.isWebMercator)switch(this._getPatchType(this.lij[1],this.lij[0])){case c.HAS_NORTH_POLE:i(e[1],0,0,this.ellipsoid.radius),i(e[2],0,0,this.ellipsoid.radius),i(e[5],0,0,this.ellipsoid.radius),i(e[6],0,0,this.ellipsoid.radius);break;case c.HAS_SOUTH_POLE:i(e[0],0,0,-this.ellipsoid.radius),i(e[3],0,0,-this.ellipsoid.radius),i(e[4],0,0,-this.ellipsoid.radius),i(e[7],0,0,-this.ellipsoid.radius)}}_getPatchType(t,e){return t===(1<<e)-1?0===t?c.HAS_BOTH_POLES:c.HAS_SOUTH_POLE:0===t?c.HAS_NORTH_POLE:c.REGULAR}intersectsRay(t,e,i,s){const r=this._center[O.MIDDLE],a=r[3]+i,o=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=r[0]-t[0],h=r[1]-t[1],l=r[2]-t[2],d=(n*e[0]+h*e[1]+l*e[2])/o,u=e[0]*d-n,c=e[1]*d-h,p=e[2]*d-l;return u*u+c*c+p*p<a*a}getDefaultVerticesPerRowOnLevel(){return this.level<D.length?D[this.level]+1:2}updateCornerElevations(){_(this.renderData)}updateEdgeElevations(){m(this.renderData)}}const D=[128,64,32,16,16,8,8,4];var O;!function(t){t[t.TOP=0]="TOP",t[t.MIDDLE=1]="MIDDLE",t[t.BOTTOM=2]="BOTTOM"}(O||(O={}));export{O as CenterPosition,E as SphericalPatch};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import a from"../../../core/Evented.js";import n from"../../../core/Handles.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{releaseMaybe as h,destroyMaybe as d,isNone as p,isSome as u}from"../../../core/maybe.js";import c from"../../../core/ObjectPool.js";import g from"../../../core/PooledArray.js";import{isAbortError as _,isAborted as m,createAbortError as T}from"../../../core/promiseUtils.js";import{watch as f,syncAndInitial as y,sync as v,initial as w}from"../../../core/reactiveUtils.js";import{property as S}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as L}from"../../../core/accessorSupport/decorators/subclass.js";import{m as E}from"../../../chunks/mat4.js";import{c as D}from"../../../chunks/mat4f64.js";import{c as x}from"../../../chunks/vec3.js";import{c as C}from"../../../chunks/vec3f64.js";import{c as P}from"../../../chunks/vec4f64.js";import{WatchUpdatingTracking as b}from"../../../core/support/WatchUpdatingTracking.js";import{projectVectorToVector as U,projectPointToVector as R}from"../../../geometry/projection.js";import{getReferenceEllipsoid as M}from"../../../geometry/projectionEllipsoid.js";import{create as j,equals as A,intersection as I,empty as V,expand as O,intersectsSphere as k}from"../../../geometry/support/aaBoundingRect.js";import{create as B,copy as N}from"../../../geometry/support/frustum.js";import{isPlateCarree as q}from"../../../geometry/support/spatialReferenceUtils.js";import{isRefreshableLayer as G}from"../../../layers/mixins/RefreshableLayer.js";import{ElevationQueryTileCache as F}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as W}from"../../../layers/support/layerUtils.js";import{acquireDecoder as H}from"../../../layers/support/LercDecoder.js";import{printAllocations as z}from"../../2d/engine/vectorTiles/VectorTile.js";import{directionToHeadingTilt as Q,scaleToZoom as X}from"../support/cameraUtils.js";import Y from"../support/debugFlags.js";import{toBoundingRect as $}from"../support/extentUtils.js";import{ClientType as K}from"../support/index.js";import{updatingProgress as J}from"../support/updatingProperties.js";import{ElevationBounds as Z}from"./ElevationBounds.js";import{sampleElevation as ee,ElevationData as te}from"./ElevationData.js";import{create as ie}from"./ExtentHelper.js";import{LODSnapping as re,TextureUpdate as se}from"./interfaces.js";import{LayerClass as ae,LayerClasses as ne}from"./LayerClass.js";import{OverlayManager as le}from"./OverlayManager.js";import{PlanarPatch as oe}from"./PlanarPatch.js";import{RenderOrder as he}from"./RenderOrder.js";import{SphericalPatch as de}from"./SphericalPatch.js";import{MAX_ROOT_TILES as pe,TOO_MANY_ROOT_TILES_AFTER_CHANGE_ERROR as ue,TOO_MANY_ROOT_TILES_FOR_LAYER_ERROR as ce,MAX_MEMORY_LOD_BIAS as ge,ELEVATION_NODATA_VALUE as _e}from"./TerrainConst.js";import me from"./TerrainRenderer.js";import Te from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as fe,internalAssert as ye,oppositeEdge as ve,isSurfaceLayerView as we,isMapTileLayerView as Se,isBlendableLayerView as Le,isGroupLayer as Ee,isElevationLayerView as De,isVectorTileLayerView as xe,useFetchTileForLayer as Ce,isImageryTileLayerView as Pe,isTileLayerView as be,releaseTileData as Ue,neighborEdgeIndices as Re,ENABLE_TERRAIN_INTERNAL_CHECKS as Me,ENABLE_WATERPROOFNESS_TESTS as je,enableTerrainInternalChecks as Ae,enableTerrainWaterproofnessChecks as Ie}from"./terrainUtils.js";import{SplitLimits as Ve,Tile as Oe}from"./Tile.js";import{printAllocations as ke}from"./TilePerLayerInfo.js";import{TileUpdate as Be}from"./TileUpdate.js";import{IteratorPreorder as Ne,IteratorPostorder as qe,compareTilesByLij as Ge,hasLoadableSiblings as Fe,sortTilesByPOI as We,sortTiles as He}from"./tileUtils.js";import{TilingSchemeLogic as ze}from"./TilingSchemeLogic.js";import{UpsampleInfo as Qe}from"./UpsampleInfo.js";import{isCompositeBlendMode as Xe,blendModeFromString as Ye}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{RenderRequestType as $e}from"../webgl-engine/lib/basicInterfaces.js";import{ImmediateTask as Ke,TaskPriority as Je,noBudget as Ze}from"../../support/Scheduler.js";const et=.25;let tt=class extends(a.EventedMixin(i)){constructor(e){super(e),this._iteratorPool=new c(Ne,(e=>e.remove=()=>this._iteratorPool.release(e))),this._postorderIterator=new qe,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._visibleCached=!1,this._usedMemory=null,this._performanceInfo=new Te,this._viewChanged=!1,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=C(),this._eyePosSurfaceSR=C(),this._splitLimits=new Ve,this._snapLevel=1/0,this._frustum=B(),this._viewProjectionMatrix=D(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._handles=new n,this._watchUpdatingTracking=new b,this._frameTask=Ke,this._allTiles=new g,this._upsampleInfoPool=new c(Qe),this._rootTilesExtent=j(),this._maxNumUpdating=1,this.maxTextureScale=1.2,this.visibleElevationBounds=new Z(1/0,-1/0),this.rootTileElevationBounds=new Z(1/0,-1/0),this._updatingRootTiles=!1,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this.shortBatches=!1,this._layerViewsDirty=!1,this._isGlobal=!e.view?.state?.isLocal}initialize(){this._lercDecoder=H(this.view.resourceController),this._tilePool=this.view.state.isLocal?new c(oe):new c(de);const e=this.view.resourceController.memoryController;this._upsampleMapCache=e.newCache("esri.views.3d.terrain.upsample",(e=>e.unloadMapData())),this._elevationQueryCache=new F(e.newCache("elevation-query")),this._set("overlayManager",new le({surface:this})),this._handles.add([f((()=>this.overlayManager.hasHighlights),(e=>this._renderer.setNeedsHighlight(e))),f((()=>this.overlayManager.rendersOccluded),(e=>this._renderer.setRenderOccludedOverlay(e)))],"overlayManager"),this._renderer=new me({_overlayRenderer:this.overlayManager.renderer,_ellipsoidRadius:M(this.view.spatialReference).radius,_stage:this.view._stage,_allTiles:this._allTiles}),this._handles.add([f((()=>this.baseOpacity),(e=>{this._handleLayerViewChanges(),this._updateBaseOpacity(e)}),y),f((()=>this.hasCompositeBlendMode),(()=>{this._updateBaseOpacity(this.baseOpacity)}),y),f((()=>this.renderingDisabled),(()=>this._updateTransparentTerrain()),v),f((()=>this.backgroundColor),(e=>{this._handleLayerViewChanges(),this._renderer.updateTileBackground(e)}),y),f((()=>this.view.pointsOfInterest),(e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add((()=>e.focus.renderLocation),(()=>()=>this._allTilesSorted=!1))})),f((()=>Y.TERRAIN_TILE_TREE_SHOW_TILES),(e=>{e&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then((({TerrainTileTree3DDebugger:e})=>{!this._treeDebugger&&Y.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new e({view:this.view}))})):e||(this._treeDebugger=d(this._treeDebugger))}),w)]),this._extentHelper=ie(this.viewingMode,{layers:this.view.map.allLayers,layerViews:this.view.allLayerViews,viewSpatialReference:this.view.spatialReference});const t=this.view.defaultsFromMap?new s({getCollections:()=>this.view?.defaultsFromMap?.mapCollections?.map((({layers:e})=>e)),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}):this.view.map.allLayers,i=new ze({layers:t,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:this.view.spatialReference});this._set("tilingSchemeLogic",i),this._updateTilingScheme(),this._elevationDataRequester=this.view.resourceController.createStreamDataRequester(K.ELEVATION),this._mapDataRequester=this.view.resourceController.createStreamDataRequester(K.BASEMAP);const r=this.view.resourceController.scheduler;this._frameTask=r.registerTask(Je.TERRAIN_SURFACE,this),this._handles.add([f((()=>this._extentHelper.stencilEnabledExtents),(e=>this._renderer.setStencilEnabledLayerExtents(e)),w),f((()=>this.tilingSchemeLogic.tilingScheme),(()=>this._updateTilingScheme()),v),f((()=>this.extent),(()=>this._updateRootTiles()),w),this.view.on("resize",(()=>this._viewChangeUpdate())),f((()=>{const e=this.view,t=e.state;return[this._lodBias,this.lodSnapping,e.resourceController?.memoryController?.memoryFactor,t.camera,t.contentCamera,t.fixedContentCamera]}),(()=>this._viewChangeUpdate()),y),f((()=>this.view.qualitySettings?.tiledSurface?.textureFadeDuration),(e=>this._renderer.textureFadingEnabled=e>0),w),f((()=>this._userClippingExtent),(()=>this._updateClippingExtent()),v)]),this._handles.add(this.view.allLayerViews.on("after-changes",(()=>this._layerViewsDirty=!0))),this._handles.add([f((()=>this.view?.map.ground.shading),(()=>{this._updateShading()}))]),this._layerViewsDirty=!0,this._handleLayerViewChanges()}destroy(){this._frameTask.remove(),this._handles.destroy(),this._watchUpdatingTracking.destroy(),this._lercDecoder=h(this._lercDecoder),this._removeAllTiles(),this._upsampleMapCache=d(this._upsampleMapCache),this._elevationQueryCache=d(this._elevationQueryCache),this._set("tilingSchemeLogic",d(this.tilingSchemeLogic)),this._extentHelper=d(this._extentHelper),this._basemapLayerViewHandles.forEach(((e,t)=>this._unregisterTiledLayerView(t))),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",d(this.overlayManager)),this._tilePool=d(this._tilePool),Oe.prune(),this._treeDebugger&&(this._treeDebugger.destroy(),this._treeDebugger=null),this._renderer=d(this._renderer),this._iteratorPool=d(this._iteratorPool),this._set("view",null),this._upsampleInfoPool=d(this._upsampleInfoPool),z(),ke()}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){const e=this.view.pointsOfInterest?.contentCameraOnSurface?.scale;if(e){const t=this.view.state.contentCamera;let i=Q(this.view,t.eye,t.viewForward,t.up).tilt;i>90&&(i=180-i);const r=2*(i/90)**2,s=X(this.view,e)-r;Math.abs(this._snapLevel-s)>et&&(Math.round(s)!==Math.round(this._snapLevel)&&(this._viewChanged=!0),this._snapLevel=s)}return Math.round(this._snapLevel)}get lodSnapping(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences?re.ON:re.OFF}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get mapTileRequester(){return this._mapDataRequester}get _userClippingExtent(){const{spatialReference:e}=this,{clippingArea:t}=this.view;if(p(t)||p(e))return null;const i=j(),r=$(t,i,e)?i:null,s=this._get("extent");return A(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=I(this.groundExtent,this._userClippingExtent,j()),t=this._get("extent");return A(e,t)?t:e}get groundExtent(){return u(this._tilingSchemeExtent)?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),!!((this._watchUpdatingTracking.updating||this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||this._asyncWorkItems>0||!this._allTilesSorted||this._layerViewsDirty)&&this.ready&&!this.suspended||this.overlayManager.updating||this._frameTask.updating)}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view.map.ground.opacity}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return u(this.rootTiles)}set renderOrder(e){this._renderer.renderOrder=e,this._set("renderOrder",e)}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view.map.ground.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._updateTransparentTerrain()}_updateTransparentTerrain(){const e=!this.renderingDisabled&&!this.opaque;this.view?._stage?.renderView.setRenderParameters({transparentTerrain:e})}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}set velvetOverground(e){e!==this.velvetOverground&&(this._renderer.velvetOverground=e),this._set("velvetOverground",e)}get wireframe(){return this._renderer.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}set _visible(e){e!==this._visibleCached&&(this._visibleCached=e,this._renderer.setVisibility(e),this.suspended=!e)}get opaque(){return this._renderer.opaque}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get textureFadeDuration(){return this.view.qualitySettings.tiledSurface.textureFadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevation(e,t,i,r){const s=this.getTileWithElevation(e,t,i,r,nt);return p(s)?null:ee(nt[0],nt[1],s.renderData.geometryState.samplerData)}getTileWithElevation(e,t,i,r,s=nt){const a=this.rootTiles;if(p(a)||!a.length)return null;if(0===a[0].layerInfo[ae.ELEVATION].length)return null;if(s[0]=e,s[1]=t,s[2]=i,!U(s,r,s,this.tilingScheme?.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;for(let n of a){if(!n.containsPoint(s))continue;for(;n&&!n.rendered&&!n.isLeaf;){let e=0;s[0]>.5*(n.extent[0]+n.extent[2])&&(e+=1),s[1]<.5*(n.extent[1]+n.extent[3])&&(e+=2),n=n.children[e]}const e=n.renderData;return(e?e.geometryState.samplerData:null)?n:null}return null}getScale(e){if(this.tilingScheme){if(!R(e,nt,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this.rootTiles;if(u(t))for(let e of t)if(e?.containsPoint(nt)){for(;!e.isLeaf&&!e.rendered;){let t=0;nt[0]>e.children[0].extent[2]&&(t+=1),nt[1]<e.children[0].extent[1]&&(t+=2),e=e.children[t]}return this._getLodBiasCorrectedScale(e.level)}}return 1e100}getSphereElevationBounds(e,t,i,r,s){if(nt[0]=e,nt[1]=t,nt[2]=i,nt[3]=r,!U(nt,s,nt,this.tilingScheme?.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;let a=1/0,n=-1/0;const o=e=>{if(e&&k(e.extent,nt))if(e.isLeaf||e.rendered)a=Math.min(a,e.elevationBounds[0]),n=Math.max(n,e.elevationBounds[1]);else for(const t of e.children)o(t)},h=this.rootTiles;if(u(h))for(const l of h)o(l);return{min:a,max:n}}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!R(e,nt,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;nt[3]=t;let i=null;const r=e=>{if(e&&k(e.extent,nt))if(e.isLeaf||e.rendered){const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}else for(const t of e.children)r(t)},s=this.rootTiles;if(u(s))for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._renderer.queryVisibleLevelRange(e,s+n,a+n,r)}_updateBaseOpacity(e){const t=this._renderer.opaque;this._renderer.opaque=e>=1&&!this.hasCompositeBlendMode,this._renderer.isTransparent=this._allSurfaceLayersTransparent();const i=t!==this._renderer.opaque;i&&this._updateTransparentTerrain(),this._updateTileTextures(i?se.UNFADED:se.IMMEDIATE)}_updateTilingScheme(){const e=this.tilingSchemeLogic.tilingScheme;e!==this.tilingScheme&&(fe(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles(),this._set("tilingScheme",e),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.setTileSize(e.pixelSize),this.overlayManager.setSpatialReference(e.spatialReference),this._updateRootTiles()))}_acquireTile(e,t,i,r){const s=this._tilePool.acquire();return ot[0]=e,ot[1]=t,ot[2]=i,s.init(ot,r,this),s}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=lt;let s=t.rootTilesInExtent(e,i,5*pe);if(u(this.rootTiles)){if(s.length>pe)return void l.getLogger(this.declaredClass).warn(ue);const e=this.rootTiles.map((e=>e.lij)),t=r(e,s,rt);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this.rootTiles.filter((e=>!(t.removed.findIndex((t=>rt(t,e.lij)))>-1)||(this._purgeTile(e),!1)));t.added.forEach((t=>e.push(this._newRootTile(t)))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>pe&&(l.getLogger(this.declaredClass).warn(ce),s=t.rootTilesInExtent(e,i,pe)),this._setRootTiles(s.map((e=>this._newRootTile(e))));A(i,this._rootTilesExtent)||(this._rootTilesExtent=j(i)),this._visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter((e=>e.isLoaded&&e.intersectsClippingArea));e.forEach((e=>this._renderer.updateTileGeometryState(e))),e.forEach((e=>e.renderData.updateNeighborData())),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Ge);const t=this.renderer;e.forEach((e=>t.updateGeometryIfNeeded(e)))}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return t.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Be.SPLIT&&t.setPendingUpdate(Be.SPLIT),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationBounds(),t}_setRootTiles(e){if(this._set("rootTiles",e),this._allTiles.clear(),u(e)){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this.rootTiles),this._updateTilesVisibility(e)}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this._visibleCached&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this.rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(Be.GEOMETRY)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(p(e))return;const t=Fe(e),i=this.visibleElevationBounds;let r=t?i.min:1/0,s=t?i.max:-1/0;const a=this.extent,n=this._viewProjectionMatrix;this.setTileTreeDirty();const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(Be.GEOMETRY)&&this._updateTileGeometryState(e),e.setPendingUpdate(Be.RENDERDATA),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBounds[0],r),s=Math.max(e.elevationBounds[1],s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._batchUpdatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.min!==r||i.max!==s)&&(this.visibleElevationBounds=new Z(r,s))}_updateRootTileElevationBounds(){let e=1/0,t=-1/0;const i=this.rootTiles;u(i)&&i.forEach((({elevationBounds:i})=>{e=Math.min(e,i[0]),t=Math.max(t,i[1])}));const r=this.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new Z(e,t))}_updateViewDependentParameters(){const e=this.view.state.camera,t=this.view.state.contentCamera,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?(p(this._splitLimits.frustum)&&(this._splitLimits.frustum=B()),N(this._splitLimits.frustum,t.frustum)):this._splitLimits.frustum=null,N(this._frustum,e.frustum),E(this._viewProjectionMatrix,t.projectionMatrix,t.viewMatrix),x(this._eyePosRenderSR,t.eye),U(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateRenderData(e){e.rendered&&!e.shouldLoad&&(st(e)?this._loadChildren(e):at(e)&&this._loadParent(e))}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this._usedMemory=null}_markAllTileNeighborsForGeometryUpdate(e){const t=this._pendingTilesToUpdate;e.forEachLoadedNeighbor((e=>{t.add(e)}))}_updateTileTexture(e,t){const i=e.resetPendingUpdate(Be.TEXTURE_FADING)?Be.TEXTURE_FADING:!!e.resetPendingUpdate(Be.TEXTURE_NOFADING)&&Be.TEXTURE_NOFADING;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(e){const t=dt.extent;V(t);const i=e.length;for(let r=0;r<i;r++)O(t,e[r].extent,t);dt.spatialReference=this.spatialReference,this.emit("elevation-change",dt)}get running(){return this.updating&&this.ready&&!this.suspended}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),e.run((()=>this._updateElevation(e))),e.run((()=>this._updateTextures(e))),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),e.done?this.requestUpdate():this.getUsedMemory(),this.notifyChange("updatingProgressValue")}_updateAllTilesStatus(e){if(!this._viewChanged||!this.rootTiles||e.done)return;this._viewChanged=!1;const t=this._iteratorPool.acquire();for(t.reset(this.rootTiles);!t.done;){const e=t.next(),i=e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping);if(i!==Be.SPLIT){if(e.resetPendingUpdate(Be.SPLIT)&&e.updateAgentSuspension(),i===Be.VSPLITMERGE&&e.updateAgents(ae.ELEVATION),t.skipSubtree(),!e.isLeaf){e.setPendingUpdate(Be.MERGE),e.resetPendingUpdate(Be.SPLIT);const t=this._iteratorPool.acquire();t.resetOne(e);for(let e=t.next();!t.done;e=t.next())this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(this._viewProjectionMatrix);t.remove()}}else e.resetPendingUpdate(Be.MERGE),e.isLeaf&&(e.setPendingUpdate(Be.SPLIT),t.skipSubtree())}t.remove(),this.requestUpdate(),this._batchUpdatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||(We(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_markTileToUpdate(e,t=!0){ye(e.isLoaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),t&&this._markAllTileNeighborsForGeometryUpdate(e))}_batchUpdatePendingTileGeometries(){const e=this._pendingTilesToUpdate;if(0===e.size)return;const t=[];e.forEach((e=>{e.isLoaded&&e.intersectsClippingArea&&t.push(e)}));const i=(i,r)=>{!r?.isLoaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Ge);const r=t.length;for(let s=0;s<r;++s){const r=t[s];ye(r.isLoaded),ye(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a._dirtyEdgeResolutions,l=a.geometryState.neighborData;for(let t=0;t<4;++t)if(n&1<<t){const s=r.renderData.geometryState.neighborData.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(ve(Re[t]),(t=>!(!t.isLoaded||!t.intersectsClippingArea)&&(ye(e.has(t)||Ge(r,t)<0),i(r,t),!0))),i(r,l.cornerPeerNeighbors[t]),i(r,l.cornerPeerNeighbors[(t+1)%4])}}e.clear(),this._updateTilesGeometries(t),this._emitElevationUpdateEventForTiles(t),Me&&je&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1,r=!1;for(;!e.done;){r=!0;let s=!1;const a=!this._allTiles.some((r=>{if(!i&&!r.loadable)return e.done;let a=r;if(r.resetPendingUpdate(Be.MERGE)){if(!t)return r.setPendingUpdate(Be.MERGE),e.done;for(;a.parent?.resetPendingUpdate(Be.MERGE);)a=a.parent;this._mergeTile(a),s=!0,e.madeProgress()}else r.resetPendingUpdate(Be.SPLIT)&&(this._splitTile(r),s=!0,e.madeProgress());return!e.done&&a===r&&r.resetPendingUpdate(Be.RENDERDATA)&&(this._updateRenderData(r),e.madeProgress()),e.done}));if(s&&(this._allTilesSorted=!1,this._allTilesDirty=!0),a){if(!i){i=!0;continue}if(!s)break;this._updateTilesVisibility(this.rootTiles)}else this._allTilesDirty=!0}r||(this._allTilesDirty=!0),this._batchUpdatePendingTileGeometries(),this._sortTiles(e)}_updateElevation(e){return this._allTiles.some((t=>(t.resetPendingUpdate(Be.GEOMETRY)&&(this._updateTileGeometryState(t),this._updateTileTexture(t,e),e.madeProgress()),e.done))),this._batchUpdatePendingTileGeometries(),e.hasProgressed}_updateTextures(e){return this._allTiles.some((t=>(this._updateTileTexture(t,e),e.done))),e.hasProgressed}_updateClippingExtent(){this.spatialReference&&(this.updateTileOverlayParams($e.UPDATE),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.resourceController.memoryController.memoryFactor;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*ge}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){u(this.rootTiles)&&(this.rootTiles.forEach((e=>this._purgeTile(e))),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this._visible=!1}_purgeDescendantTiles(e){if(e.isLeaf)return!1;let t=!1;for(let i=0;i<4;++i)t=this._purgeTile(e.children[i])||t;return e.unsetChildren(),t}_purgeTile(e){const t=this._purgeDescendantTiles(e)||e.rendered;return this._allTiles.removeUnordered(e),this._unloadTile(e),this._tilePool.release(e),t}_unloadTile(e){this._pendingTilesToUpdate.delete(e),e.unload(this._renderer)}_splitTile(e){fe(e.isLeaf,"tile that is already split should not be split again!");const t=e.level+1,i=2*e.lij[1],r=2*e.lij[2];e.setChildren(this._createTile(t,i,r,e),this._createTile(t,i,r+1,e),this._createTile(t,i+1,r,e),this._createTile(t,i+1,r+1,e)),e.setPendingUpdate(Be.RENDERDATA),e.updateAgentSuspension(),this._allTiles.pushArray(e.children),this._allTilesDirty=!0,++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){pt.spatialReference=this.spatialReference,pt.extent=e.extent,pt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",pt)}_createTile(e,t,i,r){fe(!!r,"_createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this._viewProjectionMatrix),s.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Be.SPLIT&&s.setPendingUpdate(Be.SPLIT),s}_mergeTile(e){fe(!e.hasPendingUpdate(Be.SPLIT),"_mergeTile sanity check"),this._purgeDescendantTiles(e)&&(fe(!e.renderData,"_mergeTile sanity check"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this.shortBatches&&this._batchUpdatePendingTileGeometries()),this._allTilesDirty=!0,++this._performanceInfo.numMerged}_loadChildren(e){fe(e.rendered,"parent should be rendered"),this._unloadTile(e);const t=e.children;t.forEach((e=>this._loadTile(e))),t.forEach((e=>this._pendingTilesToUpdate.add(e))),this._markAllTileNeighborsForGeometryUpdate(e),this._emitTileScaleChange(e,e.level+1),this.shortBatches&&this._batchUpdatePendingTileGeometries()}_loadParent(e){const t=e.parent;this._unloadChildren(t),this._loadTile(t),this._markTileToUpdate(t),this._emitTileScaleChange(t,t.level),this.shortBatches&&this._batchUpdatePendingTileGeometries()}_unloadChildren(e){if(!e.isLeaf)for(let t=0;t<4;++t){const i=e.children[t];this._unloadChildren(i),this._unloadTile(i)}}_loadTile(e){e.load(),e.setPendingUpdate(Be.RENDERDATA),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager&&this.overlayManager.hasOverlays&&this.overlayManager.setTileParameters(e)}_elevationDataArrived(e,t,i){const r=new te(e.lij,e.extent,i);e.dataArrived(t,ae.ELEVATION,r);const s=[e],a=e.level,n=this._iteratorPool.acquire();for(n.reset(s);!n.done;){const e=n.next();e.findElevationBoundsForLayer(t,a),e.computeElevationBounds()}0===a&&this._updateRootTileElevationBounds(),n.remove(),this._updateTilesVisibility(s)}_handleLayerViewChanges(e=Ze){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(const s of this.view.allLayerViews.items)if(i.add(s.uid),we(s))if(this._basemapLayerViewHandles.has(s.uid)){const e=this._layerClassFromLayerView(s),i=this._getLayerIdxByUID(e,s.uid);u(i)&&((i<r||p(r))&&(t=!0),r=i)}else this._registerTiledLayerView(s),s.layer.loaded&&(t=!0);this._basemapLayerViewHandles.forEach(((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)})),t&&this._updateTiledLayers(),this._renderer.isTransparent=this._allSurfaceLayersTransparent(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),e.madeProgress()}_allSurfaceLayersTransparent(){let e=0===this.view.map?.ground?.opacity;for(const t of this.view.allLayerViews.items)if(Se(t)&&!W(t.layer)&&0!==t.fullOpacity)return e=!1,e;return e}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if(Le(e)){const t=Ee(e.layer.parent)?"normal":e.layer.blendMode;if(Xe(Ye[t]))return!0}return!1}_layerClassFromLayerView(e){return De(e)?ae.ELEVATION:ae.MAP}_registerTiledLayerView(e){const t=[],i=this._layerClassFromLayerView(e);t.push(f((()=>e.suspended),(()=>this._updateTiledLayers()))),t.push(f((()=>e.fullOpacity),(()=>this._updateTileTextures(se.UNFADED)))),t.push(f((()=>"effectiveScaleRange"in e.layer?e.layer.effectiveScaleRange:null),(()=>this._restartAllAgents(i)))),Le(e)&&t.push(f((()=>e.layer.blendMode),(()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(se.UNFADED)}))),e.on("data-changed",(()=>{const t=this._getLayerIdxByUID(i,e.uid);u(t)&&this._invalidateLayerData(t,i)})),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(let e=0;e<t.length;e++)t[e].remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach((e=>{if(!e.layer||e.suspended||!we(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(r===ae.MAP){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)}));for(const r of ne){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this.rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this.rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&this._viewChangeUpdate()}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this.rootTiles);!t.done;){const i=t.next();i.restartAgents(e),e===ae.ELEVATION&&i.computeElevationBounds()}this._updateRootTileElevationBounds()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll((t=>{t.updateAgents(ae.MAP),e===se.IMMEDIATE?this.renderer.updateTileTexture(t,Be.TEXTURE_NOFADING):t.updateRenderData(ae.MAP,e)})),this._renderer.isTransparent=this._allSurfaceLayersTransparent()}_invalidateLayerData(e,t){this._allTiles.forAll((i=>i.removeLayerAgent(e,t))),this._allTiles.forAll((i=>i.invalidateLayerData(e,t)))}setTileTreeDirty(){this._allTilesDirty=!0}requestRender(e=$e.UPDATE){this.renderer.setNeedsRender(e)}requestUpdate(){1==++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||xe(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.lij[0],e.lij[1],e.lij[2],{...r,timeout:6e3}).then((()=>--this._asyncWorkItems)).catch((t=>{throw--this._asyncWorkItems,_(t)||this._dataMissing(e,i,s,{notInTilemap:!0}),t})).then((()=>this._frameTask.schedule((()=>this._requestTileData(e,i,s,r)),r.signal))))}_requestTileData(e,t,i,r){return t===ae.ELEVATION?De(i)?this._requestElevationTileData(e,i,r):Promise.reject():Se(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{if(m(i))return;const s=this._layerIndexByUid[ae.ELEVATION].get(t.uid);null!=s?(this._usedMemory=null,this.requestUpdate(),this._elevationDataArrived(e,s,r)):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer %d %s",ae.ELEVATION,e.lij.toString())},s=i=>{_(i)||(this._dataMissing(e,ae.ELEVATION,t,i),this.requestUpdate())};if(Ce(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],{noDataValue:_e,signal:i.signal}).then((e=>{if(!m(i))return this._frameTask.schedule((()=>r(e)),i.signal,s);l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true.")}),s).finally((()=>{--this._asyncWorkItems}));const a=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);return this._elevationDataRequester.request(a,"binary",i).then((e=>this._lercDecoder.decode(e,{noDataValue:_e},i.signal))).then((e=>{e?r({values:e.pixelData,width:e.width,height:e.height,noDataValue:e.noDataValue,minValue:e.minValue,maxValue:e.maxValue}):s(new Error("LERC decoding failed"))}),s).finally((()=>{--this._asyncWorkItems}))}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{--this._asyncWorkItems,Ue(s),m(i)||(this._dataMissing(e,ae.MAP,t,r),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule((()=>{--this._asyncWorkItems,this.requestUpdate(),m(i)?Ue(r):this._mapTileDataArrived(e,t,r)}),i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule((()=>r(e,t)));if(xe(t)){const r=t.schemaHelper.getLevelRowColumn(e.lij);return t.fetchTile(r[0],r[1],r[2],i).then(a,n)}if(Pe(t))return t.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then(a,n);if(be(t)&&Ce(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then((e=>{if(m(i))return l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true."),void n(T());a(e)}),n);let o=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);G(t.layer)&&t.layer.refreshTimestamp&&(o+=`${o.includes("?")?"&":"?"}_ts=${t.layer.refreshTimestamp}`);const h=t.hasMixedImageFormats?"image+type":"image";return this._mapDataRequester.request(o,h,i).then(a,n)}_mapTileDataArrived(e,t,i){const r=this._getLayerIdxByUID(ae.MAP,t.uid);u(r)?e.dataArrived(r,ae.MAP,i):(Ue(i),l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer"))}_getLayerIdxByUID(e,t){return this._layerIndexByUid[e].get(t)}_dataMissing(e,t,i,r){const s=this._getLayerIdxByUID(t,i.uid);u(s)?e.dataMissing(s,t,r):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer")}updateTileOverlayParams(e){this.rootTiles&&this.overlayManager&&(this._allTiles.forAll((e=>{e.renderData&&this.overlayManager.setTileParameters(e)})),this._renderer.setNeedsRender(e))}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll((t=>{t.isLeaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))})),e}getUsedMemory(){return this.tilingScheme?(p(this._usedMemory)&&(this._usedMemory=this._recalculateUsedMemory()),u(this._usedMemory)?this._usedMemory:0):0}_recalculateUsedMemory(){return this.tilingScheme?this._allTiles.reduce(((e,t)=>e+t.usedMemory),0):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this._getLayerIdxByUID(i,e.uid);return u(r)&&this._allTiles.forAll((e=>t+=e.getUsedMemoryForLayer(i,r))),t}getTile(e){if(p(e)||p(this.rootTiles))return null;const t=e.split("/").map((e=>+e));if(0===t[0])return this.rootTiles.find((e=>e.lij[1]===t[1]&&e.lij[2]===t[2]));const i=2**t[0],r=Math.floor(t[1]/i),s=Math.floor(t[2]/i);let a;if(this.rootTiles.some((e=>e.lij[1]===r&&e.lij[2]===s&&(a=e,!0))),a){let e=1<<t[0]-1;for(;a.lij[0]<t[0];){let i=t[1]&e?2:0;if((t[2]&e)>0&&i++,!a.children[i])return null;a=a.children[i],e>>=1}return fe(a.lij[0]===t[0]&&a.lij[1]===t[1]&&a.lij[2]===t[2],"not the right tile?"),a}return null}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get visualizeNormals(){return this._renderer.visualizeNormals}set visualizeNormals(e){this._renderer.visualizeNormals=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){const e=this;return{renderer:e._renderer,lercDecoder:e._lercDecoder,forceReload:()=>{u(e.rootTiles)&&(e._mergeTile(e.rootTiles[0]),e._viewChangeUpdate())},getTiles:()=>e._allTiles.toArray(),getRenderedTiles(){ht.clear(),e._allTiles.forAll((e=>{e.visible&&e.rendered&&ht.push(e)}));const t=ht.toArray();return He(e.renderOrder,t),t},lockTilingScheme(t,i){e._extentHelper.defaultTiledLayersExtent=i,e.tilingSchemeLogic.test.lockTilingScheme(t)}}}checkAllTilesWaterproofness(){if(!je)return;const e=this.rootTiles;if(p(e))return;const t=e=>e?.renderData?.geometryInfo?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometryInfo&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometryInfo||(e.renderData.geometryInfo.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometryInfo),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.isLeaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.isLeaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get shading(){return this.view?.map?.ground?.shading}_updateShading(){const e=this.view?.map?.ground?.shading;e!==this.renderer?.shading&&(this._updateAllTileGeometries(),this.renderer&&(this.renderer.shading=e,this.renderer.setNeedsRender()))}get isWebMercator(){return!!this.tilingScheme?.spatialReference.isWebMercator}get isWebMercatorOnPlateeCarree(){return this.isWebMercator&&q(this.view?.renderSpatialReference)}isEastEndWrap(e){return this.isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this.isGlobal&&0===e[2]}lijEastEnd(e){return 2**(e+(u(this.spatialReference)&&this.spatialReference.isGeographic?1:0))}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this.isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Ae(e)}enableWaterproofnessChecks(e){Ie(e)}};e([S()],tt.prototype,"_renderer",void 0),e([S()],tt.prototype,"_hasPendingUpdates",void 0),e([S()],tt.prototype,"_asyncWorkItems",void 0),e([S()],tt.prototype,"_allTilesDirty",void 0),e([S()],tt.prototype,"_allTilesSorted",void 0),e([S()],tt.prototype,"_viewChanged",void 0),e([S({readOnly:!0})],tt.prototype,"_watchUpdatingTracking",void 0),e([S()],tt.prototype,"_frameTask",void 0),e([S({readOnly:!0})],tt.prototype,"snapLevel",null),e([S({readOnly:!0})],tt.prototype,"lodSnapping",null),e([S({constructOnly:!0})],tt.prototype,"view",void 0),e([S()],tt.prototype,"_userClippingExtent",null),e([S()],tt.prototype,"_rootTilesExtent",void 0),e([S({readOnly:!0})],tt.prototype,"extent",null),e([S({readOnly:!0})],tt.prototype,"groundExtent",null),e([S({readOnly:!0})],tt.prototype,"_tilingSchemeExtent",null),e([S({readOnly:!0})],tt.prototype,"updating",null),e([S(J)],tt.prototype,"updatingProgress",void 0),e([S({readOnly:!0})],tt.prototype,"updatingProgressValue",null),e([S()],tt.prototype,"_maxNumUpdating",void 0),e([S()],tt.prototype,"baseOpacity",null),e([S()],tt.prototype,"hasCompositeBlendMode",void 0),e([S({readOnly:!0})],tt.prototype,"overlayManager",void 0),e([S({readOnly:!0})],tt.prototype,"viewingMode",null),e([S()],tt.prototype,"maxTextureScale",void 0),e([S({readOnly:!0})],tt.prototype,"ready",null),e([S({value:he.FRONT_TO_BACK})],tt.prototype,"renderOrder",null),e([S({readOnly:!0})],tt.prototype,"rootTiles",void 0),e([S({readOnly:!0})],tt.prototype,"spatialReference",null),e([S({type:t})],tt.prototype,"backgroundColor",null),e([S({value:!1})],tt.prototype,"slicePlaneEnabled",null),e([S({readOnly:!0})],tt.prototype,"tilingScheme",void 0),e([S({readOnly:!0})],tt.prototype,"tilingSchemeLocked",null),e([S({readOnly:!0})],tt.prototype,"tilingSchemeLogic",void 0),e([S({value:!0})],tt.prototype,"velvetOverground",null),e([S()],tt.prototype,"wireframe",null),e([S({value:!1})],tt.prototype,"suspended",null),e([S()],tt.prototype,"textureFadeDuration",null),e([S()],tt.prototype,"visibleElevationBounds",void 0),e([S()],tt.prototype,"rootTileElevationBounds",void 0),e([S()],tt.prototype,"_layerViewsDirty",void 0),e([S()],tt.prototype,"renderPatchBorders",null),e([S()],tt.prototype,"visualizeNormals",null),e([S()],tt.prototype,"renderingDisabled",null),tt=e([L("esri.views.3d.terrain.TerrainSurface")],tt);const it=tt;function rt(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function st(e){return!e.isLeaf&&(e.children.some((e=>e.shouldLoad))||e.children.some((e=>st(e))))}function at(e){return e.isLeaf&&e.parent&&e.parent.shouldLoad}const nt=P(),lt=j(),ot=[0,0,0],ht=new g,dt={spatialReference:null,extent:j(),context:"ground"},pt={spatialReference:null,extent:null,scale:0};export{it as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import a from"../../../core/Evented.js";import n from"../../../core/Handles.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{releaseMaybe as h,destroyMaybe as d,isNone as p,isSome as u}from"../../../core/maybe.js";import c from"../../../core/ObjectPool.js";import g from"../../../core/PooledArray.js";import{isAbortError as _,isAborted as m,createAbortError as T}from"../../../core/promiseUtils.js";import{watch as f,syncAndInitial as y,sync as v,initial as w}from"../../../core/reactiveUtils.js";import{property as S}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as L}from"../../../core/accessorSupport/decorators/subclass.js";import{m as E}from"../../../chunks/mat4.js";import{c as D}from"../../../chunks/mat4f64.js";import{c as x}from"../../../chunks/vec3.js";import{c as C}from"../../../chunks/vec3f64.js";import{c as P}from"../../../chunks/vec4f64.js";import{WatchUpdatingTracking as U}from"../../../core/support/WatchUpdatingTracking.js";import{projectVectorToVector as b,projectPointToVector as R}from"../../../geometry/projection.js";import{getReferenceEllipsoid as M}from"../../../geometry/projectionEllipsoid.js";import{create as j,equals as A,intersection as I,empty as V,expand as O,intersectsSphere as k}from"../../../geometry/support/aaBoundingRect.js";import{create as B,copy as N}from"../../../geometry/support/frustum.js";import{isPlateCarree as q}from"../../../geometry/support/spatialReferenceUtils.js";import{isRefreshableLayer as G}from"../../../layers/mixins/RefreshableLayer.js";import{ElevationQueryTileCache as F}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as W}from"../../../layers/support/layerUtils.js";import{acquireDecoder as H}from"../../../layers/support/LercDecoder.js";import{printAllocations as z}from"../../2d/engine/vectorTiles/VectorTile.js";import{directionToHeadingTilt as Q,scaleToZoom as X}from"../support/cameraUtils.js";import Y from"../support/debugFlags.js";import{toBoundingRect as $}from"../support/extentUtils.js";import{ClientType as K}from"../support/index.js";import{updatingProgress as J}from"../support/updatingProperties.js";import{ElevationBounds as Z}from"./ElevationBounds.js";import{sampleElevation as ee,ElevationData as te}from"./ElevationData.js";import{create as ie}from"./ExtentHelper.js";import{LODSnapping as re,TextureUpdate as se}from"./interfaces.js";import{LayerClass as ae,LayerClasses as ne}from"./LayerClass.js";import{OverlayManager as le}from"./OverlayManager.js";import{PlanarPatch as oe}from"./PlanarPatch.js";import{RenderOrder as he}from"./RenderOrder.js";import{SphericalPatch as de}from"./SphericalPatch.js";import{MAX_ROOT_TILES as pe,TOO_MANY_ROOT_TILES_AFTER_CHANGE_ERROR as ue,TOO_MANY_ROOT_TILES_FOR_LAYER_ERROR as ce,MAX_MEMORY_LOD_BIAS as ge,ELEVATION_NODATA_VALUE as _e}from"./TerrainConst.js";import me from"./TerrainRenderer.js";import Te from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as fe,internalAssert as ye,oppositeEdge as ve,isSurfaceLayerView as we,isMapTileLayerView as Se,isBlendableLayerView as Le,isGroupLayer as Ee,isElevationLayerView as De,isVectorTileLayerView as xe,useFetchTileForLayer as Ce,isImageryTileLayerView as Pe,isTileLayerView as Ue,releaseTileData as be,neighborEdgeIndices as Re,ENABLE_TERRAIN_INTERNAL_CHECKS as Me,ENABLE_WATERPROOFNESS_TESTS as je,enableTerrainInternalChecks as Ae,enableTerrainWaterproofnessChecks as Ie}from"./terrainUtils.js";import{SplitLimits as Ve,Tile as Oe}from"./Tile.js";import{printAllocations as ke}from"./TilePerLayerInfo.js";import{TileUpdate as Be}from"./TileUpdate.js";import{IteratorPreorder as Ne,IteratorPostorder as qe,compareTilesByLij as Ge,hasLoadableSiblings as Fe,sortTilesByPOI as We,sortTiles as He}from"./tileUtils.js";import{TilingSchemeLogic as ze}from"./TilingSchemeLogic.js";import{UpsampleInfo as Qe}from"./UpsampleInfo.js";import{isCompositeBlendMode as Xe,blendModeFromString as Ye}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{RenderRequestType as $e}from"../webgl-engine/lib/basicInterfaces.js";import{ImmediateTask as Ke,TaskPriority as Je,noBudget as Ze}from"../../support/Scheduler.js";const et=.25;let tt=class extends(a.EventedMixin(i)){constructor(e){super(e),this._iteratorPool=new c(Ne,(e=>e.remove=()=>this._iteratorPool.release(e))),this._postorderIterator=new qe,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._visibleCached=!1,this._usedMemory=null,this._performanceInfo=new Te,this._viewChanged=!1,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=C(),this._eyePosSurfaceSR=C(),this._splitLimits=new Ve,this._snapLevel=1/0,this._frustum=B(),this._viewProjectionMatrix=D(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._handles=new n,this._watchUpdatingTracking=new U,this._frameTask=Ke,this._allTiles=new g,this._upsampleInfoPool=new c(Qe),this._rootTilesExtent=j(),this._maxNumUpdating=1,this.maxTextureScale=1.2,this.visibleElevationBounds=new Z(1/0,-1/0),this.rootTileElevationBounds=new Z(1/0,-1/0),this._updatingRootTiles=!1,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this.shortBatches=!1,this._layerViewsDirty=!1,this._isGlobal=!e.view?.state?.isLocal}initialize(){this._lercDecoder=H(this.view.resourceController),this._tilePool=this.view.state.isLocal?new c(oe):new c(de);const e=this.view.resourceController.memoryController;this._upsampleMapCache=e.newCache("esri.views.3d.terrain.upsample",(e=>e.unloadMapData())),this._elevationQueryCache=new F(e.newCache("elevation-query")),this._set("overlayManager",new le({surface:this})),this._handles.add([f((()=>this.overlayManager.hasHighlights),(e=>this._renderer.setNeedsHighlight(e))),f((()=>this.overlayManager.rendersOccluded),(e=>this._renderer.setRenderOccludedOverlay(e)))],"overlayManager"),this._renderer=new me({_overlayRenderer:this.overlayManager.renderer,_ellipsoidRadius:M(this.view.spatialReference).radius,_stage:this.view._stage,_allTiles:this._allTiles}),this._handles.add([f((()=>this.baseOpacity),(e=>{this._handleLayerViewChanges(),this._updateBaseOpacity(e)}),y),f((()=>this.hasCompositeBlendMode),(()=>{this._updateBaseOpacity(this.baseOpacity)}),y),f((()=>this.renderingDisabled),(()=>this._updateTransparentTerrain()),v),f((()=>this.backgroundColor),(e=>{this._handleLayerViewChanges(),this._renderer.updateTileBackground(e)}),y),f((()=>this.view.pointsOfInterest),(e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add((()=>e.focus.renderLocation),(()=>()=>this._allTilesSorted=!1))})),f((()=>Y.TERRAIN_TILE_TREE_SHOW_TILES),(e=>{e&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then((({TerrainTileTree3DDebugger:e})=>{!this._treeDebugger&&Y.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new e({view:this.view}))})):e||(this._treeDebugger=d(this._treeDebugger))}),w)]),this._extentHelper=ie(this.viewingMode,{layers:this.view.map.allLayers,layerViews:this.view.allLayerViews,viewSpatialReference:this.view.spatialReference});const t=this.view.defaultsFromMap?new s({getCollections:()=>this.view?.defaultsFromMap?.mapCollections?.map((({layers:e})=>e)),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}):this.view.map.allLayers,i=new ze({layers:t,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:this.view.spatialReference});this._set("tilingSchemeLogic",i),this._updateTilingScheme(),this._elevationDataRequester=this.view.resourceController.createStreamDataRequester(K.ELEVATION),this._mapDataRequester=this.view.resourceController.createStreamDataRequester(K.BASEMAP);const r=this.view.resourceController.scheduler;this._frameTask=r.registerTask(Je.TERRAIN_SURFACE,this),this._handles.add([f((()=>this._extentHelper.stencilEnabledExtents),(e=>this._renderer.setStencilEnabledLayerExtents(e)),w),f((()=>this.tilingSchemeLogic.tilingScheme),(()=>this._updateTilingScheme()),v),f((()=>this.extent),(()=>this._updateRootTiles()),w),this.view.on("resize",(()=>this._viewChangeUpdate())),f((()=>{const e=this.view,t=e.state;return[this._lodBias,this.lodSnapping,e.resourceController?.memoryController?.memoryFactor,t.camera,t.contentCamera,t.fixedContentCamera]}),(()=>this._viewChangeUpdate()),y),f((()=>this.view.qualitySettings?.tiledSurface?.textureFadeDuration),(e=>this._renderer.textureFadingEnabled=e>0),w),f((()=>this._userClippingExtent),(()=>this._updateClippingExtent()),v)]),this._handles.add(this.view.allLayerViews.on("after-changes",(()=>this._layerViewsDirty=!0))),this._handles.add([f((()=>this.view?.map.ground.shading),(()=>{this._updateShading()}))]),this._layerViewsDirty=!0,this._handleLayerViewChanges()}destroy(){this._frameTask.remove(),this._handles.destroy(),this._watchUpdatingTracking.destroy(),this._lercDecoder=h(this._lercDecoder),this._removeAllTiles(),this._upsampleMapCache=d(this._upsampleMapCache),this._elevationQueryCache=d(this._elevationQueryCache),this._set("tilingSchemeLogic",d(this.tilingSchemeLogic)),this._extentHelper=d(this._extentHelper),this._basemapLayerViewHandles.forEach(((e,t)=>this._unregisterTiledLayerView(t))),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",d(this.overlayManager)),this._tilePool=d(this._tilePool),Oe.prune(),this._treeDebugger&&(this._treeDebugger.destroy(),this._treeDebugger=null),this._renderer=d(this._renderer),this._iteratorPool=d(this._iteratorPool),this._set("view",null),this._upsampleInfoPool=d(this._upsampleInfoPool),z(),ke()}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){const e=this.view.pointsOfInterest?.contentCameraOnSurface?.scale;if(e){const t=this.view.state.contentCamera;let i=Q(this.view,t.eye,t.viewForward,t.up).tilt;i>90&&(i=180-i);const r=2*(i/90)**2,s=X(this.view,e)-r;Math.abs(this._snapLevel-s)>et&&(Math.round(s)!==Math.round(this._snapLevel)&&(this._viewChanged=!0),this._snapLevel=s)}return Math.round(this._snapLevel)}get lodSnapping(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences?re.ON:re.OFF}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get mapTileRequester(){return this._mapDataRequester}get _userClippingExtent(){const{spatialReference:e}=this,{clippingArea:t}=this.view;if(p(t)||p(e))return null;const i=j(),r=$(t,i,e)?i:null,s=this._get("extent");return A(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=I(this.groundExtent,this._userClippingExtent,j()),t=this._get("extent");return A(e,t)?t:e}get groundExtent(){return u(this._tilingSchemeExtent)?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),!!((this._watchUpdatingTracking.updating||this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||this._asyncWorkItems>0||!this._allTilesSorted||this._layerViewsDirty)&&this.ready&&!this.suspended||this.overlayManager.updating||this._frameTask.updating)}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view.map.ground.opacity}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return u(this.rootTiles)}set renderOrder(e){this._renderer.renderOrder=e,this._set("renderOrder",e)}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view.map.ground.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._updateTransparentTerrain()}_updateTransparentTerrain(){const e=!this.renderingDisabled&&!this.opaque;this.view?._stage?.renderView.setRenderParameters({transparentTerrain:e})}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}set velvetOverground(e){e!==this.velvetOverground&&(this._renderer.velvetOverground=e),this._set("velvetOverground",e)}get wireframe(){return this._renderer.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}set _visible(e){e!==this._visibleCached&&(this._visibleCached=e,this._renderer.setVisibility(e),this.suspended=!e)}get opaque(){return this._renderer.opaque}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get textureFadeDuration(){return this.view.qualitySettings.tiledSurface.textureFadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevation(e,t,i,r){const s=this.getTileWithElevation(e,t,i,r,nt);return p(s)?null:ee(nt[0],nt[1],s.renderData.geometryState.samplerData)}getTileWithElevation(e,t,i,r,s=nt){const a=this.rootTiles;if(p(a)||!a.length)return null;if(0===a[0].layerInfo[ae.ELEVATION].length)return null;if(s[0]=e,s[1]=t,s[2]=i,!b(s,r,s,this.tilingScheme?.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;for(let n of a){if(!n.containsPoint(s))continue;for(;n&&!n.rendered&&!n.isLeaf;){let e=0;s[0]>.5*(n.extent[0]+n.extent[2])&&(e+=1),s[1]<.5*(n.extent[1]+n.extent[3])&&(e+=2),n=n.children[e]}const e=n.renderData;return(e?e.geometryState.samplerData:null)?n:null}return null}getScale(e){if(this.tilingScheme){if(!R(e,nt,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this.rootTiles;if(u(t))for(let e of t)if(e?.containsPoint(nt)){for(;!e.isLeaf&&!e.rendered;){let t=0;nt[0]>e.children[0].extent[2]&&(t+=1),nt[1]<e.children[0].extent[1]&&(t+=2),e=e.children[t]}return this._getLodBiasCorrectedScale(e.level)}}return 1e100}getSphereElevationBounds(e,t,i,r,s){if(nt[0]=e,nt[1]=t,nt[2]=i,nt[3]=r,!b(nt,s,nt,this.tilingScheme?.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;let a=1/0,n=-1/0;const o=e=>{if(e&&k(e.extent,nt))if(e.isLeaf||e.rendered)a=Math.min(a,e.elevationBounds[0]),n=Math.max(n,e.elevationBounds[1]);else for(const t of e.children)o(t)},h=this.rootTiles;if(u(h))for(const l of h)o(l);return{min:a,max:n}}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!R(e,nt,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;nt[3]=t;let i=null;const r=e=>{if(e&&k(e.extent,nt))if(e.isLeaf||e.rendered){const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}else for(const t of e.children)r(t)},s=this.rootTiles;if(u(s))for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._renderer.queryVisibleLevelRange(e,s+n,a+n,r)}_updateBaseOpacity(e){const t=this._renderer.opaque;this._renderer.opaque=e>=1&&!this.hasCompositeBlendMode,this._renderer.isTransparent=this._allSurfaceLayersTransparent();const i=t!==this._renderer.opaque;i&&this._updateTransparentTerrain(),this._updateTileTextures(i?se.UNFADED:se.IMMEDIATE)}_updateTilingScheme(){const e=this.tilingSchemeLogic.tilingScheme;e!==this.tilingScheme&&(fe(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles(),this._set("tilingScheme",e),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.setTileSize(e.pixelSize),this.overlayManager.setSpatialReference(e.spatialReference),this._updateRootTiles()))}_acquireTile(e,t,i,r){const s=this._tilePool.acquire();return ot[0]=e,ot[1]=t,ot[2]=i,s.init(ot,r,this),s}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=lt;let s=t.rootTilesInExtent(e,i,5*pe);if(u(this.rootTiles)){if(s.length>pe)return void l.getLogger(this.declaredClass).warn(ue);const e=this.rootTiles.map((e=>e.lij)),t=r(e,s,rt);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this.rootTiles.filter((e=>!(t.removed.findIndex((t=>rt(t,e.lij)))>-1)||(this._purgeTile(e),!1)));t.added.forEach((t=>e.push(this._newRootTile(t)))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>pe&&(l.getLogger(this.declaredClass).warn(ce),s=t.rootTilesInExtent(e,i,pe)),this._setRootTiles(s.map((e=>this._newRootTile(e))));A(i,this._rootTilesExtent)||(this._rootTilesExtent=j(i)),this._visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter((e=>e.isLoaded&&e.intersectsClippingArea));e.forEach((e=>this._renderer.updateTileGeometryState(e))),e.forEach((e=>e.renderData.updateNeighborData())),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Ge);const t=this.renderer;e.forEach((e=>t.updateGeometryIfNeeded(e)))}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return t.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Be.SPLIT&&t.setPendingUpdate(Be.SPLIT),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationBounds(),t}_setRootTiles(e){if(this._set("rootTiles",e),this._allTiles.clear(),u(e)){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this.rootTiles),this._updateTilesVisibility(e)}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this._visibleCached&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this.rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(Be.GEOMETRY)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(p(e))return;const t=Fe(e),i=this.visibleElevationBounds;let r=t?i.min:1/0,s=t?i.max:-1/0;const a=this.extent,n=this._viewProjectionMatrix;this.setTileTreeDirty();const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(Be.GEOMETRY)&&this._updateTileGeometryState(e),e.setPendingUpdate(Be.RENDERDATA),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBounds[0],r),s=Math.max(e.elevationBounds[1],s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._batchUpdatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.min!==r||i.max!==s)&&(this.visibleElevationBounds=new Z(r,s))}_updateRootTileElevationBounds(){let e=1/0,t=-1/0;const i=this.rootTiles;u(i)&&i.forEach((({elevationBounds:i})=>{e=Math.min(e,i[0]),t=Math.max(t,i[1])}));const r=this.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new Z(e,t))}_updateViewDependentParameters(){const e=this.view.state.camera,t=this.view.state.contentCamera,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?(p(this._splitLimits.frustum)&&(this._splitLimits.frustum=B()),N(this._splitLimits.frustum,t.frustum)):this._splitLimits.frustum=null,N(this._frustum,e.frustum),E(this._viewProjectionMatrix,t.projectionMatrix,t.viewMatrix),x(this._eyePosRenderSR,t.eye),b(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateRenderData(e){e.rendered&&!e.shouldLoad&&(st(e)?this._loadChildren(e):at(e)&&this._loadParent(e))}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this._usedMemory=null}_markAllTileNeighborsForGeometryUpdate(e){const t=this._pendingTilesToUpdate;e.forEachLoadedNeighbor((e=>{t.add(e)}))}_updateTileTexture(e,t){const i=e.resetPendingUpdate(Be.TEXTURE_FADING)?Be.TEXTURE_FADING:!!e.resetPendingUpdate(Be.TEXTURE_NOFADING)&&Be.TEXTURE_NOFADING;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(e){const t=dt.extent;V(t);const i=e.length;for(let r=0;r<i;r++)O(t,e[r].extent,t);dt.spatialReference=this.spatialReference,this.emit("elevation-change",dt)}get running(){return this.updating&&this.ready&&!this.suspended}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),e.run((()=>this._updateElevation(e))),e.run((()=>this._updateTextures(e))),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),e.done?this.requestUpdate():this.getUsedMemory(),this.notifyChange("updatingProgressValue")}_updateAllTilesStatus(e){if(!this._viewChanged||!this.rootTiles||e.done)return;this._viewChanged=!1;const t=this._iteratorPool.acquire();for(t.reset(this.rootTiles);!t.done;){const e=t.next(),i=e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping);if(i!==Be.SPLIT){if(e.resetPendingUpdate(Be.SPLIT)&&e.updateAgentSuspension(),i===Be.VSPLITMERGE&&e.updateAgents(ae.ELEVATION),t.skipSubtree(),!e.isLeaf){e.setPendingUpdate(Be.MERGE),e.resetPendingUpdate(Be.SPLIT);const t=this._iteratorPool.acquire();t.resetOne(e);for(let e=t.next();!t.done;e=t.next())this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(this._viewProjectionMatrix);t.remove()}}else e.resetPendingUpdate(Be.MERGE),e.isLeaf&&(e.setPendingUpdate(Be.SPLIT),t.skipSubtree()),e.rendered&&e.setPendingUpdate(Be.RENDERDATA)}t.remove(),this.requestUpdate(),this._batchUpdatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||(We(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_markTileToUpdate(e,t=!0){ye(e.isLoaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),t&&this._markAllTileNeighborsForGeometryUpdate(e))}_batchUpdatePendingTileGeometries(){const e=this._pendingTilesToUpdate;if(0===e.size)return;const t=[];e.forEach((e=>{e.isLoaded&&e.intersectsClippingArea&&t.push(e)}));const i=(i,r)=>{!r?.isLoaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Ge);const r=t.length;for(let s=0;s<r;++s){const r=t[s];ye(r.isLoaded),ye(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a._dirtyEdgeResolutions,l=a.geometryState.neighborData;for(let t=0;t<4;++t)if(n&1<<t){const s=r.renderData.geometryState.neighborData.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(ve(Re[t]),(t=>!(!t.isLoaded||!t.intersectsClippingArea)&&(ye(e.has(t)||Ge(r,t)<0),i(r,t),!0))),i(r,l.cornerPeerNeighbors[t]),i(r,l.cornerPeerNeighbors[(t+1)%4])}}e.clear(),this._updateTilesGeometries(t),this._emitElevationUpdateEventForTiles(t),Me&&je&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1,r=!1;for(;!e.done;){r=!0;let s=!1;const a=!this._allTiles.some((r=>{if(!i&&!r.loadable)return e.done;let a=r;if(r.resetPendingUpdate(Be.MERGE)){if(!t)return r.setPendingUpdate(Be.MERGE),e.done;for(;a.parent?.resetPendingUpdate(Be.MERGE);)a=a.parent;this._mergeTile(a),s=!0,e.madeProgress()}else r.resetPendingUpdate(Be.SPLIT)&&(this._splitTile(r),s=!0,e.madeProgress());return!e.done&&a===r&&r.resetPendingUpdate(Be.RENDERDATA)&&(this._updateRenderData(r),e.madeProgress()),e.done}));if(s&&(this._allTilesSorted=!1,this._allTilesDirty=!0),a){if(!i){i=!0;continue}if(!s)break}else this._allTilesDirty=!0}r||(this._allTilesDirty=!0),this._batchUpdatePendingTileGeometries(),this._sortTiles(e)}_updateElevation(e){return this._allTiles.some((t=>(t.resetPendingUpdate(Be.GEOMETRY)&&(this._updateTileGeometryState(t),this._updateTileTexture(t,e),e.madeProgress()),e.done))),this._batchUpdatePendingTileGeometries(),e.hasProgressed}_updateTextures(e){return this._allTiles.some((t=>(this._updateTileTexture(t,e),e.done))),e.hasProgressed}_updateClippingExtent(){this.spatialReference&&(this.updateTileOverlayParams($e.UPDATE),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.resourceController.memoryController.memoryFactor;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*ge}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){u(this.rootTiles)&&(this.rootTiles.forEach((e=>this._purgeTile(e))),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this._visible=!1}_purgeDescendantTiles(e){if(e.isLeaf)return!1;let t=!1;for(let i=0;i<4;++i)t=this._purgeTile(e.children[i])||t;return e.unsetChildren(),t}_purgeTile(e){const t=this._purgeDescendantTiles(e)||e.rendered;return this._allTiles.removeUnordered(e),this._unloadTile(e),this._tilePool.release(e),t}_unloadTile(e){this._pendingTilesToUpdate.delete(e),e.unload(this._renderer)}_splitTile(e){fe(e.isLeaf,"tile that is already split should not be split again!");const t=e.level+1,i=2*e.lij[1],r=2*e.lij[2];e.setChildren(this._createTile(t,i,r,e),this._createTile(t,i,r+1,e),this._createTile(t,i+1,r,e),this._createTile(t,i+1,r+1,e)),e.setPendingUpdate(Be.RENDERDATA),e.updateAgentSuspension(),this._allTiles.pushArray(e.children),this._allTilesDirty=!0,++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){pt.spatialReference=this.spatialReference,pt.extent=e.extent,pt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",pt)}_createTile(e,t,i,r){fe(!!r,"_createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this._viewProjectionMatrix),s.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Be.SPLIT&&s.setPendingUpdate(Be.SPLIT),s}_mergeTile(e){fe(!e.hasPendingUpdate(Be.SPLIT),"_mergeTile sanity check"),this._purgeDescendantTiles(e)&&(fe(!e.renderData,"_mergeTile sanity check"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this.shortBatches&&this._batchUpdatePendingTileGeometries()),this._allTilesDirty=!0,++this._performanceInfo.numMerged}_loadChildren(e){fe(e.rendered,"parent should be rendered"),this._unloadTile(e);const t=e.children;t.forEach((e=>this._loadTile(e))),t.forEach((e=>this._pendingTilesToUpdate.add(e))),this._markAllTileNeighborsForGeometryUpdate(e),this._emitTileScaleChange(e,e.level+1),this.shortBatches&&this._batchUpdatePendingTileGeometries()}_loadParent(e){const t=e.parent;this._unloadChildren(t),this._loadTile(t),this._markTileToUpdate(t),this._emitTileScaleChange(t,t.level),this.shortBatches&&this._batchUpdatePendingTileGeometries()}_unloadChildren(e){if(!e.isLeaf)for(let t=0;t<4;++t){const i=e.children[t];this._unloadChildren(i),this._unloadTile(i)}}_loadTile(e){e.load(),e.setPendingUpdate(Be.RENDERDATA),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager&&this.overlayManager.hasOverlays&&this.overlayManager.setTileParameters(e)}_elevationDataArrived(e,t,i){const r=new te(e.lij,e.extent,i);e.dataArrived(t,ae.ELEVATION,r);const s=[e],a=e.level,n=this._iteratorPool.acquire();for(n.reset(s);!n.done;){const e=n.next();e.findElevationBoundsForLayer(t,a),e.computeElevationBounds()}0===a&&this._updateRootTileElevationBounds(),n.remove(),this._updateTilesVisibility(s)}_handleLayerViewChanges(e=Ze){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(const s of this.view.allLayerViews.items)if(i.add(s.uid),we(s))if(this._basemapLayerViewHandles.has(s.uid)){const e=this._layerClassFromLayerView(s),i=this._getLayerIdxByUID(e,s.uid);u(i)&&((i<r||p(r))&&(t=!0),r=i)}else this._registerTiledLayerView(s),s.layer.loaded&&(t=!0);this._basemapLayerViewHandles.forEach(((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)})),t&&this._updateTiledLayers(),this._renderer.isTransparent=this._allSurfaceLayersTransparent(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),e.madeProgress()}_allSurfaceLayersTransparent(){let e=0===this.view.map?.ground?.opacity;for(const t of this.view.allLayerViews.items)if(Se(t)&&!W(t.layer)&&0!==t.fullOpacity)return e=!1,e;return e}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if(Le(e)){const t=Ee(e.layer.parent)?"normal":e.layer.blendMode;if(Xe(Ye[t]))return!0}return!1}_layerClassFromLayerView(e){return De(e)?ae.ELEVATION:ae.MAP}_registerTiledLayerView(e){const t=[],i=this._layerClassFromLayerView(e);t.push(f((()=>e.suspended),(()=>this._updateTiledLayers()))),t.push(f((()=>e.fullOpacity),(()=>this._updateTileTextures(se.UNFADED)))),t.push(f((()=>"effectiveScaleRange"in e.layer?e.layer.effectiveScaleRange:null),(()=>this._restartAllAgents(i)))),Le(e)&&t.push(f((()=>e.layer.blendMode),(()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(se.UNFADED)}))),e.on("data-changed",(()=>{const t=this._getLayerIdxByUID(i,e.uid);u(t)&&this._invalidateLayerData(t,i)})),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(let e=0;e<t.length;e++)t[e].remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach((e=>{if(!e.layer||e.suspended||!we(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(r===ae.MAP){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)}));for(const r of ne){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this.rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this.rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&this._viewChangeUpdate()}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this.rootTiles);!t.done;){const i=t.next();i.restartAgents(e),e===ae.ELEVATION&&i.computeElevationBounds()}this._updateRootTileElevationBounds()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll((t=>{t.updateAgents(ae.MAP),e===se.IMMEDIATE?this.renderer.updateTileTexture(t,Be.TEXTURE_NOFADING):t.updateRenderData(ae.MAP,e)})),this._renderer.isTransparent=this._allSurfaceLayersTransparent()}_invalidateLayerData(e,t){this._allTiles.forAll((i=>i.removeLayerAgent(e,t))),this._allTiles.forAll((i=>i.invalidateLayerData(e,t)))}setTileTreeDirty(){this._allTilesDirty=!0}requestRender(e=$e.UPDATE){this.renderer.setNeedsRender(e)}requestUpdate(){1==++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||xe(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.lij[0],e.lij[1],e.lij[2],{...r,timeout:6e3}).then((()=>--this._asyncWorkItems)).catch((t=>{throw--this._asyncWorkItems,_(t)||this._dataMissing(e,i,s,{notInTilemap:!0}),t})).then((()=>this._frameTask.schedule((()=>this._requestTileData(e,i,s,r)),r.signal))))}_requestTileData(e,t,i,r){return t===ae.ELEVATION?De(i)?this._requestElevationTileData(e,i,r):Promise.reject():Se(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{if(m(i))return;const s=this._layerIndexByUid[ae.ELEVATION].get(t.uid);null!=s?(this._usedMemory=null,this.requestUpdate(),this._elevationDataArrived(e,s,r)):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer %d %s",ae.ELEVATION,e.lij.toString())},s=i=>{_(i)||(this._dataMissing(e,ae.ELEVATION,t,i),this.requestUpdate())};if(Ce(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],{noDataValue:_e,signal:i.signal}).then((e=>{if(!m(i))return this._frameTask.schedule((()=>r(e)),i.signal,s);l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true.")}),s).finally((()=>{--this._asyncWorkItems}));const a=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);return this._elevationDataRequester.request(a,"binary",i).then((e=>this._lercDecoder.decode(e,{noDataValue:_e},i.signal))).then((e=>{e?r({values:e.pixelData,width:e.width,height:e.height,noDataValue:e.noDataValue,minValue:e.minValue,maxValue:e.maxValue}):s(new Error("LERC decoding failed"))}),s).finally((()=>{--this._asyncWorkItems}))}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{--this._asyncWorkItems,be(s),m(i)||(this._dataMissing(e,ae.MAP,t,r),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule((()=>{--this._asyncWorkItems,this.requestUpdate(),m(i)?be(r):this._mapTileDataArrived(e,t,r)}),i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule((()=>r(e,t)));if(xe(t)){const r=t.schemaHelper.getLevelRowColumn(e.lij);return t.fetchTile(r[0],r[1],r[2],i).then(a,n)}if(Pe(t))return t.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then(a,n);if(Ue(t)&&Ce(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then((e=>{if(m(i))return l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true."),void n(T());a(e)}),n);let o=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);G(t.layer)&&t.layer.refreshTimestamp&&(o+=`${o.includes("?")?"&":"?"}_ts=${t.layer.refreshTimestamp}`);const h=t.hasMixedImageFormats?"image+type":"image";return this._mapDataRequester.request(o,h,i).then(a,n)}_mapTileDataArrived(e,t,i){const r=this._getLayerIdxByUID(ae.MAP,t.uid);u(r)?e.dataArrived(r,ae.MAP,i):(be(i),l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer"))}_getLayerIdxByUID(e,t){return this._layerIndexByUid[e].get(t)}_dataMissing(e,t,i,r){const s=this._getLayerIdxByUID(t,i.uid);u(s)?e.dataMissing(s,t,r):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer")}updateTileOverlayParams(e){this.rootTiles&&this.overlayManager&&(this._allTiles.forAll((e=>{e.renderData&&this.overlayManager.setTileParameters(e)})),this._renderer.setNeedsRender(e))}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll((t=>{t.isLeaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))})),e}getUsedMemory(){return this.tilingScheme?(p(this._usedMemory)&&(this._usedMemory=this._recalculateUsedMemory()),u(this._usedMemory)?this._usedMemory:0):0}_recalculateUsedMemory(){return this.tilingScheme?this._allTiles.reduce(((e,t)=>e+t.usedMemory),0):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this._getLayerIdxByUID(i,e.uid);return u(r)&&this._allTiles.forAll((e=>t+=e.getUsedMemoryForLayer(i,r))),t}getTile(e){if(p(e)||p(this.rootTiles))return null;const t=e.split("/").map((e=>+e));if(0===t[0])return this.rootTiles.find((e=>e.lij[1]===t[1]&&e.lij[2]===t[2]));const i=2**t[0],r=Math.floor(t[1]/i),s=Math.floor(t[2]/i);let a;if(this.rootTiles.some((e=>e.lij[1]===r&&e.lij[2]===s&&(a=e,!0))),a){let e=1<<t[0]-1;for(;a.lij[0]<t[0];){let i=t[1]&e?2:0;if((t[2]&e)>0&&i++,!a.children[i])return null;a=a.children[i],e>>=1}return fe(a.lij[0]===t[0]&&a.lij[1]===t[1]&&a.lij[2]===t[2],"not the right tile?"),a}return null}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get visualizeNormals(){return this._renderer.visualizeNormals}set visualizeNormals(e){this._renderer.visualizeNormals=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){const e=this;return{renderer:e._renderer,lercDecoder:e._lercDecoder,forceReload:()=>{u(e.rootTiles)&&(e._mergeTile(e.rootTiles[0]),e._viewChangeUpdate())},getTiles:()=>e._allTiles.toArray(),getRenderedTiles(){ht.clear(),e._allTiles.forAll((e=>{e.visible&&e.rendered&&ht.push(e)}));const t=ht.toArray();return He(e.renderOrder,t),t},lockTilingScheme(t,i){e._extentHelper.defaultTiledLayersExtent=i,e.tilingSchemeLogic.test.lockTilingScheme(t)}}}checkAllTilesWaterproofness(){if(!je)return;const e=this.rootTiles;if(p(e))return;const t=e=>e?.renderData?.geometryInfo?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometryInfo&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometryInfo||(e.renderData.geometryInfo.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometryInfo),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.isLeaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.isLeaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get shading(){return this.view?.map?.ground?.shading}_updateShading(){const e=this.view?.map?.ground?.shading;e!==this.renderer?.shading&&(this._updateAllTileGeometries(),this.renderer&&(this.renderer.shading=e,this.renderer.setNeedsRender()))}get isWebMercator(){return!!this.tilingScheme?.spatialReference.isWebMercator}get isWebMercatorOnPlateeCarree(){return this.isWebMercator&&q(this.view?.renderSpatialReference)}isEastEndWrap(e){return this.isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this.isGlobal&&0===e[2]}lijEastEnd(e){return 2**(e+(u(this.spatialReference)&&this.spatialReference.isGeographic?1:0))}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this.isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Ae(e)}enableWaterproofnessChecks(e){Ie(e)}};e([S()],tt.prototype,"_renderer",void 0),e([S()],tt.prototype,"_hasPendingUpdates",void 0),e([S()],tt.prototype,"_asyncWorkItems",void 0),e([S()],tt.prototype,"_allTilesDirty",void 0),e([S()],tt.prototype,"_allTilesSorted",void 0),e([S()],tt.prototype,"_viewChanged",void 0),e([S({readOnly:!0})],tt.prototype,"_watchUpdatingTracking",void 0),e([S()],tt.prototype,"_frameTask",void 0),e([S({readOnly:!0})],tt.prototype,"snapLevel",null),e([S({readOnly:!0})],tt.prototype,"lodSnapping",null),e([S({constructOnly:!0})],tt.prototype,"view",void 0),e([S()],tt.prototype,"_userClippingExtent",null),e([S()],tt.prototype,"_rootTilesExtent",void 0),e([S({readOnly:!0})],tt.prototype,"extent",null),e([S({readOnly:!0})],tt.prototype,"groundExtent",null),e([S({readOnly:!0})],tt.prototype,"_tilingSchemeExtent",null),e([S({readOnly:!0})],tt.prototype,"updating",null),e([S(J)],tt.prototype,"updatingProgress",void 0),e([S({readOnly:!0})],tt.prototype,"updatingProgressValue",null),e([S()],tt.prototype,"_maxNumUpdating",void 0),e([S()],tt.prototype,"baseOpacity",null),e([S()],tt.prototype,"hasCompositeBlendMode",void 0),e([S({readOnly:!0})],tt.prototype,"overlayManager",void 0),e([S({readOnly:!0})],tt.prototype,"viewingMode",null),e([S()],tt.prototype,"maxTextureScale",void 0),e([S({readOnly:!0})],tt.prototype,"ready",null),e([S({value:he.FRONT_TO_BACK})],tt.prototype,"renderOrder",null),e([S({readOnly:!0})],tt.prototype,"rootTiles",void 0),e([S({readOnly:!0})],tt.prototype,"spatialReference",null),e([S({type:t})],tt.prototype,"backgroundColor",null),e([S({value:!1})],tt.prototype,"slicePlaneEnabled",null),e([S({readOnly:!0})],tt.prototype,"tilingScheme",void 0),e([S({readOnly:!0})],tt.prototype,"tilingSchemeLocked",null),e([S({readOnly:!0})],tt.prototype,"tilingSchemeLogic",void 0),e([S({value:!0})],tt.prototype,"velvetOverground",null),e([S()],tt.prototype,"wireframe",null),e([S({value:!1})],tt.prototype,"suspended",null),e([S()],tt.prototype,"textureFadeDuration",null),e([S()],tt.prototype,"visibleElevationBounds",void 0),e([S()],tt.prototype,"rootTileElevationBounds",void 0),e([S()],tt.prototype,"_layerViewsDirty",void 0),e([S()],tt.prototype,"renderPatchBorders",null),e([S()],tt.prototype,"visualizeNormals",null),e([S()],tt.prototype,"renderingDisabled",null),tt=e([L("esri.views.3d.terrain.TerrainSurface")],tt);const it=tt;function rt(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function st(e){return!e.isLeaf&&(e.children.some((e=>e.shouldLoad))||e.children.some((e=>st(e))))}function at(e){return e.isLeaf&&e.parent&&e.parent.shouldLoad}const nt=P(),lt=j(),ot=[0,0,0],ht=new g,dt={spatialReference:null,extent:j(),context:"ground"},pt={spatialReference:null,extent:null,scale:0};export{it as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{clamp as e}from"../../../core/mathUtils.js";import{isSome as t,abortMaybe as i,isNone as s}from"../../../core/maybe.js";import n from"../../../core/ObjectPool.js";import{c as r,s as a}from"../../../chunks/vec2.js";import{a as o}from"../../../chunks/vec2f64.js";import{b as l,p as h,e as d,g as u,a as c,l as g}from"../../../chunks/vec3.js";import{c as f,u as p}from"../../../chunks/vec3f64.js";import{g as m}from"../../../chunks/common.js";import{getReferenceEllipsoid as _}from"../../../geometry/projectionEllipsoid.js";import{create as y,equals as A}from"../../../geometry/support/aaBoundingRect.js";import{c as v}from"../../../chunks/sphere.js";import{VectorTile as T}from"../../2d/engine/vectorTiles/VectorTile.js";import{ImageWithType as E}from"../support/StreamDataLoader.js";import{ElevationBounds as M}from"./ElevationBounds.js";import{ElevationTileAgent as I}from"./ElevationTileAgent.js";import{LODSnapping as L,TextureUpdate as D,NeighborIndex as x}from"./interfaces.js";import{LayerClasses as S,LayerClass as j}from"./LayerClass.js";import{MapTileAgent as N}from"./MapTileAgent.js";import{RasterTile as O}from"./RasterTile.js";import{MAX_PATCH_TESSELATION as b,getElevationDesiredResolutionLevel as U}from"./TerrainConst.js";import{weakAssert as C,getLayerWithExtentRange as P,isBlendableLayerView as B,oppositeCorner as R,neighborCornerIndices as G,neighborEdgeIndices as V,oppositeEdge as w,internalAssert as W,ENABLE_TERRAIN_INTERNAL_CHECKS as q,isNorth as H,isSouth as F,isWest as k,isEast as X,ENABLE_WATERPROOFNESS_TESTS as z,isWestCorner as J,isNorthCorner as Y}from"./terrainUtils.js";import{TILE_AGENT_DONE as $}from"./TileAgent.js";import{TilePerLayerInfo as Q}from"./TilePerLayerInfo.js";import K from"./TileTexture.js";import{TileUpdate as Z}from"./TileUpdate.js";import{fallsWithinLayer as ee}from"./tileUtils.js";import{getGpuMemoryUsage as te}from"../../webgl/Util.js";const ie=f(),se=f(),ne=f(),re=.1;class ae{constructor(){this.fovX=0,this.fovY=0,this.relativeWidthLimit=0,this.relativeHeightLimit=0,this.maxLod=0,this.angledSplitBias=0,this.aboveGround=!0}}class oe{constructor(){this.lij=[0,0,0],this._children=[null,null,null,null],this._pendingUpdates=0,this._dirty=!0,this._previouslyRendered=!1,this.extent=y(),this._elevationBounds=o(),this.layerInfo=[[],[]],this.extentInRadians=y(),this.centerAtSeaLevel=f(),this._center=[f(),v(),f()],this.up=p(),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._maxTesselation=0,this._usedMemory=null,this._mapTileMemoryInternal=0,this._mapDataRefCount=0,this._screenDepth=0,this.renderOrder=0,this._edgeLen=0,this._edgeLen2=0,this._curvatureHeight=0}static prune(){de.prune(0),ue.prune(0),Q.prune()}get _isCached(){return!this.shouldLoad&&this._mapDataRefCount<=0}get maxTesselation(){return this._maxTesselation}get isWithinClippingArea(){return this._isWithinClippingArea}get intersectsClippingArea(){return this._intersectsClippingArea}get clippingArea(){return this._clippingArea}get parent(){return this._parent}get children(){return this._children}get surface(){return this._surface}get elevationBounds(){return this._elevationBounds}get level(){return this.lij[0]}get key(){return`${this.lij[0]}/${this.lij[1]}/${this.lij[2]}`}get edgeLen(){return this._edgeLen}get radius(){return this._center[ge.MIDDLE][3]}get screenDepth(){return this._screenDepth}get visible(){return this._dirty&&this.computeVisibility(),this._visible}computeVisibility(){this._dirty=!1;const e=this._intersectsClippingArea&&this._isVisible(this.surface.frustum);return e!==this._visible&&(this._visible=e,this._surface.emit("tiles-visibility-changed"),this._surface.renderer.setDirty(),this.updateAgentSuspension()),this._visible}get loadable(){return this.visible||this._surface.view.state.fixedContentCamera}get rendered(){const e=!!this.renderData;return e!==this._previouslyRendered&&(this._surface.emit("tiles-visibility-changed"),this._previouslyRendered=e,this._surface.renderer.setDirty()),e}get shouldLoad(){if(this._surface.lodSnapping===L.ON){const e=this.level-this._surface.snapLevel;if(0===e)return!0;if(1===e)return!1}return this.isLeaf}init(e,t,i){this.lij[0]=e[0],this.lij[1]=e[1],this.lij[2]=e[2],this.ellipsoid=_(i.tilingScheme.spatialReference),i.tilingScheme.getExtent(e[0],e[1],e[2],this.extent),i.tilingScheme.convertExtentToRadians(this.extent,this.extentInRadians),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._clippingArea=null,this._mapDataRefCount=0,i.upsampleMapCache.pop(this.key),this._edgeLen=0,this._edgeLen2=0,this._center[ge.MIDDLE][3]=0,this.vlevel=e?e[0]:0,t&&t.elevationBounds?r(this._elevationBounds,t.elevationBounds):a(this._elevationBounds,0,0),this._pendingUpdates=0,this.renderData=null,this._screenDepth=0,this._visible=!1,this._previouslyRendered=!1,this._parent=t,this.unsetChildren(),this._surface=i,this.updateVisibility();for(const s of S){const e=i.numLayers(s),t=this.layerInfo[s];for(const i of t)i.release();t.length=e;for(let i=0;i<e;i++)t[i]=Q.acquire(this._surface.upsampleInfoPool),s===j.ELEVATION&&this.findElevationBoundsForLayer(i,-1)}this.computeElevationBounds(),this._maxTesselation=Math.min(i.tilingScheme.pixelSize,b)}release(){C(!this.renderData,"tile.renderData was not unloaded"),this._surface.upsampleMapCache.pop(this.key);for(const e of S){for(const t of this.layerInfo[e])t.release();this.layerInfo[e].length=0}this._parent=null,this._surface=null,this.setMemoryDirty()}refMapData(){++this._mapDataRefCount,this._isCached||this._surface.upsampleMapCache.pop(this.key)}unrefMapData(){if(--this._mapDataRefCount,this._isCached){this.setMemoryDirty();const e=this._cachedMemory;e>0&&this._surface.upsampleMapCache.put(this.key,this,e)}}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this._ensureUsedMemory()+(this._isCached?0:this._mapTileMemoryInternal)}get _cachedMemory(){return this._isCached?this._mapTileMemory:0}get _mapTileMemory(){return this._ensureUsedMemory(),this.layerInfo[j.MAP].reduce(((e,t)=>e+(t instanceof T?t.memoryUsage:0)),this._mapTileMemoryInternal)}get _cpuImageMemorySize(){const e=4,t=this._surface.tilingScheme.pixelSize;return t*t*e}_ensureUsedMemory(){if(t(this._usedMemory))return this._usedMemory;this._usedMemory=0,this._mapTileMemoryInternal=0;let e=0;for(const{data:t}of this.layerInfo[j.MAP])t instanceof T?e+=this._getTerrainDataMemory(t):this._mapTileMemoryInternal+=this._getTerrainDataMemory(t);const i=this._cpuImageMemorySize;for(const t of this.layerInfo[j.ELEVATION])this._usedMemory+=t.data?i:0;return this.renderData&&(this._usedMemory+=this.renderData.estimatedGeometryMemoryUsage,this._mapTileMemoryInternal+=te(this.renderData.textureDescriptor)),this._isCached&&this._surface.upsampleMapCache.updateSize(this.key,this,this._mapTileMemoryInternal+e),this._usedMemory}getUsedMemoryForLayer(e,t){const i=this.layerInfo[e][t];return i?.data?e===j.MAP?this._isCached?0:this._getTerrainDataMemory(i.data):e===j.ELEVATION?this._cpuImageMemorySize:0:0}_getTerrainDataMemory(e){return e instanceof K?te(e.texture):e instanceof HTMLImageElement||e instanceof E?this._cpuImageMemorySize:e instanceof T||e instanceof O?e.memoryUsage:0}updateScreenDepth(e){const t=this._center[ge.MIDDLE],i=e,s=t[0],n=t[1],r=t[2],a=i[2]*s+i[6]*n+i[10]*r+i[14];this._screenDepth=a<0?0:a/(i[3]*s+i[7]*n+i[11]*r+i[15])}shouldSplit(e,i,s){if(t(e.frustum)&&(!this._intersectsClippingArea||!this._isVisible(e.frustum)))return Z.NONE;if(!this.visible)return Z.NONE;const n=this.level;l(ie,this._center[ge.MIDDLE],i);let r=h(ie),a=ge.MIDDLE;l(se,this._center[ge.TOP],i);const o=h(se);o<r&&(r=o,a=ge.TOP),l(se,this._center[ge.BOTTOM],i);const f=h(se);if(f<r&&(r=f,a=ge.BOTTOM),this._edgeLen2>r&&n<e.maxLod)return Z.SPLIT;const p=Math.sqrt(r),m=e.fovX*p*2,_=this._edgeLen/m,y=()=>{const t=n+Math.ceil(-Math.log2(e.relativeWidthLimit/_));return t!==this.vlevel?(this.vlevel=t,Z.VSPLITMERGE):Z.NONE_HIT_MAXLOD};if(s===L.ON){if(1===this._surface.snapLevel-n)return n>=e.maxLod?y():Z.SPLIT}const A=d(this.up,ie),v=this._elevationBounds[1]-this._elevationBounds[0],T=v/this.edgeLen;if(e.aboveGround&&A>0&&T<.001){if(A/p-Math.sin(this._curvatureHeight/(this.edgeLen*Math.SQRT1_2)*Math.PI)-T>0)return Z.NONE}if(_<e.relativeWidthLimit)return this.vlevel!==this.level?(this.vlevel=this.level,Z.VSPLITMERGE):Z.NONE;if(n>=e.maxLod)return y();if(n>6){l(se,this._center[a],i),u(ne,this.up,A),l(ne,ne,se);const t=h(ne);if(t>this.radius*this.radius){u(ne,ne,this.radius/Math.sqrt(t)),c(ne,ne,this._center[a]),l(ne,i,ne);const s=Math.min(1,(Math.abs(d(ne,this.up))+.5*v+this._curvatureHeight)/g(ne)),n=re/e.angledSplitBias,r=e.fovY*p*2;if(s*(this._edgeLen/r)<n*e.relativeHeightLimit)return Z.NONE}}return Z.SPLIT}setChildren(e,t,i,s){C(!!(e&&t&&i&&s),"Null child passed"),this._children[0]=e,this._children[1]=t,this._children[2]=i,this._children[3]=s}unsetChildren(){this._children[0]=null,this._children[1]=null,this._children[2]=null,this._children[3]=null}get isLoaded(){return this.renderData?.hasGeometry??!1}load(){this.refMapData();for(const e of S)this._createOrUpdateAgents(0,e);this.surface.renderer.loadTile(this)}unload(e){e.unloadTile(this);for(const t of S){const e=this.layerInfo[t];for(const t of e)t.loadingAgent&&t.loadingAgent!==$&&(he(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0}this.resetPendingUpdate(Z.GEOMETRY),this.resetPendingUpdate(Z.TEXTURE_NOFADING),this.resetPendingUpdate(Z.TEXTURE_FADING),this.unrefMapData()}unloadMapData(){const e=this.layerInfo[j.MAP];for(const t of e)t.loadingAgent&&t.loadingAgent!==$&&(he(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0;this.renderData&&this.renderData.releaseTexture(),this.setMemoryDirty()}updateClippingStatus(e){if(A(e,this._clippingArea))return!1;const i=this._intersectsClippingArea,s=this._isWithinClippingArea;t(e)?(this._intersectsClippingArea=this.intersectsExtent(e),this._isWithinClippingArea=this._isWithinExtent(e)):(this._intersectsClippingArea=!0,this._isWithinClippingArea=!0),this._clippingArea=e,this.updateVisibility();const n=s&&this._isWithinClippingArea,r=!(s||i||this._isWithinClippingArea||this._intersectsClippingArea);return!this.renderData||n||r||this.setPendingUpdate(Z.GEOMETRY),!0}updateVisibility(){this._dirty=!0,this._surface.setTileTreeDirty()}getLayerInfo(e,t){return this.layerInfo[t][e]}hasLayerData(e,t){const i=this.layerInfo[t][e];return!(!i||!i.data||i.dataInvalidated)}get updating(){if(this.hasPendingUpdates)return!0;for(const e of S){const t=this.layerInfo[e];for(const e of t)if(e.loadingAgent&&e.loadingAgent!==$&&e.loadingAgent.updating)return!0}return!1}_isSuspended(e){return!!this.hasPendingUpdate(Z.SPLIT)||e!==j.ELEVATION&&!this.loadable}get hasPendingUpdates(){return 0!==this._pendingUpdates}hasPendingUpdate(e){return(this._pendingUpdates&e)===e}setPendingUpdate(e){this._pendingUpdates|=e,e===Z.SPLIT||e===Z.MERGE?this._surface.setTileTreeDirty():this._surface.requestUpdate()}resetPendingUpdate(e){return!!this.hasPendingUpdate(e)&&(this._pendingUpdates&=~e,!0)}requestLayerData(e,t,s){const n=this.layerInfo[t][e];if(n.waitingAgents.has(s))return console.warn("agent already requested this piece of map data (tile %s, agent tile %s, layer: %d/%d)",this.lij.toString(),s.tile.lij.toString(),t,e),!0;if(n.waitingAgents.push(s),n.data&&!n.dataInvalidated)return console.warn("agent requested existing data (tile %s, agent tile %s, layer: %d/%d)",this.lij.toString(),s.tile.lij.toString(),t,e),s.dataArrived(this),!0;if(n.requestPromise)return!0;i(n.requestAbort),n.requestAbort=new AbortController;const r=this._surface.requestTileData(this,e,t,n.requestAbort);if(!r)return n.requestAbort=null,!1;const a=()=>{n.requestPromise===r&&(n.requestPromise=null,n.requestAbort=null)};return n.requestPromise=r,r.then(a,a),!0}get isLeaf(){return null==this._children[0]}hasLij(e){return this.lij[0]===e[0]&&this.lij[1]===e[1]&&this.lij[2]===e[2]}findByLij(e){if(this.hasLij(e))return this;if(this.isLeaf)return null;const t=this._children[0].findByLij(e)||this._children[1].findByLij(e)||this._children[2].findByLij(e)||this._children[3].findByLij(e);return t||null}distanceToSquared(e){return h(l(ne,this._center[ge.MIDDLE],e))}containsPoint(e){const t=this.extent;return e[0]>=t[0]&&e[1]>=t[1]&&e[0]<=t[2]&&e[1]<=t[3]}unrequestLayerData(e,t,i){const s=this.layerInfo[t][e],n=s.waitingAgents,r=null!=n.removeUnordered(i);C(r,"agent has not requested this piece of map data"),n.length<1&&(s.abortRequest(),this.setMemoryDirty())}dataArrived(e,t,i){const s=this.layerInfo[t][e];s.data=i,s.dataInvalidated=!1,s.waitingAgents.forAll((e=>e.dataArrived(this))),s.waitingAgents.clear(),this.setMemoryDirty()}dataMissing(e,t,i){i.notInTilemap||console.error(`Tile ${this.lij.toString()} layer ${t}/${e} error ${i}`);const s=this.layerInfo[t][e];s.dataMissing=!0,s.waitingAgents.forAll((e=>e.dataMissing())),s.waitingAgents.clear(),this.setMemoryDirty()}updateRenderData(e,t){switch(e){case j.MAP:return this._updateTexture(t);case j.ELEVATION:return this._updateGeometry()}}_updateTexture(e){this.renderData&&(this.resetPendingUpdate(e===D.FADING?Z.TEXTURE_NOFADING:Z.TEXTURE_FADING),this.setPendingUpdate(e===D.FADING?Z.TEXTURE_FADING:Z.TEXTURE_NOFADING))}_updateGeometry(){this.setPendingUpdate(Z.GEOMETRY);for(const e of this.layerInfo[j.ELEVATION])e.pendingUpdates|=Z.GEOMETRY}invalidateLayerData(e,t){this.layerInfo[t][e].invalidateSourceData(),this.restartAgents(t)}computeElevationBounds(){const e=this._elevationBounds;a(e,1/0,-1/0);const i=this.layerInfo[j.ELEVATION];let s=!0;for(const n of i)t(n.elevationBounds)&&(e[0]=Math.min(e[0],n.elevationBounds.min),e[1]=Math.max(e[1],n.elevationBounds.max),n.elevationBounds.hasNoDataValues||(s=!1));s&&(e[0]=Math.min(e[0],0),e[1]=Math.max(e[1],0)),this.updateRadiusAndCenter(),this._surface.setTileTreeDirty()}_updateCenter(){const e=this._elevationBounds,t=.5*(e[0]+e[1]);u(ne,this.up,t),c(this._center[ge.MIDDLE],this.centerAtSeaLevel,ne),u(ne,this.up,e[0]),c(this._center[ge.TOP],this.centerAtSeaLevel,ne),u(ne,this.up,e[1]),c(this._center[ge.BOTTOM],this.centerAtSeaLevel,ne)}findElevationBoundsForLayer(e,i){const n=this.layerInfo[j.ELEVATION][e];if(t(n.elevationBounds)&&n.elevationBounds.level>=i)return;const r=this._surface.layerViewByIndex(e,j.ELEVATION),a=P(r);if(!ee(this,a,!1))return;const o=ce;let l=!1;if(n.data){const e=n.data;o.min=e.bounds[0],o.max=e.bounds[1],o.hasNoDataValues=e.hasNoDataValues,o.level=this.level,l=!0}else{let t,i,s=0;for(let n=this._parent;n&&(!i||s<U(this.level))&&(s=this.vlevel-n.level,t=i||t,i=n.layerInfo[j.ELEVATION][e].data,!(!i&&t&&s>=U(this.level)));n=n.parent);i=i||t,i&&(i.computeMinMaxValue(this.lij[0],this.lij[1],this.lij[2],o),o.min!==1/0&&(o.level=i.level,l=!0))}l&&(s(n.elevationBounds)&&(n.elevationBounds=new M),n.elevationBounds.copyFrom(o))}modifyLayers(e,t,i){const s=this.layerInfo[i];for(const a of s)a.loadingAgent&&a.loadingAgent!==$&&(he(a.loadingAgent),a.loadingAgent=null),a.waitingAgents.clear();for(let a=0;a<s.length;++a)void 0===e[a]&&s[a].release();const n=new Array(...s),r=t.length;s.length=r;for(let a=0;a<r;a++){const e=t[a];s[a]=e>-1?n[e]:Q.acquire(this._surface.upsampleInfoPool)}this.setMemoryDirty()}restartAgents(e){this.renderData&&(this._createOrUpdateAgents(0,e),this.updateRenderData(e,D.FADING))}updateAgents(e){if(this.renderData){const t=this.layerInfo[e];for(const e of t)e.loadingAgent===$&&(e.loadingAgent=null);this._createOrUpdateAgents(0,e)}}updateAgentSuspension(){for(const e of S){const t=this._isSuspended(e);for(const i of this.layerInfo[e])i.loadingAgent&&i.loadingAgent!==$&&(i.loadingAgent.setSuspension(t),i.loadingAgent===$&&this.updateRenderData(e,D.FADING))}}removeLayerAgent(e,t){const i=this.layerInfo[t][e];i.loadingAgent&&i.loadingAgent!==$&&i.loadingAgent.dispose(),i.loadingAgent=null}agentDone(e,t){const i=this.layerInfo[t][e];i.loadingAgent=$,!i.data&&s(i.upsampleInfo)&&this._createOrUpdateAgents(e+1,t)}_createOrUpdateAgents(e,t){const i=this.layerInfo[t];if(0===i.length)return;const s=(()=>{for(let s=e;s<i.length;++s){const e=this._surface.layerViewByIndex(s,t);if(B(e)&&"normal"!==e.layer.blendMode)return!0}return!1})(),n=this._isSuspended(t);for(let r=e;r<i.length;++r){const e=i[r];let a=!1;const o=this._surface.layerViewByIndex(r,t),l=P(o);if(e.loadingAgent?ee(this,l,!1)?(e.loadingAgent!==$&&e.loadingAgent.setSuspension(n),e.loadingAgent!==$&&(a=e.loadingAgent.update())):e.dispose():ee(this,l,!1)&&(e.loadingAgent=le(this,r,t,n),a=e.loadingAgent.startLoading(),a?e.loadingAgent===$&&this.setPendingUpdate(Z.GEOMETRY):(he(e.loadingAgent),e.loadingAgent=$)),e.loadingAgent===$&&this.updateRenderData(t,D.FADING),!s&&a&&o.isOpaque)return}}_isWithinExtent(e){const t=this.extent;return t[0]>=e[0]&&e[2]>=t[2]&&t[1]>=e[1]&&e[3]>=t[3]}intersectsExtent(e){const t=this.extent;return t[2]>=e[0]&&e[2]>=t[0]&&t[3]>=e[1]&&e[3]>=t[1]}getElevationBasedVerticesPerSide(t){const i=this.vlevel-this.level,s=Math.max(this.level-t,U(this.level)-i);return e(1+(this.maxTesselation>>s),2,this.maxTesselation+1)}get test(){return{cachedMemory:this._cachedMemory}}_findLIJ(e,i){if(!e)return null;const s=this.surface.rootTiles;if(t(s))for(const t of s)if(fe(t,e)){let s=t,n=e[0]-s.level-1;for(;n>=0&&!s.isLeaf&&!i(s);){const t=e[1]>>n&1,i=e[2]>>n&1;s=s.children[2*t+i],n--}return i(s)?s:null}return null}findNeighborTile(e,t){const i=this.lij,s=this.getNeighborLIJ(i,e);return s?pe(i,s)?t(this)?this:null:this._findLIJ(s,t):null}findCorner(e,t){const i=e===x.NORTH_EAST?1:e===x.NORTH_WEST?0:e===x.SOUTH_WEST?2:3;let s=this;for(;!(s.isLeaf||t&&t(s));)s=s.children[i];return s}findNeighborCornerTileExact(e,t){return this.findNeighborTile(e,(e=>t(e)||e.level===this.level))?.findCorner(R(e),t)}forAllSubtreeOnSide(e,t){const i=e===x.NORTH?[0,1]:e===x.NORTH_EAST?[1]:e===x.EAST?[1,3]:e===x.SOUTH_EAST?[3]:e===x.SOUTH?[2,3]:e===x.SOUTH_WEST?[2]:e===x.WEST?[0,2]:[0],s=e=>{t(e)||e.isLeaf||i.forEach((t=>s(e.children[t])))};s(this)}forallNeighbors(e){G.forEach((t=>this.findNeighborCornerTileExact(t,e))),V.forEach((t=>this.findNeighborTile(t,(t=>t.level===this.level||e(t)))?.forAllSubtreeOnSide(w(t),e)))}getNeighborEdgeStartVertexIndex(e,t){if(!t)return 0;const i=this.level-t.level;if(W(!q||i>=0),0===i)return 0;const s=2**i,n=1==(1&e),r=n?0:1,a=t.lij[r+1]*s,o=this.lij[r+1],l=o-a,h=n?s-1-l:l;return q&&(W(a<=o&&o<a+s),W(0<=h&&h<s)),h}forEachLoadedNeighbor(e){const t=this.level,i=e=>e.level===t||e.isLoaded;V.forEach((t=>{const s=this.findNeighborTile(t,i);null!=s&&s!==this&&s.forAllSubtreeOnSide(w(t),(i=>!!i.isLoaded&&(e(i,t),!0)))})),G.forEach((t=>{const s=this.findNeighborTile(t,i)?.findCorner(R(t),(e=>e.isLoaded));W(!s||ye(this,s,t)),s?.isLoaded&&e(s,t)}))}getNeighborLIJ(e,t){const i=H(t)?-1:F(t)?1:0,s=k(t)?-1:X(t)?1:0,n=[e[0],e[1]+i,e[2]+s];return n[1]<0?null:this.surface.isGlobal?this.wrapLIJ(n):n[2]<0?null:n}wrapLIJ(e){return!e||e[1]<0||e[1]>=2**e[0]?null:this.surface.wrapEastWest(e)}get westNeighborWestExtent(){return this.extent[0]*(this.isWestEnd?-1:1)}get eastNeighborEastExtent(){return this.extent[2]*(this.isEastEnd?-1:1)}get isEastEnd(){return this.lij[2]===this.surface.lijEastEnd(this.level)-1}get isWestEnd(){return 0===this.lij[2]}get isNorthEnd(){return 0===this.lij[1]}get isSouthEnd(){return this.extent[1]+m()>=this.surface.extent[1]}compareLIJs(e){const t=this.lij,i=t[0],s=e[0];if(i===s)return[t,e];const n=i-s;if(n<0){const i=2**-n;return[[s,t[1]*i,t[2]*i],e]}{const s=2**n;return[t,[i,e[1]*s,e[2]*s]]}}checkGeometryWaterproofness(){z&&(W(this.isLoaded),this.renderData.checkGeometryWaterproofness())}shouldHaveNeighbor(e){const t=this.extent,i=this.surface.rootTilesExtent,s=.25*(t[2]-t[0]);if(H(e)&&t[3]+s>=i[3])return!1;if(F(e)&&t[1]-s<=i[1])return!1;const n=this.surface.isGlobal;return!(!n&&k(e)&&t[0]-s<=i[0])&&!(!n&&X(e)&&t[2]+s>=i[2])}}function le(e,t,i,s){const n=i===j.ELEVATION?ue.acquire():de.acquire();return n.init(e,t,i,s),n}function he(e){e.dispose(),e instanceof I?ue.release(e):e instanceof N&&de.release(e)}const de=new n(N),ue=new n(I),ce=new M;var ge;function fe(e,t){const i=e.level,s=t[0];if(i>s)return!1;const n=s-i,r=Math.floor(t[1]/2**n),a=Math.floor(t[2]/2**n);return r===e.lij[1]&&a===e.lij[2]}function pe(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function me(e,t,i){return Math.abs(e-t)<=i}function _e(e,t,i){if(s(e)||s(t))return!1;if(0===e.level&&0===t.level){if(e.isEastEnd&&t.isWestEnd&&i===x.EAST)return!0;if(e.isWestEnd&&t.isEastEnd&&i===x.WEST)return!0}const n=Math.max(1e-6*(e.extent[2]-e.extent[0]),1);switch(i){case x.NORTH:return me(e.extent[3],t.extent[1],n);case x.SOUTH:return me(e.extent[1],t.extent[3],n);case x.EAST:return me(e.extent[2],t.extent[0],n)||me(e.extent[2],-t.extent[0],n);case x.WEST:return me(e.extent[0],t.extent[2],n)||me(e.extent[0],-t.extent[2],n)}}function ye(e,t,i){return!s(e)&&!s(t)&&t!==e&&(e.level>=t.level?Ae(e,t,i):Ae(t,e,R(i)))}function Ae(e,t,i){W(e.level>=t.level);const s=J(i),n=Y(i),r=e.extent,a=t.extent,o=[s?r[0]:r[2],n?r[3]:r[1]],l=[s?a[2]:a[0],n?a[1]:a[3]],h=1e-5*(r[2]-r[0]),d=me(o[0],l[0],h)||e.surface.isGlobal&&me(o[0],-l[0],h),u=me(o[1],l[1],h);if(d&&u)return!0;if(e.level===t.level)return W(!1),!1;if(!d&&!u)return W(!1),!1;const c=d?ve(a[1],a[3],r[1],r[3],h):ve(a[0],a[2],r[0],r[2],h);return W(c),c}function ve(e,t,i,s,n=m()){return e-n<=i&&i<=s&&s<=t+n}!function(e){e[e.TOP=0]="TOP",e[e.MIDDLE=1]="MIDDLE",e[e.BOTTOM=2]="BOTTOM"}(ge||(ge={}));export{ge as CenterPosition,ae as SplitLimits,oe as Tile,me as almostEquals,ye as isCornerNeighbor,_e as isEdgeNeighbor};
5
+ import{clamp as e}from"../../../core/mathUtils.js";import{isSome as t,abortMaybe as i,isNone as s}from"../../../core/maybe.js";import n from"../../../core/ObjectPool.js";import{c as r,s as a}from"../../../chunks/vec2.js";import{a as o}from"../../../chunks/vec2f64.js";import{b as l,p as h,e as u,g as d,a as c,l as g}from"../../../chunks/vec3.js";import{c as f,u as p}from"../../../chunks/vec3f64.js";import{g as m}from"../../../chunks/common.js";import{getReferenceEllipsoid as _}from"../../../geometry/projectionEllipsoid.js";import{create as y,equals as A}from"../../../geometry/support/aaBoundingRect.js";import{c as T}from"../../../chunks/sphere.js";import{VectorTile as E}from"../../2d/engine/vectorTiles/VectorTile.js";import{ImageWithType as v}from"../support/StreamDataLoader.js";import{ElevationBounds as I}from"./ElevationBounds.js";import{ElevationTileAgent as M}from"./ElevationTileAgent.js";import{TileFrustumVisibility as D,LODSnapping as L,TextureUpdate as S,NeighborIndex as x}from"./interfaces.js";import{LayerClasses as O,LayerClass as N}from"./LayerClass.js";import{MapTileAgent as j}from"./MapTileAgent.js";import{RasterTile as b}from"./RasterTile.js";import{MAX_PATCH_TESSELATION as U,getElevationDesiredResolutionLevel as C}from"./TerrainConst.js";import{weakAssert as P,getLayerWithExtentRange as B,isBlendableLayerView as R,oppositeCorner as V,neighborCornerIndices as G,neighborEdgeIndices as w,oppositeEdge as W,internalAssert as q,ENABLE_TERRAIN_INTERNAL_CHECKS as H,isNorth as F,isSouth as k,isWest as X,isEast as z,ENABLE_WATERPROOFNESS_TESTS as J,isWestCorner as Y,isNorthCorner as $}from"./terrainUtils.js";import{TILE_AGENT_DONE as Q}from"./TileAgent.js";import{TilePerLayerInfo as K}from"./TilePerLayerInfo.js";import Z from"./TileTexture.js";import{TileUpdate as ee}from"./TileUpdate.js";import{fallsWithinLayer as te}from"./tileUtils.js";import{getGpuMemoryUsage as ie}from"../../webgl/Util.js";const se=f(),ne=f(),re=f(),ae=.1;class oe{constructor(){this.fovX=0,this.fovY=0,this.relativeWidthLimit=0,this.relativeHeightLimit=0,this.maxLod=0,this.angledSplitBias=0,this.aboveGround=!0}}class le{constructor(){this.lij=[0,0,0],this._children=[null,null,null,null],this._pendingUpdates=0,this._dirty=!0,this._previouslyRendered=!1,this.extent=y(),this._elevationBounds=o(),this.layerInfo=[[],[]],this.extentInRadians=y(),this.centerAtSeaLevel=f(),this._center=[f(),T(),f()],this.up=p(),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._maxTesselation=0,this._usedMemory=null,this._mapTileMemoryInternal=0,this._mapDataRefCount=0,this._screenDepth=0,this.renderOrder=0,this._edgeLen=0,this._edgeLen2=0,this._curvatureHeight=0}static prune(){de.prune(0),ce.prune(0),K.prune()}get _isCached(){return!this.shouldLoad&&this._mapDataRefCount<=0}get maxTesselation(){return this._maxTesselation}get isWithinClippingArea(){return this._isWithinClippingArea}get intersectsClippingArea(){return this._intersectsClippingArea}get clippingArea(){return this._clippingArea}get parent(){return this._parent}get children(){return this._children}get surface(){return this._surface}get elevationBounds(){return this._elevationBounds}get level(){return this.lij[0]}get key(){return`${this.lij[0]}/${this.lij[1]}/${this.lij[2]}`}get edgeLen(){return this._edgeLen}get radius(){return this._center[fe.MIDDLE][3]}get screenDepth(){return this._screenDepth}get visible(){return this._dirty&&this.computeVisibility(),this._visible}get frustumVisibility(){return this._dirty&&this.computeVisibility(),this._frustumVisibility}computeVisibility(){this._dirty=!1;const e=this.parent?.frustumVisibility??D.INTERSECTS;this._frustumVisibility=e===D.INSIDE?D.INSIDE:e===D.OUTSIDE?D.OUTSIDE:this._calculateFrustumVisibilityStatus(this.surface.frustum);const t=this._frustumVisibility!==D.OUTSIDE&&this._intersectsClippingArea;t!==this._visible&&(this._visible=t,this._surface.emit("tiles-visibility-changed"),this._surface.renderer.setDirty(),this.updateAgentSuspension())}get loadable(){return this.visible||this._surface.view.state.fixedContentCamera}get rendered(){const e=!!this.renderData;return e!==this._previouslyRendered&&(this._surface.emit("tiles-visibility-changed"),this._previouslyRendered=e,this._surface.renderer.setDirty()),e}get shouldLoad(){if(this._surface.lodSnapping===L.ON){const e=this.level-this._surface.snapLevel;if(0===e)return!0;if(1===e)return!1}return this.isLeaf}init(e,t,i){this.lij[0]=e[0],this.lij[1]=e[1],this.lij[2]=e[2],this.ellipsoid=_(i.tilingScheme.spatialReference),i.tilingScheme.getExtent(e[0],e[1],e[2],this.extent),i.tilingScheme.convertExtentToRadians(this.extent,this.extentInRadians),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._clippingArea=null,this._mapDataRefCount=0,i.upsampleMapCache.pop(this.key),this._edgeLen=0,this._edgeLen2=0,this._center[fe.MIDDLE][3]=0,this.vlevel=e?e[0]:0,t&&t.elevationBounds?r(this._elevationBounds,t.elevationBounds):a(this._elevationBounds,0,0),this._pendingUpdates=0,this.renderData=null,this._screenDepth=0,this._visible=!1,this._previouslyRendered=!1,this._parent=t,this.unsetChildren(),this._surface=i,this.updateVisibility();for(const s of O){const e=i.numLayers(s),t=this.layerInfo[s];for(const i of t)i.release();t.length=e;for(let i=0;i<e;i++)t[i]=K.acquire(this._surface.upsampleInfoPool),s===N.ELEVATION&&this.findElevationBoundsForLayer(i,-1)}this.computeElevationBounds(),this._maxTesselation=Math.min(i.tilingScheme.pixelSize,U)}release(){P(!this.renderData,"tile.renderData was not unloaded"),this._surface.upsampleMapCache.pop(this.key);for(const e of O){for(const t of this.layerInfo[e])t.release();this.layerInfo[e].length=0}this._parent=null,this._surface=null,this.setMemoryDirty()}refMapData(){++this._mapDataRefCount,this._isCached||this._surface.upsampleMapCache.pop(this.key)}unrefMapData(){if(--this._mapDataRefCount,this._isCached){this.setMemoryDirty();const e=this._cachedMemory;e>0&&this._surface.upsampleMapCache.put(this.key,this,e)}}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this._ensureUsedMemory()+(this._isCached?0:this._mapTileMemoryInternal)}get _cachedMemory(){return this._isCached?this._mapTileMemory:0}get _mapTileMemory(){return this._ensureUsedMemory(),this.layerInfo[N.MAP].reduce(((e,t)=>e+(t instanceof E?t.memoryUsage:0)),this._mapTileMemoryInternal)}get _cpuImageMemorySize(){const e=4,t=this._surface.tilingScheme.pixelSize;return t*t*e}_ensureUsedMemory(){if(t(this._usedMemory))return this._usedMemory;this._usedMemory=0,this._mapTileMemoryInternal=0;let e=0;for(const{data:t}of this.layerInfo[N.MAP])t instanceof E?e+=this._getTerrainDataMemory(t):this._mapTileMemoryInternal+=this._getTerrainDataMemory(t);const i=this._cpuImageMemorySize;for(const t of this.layerInfo[N.ELEVATION])this._usedMemory+=t.data?i:0;return this.renderData&&(this._usedMemory+=this.renderData.estimatedGeometryMemoryUsage,this._mapTileMemoryInternal+=ie(this.renderData.textureDescriptor)),this._isCached&&this._surface.upsampleMapCache.updateSize(this.key,this,this._mapTileMemoryInternal+e),this._usedMemory}getUsedMemoryForLayer(e,t){const i=this.layerInfo[e][t];return i?.data?e===N.MAP?this._isCached?0:this._getTerrainDataMemory(i.data):e===N.ELEVATION?this._cpuImageMemorySize:0:0}_getTerrainDataMemory(e){return e instanceof Z?ie(e.texture):e instanceof HTMLImageElement||e instanceof v?this._cpuImageMemorySize:e instanceof E||e instanceof b?e.memoryUsage:0}updateScreenDepth(e){const t=this._center[fe.MIDDLE],i=e,s=t[0],n=t[1],r=t[2],a=i[2]*s+i[6]*n+i[10]*r+i[14];this._screenDepth=a<0?0:a/(i[3]*s+i[7]*n+i[11]*r+i[15])}shouldSplit(e,i,s){if(!this.visible)return ee.NONE;if(t(e.frustum)&&(!this._intersectsClippingArea||this._calculateFrustumVisibilityStatus(e.frustum)===D.OUTSIDE))return ee.NONE;const n=this.level;l(se,this._center[fe.MIDDLE],i);let r=h(se),a=fe.MIDDLE;l(ne,this._center[fe.TOP],i);const o=h(ne);o<r&&(r=o,a=fe.TOP),l(ne,this._center[fe.BOTTOM],i);const f=h(ne);if(f<r&&(r=f,a=fe.BOTTOM),this._edgeLen2>r&&n<e.maxLod)return ee.SPLIT;const p=Math.sqrt(r),m=e.fovX*p*2,_=this._edgeLen/m,y=()=>{const t=n+Math.ceil(-Math.log2(e.relativeWidthLimit/_));return t!==this.vlevel?(this.vlevel=t,ee.VSPLITMERGE):ee.NONE_HIT_MAXLOD};if(s===L.ON){if(1===this._surface.snapLevel-n)return n>=e.maxLod?y():ee.SPLIT}const A=u(this.up,se),T=this._elevationBounds[1]-this._elevationBounds[0],E=T/this.edgeLen;if(e.aboveGround&&A>0&&E<.001){if(A/p-Math.sin(this._curvatureHeight/(this.edgeLen*Math.SQRT1_2)*Math.PI)-E>0)return ee.NONE}if(_<e.relativeWidthLimit)return this.vlevel!==this.level?(this.vlevel=this.level,ee.VSPLITMERGE):ee.NONE;if(n>=e.maxLod)return y();if(n>6){l(ne,this._center[a],i),d(re,this.up,A),l(re,re,ne);const t=h(re);if(t>this.radius*this.radius){d(re,re,this.radius/Math.sqrt(t)),c(re,re,this._center[a]),l(re,i,re);const s=Math.min(1,(Math.abs(u(re,this.up))+.5*T+this._curvatureHeight)/g(re)),n=ae/e.angledSplitBias,r=e.fovY*p*2;if(s*(this._edgeLen/r)<n*e.relativeHeightLimit)return ee.NONE}}return ee.SPLIT}setChildren(e,t,i,s){P(!!(e&&t&&i&&s),"Null child passed"),this._children[0]=e,this._children[1]=t,this._children[2]=i,this._children[3]=s}unsetChildren(){this._children[0]=null,this._children[1]=null,this._children[2]=null,this._children[3]=null}get isLoaded(){return this.renderData?.hasGeometry??!1}load(){this.refMapData();for(const e of O)this._createOrUpdateAgents(0,e);this.surface.renderer.loadTile(this)}unload(e){e.unloadTile(this);for(const t of O){const e=this.layerInfo[t];for(const t of e)t.loadingAgent&&t.loadingAgent!==Q&&(ue(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0}this.resetPendingUpdate(ee.GEOMETRY),this.resetPendingUpdate(ee.TEXTURE_NOFADING),this.resetPendingUpdate(ee.TEXTURE_FADING),this.unrefMapData()}unloadMapData(){const e=this.layerInfo[N.MAP];for(const t of e)t.loadingAgent&&t.loadingAgent!==Q&&(ue(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0;this.renderData&&this.renderData.releaseTexture(),this.setMemoryDirty()}updateClippingStatus(e){if(A(e,this._clippingArea))return!1;const i=this._intersectsClippingArea,s=this._isWithinClippingArea;t(e)?(this._intersectsClippingArea=this.intersectsExtent(e),this._isWithinClippingArea=this._isWithinExtent(e)):(this._intersectsClippingArea=!0,this._isWithinClippingArea=!0),this._clippingArea=e,this.updateVisibility();const n=s&&this._isWithinClippingArea,r=!(s||i||this._isWithinClippingArea||this._intersectsClippingArea);return!this.renderData||n||r||this.setPendingUpdate(ee.GEOMETRY),!0}updateVisibility(){this._dirty=!0,this._surface.setTileTreeDirty()}getLayerInfo(e,t){return this.layerInfo[t][e]}hasLayerData(e,t){const i=this.layerInfo[t][e];return!(!i||!i.data||i.dataInvalidated)}get updating(){if(this.hasPendingUpdates)return!0;for(const e of O){const t=this.layerInfo[e];for(const e of t)if(e.loadingAgent&&e.loadingAgent!==Q&&e.loadingAgent.updating)return!0}return!1}_isSuspended(e){return!!this.hasPendingUpdate(ee.SPLIT)||e!==N.ELEVATION&&!this.loadable}get hasPendingUpdates(){return 0!==this._pendingUpdates}hasPendingUpdate(e){return(this._pendingUpdates&e)===e}setPendingUpdate(e){this._pendingUpdates|=e,e===ee.SPLIT||e===ee.MERGE?this._surface.setTileTreeDirty():this._surface.requestUpdate()}resetPendingUpdate(e){return!!this.hasPendingUpdate(e)&&(this._pendingUpdates&=~e,!0)}requestLayerData(e,t,s){const n=this.layerInfo[t][e];if(n.waitingAgents.has(s))return console.warn("agent already requested this piece of map data (tile %s, agent tile %s, layer: %d/%d)",this.lij.toString(),s.tile.lij.toString(),t,e),!0;if(n.waitingAgents.push(s),n.data&&!n.dataInvalidated)return console.warn("agent requested existing data (tile %s, agent tile %s, layer: %d/%d)",this.lij.toString(),s.tile.lij.toString(),t,e),s.dataArrived(this),!0;if(n.requestPromise)return!0;i(n.requestAbort),n.requestAbort=new AbortController;const r=this._surface.requestTileData(this,e,t,n.requestAbort);if(!r)return n.requestAbort=null,!1;const a=()=>{n.requestPromise===r&&(n.requestPromise=null,n.requestAbort=null)};return n.requestPromise=r,r.then(a,a),!0}get isLeaf(){return null==this._children[0]}hasLij(e){return this.lij[0]===e[0]&&this.lij[1]===e[1]&&this.lij[2]===e[2]}findByLij(e){if(this.hasLij(e))return this;if(this.isLeaf)return null;const t=this._children[0].findByLij(e)||this._children[1].findByLij(e)||this._children[2].findByLij(e)||this._children[3].findByLij(e);return t||null}distanceToSquared(e){return h(l(re,this._center[fe.MIDDLE],e))}containsPoint(e){const t=this.extent;return e[0]>=t[0]&&e[1]>=t[1]&&e[0]<=t[2]&&e[1]<=t[3]}unrequestLayerData(e,t,i){const s=this.layerInfo[t][e],n=s.waitingAgents,r=null!=n.removeUnordered(i);P(r,"agent has not requested this piece of map data"),n.length<1&&(s.abortRequest(),this.setMemoryDirty())}dataArrived(e,t,i){const s=this.layerInfo[t][e];s.data=i,s.dataInvalidated=!1,s.waitingAgents.forAll((e=>e.dataArrived(this))),s.waitingAgents.clear(),this.setMemoryDirty()}dataMissing(e,t,i){i.notInTilemap||console.error(`Tile ${this.lij.toString()} layer ${t}/${e} error ${i}`);const s=this.layerInfo[t][e];s.dataMissing=!0,s.waitingAgents.forAll((e=>e.dataMissing())),s.waitingAgents.clear(),this.setMemoryDirty()}updateRenderData(e,t){switch(e){case N.MAP:return this._updateTexture(t);case N.ELEVATION:return this._updateGeometry()}}_updateTexture(e){this.renderData&&(this.resetPendingUpdate(e===S.FADING?ee.TEXTURE_NOFADING:ee.TEXTURE_FADING),this.setPendingUpdate(e===S.FADING?ee.TEXTURE_FADING:ee.TEXTURE_NOFADING))}_updateGeometry(){this.setPendingUpdate(ee.GEOMETRY);for(const e of this.layerInfo[N.ELEVATION])e.pendingUpdates|=ee.GEOMETRY}invalidateLayerData(e,t){this.layerInfo[t][e].invalidateSourceData(),this.restartAgents(t)}computeElevationBounds(){const e=this._elevationBounds;a(e,1/0,-1/0);const i=this.layerInfo[N.ELEVATION];let s=!0;for(const n of i)t(n.elevationBounds)&&(e[0]=Math.min(e[0],n.elevationBounds.min),e[1]=Math.max(e[1],n.elevationBounds.max),n.elevationBounds.hasNoDataValues||(s=!1));s&&(e[0]=Math.min(e[0],0),e[1]=Math.max(e[1],0)),this.updateRadiusAndCenter(),this._surface.setTileTreeDirty()}_updateCenter(){const e=this._elevationBounds,t=.5*(e[0]+e[1]);d(re,this.up,t),c(this._center[fe.MIDDLE],this.centerAtSeaLevel,re),d(re,this.up,e[0]),c(this._center[fe.TOP],this.centerAtSeaLevel,re),d(re,this.up,e[1]),c(this._center[fe.BOTTOM],this.centerAtSeaLevel,re)}findElevationBoundsForLayer(e,i){const n=this.layerInfo[N.ELEVATION][e];if(t(n.elevationBounds)&&n.elevationBounds.level>=i)return;const r=this._surface.layerViewByIndex(e,N.ELEVATION),a=B(r);if(!te(this,a,!1))return;const o=ge;let l=!1;if(n.data){const e=n.data;o.min=e.bounds[0],o.max=e.bounds[1],o.hasNoDataValues=e.hasNoDataValues,o.level=this.level,l=!0}else{let t,i,s=0;for(let n=this._parent;n&&(!i||s<C(this.level))&&(s=this.vlevel-n.level,t=i||t,i=n.layerInfo[N.ELEVATION][e].data,!(!i&&t&&s>=C(this.level)));n=n.parent);i=i||t,i&&(i.computeMinMaxValue(this.lij[0],this.lij[1],this.lij[2],o),o.min!==1/0&&(o.level=i.level,l=!0))}l&&(s(n.elevationBounds)&&(n.elevationBounds=new I),n.elevationBounds.copyFrom(o))}modifyLayers(e,t,i){const s=this.layerInfo[i];for(const a of s)a.loadingAgent&&a.loadingAgent!==Q&&(ue(a.loadingAgent),a.loadingAgent=null),a.waitingAgents.clear();for(let a=0;a<s.length;++a)void 0===e[a]&&s[a].release();const n=new Array(...s),r=t.length;s.length=r;for(let a=0;a<r;a++){const e=t[a];s[a]=e>-1?n[e]:K.acquire(this._surface.upsampleInfoPool)}this.setMemoryDirty()}restartAgents(e){this.renderData&&(this._createOrUpdateAgents(0,e),this.updateRenderData(e,S.FADING))}updateAgents(e){if(this.renderData){const t=this.layerInfo[e];for(const e of t)e.loadingAgent===Q&&(e.loadingAgent=null);this._createOrUpdateAgents(0,e)}}updateAgentSuspension(){for(const e of O){const t=this._isSuspended(e);for(const i of this.layerInfo[e])i.loadingAgent&&i.loadingAgent!==Q&&(i.loadingAgent.setSuspension(t),i.loadingAgent===Q&&this.updateRenderData(e,S.FADING))}}removeLayerAgent(e,t){const i=this.layerInfo[t][e];i.loadingAgent&&i.loadingAgent!==Q&&i.loadingAgent.dispose(),i.loadingAgent=null}agentDone(e,t){const i=this.layerInfo[t][e];i.loadingAgent=Q,!i.data&&s(i.upsampleInfo)&&this._createOrUpdateAgents(e+1,t)}_createOrUpdateAgents(e,t){const i=this.layerInfo[t];if(0===i.length)return;const s=(()=>{for(let s=e;s<i.length;++s){const e=this._surface.layerViewByIndex(s,t);if(R(e)&&"normal"!==e.layer.blendMode)return!0}return!1})(),n=this._isSuspended(t);for(let r=e;r<i.length;++r){const e=i[r];let a=!1;const o=this._surface.layerViewByIndex(r,t),l=B(o);if(e.loadingAgent?te(this,l,!1)?(e.loadingAgent!==Q&&e.loadingAgent.setSuspension(n),e.loadingAgent!==Q&&(a=e.loadingAgent.update())):e.dispose():te(this,l,!1)&&(e.loadingAgent=he(this,r,t,n),a=e.loadingAgent.startLoading(),a?e.loadingAgent===Q&&this.setPendingUpdate(ee.GEOMETRY):(ue(e.loadingAgent),e.loadingAgent=Q)),e.loadingAgent===Q&&this.updateRenderData(t,S.FADING),!s&&a&&o.isOpaque)return}}_isWithinExtent(e){const t=this.extent;return t[0]>=e[0]&&e[2]>=t[2]&&t[1]>=e[1]&&e[3]>=t[3]}intersectsExtent(e){const t=this.extent;return t[2]>=e[0]&&e[2]>=t[0]&&t[3]>=e[1]&&e[3]>=t[1]}getElevationBasedVerticesPerSide(t){const i=this.vlevel-this.level,s=Math.max(this.level-t,C(this.level)-i);return e(1+(this.maxTesselation>>s),2,this.maxTesselation+1)}get test(){return{cachedMemory:this._cachedMemory}}_findLIJ(e,i){if(!e)return null;const s=this.surface.rootTiles;if(t(s))for(const t of s)if(pe(t,e)){let s=t,n=e[0]-s.level-1;for(;n>=0&&!s.isLeaf&&!i(s);){const t=e[1]>>n&1,i=e[2]>>n&1;s=s.children[2*t+i],n--}return i(s)?s:null}return null}findNeighborTile(e,t){const i=this.lij,s=this.getNeighborLIJ(i,e);return s?me(i,s)?t(this)?this:null:this._findLIJ(s,t):null}findCorner(e,t){const i=e===x.NORTH_EAST?1:e===x.NORTH_WEST?0:e===x.SOUTH_WEST?2:3;let s=this;for(;!(s.isLeaf||t&&t(s));)s=s.children[i];return s}findNeighborCornerTileExact(e,t){return this.findNeighborTile(e,(e=>t(e)||e.level===this.level))?.findCorner(V(e),t)}forAllSubtreeOnSide(e,t){const i=e===x.NORTH?[0,1]:e===x.NORTH_EAST?[1]:e===x.EAST?[1,3]:e===x.SOUTH_EAST?[3]:e===x.SOUTH?[2,3]:e===x.SOUTH_WEST?[2]:e===x.WEST?[0,2]:[0],s=e=>{t(e)||e.isLeaf||i.forEach((t=>s(e.children[t])))};s(this)}forallNeighbors(e){G.forEach((t=>this.findNeighborCornerTileExact(t,e))),w.forEach((t=>this.findNeighborTile(t,(t=>t.level===this.level||e(t)))?.forAllSubtreeOnSide(W(t),e)))}getNeighborEdgeStartVertexIndex(e,t){if(!t)return 0;const i=this.level-t.level;if(q(!H||i>=0),0===i)return 0;const s=2**i,n=1==(1&e),r=n?0:1,a=t.lij[r+1]*s,o=this.lij[r+1],l=o-a,h=n?s-1-l:l;return H&&(q(a<=o&&o<a+s),q(0<=h&&h<s)),h}forEachLoadedNeighbor(e){const t=this.level,i=e=>e.level===t||e.isLoaded;w.forEach((t=>{const s=this.findNeighborTile(t,i);null!=s&&s!==this&&s.forAllSubtreeOnSide(W(t),(i=>!!i.isLoaded&&(e(i,t),!0)))})),G.forEach((t=>{const s=this.findNeighborTile(t,i)?.findCorner(V(t),(e=>e.isLoaded));q(!s||Ae(this,s,t)),s?.isLoaded&&e(s,t)}))}getNeighborLIJ(e,t){const i=F(t)?-1:k(t)?1:0,s=X(t)?-1:z(t)?1:0,n=[e[0],e[1]+i,e[2]+s];return n[1]<0?null:this.surface.isGlobal?this.wrapLIJ(n):n[2]<0?null:n}wrapLIJ(e){return!e||e[1]<0||e[1]>=2**e[0]?null:this.surface.wrapEastWest(e)}get westNeighborWestExtent(){return this.extent[0]*(this.isWestEnd?-1:1)}get eastNeighborEastExtent(){return this.extent[2]*(this.isEastEnd?-1:1)}get isEastEnd(){return this.lij[2]===this.surface.lijEastEnd(this.level)-1}get isWestEnd(){return 0===this.lij[2]}get isNorthEnd(){return 0===this.lij[1]}get isSouthEnd(){return this.extent[1]+m()>=this.surface.extent[1]}compareLIJs(e){const t=this.lij,i=t[0],s=e[0];if(i===s)return[t,e];const n=i-s;if(n<0){const i=2**-n;return[[s,t[1]*i,t[2]*i],e]}{const s=2**n;return[t,[i,e[1]*s,e[2]*s]]}}checkGeometryWaterproofness(){J&&(q(this.isLoaded),this.renderData.checkGeometryWaterproofness())}shouldHaveNeighbor(e){const t=this.extent,i=this.surface.rootTilesExtent,s=.25*(t[2]-t[0]);if(F(e)&&t[3]+s>=i[3])return!1;if(k(e)&&t[1]-s<=i[1])return!1;const n=this.surface.isGlobal;return!(!n&&X(e)&&t[0]-s<=i[0])&&!(!n&&z(e)&&t[2]+s>=i[2])}}function he(e,t,i,s){const n=i===N.ELEVATION?ce.acquire():de.acquire();return n.init(e,t,i,s),n}function ue(e){e.dispose(),e instanceof M?ce.release(e):e instanceof j&&de.release(e)}const de=new n(j),ce=new n(M),ge=new I;var fe;function pe(e,t){const i=e.level,s=t[0];if(i>s)return!1;const n=s-i,r=Math.floor(t[1]/2**n),a=Math.floor(t[2]/2**n);return r===e.lij[1]&&a===e.lij[2]}function me(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function _e(e,t,i){return Math.abs(e-t)<=i}function ye(e,t,i){if(s(e)||s(t))return!1;if(0===e.level&&0===t.level){if(e.isEastEnd&&t.isWestEnd&&i===x.EAST)return!0;if(e.isWestEnd&&t.isEastEnd&&i===x.WEST)return!0}const n=Math.max(1e-6*(e.extent[2]-e.extent[0]),1);switch(i){case x.NORTH:return _e(e.extent[3],t.extent[1],n);case x.SOUTH:return _e(e.extent[1],t.extent[3],n);case x.EAST:return _e(e.extent[2],t.extent[0],n)||_e(e.extent[2],-t.extent[0],n);case x.WEST:return _e(e.extent[0],t.extent[2],n)||_e(e.extent[0],-t.extent[2],n)}}function Ae(e,t,i){return!s(e)&&!s(t)&&t!==e&&(e.level>=t.level?Te(e,t,i):Te(t,e,V(i)))}function Te(e,t,i){q(e.level>=t.level);const s=Y(i),n=$(i),r=e.extent,a=t.extent,o=[s?r[0]:r[2],n?r[3]:r[1]],l=[s?a[2]:a[0],n?a[1]:a[3]],h=1e-5*(r[2]-r[0]),u=_e(o[0],l[0],h)||e.surface.isGlobal&&_e(o[0],-l[0],h),d=_e(o[1],l[1],h);if(u&&d)return!0;if(e.level===t.level)return q(!1),!1;if(!u&&!d)return q(!1),!1;const c=u?Ee(a[1],a[3],r[1],r[3],h):Ee(a[0],a[2],r[0],r[2],h);return q(c),c}function Ee(e,t,i,s,n=m()){return e-n<=i&&i<=s&&s<=t+n}!function(e){e[e.TOP=0]="TOP",e[e.MIDDLE=1]="MIDDLE",e[e.BOTTOM=2]="BOTTOM"}(fe||(fe={}));export{fe as CenterPosition,oe as SplitLimits,le as Tile,_e as almostEquals,Ae as isCornerNeighbor,ye as isEdgeNeighbor};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- var O,T,E,S,H,A;!function(O){O[O.INNER=0]="INNER",O[O.OUTER=1]="OUTER"}(O||(O={})),function(O){O[O.REGULAR=0]="REGULAR",O[O.HAS_NORTH_POLE=1]="HAS_NORTH_POLE",O[O.HAS_SOUTH_POLE=2]="HAS_SOUTH_POLE",O[O.HAS_BOTH_POLES=3]="HAS_BOTH_POLES"}(T||(T={})),function(O){O[O.NORTH=0]="NORTH",O[O.NORTH_EAST=1]="NORTH_EAST",O[O.EAST=2]="EAST",O[O.SOUTH_EAST=3]="SOUTH_EAST",O[O.SOUTH=4]="SOUTH",O[O.SOUTH_WEST=5]="SOUTH_WEST",O[O.WEST=6]="WEST",O[O.NORTH_WEST=7]="NORTH_WEST"}(E||(E={})),function(O){O[O.OFF=0]="OFF",O[O.ON=1]="ON"}(S||(S={})),function(O){O[O.Color=0]="Color",O[O.ColorNoRasterImage=1]="ColorNoRasterImage",O[O.Highlight=2]="Highlight",O[O.Water=3]="Water",O[O.Occluded=4]="Occluded",O[O.ObjectAndLayerIdColor=5]="ObjectAndLayerIdColor"}(H||(H={})),function(O){O[O.FADING=0]="FADING",O[O.IMMEDIATE=1]="IMMEDIATE",O[O.UNFADED=2]="UNFADED"}(A||(A={}));export{S as LODSnapping,E as NeighborIndex,O as OverlayIndex,T as PatchType,H as RenderTargetType,A as TextureUpdate};
5
+ var T,E,O,S,H,N,o;!function(T){T[T.INNER=0]="INNER",T[T.OUTER=1]="OUTER"}(T||(T={})),function(T){T[T.REGULAR=0]="REGULAR",T[T.HAS_NORTH_POLE=1]="HAS_NORTH_POLE",T[T.HAS_SOUTH_POLE=2]="HAS_SOUTH_POLE",T[T.HAS_BOTH_POLES=3]="HAS_BOTH_POLES"}(E||(E={})),function(T){T[T.NORTH=0]="NORTH",T[T.NORTH_EAST=1]="NORTH_EAST",T[T.EAST=2]="EAST",T[T.SOUTH_EAST=3]="SOUTH_EAST",T[T.SOUTH=4]="SOUTH",T[T.SOUTH_WEST=5]="SOUTH_WEST",T[T.WEST=6]="WEST",T[T.NORTH_WEST=7]="NORTH_WEST"}(O||(O={})),function(T){T[T.OFF=0]="OFF",T[T.ON=1]="ON"}(S||(S={})),function(T){T[T.Color=0]="Color",T[T.ColorNoRasterImage=1]="ColorNoRasterImage",T[T.Highlight=2]="Highlight",T[T.Water=3]="Water",T[T.Occluded=4]="Occluded",T[T.ObjectAndLayerIdColor=5]="ObjectAndLayerIdColor"}(H||(H={})),function(T){T[T.FADING=0]="FADING",T[T.IMMEDIATE=1]="IMMEDIATE",T[T.UNFADED=2]="UNFADED"}(N||(N={})),function(T){T[T.INSIDE=0]="INSIDE",T[T.INTERSECTS=1]="INTERSECTS",T[T.OUTSIDE=2]="OUTSIDE"}(o||(o={}));export{S as LODSnapping,O as NeighborIndex,T as OverlayIndex,E as PatchType,H as RenderTargetType,N as TextureUpdate,o as TileFrustumVisibility};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{createLength as e}from"../../core/quantityUtils.js";import{c as t}from"../../chunks/vec3f64.js";import{geodesicLength as r}from"../../geometry/geometryEngine.js";import{projectVectorToWGS84ComparableLonLat as n,projectPolylineToWGS84ComparableLonLat as o}from"../../geometry/projection.js";import{inverseGeodeticSolver as s,geodesicLengths as i}from"../../geometry/support/geodesicUtils.js";import{equals as c}from"../../geometry/support/spatialReferenceUtils.js";import{geodesicMeasure as u}from"./geodesicMeasurementUtils.js";function f(e){const{spatialReference:t}=e;return u(t,y,j,d,e)}function m(e,t){if(!c(e.spatialReference,t.spatialReference))return null;const{spatialReference:r}=e;return U[0]=e.x,U[1]=e.y,U[2]=e.hasZ?e.z:0,x[0]=t.x,x[1]=t.y,x[2]=t.hasZ?t.z:0,l(U,x,r)}function l(e,t,r){return u(r,a,p,g,e,t,r)}function a(t,r,n){return e(s(R,t,r,n).distance,"meters")}function p(t,n,o){return e(r(h(t,n,o),"meters"),"meters")}function g(t,r,o){return n(t,o,z)&&n(r,o,Z)?e(s(R,z,Z).distance,"meters"):null}function y(t){return e(i([t],"meters")[0],"meters")}function j(t){return e(r(t,"meters"),"meters")}function d(t){const r=[];if(!o(t,r))return null;let n=0;for(const e of r){let t=0;for(let r=1;r<e.length;++r)t+=s(R,e[r-1],e[r]).distance;n+=t}return e(n,"meters")}function h(e,t,r){return{type:"polyline",spatialReference:r,paths:[[[...e],[...t]]]}}const R={distance:null},U=t(),x=t(),z=t(),Z=t();export{l as geodesicDistance,m as geodesicDistanceBetweenPoints,f as geodesicLength};
5
+ import{createLength as e}from"../../core/quantityUtils.js";import{c as t}from"../../chunks/vec3f64.js";import{geodesicLength as r}from"../../geometry/geometryEngine.js";import{projectVectorToWGS84ComparableLonLat as n,projectPolylineToWGS84ComparableLonLat as o}from"../../geometry/projection.js";import{inverseGeodeticSolver as s,geodesicLengths as i,InverseGeodeticSolverResult as c}from"../../geometry/support/geodesicUtils.js";import{equals as u}from"../../geometry/support/spatialReferenceUtils.js";import{geodesicMeasure as f}from"./geodesicMeasurementUtils.js";function m(e){const{spatialReference:t}=e;return f(t,j,d,h,e)}function a(e,t){if(!u(e.spatialReference,t.spatialReference))return null;const{spatialReference:r}=e;return x[0]=e.x,x[1]=e.y,x[2]=e.hasZ?e.z:0,z[0]=t.x,z[1]=t.y,z[2]=t.hasZ?t.z:0,l(x,z,r)}function l(e,t,r){return f(r,p,g,y,e,t,r)}function p(t,r,n){return e(s(U,t,r,n).distance,"meters")}function g(t,n,o){return e(r(R(t,n,o),"meters"),"meters")}function y(t,r,o){return n(t,o,Z)&&n(r,o,k)?e(s(U,Z,k).distance,"meters"):null}function j(t){return e(i([t],"meters")[0],"meters")}function d(t){return e(r(t,"meters"),"meters")}function h(t){const r=[];if(!o(t,r))return null;let n=0;for(const e of r){let t=0;for(let r=1;r<e.length;++r)t+=s(U,e[r-1],e[r]).distance;n+=t}return e(n,"meters")}function R(e,t,r){return{type:"polyline",spatialReference:r,paths:[[[...e],[...t]]]}}const U=new c,x=t(),z=t(),Z=t(),k=t();export{l as geodesicDistance,a as geodesicDistanceBetweenPoints,m as geodesicLength};