@arcgis/core 4.33.0-next.20250304 → 4.33.0-next.20250306

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 (60) hide show
  1. package/arcade/arcadeCompiler.js +1 -1
  2. package/assets/esri/core/workers/RemoteClient.js +1 -1
  3. package/assets/esri/core/workers/chunks/{e99d7ecb80a9df9ead6d.js → 1e7a70a1871fea29169e.js} +3 -3
  4. package/assets/esri/core/workers/chunks/{618016fc1165bcfc2b0d.js → 42b862550c96cc1be956.js} +7 -9
  5. package/assets/esri/core/workers/chunks/4403b3f08907e88d0d91.js +1 -0
  6. package/assets/esri/core/workers/chunks/{0e2d9cd4e8ee5a62b05c.js → 45eee326f7a649c5a15b.js} +7 -9
  7. package/assets/esri/core/workers/chunks/7975ada96e4540a37c83.js +1 -0
  8. package/assets/esri/core/workers/chunks/e3e049311bced533c853.js +1 -0
  9. package/assets/esri/core/workers/chunks/{b464b7800a2ddd92b9a7.js → e8a19f9144df8f155e30.js} +1 -1
  10. package/assets/esri/core/workers/chunks/f4111bb5e5a4910b684a.js +1 -0
  11. package/assets/esri/libs/parquet/pkg/arcgis_parquet_bg.wasm +0 -0
  12. package/chunks/Clouds.glsl.js +19 -23
  13. package/chunks/ImageMaterial.glsl.js +1 -1
  14. package/core/Accessor.js +1 -1
  15. package/core/accessorSupport/decorators/subclass.js +1 -1
  16. package/core/accessorSupport/interfaces.js +1 -1
  17. package/interfaces.d.ts +8 -4
  18. package/layers/mixins/ArcGISImageService.js +1 -1
  19. package/layers/support/featureLayerUtils.js +1 -1
  20. package/libs/parquet/parquet.js +1 -1
  21. package/package.json +1 -1
  22. package/request.js +1 -1
  23. package/rest/support/IdentifyParameters.js +1 -1
  24. package/support/revision.js +1 -1
  25. package/views/3d/analysis/Dimension/DimensionTool.js +1 -1
  26. package/views/3d/analysis/Dimension/LengthDimensionSubTool.js +1 -1
  27. package/views/3d/analysis/Dimension/lengthDimensionManipulatorUtils.js +1 -1
  28. package/views/3d/analysis/Slice/RotateManipulator.js +1 -1
  29. package/views/3d/environment/Clouds.glsl.js +1 -1
  30. package/views/3d/environment/CloudsParameters.js +1 -1
  31. package/views/3d/environment/CloudsRenderer.js +1 -1
  32. package/views/3d/layers/DynamicLayerView3D.js +1 -1
  33. package/views/3d/layers/MediaLayerView3D.js +1 -1
  34. package/views/3d/layers/support/FeatureTile.js +1 -1
  35. package/views/3d/layers/support/FeatureTileFetcher3D.js +1 -1
  36. package/views/3d/support/StreamTextureCollection.js +1 -1
  37. package/views/3d/support/TextureCollection.js +1 -1
  38. package/views/3d/terrain/TerrainRenderer.js +1 -1
  39. package/views/3d/terrain/TerrainSurface.js +1 -1
  40. package/views/3d/webgl-engine/core/shaderLibrary/util/CloudsParallaxShading.glsl.js +7 -7
  41. package/views/3d/webgl-engine/core/shaderLibrary/util/DoublePrecision.glsl.js +5 -7
  42. package/views/3d/webgl-engine/core/shaderLibrary/util/LookupCloudsFromTextureArray.glsl.js +51 -0
  43. package/views/3d/webgl-engine/lib/GLMaterialParameters.js +5 -0
  44. package/views/3d/webgl-engine/lib/GLMaterialRepository.js +1 -1
  45. package/views/3d/webgl-engine/lib/RenderingContext.js +1 -1
  46. package/views/3d/webgl-engine/lib/TextTextureAtlas.js +1 -1
  47. package/views/3d/webgl-engine/lib/Texture.js +1 -1
  48. package/views/3d/webgl-engine/lib/TextureRepository.js +1 -1
  49. package/views/3d/webgl-engine/materials/ImageMaterial.js +1 -1
  50. package/views/animation/pointToPoint/apex/planning.js +1 -1
  51. package/views/webgl/FramebufferObject.js +1 -1
  52. package/views/webgl/TextureDescriptor.js +1 -1
  53. package/widgets/FeatureForm/FieldInput.js +1 -1
  54. package/widgets/FeatureForm/UtilityNetworkAssociationAddAssociationViewModel.js +1 -1
  55. package/widgets/UtilityNetworkTraceAnalysis/UtilityNetworkTraceAnalysisViewModel.js +1 -1
  56. package/assets/esri/core/workers/chunks/04341d50082f864025aa.js +0 -1
  57. package/assets/esri/core/workers/chunks/10118666a5a5b141ece6.js +0 -1
  58. package/assets/esri/core/workers/chunks/64d3e683872791eb6ae9.js +0 -1
  59. package/assets/esri/core/workers/chunks/8b057b5a606ac3669a78.js +0 -1
  60. package/views/3d/webgl-engine/core/shaderLibrary/util/LookupCubemapFromTextureArray.glsl.js +0 -39
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../../Color.js";import{multiplyOpacity as t,getContrast as r}from"../../../../core/colorUtils.js";import{watch as i,initial as o}from"../../../../core/reactiveUtils.js";import{DidPointerMoveRecentlyFlag as n}from"./sliceToolUtils.js";import{Manipulator3D as s}from"../../interactive/Manipulator3D.js";import{rotateManipulatorDefaults as l}from"../../interactive/manipulatorUtils.js";import{RenderObject as a}from"../../interactive/RenderObject.js";import{Attribute as c}from"../../webgl-engine/lib/Attribute.js";import{Geometry as m}from"../../webgl-engine/lib/Geometry.js";import{createPolylineGeometry as u}from"../../webgl-engine/lib/GeometryUtil.js";import{RenderOccludedFlag as d}from"../../webgl-engine/lib/Material.js";import{VertexAttribute as p}from"../../webgl-engine/lib/VertexAttribute.js";import{ImageMaterial as f}from"../../webgl-engine/materials/ImageMaterial.js";import{RibbonLineMaterial as b}from"../../webgl-engine/materials/RibbonLineMaterial.js";import{ManipulatorStateFlags as w}from"../../../interactive/interfaces.js";class g extends s{constructor(n,s){const a=new f({writeDepth:!1,renderOccluded:d.Opaque,isDecoration:!0}),c=l.calloutWidth,m=new b({width:c,renderOccluded:d.OccludeAndTransparent,isDecoration:!0});super({view:n,...j({imageMaterial:a,calloutMaterial:m})}),this._currentTexture=null,this._themeHandle=i((()=>n.effectiveTheme.accentColor),(i=>{const o=t(i,.5),n=r(i),l=this._currentTexture,c=s(o,n);a.setParameters({textureId:c.texture.id}),m.setParameters({color:e.toUnitRGBA(i)}),this._currentTexture=c,l?.release()}),o)}destroy(){this._themeHandle.remove(),this._currentTexture?.release(),super.destroy()}}function j({imageMaterial:e,calloutMaterial:t}){const{focusMultiplier:r,calloutLength:i,discRadius:o}=l,s=o*r,d=(e,t)=>{const r=[0,1,2,2,3,0];return new m(t,[[p.POSITION,new c([i-e,-e,0,i+e,-e,0,i+e,e,0,i-e,e,0],r,3,!0)],[p.UV0,new c([0,0,1,0,1,1,0,1],r,2,!0)]])},f=u(t,[[0,0,0],[i-o,0,0]]),b=u(t,[[0,0,0],[i-s,0,0]]),g=n;return{autoScaleRenderObjects:!1,collisionPriority:1,collisionType:{type:"disc",direction:[0,0,1],offset:[i,0,0]},focusMultiplier:r,radius:o,renderObjects:[new a(d(o,e),w.Unfocused|g),new a(f,w.Unfocused|g),new a(d(s,e),w.Focused|g),new a(b,w.Focused|g)],state:g}}export{g as RotateManipulator};
5
+ import e from"../../../../Color.js";import{multiplyOpacity as t,getContrast as r}from"../../../../core/colorUtils.js";import{releaseMaybe as i}from"../../../../core/maybe.js";import{watch as o,initial as s}from"../../../../core/reactiveUtils.js";import{DidPointerMoveRecentlyFlag as n}from"./sliceToolUtils.js";import{Manipulator3D as l}from"../../interactive/Manipulator3D.js";import{rotateManipulatorDefaults as a}from"../../interactive/manipulatorUtils.js";import{RenderObject as c}from"../../interactive/RenderObject.js";import{Attribute as m}from"../../webgl-engine/lib/Attribute.js";import{Geometry as u}from"../../webgl-engine/lib/Geometry.js";import{createPolylineGeometry as d}from"../../webgl-engine/lib/GeometryUtil.js";import{RenderOccludedFlag as f}from"../../webgl-engine/lib/Material.js";import{VertexAttribute as p}from"../../webgl-engine/lib/VertexAttribute.js";import{ImageMaterial as b}from"../../webgl-engine/materials/ImageMaterial.js";import{RibbonLineMaterial as h}from"../../webgl-engine/materials/RibbonLineMaterial.js";import{ManipulatorStateFlags as j}from"../../../interactive/interfaces.js";class w extends l{constructor(i,n){const l=t(i.effectiveTheme.accentColor,.5),c=r(i.effectiveTheme.accentColor),m=n(l,c),u=new b({texture:m.texture,writeDepth:!1,renderOccluded:f.Opaque,isDecoration:!0}),d=a.calloutWidth,p=new h({width:d,renderOccluded:f.OccludeAndTransparent,isDecoration:!0});super({view:i,...g({imageMaterial:u,calloutMaterial:p})}),this._material=u,this._textureHandle=m,this._themeHandle=o((()=>i.effectiveTheme.accentColor),(i=>{const o=t(i,.5),s=r(i),l=this._textureHandle;this._textureHandle=n(o,s),u.setParameters({texture:this._textureHandle.texture}),l?.release(),p.setParameters({color:e.toUnitRGBA(i)})}),s)}destroy(){this._textureHandle=i(this._textureHandle),this._themeHandle.remove(),this._material.dispose(),super.destroy()}}function g({imageMaterial:e,calloutMaterial:t}){const{focusMultiplier:r,calloutLength:i,discRadius:o}=a,s=o*r,l=(e,t)=>{const r=[0,1,2,2,3,0];return new u(t,[[p.POSITION,new m([i-e,-e,0,i+e,-e,0,i+e,e,0,i-e,e,0],r,3,!0)],[p.UV0,new m([0,0,1,0,1,1,0,1],r,2,!0)]])},f=d(t,[[0,0,0],[i-o,0,0]]),b=d(t,[[0,0,0],[i-s,0,0]]),h=n;return{autoScaleRenderObjects:!1,collisionPriority:1,collisionType:{type:"disc",direction:[0,0,1],offset:[i,0,0]},focusMultiplier:r,radius:o,renderObjects:[new c(l(o,e),j.Unfocused|h),new c(f,j.Unfocused|h),new c(l(s,e),j.Focused|h),new c(b,j.Focused|h)],state:h}}export{w as RotateManipulator};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import"../../../core/has.js";import"../../../core/mathUtils.js";import"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import"../../../core/libs/gl-matrix-2/math/vec2.js";import"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import"./CloudsTechniqueConfiguration.js";import"./NoiseTextureAtlasDimensions.js";import"../webgl-engine/core/shaderLibrary/ScreenSpacePass.glsl.js";import"../webgl-engine/core/shaderModules/Float2PassUniform.js";import"../webgl-engine/core/shaderModules/FloatPassUniform.js";import"../webgl-engine/core/shaderModules/glsl.js";import"../webgl-engine/core/shaderModules/Matrix3PassUniform.js";import"../webgl-engine/core/shaderModules/Texture2DPassUniform.js";import"../webgl-engine/shaders/SphereIntersect.glsl.js";import"../../webgl/NoParameters.js";import"../../webgl/ShaderBuilder.js";export{C as CloudsPassParameters,b as build,c as cubeMapSize}from"../../../chunks/Clouds.glsl.js";
5
+ import"../../../core/has.js";import"../../../core/mathUtils.js";import"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import"../../../core/libs/gl-matrix-2/math/vec2.js";import"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import"./CloudsTechniqueConfiguration.js";import"./NoiseTextureAtlasDimensions.js";import"../webgl-engine/core/shaderLibrary/ScreenSpacePass.glsl.js";import"../webgl-engine/core/shaderModules/BooleanPassUniform.js";import"../webgl-engine/core/shaderModules/Float2PassUniform.js";import"../webgl-engine/core/shaderModules/FloatPassUniform.js";import"../webgl-engine/core/shaderModules/glsl.js";import"../webgl-engine/core/shaderModules/Matrix3PassUniform.js";import"../webgl-engine/core/shaderModules/Texture2DPassUniform.js";import"../webgl-engine/shaders/SphereIntersect.glsl.js";import"../../webgl/NoParameters.js";import"../../webgl/ShaderBuilder.js";export{C as CloudsPassParameters,b as build,c as cubeMapSize}from"../../../chunks/Clouds.glsl.js";
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{neverReached as a}from"../../../core/compilerUtils.js";import{clamp as t}from"../../../core/mathUtils.js";import{signal as e}from"../../../core/signal.js";import{rotate as s}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{IDENTITY as i,create as r}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{k as h,n as o,h as n,c,l as d,d as l}from"../../../chunks/vec32.js";import{create as _,fromValues as u}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as F,fromPoints as f,axis as p}from"../../../geometry/support/axisAngleDegrees.js";import{earth as S}from"../../../geometry/support/Ellipsoid.js";import{CloudsTextureChannels as m,ensureClouds as E,CubeMapState as D}from"./Clouds.js";import{heightLimit as P}from"./weather.js";class x{constructor(){this.startTime=0,this._data=e(null),this._readChannels=m.RG,this.parallax=new O,this.parallaxNew=new O,this._anchorPoint=_(),this._fadeState=e(A.HIDE),this._fadeFactor=e(1)}get data(){return this._data.value}set data(a){this._data.value=a}get readChannels(){return this._readChannels}get fadeState(){return this._fadeState.value}get fadeFactor(){return this._fadeFactor.value}get opacity(){switch(this.fadeState){case A.HIDE:return 0;case A.FADE_OUT:return 1-this.fadeFactor;case A.FADE_IN:return this.fadeFactor;case A.SHOW:case A.CROSS_FADE:return 1}}fade(a,e,s){this.isFading&&this.fadeFactor<1&&(this._fadeFactor.value=s?t((e-this.startTime)/(H*s),0,1):1,1===this.fadeFactor&&this._endFade()),this._evaluateState(a,e),this._updateParallax(a)}_evaluateState(a,t){const e=a.relativeElevation,s=this._updateAnchorPoint(a);(e>1.7*P||e<-1e4||s>I)&&this.opacity>0?this._startFade(A.HIDE,t):this.isFading||(e>P||e<-.35*P||s>w*I?this.opacity>0&&this._startFade(A.FADE_OUT,t):E(this.data)&&(0===this.opacity?this._startFade(A.FADE_IN,t):this.data.state===D.Ready&&(this.fadeState===A.SHOW?this._startFade(A.CROSS_FADE,t):this._startFade(A.SHOW,t))))}_updateParallax(a){const t=h(a.eye);this.parallax.radiusCurvatureCorrection=.84*Math.sqrt(Math.max(t-S.radius*S.radius,0))/Math.sqrt(t),f(C,this.parallax.anchorPoint,v),s(this.parallax.transform,i,v[3],p(v)),f(C,this.parallaxNew.anchorPoint,v),s(this.parallaxNew.transform,i,v[3],p(v))}_updateAnchorPoint(a){return o(this._anchorPoint,a.eye),n(this._anchorPoint,this._anchorPoint,S.radius),this.fadeState===A.HIDE&&this.data?.state===D.Ready?(c(this.parallax.anchorPoint,this._anchorPoint),0):d(l(g,this.parallax.anchorPoint,this._anchorPoint))}requestFade(){this._fadeFactor.value=0}_startFade(a,t){switch(this._fadeState.value=a,this.startTime=t,a){case A.CROSS_FADE:this.requestFade(),this._switchReadChannels(),c(this.parallaxNew.anchorPoint,this._anchorPoint);break;case A.FADE_IN:this.requestFade(),this._switchReadChannels(),c(this.parallax.anchorPoint,this._anchorPoint),c(this.parallaxNew.anchorPoint,this._anchorPoint);break;case A.FADE_OUT:this.requestFade();break;case A.SHOW:this._switchReadChannels(),c(this.parallax.anchorPoint,this._anchorPoint),c(this.parallaxNew.anchorPoint,this._anchorPoint),this._endFade();break;case A.HIDE:this._endFade()}}_endFade(){switch(this._fadeFactor.value=1,this.data&&this.data.state!==D.Ready&&(this.data.state=D.Idle),this.fadeState){case A.CROSS_FADE:c(this.parallax.anchorPoint,this.parallaxNew.anchorPoint),this._fadeState.value=A.SHOW;break;case A.FADE_IN:this._fadeState.value=A.SHOW;break;case A.FADE_OUT:this._fadeState.value=A.HIDE;break;case A.SHOW:case A.HIDE:break;default:a(this.fadeState)}}_switchReadChannels(){this.data?.state===D.Ready&&(this._readChannels=1-this._readChannels,this.data.state=D.Fading)}get isFading(){return this.fadeState===A.FADE_OUT||this.fadeState===A.FADE_IN||this.fadeState===A.CROSS_FADE}}var A;!function(a){a[a.HIDE=0]="HIDE",a[a.FADE_IN=1]="FADE_IN",a[a.SHOW=2]="SHOW",a[a.CROSS_FADE=3]="CROSS_FADE",a[a.FADE_OUT=4]="FADE_OUT"}(A||(A={}));class O{constructor(){this.anchorPoint=_(),this.radiusCurvatureCorrection=0,this.transform=r()}}const C=u(0,0,1),v=F(),g=_(),H=1.25,w=.5,I=2e5;export{x as CloudsParameters,A as FadeState};
5
+ import{neverReached as a}from"../../../core/compilerUtils.js";import{clamp as t}from"../../../core/mathUtils.js";import{signal as e}from"../../../core/signal.js";import{rotate as s}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{IDENTITY as i,create as r}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{k as h,n as o,h as n,c,l as d,d as l}from"../../../chunks/vec32.js";import{create as _,fromValues as u}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as F,fromPoints as f,axis as p}from"../../../geometry/support/axisAngleDegrees.js";import{earth as S}from"../../../geometry/support/Ellipsoid.js";import{CloudsTextureChannels as m,ensureClouds as E,CubeMapState as D}from"./Clouds.js";import{heightLimit as P}from"./weather.js";class x{constructor(){this.startTime=0,this._data=e(null),this.coverage=0,this.absorption=0,this._readChannels=m.RG,this.parallax=new O,this.parallaxNew=new O,this._anchorPoint=_(),this._fadeState=e(A.HIDE),this._fadeFactor=e(1)}get data(){return this._data.value}set data(a){this._data.value=a}get readChannels(){return this._readChannels}get fadeState(){return this._fadeState.value}get fadeFactor(){return this._fadeFactor.value}get opacity(){switch(this.fadeState){case A.HIDE:return 0;case A.FADE_OUT:return 1-this.fadeFactor;case A.FADE_IN:return this.fadeFactor;case A.SHOW:case A.CROSS_FADE:return 1}}fade(a,e,s){this.isFading&&this.fadeFactor<1&&(this._fadeFactor.value=s?t((e-this.startTime)/(H*s),0,1):1,1===this.fadeFactor&&this._endFade()),this._evaluateState(a,e),this._updateParallax(a)}_evaluateState(a,t){const e=a.relativeElevation,s=this._updateAnchorPoint(a);(e>1.7*P||e<-1e4||s>I)&&this.opacity>0?this._startFade(A.HIDE,t):this.isFading||(e>P||e<-.35*P||s>w*I?this.opacity>0&&this._startFade(A.FADE_OUT,t):E(this.data)&&(0===this.opacity?this._startFade(A.FADE_IN,t):this.data.state===D.Ready&&(this.fadeState===A.SHOW?this._startFade(A.CROSS_FADE,t):this._startFade(A.SHOW,t))))}_updateParallax(a){const t=h(a.eye);this.parallax.radiusCurvatureCorrection=.84*Math.sqrt(Math.max(t-S.radius*S.radius,0))/Math.sqrt(t),f(v,this.parallax.anchorPoint,C),s(this.parallax.transform,i,C[3],p(C)),f(v,this.parallaxNew.anchorPoint,C),s(this.parallaxNew.transform,i,C[3],p(C))}_updateAnchorPoint(a){return o(this._anchorPoint,a.eye),n(this._anchorPoint,this._anchorPoint,S.radius),this.fadeState===A.HIDE&&this.data?.state===D.Ready?(c(this.parallax.anchorPoint,this._anchorPoint),0):d(l(g,this.parallax.anchorPoint,this._anchorPoint))}requestFade(){this._fadeFactor.value=0}_startFade(a,t){switch(this._fadeState.value=a,this.startTime=t,a){case A.CROSS_FADE:this.requestFade(),this._switchReadChannels(),c(this.parallaxNew.anchorPoint,this._anchorPoint);break;case A.FADE_IN:this.requestFade(),this._switchReadChannels(),c(this.parallax.anchorPoint,this._anchorPoint),c(this.parallaxNew.anchorPoint,this._anchorPoint);break;case A.FADE_OUT:this.requestFade();break;case A.SHOW:this._switchReadChannels(),c(this.parallax.anchorPoint,this._anchorPoint),c(this.parallaxNew.anchorPoint,this._anchorPoint),this._endFade();break;case A.HIDE:this._endFade()}}_endFade(){switch(this._fadeFactor.value=1,this.data&&this.data.state!==D.Ready&&(this.data.state=D.Idle),this.fadeState){case A.CROSS_FADE:c(this.parallax.anchorPoint,this.parallaxNew.anchorPoint),this._fadeState.value=A.SHOW;break;case A.FADE_IN:this._fadeState.value=A.SHOW;break;case A.FADE_OUT:this._fadeState.value=A.HIDE;break;case A.SHOW:case A.HIDE:break;default:a(this.fadeState)}}_switchReadChannels(){this.data?.state===D.Ready&&(this._readChannels=1-this._readChannels,this.data.state=D.Fading)}get isFading(){return this.fadeState===A.FADE_OUT||this.fadeState===A.FADE_IN||this.fadeState===A.CROSS_FADE}}var A;!function(a){a[a.HIDE=0]="HIDE",a[a.FADE_IN=1]="FADE_IN",a[a.SHOW=2]="SHOW",a[a.CROSS_FADE=3]="CROSS_FADE",a[a.FADE_OUT=4]="FADE_OUT"}(A||(A={}));class O{constructor(){this.anchorPoint=_(),this.radiusCurvatureCorrection=0,this.transform=r()}}const v=u(0,0,1),C=F(),g=_(),H=1.25,w=.5,I=2e5;export{x as CloudsParameters,A as FadeState};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../../../chunks/tslib.es6.js";import e from"../../../core/Accessor.js";import{neverReached as s}from"../../../core/compilerUtils.js";import{lerp as i}from"../../../core/mathUtils.js";import{destroyMaybe as r,disposeMaybe as o}from"../../../core/maybe.js";import{watch as a,initial as n}from"../../../core/reactiveUtils.js";import{signal as h}from"../../../core/signal.js";import{property as c}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import{fromMat4 as u}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{targetTo as d}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{create as p}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as m,equals as f,copy as _}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{clone as g,ZEROS as x,zeros as y}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{fromValues as T}from"../../../core/libs/gl-matrix-2/factories/vec3f32.js";import{zeros as b}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as v}from"../../../geometry/ellipsoidUtils.js";import{CubeMapState as C,CloudsTextureChannels as w}from"./Clouds.js";import{C as S,c as j}from"../../../chunks/Clouds.glsl.js";import{cloudPresets as P}from"./CloudsPresets.js";import{CloudsTechnique as z}from"./CloudsTechnique.js";import{CloudsTechniqueConfiguration as R,RayMarchingSteps as M}from"./CloudsTechniqueConfiguration.js";import{NoiseTextureAtlas as I}from"./NoiseTextureAtlas.js";import{TaskPriority as H}from"../../support/Scheduler.js";import{Yield as U}from"../../support/Yield.js";import{TextureType as q,TextureWrapMode as A,ColorAttachment as D}from"../../webgl/enums.js";import{FramebufferObject as E}from"../../webgl/FramebufferObject.js";import{TextureDescriptor as F}from"../../webgl/TextureDescriptor.js";let O=class extends e{constructor(t){super(t),this._state=h(C.Idle),this._passParameters=new S,this._weatherTileCount=128,this._faceIndex=0,this._tileIndex=0,this._tilesPerFace=1,this.coverage=i(P.default.coverage[0],P.default.coverage[1],.5),this.density=i(P.default.density[0],P.default.density[1],.5),this.absorption=i(P.default.absorption[0],P.default.absorption[1],.5),this.cloudSize=i(P.default.cloudSize[0],P.default.cloudSize[1],.5),this.detailSize=i(P.default.detailSize[0],P.default.detailSize[1],.5),this.smoothness=i(P.default.smoothness[0],P.default.smoothness[1],.5),this.cloudHeight=i(P.default.cloudHeight[0],P.default.cloudHeight[1],.5),this.raymarchingSteps=P.default.raymarchingSteps,this._viewMatrix=p(),this._dirty=!0,this.running=!0,this._configuration=new R}initialize(){const t=v(this.view.spatialReference);this._passParameters.cloudRadius=.5*t.radius;const e=()=>this.setDirty();this.addHandles([this.view.resourceController.scheduler.registerTask(H.CLOUDS_GENERATOR,this),a((()=>this.coverage),e,n),a((()=>this.density),e,n),a((()=>this.absorption),e,n),a((()=>this.cloudSize),e,n),a((()=>this.detailSize),e,n),a((()=>this.smoothness),e,n),a((()=>this.cloudHeight),e,n),a((()=>this.raymarchingSteps),e,n)]);const s=g(this._computeWeatherTile());let i=0;this.addHandles(a((()=>{const t=this._computeWeatherTile();return f(s,t)||(++i,_(s,t)),i}),e))}destroy(){this.destroyCubeMap(),this._passParameters.noiseTexture=r(this._passParameters.noiseTexture)}_precompileTechniques(){this._configuration.steps=this.raymarchingSteps,this._configuration.writeTextureChannels=w.RG,this.context.techniques.precompile(z,this._configuration),this._configuration.writeTextureChannels=w.BA,this.context.techniques.precompile(z,this._configuration)}_acquireTechnique(){switch(this.raymarchingSteps){case M.SIXTEEN:this._tilesPerFace=1;break;case M.HUNDRED:this._tilesPerFace=4;break;case M.COUNT:case M.TWOHUNDRED:this._tilesPerFace=8;break;default:s(this.raymarchingSteps)}return this._configuration.writeTextureChannels=1-this.parameters.readChannels,this._configuration.steps=this.raymarchingSteps,this.context.techniques.get(z,this._configuration)}_computeWeatherTile(){const{camera:t,environment:e}=this.view,{latitude:s,longitude:i}=t.position;if(null==s||null==i)return x;m(L,(s+90)/180,(i+180)/360);const r=Math.floor(this._weatherTileCount*Math.abs(2*L[0]-1));L[0]=Math.floor(2*this._weatherTileCount*L[0]),L[1]=Math.floor(4*(this._weatherTileCount-r)*L[1]);let o=0,a=0;if("virtual"!==e?.lighting?.type&&null!=e?.lighting?.date){const t=new Date(e.lighting.date);t.setUTCHours(e.lighting.date.getUTCHours()+(e.lighting.displayUTCOffset??0)),o=31*t.getUTCMonth()+t.getUTCDate(),a=t.getUTCFullYear()}return L[0]=(L[0]+o)%(2*this._weatherTileCount),L[1]=(L[1]+a%100)%(4*this._weatherTileCount),L}get state(){return this._state.value}set state(t){this._state.value=t}get usedMemory(){return(this._fbo?.usedMemory??0)+(this._passParameters.noiseTexture?.textureAtlas?.usedMemory??0)}_ensureNoiseTexture(){return this._passParameters.noiseTexture??=new I({context:this.context}),this._passParameters.noiseTexture}_ensureFrameBufferCube(t){const e=this.context.renderContext.rctx;if(null==this._fbo){const s=new F(t);s.target=q.TEXTURE_2D_ARRAY,s.depth=5,s.wrapMode=A.CLAMP_TO_EDGE,this._fbo=new E(e,s),this.parameters.data=this}return e.unbindTexture(this._fbo.colorTexture),this._fbo}get cubeMap(){return this._fbo}get parameters(){return this.context.renderContext.bind.clouds}destroyCubeMap(){this._fbo=o(this._fbo),this.parameters.data=null}applyPreset(t,e){const s=t.median,r=t=>{const r=i(t[0],t[1],s);return e<.5?i(t[0],r,2*e):i(r,t[1],2*(e-.5))};this.coverage=r(t.coverage),this.density=r(t.density),this.absorption=r(t.absorption),this.cloudSize=r(t.cloudSize),this.detailSize=r(t.detailSize),this.smoothness=r(t.smoothness),this.cloudHeight=r(t.cloudHeight),this.raymarchingSteps=t.raymarchingSteps,this._precompileTechniques()}setDirty(){this._dirty=this.running=!0}runTask(t){if(this.state===C.Fading)return U;this._dirty&&(this._faceIndex=this._tileIndex=0,this.state=C.Rendering,this._passParameters.absorption=this.absorption,this._passParameters.density=this.density,this._passParameters.cloudSize=this.cloudSize,this._passParameters.detailSize=this.detailSize,this._passParameters.smoothness=this.smoothness,this._passParameters.cloudHeight=this.cloudHeight,this._passParameters.coverage=this.coverage,this._ensureNoiseTexture().updateWeatherMap(this._computeWeatherTile()),this._dirty=!1);const e=this._acquireTechnique();if(!this._ensureNoiseTexture().textureAtlas||!e.compiled)return U;const s=N[this._faceIndex],i=k[this._faceIndex];d(this._viewMatrix,W,s,i),u(this._passParameters.viewMatrix,this._viewMatrix);const r=this.context.renderContext.rctx,o=r.getViewport(),a=j/this._tilesPerFace,n=this._tileIndex*a;r.setViewport(0,n,j,a);const h=this._ensureFrameBufferCube(j);r.bindFramebuffer(h),r.bindTechnique(e,this.context.renderContext.bind,this._passParameters);const c=q.TEXTURE_2D_ARRAY;return h.setColorTextureTarget(c,D.COLOR_ATTACHMENT0,this._faceIndex),r.screen.draw(),r.gl.flush(),r.setViewport(o.x,o.y,o.width,o.height),this.requestRender(),++this._tileIndex,4===this._faceIndex&&this._tileIndex===this._tilesPerFace?(this._faceIndex=this._tileIndex=0,this.state=C.Ready,this.running=!1):this._tileIndex===this._tilesPerFace&&(++this._faceIndex,this._tileIndex=0),t.madeProgress(),U}};t([c({constructOnly:!0})],O.prototype,"context",void 0),t([c({constructOnly:!0})],O.prototype,"view",void 0),t([c({constructOnly:!0})],O.prototype,"requestRender",void 0),t([c()],O.prototype,"coverage",void 0),t([c()],O.prototype,"density",void 0),t([c()],O.prototype,"absorption",void 0),t([c()],O.prototype,"cloudSize",void 0),t([c()],O.prototype,"detailSize",void 0),t([c()],O.prototype,"smoothness",void 0),t([c()],O.prototype,"cloudHeight",void 0),t([c()],O.prototype,"raymarchingSteps",void 0),t([c()],O.prototype,"running",void 0),O=t([l("esri.views.3d.environment.CloudsRenderer")],O);const N=[T(1,0,0),T(-1,0,0),T(0,1,0),T(0,-1,0),T(0,0,1)],k=[T(0,1,0),T(0,1,0),T(0,0,-1),T(0,0,1),T(0,1,0)],W=b(),L=y();export{O as CloudsRenderer};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import{neverReached as s}from"../../../core/compilerUtils.js";import{lerp as i}from"../../../core/mathUtils.js";import{destroyMaybe as r,disposeMaybe as o}from"../../../core/maybe.js";import{watch as a,initial as n}from"../../../core/reactiveUtils.js";import{signal as h}from"../../../core/signal.js";import{property as l}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import{fromMat4 as u}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{targetTo as d}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{create as p}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as m,equals as _,copy as f}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{clone as g,ZEROS as x,zeros as y}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{fromValues as T}from"../../../core/libs/gl-matrix-2/factories/vec3f32.js";import{zeros as b}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as v}from"../../../geometry/ellipsoidUtils.js";import{CubeMapState as S,CloudsTextureChannels as C}from"./Clouds.js";import{C as w,c as j}from"../../../chunks/Clouds.glsl.js";import{cloudPresets as P}from"./CloudsPresets.js";import{CloudsTechnique as z}from"./CloudsTechnique.js";import{CloudsTechniqueConfiguration as R,RayMarchingSteps as I}from"./CloudsTechniqueConfiguration.js";import{NoiseTextureAtlas as M}from"./NoiseTextureAtlas.js";import{TaskPriority as H}from"../../support/Scheduler.js";import{Yield as U}from"../../support/Yield.js";import{TextureType as q,TextureWrapMode as A,ColorAttachment as D}from"../../webgl/enums.js";import{FramebufferObject as E}from"../../webgl/FramebufferObject.js";import{TextureDescriptor as O}from"../../webgl/TextureDescriptor.js";let N=class extends t{constructor(e){super(e),this._state=h(S.Idle),this._passParameters=new w,this._weatherTileCount=128,this._sliceIndex=0,this._tileIndex=0,this._tilesPerSlice=1,this.coverage=i(P.default.coverage[0],P.default.coverage[1],.5),this.density=i(P.default.density[0],P.default.density[1],.5),this.absorption=i(P.default.absorption[0],P.default.absorption[1],.5),this.cloudSize=i(P.default.cloudSize[0],P.default.cloudSize[1],.5),this.detailSize=i(P.default.detailSize[0],P.default.detailSize[1],.5),this.smoothness=i(P.default.smoothness[0],P.default.smoothness[1],.5),this.cloudHeight=i(P.default.cloudHeight[0],P.default.cloudHeight[1],.5),this.raymarchingSteps=P.default.raymarchingSteps,this._viewMatrix=p(),this._dirty=!0,this.running=!0,this._configuration=new R}initialize(){const e=v(this.view.spatialReference);this._passParameters.cloudRadius=.5*e.radius;const t=()=>this.setDirty();this.addHandles([this.view.resourceController.scheduler.registerTask(H.CLOUDS_GENERATOR,this),a((()=>this.coverage),t,n),a((()=>this.density),t,n),a((()=>this.absorption),t,n),a((()=>this.cloudSize),t,n),a((()=>this.detailSize),t,n),a((()=>this.smoothness),t,n),a((()=>this.cloudHeight),t,n),a((()=>this.raymarchingSteps),t,n)]);const s=g(this._computeWeatherTile());let i=0;this.addHandles(a((()=>{const e=this._computeWeatherTile();return _(s,e)||(++i,f(s,e)),i}),t))}destroy(){this.destroyCubeMap(),this._passParameters.noiseTexture=r(this._passParameters.noiseTexture)}_precompileTechniques(){this._configuration.steps=this.raymarchingSteps,this._configuration.writeTextureChannels=C.RG,this.context.techniques.precompile(z,this._configuration),this._configuration.writeTextureChannels=C.BA,this.context.techniques.precompile(z,this._configuration)}_acquireTechnique(){switch(this.raymarchingSteps){case I.SIXTEEN:this._tilesPerSlice=1;break;case I.HUNDRED:this._tilesPerSlice=4;break;case I.COUNT:case I.TWOHUNDRED:this._tilesPerSlice=8;break;default:s(this.raymarchingSteps)}return this._configuration.writeTextureChannels=1-this.parameters.readChannels,this._configuration.steps=this.raymarchingSteps,this.context.techniques.get(z,this._configuration)}_computeWeatherTile(){const{camera:e,environment:t}=this.view,{latitude:s,longitude:i}=e.position;if(null==s||null==i)return x;m(L,(s+90)/180,(i+180)/360);const r=Math.floor(this._weatherTileCount*Math.abs(2*L[0]-1));L[0]=Math.floor(2*this._weatherTileCount*L[0]),L[1]=Math.floor(4*(this._weatherTileCount-r)*L[1]);let o=0,a=0;if("virtual"!==t?.lighting?.type&&null!=t?.lighting?.date){const e=new Date(t.lighting.date);e.setUTCHours(t.lighting.date.getUTCHours()+(t.lighting.displayUTCOffset??0)),o=31*e.getUTCMonth()+e.getUTCDate(),a=e.getUTCFullYear()}return L[0]=(L[0]+o)%(2*this._weatherTileCount),L[1]=(L[1]+a%100)%(4*this._weatherTileCount),L}get state(){return this._state.value}set state(e){this._state.value=e}get usedMemory(){return(this._fbo?.usedMemory??0)+(this._passParameters.noiseTexture?.textureAtlas?.usedMemory??0)}_ensureNoiseTexture(){return this._passParameters.noiseTexture??=new M({context:this.context}),this._passParameters.noiseTexture}_ensureFrameBufferCube(e){const t=this.context.renderContext.rctx;if(null==this._fbo){const s=new O(e,e/2);s.target=q.TEXTURE_2D_ARRAY,s.depth=6,s.wrapMode=A.CLAMP_TO_EDGE,this._fbo=new E(t,s),this.parameters.data=this,this.parameters.absorption=this.absorption,this.parameters.coverage=this.coverage}return t.unbindTexture(this._fbo.colorTexture),this._fbo}get cubeMap(){return this._fbo}get parameters(){return this.context.renderContext.bind.clouds}destroyCubeMap(){this._fbo=o(this._fbo),this.parameters.data=null}applyPreset(e,t){const s=e.median,r=e=>{const r=i(e[0],e[1],s);return t<.5?i(e[0],r,2*t):i(r,e[1],2*(t-.5))};this.coverage=r(e.coverage),this.density=r(e.density),this.absorption=r(e.absorption),this.cloudSize=r(e.cloudSize),this.detailSize=r(e.detailSize),this.smoothness=r(e.smoothness),this.cloudHeight=r(e.cloudHeight),this.raymarchingSteps=e.raymarchingSteps,this._precompileTechniques()}setDirty(){this._dirty=this.running=!0}runTask(e){if(this.state===S.Fading)return U;this._dirty&&(this._sliceIndex=this._tileIndex=0,this.state=S.Rendering,this._passParameters.absorption=this.absorption,this._passParameters.density=this.density,this._passParameters.cloudSize=this.cloudSize,this._passParameters.detailSize=this.detailSize,this._passParameters.smoothness=this.smoothness,this._passParameters.cloudHeight=this.cloudHeight,this._passParameters.coverage=this.coverage,this._ensureNoiseTexture().updateWeatherMap(this._computeWeatherTile()),this._dirty=!1);const t=this._acquireTechnique();if(!this._ensureNoiseTexture().textureAtlas||!t.compiled)return U;const s=k[this._sliceIndex],i=F[this._sliceIndex];d(this._viewMatrix,W,s,i),u(this._passParameters.viewMatrix,this._viewMatrix);const r=this.context.renderContext.rctx,o=r.getViewport(),a=j/this._tilesPerSlice,n=this._tileIndex*a;r.setViewport(0,n,j,a);const h=this._ensureFrameBufferCube(j);r.bindFramebuffer(h),this._passParameters.lastSlice=5===this._sliceIndex,r.bindTechnique(t,this.context.renderContext.bind,this._passParameters);const l=q.TEXTURE_2D_ARRAY;return h.setColorTextureTarget(l,D.COLOR_ATTACHMENT0,this._sliceIndex),r.screen.draw(),r.gl.flush(),r.setViewport(o.x,o.y,o.width,o.height),this.requestRender(),++this._tileIndex,5===this._sliceIndex&&this._tileIndex===this._tilesPerSlice?(this._sliceIndex=this._tileIndex=0,this.state=S.Ready,this.running=!1):this._tileIndex===this._tilesPerSlice&&(++this._sliceIndex,this._tileIndex=0),e.madeProgress(),U}};e([l({constructOnly:!0})],N.prototype,"context",void 0),e([l({constructOnly:!0})],N.prototype,"view",void 0),e([l({constructOnly:!0})],N.prototype,"requestRender",void 0),e([l()],N.prototype,"coverage",void 0),e([l()],N.prototype,"density",void 0),e([l()],N.prototype,"absorption",void 0),e([l()],N.prototype,"cloudSize",void 0),e([l()],N.prototype,"detailSize",void 0),e([l()],N.prototype,"smoothness",void 0),e([l()],N.prototype,"cloudHeight",void 0),e([l()],N.prototype,"raymarchingSteps",void 0),e([l()],N.prototype,"running",void 0),N=e([c("esri.views.3d.environment.CloudsRenderer")],N);const k=[T(1,0,0),T(-1,0,0),T(0,1,0),T(0,-1,0),T(0,0,1),T(0,0,1)],F=[T(0,0,-1),T(0,0,-1),T(0,0,-1),T(0,0,-1),T(0,1,0),T(0,1,0)],W=b(),L=y();export{N as CloudsRenderer};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import{forEach as t,result as r}from"../../../core/asyncUtils.js";import{makeHandle as i}from"../../../core/handleUtils.js";import s from"../../../core/Logger.js";import{abortMaybe as a}from"../../../core/maybe.js";import{debounce as o,isAbortError as n,onAbort as l,isAborted as h,createAbortError as m,throwIfAborted as d}from"../../../core/promiseUtils.js";import{whenOnce as c}from"../../../core/reactiveUtils.js";import{property as g}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/RandomLCG.js";import{subclass as u}from"../../../core/accessorSupport/decorators/subclass.js";import p from"../../../geometry/Extent.js";import{equals as f,create as y,width as w,height as _,copy as x,intersection as v}from"../../../geometry/support/aaBoundingRect.js";import{DrapeSourceType as R}from"./interfaces.js";import{LayerView3D as b}from"./LayerView3D.js";import{computeImageExportSize as E,createGeometryForExtent as j,createOuterImageGeometry as S}from"./support/overlayImageUtils.js";import{toViewIfLocal as I}from"./support/projectExtentUtils.js";import{debugFlags as A}from"../support/debugFlags.js";import{OverlayIndex as D}from"../terrain/interfaces.js";import{DirtyOperation as M}from"../webgl-engine/lib/ModelDirtyTypes.js";import{RenderGeometry as L}from"../webgl-engine/lib/RenderGeometry.js";import{Texture as C}from"../webgl-engine/lib/Texture.js";import{UpdatePolicy as G}from"../webgl-engine/lib/UpdatePolicy.js";import{ImageMaterial as P}from"../webgl-engine/materials/ImageMaterial.js";import T from"../../layers/LayerView.js";import O from"../../layers/RefreshableLayerView.js";import{isInEffectiveScaleRange as U}from"../../support/layerViewUtils.js";import{TextureWrapMode as H}from"../../webgl/enums.js";let V=class extends(O(b(T))){constructor(){super(...arguments),this.drapeSourceType=R.RasterImage,this.updatePolicy=G.SYNC,this.fullExtentInLocalViewSpatialReference=null,this.maximumDataResolution=null,this._images=new Array,this._extents=new Array,this._overlays=new Array,this.updateWhenStationary=!0,this._drapeSourceRenderer=null,this.refreshDebounced=o((async e=>{this.destroyed||await this._doRefresh(e).catch((e=>{n(e)||s.getLogger(this).error(e)}))}),2e3)}get visibleAtCurrentScale(){const e=this.layer,t="effectiveScaleRange"in e?e.effectiveScaleRange:null;return U(t,this.view.scale)}initialize(){this._drapeSourceRenderer=this.view.basemapTerrain.overlayManager.registerGeometryDrapeSource(this),this.addHandles(i((()=>this.view.basemapTerrain.overlayManager.unregisterDrapeSource(this)))),this.addResolvingPromise(I(this).then((e=>this._set("fullExtentInLocalViewSpatialReference",e)))),this._updatingHandles.add((()=>this.suspended),(()=>this._suspendedChangeHandler()))}destroy(){this.clear()}setDrapingExtent(e,t){this._spatialReference=t,e.forEach(((e,t)=>{this._overlays[t]=e,this._updateImageExtent(e,t)}))}_updateImageExtent(e,t){const r=this._clippedExtent(e.extent,z);if(null==r)return;const i=E(e.extent,r,e.resolution);let a=e.pixelRatio*this.view.state.pixelRatio;const{layer:o}=this;if("imageMaxWidth"in o&&null!=o.imageMaxWidth||"imageMaxHeight"in o&&null!=o.imageMaxHeight){const e=o.imageMaxWidth,t=o.imageMaxHeight;if(i.width>e){const t=e/i.width;i.height=Math.floor(i.height*t),i.width=e,a*=t}if(i.height>t){const e=t/i.height;i.width=Math.floor(i.width*e),i.height=t,a*=e}}const l=this._extents[t];l&&f(l.extent,r)&&this._imageSizeEquals(r,l.imageSize,i)||(this._extents[t]={extent:y(r),imageSize:i,pixelRatio:a},this.suspended||this._fetch(t).catch((e=>{n(e)||s.getLogger(this).error(e)})))}clear(){for(let e=0;e<this._images.length;e++)this._clearImage(e)}async doRefresh(){return this._doRefresh()}async _doRefresh(e){if(this.suspended)return;const t=[];for(let r=0;r<this._extents.length;r++)this._extents[r]&&t.push(this._fetch(r,e));await Promise.allSettled(t)}async processResult(e,t,r){(t instanceof HTMLImageElement||t instanceof HTMLCanvasElement)&&(e.image=t)}findExtentInfoAt(e){for(const t of this._extents){const r=t.extent;if(new p(r[0],r[1],r[2],r[3],this._spatialReference).contains(e))return t}return null}getFetchOptions(){}async redraw(e,r){await t(this._images,(async(t,i)=>{t&&(await e(t,r),await this._createStageObjects(i,t.image,r))}))}_imageSizeEquals(e,t,r){if(!this.maximumDataResolution)return!1;const i=w(e)/this.maximumDataResolution.x,s=_(e)/this.maximumDataResolution.y,a=i/t.width,o=s/t.height,n=i/r.width,l=s/r.height,h=Math.abs(a-n),m=Math.abs(o-l),d=A.TESTS_DISABLE_OPTIMIZATIONS?0:1.5;return h<=d&&m<=d}async _fetch(e,t){if(this.suspended)return;const r=this._extents[e],i=r.extent;this._images[e]||(this._images[e]={texture:null,material:null,renderGeometry:null,loadingPromise:null,loadingAbortController:null,image:null,pixelData:null,renderExtent:y(i)});const o=this._images[e];o.loadingAbortController=a(o.loadingAbortController);const c=new p(i[0],i[1],i[2],i[3],this._spatialReference);if(0===c.width||0===c.height)return void this._clearImage(e);const g=new AbortController;o.loadingAbortController=g,l(t,(()=>g.abort()));const u=g.signal,f=this._waitFetchReady(u).then((async()=>{const t={requestAsImageElement:!0,pixelRatio:this._overlays[e].pixelRatio,...this.getFetchOptions(),signal:u},{height:i,width:s}=r.imageSize;return"imagery"===this.layer.type?this.layer.internalFetchImage(c,s,i,t):this.layer.fetchImage(c,s,i,t)})).then((e=>{if(h(u))throw s.getLogger(this).warnOnce("A call to fetchImage resolved even though the request was aborted. fetchImage should not resolve if options.signal.aborted is true."),m();return this.processResult(o,e)})).then((()=>{x(o.renderExtent,i)}));o.loadingPromise=f,await this._updatingHandles.addPromise(f.then((async()=>{d(u),await this._createStageObjects(e,o.image,u)})).catch((e=>{throw e&&!n(e)&&s.getLogger(this).error(e),e})).finally((()=>{f===o.loadingPromise&&(o.loadingPromise=null,o.loadingAbortController=null)})))}_clearImage(e){const t=this._images[e];if(t){null!=t.renderGeometry&&(this._drapeSourceRenderer.removeGeometries([t.renderGeometry],M.UPDATE),t.renderGeometry=null);const e=this.view._stage,r=t.texture;r?.unload(),e.remove(r),t.texture=null,e.remove(t.material),t.material=null,t.loadingAbortController=a(t.loadingAbortController),t.loadingPromise=null,t.image=null,t.pixelData=null}}async _createStageObjects(e,t,i){const s=this.view._stage,a=this._images[e],o=()=>{a.texture?.unload(),s.remove(a.texture),a.texture=null,a.renderGeometry&&(this._drapeSourceRenderer.removeGeometries([a.renderGeometry],M.UPDATE),a.renderGeometry=null)};if(t){const n=new C(t,{width:t.width,height:t.height,preMultiplyAlpha:!0,wrap:{s:H.CLAMP_TO_EDGE,t:H.CLAMP_TO_EDGE}});let l;if(await r(this._images[e===D.INNER?D.OUTER:D.INNER].loadingPromise),d(i),o(),await s.schedule((()=>n.load(s.renderView.renderingContext)),i),s.add(n),a.texture=n,null==a.material?(a.material=new P({textureId:n.id}),s.add(a.material)):a.material.setParameters({textureId:n.id}),e===D.INNER)l=j(a.material,a.renderExtent);else{const e=this._images[0].renderExtent;if(!e)return void o();l=S(a.material,e,a.renderExtent)}a.renderGeometry=new L(l),a.renderGeometry.localOrigin=this._overlays[e].renderLocalOrigin,this._drapeSourceRenderer.addGeometries([a.renderGeometry],M.UPDATE)}else o(),s.remove(a.material),a.material=null}_clippedExtent(e,t){if("local"!==this.view.viewingMode)return x(t,e);const r=this.view.basemapTerrain;return r.ready?v(e,r.extent,t):x(t,e)}_suspendedChangeHandler(){this.suspended?this.clear():this.refreshDebounced()}async _waitFetchReady(e){await c((()=>this.view.stationary),e),d(e)}};e([g()],V.prototype,"layer",void 0),e([g()],V.prototype,"suspended",void 0),e([g({readOnly:!0})],V.prototype,"fullExtentInLocalViewSpatialReference",void 0),e([g({readOnly:!0})],V.prototype,"visibleAtCurrentScale",null),e([g()],V.prototype,"updating",void 0),V=e([u("esri.views.3d.layers.DynamicLayerView3D")],V);const N=V,z=y();export{N as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import{forEach as t,result as r}from"../../../core/asyncUtils.js";import{makeHandle as i}from"../../../core/handleUtils.js";import s from"../../../core/Logger.js";import{abortMaybe as a}from"../../../core/maybe.js";import{debounce as o,isAbortError as n,onAbort as l,isAborted as h,createAbortError as m,throwIfAborted as d}from"../../../core/promiseUtils.js";import{whenOnce as c}from"../../../core/reactiveUtils.js";import{property as g}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/RandomLCG.js";import{subclass as u}from"../../../core/accessorSupport/decorators/subclass.js";import p from"../../../geometry/Extent.js";import{equals as f,create as y,width as w,height as _,copy as x,intersection as v}from"../../../geometry/support/aaBoundingRect.js";import{DrapeSourceType as R}from"./interfaces.js";import{LayerView3D as b}from"./LayerView3D.js";import{computeImageExportSize as E,createGeometryForExtent as j,createOuterImageGeometry as S}from"./support/overlayImageUtils.js";import{toViewIfLocal as I}from"./support/projectExtentUtils.js";import{debugFlags as A}from"../support/debugFlags.js";import{OverlayIndex as D}from"../terrain/interfaces.js";import{DirtyOperation as M}from"../webgl-engine/lib/ModelDirtyTypes.js";import{RenderGeometry as L}from"../webgl-engine/lib/RenderGeometry.js";import{Texture as C}from"../webgl-engine/lib/Texture.js";import{UpdatePolicy as G}from"../webgl-engine/lib/UpdatePolicy.js";import{ImageMaterial as P}from"../webgl-engine/materials/ImageMaterial.js";import T from"../../layers/LayerView.js";import O from"../../layers/RefreshableLayerView.js";import{isInEffectiveScaleRange as U}from"../../support/layerViewUtils.js";import{TextureWrapMode as H}from"../../webgl/enums.js";let V=class extends(O(b(T))){constructor(){super(...arguments),this.drapeSourceType=R.RasterImage,this.updatePolicy=G.SYNC,this.fullExtentInLocalViewSpatialReference=null,this.maximumDataResolution=null,this._images=new Array,this._extents=new Array,this._overlays=new Array,this.updateWhenStationary=!0,this._drapeSourceRenderer=null,this.refreshDebounced=o((async e=>{this.destroyed||await this._doRefresh(e).catch((e=>{n(e)||s.getLogger(this).error(e)}))}),2e3)}get visibleAtCurrentScale(){const e=this.layer,t="effectiveScaleRange"in e?e.effectiveScaleRange:null;return U(t,this.view.scale)}initialize(){this._drapeSourceRenderer=this.view.basemapTerrain.overlayManager.registerGeometryDrapeSource(this),this.addHandles(i((()=>this.view.basemapTerrain.overlayManager.unregisterDrapeSource(this)))),this.addResolvingPromise(I(this).then((e=>this._set("fullExtentInLocalViewSpatialReference",e)))),this._updatingHandles.add((()=>this.suspended),(()=>this._suspendedChangeHandler()))}destroy(){this.clear()}setDrapingExtent(e,t){this._spatialReference=t,e.forEach(((e,t)=>{this._overlays[t]=e,this._updateImageExtent(e,t)}))}_updateImageExtent(e,t){const r=this._clippedExtent(e.extent,z);if(null==r)return;const i=E(e.extent,r,e.resolution);let a=e.pixelRatio*this.view.state.pixelRatio;const{layer:o}=this;if("imageMaxWidth"in o&&null!=o.imageMaxWidth||"imageMaxHeight"in o&&null!=o.imageMaxHeight){const e=o.imageMaxWidth,t=o.imageMaxHeight;if(i.width>e){const t=e/i.width;i.height=Math.floor(i.height*t),i.width=e,a*=t}if(i.height>t){const e=t/i.height;i.width=Math.floor(i.width*e),i.height=t,a*=e}}const l=this._extents[t];l&&f(l.extent,r)&&this._imageSizeEquals(r,l.imageSize,i)||(this._extents[t]={extent:y(r),imageSize:i,pixelRatio:a},this.suspended||this._fetch(t).catch((e=>{n(e)||s.getLogger(this).error(e)})))}clear(){for(let e=0;e<this._images.length;e++)this._clearImage(e)}async doRefresh(){return this._doRefresh()}async _doRefresh(e){if(this.suspended)return;const t=[];for(let r=0;r<this._extents.length;r++)this._extents[r]&&t.push(this._fetch(r,e));await Promise.allSettled(t)}async processResult(e,t,r){(t instanceof HTMLImageElement||t instanceof HTMLCanvasElement)&&(e.image=t)}findExtentInfoAt(e){for(const t of this._extents){const r=t.extent;if(new p(r[0],r[1],r[2],r[3],this._spatialReference).contains(e))return t}return null}getFetchOptions(){}async redraw(e,r){await t(this._images,(async(t,i)=>{t&&(await e(t,r),await this._createStageObjects(i,t.image,r))}))}_imageSizeEquals(e,t,r){if(!this.maximumDataResolution)return!1;const i=w(e)/this.maximumDataResolution.x,s=_(e)/this.maximumDataResolution.y,a=i/t.width,o=s/t.height,n=i/r.width,l=s/r.height,h=Math.abs(a-n),m=Math.abs(o-l),d=A.TESTS_DISABLE_OPTIMIZATIONS?0:1.5;return h<=d&&m<=d}async _fetch(e,t){if(this.suspended)return;const r=this._extents[e],i=r.extent;this._images[e]||(this._images[e]={texture:null,material:null,renderGeometry:null,loadingPromise:null,loadingAbortController:null,image:null,pixelData:null,renderExtent:y(i)});const o=this._images[e];o.loadingAbortController=a(o.loadingAbortController);const c=new p(i[0],i[1],i[2],i[3],this._spatialReference);if(0===c.width||0===c.height)return void this._clearImage(e);const g=new AbortController;o.loadingAbortController=g,l(t,(()=>g.abort()));const u=g.signal,f=this._waitFetchReady(u).then((async()=>{const t={requestAsImageElement:!0,pixelRatio:this._overlays[e].pixelRatio,...this.getFetchOptions(),signal:u},{height:i,width:s}=r.imageSize;return"imagery"===this.layer.type?this.layer.internalFetchImage(c,s,i,t):this.layer.fetchImage(c,s,i,t)})).then((e=>{if(h(u))throw s.getLogger(this).warnOnce("A call to fetchImage resolved even though the request was aborted. fetchImage should not resolve if options.signal.aborted is true."),m();return this.processResult(o,e)})).then((()=>{x(o.renderExtent,i)}));o.loadingPromise=f,await this._updatingHandles.addPromise(f.then((async()=>{d(u),await this._createStageObjects(e,o.image,u)})).catch((e=>{throw e&&!n(e)&&s.getLogger(this).error(e),e})).finally((()=>{f===o.loadingPromise&&(o.loadingPromise=null,o.loadingAbortController=null)})))}_clearImage(e){const t=this._images[e];if(t){null!=t.renderGeometry&&(this._drapeSourceRenderer.removeGeometries([t.renderGeometry],M.UPDATE),t.renderGeometry=null);const e=this.view._stage,r=t.texture;r?.unload(),e.remove(r),t.texture=null,e.remove(t.material),t.material=null,t.loadingAbortController=a(t.loadingAbortController),t.loadingPromise=null,t.image=null,t.pixelData=null}}async _createStageObjects(e,t,i){const s=this.view._stage,a=this._images[e],o=()=>{a.texture?.unload(),s.remove(a.texture),a.texture=null,a.renderGeometry&&(this._drapeSourceRenderer.removeGeometries([a.renderGeometry],M.UPDATE),a.renderGeometry=null)};if(t){const n=new C(t,{width:t.width,height:t.height,preMultiplyAlpha:!0,wrap:{s:H.CLAMP_TO_EDGE,t:H.CLAMP_TO_EDGE}});if(await r(this._images[e===D.INNER?D.OUTER:D.INNER].loadingPromise),d(i),o(),await s.schedule((()=>n.load(s.renderView.renderingContext)),i),!n.loaded)return void o();let l;if(s.add(n),a.texture=n,a.material??=new P({texture:n}),a.material.setParameters({texture:n}),e===D.INNER)l=j(a.material,a.renderExtent);else{const e=this._images[0].renderExtent;if(!e)return void o();l=S(a.material,e,a.renderExtent)}a.renderGeometry=new L(l),a.renderGeometry.localOrigin=this._overlays[e].renderLocalOrigin,this._drapeSourceRenderer.addGeometries([a.renderGeometry],M.UPDATE)}else o(),s.remove(a.material),a.material=null}_clippedExtent(e,t){if("local"!==this.view.viewingMode)return x(t,e);const r=this.view.basemapTerrain;return r.ready?v(e,r.extent,t):x(t,e)}_suspendedChangeHandler(){this.suspended?this.clear():this.refreshDebounced()}async _waitFetchReady(e){await c((()=>this.view.stationary),e),d(e)}};e([g()],V.prototype,"layer",void 0),e([g()],V.prototype,"suspended",void 0),e([g({readOnly:!0})],V.prototype,"fullExtentInLocalViewSpatialReference",void 0),e([g({readOnly:!0})],V.prototype,"visibleAtCurrentScale",null),e([g()],V.prototype,"updating",void 0),V=e([u("esri.views.3d.layers.DynamicLayerView3D")],V);const N=V,z=y();export{N 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.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Error.js";import{makeHandle as r,handlesGroup as i,destroyHandle as n}from"../../../core/handleUtils.js";import"../../../core/has.js";import{isIterable as s}from"../../../core/iteratorUtils.js";import{getProjectiveTransform as a}from"../../../core/perspectiveUtils.js";import{debounce as o,isPromiseLike as d}from"../../../core/promiseUtils.js";import{watch as l,on as m,syncAndInitial as h}from"../../../core/reactiveUtils.js";import{property as c}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as p}from"../../../core/accessorSupport/decorators/subclass.js";import{create as g}from"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{toExtent as u}from"../../../geometry/support/aaBoundingRect.js";import{MediaElementView as y}from"../../../layers/support/MediaElementView.js";import{DrapeSourceType as _}from"./interfaces.js";import{LayerView3D as f}from"./LayerView3D.js";import{MediaLayerInteraction as E}from"./support/MediaLayerInteraction.js";import{drapedZ as w}from"../terrain/OverlayRenderer.js";import{Attribute as v}from"../webgl-engine/lib/Attribute.js";import{ContentObjectType as D}from"../webgl-engine/lib/ContentObjectType.js";import{Geometry as b}from"../webgl-engine/lib/Geometry.js";import{DirtyState as R,DirtyOperation as j}from"../webgl-engine/lib/ModelDirtyTypes.js";import{Object3DHighlightStateID as I}from"../webgl-engine/lib/Object3DStateID.js";import{RenderGeometry as H}from"../webgl-engine/lib/RenderGeometry.js";import{Texture as G}from"../webgl-engine/lib/Texture.js";import{UpdatePolicy as A}from"../webgl-engine/lib/UpdatePolicy.js";import{VertexAttribute as M}from"../webgl-engine/lib/VertexAttribute.js";import{ImageMaterial as T}from"../webgl-engine/materials/ImageMaterial.js";import x from"../../layers/LayerView.js";import P from"../../layers/MediaLayerView.js";import{defaultHighlightName as S}from"../../support/HighlightDefaults.js";import{isInEffectiveScaleRange as L}from"../../support/layerViewUtils.js";import{TextureWrapMode as O}from"../../webgl/enums.js";let V=class extends(f(P(x))){get interactive(){return this._interaction.enabled}set interactive(e){this._interaction&&(this._interaction.enabled=e)}get selectedElement(){return this._interaction.selectedElement}set selectedElement(e){this._interaction&&(this._interaction.selectedElement=e)}get visibleAtCurrentScale(){return L(this.layer.effectiveScaleRange,this.view.scale)}get usedMemory(){return Array.from(this._renderElements.values()).reduce(((e,t)=>e+(t.getRenderData()?.texture.usedMemory??0)),0)}constructor(e){super(e),this.type="media-3d",this.drapeSourceType=_.Features,this.updatePolicy=A.SYNC,this.ignoresMemoryFactor=!0,this.unloadedMemory=0,this._uidToElement=new Map,this._highlightedElements=new Map,this._elementsInHighlightedId=new Map,this._renderElements=new Map,this._lastDrapingExtent=null,this._update=o((async(e,t,r)=>{const i=await this._collectMediaElements(e,t,r);this._synchronizeRenderElements(i)}),0);const{view:t,layer:r}=e;this._interaction=new E({view:t,layer:r}),this.addHandles(l((()=>this.interactionOptions),(e=>this._interaction.options=e),h))}initialize(){const{view:e,layer:t}=this;this._renderer=e.basemapTerrain.overlayManager.registerGeometryDrapeSource(this);const i=()=>this._updateWithLastDrapingExtent();this.addHandles([r((()=>e.basemapTerrain.overlayManager.unregisterDrapeSource(this))),m((()=>t.effectiveSource),"change",i),m((()=>t.effectiveSource),"refresh",i)]),this._updatingHandles.add((()=>this.suspended),i)}setDrapingExtent(e,t){this._lastDrapingExtent={overlays:e,spatialReference:t},this._updateWithLastDrapingExtent()}getHit(e){const t=this._uidToElement.get(e);return t?{type:"media",element:t,layer:this.layer}:null}highlight(e,t){const i=new I(t?.name??S),n=s(e)?Array.from(e):[e];this._elementsInHighlightedId.set(i,n);for(const r of n){const e=this._highlightedElements.get(r);e?e.add(i):this._highlightedElements.set(r,new Set([i]));const t=this._renderElements.get(r)?.getRenderData();t&&(t.renderGeometry.geometry.addHighlight(i),this._renderer.modifyGeometries([t.renderGeometry],R.HIGHLIGHT))}return r((()=>{const e=this._elementsInHighlightedId.get(i);if(e){for(const t of e){const e=this._highlightedElements.get(t);if(!e)continue;e.delete(i);const r=this._renderElements.get(t)?.getRenderData();r&&(r.renderGeometry.geometry.removeHighlight(i),this._renderer.modifyGeometries([r.renderGeometry],R.HIGHLIGHT)),0===e.size&&this._highlightedElements.delete(t)}this._elementsInHighlightedId.delete(i)}}))}isUpdating(){return super.isUpdating()||this._interaction.updating}_updateWithLastDrapingExtent(){if(null==this._lastDrapingExtent||this.suspended)return void(this._renderer&&this._synchronizeRenderElements(new Set));const{overlays:e,spatialReference:t}=this._lastDrapingExtent;this._updatingHandles.addPromise(this._update(e,t).catch((()=>{})))}async _collectMediaElements(e,t,r){const i=this.layer.effectiveSource;return null==i?new Set:new Set((await Promise.all(e.map((e=>i.queryElements(u(e.extent,t),{signal:r}))))).flat())}_synchronizeRenderElements(e){this._synchronizeRenderElementsRemove(e),this._synchronizeRenderElementsAdd(e)}_synchronizeRenderElementsRemove(e){this._renderElements.forEach(((t,r)=>{e.has(r)||(this._removeElement(r,t),this.emit("element-render-changed",{element:r}))}))}_synchronizeRenderElementsAdd(e){for(const t of e)this._renderElements.has(t)||this._createRenderElement(t)}_removeElement(e,t){this._destroyRenderData(e,t),this._renderElements.delete(e),this._uidToElement.delete(e.uid),t.handle.remove()}_createRenderElement(e){const t=new y({spatialReference:this.view.spatialReference,element:e}),r=new U(i([this._updatingHandles.add((()=>e.opacity),(e=>r.getRenderData()?.material.setParameters({opacity:e}))),this._updatingHandles.add((()=>t.coords),(()=>{r.data?this._updateGeometry(t,r):this._initializeRenderData(t,r)})),this._updatingHandles.add((()=>e.content),(()=>this._initializeRenderData(t,r))),n(t)]));this._renderElements.set(e,r),this._uidToElement.set(e.uid,e),this._updatingHandles.addPromise(e.load().catch((()=>{}))),this._initializeRenderData(t,r)}_initializeRenderData(e,t){const{coords:r,element:i}=e,{contentWidth:n,contentHeight:s}=i;if(null==r||null==i.content)return void this._destroyRenderData(i,t);if(t.data)return;const a=this._createTexture(i.content),o=a.load(this.view._stage.renderView.renderingContext),l=()=>{this.view._stage.add(a);const e=new T({textureId:a.id,opacity:i.opacity,perspectiveInterpolation:!0}),o=this._getPositionAttributeArray(r),d=[0,0,1,0,1,1,0,1],l=this._getPerspectiveDivideAttributeArray(o,n,s),m=[0,1,2,0,2,3],h=new b(e,[[M.POSITION,new v(o,m,3,!0)],[M.UV0,new v(d,m,2,!0)],[M.PERSPECTIVEDIVIDE,new v(l,m,1,!0)]]),c=new H(h,{layerUid:this.layer.uid,graphicUid:i.uid}),p=this._highlightedElements.get(i);p?.forEach((e=>c.geometry.addHighlight(e))),this._renderer.addGeometries([c],j.ADD),t.data=new C(c,a,e),this.emit("element-render-changed",{element:i})};d(o)?(t.data=a,this._updatingHandles.addPromise(o),o.then(l).catch((()=>a.dispose()))):l()}_updateGeometry(e,t){const{coords:r,element:i}=e;if(null==r||null==i.content)return void this._destroyRenderData(i,t);const n=t.getRenderData();if(!n)return;const s=this._getPositionAttributeArray(r);n.renderGeometry.geometry.setAttributeData(M.POSITION,s);const a=this._getPerspectiveDivideAttributeArray(s,i.contentWidth,i.contentHeight);n.renderGeometry.geometry.setAttributeData(M.PERSPECTIVEDIVIDE,a),n.renderGeometry.geometry.invalidateBoundingInfo(),this._renderer.modifyGeometries([n.renderGeometry],R.GEOMETRY),this.emit("element-render-changed",{element:i})}_getPositionAttributeArray(e){const[t,r,i,n]=e.rings[0];return[t[0],t[1],w,n[0],n[1],w,i[0],i[1],w,r[0],r[1],w]}_getPerspectiveDivideAttributeArray(e,t,r){a(z,[0,0,t,0,t,r,0,r],[e[0],e[1],e[3],e[4],e[6],e[7],e[9],e[10]]);const i=z[6]/z[8]*t,n=z[7]/z[8]*r;return[1,1+i,1+i+n,1+n]}_destroyRenderData(e,t){const r=t.data;if(null==r)return;if(t.data=null,r?.type===D.Texture)return void r.dispose();const i=r.texture;i.unload(),this.view._stage.remove(i),this._renderer.removeGeometries([r.renderGeometry],j.REMOVE),this.emit("element-render-changed",{element:e})}_createTexture(e){const r=e instanceof HTMLImageElement?e.naturalWidth:e.width,i=e instanceof HTMLImageElement?e.naturalHeight:e.height;if("getFrame"in e)throw new t("media-layer-view-3d","animation is not supported");return new G(e,{wrap:{s:O.CLAMP_TO_EDGE,t:O.CLAMP_TO_EDGE},preMultiplyAlpha:!0,width:r,height:i,mipmap:!0,updateCallback:()=>this.view.basemapTerrain.overlayManager.requestRender()})}get test(){}};e([c({readOnly:!0})],V.prototype,"type",void 0),e([c()],V.prototype,"layer",void 0),e([c()],V.prototype,"interactive",null),e([c()],V.prototype,"selectedElement",null),e([c({readOnly:!0})],V.prototype,"visibleAtCurrentScale",null),V=e([p("esri.views.3d.layers.MediaLayerView3D")],V);const z=g();class U{constructor(e){this.handle=e}getRenderData(){return this.data?.type===D.Texture?null:this.data}}class C{constructor(e,t,r){this.renderGeometry=e,this.texture=t,this.material=r,this.type="RenderData"}}const W=V;export{W as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Error.js";import{makeHandle as r,handlesGroup as i,destroyHandle as n}from"../../../core/handleUtils.js";import"../../../core/has.js";import{isIterable as s}from"../../../core/iteratorUtils.js";import{getProjectiveTransform as a}from"../../../core/perspectiveUtils.js";import{debounce as o,isPromiseLike as d}from"../../../core/promiseUtils.js";import{watch as l,on as m,syncAndInitial as h}from"../../../core/reactiveUtils.js";import{property as c}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as p}from"../../../core/accessorSupport/decorators/subclass.js";import{create as g}from"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{toExtent as u}from"../../../geometry/support/aaBoundingRect.js";import{MediaElementView as y}from"../../../layers/support/MediaElementView.js";import{DrapeSourceType as _}from"./interfaces.js";import{LayerView3D as f}from"./LayerView3D.js";import{MediaLayerInteraction as E}from"./support/MediaLayerInteraction.js";import{drapedZ as w}from"../terrain/OverlayRenderer.js";import{Attribute as v}from"../webgl-engine/lib/Attribute.js";import{ContentObjectType as D}from"../webgl-engine/lib/ContentObjectType.js";import{Geometry as b}from"../webgl-engine/lib/Geometry.js";import{DirtyState as R,DirtyOperation as j}from"../webgl-engine/lib/ModelDirtyTypes.js";import{Object3DHighlightStateID as H}from"../webgl-engine/lib/Object3DStateID.js";import{RenderGeometry as I}from"../webgl-engine/lib/RenderGeometry.js";import{Texture as G}from"../webgl-engine/lib/Texture.js";import{UpdatePolicy as A}from"../webgl-engine/lib/UpdatePolicy.js";import{VertexAttribute as M}from"../webgl-engine/lib/VertexAttribute.js";import{ImageMaterial as T}from"../webgl-engine/materials/ImageMaterial.js";import x from"../../layers/LayerView.js";import P from"../../layers/MediaLayerView.js";import{defaultHighlightName as S}from"../../support/HighlightDefaults.js";import{isInEffectiveScaleRange as L}from"../../support/layerViewUtils.js";import{TextureWrapMode as O}from"../../webgl/enums.js";let V=class extends(f(P(x))){get interactive(){return this._interaction.enabled}set interactive(e){this._interaction&&(this._interaction.enabled=e)}get selectedElement(){return this._interaction.selectedElement}set selectedElement(e){this._interaction&&(this._interaction.selectedElement=e)}get visibleAtCurrentScale(){return L(this.layer.effectiveScaleRange,this.view.scale)}get usedMemory(){return Array.from(this._renderElements.values()).reduce(((e,t)=>e+(t.getRenderData()?.texture.usedMemory??0)),0)}constructor(e){super(e),this.type="media-3d",this.drapeSourceType=_.Features,this.updatePolicy=A.SYNC,this.ignoresMemoryFactor=!0,this.unloadedMemory=0,this._uidToElement=new Map,this._highlightedElements=new Map,this._elementsInHighlightedId=new Map,this._renderElements=new Map,this._lastDrapingExtent=null,this._update=o((async(e,t,r)=>{const i=await this._collectMediaElements(e,t,r);this._synchronizeRenderElements(i)}),0);const{view:t,layer:r}=e;this._interaction=new E({view:t,layer:r}),this.addHandles(l((()=>this.interactionOptions),(e=>this._interaction.options=e),h))}initialize(){const{view:e,layer:t}=this;this._renderer=e.basemapTerrain.overlayManager.registerGeometryDrapeSource(this);const i=()=>this._updateWithLastDrapingExtent();this.addHandles([r((()=>e.basemapTerrain.overlayManager.unregisterDrapeSource(this))),m((()=>t.effectiveSource),"change",i),m((()=>t.effectiveSource),"refresh",i)]),this._updatingHandles.add((()=>this.suspended),i)}setDrapingExtent(e,t){this._lastDrapingExtent={overlays:e,spatialReference:t},this._updateWithLastDrapingExtent()}getHit(e){const t=this._uidToElement.get(e);return t?{type:"media",element:t,layer:this.layer}:null}highlight(e,t){const i=new H(t?.name??S),n=s(e)?Array.from(e):[e];this._elementsInHighlightedId.set(i,n);for(const r of n){const e=this._highlightedElements.get(r);e?e.add(i):this._highlightedElements.set(r,new Set([i]));const t=this._renderElements.get(r)?.getRenderData();t&&(t.renderGeometry.geometry.addHighlight(i),this._renderer.modifyGeometries([t.renderGeometry],R.HIGHLIGHT))}return r((()=>{const e=this._elementsInHighlightedId.get(i);if(e){for(const t of e){const e=this._highlightedElements.get(t);if(!e)continue;e.delete(i);const r=this._renderElements.get(t)?.getRenderData();r&&(r.renderGeometry.geometry.removeHighlight(i),this._renderer.modifyGeometries([r.renderGeometry],R.HIGHLIGHT)),0===e.size&&this._highlightedElements.delete(t)}this._elementsInHighlightedId.delete(i)}}))}isUpdating(){return super.isUpdating()||this._interaction.updating}_updateWithLastDrapingExtent(){if(null==this._lastDrapingExtent||this.suspended)return void(this._renderer&&this._synchronizeRenderElements(new Set));const{overlays:e,spatialReference:t}=this._lastDrapingExtent;this._updatingHandles.addPromise(this._update(e,t).catch((()=>{})))}async _collectMediaElements(e,t,r){const i=this.layer.effectiveSource;return null==i?new Set:new Set((await Promise.all(e.map((e=>i.queryElements(u(e.extent,t),{signal:r}))))).flat())}_synchronizeRenderElements(e){this._synchronizeRenderElementsRemove(e),this._synchronizeRenderElementsAdd(e)}_synchronizeRenderElementsRemove(e){this._renderElements.forEach(((t,r)=>{e.has(r)||(this._removeElement(r,t),this.emit("element-render-changed",{element:r}))}))}_synchronizeRenderElementsAdd(e){for(const t of e)this._renderElements.has(t)||this._createRenderElement(t)}_removeElement(e,t){this._destroyRenderData(e,t),this._renderElements.delete(e),this._uidToElement.delete(e.uid),t.handle.remove()}_createRenderElement(e){const t=new y({spatialReference:this.view.spatialReference,element:e}),r=new U(i([this._updatingHandles.add((()=>e.opacity),(e=>r.getRenderData()?.material.setParameters({opacity:e}))),this._updatingHandles.add((()=>t.coords),(()=>{r.data?this._updateGeometry(t,r):this._initializeRenderData(t,r)})),this._updatingHandles.add((()=>e.content),(()=>this._initializeRenderData(t,r))),n(t)]));this._renderElements.set(e,r),this._uidToElement.set(e.uid,e),this._updatingHandles.addPromise(e.load().catch((()=>{}))),this._initializeRenderData(t,r)}_initializeRenderData(e,t){const{coords:r,element:i}=e,{contentWidth:n,contentHeight:s}=i;if(null==r||null==i.content)return void this._destroyRenderData(i,t);if(t.data)return;const a=this._createTexture(i.content),o=a.load(this.view._stage.renderView.renderingContext),l=()=>{if(!a.loaded)return;this.view._stage.add(a);const e=new T({texture:a,opacity:i.opacity,perspectiveInterpolation:!0}),o=this._getPositionAttributeArray(r),d=[0,0,1,0,1,1,0,1],l=this._getPerspectiveDivideAttributeArray(o,n,s),m=[0,1,2,0,2,3],h=new b(e,[[M.POSITION,new v(o,m,3,!0)],[M.UV0,new v(d,m,2,!0)],[M.PERSPECTIVEDIVIDE,new v(l,m,1,!0)]]),c=new I(h,{layerUid:this.layer.uid,graphicUid:i.uid}),p=this._highlightedElements.get(i);p?.forEach((e=>c.geometry.addHighlight(e))),this._renderer.addGeometries([c],j.ADD),t.data=new C(c,a,e),this.emit("element-render-changed",{element:i})};d(o)?(t.data=a,this._updatingHandles.addPromise(o),o.then(l).catch((()=>a.dispose()))):l()}_updateGeometry(e,t){const{coords:r,element:i}=e;if(null==r||null==i.content)return void this._destroyRenderData(i,t);const n=t.getRenderData();if(!n)return;const s=this._getPositionAttributeArray(r);n.renderGeometry.geometry.setAttributeData(M.POSITION,s);const a=this._getPerspectiveDivideAttributeArray(s,i.contentWidth,i.contentHeight);n.renderGeometry.geometry.setAttributeData(M.PERSPECTIVEDIVIDE,a),n.renderGeometry.geometry.invalidateBoundingInfo(),this._renderer.modifyGeometries([n.renderGeometry],R.GEOMETRY),this.emit("element-render-changed",{element:i})}_getPositionAttributeArray(e){const[t,r,i,n]=e.rings[0];return[t[0],t[1],w,n[0],n[1],w,i[0],i[1],w,r[0],r[1],w]}_getPerspectiveDivideAttributeArray(e,t,r){a(z,[0,0,t,0,t,r,0,r],[e[0],e[1],e[3],e[4],e[6],e[7],e[9],e[10]]);const i=z[6]/z[8]*t,n=z[7]/z[8]*r;return[1,1+i,1+i+n,1+n]}_destroyRenderData(e,t){const r=t.data;if(null==r)return;if(t.data=null,r?.type===D.Texture)return void r.dispose();const i=r.texture;i.unload(),this.view._stage.remove(i),this._renderer.removeGeometries([r.renderGeometry],j.REMOVE),this.emit("element-render-changed",{element:e})}_createTexture(e){const r=e instanceof HTMLImageElement?e.naturalWidth:e.width,i=e instanceof HTMLImageElement?e.naturalHeight:e.height;if("getFrame"in e)throw new t("media-layer-view-3d","animation is not supported");return new G(e,{wrap:{s:O.CLAMP_TO_EDGE,t:O.CLAMP_TO_EDGE},preMultiplyAlpha:!0,width:r,height:i,mipmap:!0,updateCallback:()=>this.view.basemapTerrain.overlayManager.requestRender()})}get test(){}};e([c({readOnly:!0})],V.prototype,"type",void 0),e([c()],V.prototype,"layer",void 0),e([c()],V.prototype,"interactive",null),e([c()],V.prototype,"selectedElement",null),e([c({readOnly:!0})],V.prototype,"visibleAtCurrentScale",null),V=e([p("esri.views.3d.layers.MediaLayerView3D")],V);const z=g();class U{constructor(e){this.handle=e}getRenderData(){return this.data?.type===D.Texture?null:this.data}}class C{constructor(e,t,r){this.renderGeometry=e,this.texture=t,this.material=r,this.type="RenderData"}}const W=V;export{W 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.33/esri/copyright.txt for details.
4
4
  */
5
- import{shuffle as t}from"../../../../core/arrayUtils.js";import{baseObjectMemory as e}from"../../../../core/memoryEstimations.js";import{signal as s}from"../../../../core/signal.js";import{create as i,diameter as r}from"../../../../geometry/support/aaBoundingBox.js";import{create as u,fromExtent as a,intersects as h,copy as n,positiveInfinity as f,intersection as _}from"../../../../geometry/support/aaBoundingRect.js";import{numVertices as l,estimateSize as m,getObjectId as o,computeAABB as c}from"../../../../layers/graphics/dehydratedFeatures.js";import{computeMaxZ as d}from"../graphics/graphicUtils.js";const F=16438;class g{constructor(t){this.descriptor=t,this._numVertices=0,this._featuresMissing=s(!0),this._fetchFailed=s(!1),this._sorted=!1,this._numFeatures=E,this._emptyFeatureRatio=s(0),this._estimatedSize=-1,this._estimatedUnusedSize=0,this._estimatedUnusedSizeDirty=!1,this._displayingFeatures=null,this.alive=!0,this.filtered=!1,this._features=null,this._featuresLength=s(0),this._featureLimit=s(0),this._fetchStatus=p.FETCH_NEEDED,this.fetchingResolution=this.displayingResolution=t.resolution}get featuresMissing(){return this._featuresMissing.value}set featuresMissing(t){this._featuresMissing.value=t}get missingAttributes(){return this._missingAttributes}get fetchFailed(){return this._fetchFailed.value}set fetchFailed(t){this._fetchFailed.value=t}get displayingFeatures(){return this._displayingFeatures}set displayingFeatures(t){this._displayingFeatures=t,this.extentIncludingBorrowedFeatures=null}get perTileMaximumNumberOfFeaturesExceeded(){const t=this.isFetched&&this.featuresMissing;return!this.filtered&&(t||this.hasFeatureLimit)}get features(){return this._features}get featureLimit(){return this._featureLimit.value}set featureLimit(t){this._featureLimit.value!==t&&(this._featureLimit.value=t,this._estimatedUnusedSizeDirty=!0)}get hasFeatureLimit(){return this.featureLimit!==this._featuresLength.value}get hasAllFeatures(){return!(this.featuresMissing||this.fetchFailed||this.hasFeatureLimit)}get availableFields(){return this._availableFields}setFeatures(t,e,s,i){this._availableFields=s,this._features=t,this._featuresLength.value=t?.length??0,this._sorted=!1,this._estimatedSize=-1,this._estimatedUnusedSizeDirty=!0,this._missingAttributes=i,t&&t.length>0?(this._emptyFeatureRatio.value=e/(t.length+e),this._numVertices=t.reduce(((t,e)=>t+l(e.geometry)),0)):(this._emptyFeatureRatio.value=0,this._numVertices=0)}computeZQuantizationFactor(){if(this._features&&this._features.length>0){const t=this._features.reduce(((t,{geometry:e})=>Math.max(t,d(e)??0)),0);return Math.floor(t/this.descriptor.planetRadius)+1}return 1}get emptyFeatureRatio(){return this._emptyFeatureRatio.value}get numFeatures(){return this.hasPreciseFeatureCount?this._numFeatures:this._features?this._features.length:0}set numFeatures(t){this._numFeatures=t}get hasPreciseFeatureCount(){return this._numFeatures>E}get needsFeatureCount(){return this._numFeatures===E}get numVertices(){return this._numVertices}get id(){return this.descriptor.id}get estimatedSize(){return this.updateMemoryEstimates(),this._estimatedSize}get estimatedUnusedSize(){return this._estimatedUnusedSize}updateMemoryEstimates(){if(this._estimatedSize<0){if(this._estimatedSize=0,this._estimatedUnusedSize=0,this._features)for(let t=0;t<this._features.length;++t){const e=m(this._features[t]);this._estimatedSize+=e,t>=this.featureLimit&&(this._estimatedUnusedSize+=e)}return!0}if(this._estimatedUnusedSizeDirty){if(this._estimatedUnusedSize=0,this._estimatedUnusedSizeDirty=!1,this._features)for(let t=this.featureLimit;t<this._features.length;++t)this._estimatedUnusedSize+=m(this._features[t]);return!0}return!1}get fetchStatus(){return this._fetchStatus}requestFetch(){this._fetchStatus=p.FETCH_NEEDED}requestRefetch(){this._fetchStatus=p.REFETCH_NEEDED}startFetch(){this._fetchStatus=this.needsRefetch?p.REFETCHING:p.FETCHING}fetchDone(t){this._fetchStatus=t?p.FULL:p.DONE}get isFetching(){return this._fetchStatus===p.FETCHING||this._fetchStatus===p.REFETCHING}get isRefetching(){return this._fetchStatus===p.REFETCHING}get needsFetch(){return this._fetchStatus===p.FETCH_NEEDED||this._fetchStatus===p.REFETCH_NEEDED}get needsRefetch(){return this._fetchStatus===p.REFETCH_NEEDED}get isFetched(){return this._fetchStatus===p.DONE||this._fetchStatus===p.FULL}isFullyFetched(t){return!!this.features&&(this.features.length>=t||this.fetchStatus===p.FULL)}resetFetching(){this._fetchStatus=this.isRefetching?p.REFETCH_NEEDED:p.FETCH_NEEDED}get needsDisplayUpdate(){return!!this._features&&!L(this._features,this.displayingFeatures,this.featureLimit)}intersects(t){return null==t||!this.descriptor.extent||(a(t,R),h(this.descriptor.extent,R))}intersectionIncludingBorrowed(t,e){const s=null!=this.extentIncludingBorrowedFeatures?this.extentIncludingBorrowedFeatures:this.descriptor.extent;return t||s?(null!=t?(a(t,e),_(e,s,e)):n(e,s),e):(n(e,f),e)}_shuffle(e){this._features?.sort(((t,s)=>o(t,e)-o(s,e))),t(this._features,F)}_sortBySize(t){this._features?.sort(((e,s)=>r(c(s.geometry,N))-r(c(e.geometry,N))||o(e,t)-o(s,t)))}reduceFeatures(t,e,s,i){if(t<=0)return!1;if(!this._features)return this.featureLimit=0,!1;let r=!1;this.featureLimit=Math.ceil(this.numFeatures*t),this.featureLimit>this._features.length&&(this.featureLimit=this._features.length,this._fetchStatus===p.DONE&&this._features.length>0&&(this._fetchStatus=p.REFETCH_NEEDED,r=!0)),!this._sorted&&t<1&&(i===D.RANDOM?this._shuffle(s):this._sortBySize(s),this._sorted=!0,this._estimatedUnusedSizeDirty=!0);const u=Math.max(this.featureLimit,Math.ceil(e*this.numFeatures));return this._features.length>u&&(this._features.length=u,this._featuresLength.value=u,this.featuresMissing=!0,this._fetchStatus===p.FULL&&(this._fetchStatus=p.DONE)),r}get cache(){return new y(this,this._features,this._numFeatures,this._emptyFeatureRatio.value)}set cache(t){this.requestController=null,this._availableFields=t.availableFields,this._features=t.features,this._featuresLength.value=t.features?.length??0,this._numFeatures=t.numFeatures,this._emptyFeatureRatio.value=t.emptyFeatureRatio,this._fetchStatus=t.fetchStatus,this.featuresMissing=t.featuresMissing,this._estimatedSize=-1,this._estimatedUnusedSizeDirty=!0}}const E=-1,S=-2;var p,D;!function(t){t[t.FETCH_NEEDED=0]="FETCH_NEEDED",t[t.REFETCH_NEEDED=1]="REFETCH_NEEDED",t[t.FETCHING=2]="FETCHING",t[t.REFETCHING=3]="REFETCHING",t[t.DONE=4]="DONE",t[t.FULL=5]="FULL"}(p||(p={})),function(t){t[t.SIZE=0]="SIZE",t[t.RANDOM=1]="RANDOM"}(D||(D={}));class y{constructor(t,s,i,r){this.features=s,this.numFeatures=i,this.emptyFeatureRatio=r,this.cachedMemory=e+t.estimatedSize,this.resolution=t.displayingResolution,this.availableFields=t.availableFields,this.fetchStatus=t.fetchStatus,this.featuresMissing=t.featuresMissing}}function L(t,e,s){if(null==e||null==t||s!==e.length||s>t.length)return!1;for(let i=0;i<s;++i)if(t[i]!==e[i])return!1;return!0}const R=u(),N=i();export{g as FeatureTile,y as FeatureTileCacheItem,D as ReduceMode,S as failedFeatureCount};
5
+ import{shuffle as t}from"../../../../core/arrayUtils.js";import{baseObjectMemory as e}from"../../../../core/memoryEstimations.js";import{signal as s}from"../../../../core/signal.js";import{create as i,diameter as r}from"../../../../geometry/support/aaBoundingBox.js";import{create as u,fromExtent as a,intersects as h,copy as n,positiveInfinity as f,intersection as _}from"../../../../geometry/support/aaBoundingRect.js";import{numVertices as l,estimateSize as m,getObjectId as o,computeAABB as c}from"../../../../layers/graphics/dehydratedFeatures.js";import{computeMaxZ as d}from"../graphics/graphicUtils.js";const F=16438;class g{constructor(t){this.descriptor=t,this._numVertices=0,this._featuresMissing=s(!0),this._fetchFailed=s(!1),this._sorted=!1,this._numFeatures=E,this._emptyFeatureRatio=s(0),this._estimatedSize=-1,this._estimatedUnusedSize=0,this._estimatedUnusedSizeDirty=!1,this._displayingFeatures=null,this.alive=!0,this.filtered=!1,this._features=null,this._featuresLength=s(0),this._featureLimit=s(0),this._fetchStatus=p.FETCH_NEEDED,this.fetchingResolution=this.displayingResolution=t.resolution}get featuresMissing(){return this._featuresMissing.value}set featuresMissing(t){this._featuresMissing.value=t}get missingAttributes(){return this._missingAttributes}get fetchFailed(){return this._fetchFailed.value}set fetchFailed(t){this._fetchFailed.value=t}get displayingFeatures(){return this._displayingFeatures}set displayingFeatures(t){this._displayingFeatures=t,this.extentIncludingBorrowedFeatures=null}get perTileMaximumNumberOfFeaturesExceeded(){const t=this.isFetched&&this.featuresMissing;return!this.filtered&&(t||this.hasFeatureLimit)}get features(){return this._features}get featureLimit(){return this._featureLimit.value}set featureLimit(t){this._featureLimit.value!==t&&(this._featureLimit.value=t,this._estimatedUnusedSizeDirty=!0)}get hasFeatureLimit(){return this.featureLimit!==this._featuresLength.value}get hasAllFeatures(){return!this.featuresMissing&&!this.fetchFailed&&!this.hasFeatureLimit}get availableFields(){return this._availableFields}setFeatures(t,e,s,i){this._availableFields=s,this._features=t,this._featuresLength.value=t?.length??0,this._sorted=!1,this._estimatedSize=-1,this._estimatedUnusedSizeDirty=!0,this._missingAttributes=i,t&&t.length>0?(this._emptyFeatureRatio.value=e/(t.length+e),this._numVertices=t.reduce(((t,e)=>t+l(e.geometry)),0)):(this._emptyFeatureRatio.value=0,this._numVertices=0)}computeZQuantizationFactor(){if(this._features&&this._features.length>0){const t=this._features.reduce(((t,{geometry:e})=>Math.max(t,d(e)??0)),0);return Math.floor(t/this.descriptor.planetRadius)+1}return 1}get emptyFeatureRatio(){return this._emptyFeatureRatio.value}get numFeatures(){return this.hasPreciseFeatureCount?this._numFeatures:this._features?this._features.length:0}set numFeatures(t){this._numFeatures=t}get hasPreciseFeatureCount(){return this._numFeatures>E}get needsFeatureCount(){return this._numFeatures===E}get numVertices(){return this._numVertices}get id(){return this.descriptor.id}get estimatedSize(){return this.updateMemoryEstimates(),this._estimatedSize}get estimatedUnusedSize(){return this._estimatedUnusedSize}updateMemoryEstimates(){if(this._estimatedSize<0){if(this._estimatedSize=0,this._estimatedUnusedSize=0,this._features)for(let t=0;t<this._features.length;++t){const e=m(this._features[t]);this._estimatedSize+=e,t>=this.featureLimit&&(this._estimatedUnusedSize+=e)}return!0}if(this._estimatedUnusedSizeDirty){if(this._estimatedUnusedSize=0,this._estimatedUnusedSizeDirty=!1,this._features)for(let t=this.featureLimit;t<this._features.length;++t)this._estimatedUnusedSize+=m(this._features[t]);return!0}return!1}get fetchStatus(){return this._fetchStatus}requestFetch(){this._fetchStatus=p.FETCH_NEEDED}requestRefetch(){this._fetchStatus=p.REFETCH_NEEDED}startFetch(){this._fetchStatus=this.needsRefetch?p.REFETCHING:p.FETCHING}fetchDone(t){this._fetchStatus=t?p.FULL:p.DONE}get isFetching(){return this._fetchStatus===p.FETCHING||this._fetchStatus===p.REFETCHING}get isRefetching(){return this._fetchStatus===p.REFETCHING}get needsFetch(){return this._fetchStatus===p.FETCH_NEEDED||this._fetchStatus===p.REFETCH_NEEDED}get needsRefetch(){return this._fetchStatus===p.REFETCH_NEEDED}get isFetched(){return this._fetchStatus===p.DONE||this._fetchStatus===p.FULL}isFullyFetched(t){return!!this.features&&(this.features.length>=t||this.fetchStatus===p.FULL)}resetFetching(){this._fetchStatus=this.isRefetching?p.REFETCH_NEEDED:p.FETCH_NEEDED}get needsDisplayUpdate(){return!!this._features&&!L(this._features,this.displayingFeatures,this.featureLimit)}intersects(t){return null==t||!this.descriptor.extent||(a(t,R),h(this.descriptor.extent,R))}intersectionIncludingBorrowed(t,e){const s=null!=this.extentIncludingBorrowedFeatures?this.extentIncludingBorrowedFeatures:this.descriptor.extent;return t||s?(null!=t?(a(t,e),_(e,s,e)):n(e,s),e):(n(e,f),e)}_shuffle(e){this._features?.sort(((t,s)=>o(t,e)-o(s,e))),t(this._features,F)}_sortBySize(t){this._features?.sort(((e,s)=>r(c(s.geometry,N))-r(c(e.geometry,N))||o(e,t)-o(s,t)))}reduceFeatures(t,e,s,i){if(t<=0)return!1;if(!this._features)return this.featureLimit=0,!1;let r=!1;this.featureLimit=Math.ceil(this.numFeatures*t),this.featureLimit>this._features.length&&(this.featureLimit=this._features.length,this._fetchStatus===p.DONE&&this._features.length>0&&(this._fetchStatus=p.REFETCH_NEEDED,r=!0)),!this._sorted&&t<1&&(i===D.RANDOM?this._shuffle(s):this._sortBySize(s),this._sorted=!0,this._estimatedUnusedSizeDirty=!0);const u=Math.max(this.featureLimit,Math.ceil(e*this.numFeatures));return this._features.length>u&&(this._features.length=u,this._featuresLength.value=u,this.featuresMissing=!0,this._fetchStatus===p.FULL&&(this._fetchStatus=p.DONE)),r}get cache(){return new y(this,this._features,this._numFeatures,this._emptyFeatureRatio.value)}set cache(t){this.requestController=null,this._availableFields=t.availableFields,this._features=t.features,this._featuresLength.value=t.features?.length??0,this._numFeatures=t.numFeatures,this._emptyFeatureRatio.value=t.emptyFeatureRatio,this._fetchStatus=t.fetchStatus,this.featuresMissing=t.featuresMissing,this._estimatedSize=-1,this._estimatedUnusedSizeDirty=!0}}const E=-1,S=-2;var p,D;!function(t){t[t.FETCH_NEEDED=0]="FETCH_NEEDED",t[t.REFETCH_NEEDED=1]="REFETCH_NEEDED",t[t.FETCHING=2]="FETCHING",t[t.REFETCHING=3]="REFETCHING",t[t.DONE=4]="DONE",t[t.FULL=5]="FULL"}(p||(p={})),function(t){t[t.SIZE=0]="SIZE",t[t.RANDOM=1]="RANDOM"}(D||(D={}));class y{constructor(t,s,i,r){this.features=s,this.numFeatures=i,this.emptyFeatureRatio=r,this.cachedMemory=e+t.estimatedSize,this.resolution=t.displayingResolution,this.availableFields=t.availableFields,this.fetchStatus=t.fetchStatus,this.featuresMissing=t.featuresMissing}}function L(t,e,s){if(null==e||null==t||s!==e.length||s>t.length)return!1;for(let i=0;i<s;++i)if(t[i]!==e[i])return!1;return!0}const R=u(),N=i();export{g as FeatureTile,y as FeatureTileCacheItem,D as ReduceMode,S as failedFeatureCount};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import{filterInPlace as s}from"../../../../core/arrayUtils.js";import"../../../../core/has.js";import i from"../../../../core/Logger.js";import{getOrCreateMapValue as r}from"../../../../core/MapUtils.js";import{isAbortError as a,throwIfAborted as n}from"../../../../core/promiseUtils.js";import o from"../../../../core/ReactiveMap.js";import{on as u,watch as l}from"../../../../core/reactiveUtils.js";import{schedule as h}from"../../../../core/scheduling.js";import{signal as d}from"../../../../core/signal.js";import{sqlAnd as c}from"../../../../core/sql.js";import{property as p}from"../../../../core/accessorSupport/decorators/property.js";import{subclass as f}from"../../../../core/accessorSupport/decorators/subclass.js";import{create as _,equals as m,clone as g,expand as F,toExtent as y}from"../../../../geometry/support/aaBoundingRect.js";import{getObjectId as T,hasVertices as x}from"../../../../layers/graphics/dehydratedFeatures.js";import R from"../../../../rest/support/QuantizationParameters.js";import v from"../../../../rest/support/Query.js";import{ViewingMode as b}from"../../../ViewingMode.js";import{MultiFeatureReference as C,SingleFeatureReference as E}from"./featureReference.js";import{failedFeatureCount as M,FeatureTile as D,ReduceMode as w}from"./FeatureTile.js";import{tilesAreRelated as U}from"../../terrain/tileUtils.js";import{ImmediateTask as j,TaskPriority as O}from"../../../support/Scheduler.js";let A=class extends t{set maximumNumberOfFeatures(e){e=e||1/0;const t=this._get("maximumNumberOfFeatures");e===t||e<1||(this._set("maximumNumberOfFeatures",e),this._maximumFeaturesUpdated(t,e))}set memoryFactor(e){this.memoryFactor!==e&&(this._set("memoryFactor",e),this._setDirty())}set lodFactor(e){this.lodFactor!==e&&(this._set("lodFactor",e),this._supportsResolution&&this.refetch())}get useTileCount(){return this._useTileCount&&null!=this.context.query.queryFeatureCount}set useTileCount(e){this._useTileCount=e,this.notifyChange("useTileCount")}get updating(){return this._dirty||!!this._pendingEdits||this._isFetching||(this.tileDescriptors?.updating??!1)}get memoryForUnusedFeatures(){let e=0;return this._featureTiles.forEach((t=>e+=t.estimatedUnusedSize)),e}get totalVertices(){let e=0;return this._featureTiles.forEach((t=>e+=t.numVertices)),e}get totalFeatures(){let e=0;return this._featureTiles.forEach((t=>e+=t.numFeatures)),e}get hasAllFeatures(){if(this._paused||this.dataUpdating)return!1;for(const e of this._featureTiles.values())if(!this.hasFullGeometries&&0!==e.emptyFeatureRatio||!e.hasAllFeatures)return!1;return!0}get hasFullGeometries(){if(!this._supportsResolution)return!0;return this.tileDescriptors.some(P)||!this.context.capabilities.supportsQuantization&&"polyline"!==this.context.geometryType}set filterExtent(e){if(null!=e&&this.context.tilingScheme&&!e.spatialReference.equals(this.context.tilingScheme.spatialReference))return void i.getLogger(this).error("#filterExtent=","extent needs to be in the same spatial reference as the tiling scheme");const t=this._get("filterExtent");if(t===e||null!=t&&e&&t.equals(e))return;const s=null!=e?e.clone():null;this._set("filterExtent",s),this._reclip(s,t)}_updateTileZQuantization(e){if(this.context.viewingMode===b.Global){const t=e.computeZQuantizationFactor();this._zQuantizationFactor.value<t&&(this._zQuantizationFactor.value=t)}}get _tileZQuantization(){return this.context.isDraped?1:this._zQuantizationFactor.value}constructor(e){super(e),this._useTileCount=!1,this.dataUpdating=!1,this.running=!1,this.updatingTotal=0,this.updatingRemaining=0,this.expectedFeatureDiff=0,this.maximumNumberOfFeaturesExceeded=!1,this._fullRatio=1,this._farRatio=1,this._zQuantizationFactor=d(1),this._changes={updates:{adds:new Array,removes:new Array},adds:new Array,removes:new Array},this._frameTask=j,this._featureTiles=new o,this._displayingFeatureReferences=new Map,this._numDisplayingFeatureReferences=0,this._dirty=!1,this._suspended=!0,this._pendingEdits=null,this._applyEditsTilesUpdated=!1,this._isFetching=!1}initialize(){this.addHandles([u((()=>this.tileDescriptors),"change",(()=>this._setDirty()),{sync:!0,onListenerAdd:()=>this._setDirty()}),l((()=>this._tileZQuantization),(()=>this.refetch()))]),this._objectIdField=this.context.objectIdField,this.FeatureReferenceClass=this.context.capabilities.supportsMultipleResolutions?C:E;const e=this.context.scheduler;null!=e&&(this._frameTask=e.registerTask(O.FEATURE_TILE_FETCHER,this)),this._setDirty()}destroy(){this._frameTask.remove(),this._featureTiles.forEach((e=>{this._cancelFetchTile(e),this._removeTile(e)})),this._featureTiles.clear(),this._displayingFeatureReferences.clear(),this._pendingEdits?.controller.abort(),this._pendingEdits=null}get _paused(){return this._suspended||!!this._pendingEdits}restart(){this._featureTiles.forEach((e=>{this._cancelFetchTile(e),this._clearTile(e),this._resetFetchTile(e)})),null!=this.context.memoryCache&&this.context.memoryCache.clear(),this._setDirty()}refetch(){this._featureTiles.forEach((e=>{this._cancelFetchTile(e),this._resetFetchTile(e)})),null!=this.context.memoryCache&&this.context.memoryCache.clear(),this._setDirty()}suspend(){this._suspended||(this._suspended=!0,this._pause(),this._setDirty())}resume(){this._suspended&&(this._suspended=!1,this._unpause())}getMissingAttributesForFeature(e){for(const t of this._featureTiles.values()){const s=t.missingAttributes?.get(e);if(null!=s)return s}}_pause(){this._paused&&(this._featureTiles.forEach((e=>this._cancelFetchTile(e))),this._updated())}_unpause(){this._paused||this._setDirty()}get availableFields(){let e=null;return this._featureTiles.forEach((t=>{null!=t.displayingFeatures&&0!==t.displayingFeatures.length&&(null==e?e=new Set(t.availableFields):e.forEach((s=>{t.availableFields?.has(s)||e.delete(s)})))})),null!=e?e:new Set}applyEdits(e){this._pendingEdits||(this._pendingEdits={edits:Promise.resolve(),count:0,controller:new AbortController},this._pause());const t=this._pendingEdits;t.count++;const s=t.edits.then((()=>e.result.catch((e=>{if(a(e))throw e;return null})).then((e=>e?(this._applyEditsDeleteFeatures(e.deletedFeatures),this._applyEditsAddUpdateFeatures(e.addedFeatures,e.updatedFeatures,t.controller.signal).then((()=>e))):e)).then((e=>(0==--t.count&&(this._pendingEdits===t&&(this._pendingEdits=null),null!=this.context.memoryCache&&this.context.memoryCache.clear(),this._applyEditsTilesUpdated=!1,this._unpause()),e)))));return t.edits=s,this._updated(),s}_applyEditsDeleteFeatures(e){if(0===e.length)return;const t=this.context.globalIdField,s=t&&this.availableFields.has(t),r=new Set,a=this._objectIdField;e.forEach((({objectId:e,globalId:n})=>{(!e||e<0)&&t&&n&&(s||i.getLogger(this).errorOncePerTick(`Editing the specified service requires the layer's globalIdField, ${t} to be included the layer's outFields for updates to be reflected in the view`),e=this._objectIdFromGlobalId(n,a,t)),null!=e&&e>=0&&r.add(e)})),this._featureTiles.forEach((e=>{if(!e.features)return;const t=e.features.filter((e=>!r.has(T(e,this._objectIdField))));t.length!==e.features.length&&(this._applyEditsTileUpdated(),e.setFeatures(t,0,e.availableFields,e.missingAttributes),this._updateTileZQuantization(e),this._invalidateCounts())}))}_objectIdFromGlobalId(e,t,s){if(null==e)return null;const i=this.features.find((t=>t.attributes?.[s]===e));return i?T(i,t):null}async _applyEditsAddUpdateFeatures(e,t,s){const{objectIdField:r,globalIdField:a}=this.context,n=a&&this.availableFields.has(a),o=new Set,u=new Set;for(const i of e){const e=i.objectId;null!=e&&o.add(e)}for(const{objectId:h,globalId:d}of t){let e=h;(null==e||e<0)&&a&&(n||i.getLogger(this).errorOncePerTick(`Editing the specified service requires the layer's globalIdField, ${a} to be included the layer's outFields for updates to be reflected in the view`),e=this._objectIdFromGlobalId(d,r,a)),null!=e&&e>=0&&(o.add(e),u.add(e))}if(0===o.size)return;const l=[];this._featureTiles.forEach((e=>{const t=this._applyEditsAddUpdateTile(e,o,u,s);t&&l.push(t)})),this._updated(),await Promise.allSettled(l)}async _applyEditsAddUpdateTile(e,t,s,i){if(!e.features)return;e.fetchingResolution=e.descriptor.resolution;const r=this._createQuery(e);r.resultType=void 0,r.cacheHint=!1,r.objectIds=Array.from(t);const a=await this._queryFeatures(r,i);let n=null;if(s.size>0){const t=e.features.filter((e=>!s.has(T(e,this._objectIdField))));t.length!==e.features.length&&(n=t)}if(a.features.length>0){n||(n=e.features.slice());for(const e of a.features)n.push(e)}n&&(e.hasPreciseFeatureCount&&(e.numFeatures=Math.max(e.numFeatures,n.length)),this._applyEditsTileUpdated(),e.setFeatures(n,0,Q(e.availableFields,a.fields),N(e.missingAttributes,a.missingAttributes)),this._updateTileZQuantization(e),this._invalidateCounts())}_applyEditsTileUpdated(){this._applyEditsTilesUpdated||(this._applyEditsTilesUpdated=!0,this._updated())}_queryFeatures(e,t){return this.context.query.queryFeaturesDehydrated(e,{signal:t,timeout:H})}_setDirty(){this._dirty=!0,this._updated()}runTask(e){const t=this._frameTask.processQueue(e);if(!this._dirty||!this.initialized)return t;this._dirty=!1;const s=this._getListOfTiles();if(this._markTilesNotAlive(s),!e.run((()=>this._addTiles(s,e)))||!e.run((()=>this._filterExtentTiles(s,e)))||!e.run((()=>this._removeTiles(s,e)))||e.done)return void this._setDirty();const i=this._sortTiles(s);e.run((()=>this._showTiles(i,e)))&&e.run((()=>this._fetchTiles(i,e)))&&e.run((()=>this._updateMemoryEstimates(i,e)))||this._setDirty(),this._updated(),this.updating||this._updateMaximumNumberOfFeaturesExceeded()}_markTilesNotAlive(e){for(const t of e)t.alive=!1}_addTiles(e,t){return!(this._suspended||!this.tileDescriptors)&&(this.tileDescriptors.forEach((s=>{const i=this._featureTiles.get(s.id);i?i.alive=!0:t.done||(e.push(this._addTile(s)),t.madeProgress())})),t.hasProgressed)}_filterExtentTiles(e,t){for(const s of e){if(t.done)break;s.alive&&(s.filtered=!s.intersects(this.filterExtent),s.filtered&&(this._clearTile(s),t.madeProgress()))}return t.hasProgressed}_removeTiles(e,t){for(let s=e.length-1;s>=0&&!t.done;s--){const i=e[s];i.alive||(this._removeTile(i),s!==e.length-1&&(e[s]=e[e.length-1]),e.pop(),t.madeProgress())}return t.hasProgressed}_sortTiles(e){return e.sort(((e,t)=>e.descriptor.loadPriority-t.descriptor.loadPriority)),e}_showTiles(e,t){const s=this._updateRatio(e),i=e=>{const t=this._fullRatio<1?s(e)*this._farRatio:1;e.reduceFeatures(t,this.memoryFactor,this._objectIdField,this._reduceMode)&&this._setDirty();const{numFeatures:i,fetchingResolution:r,descriptor:a,isFetched:n}=e;return this._supportsResolution&&i>0&&r!==a.resolution&&n&&(e.requestRefetch(),this._setDirty()),this._showTile(e)};for(const r of e)if(!t.run((()=>i(r)))){this._setDirty();break}return t.hasProgressed}_fetchTiles(e,t){if(this._paused)return!1;let s=!1;for(const i of e){if(!i.needsFetch)continue;const e=null!=this.context.memoryCache?this.context.memoryCache.pop(i.id):null;if(e?.resolution!==i.displayingResolution){if(this._needsNumFeatures(i)){const e=new AbortController,r=this._fetchTileCount(i,e.signal);this._handleRequest(i,r,e,(()=>i.resetFetching()),(()=>i.numFeatures=M)),s=!0,t.madeProgress()}if(t.done)return!0}else i.cache=e,i.numFeatures&&this._notifyDataUpdating(),this._setDirty(),this._scheduleUpdated(),t.madeProgress()}if(s)return t.hasProgressed;for(const r of e)if(r.needsFetch){const e=new AbortController,s=this._fetchTile(r,e.signal);if(this._handleRequest(r,s,e,(e=>r.fetchDone(e)),(e=>{r.setFeatures([],0,null,void 0),this._invalidateCounts(),r.featuresMissing=!1,r.fetchFailed=!0,this.context.logFetchError(i.getLogger(this),e)})),t.madeProgress())return!0}return t.hasProgressed}_updateMemoryEstimates(e,t){return e.some((e=>!t.run((()=>e.updateMemoryEstimates()))&&(this._setDirty(),!0))),t.hasProgressed}_reclip(e,t){if(!this.initialized)return;const s=new Array;this._featureTiles.forEach((i=>{null!=i.displayingFeatures&&0!==i.displayingFeatures.length&&(i.intersectionIncludingBorrowed(t,L),i.intersectionIncludingBorrowed(e,k),m(L,k)||s.push(i))})),this._refreshDisplayingFeatures(s),this._updated()}_refreshDisplayingFeatures(e){const t=new Set,s=this._changes.updates;for(const i of e)if(null!=i.displayingFeatures)for(const e of i.displayingFeatures){const i=T(e,this._objectIdField);if(t.has(i))continue;t.add(i);const r=this._displayingFeatureReferences.get(i).feature;s.removes.push(r),s.adds.push(r)}this._applyChanges()}_updated(){let e=0;if(this._paused||this._featureTiles.forEach((t=>t.isFetching?++e:0)),this._isFetching=e>0,this._set("running",this._dirty),e>0||this._applyEditsTilesUpdated?this._notifyDataUpdating():this._dirty||this._set("dataUpdating",!1),this.updating){let t=0,s=0,i=0,r=0,a=0;const n=this._displayingFeatureReferences.size/this._numDisplayingFeatureReferences;this._featureTiles.forEach((e=>{if(++s,e.isFetching&&e.hasPreciseFeatureCount){const t=this._maximumFeaturesForTile(e)*(1-e.emptyFeatureRatio),s=null!=e.displayingFeatures?e.displayingFeatures.length*n:0;a+=t-s}e.needsFetch?++r:e.numFeatures>0&&(++i,t+=e.numFeatures)})),r+=e;let o=0,u=0;t?(u=t,o=Math.min(r*t/i,t)):(u=s,o=r),a=Math.min(this.maximumNumberOfFeatures-this.features.length,a),this._set("updatingTotal",u),this._set("updatingRemaining",o),this._set("expectedFeatureDiff",a)}else this._set("updatingTotal",0),this._set("updatingRemaining",0),this._set("expectedFeatureDiff",0);this.debugger?.update()}_updateMaximumNumberOfFeaturesExceeded(){for(const{perTileMaximumNumberOfFeaturesExceeded:e}of this._featureTiles.values())if(e)return void this._set("maximumNumberOfFeaturesExceeded",!0);this._set("maximumNumberOfFeaturesExceeded",!1)}_updateRatio(e){const t=I(e),s=e=>1/(1<<Math.max(0,t-e.descriptor.lij[0]));let i=0,r=0;for(const a of e){const e=a.numFeatures;i+=e,r+=e*s(a)}return this._fullRatio=Math.min(1,this.maximumNumberOfFeatures/i),this._farRatio=this.maximumNumberOfFeatures/r,this._scheduleUpdated(),s}_maximumFeaturesUpdated(e,t){e!==t&&(t>e&&this._featureTiles.forEach((e=>{if(!e.featuresMissing)return;const t=this._maximumFeaturesForTile(e);e.isFullyFetched(t)||(this._cancelFetchTile(e),this._resetFetchTile(e))})),this._setDirty())}_addTile(e){const t=new D(e);return this._featureTiles.set(t.id,t),this._resetFetchTile(t),this._referenceDisplayingFeaturesFromRelatedTiles(t),t}_referenceDisplayingFeaturesFromRelatedTiles(e){const t=e.displayingResolution;this._featureTiles.forEach((s=>{if(null!=s.displayingFeatures&&e!==s&&U(e.descriptor.lij,s.descriptor.lij)){null==e.displayingFeatures&&(e.displayingFeatures=[]),e.descriptor.extent&&s.descriptor.extent&&(e.extentIncludingBorrowedFeatures??=g(e.descriptor.extent),F(e.extentIncludingBorrowedFeatures,s.descriptor.extent,e.extentIncludingBorrowedFeatures));for(const i of s.displayingFeatures){e.displayingFeatures.push(i);const s=this._displayingFeatureReferences.get(T(i,this._objectIdField));s.ref(s.feature,t),this._numDisplayingFeatureReferences++}}})),e.featureLimit=null!=e.displayingFeatures?e.displayingFeatures.length:0}_removeTile(e){this._clearTile(e),this._featureTiles.delete(e.id)}_resetFetchTile(e){e.filtered=!e.intersects(this.filterExtent),e.filtered?e.needsFetch&&e.fetchDone(!1):e.requestFetch()}_cancelFetchTile(e){const t=e.requestController;null!=t&&(e.requestController=null,e.resetFetching(),t.abort())}async _fetchTileCount(e,t){e.numFeatures=await this._fetchCount(e,t),this._updateRatio(this._getListOfTiles())}async _fetchTile(e,t){e.fetchFailed=!1;const s=this._maximumFeaturesForTile(e);if(s<=0)return e.hasPreciseFeatureCount&&0===e.numFeatures||(e.fetchFailed=!0),z(e),!1;const i=this._getMaxRecordCount(e),r=Math.ceil(s/i);if(e.fetchingResolution=e.descriptor.resolution,P(e)||!this.context.capabilities.supportsMaxRecordCountFactor||e.numFeatures<=s&&r>v.MAX_MAX_RECORD_COUNT_FACTOR)return this._fetchPagedTile(e,t);const a=this._createQuery(e);if(a.maxRecordCountFactor=r,e.isRefetching&&e.features&&e.features.length>0){const t=Math.ceil(e.features.length/(1-e.emptyFeatureRatio)/i);a.maxRecordCountFactor=Math.max(t+1,a.maxRecordCountFactor)}const{features:o,exceededTransferLimit:u,fields:l,missingAttributes:h}=await this._queryFeatures(a,t),d=!u||a.maxRecordCountFactor>=v.MAX_MAX_RECORD_COUNT_FACTOR;return await this._frameTask.schedule((()=>{e.featuresMissing=e.hasPreciseFeatureCount&&o.length<e.numFeatures||!!u;const t=this._removeEmptyFeatures(o);e.setFeatures(o,t,q(l),N(void 0,h)),this._updateTileZQuantization(e)}),t),n(t),this._invalidateCounts(),d}async _fetchCount(e,t){return this.context.query.queryFeatureCount(this._createFeatureCountQuery(e),{signal:t})}async _fetchPagedTile(e,t){let s,i=0,r=0,a=0,o=this._maximumFeaturesForTile(e)-a;const u=this._getMaxRecordCount(e);let l,h=null;for(;;){const d=this._createQuery(e),c=this._setPagingParameters(d,i,o,u),{features:p,exceededTransferLimit:f,fields:_,missingAttributes:m}=await this._queryFeatures(d,t);if(await this._frameTask.schedule((()=>{c&&(i+=d.num),a+=p.length,r+=this._removeEmptyFeatures(p),e.featuresMissing=c&&e.hasPreciseFeatureCount&&i<e.numFeatures||!!f,s=s?.concat(p)??p,h=Q(h,_),l=N(l,m),e.setFeatures(s,r,h,l),this._updateTileZQuantization(e),this._invalidateCounts(),this._setDirty()}),t),n(t),o=this._maximumFeaturesForTile(e)-a,!c||!f||o<=0)return!f}}_createFeatureCountQuery(e){const t=this._createQuery(e);return this.context.capabilities.supportsCacheHint&&(t.resultType=void 0,t.cacheHint=!0),t}_createQuery(e){const t=this.context.createQuery();t.resultType=this._resultType(e);const s=P(e);return s||(t.geometry=y(e.descriptor.extent,this.context.tilingScheme.spatialReference)),this._setResolutionParams(t,e),"tile"!==t.resultType&&this.context.capabilities.supportsCacheHint&&(t.cacheHint=!0),!s&&this.context.effectiveDisplayFilter&&(t.where=c(t.where,this.context.effectiveDisplayFilter.where)),t}_setPagingParameters(e,t,s,i){return!!this.context.capabilities.supportsPagination&&(e.start=t,s>0&&this.context.capabilities.supportsMaxRecordCountFactor?(e.maxRecordCountFactor=Math.ceil(s/i),e.num=Math.min(e.maxRecordCountFactor*i,s)):e.num=Math.min(i),!0)}_getEffectiveTileResolution(e){if(P(e)||!this._supportsResolution)return null;const t=this.context.viewingMode===b.Global?this.context.tilingScheme.resolutionAtLevel(3):1/0;return Math.min(e.fetchingResolution,t)/this.lodFactor/this._tileZQuantization}get _supportsResolution(){return this.context.capabilities.supportsMultipleResolutions&&"point"!==this.context.geometryType}_setResolutionParams(e,t){const s=this._getEffectiveTileResolution(t);null!=s&&(this.context.capabilities.supportsQuantization?e.quantizationParameters=new R({mode:"view",originPosition:"upper-left",tolerance:s,extent:this.context.fullExtent}):"polyline"===this.context.geometryType&&(e.maxAllowableOffset=s))}_removeEmptyFeatures(e){const t=e.length;return s(e,(({geometry:e})=>x(e))),t-e.length}_needsNumFeatures(e){return this.useTileCount&&e.needsFeatureCount&&!P(e)}_getMaxRecordCount(e){switch(this._resultType(e)){case"tile":if(this.context.tileMaxRecordCount)return this.context.tileMaxRecordCount;break;case"standard":if(this.context.standardMaxRecordCount)return this.context.standardMaxRecordCount}return this.context.maxRecordCount||S}_resultType(e){if(this.context.capabilities.supportsResultType)return P(e)?"standard":"tile"}get _reduceMode(){const e=this.context.geometryType;return"polygon"===e||"polyline"===e?w.SIZE:w.RANDOM}_handleRequest(e,t,s,i,r){e.startFetch(),e.requestController=s;let n=!1;t.then((t=>{e.requestController=null,i(t)})).catch((t=>{e.requestController===s&&(e.requestController=null,e.fetchDone(!1)),a(t)?n=!0:r(t)})).then((()=>{n||this._setDirty(),this._scheduleUpdated()}))}_scheduleUpdated(){this.hasHandles("scheduleUpdated")||this.addHandles(h((()=>{this.removeHandles("scheduleUpdated"),this._updated()})),"scheduleUpdated")}_showTile(e){if(e.displayingFeatures&&!e.needsDisplayUpdate)return!1;const{features:t}=e;if(0===e.featureLimit||!t){const t=null!=e.displayingFeatures&&e.displayingFeatures.length>0;return this._hideTileFeatures(e),e.displayingFeatures=[],t}const s=e.fetchingResolution,{adds:i,updates:r}=this._changes,a=Math.min(e.featureLimit,t.length);e.featureLimit=a;for(let n=0;n<a;++n){const e=t[n],a=T(e,this._objectIdField),o=this._displayingFeatureReferences.get(a);if(o){const{oldVersion:t,newVersion:i}=o.ref(e,s);t!==i&&(t&&r.removes.push(t),i&&r.adds.push(i))}else this._displayingFeatureReferences.set(a,new this.FeatureReferenceClass(e,s)),i.push(e);this._numDisplayingFeatureReferences++}return this._hideTileFeatures(e),e.displayingResolution=e.fetchingResolution,this._applyChanges(),e.displayingFeatures=t.slice(0,a),!0}_hideTile(e){this._cancelFetchTile(e),this._hideTileFeatures(e)}_hideTileFeatures(e){if(null==e.displayingFeatures)return;const{updates:t,removes:s}=this._changes;for(const i of e.displayingFeatures){const r=T(i,this._objectIdField),a=this._displayingFeatureReferences.get(r);if(!a)continue;const{oldVersion:n,newVersion:o}=a.unref(e.displayingResolution);this._numDisplayingFeatureReferences--,n!==o&&(null==o?(this._displayingFeatureReferences.delete(r),n&&s.push(n)):(t.adds.push(o),n&&t.removes.push(n)))}this._applyChanges(),e.displayingFeatures=null}_notifyDataUpdating(){this._get("dataUpdating")||this._set("dataUpdating",!0)}_applyChanges(){const e=this._changes.updates;e.removes.length>0&&(this._notifyDataUpdating(),this.features.removeMany(e.removes),e.removes.length=0),e.adds.length>0&&(this._notifyDataUpdating(),this.features.addMany(e.adds),e.adds.length=0);const t=this._changes.adds,s=this._changes.removes,i=Math.min(t.length,s.length);let r=0;for(;r<i;){const e=Math.min(r+Z,i);this._notifyDataUpdating(),this.features.addMany(t.slice(r,e)),this.features.removeMany(s.slice(r,e)),r=e}t.length>i&&(this._notifyDataUpdating(),this.features.addMany(0===r?t:t.slice(r))),s.length>i&&(this._notifyDataUpdating(),this.features.removeMany(0===r?s:s.slice(r))),t.length=0,s.length=0}_clearTile(e){this._hideTile(e),e.features&&null!=this.context.memoryCache&&this.context.memoryCache.put(e.id,e.cache),e.setFeatures(null,0,null,void 0),this._invalidateCounts()}_invalidateCounts(){this.notifyChange("totalVertices"),this.notifyChange("totalFeatures"),this.notifyChange("memoryForUnusedFeatures")}_getListOfTiles(){return Array.from(this._featureTiles.values())}get storedFeatures(){return this._getListOfTiles().reduce(((e,t)=>e+(t.features?t.features.length:0)),0)}get missingTiles(){return Array.from(this._featureTiles.values()).reduce(((e,t)=>e+(t.needsFetch||t.isFetching?1:0)),0)}_maximumFeaturesForTile(e){const t=e.hasPreciseFeatureCount?e.numFeatures:1/0,s=e.hasPreciseFeatureCount?t:this.maximumNumberOfFeatures,i=this._fullRatio<1?this._farRatio:1;return Math.min(Math.ceil(s*i/(1-e.emptyFeatureRatio)),t)}get test(){}};function P(e){return"dummy-tile-full-extent"===e.id}function I(e){let t=0;for(const s of e)s.features&&s.features.length>0&&s.alive&&(t=Math.max(t,s.descriptor.lij[0]));return t}function z(e){e.setFeatures([],0,null,void 0),e.featuresMissing=!1}function q(e){return null==e?new Set:new Set(e.map((e=>e.name)))}function Q(e,t){if(null==e||null==t)return q(t);const s=new Set;for(const{name:i}of t)e.has(i)&&s.add(i);return s}function N(e,t){if(!t?.length)return e;e??=new Map;const s=()=>new Set;for(const{objectId:i,attribute:a}of t)r(e,i,s).add(a);return e}e([p({constructOnly:!0})],A.prototype,"features",void 0),e([p()],A.prototype,"tileDescriptors",void 0),e([p({value:1/0})],A.prototype,"maximumNumberOfFeatures",null),e([p({value:1})],A.prototype,"memoryFactor",null),e([p({value:1})],A.prototype,"lodFactor",null),e([p()],A.prototype,"useTileCount",null),e([p({readOnly:!0})],A.prototype,"updating",null),e([p({readOnly:!0})],A.prototype,"dataUpdating",void 0),e([p({readOnly:!0})],A.prototype,"running",void 0),e([p({readOnly:!0})],A.prototype,"updatingTotal",void 0),e([p({readOnly:!0})],A.prototype,"updatingRemaining",void 0),e([p({readOnly:!0})],A.prototype,"expectedFeatureDiff",void 0),e([p({readOnly:!0})],A.prototype,"memoryForUnusedFeatures",null),e([p({readOnly:!0})],A.prototype,"maximumNumberOfFeaturesExceeded",void 0),e([p({readOnly:!0})],A.prototype,"totalVertices",null),e([p({readOnly:!0})],A.prototype,"totalFeatures",null),e([p({readOnly:!0})],A.prototype,"hasAllFeatures",null),e([p({readOnly:!0})],A.prototype,"hasFullGeometries",null),e([p()],A.prototype,"filterExtent",null),e([p({constructOnly:!0})],A.prototype,"context",void 0),e([p()],A.prototype,"_dirty",void 0),e([p()],A.prototype,"_suspended",void 0),e([p()],A.prototype,"_pendingEdits",void 0),e([p()],A.prototype,"_applyEditsTilesUpdated",void 0),e([p()],A.prototype,"_paused",null),e([p()],A.prototype,"_isFetching",void 0),A=e([f("esri.views.3d.layers.support.FeatureTileFetcher3D")],A);const S=2e3,L=_(),k=_(),H=6e5,Z=200;export{A as FeatureTileFetcher3D};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import{filterInPlace as s}from"../../../../core/arrayUtils.js";import"../../../../core/has.js";import i from"../../../../core/Logger.js";import{getOrCreateMapValue as r}from"../../../../core/MapUtils.js";import{isAbortError as a,throwIfAborted as n}from"../../../../core/promiseUtils.js";import o from"../../../../core/ReactiveMap.js";import{on as u,watch as l}from"../../../../core/reactiveUtils.js";import{schedule as h}from"../../../../core/scheduling.js";import{signal as d}from"../../../../core/signal.js";import{sqlAnd as c}from"../../../../core/sql.js";import{property as p}from"../../../../core/accessorSupport/decorators/property.js";import{subclass as f}from"../../../../core/accessorSupport/decorators/subclass.js";import{create as _,equals as m,clone as g,expand as F,toExtent as y}from"../../../../geometry/support/aaBoundingRect.js";import{getObjectId as T,hasVertices as x}from"../../../../layers/graphics/dehydratedFeatures.js";import R from"../../../../rest/support/QuantizationParameters.js";import v from"../../../../rest/support/Query.js";import{ViewingMode as b}from"../../../ViewingMode.js";import{MultiFeatureReference as C,SingleFeatureReference as E}from"./featureReference.js";import{failedFeatureCount as M,FeatureTile as D,ReduceMode as w}from"./FeatureTile.js";import{tilesAreRelated as U}from"../../terrain/tileUtils.js";import{TaskPriority as j,ImmediateTask as O}from"../../../support/Scheduler.js";let A=class extends t{set maximumNumberOfFeatures(e){e=e||1/0;const t=this._get("maximumNumberOfFeatures");e===t||e<1||(this._set("maximumNumberOfFeatures",e),this._maximumFeaturesUpdated(t,e))}set memoryFactor(e){this.memoryFactor!==e&&(this._set("memoryFactor",e),this._setDirty())}set lodFactor(e){this.lodFactor!==e&&(this._set("lodFactor",e),this._supportsResolution&&this.refetch())}get useTileCount(){return this._useTileCount&&null!=this.context.query.queryFeatureCount}set useTileCount(e){this._useTileCount=e,this.notifyChange("useTileCount")}get updating(){return this._dirty||!!this._pendingEdits||this._isFetching||(this.tileDescriptors?.updating??!1)}get running(){return this._dirty}get memoryForUnusedFeatures(){let e=0;return this._featureTiles.forEach((t=>e+=t.estimatedUnusedSize)),e}get totalVertices(){let e=0;return this._featureTiles.forEach((t=>e+=t.numVertices)),e}get totalFeatures(){let e=0;return this._featureTiles.forEach((t=>e+=t.numFeatures)),e}get hasAllFeatures(){if(this._paused||this.dataUpdating)return!1;for(const e of this._featureTiles.values())if(!this.hasFullGeometries&&0!==e.emptyFeatureRatio||!e.hasAllFeatures)return!1;return!0}get hasFullGeometries(){if(!this._supportsResolution)return!0;return this.tileDescriptors.some(P)||!this.context.capabilities.supportsQuantization&&"polyline"!==this.context.geometryType}set filterExtent(e){if(null!=e&&this.context.tilingScheme&&!e.spatialReference.equals(this.context.tilingScheme.spatialReference))return void i.getLogger(this).error("#filterExtent=","extent needs to be in the same spatial reference as the tiling scheme");const t=this._get("filterExtent");if(t===e||null!=t&&e&&t.equals(e))return;const s=null!=e?e.clone():null;this._set("filterExtent",s),this._reclip(s,t)}_updateTileZQuantization(e){if(this.context.viewingMode===b.Global){const t=e.computeZQuantizationFactor();this._zQuantizationFactor.value<t&&(this._zQuantizationFactor.value=t)}}get _tileZQuantization(){return this.context.isDraped?1:this._zQuantizationFactor.value}constructor(e){super(e),this._useTileCount=!1,this.dataUpdating=!1,this.updatingTotal=0,this.updatingRemaining=0,this.expectedFeatureDiff=0,this.maximumNumberOfFeaturesExceeded=!1,this._fullRatio=1,this._farRatio=1,this._zQuantizationFactor=d(1),this._changes={updates:{adds:new Array,removes:new Array},adds:new Array,removes:new Array},this._featureTiles=new o,this._displayingFeatureReferences=new Map,this._numDisplayingFeatureReferences=0,this._dirty=!1,this._suspended=!0,this._pendingEdits=null,this._applyEditsTilesUpdated=!1,this._isFetching=!1;const t=e.context;this._frameTask=t.scheduler?.registerTask(j.FEATURE_TILE_FETCHER,this)??O,this.FeatureReferenceClass=t.capabilities.supportsMultipleResolutions?C:E,this._objectIdField=t.objectIdField}initialize(){this.addHandles([u((()=>this.tileDescriptors),"change",(()=>this._setDirty())),l((()=>this._tileZQuantization),(()=>this.refetch()))]),this._setDirty()}destroy(){this._frameTask.remove(),this._featureTiles.forEach((e=>{this._cancelFetchTile(e),this._removeTile(e)})),this._featureTiles.clear(),this._displayingFeatureReferences.clear(),this._pendingEdits?.controller.abort(),this._pendingEdits=null}get _paused(){return this._suspended||!!this._pendingEdits}restart(){this._featureTiles.forEach((e=>{this._cancelFetchTile(e),this._clearTile(e),this._resetFetchTile(e)})),null!=this.context.memoryCache&&this.context.memoryCache.clear(),this._setDirty()}refetch(){this._featureTiles.forEach((e=>{this._cancelFetchTile(e),this._resetFetchTile(e)})),null!=this.context.memoryCache&&this.context.memoryCache.clear(),this._setDirty()}suspend(){this._suspended||(this._suspended=!0,this._pause(),this._setDirty())}resume(){this._suspended&&(this._suspended=!1,this._unpause())}getMissingAttributesForFeature(e){for(const t of this._featureTiles.values()){const s=t.missingAttributes?.get(e);if(null!=s)return s}}_pause(){this._paused&&(this._featureTiles.forEach((e=>this._cancelFetchTile(e))),this._updated())}_unpause(){this._paused||this._setDirty()}get availableFields(){let e=null;return this._featureTiles.forEach((t=>{null!=t.displayingFeatures&&0!==t.displayingFeatures.length&&(null==e?e=new Set(t.availableFields):e.forEach((s=>{t.availableFields?.has(s)||e.delete(s)})))})),null!=e?e:new Set}applyEdits(e){this._pendingEdits||(this._pendingEdits={edits:Promise.resolve(),count:0,controller:new AbortController},this._pause());const t=this._pendingEdits;t.count++;const s=t.edits.then((()=>e.result.catch((e=>{if(a(e))throw e;return null})).then((e=>e?(this._applyEditsDeleteFeatures(e.deletedFeatures),this._applyEditsAddUpdateFeatures(e.addedFeatures,e.updatedFeatures,t.controller.signal).then((()=>e))):e)).then((e=>(0==--t.count&&(this._pendingEdits===t&&(this._pendingEdits=null),null!=this.context.memoryCache&&this.context.memoryCache.clear(),this._applyEditsTilesUpdated=!1,this._unpause()),e)))));return t.edits=s,this._updated(),s}_applyEditsDeleteFeatures(e){if(0===e.length)return;const t=this.context.globalIdField,s=t&&this.availableFields.has(t),r=new Set,a=this._objectIdField;e.forEach((({objectId:e,globalId:n})=>{(!e||e<0)&&t&&n&&(s||i.getLogger(this).errorOncePerTick(`Editing the specified service requires the layer's globalIdField, ${t} to be included the layer's outFields for updates to be reflected in the view`),e=this._objectIdFromGlobalId(n,a,t)),null!=e&&e>=0&&r.add(e)})),this._featureTiles.forEach((e=>{if(!e.features)return;const t=e.features.filter((e=>!r.has(T(e,this._objectIdField))));t.length!==e.features.length&&(this._applyEditsTileUpdated(),e.setFeatures(t,0,e.availableFields,e.missingAttributes),this._updateTileZQuantization(e),this._invalidateCounts())}))}_objectIdFromGlobalId(e,t,s){if(null==e)return null;const i=this.features.find((t=>t.attributes?.[s]===e));return i?T(i,t):null}async _applyEditsAddUpdateFeatures(e,t,s){const{objectIdField:r,globalIdField:a}=this.context,n=a&&this.availableFields.has(a),o=new Set,u=new Set;for(const i of e){const e=i.objectId;null!=e&&o.add(e)}for(const{objectId:h,globalId:d}of t){let e=h;(null==e||e<0)&&a&&(n||i.getLogger(this).errorOncePerTick(`Editing the specified service requires the layer's globalIdField, ${a} to be included the layer's outFields for updates to be reflected in the view`),e=this._objectIdFromGlobalId(d,r,a)),null!=e&&e>=0&&(o.add(e),u.add(e))}if(0===o.size)return;const l=[];this._featureTiles.forEach((e=>{const t=this._applyEditsAddUpdateTile(e,o,u,s);t&&l.push(t)})),this._updated(),await Promise.allSettled(l)}async _applyEditsAddUpdateTile(e,t,s,i){if(!e.features)return;e.fetchingResolution=e.descriptor.resolution;const r=this._createQuery(e);r.resultType=void 0,r.cacheHint=!1,r.objectIds=Array.from(t);const a=await this._queryFeatures(r,i);let n=null;if(s.size>0){const t=e.features.filter((e=>!s.has(T(e,this._objectIdField))));t.length!==e.features.length&&(n=t)}if(a.features.length>0){n||(n=e.features.slice());for(const e of a.features)n.push(e)}n&&(e.hasPreciseFeatureCount&&(e.numFeatures=Math.max(e.numFeatures,n.length)),this._applyEditsTileUpdated(),e.setFeatures(n,0,Q(e.availableFields,a.fields),N(e.missingAttributes,a.missingAttributes)),this._updateTileZQuantization(e),this._invalidateCounts())}_applyEditsTileUpdated(){this._applyEditsTilesUpdated||(this._applyEditsTilesUpdated=!0,this._updated())}_queryFeatures(e,t){return this.context.query.queryFeaturesDehydrated(e,{signal:t,timeout:H})}_setDirty(){this._dirty=!0,this._updated()}runTask(e){const t=this._frameTask.processQueue(e);if(!this._dirty||!this.initialized)return t;this._dirty=!1;const s=this._getListOfTiles();if(this._markTilesNotAlive(s),!e.run((()=>this._addTiles(s,e)))||!e.run((()=>this._filterExtentTiles(s,e)))||!e.run((()=>this._removeTiles(s,e)))||e.done)return void this._setDirty();const i=this._sortTiles(s);e.run((()=>this._showTiles(i,e)))&&e.run((()=>this._fetchTiles(i,e)))&&e.run((()=>this._updateMemoryEstimates(i,e)))||this._setDirty(),this._updated(),this.updating||this._updateMaximumNumberOfFeaturesExceeded()}_markTilesNotAlive(e){for(const t of e)t.alive=!1}_addTiles(e,t){return!(this._suspended||!this.tileDescriptors)&&(this.tileDescriptors.forEach((s=>{const i=this._featureTiles.get(s.id);i?i.alive=!0:t.done||(e.push(this._addTile(s)),t.madeProgress())})),t.hasProgressed)}_filterExtentTiles(e,t){for(const s of e){if(t.done)break;s.alive&&(s.filtered=!s.intersects(this.filterExtent),s.filtered&&(this._clearTile(s),t.madeProgress()))}return t.hasProgressed}_removeTiles(e,t){for(let s=e.length-1;s>=0&&!t.done;s--){const i=e[s];i.alive||(this._removeTile(i),s!==e.length-1&&(e[s]=e[e.length-1]),e.pop(),t.madeProgress())}return t.hasProgressed}_sortTiles(e){return e.sort(((e,t)=>e.descriptor.loadPriority-t.descriptor.loadPriority)),e}_showTiles(e,t){const s=this._updateRatio(e),i=e=>{const t=this._fullRatio<1?s(e)*this._farRatio:1;e.reduceFeatures(t,this.memoryFactor,this._objectIdField,this._reduceMode)&&this._setDirty();const{numFeatures:i,fetchingResolution:r,descriptor:a,isFetched:n}=e;return this._supportsResolution&&i>0&&r!==a.resolution&&n&&(e.requestRefetch(),this._setDirty()),this._showTile(e)};for(const r of e)if(!t.run((()=>i(r)))){this._setDirty();break}return t.hasProgressed}_fetchTiles(e,t){if(this._paused)return!1;let s=!1;for(const i of e){if(!i.needsFetch)continue;const e=null!=this.context.memoryCache?this.context.memoryCache.pop(i.id):null;if(e?.resolution!==i.displayingResolution){if(this._needsNumFeatures(i)){const e=new AbortController,r=this._fetchTileCount(i,e.signal);this._handleRequest(i,r,e,(()=>i.resetFetching()),(()=>i.numFeatures=M)),s=!0,t.madeProgress()}if(t.done)return!0}else i.cache=e,i.numFeatures&&this._notifyDataUpdating(),this._setDirty(),this._scheduleUpdated(),t.madeProgress()}if(s)return t.hasProgressed;for(const r of e){if(!r.needsFetch)continue;const e=new AbortController,s=this._fetchTile(r,e.signal);if(this._handleRequest(r,s,e,(e=>r.fetchDone(e)),(e=>{r.featuresMissing=!0,r.fetchFailed=!0,this.context.logFetchError(i.getLogger(this),e)})),t.madeProgress(),t.done)return!0}return t.hasProgressed}_updateMemoryEstimates(e,t){return e.some((e=>!t.run((()=>e.updateMemoryEstimates()))&&(this._setDirty(),!0))),t.hasProgressed}_reclip(e,t){if(!this.initialized)return;const s=new Array;this._featureTiles.forEach((i=>{null!=i.displayingFeatures&&0!==i.displayingFeatures.length&&(i.intersectionIncludingBorrowed(t,L),i.intersectionIncludingBorrowed(e,k),m(L,k)||s.push(i))})),this._refreshDisplayingFeatures(s),this._updated()}_refreshDisplayingFeatures(e){const t=new Set,s=this._changes.updates;for(const i of e)if(null!=i.displayingFeatures)for(const e of i.displayingFeatures){const i=T(e,this._objectIdField);if(t.has(i))continue;t.add(i);const r=this._displayingFeatureReferences.get(i).feature;s.removes.push(r),s.adds.push(r)}this._applyChanges()}_updated(){let e=0;if(this._paused||this._featureTiles.forEach((t=>t.isFetching?++e:0)),this._isFetching=e>0,e>0||this._applyEditsTilesUpdated?this._notifyDataUpdating():this._dirty||this._set("dataUpdating",!1),this.updating){let t=0,s=0,i=0,r=0,a=0;const n=this._displayingFeatureReferences.size/this._numDisplayingFeatureReferences;this._featureTiles.forEach((e=>{if(++s,e.isFetching&&e.hasPreciseFeatureCount){const t=this._maximumFeaturesForTile(e)*(1-e.emptyFeatureRatio),s=null!=e.displayingFeatures?e.displayingFeatures.length*n:0;a+=t-s}e.needsFetch?++r:e.numFeatures>0&&(++i,t+=e.numFeatures)})),r+=e;let o=0,u=0;t?(u=t,o=Math.min(r*t/i,t)):(u=s,o=r),a=Math.min(this.maximumNumberOfFeatures-this.features.length,a),this._set("updatingTotal",u),this._set("updatingRemaining",o),this._set("expectedFeatureDiff",a)}else this._set("updatingTotal",0),this._set("updatingRemaining",0),this._set("expectedFeatureDiff",0);this.debugger?.update()}_updateMaximumNumberOfFeaturesExceeded(){for(const{perTileMaximumNumberOfFeaturesExceeded:e}of this._featureTiles.values())if(e)return void this._set("maximumNumberOfFeaturesExceeded",!0);this._set("maximumNumberOfFeaturesExceeded",!1)}_updateRatio(e){const t=I(e),s=e=>1/(1<<Math.max(0,t-e.descriptor.lij[0]));let i=0,r=0;for(const a of e){const e=a.numFeatures;i+=e,r+=e*s(a)}return this._fullRatio=Math.min(1,this.maximumNumberOfFeatures/i),this._farRatio=this.maximumNumberOfFeatures/r,this._scheduleUpdated(),s}_maximumFeaturesUpdated(e,t){e!==t&&(t>e&&this._featureTiles.forEach((e=>{if(!e.featuresMissing)return;const t=this._maximumFeaturesForTile(e);e.isFullyFetched(t)||(this._cancelFetchTile(e),this._resetFetchTile(e))})),this._setDirty())}_addTile(e){const t=new D(e);return this._featureTiles.set(t.id,t),this._resetFetchTile(t),this._referenceDisplayingFeaturesFromRelatedTiles(t),t}_referenceDisplayingFeaturesFromRelatedTiles(e){const t=e.displayingResolution;this._featureTiles.forEach((s=>{if(null!=s.displayingFeatures&&e!==s&&U(e.descriptor.lij,s.descriptor.lij)){null==e.displayingFeatures&&(e.displayingFeatures=[]),e.descriptor.extent&&s.descriptor.extent&&(e.extentIncludingBorrowedFeatures??=g(e.descriptor.extent),F(e.extentIncludingBorrowedFeatures,s.descriptor.extent,e.extentIncludingBorrowedFeatures));for(const i of s.displayingFeatures){e.displayingFeatures.push(i);const s=this._displayingFeatureReferences.get(T(i,this._objectIdField));s.ref(s.feature,t),this._numDisplayingFeatureReferences++}}})),e.featureLimit=null!=e.displayingFeatures?e.displayingFeatures.length:0}_removeTile(e){this._clearTile(e),this._featureTiles.delete(e.id)}_resetFetchTile(e){e.filtered=!e.intersects(this.filterExtent),e.filtered?e.needsFetch&&e.fetchDone(!1):e.requestFetch()}_cancelFetchTile(e){const t=e.requestController;null!=t&&(e.requestController=null,e.resetFetching(),t.abort())}async _fetchTileCount(e,t){e.numFeatures=await this._fetchCount(e,t),this._updateRatio(this._getListOfTiles())}async _fetchTile(e,t){e.fetchFailed=!1;const s=this._maximumFeaturesForTile(e);if(s<=0)return e.hasPreciseFeatureCount&&0===e.numFeatures||(e.fetchFailed=!0),z(e),!1;const i=this._getMaxRecordCount(e),r=Math.ceil(s/i);if(e.fetchingResolution=e.descriptor.resolution,P(e)||!this.context.capabilities.supportsMaxRecordCountFactor||e.numFeatures<=s&&r>v.MAX_MAX_RECORD_COUNT_FACTOR)return this._fetchPagedTile(e,t);const a=this._createQuery(e);if(a.maxRecordCountFactor=r,e.isRefetching&&e.features&&e.features.length>0){const t=Math.ceil(e.features.length/(1-e.emptyFeatureRatio)/i);a.maxRecordCountFactor=Math.max(t+1,a.maxRecordCountFactor)}const{features:o,exceededTransferLimit:u,fields:l,missingAttributes:h}=await this._queryFeatures(a,t),d=!u||a.maxRecordCountFactor>=v.MAX_MAX_RECORD_COUNT_FACTOR;return await this._frameTask.schedule((()=>{e.featuresMissing=e.hasPreciseFeatureCount&&o.length<e.numFeatures||!!u;const t=this._removeEmptyFeatures(o);e.setFeatures(o,t,q(l),N(void 0,h)),this._updateTileZQuantization(e)}),t),n(t),this._invalidateCounts(),d}async _fetchCount(e,t){return this.context.query.queryFeatureCount(this._createFeatureCountQuery(e),{signal:t})}async _fetchPagedTile(e,t){let s,i=0,r=0,a=0,o=this._maximumFeaturesForTile(e)-a;const u=this._getMaxRecordCount(e);let l,h=null;for(;;){const d=this._createQuery(e),c=this._setPagingParameters(d,i,o,u),{features:p,exceededTransferLimit:f,fields:_,missingAttributes:m}=await this._queryFeatures(d,t);if(await this._frameTask.schedule((()=>{c&&(i+=d.num),a+=p.length,r+=this._removeEmptyFeatures(p),e.featuresMissing=c&&e.hasPreciseFeatureCount&&i<e.numFeatures||!!f,s=s?.concat(p)??p,h=Q(h,_),l=N(l,m),e.setFeatures(s,r,h,l),this._updateTileZQuantization(e),this._invalidateCounts(),this._setDirty()}),t),n(t),o=this._maximumFeaturesForTile(e)-a,!c||!f||o<=0)return!f}}_createFeatureCountQuery(e){const t=this._createQuery(e);return this.context.capabilities.supportsCacheHint&&(t.resultType=void 0,t.cacheHint=!0),t}_createQuery(e){const t=this.context.createQuery();t.resultType=this._resultType(e);const s=P(e);return s||(t.geometry=y(e.descriptor.extent,this.context.tilingScheme.spatialReference)),this._setResolutionParams(t,e),"tile"!==t.resultType&&this.context.capabilities.supportsCacheHint&&(t.cacheHint=!0),!s&&this.context.effectiveDisplayFilter&&(t.where=c(t.where,this.context.effectiveDisplayFilter.where)),t}_setPagingParameters(e,t,s,i){return!!this.context.capabilities.supportsPagination&&(e.start=t,s>0&&this.context.capabilities.supportsMaxRecordCountFactor?(e.maxRecordCountFactor=Math.ceil(s/i),e.num=Math.min(e.maxRecordCountFactor*i,s)):e.num=Math.min(i),!0)}_getEffectiveTileResolution(e){if(P(e)||!this._supportsResolution)return null;const t=this.context.viewingMode===b.Global?this.context.tilingScheme.resolutionAtLevel(3):1/0;return Math.min(e.fetchingResolution,t)/this.lodFactor/this._tileZQuantization}get _supportsResolution(){return this.context.capabilities.supportsMultipleResolutions&&"point"!==this.context.geometryType}_setResolutionParams(e,t){const s=this._getEffectiveTileResolution(t);null!=s&&(this.context.capabilities.supportsQuantization?e.quantizationParameters=new R({mode:"view",originPosition:"upper-left",tolerance:s,extent:this.context.fullExtent}):"polyline"===this.context.geometryType&&(e.maxAllowableOffset=s))}_removeEmptyFeatures(e){const t=e.length;return s(e,(({geometry:e})=>x(e))),t-e.length}_needsNumFeatures(e){return this.useTileCount&&e.needsFeatureCount&&!P(e)}_getMaxRecordCount(e){switch(this._resultType(e)){case"tile":if(this.context.tileMaxRecordCount)return this.context.tileMaxRecordCount;break;case"standard":if(this.context.standardMaxRecordCount)return this.context.standardMaxRecordCount}return this.context.maxRecordCount||S}_resultType(e){if(this.context.capabilities.supportsResultType)return P(e)?"standard":"tile"}get _reduceMode(){const e=this.context.geometryType;return"polygon"===e||"polyline"===e?w.SIZE:w.RANDOM}_handleRequest(e,t,s,i,r){e.startFetch(),e.requestController=s;let n=!1;t.then((t=>{e.requestController=null,i(t)})).catch((t=>{e.requestController===s&&(e.requestController=null,e.fetchDone(!1)),a(t)?n=!0:r(t)})).then((()=>{n||this._setDirty(),this._scheduleUpdated()}))}_scheduleUpdated(){this.hasHandles("scheduleUpdated")||this.addHandles(h((()=>{this.removeHandles("scheduleUpdated"),this._updated()})),"scheduleUpdated")}_showTile(e){if(e.displayingFeatures&&!e.needsDisplayUpdate)return!1;const{features:t}=e;if(0===e.featureLimit||!t){const t=null!=e.displayingFeatures&&e.displayingFeatures.length>0;return this._hideTileFeatures(e),e.displayingFeatures=[],t}const s=e.fetchingResolution,{adds:i,updates:r}=this._changes,a=Math.min(e.featureLimit,t.length);e.featureLimit=a;for(let n=0;n<a;++n){const e=t[n],a=T(e,this._objectIdField),o=this._displayingFeatureReferences.get(a);if(o){const{oldVersion:t,newVersion:i}=o.ref(e,s);t!==i&&(t&&r.removes.push(t),i&&r.adds.push(i))}else this._displayingFeatureReferences.set(a,new this.FeatureReferenceClass(e,s)),i.push(e);this._numDisplayingFeatureReferences++}return this._hideTileFeatures(e),e.displayingResolution=e.fetchingResolution,this._applyChanges(),e.displayingFeatures=t.slice(0,a),!0}_hideTile(e){this._cancelFetchTile(e),this._hideTileFeatures(e)}_hideTileFeatures(e){if(null==e.displayingFeatures)return;const{updates:t,removes:s}=this._changes;for(const i of e.displayingFeatures){const r=T(i,this._objectIdField),a=this._displayingFeatureReferences.get(r);if(!a)continue;const{oldVersion:n,newVersion:o}=a.unref(e.displayingResolution);this._numDisplayingFeatureReferences--,n!==o&&(null==o?(this._displayingFeatureReferences.delete(r),n&&s.push(n)):(t.adds.push(o),n&&t.removes.push(n)))}this._applyChanges(),e.displayingFeatures=null}_notifyDataUpdating(){this._get("dataUpdating")||this._set("dataUpdating",!0)}_applyChanges(){const e=this._changes.updates;e.removes.length>0&&(this._notifyDataUpdating(),this.features.removeMany(e.removes),e.removes.length=0),e.adds.length>0&&(this._notifyDataUpdating(),this.features.addMany(e.adds),e.adds.length=0);const t=this._changes.adds,s=this._changes.removes,i=Math.min(t.length,s.length);let r=0;for(;r<i;){const e=Math.min(r+Z,i);this._notifyDataUpdating(),this.features.addMany(t.slice(r,e)),this.features.removeMany(s.slice(r,e)),r=e}t.length>i&&(this._notifyDataUpdating(),this.features.addMany(0===r?t:t.slice(r))),s.length>i&&(this._notifyDataUpdating(),this.features.removeMany(0===r?s:s.slice(r))),t.length=0,s.length=0}_clearTile(e){this._hideTile(e),e.features&&null!=this.context.memoryCache&&this.context.memoryCache.put(e.id,e.cache),e.setFeatures(null,0,null,void 0),this._invalidateCounts()}_invalidateCounts(){this.notifyChange("totalVertices"),this.notifyChange("totalFeatures"),this.notifyChange("memoryForUnusedFeatures")}_getListOfTiles(){return Array.from(this._featureTiles.values())}get storedFeatures(){return this._getListOfTiles().reduce(((e,t)=>e+(t.features?t.features.length:0)),0)}get missingTiles(){return Array.from(this._featureTiles.values()).reduce(((e,t)=>e+(t.needsFetch||t.isFetching?1:0)),0)}_maximumFeaturesForTile(e){const t=e.hasPreciseFeatureCount?e.numFeatures:1/0,s=e.hasPreciseFeatureCount?t:this.maximumNumberOfFeatures,i=this._fullRatio<1?this._farRatio:1;return Math.min(Math.ceil(s*i/(1-e.emptyFeatureRatio)),t)}get test(){}};function P(e){return"dummy-tile-full-extent"===e.id}function I(e){let t=0;for(const s of e)s.features&&s.features.length>0&&s.alive&&(t=Math.max(t,s.descriptor.lij[0]));return t}function z(e){e.setFeatures([],0,null,void 0),e.featuresMissing=!1}function q(e){return null==e?new Set:new Set(e.map((e=>e.name)))}function Q(e,t){if(null==e||null==t)return q(t);const s=new Set;for(const{name:i}of t)e.has(i)&&s.add(i);return s}function N(e,t){if(!t?.length)return e;e??=new Map;const s=()=>new Set;for(const{objectId:i,attribute:a}of t)r(e,i,s).add(a);return e}e([p({constructOnly:!0})],A.prototype,"features",void 0),e([p()],A.prototype,"tileDescriptors",void 0),e([p({value:1/0})],A.prototype,"maximumNumberOfFeatures",null),e([p({value:1})],A.prototype,"memoryFactor",null),e([p({value:1})],A.prototype,"lodFactor",null),e([p()],A.prototype,"useTileCount",null),e([p({readOnly:!0})],A.prototype,"updating",null),e([p({readOnly:!0})],A.prototype,"dataUpdating",void 0),e([p({readOnly:!0})],A.prototype,"updatingTotal",void 0),e([p({readOnly:!0})],A.prototype,"updatingRemaining",void 0),e([p({readOnly:!0})],A.prototype,"expectedFeatureDiff",void 0),e([p({readOnly:!0})],A.prototype,"memoryForUnusedFeatures",null),e([p({readOnly:!0})],A.prototype,"maximumNumberOfFeaturesExceeded",void 0),e([p({readOnly:!0})],A.prototype,"totalVertices",null),e([p({readOnly:!0})],A.prototype,"totalFeatures",null),e([p({readOnly:!0})],A.prototype,"hasAllFeatures",null),e([p({readOnly:!0})],A.prototype,"hasFullGeometries",null),e([p()],A.prototype,"filterExtent",null),e([p({constructOnly:!0})],A.prototype,"context",void 0),e([p()],A.prototype,"_dirty",void 0),e([p()],A.prototype,"_suspended",void 0),e([p()],A.prototype,"_pendingEdits",void 0),e([p()],A.prototype,"_applyEditsTilesUpdated",void 0),e([p()],A.prototype,"_paused",null),e([p()],A.prototype,"_isFetching",void 0),A=e([f("esri.views.3d.layers.support.FeatureTileFetcher3D")],A);const S=2e3,L=_(),k=_(),H=6e5,Z=200;export{A as FeatureTileFetcher3D};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{throwIfAborted as e,whenOrAbort as t}from"../../../core/promiseUtils.js";import{isSVG as r}from"../../../core/urlUtils.js";import{TextureCollection as s,TextureRequest as i,TextureResult as o}from"./TextureCollection.js";import{Texture as n}from"../webgl-engine/lib/Texture.js";import{TextureWrapMode as l}from"../../webgl/enums.js";class a extends s{constructor(e,t,r){super(t,r),this._streamDataRequester=e}async fromUrl(r,s,n){e(n);const l=n?.signal,a=this.makeUid(r,s);let h=this._textureRequests.get(a);if(!h){const e=new AbortController,t=this._streamDataRequester.request(r,"image",{uid:a,signal:e.signal});h=new i,h.abortController=e;const n=h;this._textureRequests.set(a,h),h.textureAsync=t.then((async e=>{const t=this._createTexture(r,e,s);return n.texture=t,n.abortController=null,await t.load(this._stage.renderView.renderingContext),this._stage.add(t),new o(a,t,(()=>this._release(a)))}),(e=>{throw n.abortController=null,e}))}h.referenceCount++;try{return await t(h.textureAsync,l)}catch(u){throw this._release(a),u}}_createTexture(e,t,s){const i={width:t.width,height:t.height,wrap:{s:l.CLAMP_TO_EDGE,t:l.CLAMP_TO_EDGE},preMultiplyAlpha:!0,reloadable:!0};if(r(e)){if(s||0===t.width&&0===t.height){const e=t.width?t.height/t.width:1;s=s||64,e>1?(t.width=Math.round(s/e),t.height=s):(t.width=s,t.height=Math.round(s*e))}this._stage.renderView?.renderingContext.driverTest.svgPremultipliesAlpha.result&&(i.preMultiplyAlpha=!1)}return new n(t,i)}}export{a as StreamTextureCollection};
5
+ import{throwIfAborted as e,whenOrAbort as t}from"../../../core/promiseUtils.js";import{isSVG as r}from"../../../core/urlUtils.js";import{TextureCollection as s,TextureRequest as i,TextureHandle as o}from"./TextureCollection.js";import{Texture as n}from"../webgl-engine/lib/Texture.js";import{TextureWrapMode as l}from"../../webgl/enums.js";class a extends s{constructor(e,t,r){super(t,r),this._streamDataRequester=e}async fromUrl(r,s,n){e(n);const l=n?.signal,a=this.makeUid(r,s);let h=this._textureRequests.get(a);if(!h){const e=new AbortController,t=this._streamDataRequester.request(r,"image",{uid:a,signal:e.signal});h=new i,h.abortController=e;const n=h;this._textureRequests.set(a,h),h.textureAsync=t.then((async e=>{const t=this._createTexture(r,e,s);return n.texture=t,n.abortController=null,await t.load(this._stage.renderView.renderingContext),this._stage.add(t),new o(a,t,(()=>this._release(a)))}),(e=>{throw n.abortController=null,e}))}h.referenceCount++;try{return await t(h.textureAsync,l)}catch(u){throw this._release(a),u}}_createTexture(e,t,s){const i={width:t.width,height:t.height,wrap:{s:l.CLAMP_TO_EDGE,t:l.CLAMP_TO_EDGE},preMultiplyAlpha:!0,reloadable:!0};if(r(e)){if(s||0===t.width&&0===t.height){const e=t.width?t.height/t.width:1;s=s||64,e>1?(t.width=Math.round(s/e),t.height=s):(t.width=s,t.height=Math.round(s*e))}this._stage.renderView?.renderingContext.driverTest.svgPremultipliesAlpha.result&&(i.preMultiplyAlpha=!1)}return new n(t,i)}}export{a as StreamTextureCollection};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import"../../../core/has.js";import{property as r}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as s}from"../../../core/accessorSupport/decorators/subclass.js";import{TaskPriority as o,ImmediateTask as u}from"../../support/Scheduler.js";let i=class extends t{constructor(e,t){super({}),this._stage=e,this._textureRequests=new Map,this._frameTask=t?.registerTask(o.TEXTURE_UNLOAD)??u}normalizeCtorArgs(){return{}}destroy(){super.destroy(),this._frameTask?.remove(),this._textureRequests?.forEach((e=>this._releaseTextureRequest(e))),this._textureRequests?.clear()}get updating(){return this._frameTask.updating}fromData(e,t){const r=this.makeUid(e);let s=this._textureRequests.get(r);if(!s){const e=new a;e.texture=t(),this._stage&&(e.texture.load(this._stage.renderView.renderingContext),this._stage.add(e.texture)),this._textureRequests.set(r,e),s=e}return s.referenceCount++,new n(r,s.texture,(()=>this._release(r)))}_release(e){const t=this._textureRequests.get(e);t?(t.referenceCount<1&&console.warn("TextureCollection: reference count is < 1 for "+e),t.referenceCount--,t.referenceCount<1&&this._frameTask.schedule((()=>this._releaseNow(e)))):console.warn(`TextureCollection: texture doesn't exist: '${e}'`)}get test(){}_releaseNow(e){if(!this._textureRequests)return;const t=this._textureRequests.get(e);!t||t.referenceCount>0||(t.texture?.unload(),this._releaseTextureRequest(t),this._textureRequests.delete(e))}_releaseTextureRequest(e){e.texture?this._stage?.remove(e.texture):e.abortController&&(e.abortController.abort(),e.abortController=null)}makeUid(e,t=null){return null!=t?`${e}.${t}px`:e}};e([r()],i.prototype,"_frameTask",void 0),e([r()],i.prototype,"updating",null),i=e([s("esri.views.3d.support.TextureCollection")],i);class n{constructor(e,t,r){this.uid=e,this.texture=t,this.release=r}}class a{constructor(){this.referenceCount=0}}export{i as TextureCollection,a as TextureRequest,n as TextureResult};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import"../../../core/has.js";import{property as r}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as s}from"../../../core/accessorSupport/decorators/subclass.js";import{TaskPriority as o,ImmediateTask as u}from"../../support/Scheduler.js";let i=class extends t{constructor(e,t){super({}),this._stage=e,this._textureRequests=new Map,this._frameTask=t?.registerTask(o.TEXTURE_UNLOAD)??u}normalizeCtorArgs(){return{}}destroy(){super.destroy(),this._frameTask?.remove(),this._textureRequests?.forEach((e=>this._releaseTextureRequest(e))),this._textureRequests?.clear()}get updating(){return this._frameTask.updating}fromData(e,t){const r=this.makeUid(e);let s=this._textureRequests.get(r);if(!s){const e=new a;e.texture=t(),this._stage&&(e.texture.load(this._stage.renderView.renderingContext),this._stage.add(e.texture)),this._textureRequests.set(r,e),s=e}return s.referenceCount++,new n(r,s.texture,(()=>this._release(r)))}_release(e){const t=this._textureRequests.get(e);t?(t.referenceCount<1&&console.warn("TextureCollection: reference count is < 1 for "+e),t.referenceCount--,t.referenceCount<1&&this._frameTask.schedule((()=>this._releaseNow(e)))):console.warn(`TextureCollection: texture doesn't exist: '${e}'`)}get test(){}_releaseNow(e){if(!this._textureRequests)return;const t=this._textureRequests.get(e);!t||t.referenceCount>0||(t.texture?.unload(),this._releaseTextureRequest(t),this._textureRequests.delete(e))}_releaseTextureRequest(e){e.texture?this._stage?.remove(e.texture):e.abortController&&(e.abortController.abort(),e.abortController=null)}makeUid(e,t=null){return null!=t?`${e}.${t}px`:e}};e([r()],i.prototype,"_frameTask",void 0),e([r()],i.prototype,"updating",null),i=e([s("esri.views.3d.support.TextureCollection")],i);class n{constructor(e,t,r){this.uid=e,this.texture=t,this.release=r}}class a{constructor(){this.referenceCount=0}}export{i as TextureCollection,n as TextureHandle,a as TextureRequest};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import has from"../../../core/has.js";import{disposeMaybe as i}from"../../../core/maybe.js";import{MemCachePool as r}from"../../../core/MemCachePool.js";import s from"../../../core/ObjectPool.js";import{watch as n,sync as o}from"../../../core/reactiveUtils.js";import{property as a}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import{IDENTITY as c}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{d,i as h,f as u}from"../../../chunks/vec32.js";import{ZEROS as g,fromValues as _,create as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as f,ZEROS as m}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{create as b,set as y}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as T}from"../../../geometry/support/buffer/BufferView.js";import{ViewingMode as R}from"../../ViewingMode.js";import{TextureUpdate as x}from"./interfaces.js";import{LayerClass as O}from"./LayerClass.js";import{OverlayContent as v}from"./OverlayContent.js";import{overlayRenderOccludedFlag as w}from"./OverlayRenderer.js";import{PatchRenderData as P}from"./PatchRenderData.js";import{RenderOrder as D}from"./RenderOrder.js";import{TerrainAttributesCache as S}from"./TerrainAttributesCache.js";import{enableTerrainInternalChecks as C}from"./terrainUtils.js";import{TileRenderer as E}from"./TileRenderer.js";import{TileUpdate as A}from"./TileUpdate.js";import{IteratorPreorder as j,sortTiles as N,compareTiles as B}from"./tileUtils.js";import{TransparencyMode as I}from"./TransparencyMode.js";import{componentMinimalSizeForIntersectionData as q,ComponentIntersectionData as F}from"../webgl-engine/collections/Component/ComponentIntersectionData.js";import{ShaderOutput as U}from"../webgl-engine/core/shaderLibrary/ShaderOutput.js";import{TileBlendInput as G}from"../webgl-engine/core/shaderLibrary/terrain/TileBlendInput.js";import{SyncRenderPlugin as M,ConsumesDepth as L,ConsumesNone as k}from"../webgl-engine/effects/RenderPlugin.js";import{Vertices as z}from"../webgl-engine/lib/Attribute.js";import{RenderRequestType as V}from"../webgl-engine/lib/basicInterfaces.js";import{createEmptyTexture as H}from"../webgl-engine/lib/glUtil3D.js";import{newIntersectorResult as Y}from"../webgl-engine/lib/Intersector.js";import{IntersectorType as Q,StoreResults as W}from"../webgl-engine/lib/IntersectorInterfaces.js";import{RenderOccludedFlag as X}from"../webgl-engine/lib/Material.js";import{intersectAabbInvDirBefore as K,intersectTriangles as Z,MeshIntersectionOptions as J}from"../webgl-engine/lib/RayIntersections.js";import{RenderSlot as $}from"../webgl-engine/lib/RenderSlot.js";import{getSettings as ee}from"../webgl-engine/lib/screenSizePerspectiveUtils.js";import{VertexAttribute as te}from"../webgl-engine/lib/VertexAttribute.js";import{terrainId as ie,getVerticalOffsetTerrain as re}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as se}from"../webgl-engine/materials/DrawParameters.js";import{T as ne}from"../../../chunks/Terrain.glsl.js";import{TerrainTechnique as oe}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as ae}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{PrimitiveType as le}from"../../webgl/enums.js";const ce=7,de=10,he=b();let ue=class extends M{get _isGlobal(){return this._stage.viewingMode===R.Global}get _techniques(){return this._context.techniques}get _rctx(){return this._context.renderContext.rctx}constructor(e,t,i,n,o){super({}),this._overlayRenderer=e,this._stage=t,this._allTiles=i,this._ellipsoidRadius=n,this.type=Q.TERRAIN,this.isGround=!0,this._passParameters=new ne,this._drawParameters=new se,this._renderDataPool=new s(P),this._visiblePatchesByOrigin=new Map,this._allPatchesByOrigin=new Map,this._patchesByOriginDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new j,this._castShadows=!1,this._inViewshed=!1,this._emptyTex=null,this._tileRenderer=null,this._stencilEnabledLayerExtents=new Array,this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this.renderOccludedFlags=X.Occlude,this.produces=new Map([[$.OPAQUE_TERRAIN,()=>this._produces()&&this.transparency===I.Opaque],[$.TRANSPARENT_TERRAIN,()=>this._produces()&&(this.transparency===I.Transparent||this.transparency===I.InvisibleWithDraped)],[$.OCCLUDED_TERRAIN,()=>this._produces()]]),this._tileSize=256,this._configuration=new ae(t.viewingMode===R.Global),this._tileTextureCache=new r(((e,t)=>o.newCache(e,t)),"TileTexture"),this.tileGeometryCache=new S(o)}normalizeCtorArgs(){return{}}initialize(){this._stage.addRenderPlugin(this),this.addHandles(n((()=>this._overlayRenderer.rendersOccludedDraped),(e=>{this.renderOccludedFlags=e?w:X.Occlude,this.setNeedsRender()}),o))}destroy(){this._stage.removeRenderPlugin(this),this._tileTextureCache.destroy(),this.tileGeometryCache.destroy()}_produces(){return this.visible&&!!this._rootTiles&&!this.renderingDisabled}consumes(){return this._overlayRenderer.hasWater?L:k}set renderingDisabled(e){this._set("renderingDisabled",!!e),this.setDirty()}set visible(e){this._set("visible",!!e),this.setDirty()}updateHeading(e){this._tileRenderer?.updateHeading(e)}set transparency(e){this._configuration.transparencyMode!==e&&(this._configuration.transparencyMode=e,this.setNeedsRender())}get transparency(){return this._configuration.transparencyMode}get tileRenderer(){return this._tileRenderer}get texturesBeingCompressed(){return this._tileRenderer?this._tileRenderer?.texturesBeingCompressed:null}get renderPatchBorders(){return this._configuration.tileBorders}set renderPatchBorders(e){this._configuration.tileBorders!==e&&(this._configuration.tileBorders=e,this.setNeedsRender(),this.notifyChange("renderPatchBorders"))}get visualizeNormals(){return this._configuration.visualizeNormals}set visualizeNormals(e){this._configuration.visualizeNormals!==e&&(this._configuration.visualizeNormals=e,this.setNeedsRender(),this.notifyChange("visualizeNormals"))}get cullBackFaces(){return this._configuration.backfaceCullingEnabled}set cullBackFaces(e){this._configuration.backfaceCullingEnabled!==e&&(this._configuration.backfaceCullingEnabled=e,this.notifyChange("cullBackFaces"),this.setNeedsRender())}set renderOrder(e){this._set("renderOrder",e),this._setSortingDirty()}get layerUid(){return ie}get slicePlaneEnabled(){return this._configuration.hasSlicePlane}set slicePlaneEnabled(e){this._configuration.hasSlicePlane!==e&&(this._configuration.hasSlicePlane=e,this.setNeedsRender())}set textureFadingEnabled(e){this._configuration.textureFadingEnabled!==e&&(this._configuration.textureFadingEnabled=e,this.setNeedsRender())}set pbrMode(e){this._configuration.pbrMode!==e&&(this._configuration.pbrMode=e,this.setNeedsRender())}setDebugScreenSizePerspective(e){this._configuration.screenSizePerspective!==e&&(this._configuration.screenSizePerspective=e,this.setNeedsRender())}setRootTiles(e){this._rootTiles=e,this.setDirty()}setStencilEnabledLayerExtents(e){this._stencilEnabledLayerExtents=e,this._setSortingDirty()}set tileSize(e){this._tileSize=e,null!=this._tileRenderer&&(this._tileRenderer.tileSize=e),this.setDirty()}get tileSize(){return this._tileSize}_ensureRenderData(e){e.renderData||(e.renderData=this._renderDataPool.acquire(),e.renderData.init(e,this._getLocalOriginOfTile(e)))}loadTile(e){this._ensureRenderData(e),this.updateTileGeometryState(e),this.reuseTextureFromParent(e)||this.updateTileTexture(e,A.TEXTURE_FADING)}reuseTextureFromParent(e){const t=e.parent;if(!t)return!1;const i=f(1&e.lij[2]?.5:0,1&e.lij[1]?0:.5,.5,.5);return t.renderData?.reuseTexture(e.renderData,i)??!1}updateTileTexture(e,t){null!=this._tileRenderer&&(this._tileRenderer.updateTileTexture(e,t===A.TEXTURE_FADING?x.FADING:x.UNFADED),this.setNeedsRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){for(const i of e.layerInfo[O.ELEVATION])i.pendingUpdates&=~A.GEOMETRY;e.resetPendingUpdate(A.GEOMETRY);const t=e.renderData.updateGeometryState();return t&&this.setDirty(),t}updateGeometryIfNeeded(e){e.loaded&&e.renderData.updateGeometryIfNeeded(this._rctx)}unloadTile(e){const t=e.renderData;t&&(t.releaseGeometry(),this._renderDataPool.release(t),t.clear(),e.renderData=null,e.setMemoryDirty(),this.setDirty())}_getLocalOriginOfTile(e){const t=de-ce,i=Math.max(0,Math.floor((e.level-t)/ce)*ce);if(this._isGlobal&&0===i)return g;for(;e.parent&&e.level>i;)e=e.parent;return e.centerAtSeaLevel}getStats(){return{numTilesRendered:this._numTilesRendered,numTilesCulled:this._numTilesCulled,numOriginsRendered:this._numOriginsRendered}}set wireframe(e){this._get("wireframe")!==e&&(this._set("wireframe",e),this.setNeedsRender())}setDirty(e=V.UPDATE){this._patchesByOriginDirty=!0,this._context.requestRender(e)}_setSortingDirty(e=V.UPDATE){this._patchSortingDirty=!0,this._context.requestRender(e)}setNeedsRender(e=V.UPDATE){this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this._tileRenderer=new E({rctx:this._rctx,tileSize:this._tileSize,techniques:this._techniques,cache:this._tileTextureCache}),this.updateTileBackground(),this._emptyTex=H(this._rctx)}uninitializeRenderContext(){this._emptyTex=i(this._emptyTex),this._tileRenderer=i(this._tileRenderer)}intersect(e,t,i,r){if(!this._rootTiles||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&this.transparency!==I.Opaque)return;const s=ge,n=_e;d(s,r,i),h(n,1/s[0],1/s[1],1/s[2]);const o=e.results.min,a=e.results.max,l=e.results.ground,g=e.options.store===W.MIN,_=!!e.results.ground.target,p=re(e.verticalOffset),f=e.tolerance;let m,b=g&&null!=o.dist?o.dist:1/0;const R=e.options,x=R.normalRequired||!R.backfacesTerrain,O=new J(!1,x),v=h=>{const _=h.renderData;if(!_?.vao)return;const v=_.geometry;y(he,v.boundingBox);const w=_.localOrigin;null!=p&&(p.localOrigin=w,p.applyToAabb(he));const P=he;if(pe[0]=i[0]-w[0],pe[1]=i[1]-w[1],pe[2]=i[2]-w[2],!K(P,pe,n,f,b))return;const D=(e,t,i)=>{e.set(this.type,h,t,i,c),b=g&&null!=o.dist?o.dist:1/0},S=(n,c,d)=>{if((!x||null!=d)&&n>=0&&(R.backfacesTerrain||u(d,s)<0)&&(R.invisibleTerrain||!R.selectionMode||null==t||t(i,r,n))){if((null==l.dist||n<l.dist)&&D(l,n,d),R.isFiltered)return;R.store===W.ALL&&(null==m?(m=Y(e.ray),D(m,n,d),e.results.all.push(m)):n<m.dist&&D(m,n,d)),(null==o.dist||n<o.dist)&&D(o,n,d),R.store!==W.MIN&&(null==a.dist||n>a.dist)&&D(a,n,d)}},C=fe;d(C,r,w);const{indices:E,indexCount:A}=v,j=v.vertexAttributes,N=j.getField(te.POSITION,T),B=new z(N.typedBuffer,3,j.stride/4),I=A/3;if(!p&&I>q){const e=h.renderData;null==e.intersectionData&&(e.intersectionData=new F(E,0,I,B)),e.intersectionData.intersectRay(pe,C,O,S)}else Z(pe,C,0,I,E,B,p,O,S)},w=this._rootTiles;if(null!=w){(()=>{const t=this._tileIterator;t.reset(w);const r=e.options.invisibleTerrain;for(let e=t.next();e;e=t.next())!(e.visible||r&&e.intersectsClippingArea)||null==p&&!e.intersectsRay(i,s,f,b)||_&&this._useStencilForTile(e)?t.skipSubtree():v(e)})()}}processScaleRangeQueries(e,t){if(!t.done)for(this._updatePatchGroups();e.updating&&!t.done;){e.prepare();for(const t of this._visiblePatchesByOrigin.values())for(const i of t)null!=i.renderData?.textureReference&&e.queriesForTile(i);e.process(),t.madeProgress()}}acquireTechniques(e){const t=!!has("enable-feature:terrain-shadows")&&e.bind.shadowMap.enabled;t!==this._castShadows&&(this._castShadows=t,this._patchesByOriginDirty=!0);const i=e.bind.viewshedEnabled;if(this._inViewshed!==i&&(this._inViewshed=i,this._patchesByOriginDirty=!0),e.bind.slot===$.OCCLUDED_TERRAIN){if(!(e.renderOccludedMask&w))return null}else{const t=this.transparency===I.Opaque?$.OPAQUE_TERRAIN:$.TRANSPARENT_TERRAIN;if(e.bind.slot!==t)return null}if(this.transparency===I.Invisible)return null;switch(this._configuration.screenSpaceReflections=this._configuration.cloudReflections=this._configuration.receiveShadows=this._configuration.receiveAmbientOcclusion=!1,this._configuration.overlayMode=this._overlayRenderer.mode,e.output){case U.Color:case U.ColorEmission:return this._configuration.screenSpaceReflections=null!=e.bind.ssr.lastFrameColor,this._configuration.cloudReflections=null!=e.bind.clouds.data,this._configuration.receiveShadows=e.bind.shadowMap.ready,this._configuration.receiveAmbientOcclusion=null!=e.bind.ssao,this._acquireTechnique(e.output,e.bind.slot===$.OCCLUDED_TERRAIN);case U.Shadow:case U.ShadowExcludeHighlight:return this._castShadows?this._acquireTechnique(U.Shadow,!1):null;case U.ViewshedShadow:return this._inViewshed?this._acquireTechnique(U.ViewshedShadow,!1):null;case U.Depth:case U.Normal:return this._acquireTechnique(e.output,!1);case U.ObjectAndLayerIdColor:return this._acquireTechnique(U.ObjectAndLayerIdColor,!1);case U.Highlight:return this._overlayRenderer.hasHighlights?this._acquireTechnique(U.Highlight,!1):null}return null}render(e,t){switch(this._updatePatchGroups(),t.useStencil=!1,e.output){case U.Color:case U.ColorEmission:{const i=e.bind.slot===$.OCCLUDED_TERRAIN?v.Occluded:v.Color;this._renderMaterialPass(e,t,i);break}case U.Depth:case U.Normal:this._renderAuxiliaryPass(e,t,v.Color,this._visiblePatchesByOrigin);break;case U.Highlight:{const i=e.bind.highlight?.name;i&&this._overlayRenderer.hasHighlights&&this._overlayRenderer.renders(v.Highlight)&&this._overlayRenderer.hasHighlight(i)&&this._renderAuxiliaryPass(e,t,v.Highlight,this._visiblePatchesByOrigin);break}case U.Shadow:case U.ShadowExcludeHighlight:case U.ViewshedShadow:this._renderAuxiliaryPass(e,t,null,this._allPatchesByOrigin);break;case U.ObjectAndLayerIdColor:this._renderAuxiliaryPass(e,t,v.ObjectAndLayerIdColor,this._visiblePatchesByOrigin)}}updateTileBackground(e){if(null==this._tileRenderer)return;const i=this._tileRenderer;let r;if(null!=e){const i=t.toUnitRGBA(e);r=_(i[0]||0,i[1]||0,i[2]||0)}i.setBackground(r),this._allTiles.forAll((e=>i.updateTileTexture(e,x.FADING))),this._configuration.tileBlendInput=i.backgroundIsGrid?G.GridComposite:null!=i.backgroundColor?G.ColorComposite:G.LayerOnly,this.setNeedsRender()}_updatePatchGroups(){if(this._patchesByOriginDirty&&(this._rebuildPatchGroups(),this._patchesByOriginDirty=!1,this._patchSortingDirty=!0),this._patchSortingDirty&&this.renderOrder!==D.NONE){const e=Array.from(this._visiblePatchesByOrigin.values()),t=this._stencilEnabledLayerExtents;for(const i of e)N(this.renderOrder,i,t);e.sort(((e,t)=>B(e[0],t[0],this.renderOrder))),this._visiblePatchesByOrigin=new Map(e.map((e=>[e[0].renderData.localOrigin,e]))),this._patchSortingDirty=!1}}_rebuildPatchGroups(){const e=this._rootTiles;if(null!=e){e[0]?.surface.checkAllTilesWaterproofness(),this._visiblePatchesByOrigin.clear(),this._allPatchesByOrigin.clear();for(const t of e)this._rebuildPatchGroupsForRootTile(t)}}_rebuildPatchGroupsForRootTile(e){const t=this._tileIterator;for(t.resetOne(e);!t.done;){const e=t.next(),i=e.renderData;if(!i){this._numTilesCulled++;continue}const r=i.localOrigin;if(this._castShadows||this._inViewshed){let t=this._allPatchesByOrigin.get(r);t||(t=[],this._allPatchesByOrigin.set(r,t)),t.push(e)}if(!e.visible){this._numTilesCulled++,t.skipSubtree();continue}let s=this._visiblePatchesByOrigin.get(r);s||(s=[],this._visiblePatchesByOrigin.set(r,s)),s.push(e),t.skipSubtree()}}_useStencilForTile(e){for(const t of this._stencilEnabledLayerExtents)if(e.intersectsExtent(t))return!0;return!1}_renderAuxiliaryPass(e,t,i,r){const s=e.rctx;this._passParameters.overlayContent=i,s.bindTechnique(t,e.bind,this._passParameters);const n=this._stencilEnabledLayerExtents.length>0;r.forEach((r=>{this._drawParameters.origin=r[0].renderData.localOrigin,t.program.bindDraw(e.bind,this._passParameters,this._drawParameters);for(let s=0;s<r.length;s++)this._renderPatch(e,t,r[s],le.TRIANGLES,n,i)})),e.rctx.bindVAO(null)}_renderMaterialPass(e,t,i){const{rctx:r}=e;this._passParameters.overlayContent=i,r.bindTechnique(t,e.bind,this._passParameters),this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0;const s=e.bind.camera,n=t.program;if(this._configuration.screenSizePerspective&&this.pointsOfInterest){const e=ee(this._stage.viewingMode,this._ellipsoidRadius),t=this.pointsOfInterest.centerOnSurfaceFrequent.distance;e.update({distance:t,fovY:s.fovY})}const o=this._stencilEnabledLayerExtents.length>0,a=i===v.Occluded;a&&(n.bindTexture("tex",this._emptyTex),n.setUniform3fv("textureOpacities",g),n.setUniform4fv("texOffsetAndScale",m));const l=null!=this._tileRenderer?.backgroundColor?this._tileRenderer.backgroundColor:g;this._configuration.tileBlendInput===G.ColorComposite&&n.setUniform3fv("backgroundColor",l);const c=this.wireframe?le.LINES:le.TRIANGLES;this._configuration.textureFadingEnabled&&n.bindTexture("texNext",this._emptyTex);const d=this._visiblePatchesByOrigin;for(const h of d.values()){const r=h[0].renderData.localOrigin;this._drawParameters.origin=r,t.program.bindDraw(e.bind,this._passParameters,this._drawParameters),this._numOriginsRendered++;for(const s of h){const r=s.renderData,l=r.textureReference;if(null!=l){if(!a){n.setUniform4fv("texOffsetAndScale",l.offsetAndScale),n.bindTexture("tex",l.texture.texture);const e=r.textureFadeFactor,t=e<1?r.nextTextureReference:null;this._configuration.textureFadingEnabled&&null!=t&&e<1?(n.setUniform1f("fadeFactor",e),n.setUniform4fv("nextTexOffsetAndScale",t.offsetAndScale),n.setUniform3fv("nextTexOpacities",t.opacities),n.bindTexture("texNext",t.texture.texture)):n.setUniform1f("fadeFactor",1),r.textureIsFading&&this.setNeedsRender(),n.setUniform3fv("textureOpacities",l.opacities)}this._renderPatch(e,t,s,c,o,i),s.renderOrder=this._numTilesRendered,this._numTilesRendered++}}}e.rctx.bindVAO(null)}_renderPatch(e,t,i,r,s,n){const o=i.renderData,a=o.vao,l=a?.indexBuffer;if(!a||null==l)return void(C&&console.error("Rendered tile with no indices: ",i.lij," : ",o));const c=t.program;null==n||this._overlayRenderer.isEmpty||this._bindOverlayPatchData(c,o.overlay),s&&(t.useStencil=this._useStencilForTile(i),e.rctx.setPipelineState(t.getPipeline()));const d=o.geometry.indexCount;e.rctx.bindVAO(a),c.assertCompatibleVertexAttributeLocations(a),e.rctx.drawElements(r,d,l.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv("overlayTexOffset",t.offsets),e.setUniform4fv("overlayTexScale",t.scales)}_acquireTechnique(e,t){return this._configuration.output=e,this._configuration.renderOccluded=t,this._techniques.get(oe,this._configuration)}get test(){}hasHighlight(e){return this._overlayRenderer.hasHighlight(e)}};e([a({readOnly:!0})],ue.prototype,"_isGlobal",null),e([a()],ue.prototype,"renderOccludedFlags",void 0),e([a({value:!1})],ue.prototype,"renderingDisabled",null),e([a({value:!0})],ue.prototype,"visible",null),e([a()],ue.prototype,"texturesBeingCompressed",null),e([a()],ue.prototype,"renderPatchBorders",null),e([a()],ue.prototype,"visualizeNormals",null),e([a()],ue.prototype,"cullBackFaces",null),e([a({value:D.FRONT_TO_BACK})],ue.prototype,"renderOrder",null),e([a()],ue.prototype,"wireframe",null),ue=e([l("esri.views.3d.terrain.TerrainRenderer")],ue);const ge=p(),_e=p(),pe=p(),fe=p();export{ue as TerrainRenderer};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import has from"../../../core/has.js";import{disposeMaybe as i}from"../../../core/maybe.js";import{MemCachePool as r}from"../../../core/MemCachePool.js";import s from"../../../core/ObjectPool.js";import{watch as n,sync as o}from"../../../core/reactiveUtils.js";import{property as a}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import{IDENTITY as c}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{d,i as h,f as u}from"../../../chunks/vec32.js";import{ZEROS as g,fromValues as _,create as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as f,ZEROS as m}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{create as b,set as y}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as T}from"../../../geometry/support/buffer/BufferView.js";import{ViewingMode as R}from"../../ViewingMode.js";import{TextureUpdate as x}from"./interfaces.js";import{LayerClass as O}from"./LayerClass.js";import{OverlayContent as v}from"./OverlayContent.js";import{overlayRenderOccludedFlag as w}from"./OverlayRenderer.js";import{PatchRenderData as P}from"./PatchRenderData.js";import{RenderOrder as D}from"./RenderOrder.js";import{TerrainAttributesCache as S}from"./TerrainAttributesCache.js";import{enableTerrainInternalChecks as C}from"./terrainUtils.js";import{TileRenderer as E}from"./TileRenderer.js";import{TileUpdate as A}from"./TileUpdate.js";import{IteratorPreorder as j,sortTiles as N,compareTiles as B}from"./tileUtils.js";import{TransparencyMode as I}from"./TransparencyMode.js";import{componentMinimalSizeForIntersectionData as q,ComponentIntersectionData as F}from"../webgl-engine/collections/Component/ComponentIntersectionData.js";import{ShaderOutput as U}from"../webgl-engine/core/shaderLibrary/ShaderOutput.js";import{TileBlendInput as G}from"../webgl-engine/core/shaderLibrary/terrain/TileBlendInput.js";import{SyncRenderPlugin as M,ConsumesDepth as L,ConsumesNone as k}from"../webgl-engine/effects/RenderPlugin.js";import{Vertices as z}from"../webgl-engine/lib/Attribute.js";import{RenderRequestType as V}from"../webgl-engine/lib/basicInterfaces.js";import{createEmptyTexture as H}from"../webgl-engine/lib/glUtil3D.js";import{newIntersectorResult as Y}from"../webgl-engine/lib/Intersector.js";import{IntersectorType as Q,StoreResults as W}from"../webgl-engine/lib/IntersectorInterfaces.js";import{RenderOccludedFlag as X}from"../webgl-engine/lib/Material.js";import{intersectAabbInvDirBefore as K,intersectTriangles as Z,MeshIntersectionOptions as J}from"../webgl-engine/lib/RayIntersections.js";import{RenderSlot as $}from"../webgl-engine/lib/RenderSlot.js";import{getSettings as ee}from"../webgl-engine/lib/screenSizePerspectiveUtils.js";import{VertexAttribute as te}from"../webgl-engine/lib/VertexAttribute.js";import{terrainId as ie,getVerticalOffsetTerrain as re}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as se}from"../webgl-engine/materials/DrawParameters.js";import{T as ne}from"../../../chunks/Terrain.glsl.js";import{TerrainTechnique as oe}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as ae}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{PrimitiveType as le}from"../../webgl/enums.js";const ce=7,de=10,he=b();let ue=class extends M{get _isGlobal(){return this._stage.viewingMode===R.Global}get _techniques(){return this._context.techniques}get _rctx(){return this._context.renderContext.rctx}constructor(e,t,i,n,o){super({}),this._overlayRenderer=e,this._stage=t,this._allTiles=i,this._ellipsoidRadius=n,this.type=Q.TERRAIN,this.isGround=!0,this._passParameters=new ne,this._drawParameters=new se,this._renderDataPool=new s(P),this._visiblePatchesByOrigin=new Map,this._allPatchesByOrigin=new Map,this._patchesByOriginDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new j,this._castShadows=!1,this._inViewshed=!1,this._emptyTex=null,this._tileRenderer=null,this._stencilEnabledLayerExtents=new Array,this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this.renderOccludedFlags=X.Occlude,this.produces=new Map([[$.OPAQUE_TERRAIN,()=>this._produces()&&this.transparency===I.Opaque],[$.TRANSPARENT_TERRAIN,()=>this._produces()&&(this.transparency===I.Transparent||this.transparency===I.InvisibleWithDraped)],[$.OCCLUDED_TERRAIN,()=>this._produces()]]),this._tileSize=256,this._configuration=new ae(t.viewingMode===R.Global),this._tileTextureCache=new r(((e,t)=>o.newCache(e,t)),"TileTexture"),this.tileGeometryCache=new S(o)}normalizeCtorArgs(){return{}}initialize(){this._stage.addRenderPlugin(this),this.addHandles(n((()=>this._overlayRenderer.rendersOccludedDraped),(e=>{this.renderOccludedFlags=e?w:X.Occlude,this.setNeedsRender()}),o))}destroy(){this._stage.removeRenderPlugin(this),this._tileTextureCache.destroy(),this.tileGeometryCache.destroy()}_produces(){return this.visible&&!!this._rootTiles&&!this.renderingDisabled}consumes(){return this._overlayRenderer.hasWater?L:k}set renderingDisabled(e){this._set("renderingDisabled",!!e),this.setDirty()}set visible(e){this._set("visible",!!e),this.setDirty()}updateHeading(e){this._tileRenderer?.updateHeading(e)}set transparency(e){this._configuration.transparencyMode!==e&&(this._configuration.transparencyMode=e,this.setNeedsRender())}get transparency(){return this._configuration.transparencyMode}get tileRenderer(){return this._tileRenderer}get texturesBeingCompressed(){return this._tileRenderer?this._tileRenderer?.texturesBeingCompressed:null}get renderPatchBorders(){return this._configuration.tileBorders}set renderPatchBorders(e){this._configuration.tileBorders!==e&&(this._configuration.tileBorders=e,this.setNeedsRender(),this.notifyChange("renderPatchBorders"))}get visualizeNormals(){return this._configuration.visualizeNormals}set visualizeNormals(e){this._configuration.visualizeNormals!==e&&(this._configuration.visualizeNormals=e,this.setNeedsRender(),this.notifyChange("visualizeNormals"))}get cullBackFaces(){return this._configuration.backfaceCullingEnabled}set cullBackFaces(e){this._configuration.backfaceCullingEnabled!==e&&(this._configuration.backfaceCullingEnabled=e,this.notifyChange("cullBackFaces"),this.setNeedsRender())}set renderOrder(e){this._set("renderOrder",e),this._setSortingDirty()}get layerUid(){return ie}get slicePlaneEnabled(){return this._configuration.hasSlicePlane}set slicePlaneEnabled(e){this._configuration.hasSlicePlane!==e&&(this._configuration.hasSlicePlane=e,this.setNeedsRender())}set textureFadingEnabled(e){this._configuration.textureFadingEnabled!==e&&(this._configuration.textureFadingEnabled=e,this.setNeedsRender())}set pbrMode(e){this._configuration.pbrMode!==e&&(this._configuration.pbrMode=e,this.setNeedsRender())}setDebugScreenSizePerspective(e){this._configuration.screenSizePerspective!==e&&(this._configuration.screenSizePerspective=e,this.setNeedsRender())}setRootTiles(e){this._rootTiles=e,this.setDirty()}setStencilEnabledLayerExtents(e){this._stencilEnabledLayerExtents=e,this._setSortingDirty()}set tileSize(e){this._tileSize=e,null!=this._tileRenderer&&(this._tileRenderer.tileSize=e),this.setDirty()}get tileSize(){return this._tileSize}_ensureRenderData(e){e.renderData||(e.renderData=this._renderDataPool.acquire(),e.renderData.init(e,this._getLocalOriginOfTile(e)))}loadTile(e){this._ensureRenderData(e),this.updateTileGeometryState(e),this.reuseTextureFromParent(e)||this.updateTileTexture(e,A.TEXTURE_FADING)}reuseTextureFromParent(e){const t=e.parent;if(!t)return!1;const i=f(1&e.lij[2]?.5:0,1&e.lij[1]?0:.5,.5,.5);return t.renderData?.reuseTexture(e.renderData,i)??!1}updateTileTexture(e,t){null!=this._tileRenderer&&(this._tileRenderer.updateTileTexture(e,t===A.TEXTURE_FADING?x.FADING:x.UNFADED),this.setNeedsRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){for(const i of e.layerInfo[O.ELEVATION])i.pendingUpdates&=~A.GEOMETRY;e.resetPendingUpdate(A.GEOMETRY);const t=e.renderData.updateGeometryState();return t&&this.setDirty(),t}updateGeometryIfNeeded(e){e.loaded&&e.renderData.updateGeometryIfNeeded(this._rctx)}unloadTile(e){const t=e.renderData;t&&(t.releaseGeometry(),this._renderDataPool.release(t),t.clear(),e.renderData=null,e.setMemoryDirty(),this.setDirty())}_getLocalOriginOfTile(e){const t=de-ce,i=Math.max(0,Math.floor((e.level-t)/ce)*ce);if(this._isGlobal&&0===i)return g;for(;e.parent&&e.level>i;)e=e.parent;return e.centerAtSeaLevel}getStats(){return{numTilesRendered:this._numTilesRendered,numTilesCulled:this._numTilesCulled,numOriginsRendered:this._numOriginsRendered}}set wireframe(e){this._get("wireframe")!==e&&(this._set("wireframe",e),this.setNeedsRender())}setDirty(e=V.UPDATE){this._patchesByOriginDirty=!0,this._context.requestRender(e)}_setSortingDirty(e=V.UPDATE){this._patchSortingDirty=!0,this._context.requestRender(e)}setNeedsRender(e=V.UPDATE){this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this._tileRenderer=new E({rctx:this._rctx,tileSize:this._tileSize,techniques:this._techniques,cache:this._tileTextureCache}),this.updateTileBackground(),this._emptyTex=H(this._rctx)}uninitializeRenderContext(){this._emptyTex=i(this._emptyTex),this._tileRenderer=i(this._tileRenderer)}intersect(e,t,i,r){if(!this._rootTiles||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&this.transparency!==I.Opaque)return;const s=ge,n=_e;d(s,r,i),h(n,1/s[0],1/s[1],1/s[2]);const o=e.results.min,a=e.results.max,l=e.results.ground,g=e.options.store===W.MIN,_=!!e.results.ground.target,p=re(e.verticalOffset),f=e.tolerance;let m,b=g&&null!=o.dist?o.dist:1/0;const R=e.options,x=R.normalRequired||!R.backfacesTerrain,O=new J(!1,x),v=h=>{const _=h.renderData;if(!_?.vao)return;const v=_.geometry;y(he,v.boundingBox);const w=_.localOrigin;null!=p&&(p.localOrigin=w,p.applyToAabb(he));const P=he;if(pe[0]=i[0]-w[0],pe[1]=i[1]-w[1],pe[2]=i[2]-w[2],!K(P,pe,n,f,b))return;const D=(e,t,i)=>{e.set(this.type,h,t,i,c),b=g&&null!=o.dist?o.dist:1/0},S=(n,c,d)=>{if((!x||null!=d)&&n>=0&&(R.backfacesTerrain||u(d,s)<0)&&(R.invisibleTerrain||!R.selectionMode||null==t||t(i,r,n))){if((null==l.dist||n<l.dist)&&D(l,n,d),R.isFiltered)return;R.store===W.ALL&&(null==m?(m=Y(e.ray),D(m,n,d),e.results.all.push(m)):n<m.dist&&D(m,n,d)),(null==o.dist||n<o.dist)&&D(o,n,d),R.store!==W.MIN&&(null==a.dist||n>a.dist)&&D(a,n,d)}},C=fe;d(C,r,w);const{indices:E,indexCount:A}=v,j=v.vertexAttributes,N=j.getField(te.POSITION,T),B=new z(N.typedBuffer,3,j.stride/4),I=A/3;if(!p&&I>q){const e=h.renderData;null==e.intersectionData&&(e.intersectionData=new F(E,0,I,B)),e.intersectionData.intersectRay(pe,C,O,S)}else Z(pe,C,0,I,E,B,p,O,S)},w=this._rootTiles;if(null!=w){(()=>{const t=this._tileIterator;t.reset(w);const r=e.options.invisibleTerrain;for(let e=t.next();e;e=t.next())!(e.visible||r&&e.intersectsClippingArea)||null==p&&!e.intersectsRay(i,s,f,b)||_&&this._useStencilForTile(e)?t.skipSubtree():v(e)})()}}processScaleRangeQueries(e,t){if(!t.done)for(this._updatePatchGroups();e.updating&&!t.done;){e.prepare();for(const t of this._visiblePatchesByOrigin.values())for(const i of t)null!=i.renderData?.textureReference&&e.queriesForTile(i);e.process(),t.madeProgress()}}acquireTechniques(e){const t=!!has("enable-feature:terrain-shadows")&&e.bind.shadowMap.enabled;t!==this._castShadows&&(this._castShadows=t,this._patchesByOriginDirty=!0);const i=e.bind.viewshedEnabled;if(this._inViewshed!==i&&(this._inViewshed=i,this._patchesByOriginDirty=!0),e.bind.slot===$.OCCLUDED_TERRAIN){if(!(e.renderOccludedMask&w))return null}else{const t=this.transparency===I.Opaque?$.OPAQUE_TERRAIN:$.TRANSPARENT_TERRAIN;if(e.bind.slot!==t)return null}if(this.transparency===I.Invisible)return null;switch(this._configuration.screenSpaceReflections=this._configuration.cloudReflections=this._configuration.receiveShadows=this._configuration.receiveAmbientOcclusion=!1,this._configuration.overlayMode=this._overlayRenderer.mode,this._configuration.renderOccluded=!1,e.output){case U.Color:case U.ColorEmission:{this._configuration.screenSpaceReflections=null!=e.bind.ssr.lastFrameColor,this._configuration.cloudReflections=null!=e.bind.clouds.data,this._configuration.receiveShadows=e.bind.shadowMap.ready;const t=e.bind.slot===$.OCCLUDED_TERRAIN;return this._configuration.renderOccluded=t,this._configuration.receiveAmbientOcclusion=!t&&null!=e.bind.ssao,this._acquireTechnique(e.output)}case U.Shadow:case U.ShadowExcludeHighlight:return this._castShadows?this._acquireTechnique(U.Shadow):null;case U.ViewshedShadow:return this._inViewshed?this._acquireTechnique(U.ViewshedShadow):null;case U.Depth:case U.Normal:return this._acquireTechnique(e.output);case U.ObjectAndLayerIdColor:return this._acquireTechnique(U.ObjectAndLayerIdColor);case U.Highlight:return this._overlayRenderer.hasHighlights?this._acquireTechnique(U.Highlight):null}return null}render(e,t){switch(this._updatePatchGroups(),t.useStencil=!1,e.output){case U.Color:case U.ColorEmission:{const i=e.bind.slot===$.OCCLUDED_TERRAIN?v.Occluded:v.Color;this._renderMaterialPass(e,t,i);break}case U.Depth:case U.Normal:this._renderAuxiliaryPass(e,t,v.Color,this._visiblePatchesByOrigin);break;case U.Highlight:{const i=e.bind.highlight?.name;i&&this._overlayRenderer.hasHighlights&&this._overlayRenderer.renders(v.Highlight)&&this._overlayRenderer.hasHighlight(i)&&this._renderAuxiliaryPass(e,t,v.Highlight,this._visiblePatchesByOrigin);break}case U.Shadow:case U.ShadowExcludeHighlight:case U.ViewshedShadow:this._renderAuxiliaryPass(e,t,null,this._allPatchesByOrigin);break;case U.ObjectAndLayerIdColor:this._renderAuxiliaryPass(e,t,v.ObjectAndLayerIdColor,this._visiblePatchesByOrigin)}}updateTileBackground(e){if(null==this._tileRenderer)return;const i=this._tileRenderer;let r;if(null!=e){const i=t.toUnitRGBA(e);r=_(i[0]||0,i[1]||0,i[2]||0)}i.setBackground(r),this._allTiles.forAll((e=>i.updateTileTexture(e,x.FADING))),this._configuration.tileBlendInput=i.backgroundIsGrid?G.GridComposite:null!=i.backgroundColor?G.ColorComposite:G.LayerOnly,this.setNeedsRender()}_updatePatchGroups(){if(this._patchesByOriginDirty&&(this._rebuildPatchGroups(),this._patchesByOriginDirty=!1,this._patchSortingDirty=!0),this._patchSortingDirty&&this.renderOrder!==D.NONE){const e=Array.from(this._visiblePatchesByOrigin.values()),t=this._stencilEnabledLayerExtents;for(const i of e)N(this.renderOrder,i,t);e.sort(((e,t)=>B(e[0],t[0],this.renderOrder))),this._visiblePatchesByOrigin=new Map(e.map((e=>[e[0].renderData.localOrigin,e]))),this._patchSortingDirty=!1}}_rebuildPatchGroups(){const e=this._rootTiles;if(null!=e){e[0]?.surface.checkAllTilesWaterproofness(),this._visiblePatchesByOrigin.clear(),this._allPatchesByOrigin.clear();for(const t of e)this._rebuildPatchGroupsForRootTile(t)}}_rebuildPatchGroupsForRootTile(e){const t=this._tileIterator;for(t.resetOne(e);!t.done;){const e=t.next(),i=e.renderData;if(!i){this._numTilesCulled++;continue}const r=i.localOrigin;if(this._castShadows||this._inViewshed){let t=this._allPatchesByOrigin.get(r);t||(t=[],this._allPatchesByOrigin.set(r,t)),t.push(e)}if(!e.visible){this._numTilesCulled++,t.skipSubtree();continue}let s=this._visiblePatchesByOrigin.get(r);s||(s=[],this._visiblePatchesByOrigin.set(r,s)),s.push(e),t.skipSubtree()}}_useStencilForTile(e){for(const t of this._stencilEnabledLayerExtents)if(e.intersectsExtent(t))return!0;return!1}_renderAuxiliaryPass(e,t,i,r){const s=e.rctx;this._passParameters.overlayContent=i,s.bindTechnique(t,e.bind,this._passParameters);const n=this._stencilEnabledLayerExtents.length>0;r.forEach((r=>{this._drawParameters.origin=r[0].renderData.localOrigin,t.program.bindDraw(e.bind,this._passParameters,this._drawParameters);for(let s=0;s<r.length;s++)this._renderPatch(e,t,r[s],le.TRIANGLES,n,i)})),e.rctx.bindVAO(null)}_renderMaterialPass(e,t,i){const{rctx:r}=e;this._passParameters.overlayContent=i,r.bindTechnique(t,e.bind,this._passParameters),this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0;const s=e.bind.camera,n=t.program;if(this._configuration.screenSizePerspective&&this.pointsOfInterest){const e=ee(this._stage.viewingMode,this._ellipsoidRadius),t=this.pointsOfInterest.centerOnSurfaceFrequent.distance;e.update({distance:t,fovY:s.fovY})}const o=this._stencilEnabledLayerExtents.length>0,a=i===v.Occluded;a&&(n.bindTexture("tex",this._emptyTex),n.setUniform3fv("textureOpacities",g),n.setUniform4fv("texOffsetAndScale",m));const l=null!=this._tileRenderer?.backgroundColor?this._tileRenderer.backgroundColor:g;this._configuration.tileBlendInput===G.ColorComposite&&n.setUniform3fv("backgroundColor",l);const c=this.wireframe?le.LINES:le.TRIANGLES;this._configuration.textureFadingEnabled&&n.bindTexture("texNext",this._emptyTex);const d=this._visiblePatchesByOrigin;for(const h of d.values()){const r=h[0].renderData.localOrigin;this._drawParameters.origin=r,t.program.bindDraw(e.bind,this._passParameters,this._drawParameters),this._numOriginsRendered++;for(const s of h){const r=s.renderData,l=r.textureReference;if(null!=l){if(!a){n.setUniform4fv("texOffsetAndScale",l.offsetAndScale),n.bindTexture("tex",l.texture.texture);const e=r.textureFadeFactor,t=e<1?r.nextTextureReference:null;this._configuration.textureFadingEnabled&&null!=t&&e<1?(n.setUniform1f("fadeFactor",e),n.setUniform4fv("nextTexOffsetAndScale",t.offsetAndScale),n.setUniform3fv("nextTexOpacities",t.opacities),n.bindTexture("texNext",t.texture.texture)):n.setUniform1f("fadeFactor",1),r.textureIsFading&&this.setNeedsRender(),n.setUniform3fv("textureOpacities",l.opacities)}this._renderPatch(e,t,s,c,o,i),s.renderOrder=this._numTilesRendered,this._numTilesRendered++}}}e.rctx.bindVAO(null)}_renderPatch(e,t,i,r,s,n){const o=i.renderData,a=o.vao,l=a?.indexBuffer;if(!a||null==l)return void(C&&console.error("Rendered tile with no indices: ",i.lij," : ",o));const c=t.program;null==n||this._overlayRenderer.isEmpty||this._bindOverlayPatchData(c,o.overlay),s&&(t.useStencil=this._useStencilForTile(i),e.rctx.setPipelineState(t.getPipeline()));const d=o.geometry.indexCount;e.rctx.bindVAO(a),c.assertCompatibleVertexAttributeLocations(a),e.rctx.drawElements(r,d,l.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv("overlayTexOffset",t.offsets),e.setUniform4fv("overlayTexScale",t.scales)}_acquireTechnique(e){return this._configuration.output=e,this._techniques.get(oe,this._configuration)}get test(){}hasHighlight(e){return this._overlayRenderer.hasHighlight(e)}};e([a({readOnly:!0})],ue.prototype,"_isGlobal",null),e([a()],ue.prototype,"renderOccludedFlags",void 0),e([a({value:!1})],ue.prototype,"renderingDisabled",null),e([a({value:!0})],ue.prototype,"visible",null),e([a()],ue.prototype,"texturesBeingCompressed",null),e([a()],ue.prototype,"renderPatchBorders",null),e([a()],ue.prototype,"visualizeNormals",null),e([a()],ue.prototype,"cullBackFaces",null),e([a({value:D.FRONT_TO_BACK})],ue.prototype,"renderOrder",null),e([a()],ue.prototype,"wireframe",null),ue=e([l("esri.views.3d.terrain.TerrainRenderer")],ue);const ge=p(),_e=p(),pe=p(),fe=p();export{ue as TerrainRenderer};