@arcgis/core 4.33.11 → 4.33.12

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 (88) hide show
  1. package/applications/KnowledgeStudio/reshape.d.ts +5 -0
  2. package/applications/KnowledgeStudio/reshape.js +5 -0
  3. package/assets/esri/core/workers/RemoteClient.js +1 -1
  4. package/assets/esri/core/workers/chunks/{1415d4e2f5f3193be004.js → 012dee84d97b71461397.js} +1 -1
  5. package/assets/esri/core/workers/chunks/{342f61e784c9364a493b.js → 1ebff223f0f241686669.js} +1 -1
  6. package/assets/esri/core/workers/chunks/{fdfb5d601d318d6a49f9.js → 2f2cb0348f36a5157293.js} +1 -1
  7. package/assets/esri/core/workers/chunks/{cb16ba9512ae0a09c55d.js → 4ab87eea6345818de60f.js} +1 -1
  8. package/assets/esri/core/workers/chunks/{e9aa1d9ded8a52a40c57.js → 5d74b754ee0140afbd22.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{d33a5d79f2163ad62b1d.js → 64aebb3780ac4c8bfdc7.js} +1 -1
  10. package/assets/esri/core/workers/chunks/{c6cd8784a3e222eb2d4a.js → 8edd8ebca441d670380f.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{cf25f487fe4eb1579aee.js → 9128902b127d0ec70fe0.js} +1 -1
  12. package/assets/esri/core/workers/chunks/{17c623db3d9a06a9b711.js → a5fab8d7d8403b4de682.js} +1 -1
  13. package/assets/esri/core/workers/chunks/{bac5e1d50b69f0d94694.js → ad2a29aca4e5bcd545cc.js} +1 -1
  14. package/assets/esri/core/workers/chunks/{9049c81445cc044286f1.js → bbb92d0ba6a34c7a7d1b.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{7b9d14cc4a466ef18d71.js → bfd51df0a44a05596061.js} +1 -1
  16. package/assets/esri/core/workers/chunks/{3ca6f893fd58f5b17af5.js → c410b2b9d0645e9cea89.js} +1 -1
  17. package/assets/esri/core/workers/chunks/{8008f5479f4d16964088.js → dded6853cebf2165cb37.js} +1 -1
  18. package/assets/esri/core/workers/chunks/{db192728fa0ee08a776a.js → e7ca7ced4dfb04c81e84.js} +1 -1
  19. package/assets/esri/core/workers/chunks/{0155e6806621f3588ffa.js → fe71a2ea7965e75ee881.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{71e1a8bd432947c66357.js → ffeda53fee883f8025ed.js} +1 -1
  21. package/assets/esri/themes/base/widgets/_VideoPlayer.scss +16 -2
  22. package/assets/esri/themes/dark/main.css +1 -1
  23. package/assets/esri/themes/light/main.css +1 -1
  24. package/assets/esri/themes/light/view.css +1 -1
  25. package/chunks/GeodeticDistanceCalculator-Ce-woMPw.js +1 -1
  26. package/chunks/MultiPathImpl.js +1 -1
  27. package/chunks/OperatorGeodesicBuffer.js +1 -1
  28. package/chunks/OperatorGeodeticArea.js +1 -1
  29. package/chunks/OperatorGeodeticDensifyByLength.js +1 -1
  30. package/chunks/OperatorGeodeticLength.js +1 -1
  31. package/chunks/OperatorProximityGeodesic.js +1 -1
  32. package/chunks/OperatorShapePreservingLength.js +1 -1
  33. package/chunks/OperatorShapePreservingProject.js +1 -1
  34. package/chunks/Point2D.js +1 -1
  35. package/chunks/ProjectionTransformation.js +1 -1
  36. package/chunks/sphere.js +1 -1
  37. package/chunks/vec42.js +1 -1
  38. package/core/libs/gl-matrix-2/math/quat.js +1 -1
  39. package/core/libs/gl-matrix-2/math/vec4.js +1 -1
  40. package/core/quantityFormatUtils.js +1 -1
  41. package/core/unitFormatUtils.js +1 -1
  42. package/geometry/coordinateFormatter.js +1 -1
  43. package/geometry/operators/gx/operatorAlphaShape.js +1 -1
  44. package/geometry/operators/gx/operatorPolygonSlicer.js +1 -1
  45. package/geometry/support/sphere.js +1 -1
  46. package/interfaces.d.ts +128 -0
  47. package/kernel.js +1 -1
  48. package/layers/knowledgeGraph/nodeMovementUtils.js +5 -0
  49. package/package.json +1 -1
  50. package/renderers/support/RasterSymbolizer.js +1 -1
  51. package/support/revision.js +1 -1
  52. package/symbols/support/previewSymbol3D.js +1 -1
  53. package/views/2d/layers/imagery/BaseImageryTileSubView2D.js +1 -1
  54. package/views/2d/layers/imagery/ImageryTileView2D.js +1 -1
  55. package/views/3d/camera/constraintUtils/distance.js +1 -1
  56. package/views/3d/camera/constraintUtils/tilt.js +1 -1
  57. package/views/3d/layers/graphics/Deconflictor.js +1 -1
  58. package/views/3d/layers/i3s/I3SClientNodeLoader.js +1 -1
  59. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  60. package/views/3d/state/controllers/GamepadKeyboardController.js +1 -1
  61. package/views/3d/state/utils/navigationUtils.js +1 -1
  62. package/views/3d/terrain/OverlayManager.js +1 -1
  63. package/views/3d/terrain/TerrainSurface.js +1 -1
  64. package/views/3d/webgl-engine/lib/Octree.js +1 -1
  65. package/views/3d/webgl-engine/lib/Viewshed.js +1 -1
  66. package/views/LinkChartView.js +1 -1
  67. package/views/draw/DrawOperation.js +1 -1
  68. package/views/draw/support/GraphicMover.js +1 -1
  69. package/views/draw/support/HighlightHelper.js +1 -1
  70. package/views/draw/support/Reshape.js +1 -1
  71. package/views/interactive/Tooltip.js +1 -1
  72. package/views/interactive/sketch/SketchLabelOptions.js +1 -1
  73. package/views/interactive/sketch/SketchOptions.js +1 -1
  74. package/views/interactive/sketch/SketchTooltipOptions.js +1 -1
  75. package/views/interactive/sketch/SketchTooltipVisibleElements.js +1 -1
  76. package/views/interactive/sketch/SketchValueOptions.js +1 -1
  77. package/views/interactive/sketch/Units.js +1 -1
  78. package/views/interactive/sketch/constraints.js +1 -1
  79. package/views/interactive/snapping/featureSources/FeatureCollectionSnappingSource.js +1 -1
  80. package/views/interactive/snapping/featureSources/FeatureServiceSnappingSource.js +1 -1
  81. package/views/interactive/snapping/featureSources/GraphicsSnappingSource.js +1 -1
  82. package/views/interactive/tooltip/fields/fields.js +1 -1
  83. package/views/interactive/tooltip/fields/parsingAndFormattingUtils.js +1 -1
  84. package/views/interactive/tooltip/tooltipCommonUtils.js +1 -1
  85. package/views/support/angularMeasurementUtils.js +1 -1
  86. package/widgets/VideoPlayer/components/PlayerActionsGroup.js +1 -1
  87. package/widgets/VideoPlayer/css.js +1 -1
  88. package/widgets/VideoPlayer.js +1 -1
@@ -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"../../core/has.js";import r from"../../core/JSONSupport.js";import t from"../../core/Logger.js";import{property as s}from"../../core/accessorSupport/decorators/property.js";import"../../core/RandomLCG.js";import{subclass as a}from"../../core/accessorSupport/decorators/subclass.js";import o from"../../layers/support/RasterInfo.js";import{colorize as n,remapColor as i,lookupPixels as l,createColormapLUT as u,isValidPixelBlock as c}from"../../layers/support/rasterFunctions/pixelUtils.js";import{stretch as p,getStretchCutoff as d,isStandardU8Histogram as m,createStretchLUT as h,computeGammaValues as f,createHistogramEqualizationLUT as b}from"../../layers/support/rasterFunctions/stretchUtils.js";import{hillshade as g,tintHillshade as y,calculateHillshadeParams as S}from"../../layers/support/rasterFunctions/surfaceUtils.js";import{convertColorRampToColormap as x,createHsvMap as R}from"./colorRampUtils.js";import{isUVRendererSupported as I,isColormapSupportedByWebGL as k,isColormapRendererSupported as C,isShadedReliefRendererSupported as L}from"./rasterRendererChecks.js";let _=class extends r{constructor(e){super(e),this.lookup={rendererJSON:{}},this.canRenderInWebGL=!1}bind(){const{rendererJSON:e}=this;if(!e)return{success:!1};let r;switch(this.lookup={rendererJSON:{}},e.type){case"uniqueValue":r=this._updateUVRenderer(e);break;case"rasterColormap":r=this._updateColormapRenderer(e);break;case"rasterStretch":r=this._updateStretchRenderer(e);break;case"classBreaks":r=this._updateClassBreaksRenderer(e);break;case"rasterShadedRelief":r=this._updateShadedReliefRenderer(e);break;case"vectorField":r=this._updateVectorFieldRenderer();break;case"flowRenderer":r=this._updateFlowRenderer()}return r}symbolize(e){let r=e?.pixelBlock;if(!T(r))return r;if(e.simpleStretchParams&&"rasterStretch"===this.rendererJSON.type)return this.simpleStretch(r,e.simpleStretchParams);try{let t;switch(r.pixels.length>3&&(r=r.extractBands(e.bandIds??[0,1,2])),this.rendererJSON.type){case"uniqueValue":case"rasterColormap":t=this._symbolizeColormap(r);break;case"classBreaks":t=this._symbolizeClassBreaks(r);break;case"rasterStretch":t=this._symbolizeStretch(r,e.bandIds);break;case"rasterShadedRelief":{const s=e.extent,a=s.spatialReference.isGeographic,o={x:(s.xmax-s.xmin)/r.width,y:(s.ymax-s.ymin)/r.height};t=this._symbolizeShadedRelief(r,{isGCS:a,resolution:o});break}}return t}catch(s){return t.getLogger(this).error("symbolize",s.message),r}}simpleStretch(e,r){if(!T(e))return e;try{return e.pixels.length>3&&(e=e.extractBands([0,1,2])),p(e,{...r,isRenderer:!0})}catch(s){return t.getLogger(this).error("symbolize",s.message),e}}generateWebGLParameters(e){const{rendererJSON:r}=this;switch(r.type){case"uniqueValue":case"rasterColormap":case"classBreaks":return this._generateColormapWebGLParams("classBreaks"===r.type);case"rasterStretch":return this._generateStretchWebGLParams(e.pixelBlock,r,e.bandIds);case"rasterShadedRelief":return this._generateShadedReliefWebGLParams(r,e.isGCS,e.resolution??void 0);case"vectorField":return this._generateVectorFieldWebGLParams(r);default:return null}}_isLUTChanged(e){const r=this.lookup.rendererJSON;if(!r)return!0;const{rendererJSON:t}=this;if("colorRamp"in t&&t.colorRamp){const s=t.colorRamp;if(e)return JSON.stringify(s)!==JSON.stringify(r.colorRamp)}return JSON.stringify(t)!==JSON.stringify(r)}_symbolizeColormap(e){if(this._isLUTChanged()){if(!this.bind().success)return e}return n(e,this.lookup.colormapLut)}_symbolizeClassBreaks(e){const{canUseIndexedLUT:r}=this._analyzeClassBreaks(this.rendererJSON);if(this._isLUTChanged()){if(!this.bind().success)return e}return r?n(e,this.lookup.colormapLut):i(e,this.lookup.remapLut??[])}_symbolizeStretch(e,r){if(!e)return null;const{rasterInfo:t,lookup:s}=this,{pixelType:a,bandCount:o}=t,i=this.rendererJSON,u=["u8","u16","s8","s16"].includes(a);let c;const{dra:f}=i,{gamma:b}=s;if("histogramEqualization"===i.stretchType){const a=f?null:s.histogramLut,o=d(i,{rasterInfo:t,pixelBlock:e,bandIds:r,returnHistogramLut:!a}),n="u8"===t.pixelType&&!f&&m(t.histograms?.[0])?e:p(e,{...o,gamma:b,isRenderer:!0});c=l(n,{lut:f?o.histogramLut:r?.length?r.map((e=>a[e])):a,offset:0})}else if(u){let n;if(f){const s=d(i,{rasterInfo:t,pixelBlock:e,bandIds:r});n=h({pixelType:a,...s,gamma:b,rounding:"floor"})}else{if(this._isLUTChanged()){if(!this.bind().success)return e}n=s.stretchLut}if(!n)return e;o>1&&null!=r&&r.length===e?.pixels.length&&n.lut.length===o&&(n={lut:r.map((e=>n.lut[e])),offset:n.offset}),c=l(e,n)}else{const s=d(i,{rasterInfo:t,pixelBlock:e,bandIds:r});c=p(e,{...s,gamma:b,isRenderer:!0})}if(i.colorRamp){if(this._isLUTChanged(!0)){if(!this.bind().success)return e}c=n(c,s.colormapLut)}return c}_symbolizeShadedRelief(e,r){const t=this.rendererJSON,s={...t,...r},a=g(e,s);if(!t.colorRamp)return a;if(this._isLUTChanged(!0)){if(!this.bind().success)return a}const{hsvMap:o}=this.lookup;if(!o)return a;const n=this.rasterInfo.statistics?.[0]??{min:0,max:8e3};return y(a,e,o,n),a}_isVectorFieldData(){const{bandCount:e,dataType:r}=this.rasterInfo;return 2===e&&("vector-magdir"===r||"vector-uv"===r)}_updateVectorFieldRenderer(){return this._isVectorFieldData()?{success:!0}:{success:!1,error:`Unsupported data type "${this.rasterInfo.dataType}"; VectorFieldRenderer only supports "vector-magdir" and "vector-uv".`}}_updateFlowRenderer(){return this._isVectorFieldData()?{success:!0}:{success:!1,error:`Unsupported data type "${this.rasterInfo.dataType}"; FlowRenderer only supports "vector-magdir" and "vector-uv".`}}_updateUVRenderer(e){const{bandCount:r,attributeTable:t,pixelType:s}=this.rasterInfo,a=e.field1;if(!a)return{success:!1,error:"Unsupported renderer; missing UniqueValueRenderer.field."};const o=e.defaultSymbol,n=1===r&&["u8","s8"].includes(s);if(!I(this.rasterInfo,a)&&!n)return{success:!1,error:"Unsupported data; UniqueValueRenderer is only supported on single band data with a valid raster attribute table."};const i=[];if(null!=t){const r=t.fields.find((e=>"value"===e.name.toLowerCase()));if(!r)return{success:!1,error:"Unsupported data; the data's raster attribute table does not have a value field."};t.features.forEach((t=>{const s=e.uniqueValueInfos?.find((e=>String(e.value)===String(t.attributes[a]))),n=s?.symbol?.color;n?i.push([t.attributes[r.name]].concat(n)):o&&i.push([t.attributes[r.name]].concat(o.color))}))}else{if("value"!==a.toLowerCase())return{success:!1,error:'Unsupported renderer; UniqueValueRenderer.field must be "Value" when raster attribute table is not available.'};e.uniqueValueInfos?.forEach((e=>{const r=e?.symbol?.color;r?i.push([parseInt(""+e.value,10)].concat(r)):o&&i.push([parseInt(""+e.value,10)].concat(o?.color))}))}if(0===i.length)return{success:!1,error:"Invalid UniqueValueRenderer. Cannot find matching records in the raster attribute table."};const l=u({colormap:i});return this.lookup={rendererJSON:e,colormapLut:l},this.canRenderInWebGL=k(l?.indexedColormap),{success:!0}}_updateColormapRenderer(e){if(!C(this.rasterInfo))return{success:!1,error:"Unsupported data; the data source does not have a colormap."};const r=e.colormapInfos.map((e=>[e.value].concat(e.color))).sort(((e,r)=>e[0]-r[0]));if(!r||0===r.length)return{success:!1,error:"Unsupported renderer; ColormapRenderer must have meaningful colormapInfos."};const t=u({colormap:r});return this.lookup={rendererJSON:e,colormapLut:t},this.canRenderInWebGL=k(t?.indexedColormap),{success:!0}}_updateShadedReliefRenderer(e){if(!L(this.rasterInfo))return{success:!1,error:`Unsupported data type "${this.rasterInfo.dataType}"; ShadedReliefRenderer only supports "elevation", or single band float/s16 data.`};if(e.colorRamp){const r=x(e.colorRamp,{interpolateAlpha:!0}),t=u({colormap:r}),s=R(t.indexedColormap);this.lookup={rendererJSON:e,colormapLut:t,hsvMap:s}}else this.lookup={rendererJSON:e};return this.canRenderInWebGL=!0,{success:!0}}_analyzeClassBreaks(e){const{attributeTable:r,pixelType:t}=this.rasterInfo,s=r?.fields.find((e=>"value"===e.name.toLowerCase())),a=r?.fields.find((r=>r.name.toLowerCase()===e.field.toLowerCase())),o=null!=s&&null!==a;return{canUseIndexedLUT:["u8","u16","s8","s16"].includes(t)||o,tableValueField:s,tableBreakField:a}}_updateClassBreaksRenderer(e){const{attributeTable:r}=this.rasterInfo,{canUseIndexedLUT:t,tableValueField:s,tableBreakField:a}=this._analyzeClassBreaks(e),o=e.classBreakInfos;if(!o?.length)return{success:!1,error:"Unsupported renderer; missing or invalid ClassBreaksRenderer.classBreakInfos."};const n=o.sort(((e,r)=>e.classMaxValue-r.classMaxValue)),i=n[n.length-1];let l=e.minValue;if(!t){const r=[];for(let e=0;e<n.length;e++)r.push({value:n[e].classMinValue??l,mappedColor:n[e].symbol.color}),l=n[e].classMaxValue;return r.push({value:i.classMaxValue,mappedColor:i.symbol.color}),this.lookup={rendererJSON:e,remapLut:r},this.canRenderInWebGL=!1,{success:!0}}const c=[];if(null!=r&&null!=s&&null!==a&&s!==a){const t=s.name,o=a.name,i=n[n.length-1],{classMaxValue:u}=i;l=e.minValue;for(const e of r.features){const r=e.attributes[t],s=e.attributes[o],a=s===u?i:s<l?null:n.find((({classMaxValue:e})=>e>s));a&&c.push([r].concat(a.symbol.color))}}else{l=Math.floor(e.minValue);for(let e=0;e<n.length;e++){const r=n[e];for(let e=l;e<r.classMaxValue;e++)c.push([e].concat(r.symbol.color));l=Math.ceil(r.classMaxValue)}i.classMaxValue===l&&c.push([i.classMaxValue].concat(i.symbol.color))}const p=u({colormap:c,fillUnspecified:!1});return this.lookup={rendererJSON:e,colormapLut:p},this.canRenderInWebGL=k(p?.indexedColormap),{success:!0}}_updateStretchRenderer(e){let{stretchType:r,dra:t}=e;if(!("none"===r||e.statistics?.length||v(this.rasterInfo.statistics)||t))return{success:!1,error:"Unsupported renderer; StretchRenderer.statistics is required when dynamic range adjustment is not used."};const s=e.histograms||this.rasterInfo.histograms;!V(e.stretchType)||s?.length||t||(r="minMax");const{computeGamma:a,useGamma:o,colorRamp:n}=e;let{gamma:i}=e;if(o&&a&&!i?.length){const r=e.statistics?.length?e.statistics:this.rasterInfo.statistics;i=f(this.rasterInfo.pixelType,r)}const l=this.rasterInfo.pixelType,c=!t&&["u8","u16","s8","s16"].includes(l);if("histogramEqualization"===r){const r=s.map((e=>b(e)));this.lookup={rendererJSON:e,histogramLut:r}}else if(c){const r=d(e,{rasterInfo:this.rasterInfo}),t=h({pixelType:l,...r,gamma:o?i:null,rounding:"floor"});this.lookup={rendererJSON:e,stretchLut:t}}else this.lookup={rendererJSON:e};if(n&&!O(n)){const r=x(n,{interpolateAlpha:!0});this.lookup.colormapLut=u({colormap:r}),this.lookup.rendererJSON=e}return this.lookup.gamma=o&&i?.length?i:null,this.canRenderInWebGL="histogramEqualization"!==r,{success:!0}}_generateColormapWebGLParams(e){const{indexedColormap:r,offset:t}=this.lookup.colormapLut||{};return{colormap:r,colormapOffset:t,isClassBreaks:e,type:"lut"}}_generateStretchWebGLParams(e,r,t){const{colormapLut:s}=this.lookup,a=r.colorRamp?s?.indexedColormap:null,o=r.colorRamp?s?.offset:null;"histogramEqualization"===r.stretchType&&(r={...r,stretchType:"minMax"});const{gamma:n}=this.lookup,i=!(!r.useGamma||!n?.some((e=>1!==e))),{minCutOff:l,maxCutOff:u,minOutput:c,maxOutput:p}=d(r,{rasterInfo:this.rasterInfo,pixelBlock:e,bandIds:t});let m=0;null!=e&&(m=e.getPlaneCount(),2===m&&((e=e.clone()).statistics=[e.statistics[0]],e.pixels=[e.pixels[0]]));const{bandCount:h}=this.rasterInfo,f=Math.min(3,t?.length||m||h,h),b=a||i?1:255,g=new Float32Array(f);if(i&&n)for(let d=0;d<f;d++)n[d]>1?n[d]>2?g[d]=6.5+(n[d]-2)**2.5:g[d]=6.5+100*(2-n[d])**4:g[d]=1;1===l.length&&(l[2]=l[1]=l[0]),1===u.length&&(u[2]=u[1]=u[0]);const y=i&&n?[n[0],n[1]??n[0],n[2]??n[0]]:[1,1,1],S=i?[g[0],g[1]??g[0],g[2]??g[0]]:[1,1,1],x=u.map(((e,r)=>u[r]===l[r]?0:(p-c)/(u[r]-l[r])/b));return{bandCount:f,minOutput:c/b,maxOutput:p/b,minCutOff:l,maxCutOff:u,factor:x,useGamma:i,gamma:y,gammaCorrection:S,colormap:a,colormapOffset:o,stretchType:r.stretchType,type:"stretch"}}_generateShadedReliefWebGLParams(e,r=!1,t={x:0,y:0}){const{colormapLut:s}=this.lookup,a=e.colorRamp?s?.indexedColormap:null,o=e.colorRamp?s?.offset:null,n={...e,isGCS:r,resolution:t},i=S(n),l=this.rasterInfo.statistics?.[0];return{...i,minValue:l?.min??0,maxValue:l?.max??8e3,hillshadeType:"traditional"===e.hillshadeType?0:1,type:"hillshade",colormap:a,colormapOffset:o}}_generateVectorFieldWebGLParams(e){const{style:r,inputUnit:t,outputUnit:s,visualVariables:a,symbolTileSize:o,flowRepresentation:n}=e,i=this.rasterInfo.statistics?.[0].min??0,l=this.rasterInfo.statistics?.[0].max??50,u=a?.find((e=>"sizeInfo"===e.type))??{maxDataValue:l,maxSize:.8*o,minDataValue:i,minSize:.2*o},c=u.minDataValue??i,p=u.maxDataValue??l,d=null!=u.maxSize&&null!=u.minSize?[u.minSize/o,u.maxSize/o]:[.2,.8];if("wind_speed"===r){const e=(d[0]+d[1])/2;d[0]=d[1]=e}const m=null!=c&&null!=p?[c,p]:null;let h=null;if("classified_arrow"===r)if(null!=c&&null!=p&&null!=u){h=[];const e=(u.maxDataValue-u.minDataValue)/5;for(let r=0;r<6;r++)h.push(u.minDataValue+e*r)}else h=[0,1e-6,3.5,7,10.5,14];const f="flow_to"===n===("ocean_current_kn"===r||"ocean_current_m"===r)?0:Math.PI,b=a?.find((e=>"rotationInfo"===e.type));return{breakValues:h,dataRange:m,inputUnit:t,outputUnit:s,symbolTileSize:o,symbolPercentRange:d,style:r||"single_arrow",rotation:f,rotationType:this.rasterInfo.storageInfo?.tileInfo&&"vector-uv"===this.rasterInfo.dataType?"geographic":b?.rotationType||e.rotationType,type:"vectorField"}}};function V(e){return"percentClip"===e||"histogramEqualization"===e}function v(e){return null!=e&&e.length>0&&null!=e[0].min&&null!=e[0].max}function T(e){return c(e)&&0!==e.validPixelCount}function O(e){return"algorithmic"===e.type&&["0,0,0,255","0,0,0"].includes(e.fromColor.join(","))&&["255,255,255,255","255,255,255"].includes(e.toColor.join(","))}e([s({json:{write:!0}})],_.prototype,"rendererJSON",void 0),e([s({type:o,json:{write:!0}})],_.prototype,"rasterInfo",void 0),e([s({json:{write:!0}})],_.prototype,"lookup",void 0),e([s()],_.prototype,"canRenderInWebGL",void 0),_=e([a("esri.renderers.support.RasterSymbolizer")],_);export{_ as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import"../../core/has.js";import r from"../../core/JSONSupport.js";import t from"../../core/Logger.js";import{property as s}from"../../core/accessorSupport/decorators/property.js";import"../../core/RandomLCG.js";import{subclass as a}from"../../core/accessorSupport/decorators/subclass.js";import o from"../../layers/support/RasterInfo.js";import{colorize as n,remapColor as i,lookupPixels as l,createColormapLUT as u,isValidPixelBlock as c}from"../../layers/support/rasterFunctions/pixelUtils.js";import{stretch as p,getStretchCutoff as d,isStandardU8Histogram as m,createStretchLUT as h,computeGammaValues as f,createHistogramEqualizationLUT as b}from"../../layers/support/rasterFunctions/stretchUtils.js";import{hillshade as g,tintHillshade as y,calculateHillshadeParams as S}from"../../layers/support/rasterFunctions/surfaceUtils.js";import{convertColorRampToColormap as x,createHsvMap as R}from"./colorRampUtils.js";import{isUVRendererSupported as I,isColormapSupportedByWebGL as k,isColormapRendererSupported as C,isShadedReliefRendererSupported as L}from"./rasterRendererChecks.js";let _=class extends r{constructor(e){super(e),this.lookup={rendererJSON:{}},this.canRenderInWebGL=!1}bind(){const{rendererJSON:e}=this;if(!e)return{success:!1};let r;switch(this.lookup={rendererJSON:{}},e.type){case"uniqueValue":r=this._updateUVRenderer(e);break;case"rasterColormap":r=this._updateColormapRenderer(e);break;case"rasterStretch":r=this._updateStretchRenderer(e);break;case"classBreaks":r=this._updateClassBreaksRenderer(e);break;case"rasterShadedRelief":r=this._updateShadedReliefRenderer(e);break;case"vectorField":r=this._updateVectorFieldRenderer();break;case"flowRenderer":r=this._updateFlowRenderer()}return r}symbolize(e){let r=e?.pixelBlock;if(!T(r))return r;if(e.simpleStretchParams&&"rasterStretch"===this.rendererJSON.type)return this.simpleStretch(r,e.simpleStretchParams);try{let t;switch(r.pixels.length>3&&(r=r.extractBands(e.bandIds??[0,1,2])),this.rendererJSON.type){case"uniqueValue":case"rasterColormap":t=this._symbolizeColormap(r);break;case"classBreaks":t=this._symbolizeClassBreaks(r);break;case"rasterStretch":t=this._symbolizeStretch(r,e.bandIds);break;case"rasterShadedRelief":{const s=e.extent,a=s.spatialReference.isGeographic,o={x:(s.xmax-s.xmin)/r.width,y:(s.ymax-s.ymin)/r.height};t=this._symbolizeShadedRelief(r,{isGCS:a,resolution:o});break}}return t}catch(s){return t.getLogger(this).error("symbolize",s.message),r}}simpleStretch(e,r){if(!T(e))return e;try{return e.pixels.length>3&&(e=e.extractBands([0,1,2])),p(e,{...r,isRenderer:!0})}catch(s){return t.getLogger(this).error("symbolize",s.message),e}}generateWebGLParameters(e){const{rendererJSON:r}=this;switch(r.type){case"uniqueValue":case"rasterColormap":case"classBreaks":return this._generateColormapWebGLParams("classBreaks"===r.type);case"rasterStretch":return this._generateStretchWebGLParams(e.pixelBlock,r,e.bandIds);case"rasterShadedRelief":return this._generateShadedReliefWebGLParams(r,e.isGCS,e.resolution??void 0);case"vectorField":return this._generateVectorFieldWebGLParams(r);default:return null}}_isLUTChanged(e){const r=this.lookup.rendererJSON;if(!r)return!0;const{rendererJSON:t}=this;if("colorRamp"in t&&t.colorRamp){const s=t.colorRamp;if(e)return JSON.stringify(s)!==JSON.stringify(r.colorRamp)}return JSON.stringify(t)!==JSON.stringify(r)}_symbolizeColormap(e){if(this._isLUTChanged()){if(!this.bind().success)return e}return n(e,this.lookup.colormapLut)}_symbolizeClassBreaks(e){const{canUseIndexedLUT:r}=this._analyzeClassBreaks(this.rendererJSON);if(this._isLUTChanged()){if(!this.bind().success)return e}return r?n(e,this.lookup.colormapLut):i(e,this.lookup.remapLut??[])}_symbolizeStretch(e,r){if(!e)return null;const{rasterInfo:t,lookup:s}=this,{pixelType:a,bandCount:o}=t,i=this.rendererJSON,u=["u8","u16","s8","s16"].includes(a);let c;const{dra:f}=i,{gamma:b}=s;if(f&&(r=null),"histogramEqualization"===i.stretchType){const a=f?null:s.histogramLut,o=d(i,{rasterInfo:t,pixelBlock:e,bandIds:r,returnHistogramLut:!a}),n="u8"===t.pixelType&&!f&&m(t.histograms?.[0])?e:p(e,{...o,gamma:b,isRenderer:!0});c=l(n,{lut:f?o.histogramLut:r?.length?r.map((e=>a[e])):a,offset:0})}else if(u){let n;if(f){const s=d(i,{rasterInfo:t,pixelBlock:e,bandIds:r});n=h({pixelType:a,...s,gamma:b,rounding:"floor"})}else{if(this._isLUTChanged()){if(!this.bind().success)return e}n=s.stretchLut}if(!n)return e;o>1&&null!=r&&r.length===e?.pixels.length&&n.lut.length===o&&(n={lut:r.map((e=>n.lut[e])),offset:n.offset}),c=l(e,n)}else{const s=d(i,{rasterInfo:t,pixelBlock:e,bandIds:r});c=p(e,{...s,gamma:b,isRenderer:!0})}if(i.colorRamp){if(this._isLUTChanged(!0)){if(!this.bind().success)return e}c=n(c,s.colormapLut)}return c}_symbolizeShadedRelief(e,r){const t=this.rendererJSON,s={...t,...r},a=g(e,s);if(!t.colorRamp)return a;if(this._isLUTChanged(!0)){if(!this.bind().success)return a}const{hsvMap:o}=this.lookup;if(!o)return a;const n=this.rasterInfo.statistics?.[0]??{min:0,max:8e3};return y(a,e,o,n),a}_isVectorFieldData(){const{bandCount:e,dataType:r}=this.rasterInfo;return 2===e&&("vector-magdir"===r||"vector-uv"===r)}_updateVectorFieldRenderer(){return this._isVectorFieldData()?{success:!0}:{success:!1,error:`Unsupported data type "${this.rasterInfo.dataType}"; VectorFieldRenderer only supports "vector-magdir" and "vector-uv".`}}_updateFlowRenderer(){return this._isVectorFieldData()?{success:!0}:{success:!1,error:`Unsupported data type "${this.rasterInfo.dataType}"; FlowRenderer only supports "vector-magdir" and "vector-uv".`}}_updateUVRenderer(e){const{bandCount:r,attributeTable:t,pixelType:s}=this.rasterInfo,a=e.field1;if(!a)return{success:!1,error:"Unsupported renderer; missing UniqueValueRenderer.field."};const o=e.defaultSymbol,n=1===r&&["u8","s8"].includes(s);if(!I(this.rasterInfo,a)&&!n)return{success:!1,error:"Unsupported data; UniqueValueRenderer is only supported on single band data with a valid raster attribute table."};const i=[];if(null!=t){const r=t.fields.find((e=>"value"===e.name.toLowerCase()));if(!r)return{success:!1,error:"Unsupported data; the data's raster attribute table does not have a value field."};t.features.forEach((t=>{const s=e.uniqueValueInfos?.find((e=>String(e.value)===String(t.attributes[a]))),n=s?.symbol?.color;n?i.push([t.attributes[r.name]].concat(n)):o&&i.push([t.attributes[r.name]].concat(o.color))}))}else{if("value"!==a.toLowerCase())return{success:!1,error:'Unsupported renderer; UniqueValueRenderer.field must be "Value" when raster attribute table is not available.'};e.uniqueValueInfos?.forEach((e=>{const r=e?.symbol?.color;r?i.push([parseInt(""+e.value,10)].concat(r)):o&&i.push([parseInt(""+e.value,10)].concat(o?.color))}))}if(0===i.length)return{success:!1,error:"Invalid UniqueValueRenderer. Cannot find matching records in the raster attribute table."};const l=u({colormap:i});return this.lookup={rendererJSON:e,colormapLut:l},this.canRenderInWebGL=k(l?.indexedColormap),{success:!0}}_updateColormapRenderer(e){if(!C(this.rasterInfo))return{success:!1,error:"Unsupported data; the data source does not have a colormap."};const r=e.colormapInfos.map((e=>[e.value].concat(e.color))).sort(((e,r)=>e[0]-r[0]));if(!r||0===r.length)return{success:!1,error:"Unsupported renderer; ColormapRenderer must have meaningful colormapInfos."};const t=u({colormap:r});return this.lookup={rendererJSON:e,colormapLut:t},this.canRenderInWebGL=k(t?.indexedColormap),{success:!0}}_updateShadedReliefRenderer(e){if(!L(this.rasterInfo))return{success:!1,error:`Unsupported data type "${this.rasterInfo.dataType}"; ShadedReliefRenderer only supports "elevation", or single band float/s16 data.`};if(e.colorRamp){const r=x(e.colorRamp,{interpolateAlpha:!0}),t=u({colormap:r}),s=R(t.indexedColormap);this.lookup={rendererJSON:e,colormapLut:t,hsvMap:s}}else this.lookup={rendererJSON:e};return this.canRenderInWebGL=!0,{success:!0}}_analyzeClassBreaks(e){const{attributeTable:r,pixelType:t}=this.rasterInfo,s=r?.fields.find((e=>"value"===e.name.toLowerCase())),a=r?.fields.find((r=>r.name.toLowerCase()===e.field.toLowerCase())),o=null!=s&&null!==a;return{canUseIndexedLUT:["u8","u16","s8","s16"].includes(t)||o,tableValueField:s,tableBreakField:a}}_updateClassBreaksRenderer(e){const{attributeTable:r}=this.rasterInfo,{canUseIndexedLUT:t,tableValueField:s,tableBreakField:a}=this._analyzeClassBreaks(e),o=e.classBreakInfos;if(!o?.length)return{success:!1,error:"Unsupported renderer; missing or invalid ClassBreaksRenderer.classBreakInfos."};const n=o.sort(((e,r)=>e.classMaxValue-r.classMaxValue)),i=n[n.length-1];let l=e.minValue;if(!t){const r=[];for(let e=0;e<n.length;e++)r.push({value:n[e].classMinValue??l,mappedColor:n[e].symbol.color}),l=n[e].classMaxValue;return r.push({value:i.classMaxValue,mappedColor:i.symbol.color}),this.lookup={rendererJSON:e,remapLut:r},this.canRenderInWebGL=!1,{success:!0}}const c=[];if(null!=r&&null!=s&&null!==a&&s!==a){const t=s.name,o=a.name,i=n[n.length-1],{classMaxValue:u}=i;l=e.minValue;for(const e of r.features){const r=e.attributes[t],s=e.attributes[o],a=s===u?i:s<l?null:n.find((({classMaxValue:e})=>e>s));a&&c.push([r].concat(a.symbol.color))}}else{l=Math.floor(e.minValue);for(let e=0;e<n.length;e++){const r=n[e];for(let e=l;e<r.classMaxValue;e++)c.push([e].concat(r.symbol.color));l=Math.ceil(r.classMaxValue)}i.classMaxValue===l&&c.push([i.classMaxValue].concat(i.symbol.color))}const p=u({colormap:c,fillUnspecified:!1});return this.lookup={rendererJSON:e,colormapLut:p},this.canRenderInWebGL=k(p?.indexedColormap),{success:!0}}_updateStretchRenderer(e){let{stretchType:r,dra:t}=e;if(!("none"===r||e.statistics?.length||v(this.rasterInfo.statistics)||t))return{success:!1,error:"Unsupported renderer; StretchRenderer.statistics is required when dynamic range adjustment is not used."};const s=e.histograms||this.rasterInfo.histograms;!V(e.stretchType)||s?.length||t||(r="minMax");const{computeGamma:a,useGamma:o,colorRamp:n}=e;let{gamma:i}=e;if(o&&a&&!i?.length){const r=e.statistics?.length?e.statistics:this.rasterInfo.statistics;i=f(this.rasterInfo.pixelType,r)}const l=this.rasterInfo.pixelType,c=!t&&["u8","u16","s8","s16"].includes(l);if("histogramEqualization"===r){const r=s.map((e=>b(e)));this.lookup={rendererJSON:e,histogramLut:r}}else if(c){const r=d(e,{rasterInfo:this.rasterInfo}),t=h({pixelType:l,...r,gamma:o?i:null,rounding:"floor"});this.lookup={rendererJSON:e,stretchLut:t}}else this.lookup={rendererJSON:e};if(n&&!O(n)){const r=x(n,{interpolateAlpha:!0});this.lookup.colormapLut=u({colormap:r}),this.lookup.rendererJSON=e}return this.lookup.gamma=o&&i?.length?i:null,this.canRenderInWebGL="histogramEqualization"!==r,{success:!0}}_generateColormapWebGLParams(e){const{indexedColormap:r,offset:t}=this.lookup.colormapLut||{};return{colormap:r,colormapOffset:t,isClassBreaks:e,type:"lut"}}_generateStretchWebGLParams(e,r,t){const{colormapLut:s}=this.lookup,a=r.colorRamp?s?.indexedColormap:null,o=r.colorRamp?s?.offset:null;"histogramEqualization"===r.stretchType&&(r={...r,stretchType:"minMax"});const{gamma:n}=this.lookup,i=!(!r.useGamma||!n?.some((e=>1!==e))),{minCutOff:l,maxCutOff:u,minOutput:c,maxOutput:p}=d(r,{rasterInfo:this.rasterInfo,pixelBlock:e,bandIds:t});let m=0;null!=e&&(m=e.getPlaneCount(),2===m&&((e=e.clone()).statistics=[e.statistics[0]],e.pixels=[e.pixels[0]]));const{bandCount:h}=this.rasterInfo,f=Math.min(3,t?.length||m||h,h),b=a||i?1:255,g=new Float32Array(f);if(i&&n)for(let d=0;d<f;d++)n[d]>1?n[d]>2?g[d]=6.5+(n[d]-2)**2.5:g[d]=6.5+100*(2-n[d])**4:g[d]=1;1===l.length&&(l[2]=l[1]=l[0]),1===u.length&&(u[2]=u[1]=u[0]);const y=i&&n?[n[0],n[1]??n[0],n[2]??n[0]]:[1,1,1],S=i?[g[0],g[1]??g[0],g[2]??g[0]]:[1,1,1],x=u.map(((e,r)=>u[r]===l[r]?0:(p-c)/(u[r]-l[r])/b));return{bandCount:f,minOutput:c/b,maxOutput:p/b,minCutOff:l,maxCutOff:u,factor:x,useGamma:i,gamma:y,gammaCorrection:S,colormap:a,colormapOffset:o,stretchType:r.stretchType,type:"stretch"}}_generateShadedReliefWebGLParams(e,r=!1,t={x:0,y:0}){const{colormapLut:s}=this.lookup,a=e.colorRamp?s?.indexedColormap:null,o=e.colorRamp?s?.offset:null,n={...e,isGCS:r,resolution:t},i=S(n),l=this.rasterInfo.statistics?.[0];return{...i,minValue:l?.min??0,maxValue:l?.max??8e3,hillshadeType:"traditional"===e.hillshadeType?0:1,type:"hillshade",colormap:a,colormapOffset:o}}_generateVectorFieldWebGLParams(e){const{style:r,inputUnit:t,outputUnit:s,visualVariables:a,symbolTileSize:o,flowRepresentation:n}=e,i=this.rasterInfo.statistics?.[0].min??0,l=this.rasterInfo.statistics?.[0].max??50,u=a?.find((e=>"sizeInfo"===e.type))??{maxDataValue:l,maxSize:.8*o,minDataValue:i,minSize:.2*o},c=u.minDataValue??i,p=u.maxDataValue??l,d=null!=u.maxSize&&null!=u.minSize?[u.minSize/o,u.maxSize/o]:[.2,.8];if("wind_speed"===r){const e=(d[0]+d[1])/2;d[0]=d[1]=e}const m=null!=c&&null!=p?[c,p]:null;let h=null;if("classified_arrow"===r)if(null!=c&&null!=p&&null!=u){h=[];const e=(u.maxDataValue-u.minDataValue)/5;for(let r=0;r<6;r++)h.push(u.minDataValue+e*r)}else h=[0,1e-6,3.5,7,10.5,14];const f="flow_to"===n===("ocean_current_kn"===r||"ocean_current_m"===r)?0:Math.PI,b=a?.find((e=>"rotationInfo"===e.type));return{breakValues:h,dataRange:m,inputUnit:t,outputUnit:s,symbolTileSize:o,symbolPercentRange:d,style:r||"single_arrow",rotation:f,rotationType:this.rasterInfo.storageInfo?.tileInfo&&"vector-uv"===this.rasterInfo.dataType?"geographic":b?.rotationType||e.rotationType,type:"vectorField"}}};function V(e){return"percentClip"===e||"histogramEqualization"===e}function v(e){return null!=e&&e.length>0&&null!=e[0].min&&null!=e[0].max}function T(e){return c(e)&&0!==e.validPixelCount}function O(e){return"algorithmic"===e.type&&["0,0,0,255","0,0,0"].includes(e.fromColor.join(","))&&["255,255,255,255","255,255,255"].includes(e.toColor.join(","))}e([s({json:{write:!0}})],_.prototype,"rendererJSON",void 0),e([s({type:o,json:{write:!0}})],_.prototype,"rasterInfo",void 0),e([s({json:{write:!0}})],_.prototype,"lookup",void 0),e([s()],_.prototype,"canRenderInWebGL",void 0),_=e([a("esri.renderers.support.RasterSymbolizer")],_);export{_ 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
- const c="20250729",b="6617c2268829fa5b8cc30e70d4b69d6197b7cb48";export{c as buildDate,b as commitHash};
5
+ const a="20250731",e="5a8834f8afaefbeafe979dfea5a1e79284cf577a";export{a as buildDate,e as commitHash};
@@ -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{getAssetUrl as e}from"../../assets.js";import{toHSV as t,toRGB as l}from"../../core/colorUtils.js";import"../../core/has.js";import a from"../../core/Error.js";import s from"../../core/Logger.js";import{pt2px as n}from"../../core/screenUtils.js";import{defaultThematicColor as r,dekebabifyLineStyle as o,getPatternUrlWithColor as i}from"./gfxUtils.js";import{defaultPrimitive as c}from"./IconSymbol3DLayerResource.js";import{defaultPrimitive as p}from"./ObjectSymbol3DLayerResource.js";import{adjustColorComponentBrightness as u,getExtrudeSymbolShapes as h,shapes as m,getPathSymbolShapes as f,SymbolSizeDefaults as y,getTetrahedronShapes as d,getDiamondShapes as b,getCylinderShapes as k,getCubeShapes as v,getInvertedConeShapes as g,getConeShapes as w,getWaterSymbolShapes as x}from"./previewUtils.js";import{renderSymbol as M,tintImageWithColor as L}from"./renderUtils.js";import{isVolumetricSymbol as j,getIconHref as z}from"./utils.js";import{resolveWebStyleSymbol as S}from"./webStyleSymbolUtils.js";const P=y.size,D=y.maxSize,U=y.maxOutlineSize,O=y.lineWidth,C=y.tallSymbolWidth;function R(e){const t=e.outline,l=null!=e.material?e.material.color:null,a=null!=l?l.toHex():null;if(null==t||"pattern"in t&&null!=t.pattern&&"style"===t.pattern.type&&"none"===t.pattern.style)return"fill"===e.type&&"#ffffff"===a?{color:"#bdc3c7",width:.75}:null;const s=n(t.size)||0;return{color:"rgba("+(null!=t.color?t.color.toRgba():"255,255,255,1")+")",width:Math.min(s,U),style:"pattern"in t&&null!=t.pattern&&"style"===t.pattern.type?o(t.pattern.style):null,join:"butt",cap:"patternCap"in t?t.patternCap:"butt"}}async function E(t,l){if(t.thumbnail?.url)return t.thumbnail.url;if("icon"===l.type){const e=l?.resource?.href;if(e)return z(l)}const a=e("esri/images/Legend/legend3dsymboldefault.png");if(t.styleOrigin&&(t.styleOrigin.styleName||t.styleOrigin.styleUrl)){const e=await S(t.styleOrigin,{portal:t.styleOrigin.portal}).catch((()=>null));if(e&&"thumbnail"in e&&e.thumbnail?.url)return e.thumbnail.url}return a}function q(e,a=1){const s=e.a,n=t(e),r=n.h,o=n.s/a,i=100-(100-n.v)/a,{r:c,g:p,b:u}=l({h:r,s:o,v:i});return[c,p,u,s]}function I(e){return"water"===e.type?null==e.color?null:e.color:null==e.material?.color?null:e.material.color}function Z(e,t=0){const l=I(e);if(!l){if("fill"===e.type)return null;const l=r.r,a=u(l,t);return[a,a,a,100]}const a=l.toRgba();for(let s=0;s<3;s++)a[s]=u(a[s],t);return a}async function H(t,l){const a=t.style;if("none"===a)return null;return{type:"pattern",x:0,y:0,src:await i(e(`esri/symbols/patterns/${a}.png`),l.toCss(!0)),width:5,height:5}}function N(e){return e.outline?R(e):{color:"rgba(0, 0, 0, 1)",width:1.5}}function T(e,t){const l=I(e);if(!l)return null;let a="rgba(";return a+=u(l.r,t)+",",a+=u(l.g,t)+",",a+=u(l.b,t)+",",a+l.a+");"}function W(e,t){const l=T(e,t);if(!l)return{};if("pattern"in e&&null!=e.pattern&&"style"===e.pattern.type&&"none"===e.pattern.style)return null;return{color:l,width:Math.min(e.size?n(e.size):.75,U),style:"pattern"in e&&null!=e.pattern&&"style"===e.pattern.type?o(e.pattern.style):null,cap:"cap"in e?e.cap:null,join:"join"in e?"miter"===e.join?n(2):e.join:null}}function F(e,t,l){const a=null!=l?.75*l:0;return{type:"linear",x1:a?.25*a:0,y1:a?.5*a:0,x2:a||4,y2:a?.5*a:4,colors:[{color:e,offset:0},{color:t,offset:1}]}}function $(e){const t=e.depth,l=e.height,a=e.width;return 0!==a&&0!==t&&0!==l&&a===t&&null!=a&&null!=l&&a<l}function A(e,t,l){const a=[];if(!e)return a;switch(e.type){case"icon":{const l=0,s=0,n=t,r=t;switch(e.resource?.primitive??c){case"circle":a.push({shape:{type:"circle",cx:0,cy:0,r:.5*t},fill:Z(e,0),stroke:R(e)});break;case"square":a.push({shape:{type:"path",path:[{command:"M",values:[l,r]},{command:"L",values:[l,s]},{command:"L",values:[n,s]},{command:"L",values:[n,r]},{command:"Z",values:[]}]},fill:Z(e,0),stroke:R(e)});break;case"triangle":a.push({shape:{type:"path",path:[{command:"M",values:[l,r]},{command:"L",values:[.5*n,s]},{command:"L",values:[n,r]},{command:"Z",values:[]}]},fill:Z(e,0),stroke:R(e)});break;case"cross":a.push({shape:{type:"path",path:[{command:"M",values:[.5*n,s]},{command:"L",values:[.5*n,r]},{command:"M",values:[l,.5*r]},{command:"L",values:[n,.5*r]}]},stroke:N(e)});break;case"x":a.push({shape:{type:"path",path:[{command:"M",values:[l,s]},{command:"L",values:[n,r]},{command:"M",values:[n,s]},{command:"L",values:[l,r]}]},stroke:N(e)});break;case"kite":a.push({shape:{type:"path",path:[{command:"M",values:[l,.5*r]},{command:"L",values:[.5*n,s]},{command:"L",values:[n,.5*r]},{command:"L",values:[.5*n,r]},{command:"Z",values:[]}]},fill:Z(e,0),stroke:R(e)})}break}case"object":switch(e.resource?.primitive??p){case"cone":{const s=F(Z(e,0),Z(e,-.6),l?C:t),n=w(t,l);a.push({shape:n[0],fill:s},{shape:n[1],fill:s});break}case"inverted-cone":{const l=Z(e,0),s=F(l,Z(e,-.6),t),n=g(t);a.push({shape:n[0],fill:s},{shape:n[1],fill:l});break}case"cube":{const s=v(t,l);a.push({shape:s[0],fill:Z(e,0)},{shape:s[1],fill:Z(e,-.3)},{shape:s[2],fill:Z(e,-.5)});break}case"cylinder":{const s=F(Z(e,0),Z(e,-.6),l?C:t),n=k(t,l);a.push({shape:n[0],fill:s},{shape:n[1],fill:s},{shape:n[2],fill:Z(e,0)});break}case"diamond":{const l=b(t);a.push({shape:l[0],fill:Z(e,-.3)},{shape:l[1],fill:Z(e,0)},{shape:l[2],fill:Z(e,-.3)},{shape:l[3],fill:Z(e,-.7)});break}case"sphere":{const l=F(Z(e,0),Z(e,-.6));l.x1=0,l.y1=0,l.x2=.25*t,l.y2=.25*t,a.push({shape:{type:"circle",cx:0,cy:0,r:.5*t},fill:l});break}case"tetrahedron":{const l=d(t);a.push({shape:l[0],fill:Z(e,-.3)},{shape:l[1],fill:Z(e,0)},{shape:l[2],fill:Z(e,-.6)});break}}break}return a}function B(e){const t="number"==typeof e?.size?e?.size:null;return t?n(t):null}function G(e){return"icon"===e.type?"multiply":"tint"}async function J(e,t){const l=B(t),a=t?.maxSize?n(t.maxSize):null,r=t?.disableUpsampling??!1,o=e.symbolLayers,i=[],c=[];let p=!1,u=0,h=0,m=0;o.forEach((s=>{if("icon"!==s.type&&"object"!==s.type)return;s&&"icon"===s.type&&(m=Math.max(s.size&&n(s.size),m));const o="icon"===s.type?s.size&&n(s.size):0,f=l||o?Math.ceil(Math.min(l||o,a||D)):P;let y="icon"===s.type?s.angle:null;if(null!=t?.rotation&&(y=(y??0)+t.rotation),c.push(y),s?.resource?.href){const t=E(e,s).then((e=>{const t=s?.material?.color,l=G(s);return L(e,f,t,l,r)})).then((e=>{const t=e.width,l=e.height;return u=Math.max(u,t),h=Math.max(h,l),y&&(p=!0),[{shape:{type:"image",x:0,y:0,width:t,height:l,src:e.url},fill:null,stroke:null}]}));i.push(t)}else{let e=f;"icon"===s.type&&l&&(e=f*(o/m));const a="tall"===t?.symbolConfig||t?.symbolConfig?.isTall||"object"===s.type&&$(s);u=Math.max(u,a?C:e),h=Math.max(h,e),y&&s.resource?.primitive&&["square","triangle","x"].includes(s.resource?.primitive)&&(p=!0),i.push(Promise.resolve(A(s,e,a)))}}));const f=await Promise.allSettled(i),y=[];return f.forEach((e=>{"fulfilled"===e.status?y.push(e.value):e.reason&&s.getLogger("esri.symbols.support.previewSymbol3D").warn("error while building swatchInfo!",e.reason)})),M(y,[u,h],{node:t?.node,scale:!1,opacity:t?.opacity,ariaLabel:t?.ariaLabel,rotations:c,useRotationSize:p})}function K(e,t){const l=e.symbolLayers,a=[],s=j(e),r=B(t),o=(t?.maxSize?n(t.maxSize):null)||U;let i,c=0,p=0;return l.forEach(((e,t)=>{if(!e)return;if("line"!==e.type&&"path"!==e.type)return;const l=[];switch(e.type){case"line":{const a=W(e,0);if(null==a)break;const s=a?.width||0;0===t&&(i=s);const n=Math.min(r||s,o),u=0===t?n:r?n*(s/i):n,h=u>O/2?2*u:O;p=Math.max(p,u),c=Math.max(c,h),a.width=u,l.push({shape:{type:"path",path:[{command:"M",values:[0,.5*p]},{command:"L",values:[c,.5*p]}]},stroke:a});break}case"path":{const t=Math.min(r||P,o),a=Z(e,0),s=Z(e,-.2),n=T(e,-.4),i=n?{color:n,width:1}:{};if("quad"===e.profile){const t=e.width,n=e.height,r=f(t&&n?t/n:1,0===n,0===t),o={...i,join:"bevel"};l.push({shape:r[0],fill:s,stroke:o},{shape:r[1],fill:s,stroke:o},{shape:r[2],fill:a,stroke:o})}else l.push({shape:m.pathSymbol3DLayer[0],fill:s,stroke:i},{shape:m.pathSymbol3DLayer[1],fill:a,stroke:i});p=Math.max(p,t),c=p}}a.push(l)})),Promise.resolve(M(a,[c,p],{node:t?.node,scale:s,opacity:t?.opacity,ariaLabel:t?.ariaLabel}))}async function Q(e,t){const l="mesh-3d"===e.type,a=e.symbolLayers,s=B(t),r=t?.maxSize?n(t.maxSize):null,o=s||P,i=[];let c=0,p=0,u=!1;for(let n=0;n<a.length;n++){const e=a.at(n),t=[];if(!l||"fill"===e.type){switch(e.type){case"fill":{const a=Math.min(o,r||D);if(c=Math.max(c,a),p=Math.max(p,a),u=!0,l){const l=m.meshSymbol3DFill,a=T(e,-.4),s=a?{color:a,width:1,join:"round"}:{};t.push({shape:l[0],fill:Z(e,0),stroke:s},{shape:l[1],fill:Z(e,-.2),stroke:s},{shape:l[2],fill:Z(e,-.6),stroke:s})}else{let l=Z(e,0);const a="pattern"in e?e.pattern:null,s=R(e),n=I(e);null!=a&&"style"===a.type&&"solid"!==a.style&&n&&(l=await H(a,n)),t.push({shape:m.fill[0],fill:l,stroke:s})}break}case"line":{const l=W(e,0);if(null==l)break;const a={stroke:l,shape:m.fill[0]};c=Math.max(c,P),p=Math.max(p,P),t.push(a);break}case"extrude":{const l={join:"round",width:1,...W(e,-.4)},a=Z(e,0),s=Z(e,-.2),n=Math.min(o,r||D),i=h(n);l.width=1,t.push({shape:i[0],fill:s,stroke:l},{shape:i[1],fill:s,stroke:l},{shape:i[2],fill:a,stroke:l});const u=P,m=.7*P+.5*n;c=Math.max(c,u),p=Math.max(p,m);break}case"water":{const l=I(e),a=q(l),s=q(l,2),n=q(l,3),i=x();u=!0,t.push({shape:i[0],fill:a},{shape:i[1],fill:s},{shape:i[2],fill:n});const h=Math.min(o,r||D);c=Math.max(c,h),p=Math.max(p,h);break}}i.push(t)}}return M(i,[c,p],{node:t?.node,scale:u,opacity:t?.opacity,ariaLabel:t?.ariaLabel})}function V(e,t){if(0===e.symbolLayers.length)return Promise.reject(new a("symbolPreview: renderPreviewHTML3D","No symbolLayers in the symbol."));switch(e.type){case"point-3d":return J(e,t);case"line-3d":return K(e,t);case"polygon-3d":case"mesh-3d":return Q(e,t)}return Promise.reject(new a("symbolPreview: swatchInfo3D","symbol not supported."))}export{H as getPatternDescriptor,B as getSizeFromOptions,Z as getSymbolLayerFill,V as previewSymbol3D};
5
+ import{getAssetUrl as e}from"../../assets.js";import{toHSV as t,toRGB as l}from"../../core/colorUtils.js";import"../../core/has.js";import a from"../../core/Error.js";import s from"../../core/Logger.js";import{pt2px as n}from"../../core/screenUtils.js";import{defaultThematicColor as r,dekebabifyLineStyle as o,getPatternUrlWithColor as i}from"./gfxUtils.js";import{defaultPrimitive as c}from"./IconSymbol3DLayerResource.js";import{defaultPrimitive as p}from"./ObjectSymbol3DLayerResource.js";import{SymbolSizeDefaults as u,adjustColorComponentBrightness as h,getExtrudeSymbolShapes as m,shapes as f,getPathSymbolShapes as y,getTetrahedronShapes as d,getDiamondShapes as b,getCylinderShapes as k,getCubeShapes as v,getInvertedConeShapes as g,getConeShapes as w,getWaterSymbolShapes as x}from"./previewUtils.js";import{renderSymbol as M,tintImageWithColor as L}from"./renderUtils.js";import{isVolumetricSymbol as j,getIconHref as z}from"./utils.js";import{resolveWebStyleSymbol as S}from"./webStyleSymbolUtils.js";const P=u.size,D=u.maxSize,U=u.maxOutlineSize,O=u.lineWidth,C=u.tallSymbolWidth;function R(e){const t=e.outline,l=null!=e.material?e.material.color:null,a=null!=l?l.toHex():null;if(null==t||"pattern"in t&&null!=t.pattern&&"style"===t.pattern.type&&"none"===t.pattern.style)return"fill"===e.type&&"#ffffff"===a?{color:"#bdc3c7",width:.75}:null;const s=n(t.size)||0;return{color:"rgba("+(null!=t.color?t.color.toRgba():"255,255,255,1")+")",width:Math.min(s,U),style:"pattern"in t&&null!=t.pattern&&"style"===t.pattern.type?o(t.pattern.style):null,join:"butt",cap:"patternCap"in t?t.patternCap:"butt"}}async function E(t,l){if(t.thumbnail?.url)return t.thumbnail.url;if("icon"===l.type){const e=l?.resource?.href;if(e)return z(l)}const a=e("esri/images/Legend/legend3dsymboldefault.png");if(t.styleOrigin&&(t.styleOrigin.styleName||t.styleOrigin.styleUrl)){const e=await S(t.styleOrigin,{portal:t.styleOrigin.portal}).catch((()=>null));if(e&&"thumbnail"in e&&e.thumbnail?.url)return e.thumbnail.url}return a}function q(e,a=1){const s=e.a,n=t(e),r=n.h,o=n.s/a,i=100-(100-n.v)/a,{r:c,g:p,b:u}=l({h:r,s:o,v:i});return[c,p,u,s]}function I(e){return"water"===e.type?null==e.color?null:e.color:null==e.material?.color?null:e.material.color}function Z(e,t=0){const l=I(e);if(!l){if("fill"===e.type)return null;const l=r.r,a=h(l,t);return[a,a,a,100]}const a=l.toRgba();for(let s=0;s<3;s++)a[s]=h(a[s],t);return a}async function H(t,l){const a=t.style;if("none"===a)return null;return{type:"pattern",x:0,y:0,src:await i(e(`esri/symbols/patterns/${a}.png`),l.toCss(!0)),width:5,height:5}}function N(e){return e.outline?R(e):{color:"rgba(0, 0, 0, 1)",width:1.5}}function T(e,t){const l=I(e);if(!l)return null;let a="rgba(";return a+=h(l.r,t)+",",a+=h(l.g,t)+",",a+=h(l.b,t)+",",a+l.a+");"}function W(e,t){const l=T(e,t);if(!l)return{};if("pattern"in e&&null!=e.pattern&&"style"===e.pattern.type&&"none"===e.pattern.style)return null;return{color:l,width:Math.min(e.size?n(e.size):.75,U),style:"pattern"in e&&null!=e.pattern&&"style"===e.pattern.type?o(e.pattern.style):null,cap:"cap"in e?e.cap:null,join:"join"in e?"miter"===e.join?n(2):e.join:null}}function F(e,t,l){const a=null!=l?.75*l:0;return{type:"linear",x1:a?.25*a:0,y1:a?.5*a:0,x2:a||4,y2:a?.5*a:4,colors:[{color:e,offset:0},{color:t,offset:1}]}}function $(e){const t=e.depth,l=e.height,a=e.width;return 0!==a&&0!==t&&0!==l&&a===t&&null!=a&&null!=l&&a<l}function A(e,t,l){const a=[];if(!e)return a;switch(e.type){case"icon":{const l=0,s=0,n=t,r=t;switch(e.resource?.primitive??c){case"circle":a.push({shape:{type:"circle",cx:0,cy:0,r:.5*t},fill:Z(e,0),stroke:R(e)});break;case"square":a.push({shape:{type:"path",path:[{command:"M",values:[l,r]},{command:"L",values:[l,s]},{command:"L",values:[n,s]},{command:"L",values:[n,r]},{command:"Z",values:[]}]},fill:Z(e,0),stroke:R(e)});break;case"triangle":a.push({shape:{type:"path",path:[{command:"M",values:[l,r]},{command:"L",values:[.5*n,s]},{command:"L",values:[n,r]},{command:"Z",values:[]}]},fill:Z(e,0),stroke:R(e)});break;case"cross":a.push({shape:{type:"path",path:[{command:"M",values:[.5*n,s]},{command:"L",values:[.5*n,r]},{command:"M",values:[l,.5*r]},{command:"L",values:[n,.5*r]}]},stroke:N(e)});break;case"x":a.push({shape:{type:"path",path:[{command:"M",values:[l,s]},{command:"L",values:[n,r]},{command:"M",values:[n,s]},{command:"L",values:[l,r]}]},stroke:N(e)});break;case"kite":a.push({shape:{type:"path",path:[{command:"M",values:[l,.5*r]},{command:"L",values:[.5*n,s]},{command:"L",values:[n,.5*r]},{command:"L",values:[.5*n,r]},{command:"Z",values:[]}]},fill:Z(e,0),stroke:R(e)})}break}case"object":switch(e.resource?.primitive??p){case"cone":{const s=F(Z(e,0),Z(e,-.6),l?C:t),n=w(t,l);a.push({shape:n[0],fill:s},{shape:n[1],fill:s});break}case"inverted-cone":{const l=Z(e,0),s=F(l,Z(e,-.6),t),n=g(t);a.push({shape:n[0],fill:s},{shape:n[1],fill:l});break}case"cube":{const s=v(t,l);a.push({shape:s[0],fill:Z(e,0)},{shape:s[1],fill:Z(e,-.3)},{shape:s[2],fill:Z(e,-.5)});break}case"cylinder":{const s=F(Z(e,0),Z(e,-.6),l?C:t),n=k(t,l);a.push({shape:n[0],fill:s},{shape:n[1],fill:s},{shape:n[2],fill:Z(e,0)});break}case"diamond":{const l=b(t);a.push({shape:l[0],fill:Z(e,-.3)},{shape:l[1],fill:Z(e,0)},{shape:l[2],fill:Z(e,-.3)},{shape:l[3],fill:Z(e,-.7)});break}case"sphere":{const l=F(Z(e,0),Z(e,-.6));l.x1=0,l.y1=0,l.x2=.25*t,l.y2=.25*t,a.push({shape:{type:"circle",cx:0,cy:0,r:.5*t},fill:l});break}case"tetrahedron":{const l=d(t);a.push({shape:l[0],fill:Z(e,-.3)},{shape:l[1],fill:Z(e,0)},{shape:l[2],fill:Z(e,-.6)});break}}break}return a}function B(e){const t="number"==typeof e?.size?e?.size:null;return t?n(t):null}function G(e){return"icon"===e.type?"multiply":"tint"}async function J(e,t){const l=B(t),a=t?.maxSize?n(t.maxSize):null,r=t?.disableUpsampling??!1,o=e.symbolLayers,i=[],c=[];let p=!1,u=0,h=0,m=0;o.forEach((s=>{if("icon"!==s.type&&"object"!==s.type)return;s&&"icon"===s.type&&(m=Math.max(s.size&&n(s.size),m));const o="icon"===s.type?s.size&&n(s.size):0,f=l||o?Math.ceil(Math.min(l||o,a||D)):P;let y="icon"===s.type?s.angle:null;if(null!=t?.rotation&&(y=(y??0)+t.rotation),c.push(y),s?.resource?.href){const t=E(e,s).then((e=>{const t=s?.material?.color,l=G(s);return L(e,f,t,l,r)})).then((e=>{const t=e.width,l=e.height;return u=Math.max(u,t),h=Math.max(h,l),y&&(p=!0),[{shape:{type:"image",x:0,y:0,width:t,height:l,src:e.url},fill:null,stroke:null}]}));i.push(t)}else{let e=f;"icon"===s.type&&l&&(e=f*(o/m));const a="tall"===t?.symbolConfig||t?.symbolConfig?.isTall||"object"===s.type&&$(s);u=Math.max(u,a?C:e),h=Math.max(h,e),y&&s.resource?.primitive&&["square","triangle","x"].includes(s.resource?.primitive)&&(p=!0),i.push(Promise.resolve(A(s,e,a)))}}));const f=await Promise.allSettled(i),y=[];return f.forEach((e=>{"fulfilled"===e.status?y.push(e.value):e.reason&&s.getLogger("esri.symbols.support.previewSymbol3D").warn("error while building swatchInfo!",e.reason)})),M(y,[u,h],{node:t?.node,scale:!1,opacity:t?.opacity,ariaLabel:t?.ariaLabel,rotations:c,useRotationSize:p})}function K(e,t){const l=e.symbolLayers,a=[],s=j(e),r=B(t),o=(t?.maxSize?n(t.maxSize):null)||U;let i,c=0,p=0;return l.forEach(((e,t)=>{if(!e)return;if("line"!==e.type&&"path"!==e.type)return;const l=[];switch(e.type){case"line":{const a=W(e,0);if(null==a)break;const s=a?.width||0;0===t&&(i=s);const n=Math.min(r||s,o),u=0===t?n:r?n*(s/i):n,h=u>O/2?2*u:O;p=Math.max(p,u),c=Math.max(c,h),a.width=u,l.push({shape:{type:"path",path:[{command:"M",values:[0,.5*p]},{command:"L",values:[c,.5*p]}]},stroke:a});break}case"path":{const t=Math.min(r||P,o),a=Z(e,0),s=Z(e,-.2),n=T(e,-.4),i=n?{color:n,width:1}:{};if("quad"===e.profile){const t=e.width,n=e.height,r=y(t&&n?t/n:1,0===n,0===t),o={...i,join:"bevel"};l.push({shape:r[0],fill:s,stroke:o},{shape:r[1],fill:s,stroke:o},{shape:r[2],fill:a,stroke:o})}else l.push({shape:f.pathSymbol3DLayer[0],fill:s,stroke:i},{shape:f.pathSymbol3DLayer[1],fill:a,stroke:i});p=Math.max(p,t),c=p}}a.push(l)})),Promise.resolve(M(a,[c,p],{node:t?.node,scale:s,opacity:t?.opacity,ariaLabel:t?.ariaLabel}))}async function Q(e,t){const l="mesh-3d"===e.type,a=e.symbolLayers,s=B(t),r=t?.maxSize?n(t.maxSize):null,o=s||P,i=[];let c=0,p=0,u=!1;for(let n=0;n<a.length;n++){const e=a.at(n),t=[];if(!l||"fill"===e.type){switch(e.type){case"fill":{const a=Math.min(o,r||D);if(c=Math.max(c,a),p=Math.max(p,a),u=!0,l){const l=f.meshSymbol3DFill,a=T(e,-.4),s=a?{color:a,width:1,join:"round"}:{};t.push({shape:l[0],fill:Z(e,0),stroke:s},{shape:l[1],fill:Z(e,-.2),stroke:s},{shape:l[2],fill:Z(e,-.6),stroke:s})}else{let l=Z(e,0);const a="pattern"in e?e.pattern:null,s=R(e),n=I(e);null!=a&&"style"===a.type&&"solid"!==a.style&&n&&(l=await H(a,n)),t.push({shape:f.fill[0],fill:l,stroke:s})}break}case"line":{const l=W(e,0);if(null==l)break;const a={stroke:l,shape:f.fill[0]};c=Math.max(c,P),p=Math.max(p,P),t.push(a);break}case"extrude":{const l={join:"round",width:1,...W(e,-.4)},a=Z(e,0),s=Z(e,-.2),n=Math.min(o,r||D),i=m(n);l.width=1,t.push({shape:i[0],fill:s,stroke:l},{shape:i[1],fill:s,stroke:l},{shape:i[2],fill:a,stroke:l});const u=P,h=.7*P+.5*n;c=Math.max(c,u),p=Math.max(p,h);break}case"water":{const l=I(e),a=q(l),s=q(l,2),n=q(l,3),i=x();u=!0,t.push({shape:i[0],fill:a},{shape:i[1],fill:s},{shape:i[2],fill:n});const h=Math.min(o,r||D);c=Math.max(c,h),p=Math.max(p,h);break}}i.push(t)}}return M(i,[c,p],{node:t?.node,scale:u,opacity:t?.opacity,ariaLabel:t?.ariaLabel})}function V(e,t){if(0===e.symbolLayers.length)return Promise.reject(new a("symbolPreview: renderPreviewHTML3D","No symbolLayers in the symbol."));switch(e.type){case"point-3d":return J(e,t);case"line-3d":return K(e,t);case"polygon-3d":case"mesh-3d":return Q(e,t)}return Promise.reject(new a("symbolPreview: swatchInfo3D","symbol not supported."))}export{H as getPatternDescriptor,B as getSizeFromOptions,Z as getSymbolLayerFill,V as previewSymbol3D};
@@ -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 i from"../../../../core/Logger.js";import{assertIsSome as s}from"../../../../core/maybe.js";import{debounce as r,isAbortError as a}from"../../../../core/promiseUtils.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/RandomLCG.js";import{subclass as l}from"../../../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as n}from"../../../../core/support/UpdatingHandles.js";import h from"../../../../geometry/Extent.js";import c from"../../../../geometry/Point.js";import u from"../../../../layers/support/PixelBlock.js";import d from"../../../../layers/support/TileInfo.js";import{update as p,unregister as m,getRasterId as y,register as g}from"../../../../layers/support/rasterDatasets/RawBlockCache.js";import{getWorldWidth as _,computeProjectedScales as f}from"../../../../layers/support/rasterFunctions/rasterProjectionHelper.js";import b from"../../tiling/TileInfoView.js";import"../../tiling/TileKey.js";import w from"../../tiling/TileQueue.js";import P from"../../tiling/TileStrategy.js";import{tileSize as I}from"../../engine/webgl/definitions.js";import{TaskPriority as S}from"../../../support/Scheduler.js";import{getWebGLCapabilities as R}from"../../../webgl/capabilities.js";const C=[0,0];let U=class extends t{constructor(){super(...arguments),this._updatingHandles=new n,this._emptyTilePixelBlock=null,this._tileStrategy=null,this._tileInfoView=null,this._fetchQueue=null,this._blockCacheRegistryUrl=null,this._blockCacheRegistryId=null,this._srcResolutions=[],this.previousLOD=null,this._needBlockCacheUpdate=!1,this._globalSymbolizerParams=null,this._symbolizerParams=null,this._abortController=null,this._isCustomTilingScheme=!1,this._maxIndexedColormapSize=0,this._rasterFunctionState="na",this._globalUpdateRequested=!1,this.attached=!1,this.timeExtent=null,this.redrawOrRefetch=r((async(e={})=>{const t=this._rasterFunctionState,i=e.reprocess||"gpu"===t&&!this.canUseWebGLForProcessing||"cpu"===t&&this.canUseWebGLForProcessing;if(i&&(await this._updatingHandles.addPromise(this.layer.updateRasterFunction()),this.updateRasterFunctionParameters()),!this.previousLOD||this.layerView.suspended)return;const s=this._rasterFunctionState,{type:r}=this;return e.refetch||"raster"!==r&&!!i||"cpu"===s||"cpu"===t?this._updatingHandles.addPromise(this.doRefresh()):this._updatingHandles.addPromise(this._redrawImage(e.signal))}))}destroy(){this._updatingHandles.destroy()}get canUseWebGLForProcessing(){return!1}get canUseLocalSymbolizerParams(){return(this.canUseWebGLForProcessing||"rasterVF"===this.type)&&!this.layerView.hasTilingEffects}get useWebGLForProcessing(){return this._get("useWebGLForProcessing")??!0}set useWebGLForProcessing(e){this._set("useWebGLForProcessing",e)}get useProgressiveUpdate(){return this._get("useProgressiveUpdate")??!0}set useProgressiveUpdate(e){if(this._tileStrategy&&this.useProgressiveUpdate!==e){this._tileStrategy.destroy(),this.container.removeAllChildren();const t=this._getCacheSize(e);this._tileStrategy=new P({cachePolicy:"purge",acquireTile:e=>this.acquireTile(e),releaseTile:e=>this.releaseTile(e),cacheSize:t,tileInfoView:this._tileInfoView}),this._set("useProgressiveUpdate",e),this.layerView.requestUpdate()}}update(e){this._fetchQueue.pause(),this._fetchQueue.state=e.state,this._tileStrategy.update(e),this._fetchQueue.resume();const{extent:t,resolution:i,scale:s}=e.state,r=this._tileInfoView.getClosestInfoForScale(s);if(this.layer.raster){if(!this.useProgressiveUpdate||this._needBlockCacheUpdate){const e=this._srcResolutions[r.level],s="toJSON"in t?t:h.fromJSON(t);p(this._blockCacheRegistryUrl,this._blockCacheRegistryId,s,i,e,this.layer.raster.ioConfig.sampling)}this._needBlockCacheUpdate=!1,this.previousLOD?.level!==r.level&&(this.previousLOD=r,null!=this._symbolizerParams&&this.canUseLocalSymbolizerParams&&this._updateSymbolizerParams(),this._tileStrategy.updateCacheSize(0))}}moveEnd(){!this.layerView.hasTilingEffects&&this.useProgressiveUpdate||(this._abortController&&this._abortController.abort(),this._abortController=new AbortController,0===this._fetchQueue.length&&this._redrawImage(this._abortController.signal).then((()=>{this._globalUpdateRequested=!1,this.layerView.requestUpdate()})));const e=this._getCacheSize(this.useProgressiveUpdate);this._tileStrategy.updateCacheSize(e),this.layerView.requestUpdate()}get updating(){return this._globalUpdateRequested||this._updatingHandles?.updating}attach(){const e=R();this._maxIndexedColormapSize=4*(e.maxTextureSize||4096),this._initializeTileInfo(),this._tileInfoView=new b(this.layerView.tileInfo,this.layerView.fullExtent);const t=this._computeFetchConcurrency();this._fetchQueue=new w({tileInfoView:this._tileInfoView,concurrency:t,process:(e,t)=>this._fetchTile(e,t),priority:S.MAPVIEW_FETCH_QUEUE,scheduler:this.scheduler});const i=this._getCacheSize(this.useProgressiveUpdate);this._tileStrategy=new P({cachePolicy:"purge",acquireTile:e=>this.acquireTile(e),releaseTile:e=>this.releaseTile(e),cacheSize:i,tileInfoView:this._tileInfoView}),this._updateBlockCacheRegistry()}detach(){this._tileStrategy.destroy(),this._fetchQueue.clear(),this.container.removeAllChildren(),this._fetchQueue=this._tileStrategy=this._tileInfoView=null,m(this._blockCacheRegistryUrl,this._blockCacheRegistryId),this._blockCacheRegistryUrl=this._blockCacheRegistryId=null}acquireTile(e){const t=this.container.createTile(e);return this._updatingHandles.addPromise(this._enqueueTileFetch(t)),this.layerView.requestUpdate(),this._needBlockCacheUpdate=!0,this._globalUpdateRequested=this.layerView.hasTilingEffects||!this.useProgressiveUpdate,t}releaseTile(e){this._fetchQueue.abort(e.key.id),this.container.removeChild(e),e.once("detach",(()=>{e.destroy(),this.layerView.requestUpdate()})),this.layerView.requestUpdate()}createEmptyTilePixelBlock(e=null){const t=null==e||e.join(",")===this._tileInfoView.tileInfo.size.join(",");if(t&&null!=this._emptyTilePixelBlock)return this._emptyTilePixelBlock;e=e||this._tileInfoView.tileInfo.size;const[i,s]=e,r=new u({width:i,height:s,pixels:[new Uint8Array(i*s)],mask:new Uint8Array(i*s),pixelType:"u8"});return t&&(this._emptyTilePixelBlock=r),r}_getBandIds(){if(!("rasterFunctionChain"in this.container)||!this.container.rasterFunctionChain)return this.layer.bandIds;const{bandIds:e,raster:t}=this.layer,i="rasterFunction"in t?t.rasterFunction.rawInputBandIds:null;return e?.length&&i?.length&&1!==t.rasterInfo.bandCount?e.map((e=>i[Math.min(e,i.length-1)])):"rasterFunction"in t?i:e}updateRasterFunctionParameters(){}_fetchTile(e,t){const i=this._getFetchOptions(e.level,t.signal);return this.fetchTile(e,i)}_getFetchOptions(e,t){const{canUseWebGLForProcessing:i}=this,{layerView:s}=this,{tileInfo:r}=s,a=!r.isWrappable&&null!=_(s.view.spatialReference),o=i&&this.layer.raster.hasUniqueSourceStorageInfo,{layer:l}=this.layerView,n=l.serviceRasterInfo?.storageInfo.isBsqTile?l.bandIds:void 0;return{allowPartialFill:!0,datumTransformation:s.datumTransformation,interpolation:i?"nearest":this.layer.interpolation,registryId:this._blockCacheRegistryId,requestRawData:o,skipRasterFunction:"raster"===this.type&&null!=this.container.rasterFunctionChain,signal:t,srcResolution:this._srcResolutions[e],timeExtent:s.timeExtent,tileInfo:r,bandIds:n,disableWrapAround:a}}_getCacheSize(e){return e?40:0}_initializeTileInfo(){const{layerView:e}=this,t=e.view.spatialReference;if(this._canUseLayerLODs()){const{origin:i,lods:s}=this.layer.tileInfo,r=s.map((({scale:e})=>e)),a=d.create({spatialReference:t,size:I,scales:r,origin:i});return e.set("tileInfo",a),void(this._srcResolutions=s.map((({resolution:e})=>({x:e,y:e}))))}const{scales:i,srcResolutions:r,isCustomTilingScheme:a}=f(this.layer.serviceRasterInfo,t,{tileSize:I,alignGlobalDatasetWithAGOL:!0,limitToSrcResolution:!1}),o=d.create({spatialReference:t,size:I,scales:i}),l=0===o.origin.x;s(e.fullExtent);const{xmin:n,ymax:h}=e.fullExtent;(l||a&&o.origin.x>n)&&(o.origin=new c({x:n,y:h,spatialReference:t})),this._isCustomTilingScheme=a,e.set("tileInfo",o),this._srcResolutions=r??[]}_canUseLayerLODs(){const{layer:e,layerView:t}=this;if("Map"!==e.raster.tileType)return!1;const{lods:i}=e.tileInfo,s=t.view.constraints?.effectiveLODs;return s?.length===i.length&&s.every((({scale:e},t)=>Math.abs(e-i[t].scale)<.001))}_computeFetchConcurrency(){const{blockBoundary:e}=this.layer.serviceRasterInfo.storageInfo,t=e[e.length-1];return(t.maxCol-t.minCol+1)*(t.maxRow-t.minRow+1)>64?2:10}async _enqueueTileFetch(e,t){if(!this._fetchQueue.has(e.key.id)){try{const t=await this._fetchQueue.push(e.key),r=this._getBandIds();let o=!this.useProgressiveUpdate||this.layerView.hasTilingEffects&&!this._globalSymbolizerParams;if(this._globalUpdateRequested&&!this.layerView.moving&&0===this._fetchQueue.length){o=!1;try{await this._redrawImage(this._abortController?.signal)}catch(s){a(s)&&i.getLogger(this).error(s)}this._globalUpdateRequested=!1}this.canUseLocalSymbolizerParams&&null==this._symbolizerParams&&this._updateSymbolizerParams();const l=this._tileInfoView.getTileCoords(C,e.key),n=this._tileInfoView.getTileResolution(e.key);await this.updateTileSource(e,{source:t,symbolizerParams:this._symbolizerParams,globalSymbolizerParams:this._globalSymbolizerParams,suspended:o,bandIds:r,coords:l,resolution:n}),e.once("attach",(()=>this.layerView.requestUpdate())),this.container.addChild(e)}catch(s){a(s)||i.getLogger(this).error(s)}this.layerView.requestUpdate()}}async _redrawImage(e){if(0===this.container.children.length)return;await this.layer.updateRenderer(),this.layerView.hasTilingEffects?await this._updateGlobalSymbolizerParams(e):(this.canUseLocalSymbolizerParams&&this._updateSymbolizerParams(),this._globalSymbolizerParams=null);const t=this.container.children.map((async e=>this.updateTileSymbolizerParameters(e,{local:this._symbolizerParams,global:this._globalSymbolizerParams})));await Promise.allSettled(t),this.container.requestRender()}async _updateGlobalSymbolizerParams(e){const t=this._getFetchOptions(this.previousLOD.level,e),i=await this.layer.fetchPixels(this.layerView.view.extent,this.layerView.view.width,this.layerView.view.height,{...t,interpolation:"nearest",requestRawData:!1,skipRasterFunction:!1});if(!i?.pixelBlock)return;const{resolution:s}=this.previousLOD,r=this._getBandIds(),a=this.layer.symbolizer.generateWebGLParameters({pixelBlock:i.pixelBlock.extractBands(r),isGCS:this.layerView.view.spatialReference.isGeographic,resolution:{x:s,y:s},bandIds:r});!this.canUseWebGLForProcessing&&a&&"stretch"===a.type&&this.layer.renderer&&"raster-stretch"===this.layer.renderer.type&&(a.factor=a.factor.map((e=>255*e)),a.minOutput=Math.round(255*a.minOutput),a.maxOutput=Math.round(255*a.maxOutput)),this._globalSymbolizerParams=a}_updateSymbolizerParams(){const{resolution:e}=this.previousLOD,t=this._getBandIds();this._symbolizerParams=this.layer.symbolizer.generateWebGLParameters({pixelBlock:null,isGCS:this.layerView.view.spatialReference.isGeographic,resolution:{x:e,y:e},bandIds:t})}_updateBlockCacheRegistry(e=!1){const{layer:t,layerView:i}=this,{raster:s}=t,{multidimensionalDefinition:r}=t.normalizeRasterFetchOptions({multidimensionalDefinition:t.multidimensionalDefinition,timeExtent:i.timeExtent}),a=s.rasterInfo.multidimensionalInfo?s.getSliceIndex(r):null,o=s.rasterInfo.storageInfo.isBsqTile&&t.bandIds?.length?t.bandIds:null,l=y(s.rasterId,a,o);if(l!==this._blockCacheRegistryUrl){if(null!=this._blockCacheRegistryUrl&&m(this._blockCacheRegistryUrl,this._blockCacheRegistryId),this._blockCacheRegistryId=g(l,s.rasterInfo),e){const{view:e}=i,t=this._tileInfoView.getClosestInfoForScale(e.scale),r=this._srcResolutions[t.level];p(l,this._blockCacheRegistryId,e.extent,e.resolution,r,s.ioConfig.sampling)}this._blockCacheRegistryUrl=l}}async doRefresh(){if(!this.attached||!this.previousLOD||this.layerView.suspended)return;await this.layer.updateRenderer(),this.canUseLocalSymbolizerParams&&this._updateSymbolizerParams(),this._updateBlockCacheRegistry(!0),this._fetchQueue.reset();const e=[];this._globalUpdateRequested=this.layerView.hasTilingEffects||!this.useProgressiveUpdate,this._tileStrategy.refresh((t=>e.push(this._enqueueTileFetch(t)))),await this._updatingHandles.addPromise(Promise.allSettled(e))}};e([o()],U.prototype,"_globalUpdateRequested",void 0),e([o()],U.prototype,"attached",void 0),e([o()],U.prototype,"canUseWebGLForProcessing",null),e([o()],U.prototype,"canUseLocalSymbolizerParams",null),e([o()],U.prototype,"container",void 0),e([o()],U.prototype,"layer",void 0),e([o()],U.prototype,"layerView",void 0),e([o()],U.prototype,"scheduler",void 0),e([o()],U.prototype,"type",void 0),e([o()],U.prototype,"useWebGLForProcessing",null),e([o()],U.prototype,"useProgressiveUpdate",null),e([o()],U.prototype,"timeExtent",void 0),e([o()],U.prototype,"updating",null),U=e([l("esri.views.2d.layers.imagery.BaseImageryTileSubView2D")],U);export{U as BaseImageryTileSubView2D};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import i from"../../../../core/Logger.js";import{assertIsSome as s}from"../../../../core/maybe.js";import{debounce as r,isAbortError as a}from"../../../../core/promiseUtils.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/RandomLCG.js";import{subclass as l}from"../../../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as n}from"../../../../core/support/UpdatingHandles.js";import h from"../../../../geometry/Extent.js";import c from"../../../../geometry/Point.js";import u from"../../../../layers/support/PixelBlock.js";import d from"../../../../layers/support/TileInfo.js";import{update as p,unregister as m,getRasterId as y,register as g}from"../../../../layers/support/rasterDatasets/RawBlockCache.js";import{getWorldWidth as _,computeProjectedScales as f}from"../../../../layers/support/rasterFunctions/rasterProjectionHelper.js";import b from"../../tiling/TileInfoView.js";import"../../tiling/TileKey.js";import w from"../../tiling/TileQueue.js";import I from"../../tiling/TileStrategy.js";import{tileSize as P}from"../../engine/webgl/definitions.js";import{TaskPriority as S}from"../../../support/Scheduler.js";import{getWebGLCapabilities as R}from"../../../webgl/capabilities.js";const C=[0,0];let U=class extends t{constructor(){super(...arguments),this._updatingHandles=new n,this._emptyTilePixelBlock=null,this._tileStrategy=null,this._tileInfoView=null,this._fetchQueue=null,this._blockCacheRegistryUrl=null,this._blockCacheRegistryId=null,this._srcResolutions=[],this.previousLOD=null,this._needBlockCacheUpdate=!1,this._globalSymbolizerParams=null,this._symbolizerParams=null,this._abortController=null,this._isCustomTilingScheme=!1,this._maxIndexedColormapSize=0,this._rasterFunctionState="na",this._globalUpdateRequested=!1,this.attached=!1,this.timeExtent=null,this.redrawOrRefetch=r((async(e={})=>{const t=this._rasterFunctionState,i=e.reprocess||"gpu"===t&&!this.canUseWebGLForProcessing||"cpu"===t&&this.canUseWebGLForProcessing;if(i&&(await this._updatingHandles.addPromise(this.layer.updateRasterFunction()),this.updateRasterFunctionParameters()),!this.previousLOD||this.layerView.suspended)return;const s=this._rasterFunctionState,{type:r}=this;return e.refetch||"raster"!==r&&!!i||"cpu"===s||"cpu"===t?this._updatingHandles.addPromise(this.doRefresh()):this._updatingHandles.addPromise(this._redrawImage(e.signal))}))}destroy(){this._updatingHandles.destroy()}get canUseWebGLForProcessing(){return!1}get canUseLocalSymbolizerParams(){return(this.canUseWebGLForProcessing||"rasterVF"===this.type)&&!this.layerView.hasTilingEffects}get useWebGLForProcessing(){return this._get("useWebGLForProcessing")??!0}set useWebGLForProcessing(e){this._set("useWebGLForProcessing",e)}get useProgressiveUpdate(){return this._get("useProgressiveUpdate")??!0}set useProgressiveUpdate(e){if(this._tileStrategy&&this.useProgressiveUpdate!==e){this._tileStrategy.destroy(),this.container.removeAllChildren();const t=this._getCacheSize(e);this._tileStrategy=new I({cachePolicy:"purge",acquireTile:e=>this.acquireTile(e),releaseTile:e=>this.releaseTile(e),cacheSize:t,tileInfoView:this._tileInfoView}),this._set("useProgressiveUpdate",e),this.layerView.requestUpdate()}}update(e){this._fetchQueue.pause(),this._fetchQueue.state=e.state,this._tileStrategy.update(e),this._fetchQueue.resume();const{extent:t,resolution:i,scale:s}=e.state,r=this._tileInfoView.getClosestInfoForScale(s);if(this.layer.raster){if(!this.useProgressiveUpdate||this._needBlockCacheUpdate){const e=this._srcResolutions[r.level],s="toJSON"in t?t:h.fromJSON(t);p(this._blockCacheRegistryUrl,this._blockCacheRegistryId,s,i,e,this.layer.raster.ioConfig.sampling)}this._needBlockCacheUpdate=!1,this.previousLOD?.level!==r.level&&(this.previousLOD=r,null!=this._symbolizerParams&&this.canUseLocalSymbolizerParams&&this._updateSymbolizerParams(),this._tileStrategy.updateCacheSize(0))}}moveEnd(){!this.layerView.hasTilingEffects&&this.useProgressiveUpdate||(this._abortController&&this._abortController.abort(),this._abortController=new AbortController,0===this._fetchQueue.length&&this._redrawImage(this._abortController.signal).then((()=>{this._globalUpdateRequested=!1,this.layerView.requestUpdate()})));const e=this._getCacheSize(this.useProgressiveUpdate);this._tileStrategy.updateCacheSize(e),this.layerView.requestUpdate()}get updating(){return this._globalUpdateRequested||this._updatingHandles?.updating}attach(){const e=R();this._maxIndexedColormapSize=4*(e.maxTextureSize||4096),this._initializeTileInfo(),this._tileInfoView=new b(this.layerView.tileInfo,this.layerView.fullExtent);const t=this._computeFetchConcurrency();this._fetchQueue=new w({tileInfoView:this._tileInfoView,concurrency:t,process:(e,t)=>this._fetchTile(e,t),priority:S.MAPVIEW_FETCH_QUEUE,scheduler:this.scheduler});const i=this._getCacheSize(this.useProgressiveUpdate);this._tileStrategy=new I({cachePolicy:"purge",acquireTile:e=>this.acquireTile(e),releaseTile:e=>this.releaseTile(e),cacheSize:i,tileInfoView:this._tileInfoView}),this._updateBlockCacheRegistry()}detach(){this._tileStrategy.destroy(),this._fetchQueue.clear(),this.container.removeAllChildren(),this._fetchQueue=this._tileStrategy=this._tileInfoView=null,m(this._blockCacheRegistryUrl,this._blockCacheRegistryId),this._blockCacheRegistryUrl=this._blockCacheRegistryId=null}acquireTile(e){const t=this.container.createTile(e);return this._updatingHandles.addPromise(this._enqueueTileFetch(t)),this.layerView.requestUpdate(),this._needBlockCacheUpdate=!0,this._globalUpdateRequested=this.layerView.hasTilingEffects||!this.useProgressiveUpdate,t}releaseTile(e){this._fetchQueue.abort(e.key.id),this.container.removeChild(e),e.once("detach",(()=>{e.destroy(),this.layerView.requestUpdate()})),this.layerView.requestUpdate()}createEmptyTilePixelBlock(e=null){const t=null==e||e.join(",")===this._tileInfoView.tileInfo.size.join(",");if(t&&null!=this._emptyTilePixelBlock)return this._emptyTilePixelBlock;e=e||this._tileInfoView.tileInfo.size;const[i,s]=e,r=new u({width:i,height:s,pixels:[new Uint8Array(i*s)],mask:new Uint8Array(i*s),pixelType:"u8"});return t&&(this._emptyTilePixelBlock=r),r}_getBandIds(){if(!("rasterFunctionChain"in this.container)||!this.container.rasterFunctionChain)return this.layer.bandIds;const{bandIds:e,raster:t}=this.layer,i="rasterFunction"in t?t.rasterFunction.rawInputBandIds:null;return e?.length&&i?.length&&1!==t.rasterInfo.bandCount?e.map((e=>i[Math.min(e,i.length-1)])):"rasterFunction"in t?i:e}updateRasterFunctionParameters(){}_fetchTile(e,t){const i=this._getFetchOptions(e.level,t.signal);return this.fetchTile(e,i)}_getFetchOptions(e,t){const{canUseWebGLForProcessing:i}=this,{layerView:s}=this,{tileInfo:r}=s,a=!r.isWrappable&&null!=_(s.view.spatialReference),o=i&&this.layer.raster.hasUniqueSourceStorageInfo,{layer:l}=this.layerView,n=l.serviceRasterInfo?.storageInfo.isBsqTile?l.bandIds:void 0;return{allowPartialFill:!0,datumTransformation:s.datumTransformation,interpolation:i?"nearest":this.layer.interpolation,registryId:this._blockCacheRegistryId,requestRawData:o,skipRasterFunction:"raster"===this.type&&null!=this.container.rasterFunctionChain,signal:t,srcResolution:this._srcResolutions[e],timeExtent:s.timeExtent,tileInfo:r,bandIds:n,disableWrapAround:a}}_getCacheSize(e){return e?40:0}_initializeTileInfo(){const{layerView:e}=this,t=e.view.spatialReference;if(this._canUseLayerLODs()){const{origin:i,lods:s}=this.layer.tileInfo,r=s.map((({scale:e})=>e)),a=d.create({spatialReference:t,size:P,scales:r,origin:i});return e.set("tileInfo",a),void(this._srcResolutions=s.map((({resolution:e})=>({x:e,y:e}))))}const{scales:i,srcResolutions:r,isCustomTilingScheme:a}=f(this.layer.serviceRasterInfo,t,{tileSize:P,alignGlobalDatasetWithAGOL:!0,limitToSrcResolution:!1}),o=d.create({spatialReference:t,size:P,scales:i}),l=0===o.origin.x;s(e.fullExtent);const{xmin:n,ymax:h}=e.fullExtent;(l||a&&o.origin.x>n)&&(o.origin=new c({x:n,y:h,spatialReference:t})),this._isCustomTilingScheme=a,e.set("tileInfo",o),this._srcResolutions=r??[]}_canUseLayerLODs(){const{layer:e,layerView:t}=this;if("Map"!==e.raster.tileType)return!1;const{lods:i}=e.tileInfo,s=t.view.constraints?.effectiveLODs;return s?.length===i.length&&s.every((({scale:e},t)=>Math.abs(e-i[t].scale)<.001))}_computeFetchConcurrency(){const{blockBoundary:e}=this.layer.serviceRasterInfo.storageInfo,t=e[e.length-1];return(t.maxCol-t.minCol+1)*(t.maxRow-t.minRow+1)>64?2:10}async _enqueueTileFetch(e,t){if(!this._fetchQueue.has(e.key.id)){try{const t=await this._fetchQueue.push(e.key),r=this._getBandIds();let o=!this.useProgressiveUpdate||this.layerView.hasTilingEffects&&!this._globalSymbolizerParams;if(this._globalUpdateRequested&&!this.layerView.moving&&0===this._fetchQueue.length){o=!1;try{await this._redrawImage(this._abortController?.signal)}catch(s){a(s)&&i.getLogger(this).error(s)}this._globalUpdateRequested=!1}this.canUseLocalSymbolizerParams&&null==this._symbolizerParams&&this._updateSymbolizerParams();const l=this._tileInfoView.getTileCoords(C,e.key),n=this._tileInfoView.getTileResolution(e.key);await this.updateTileSource(e,{source:t,symbolizerParams:this._symbolizerParams,globalSymbolizerParams:this._globalSymbolizerParams,suspended:o,bandIds:r,coords:l,resolution:n}),e.once("attach",(()=>this.layerView.requestUpdate())),this.container.addChild(e)}catch(s){a(s)||i.getLogger(this).error(s)}this.layerView.requestUpdate()}}async _redrawImage(e){if(0===this.container.children.length)return;await this.layer.updateRenderer(),this.layerView.hasTilingEffects?await this._updateGlobalSymbolizerParams(e):(this.canUseLocalSymbolizerParams&&this._updateSymbolizerParams(),this._globalSymbolizerParams=null);const t=this.container.children.map((async e=>this.updateTileSymbolizerParameters(e,{local:this._symbolizerParams,global:this._globalSymbolizerParams})));await Promise.allSettled(t),this.container.requestRender()}async _updateGlobalSymbolizerParams(e){const t=this._getFetchOptions(this.previousLOD.level,e),i=await this.layer.fetchPixels(this.layerView.view.extent,this.layerView.view.width,this.layerView.view.height,{...t,interpolation:"nearest",requestRawData:!1,skipRasterFunction:!1});if(!i?.pixelBlock)return;const{resolution:s}=this.previousLOD,{isBsqTile:r}=this.layer.raster.rasterInfo.storageInfo,a=r?null:this._getBandIds(),o=this.layer.symbolizer.generateWebGLParameters({pixelBlock:i.pixelBlock.extractBands(a),isGCS:this.layerView.view.spatialReference.isGeographic,resolution:{x:s,y:s},bandIds:a});!this.canUseWebGLForProcessing&&o&&"stretch"===o.type&&this.layer.renderer&&"raster-stretch"===this.layer.renderer.type&&(o.factor=o.factor.map((e=>255*e)),o.minOutput=Math.round(255*o.minOutput),o.maxOutput=Math.round(255*o.maxOutput)),this._globalSymbolizerParams=o}_updateSymbolizerParams(){const{resolution:e}=this.previousLOD,t=this._getBandIds();this._symbolizerParams=this.layer.symbolizer.generateWebGLParameters({pixelBlock:null,isGCS:this.layerView.view.spatialReference.isGeographic,resolution:{x:e,y:e},bandIds:t})}_updateBlockCacheRegistry(e=!1){const{layer:t,layerView:i}=this,{raster:s}=t,{multidimensionalDefinition:r}=t.normalizeRasterFetchOptions({multidimensionalDefinition:t.multidimensionalDefinition,timeExtent:i.timeExtent}),a=s.rasterInfo.multidimensionalInfo?s.getSliceIndex(r):null,o=s.rasterInfo.storageInfo.isBsqTile&&t.bandIds?.length?t.bandIds:null,l=y(s.rasterId,a,o);if(l!==this._blockCacheRegistryUrl){if(null!=this._blockCacheRegistryUrl&&m(this._blockCacheRegistryUrl,this._blockCacheRegistryId),this._blockCacheRegistryId=g(l,s.rasterInfo),e){const{view:e}=i,t=this._tileInfoView.getClosestInfoForScale(e.scale),r=this._srcResolutions[t.level];p(l,this._blockCacheRegistryId,e.extent,e.resolution,r,s.ioConfig.sampling)}this._blockCacheRegistryUrl=l}}async doRefresh(){if(!this.attached||!this.previousLOD||this.layerView.suspended)return;await this.layer.updateRenderer(),this.canUseLocalSymbolizerParams&&this._updateSymbolizerParams(),this._updateBlockCacheRegistry(!0),this._fetchQueue.reset();const e=[];this._globalUpdateRequested=this.layerView.hasTilingEffects||!this.useProgressiveUpdate,this._tileStrategy.refresh((t=>e.push(this._enqueueTileFetch(t)))),await this._updatingHandles.addPromise(Promise.allSettled(e))}};e([o()],U.prototype,"_globalUpdateRequested",void 0),e([o()],U.prototype,"attached",void 0),e([o()],U.prototype,"canUseWebGLForProcessing",null),e([o()],U.prototype,"canUseLocalSymbolizerParams",null),e([o()],U.prototype,"container",void 0),e([o()],U.prototype,"layer",void 0),e([o()],U.prototype,"layerView",void 0),e([o()],U.prototype,"scheduler",void 0),e([o()],U.prototype,"type",void 0),e([o()],U.prototype,"useWebGLForProcessing",null),e([o()],U.prototype,"useProgressiveUpdate",null),e([o()],U.prototype,"timeExtent",void 0),e([o()],U.prototype,"updating",null),U=e([l("esri.views.2d.layers.imagery.BaseImageryTileSubView2D")],U);export{U as BaseImageryTileSubView2D};
@@ -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 has from"../../../../core/has.js";import{property as t}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as r}from"../../../../core/accessorSupport/decorators/subclass.js";import{isFunctionRaster as s}from"../../../../layers/support/rasterDatasets/datasetUtils.js";import{getBytesPerPixel as i}from"../../../../layers/support/rasterFormats/pixelRangeUtils.js";import{convertGeometryToMask as o}from"../../../../layers/support/rasterFunctions/clipUtils.js";import{RasterTileContainer as n}from"../../engine/imagery/RasterTileContainer.js";import{BaseImageryTileSubView2D as a}from"./BaseImageryTileSubView2D.js";import{canUseMajorityInterpolationOnDataSource as l}from"../support/util.js";let c=class extends a{constructor(){super(...arguments),this.type="raster"}get canUseWebGLForProcessing(){const{loaded:e,symbolizer:t}=this.layer;if(!e||!t)return!1;const r=t.lookup.colormapLut?.indexedColormap,s=r&&r.length>this._maxIndexedColormapSize,o=i(this.layer.serviceRasterInfo);return!(has("ios")&&o>4)&&this.useWebGLForProcessing&&t.canRenderInWebGL&&!s&&!("majority"===this.layer.interpolation&&l(this.layer))}attach(){super.attach(),this.container=new n(this._tileInfoView),this.container.isCustomTilingScheme=this._isCustomTilingScheme,this.updateRasterFunctionParameters()}detach(){super.detach(),this.container.removeAllChildren(),this.container=null}fetchTile(e,t){return this.layer.fetchTile(e.level,e.row,e.col,t)}updateRasterFunctionParameters(){const{raster:e,type:t}=this.layer,{container:r}=this;if("Function"!==e.datasetFormat||"wcs"===t)return r.rasterFunctionChain=null,r.children.forEach((e=>{const{bitmap:t}=e;t&&(t.suspended=!0,t.processed=!1,t.projected&&(t.invalidateTexture(),t.rasterTexture=null))})),void(this._rasterFunctionState="na");const s=this._rasterFunctionState,{rasterFunction:i,primaryRasters:o}=e,n=i.supportsGPU&&(!o||o.rasters.length<=1),a=n?i.flatWebGLFunctionChain:null,{renderer:l}=this.layer,c=!n||!a?.functions.length||"raster-stretch"===l?.type&&l.dynamicRangeAdjustment||!this.canUseWebGLForProcessing;r.rasterFunctionChain=c?null:this._addProjection(a);const p=null==i?"na":r.rasterFunctionChain?"gpu":"cpu",u=s===p||"na"===s&&"cpu"===p&&0===a?.functions?.length;r.children.forEach((e=>{const{bitmap:t}=e;t&&(t.suspended=!u,t.processed=!1,t.processedTexture=null)})),this._rasterFunctionState=p}async updateTileSource(e,t){const r=this._getBandIds(),i=this._getLayerInterpolation(),{canUseWebGLForProcessing:n}=this,{source:a,globalSymbolizerParams:l,suspended:c,coords:p,resolution:u}=t,d=this.layerView.hasTilingEffects?l:t.symbolizerParams,{bitmap:h}=e;if([h.x,h.y]=p,h.resolution=u,null!=a?.pixelBlock){const e={extent:a.extent,pixelBlock:a.pixelBlock,srcPixelSize:a.srcTilePixelSize};if(h.rawPixelData=e,n)h.source=a.pixelBlock,h.isRendereredSource=!1;else{const t=await this.layer.applyRenderer(e,"stretch"===l?.type?l:void 0);h.source=t,h.isRendereredSource=!0}h.symbolizerParameters=n?d:null,h.transformGrid=n?a.transformGrid:null}else{const e=this.createEmptyTilePixelBlock();h.source=e,h.symbolizerParameters=n?d:null,h.transformGrid=null}h.bandIds=n?r:null,h.width=this._tileInfoView.tileInfo.size[0],h.height=this._tileInfoView.tileInfo.size[1],h.interpolation=i,h.suspended=c;const{raster:m}=this.layer;if(s(m)){const t=m.getClippingGeometry(this.layerView.view.spatialReference);if(t){const r=m.getTileExtentFromTileInfo(e.key.level,e.key.row,e.key.col,this._tileInfoView.tileInfo);h.mask=o({srcExtent:r,geometry:t,size:[h.width,h.height]})}}h.invalidateTexture()}async updateTileSymbolizerParameters(e,t){const{local:r,global:s}=t,i=this._getBandIds(),o=this._getLayerInterpolation(),{canUseWebGLForProcessing:n}=this,{bitmap:a}=e,{rawPixelData:l}=a;n||null==l?(a.isRendereredSource&&null!=l&&(a.source=l.pixelBlock),a.isRendereredSource=!1):(a.source=await this.layer.applyRenderer(l,"stretch"===s?.type?s:void 0),a.isRendereredSource=!0),a.symbolizerParameters=n?this.layerView.hasTilingEffects?s:r:null,a.bandIds=n?i:null,a.interpolation=o,a.suspended=!1}_getLayerInterpolation(){const{interpolation:e,renderer:t}=this.layer;if(!t)return e;const r=t.type;return"raster-colormap"===r||"unique-value"===r?"nearest":"raster-stretch"===t.type&&null!=t.colorRamp?"bilinear"===e||"cubic"===e?"bilinear":"nearest":e}_addProjection(e){return e?.functions?.length&&!e.hasFocalFunction&&e.functions.unshift({name:"Reproject",parameters:{targetImageSize:this._tileInfoView.tileInfo.size,requireNNEdge:e.isSourceSingleBand},pixelType:"f32",id:0,isNoopProcess:!1}),e}};e([t()],c.prototype,"canUseWebGLForProcessing",null),e([t()],c.prototype,"container",void 0),e([t()],c.prototype,"layer",void 0),e([t()],c.prototype,"type",void 0),c=e([r("esri.views.2d.layers.imagery.ImageryTileView2D")],c);export{c as default};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import has from"../../../../core/has.js";import{property as t}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as r}from"../../../../core/accessorSupport/decorators/subclass.js";import{isFunctionRaster as s}from"../../../../layers/support/rasterDatasets/datasetUtils.js";import{getBytesPerPixel as i}from"../../../../layers/support/rasterFormats/pixelRangeUtils.js";import{convertGeometryToMask as o}from"../../../../layers/support/rasterFunctions/clipUtils.js";import{RasterTileContainer as n}from"../../engine/imagery/RasterTileContainer.js";import{BaseImageryTileSubView2D as a}from"./BaseImageryTileSubView2D.js";import{canUseMajorityInterpolationOnDataSource as l}from"../support/util.js";let c=class extends a{constructor(){super(...arguments),this.type="raster"}get canUseWebGLForProcessing(){const{loaded:e,symbolizer:t}=this.layer;if(!e||!t)return!1;const r=t.lookup.colormapLut?.indexedColormap,s=r&&r.length>this._maxIndexedColormapSize,o=i(this.layer.serviceRasterInfo);return!(has("ios")&&o>4)&&this.useWebGLForProcessing&&t.canRenderInWebGL&&!s&&!("majority"===this.layer.interpolation&&l(this.layer))}attach(){super.attach(),this.container=new n(this._tileInfoView),this.container.isCustomTilingScheme=this._isCustomTilingScheme,this.updateRasterFunctionParameters()}detach(){super.detach(),this.container.removeAllChildren(),this.container=null}fetchTile(e,t){return this.layer.fetchTile(e.level,e.row,e.col,t)}updateRasterFunctionParameters(){const{raster:e,type:t}=this.layer,{container:r}=this;if("Function"!==e.datasetFormat||"wcs"===t)return r.rasterFunctionChain=null,r.children.forEach((e=>{const{bitmap:t}=e;t&&(t.suspended=!0,t.processed=!1,t.projected&&(t.invalidateTexture(),t.rasterTexture=null))})),void(this._rasterFunctionState="na");const s=this._rasterFunctionState,{rasterFunction:i,primaryRasters:o}=e,n=i.supportsGPU&&(!o||o.rasters.length<=1),a=n?i.flatWebGLFunctionChain:null,{renderer:l}=this.layer,c=!n||!a?.functions.length||"raster-stretch"===l?.type&&l.dynamicRangeAdjustment||!this.canUseWebGLForProcessing;r.rasterFunctionChain=c?null:this._addProjection(a);const p=null==i?"na":r.rasterFunctionChain?"gpu":"cpu",u=s===p||"na"===s&&"cpu"===p&&0===a?.functions?.length;r.children.forEach((e=>{const{bitmap:t}=e;t&&(t.suspended=!u,t.processed=!1,t.processedTexture=null)})),this._rasterFunctionState=p}async updateTileSource(e,t){const r=this._getBandIds(),i=this._getLayerInterpolation(),{canUseWebGLForProcessing:n}=this,{source:a,globalSymbolizerParams:l,suspended:c,coords:p,resolution:u}=t,d=this.layerView.hasTilingEffects?l:t.symbolizerParams,{bitmap:h}=e;if([h.x,h.y]=p,h.resolution=u,null!=a?.pixelBlock){const e={extent:a.extent,pixelBlock:a.pixelBlock,srcPixelSize:a.srcTilePixelSize};if(h.rawPixelData=e,n)h.source=a.pixelBlock,h.isRendereredSource=!1;else{const t=await this.layer.applyRenderer(e,"stretch"===l?.type?l:void 0);h.source=t,h.isRendereredSource=!0}h.symbolizerParameters=n?d:null,h.transformGrid=n?a.transformGrid:null}else{const e=this.createEmptyTilePixelBlock();h.source=e,h.symbolizerParameters=n?d:null,h.transformGrid=null}const{isBsqTile:m}=this.layer.raster.rasterInfo.storageInfo;h.bandIds=n&&!m?r:null,h.width=this._tileInfoView.tileInfo.size[0],h.height=this._tileInfoView.tileInfo.size[1],h.interpolation=i,h.suspended=c;const{raster:y}=this.layer;if(s(y)){const t=y.getClippingGeometry(this.layerView.view.spatialReference);if(t){const r=y.getTileExtentFromTileInfo(e.key.level,e.key.row,e.key.col,this._tileInfoView.tileInfo);h.mask=o({srcExtent:r,geometry:t,size:[h.width,h.height]})}}h.invalidateTexture()}async updateTileSymbolizerParameters(e,t){const{local:r,global:s}=t,i=this._getBandIds(),o=this._getLayerInterpolation(),{canUseWebGLForProcessing:n}=this,{bitmap:a}=e,{rawPixelData:l}=a;n||null==l?(a.isRendereredSource&&null!=l&&(a.source=l.pixelBlock),a.isRendereredSource=!1):(a.source=await this.layer.applyRenderer(l,"stretch"===s?.type?s:void 0),a.isRendereredSource=!0),a.symbolizerParameters=n?this.layerView.hasTilingEffects?s:r:null;const{isBsqTile:c}=this.layer.raster.rasterInfo.storageInfo;a.bandIds=n&&!c?i:null,a.interpolation=o,a.suspended=!1}_getLayerInterpolation(){const{interpolation:e,renderer:t}=this.layer;if(!t)return e;const r=t.type;return"raster-colormap"===r||"unique-value"===r?"nearest":"raster-stretch"===t.type&&null!=t.colorRamp?"bilinear"===e||"cubic"===e?"bilinear":"nearest":e}_addProjection(e){return e?.functions?.length&&!e.hasFocalFunction&&e.functions.unshift({name:"Reproject",parameters:{targetImageSize:this._tileInfoView.tileInfo.size,requireNNEdge:e.isSourceSingleBand},pixelType:"f32",id:0,isNoopProcess:!1}),e}};e([t()],c.prototype,"canUseWebGLForProcessing",null),e([t()],c.prototype,"container",void 0),e([t()],c.prototype,"layer",void 0),e([t()],c.prototype,"type",void 0),c=e([r("esri.views.2d.layers.imagery.ImageryTileView2D")],c);export{c 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{c as e,d as r,f as n,j as t,E as o}from"../../../../chunks/vec32.js";import{create as i}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{wrap as c}from"../../../../geometry/support/ray.js";import{i as s,l as a}from"../../../../chunks/sphere.js";import{defaultConstraintOptions as f,interactionDirectionTowardsConstraintMinimization as m,adjustRangeForInteraction as u}from"./common.js";import{InteractionType as p}from"./InteractionType.js";function d(e,r,n=f){if(!e.state.isLocal)return 0;const t=e.state.constraints.distance;if(!e.pointsOfInterest.surfaceOrigin.renderLocation||t===1/0)return 0;x.min=0,x.max=t,l(e,n,x);const o=O(e,r),i=x.max-o;return i>=-1e-6?0:i}function y(t,o,i=f){const u=d(t,o,i);if(0===u)return!1;const p=t.pointsOfInterest.surfaceOrigin;if(!p.renderLocation)return!1;const y=O(t,o)+u,l=e(L,o.eye),x=m(o,i.interactionDirection,j(o,p.renderLocation,h),I);if(!s(a(p.renderLocation,y),c(o.eye,x),C))return!1;o.eye=C;const N=r(g,o.eye,l);o.center=n(C,o.center,N);const k=t.renderCoordsHelper.getAltitude(o.center),v=t.renderCoordsHelper.intersectInfiniteManifold(o.ray,k,C);return null!=v&&(o.center=v),!0}function l(e,r,n){const t=r.interactionType;if(t===p.NONE)return;const{min:o,max:i}=n,{interactionStartCamera:c,interactionFactor:s}=r;if(!c)return;const a=t===p.ZOOM||t===p.PAN,f=d(e,c),m=0===f?0:O(e,c);n.min=o,n.max=i;u(f,m,a,s,.05*m,n)}function O(e,r){const n=e.pointsOfInterest.surfaceOrigin;return n.renderLocation?t(r.eye,n.renderLocation):0}function j(e,r,n){return o(n,e.eye,r)}const x={min:0,max:0},L=i(),g=i(),I=i(),h=i(),C=i();export{y as applyDistanceConstraint,d as getDistanceConstraintError};
5
+ import{c as e,d as r,f as n,j as t,E as o}from"../../../../chunks/vec32.js";import{create as i}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{wrap as c}from"../../../../geometry/support/ray.js";import{i as s,h as a}from"../../../../chunks/sphere.js";import{defaultConstraintOptions as f,interactionDirectionTowardsConstraintMinimization as m,adjustRangeForInteraction as u}from"./common.js";import{InteractionType as p}from"./InteractionType.js";function d(e,r,n=f){if(!e.state.isLocal)return 0;const t=e.state.constraints.distance;if(!e.pointsOfInterest.surfaceOrigin.renderLocation||t===1/0)return 0;x.min=0,x.max=t,l(e,n,x);const o=O(e,r),i=x.max-o;return i>=-1e-6?0:i}function y(t,o,i=f){const u=d(t,o,i);if(0===u)return!1;const p=t.pointsOfInterest.surfaceOrigin;if(!p.renderLocation)return!1;const y=O(t,o)+u,l=e(L,o.eye),x=m(o,i.interactionDirection,j(o,p.renderLocation,h),I);if(!s(a(p.renderLocation,y),c(o.eye,x),C))return!1;o.eye=C;const N=r(g,o.eye,l);o.center=n(C,o.center,N);const k=t.renderCoordsHelper.getAltitude(o.center),v=t.renderCoordsHelper.intersectInfiniteManifold(o.ray,k,C);return null!=v&&(o.center=v),!0}function l(e,r,n){const t=r.interactionType;if(t===p.NONE)return;const{min:o,max:i}=n,{interactionStartCamera:c,interactionFactor:s}=r;if(!c)return;const a=t===p.ZOOM||t===p.PAN,f=d(e,c),m=0===f?0:O(e,c);n.min=o,n.max=i;u(f,m,a,s,.05*m,n)}function O(e,r){const n=e.pointsOfInterest.surfaceOrigin;return n.renderLocation?t(r.eye,n.renderLocation):0}function j(e,r,n){return o(n,e.eye,r)}const x={min:0,max:0},L=i(),g=i(),I=i(),h=i(),C=i();export{y as applyDistanceConstraint,d as getDistanceConstraintError};
@@ -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 e}from"../../../../core/compilerUtils.js";import{acosClamped as t,clamp as r,asinClamped as n,deg2rad as i}from"../../../../core/mathUtils.js";import{fromRotation as a}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{d as o,t as c,g as u,f as l,k as m,j as d,e as f,n as p,l as M}from"../../../../chunks/vec32.js";import{create as h}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as y}from"../../../../geometry/ellipsoidUtils.js";import{j as C,b as T,t as I}from"../../../../chunks/sphere.js";import{defaultConstraintOptions as O,hasConstraintType as A,adjustRangeForInteraction as x}from"./common.js";import{ConstraintTypes as S}from"./ConstraintTypes.js";import{InteractionType as j}from"./InteractionType.js";import{TiltMode as v}from"./TiltMode.js";import{viewAngle as R}from"../../state/utils/viewUtils.js";function w(t,r,n,i=!0){W.eyeCenterDistance=0,W.requiresTwoSteps=!1;const s=U(t,r,n,O,W);if(0===s)return!1;switch(a(_,-s,r.viewRight),n.tiltMode){case v.LOOK_AROUND:c(K,r.viewForward,_),u(K,K,W.eyeCenterDistance),r.center=l(z,r.eye,K);break;case v.TUMBLE:o(K,r.center,r.eye),c(K,K,_),r.eye=o(z,r.center,K);break;default:e(n.tiltMode)}return r.up=c(z,r.up,_),!W.requiresTwoSteps||!i||w(t,r,n,!1)}function U(e,t,r,n=O,i){if(!e.state.constraints.tilt)return 0;const a=Math.min(t.relativeElevation*J,t.distance),s=e.state.constraints.tilt(a,Q);return N(e,r,s),n.interactionType===j.TUMBLE&&A(n.selection,S.ALTITUDE)&&B(e,n.interactionStartCamera,s),r.tiltMode===v.LOOK_AROUND||n.tiltMode===v.LOOK_AROUND?P(e,t,s,i):D(e,t,s)}function D(e,t,n){const i=R(e.renderCoordsHelper,t.center,t.eye),a=i-r(i,n.min,n.max);return g(a)?a:0}function P(e,t,r,n){switch(n&&(n.requiresTwoSteps=!1),e.viewingMode){case"global":return E(e,t,r,n);case"local":return b(e,t,r,n)}}function b(e,t,n,i){const a=R(e.renderCoordsHelper,t.center,t.eye),s=r(a,n.min,n.max),o=a-s;if(!g(o))return 0;if(i){const r=Math.abs(e.pointsOfInterest.centerOnSurfaceFrequent.estimatedSurfaceAltitude),n=e.renderCoordsHelper.getAltitude(t.eye)-r,a=Math.max(Math.cos(s),1e-4);Math.abs(a)>1e-4?i.eyeCenterDistance=n/a:i.eyeCenterDistance=t.distance}return o}function E(e,t,n,i){const a=L(e,t,V),s=r(a.tiltAtCenter,n.min,n.max);if(!g(a.tiltAtCenter-s))return 0;let o,c;return a.centerIsOnSurface?(o=q(a),c=k(a,o)):(o=a.constraints.clampTilt(a.distance,a.tiltAtCenter),i&&o<Math.PI/2&&(i.requiresTwoSteps=!0,o=Math.PI/2-1e-5),c=F(a,o)),i&&(i.eyeCenterDistance=H(a,o)),c}function L(e,r,n){const i=e.pointsOfInterest.centerOnSurfaceFrequent.estimatedSurfaceAltitude,a=i+y(e.spatialReference).radius,s=e.renderCoordsHelper.intersectManifold(r.ray,i,z);return n.distance=Math.min(r.relativeElevation*J,r.distance),n.centerIsOnSurface=!1,null!=s?(n.distance=Math.min(r.relativeElevation*J,d(r.eye,s)),n.tiltAtCenter=R(e.renderCoordsHelper,s,r.eye),n.centerIsOnSurface=!0):e.state.isLocal?n.tiltAtCenter=R(e.renderCoordsHelper,r.center,r.eye):(C(T(I,a),r.ray,z),n.distance=Math.min(r.relativeElevation*J,d(r.eye,z)),n.tiltAtCenter=t(-f(r.viewForward,p(z,z)))),n.radius=a,n.eyeRadius=M(r.eye),n.constraints=e.state.constraints,n}function g(e){return Math.abs(e)>1e-9}function q(e){const{constraints:t,distance:r,tiltAtCenter:n}=e;let i=n,a=t.clampTilt(r,n);const s=H(e,a);if(t.clampTilt(s,n)===a)return a;let o=0;for(;o<10&&g(a-i);){const r=(i+a)/2,n=H(e,r);g(t.clampTilt(n,r)-r)?i=r:a=r,o++}return a}function H(e,t){if(!e.centerIsOnSurface)return e.distance;const i=Math.PI-r(t,0,Math.PI),a=n(e.radius/e.eyeRadius*Math.sin(i)),s=Math.PI-i-a,o=Math.sin(s)/Math.sin(i);if(e.eyeRadius<e.radius&&o>1){const t=Math.PI-a,r=Math.PI-i-t;return Math.sin(r)/Math.sin(i)*e.eyeRadius}return o*e.eyeRadius}function k(e,t){const r=n(e.radius/e.eyeRadius*Math.sin(e.tiltAtCenter)),i=n(e.radius/e.eyeRadius*Math.sin(t));return e.eyeRadius>e.radius?r-i:i-r}function F(e,t){return e.tiltAtCenter-Math.PI/2-(t-Math.PI/2)}function N(e,t,r){if(t.interactionType===j.NONE)return;const{interactionStartCamera:n,interactionFactor:i}=t;if(!n)return;const{min:a,max:s}=r,o=U(e,n,O,t),c=0===o?0:R(e.renderCoordsHelper,n.center,n.eye);r.min=a,r.max=s,t.interactionType===j.TUMBLE?(A(t.selection,S.ALTITUDE)&&B(e,n,r),x(o,c,!0,i,G,r)):x(o,c,!1,i,G,r)}function B(e,r,n){const i=e.state.constraints;if(e.state.isLocal||!i.altitude||!r)return;const a=m(r.center),s=Math.sqrt(a),o=r.distance,c=y(e.spatialReference).radius,u=i.altitude.min+c,l=i.altitude.max+c,d=(u*u-o*o-a)/(-2*s*o),f=(l*l-o*o-a)/(-2*s*o);n.min=Math.max(n.min,Math.min(Math.PI-t(f),n.max)),n.max=Math.min(n.max,Math.PI-t(d))}const K=h(),_=s(),z=h(),G=i(5),J=30,Q={min:0,max:0},V={constraints:null,radius:0,eyeRadius:0,centerIsOnSurface:!0,distance:0,tiltAtCenter:0},W={eyeCenterDistance:0,requiresTwoSteps:!1};export{w as applyTiltConstraint,U as getTiltConstraintError};
5
+ import{neverReached as e}from"../../../../core/compilerUtils.js";import{acosClamped as t,clamp as r,asinClamped as n,deg2rad as i}from"../../../../core/mathUtils.js";import{fromRotation as a}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{d as o,t as c,g as u,f as l,k as m,j as d,e as f,n as p,l as M}from"../../../../chunks/vec32.js";import{create as h}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as y}from"../../../../geometry/ellipsoidUtils.js";import{m as C,b as T,t as I}from"../../../../chunks/sphere.js";import{defaultConstraintOptions as O,hasConstraintType as A,adjustRangeForInteraction as x}from"./common.js";import{ConstraintTypes as S}from"./ConstraintTypes.js";import{InteractionType as v}from"./InteractionType.js";import{TiltMode as R}from"./TiltMode.js";import{viewAngle as j}from"../../state/utils/viewUtils.js";function w(t,r,n,i=!0){W.eyeCenterDistance=0,W.requiresTwoSteps=!1;const s=U(t,r,n,O,W);if(0===s)return!1;switch(a(_,-s,r.viewRight),n.tiltMode){case R.LOOK_AROUND:c(K,r.viewForward,_),u(K,K,W.eyeCenterDistance),r.center=l(z,r.eye,K);break;case R.TUMBLE:o(K,r.center,r.eye),c(K,K,_),r.eye=o(z,r.center,K);break;default:e(n.tiltMode)}return r.up=c(z,r.up,_),!W.requiresTwoSteps||!i||w(t,r,n,!1)}function U(e,t,r,n=O,i){if(!e.state.constraints.tilt)return 0;const a=Math.min(t.relativeElevation*J,t.distance),s=e.state.constraints.tilt(a,Q);return N(e,r,s),n.interactionType===v.TUMBLE&&A(n.selection,S.ALTITUDE)&&B(e,n.interactionStartCamera,s),r.tiltMode===R.LOOK_AROUND||n.tiltMode===R.LOOK_AROUND?P(e,t,s,i):D(e,t,s)}function D(e,t,n){const i=j(e.renderCoordsHelper,t.center,t.eye),a=i-r(i,n.min,n.max);return g(a)?a:0}function P(e,t,r,n){switch(n&&(n.requiresTwoSteps=!1),e.viewingMode){case"global":return E(e,t,r,n);case"local":return b(e,t,r,n)}}function b(e,t,n,i){const a=j(e.renderCoordsHelper,t.center,t.eye),s=r(a,n.min,n.max),o=a-s;if(!g(o))return 0;if(i){const r=Math.abs(e.pointsOfInterest.centerOnSurfaceFrequent.estimatedSurfaceAltitude),n=e.renderCoordsHelper.getAltitude(t.eye)-r,a=Math.max(Math.cos(s),1e-4);Math.abs(a)>1e-4?i.eyeCenterDistance=n/a:i.eyeCenterDistance=t.distance}return o}function E(e,t,n,i){const a=L(e,t,V),s=r(a.tiltAtCenter,n.min,n.max);if(!g(a.tiltAtCenter-s))return 0;let o,c;return a.centerIsOnSurface?(o=q(a),c=k(a,o)):(o=a.constraints.clampTilt(a.distance,a.tiltAtCenter),i&&o<Math.PI/2&&(i.requiresTwoSteps=!0,o=Math.PI/2-1e-5),c=F(a,o)),i&&(i.eyeCenterDistance=H(a,o)),c}function L(e,r,n){const i=e.pointsOfInterest.centerOnSurfaceFrequent.estimatedSurfaceAltitude,a=i+y(e.spatialReference).radius,s=e.renderCoordsHelper.intersectManifold(r.ray,i,z);return n.distance=Math.min(r.relativeElevation*J,r.distance),n.centerIsOnSurface=!1,null!=s?(n.distance=Math.min(r.relativeElevation*J,d(r.eye,s)),n.tiltAtCenter=j(e.renderCoordsHelper,s,r.eye),n.centerIsOnSurface=!0):e.state.isLocal?n.tiltAtCenter=j(e.renderCoordsHelper,r.center,r.eye):(C(T(I,a),r.ray,z),n.distance=Math.min(r.relativeElevation*J,d(r.eye,z)),n.tiltAtCenter=t(-f(r.viewForward,p(z,z)))),n.radius=a,n.eyeRadius=M(r.eye),n.constraints=e.state.constraints,n}function g(e){return Math.abs(e)>1e-9}function q(e){const{constraints:t,distance:r,tiltAtCenter:n}=e;let i=n,a=t.clampTilt(r,n);const s=H(e,a);if(t.clampTilt(s,n)===a)return a;let o=0;for(;o<10&&g(a-i);){const r=(i+a)/2,n=H(e,r);g(t.clampTilt(n,r)-r)?i=r:a=r,o++}return a}function H(e,t){if(!e.centerIsOnSurface)return e.distance;const i=Math.PI-r(t,0,Math.PI),a=n(e.radius/e.eyeRadius*Math.sin(i)),s=Math.PI-i-a,o=Math.sin(s)/Math.sin(i);if(e.eyeRadius<e.radius&&o>1){const t=Math.PI-a,r=Math.PI-i-t;return Math.sin(r)/Math.sin(i)*e.eyeRadius}return o*e.eyeRadius}function k(e,t){const r=n(e.radius/e.eyeRadius*Math.sin(e.tiltAtCenter)),i=n(e.radius/e.eyeRadius*Math.sin(t));return e.eyeRadius>e.radius?r-i:i-r}function F(e,t){return e.tiltAtCenter-Math.PI/2-(t-Math.PI/2)}function N(e,t,r){if(t.interactionType===v.NONE)return;const{interactionStartCamera:n,interactionFactor:i}=t;if(!n)return;const{min:a,max:s}=r,o=U(e,n,O,t),c=0===o?0:j(e.renderCoordsHelper,n.center,n.eye);r.min=a,r.max=s,t.interactionType===v.TUMBLE?(A(t.selection,S.ALTITUDE)&&B(e,n,r),x(o,c,!0,i,G,r)):x(o,c,!1,i,G,r)}function B(e,r,n){const i=e.state.constraints;if(e.state.isLocal||!i.altitude||!r)return;const a=m(r.center),s=Math.sqrt(a),o=r.distance,c=y(e.spatialReference).radius,u=i.altitude.min+c,l=i.altitude.max+c,d=(u*u-o*o-a)/(-2*s*o),f=(l*l-o*o-a)/(-2*s*o);n.min=Math.max(n.min,Math.min(Math.PI-t(f),n.max)),n.max=Math.min(n.max,Math.PI-t(d))}const K=h(),_=s(),z=h(),G=i(5),J=30,Q={min:0,max:0},V={constraints:null,radius:0,eyeRadius:0,centerIsOnSurface:!0,distance:0,tiltAtCenter:0},W={eyeCenterDistance:0,requiresTwoSteps:!1};export{w as applyTiltConstraint,U as getTiltConstraintError};
@@ -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 i}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import{lerp as e}from"../../../../core/mathUtils.js";import{destroyMaybe as s}from"../../../../core/maybe.js";import{property as r}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as c}from"../../../../core/accessorSupport/decorators/subclass.js";import{transpose as o}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{t as l,g as h,i as u,c as d}from"../../../../chunks/vec32.js";import{ZEROS as p,create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{s as _,t as m,d as g}from"../../../../chunks/vec42.js";import{create as y}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{UpdatingHandles as v}from"../../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as b}from"../../../../geometry/ellipsoidUtils.js";import{create as O,empty as w,copy as I,offset as D,width as C,height as j,expand as G}from"../../../../geometry/support/aaBoundingRect.js";import{e as k,d as S,a as A}from"../../../../chunks/boundedPlane.js";import{create as Q}from"../../../../geometry/support/ray.js";import{a as N,c as P,h as T,i as x}from"../../../../chunks/sphere.js";import{DeconflictAABR as E}from"./DeconflictAABR.js";import{prepare as V,drawPoly as L}from"./deconflictorDebug.js";import{VisibilityGroup as U,VisibilityFlag as F}from"./enums.js";import R from"../../webgl/RenderCamera.js";import{GPUPointOcclusionQuery as H}from"../../webgl-engine/lib/GPUPointOcclusionQuery.js";import{applyPrecomputedScaleFactor as B}from"../../webgl-engine/lib/screenSizePerspectiveUtils.js";import{VertexAttribute as M}from"../../webgl-engine/lib/VertexAttribute.js";import{HUDMaterial as W}from"../../webgl-engine/materials/HUDMaterial.js";import{ScaleInfo as z}from"../../webgl-engine/materials/ScaleInfo.js";import{Yield as Y}from"../../../support/Yield.js";const q=f(),J=f(),K=y(),X=y(),Z=f(),$=n(),ii=P(),ti=Q(),ei=f(),si=O();class ri{constructor(i){this.id=i,this.aabr=O(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.culled=!1,this.visible=!1,this.priority=0}}function ci(i,t){const e=0!==i.distanceToOccluder&&i.distance>i.distanceToOccluder,s=0!==t.distanceToOccluder&&t.distance>t.distanceToOccluder;return e!==s?+e-+s:i.priority!==t.priority?t.priority-i.priority:i.distance!==t.distance?i.distance-t.distance:i.visible!==t.visible?+t.visible-+i.visible:i.id-t.id}class oi{constructor(i,t){this.graphics3DGraphic=i,this.slicePlaneEnabled=t,this._info=null,this._labelInfo=null}ensureInfo(i){let t=this.getInfo(i);return t||(t=new ri(this.graphics3DGraphic.graphic.uid),this._setInfo(i,t)),t}getInfo(i){return i===U.LABEL?this._labelInfo:this._info}removeInfo(i){this._setInfo(i,null)}_setInfo(i,t){i===U.LABEL?this._labelInfo=t:this._info=t}}var ni;!function(i){i[i.Idle=0]="Idle",i[i.CheckOcclusion=1]="CheckOcclusion",i[i.WaitOcclusion=2]="WaitOcclusion",i[i.Collect=3]="Collect",i[i.Deconflict=4]="Deconflict",i[i.NumStates=5]="NumStates"}(ni||(ni={}));class ai{constructor(){this.camera=new R,this.slicePlane=S(),this.slicePlaneEnabled=!1}copyFrom(i){this.camera.copyFrom(i.camera),A(i.slicePlane,this.slicePlane),this.slicePlaneEnabled=i.slicePlaneEnabled}}let li=class extends t{get dirty(){return this._dirty}get state(){return this._state}constructor(i){super(i),this._dirty=!1,this._viewState=new ai,this._state=ni.Idle,this._checkOcclusion=new Map,this._active=new Map,this._checkOcclusionIterator=null,this._activeIterator=null,this._occlusionQueryUids=new Array,this._updatingHandles=new v,this._deconflictor=new E(((i,t)=>{i.visible=t,this._setGraphicVisibility(this._active.get(i.id),t)}),((i,t)=>i.id!==t.id),ci),this._baseOccludedVisibility=10,this._altitudeFactor=2,this._minAltitudeDifference=100}initialize(){this._updatingHandles.add((()=>(this.view?.map?.ground?.opacity??0)>0),(()=>this.setDirty())),this._updatingHandles.add((()=>this.view.ready),(()=>this._occlusionQuery=null))}destroy(){this._occlusionQuery=null,this._updatingHandles.destroy(),this._deconflictor.destroy(),this._checkOcclusion.clear(),this._active.clear()}setDirty(){!this._dirty&&(this._active.size>0||this._checkOcclusion.size>0)&&(this._dirty=!0,this.notifyChange("updating"))}setPriority(i,t){const e=this._active.get(i.graphic.uid)?.getInfo(this.visibilityGroup);e&&(e.priority=t)}get updating(){return this._state!==ni.Idle||this._dirty||this._updatingHandles.updating}get updatingProgress(){if(!this.updating)return 1;const i=this._state/ni.NumStates;return this._dirty?.5*i:i}get running(){return this.view.ready&&null!=this.view.state&&this.updating}runTask(i){switch(this._state){case ni.Idle:this._startUpdate(),i.madeProgress();case ni.CheckOcclusion:if(this._state=ni.CheckOcclusion,!this._processCheckOcclusion(i))return;case ni.WaitOcclusion:if(this._state=ni.WaitOcclusion,this._occlusionQuery&&!this._occlusionQuery.done)return Y;this._readOcclusionQueryResult(),i.madeProgress();case ni.Collect:if(this._state=ni.Collect,!this._collectActiveGraphics(i))return;case ni.Deconflict:if(this._state=ni.Deconflict,this._deconflictor.run(i),!this._deconflictor.done)return;default:this._state=ni.Idle,this.notifyChange("updating")}}setGraphicsActive(i,t){t?i.forEach((i=>this.addToActiveGraphics(i))):i.forEach((i=>this.removeFromActiveGraphics(i)))}layerSupportsDeconfliction(i){if(null==i||"object3d"!==i.type)return!1;const t=i.stageObject;if(1!==(t?.geometries.length??0))return!1;const e=t?.geometries[0],s=e?.material;return s instanceof W}_startUpdate(){V(this.view),this._dirty=!1,this._viewState.copyFrom(this.viewState);const{fullWidth:i,fullHeight:t}=this._viewState.camera;this._deconflictor.reset(i,t),this._resetIterators(),this._occlusionQueryUids.length=0,this._checkOcclusion.size||(this._occlusionQuery=s(this._occlusionQuery))}addToActiveGraphics(i){i.ensureInfo(this.visibilityGroup),this._active.set(i.graphics3DGraphic.graphic.uid,i),this.setDirty()}removeFromActiveGraphics(i){hi(i,this.visibilityGroup),i.removeInfo(this.visibilityGroup),this._active.delete(i.graphics3DGraphic.graphic.uid),this.setDirty()}addToCheckOcclusion(i){this._checkOcclusion.set(i.graphics3DGraphic.graphic.uid,i),this.setDirty()}removeFromCheckOcclusion(i){this._checkOcclusion.delete(i.graphics3DGraphic.graphic.uid)}_processCheckOcclusion(i){if(0===this._checkOcclusion.size)return!0;const t=this._ensureCheckOcclusionIterator(),e=this._viewState.camera,r=o($,e.viewInverseTransposeMatrix),c=this.view.map.ground.opacity>0,n="global"===this.view.viewingMode&&c&&e.relativeElevation>0?ii:null;let a=0;null!=n&&(l(N(n),p,e.viewMatrix),n[3]=b(this.view.spatialReference).radius,a=T(n,p));const h=O();for(;;){if(i.done)return!1;i.madeProgress();const s=t.next();if(!0===s.done)break;const c=s.value,o=c.graphics3DGraphic;if(o.destroyed)continue;if(!o.isVisible(U.GRAPHIC,F.DECONFLICTION))continue;const u=fi(o,this.visibilityGroup);let d=null,p=!0;for(const i of u){if(!this.layerSupportsDeconfliction(i))continue;d=_i,this._projectHudLayer(i,e,d),w(h);const t=i.stageObject.geometries[0].material;if(this._expandBoundingRect(h,e,i,t,d),d.isOutsideScreen){p=!1;break}if(this._isCulledBySlice(c,d.positionView)){p=!1;break}if(null!=n&&pi(d,n,a)){p=!1;break}l(J,d.positionView,r),d.altitude=this.view.renderCoordsHelper.getAltitude(J);const s=c.ensureInfo(this.visibilityGroup);if(s.altitude=d.altitude,s.distance=d.distance,s.distanceToOccluder=d.distanceToOccluder,s.culled=!1,I(s.aabr,h),t.parameters.occlusionTest)break;this._ensureOcclusionQuery().addPosition(J)===this._occlusionQueryUids.length&&this._occlusionQueryUids.push(o.graphic.uid);break}if(this._active.has(o.graphic.uid)&&(!p||!d)){const i=c.ensureInfo(this.visibilityGroup);i.visible=!d,i.culled=!0}}return this._checkOcclusionIterator=null,this._occlusionQueryUids.length||(this._occlusionQuery=s(this._occlusionQuery)),this._occlusionQuery?.start(),!0}_readOcclusionQueryResult(){if(!this._occlusionQuery||!this._occlusionQueryUids.length)return;const i=this._viewState.camera,t=this.view.renderCoordsHelper.getAltitude(i.eye);for(let e=0;e<this._occlusionQueryUids.length;e++){const i=this._occlusionQueryUids[e],s=this._checkOcclusion.get(i);if(!s)continue;const r=this._occlusionQuery.getOcclusion(e)??-1,c=s.getInfo(this.visibilityGroup);c&&(c.distanceToOccluder=r>0?c.distance-r:0);const o=r<=0||this._occludedVisibility(c?.distanceToOccluder??0,c?.distance??r,c?.altitude??0,t);this._active.has(i)?c&&(c.culled=!o,c.visible=o):this._setGraphicVisibility(s,o)}this._occlusionQueryUids.length=0}_collectActiveGraphics(i){const t=this._ensureActiveGraphicsIterator(),e=this.visibilityGroup===U.LABEL;for(;!i.done;){i.madeProgress();const s=t.next();if(!0===s.done)return this._activeIterator=null,!0;const r=s.value,c=r.getInfo(this.visibilityGroup);if(!c)continue;!(!e||r.graphics3DGraphic.isVisible())||c.culled?(L(c.aabr,!1,!0),this._setGraphicVisibility(r,c.visible)):this._deconflictor.add(c)}return!1}_occludedVisibility(i,t,e,s){const r=Math.max(this._minAltitudeDifference,Math.abs(e-s))-this._minAltitudeDifference;return 0===i||t-i<=this._baseOccludedVisibility+this._altitudeFactor*r}_resetIterators(){this._checkOcclusionIterator=null,this._activeIterator=null}_ensureCheckOcclusionIterator(){return this._checkOcclusionIterator??=this._checkOcclusion.values(),this._checkOcclusionIterator}_ensureActiveGraphicsIterator(){return this._activeIterator??=this._active.values(),this._activeIterator}_ensureOcclusionQuery(){return this._occlusionQuery??=new H({view:this.view}),this._occlusionQueryUids.length||this._occlusionQuery.init(this._checkOcclusion.size,this._viewState.camera.eye),this._occlusionQuery}_projectHudLayer(i,t,e){const s=i.stageObject,r=s.geometries[0],c=r.material,o=N(s.boundingVolumeWorldSpace.bounds);l(q,o,t.viewMatrix);const n=r.attributes,a=n.get(M.NORMAL).data,d=n.get(M.CENTEROFFSETANDDISTANCE).data;c.applyShaderOffsetsView(q,a,s.transformation,d,t,e.scaleInfo,q),_(K,q[0],q[1],q[2],1),m(X,K,t.projectionMatrix),h(e.positionNDC,X,1/X[3]),c.applyShaderOffsetsNDC(e.positionNDC,d,t,e.positionNDC,Z),e.distanceWithoutPolygonOffset=t.depthNDCToWorld(Z[2]),e.distance=Z[2]===e.positionNDC[2]?e.distanceWithoutPolygonOffset:t.depthNDCToWorld(e.positionNDC[2]),_(X,e.positionNDC[0],e.positionNDC[1],e.positionNDC[2],1),m(K,X,t.inverseProjectionMatrix),g(K,K,1/K[3]),u(e.positionView,q[0],q[1],q[2])}_isCulledBySlice(i,t){return i.slicePlaneEnabled&&this._viewState.slicePlaneEnabled&&k(this._viewState.slicePlane,t)}_expandBoundingRect(i,t,s,r,{positionNDC:c,scaleInfo:o}){const n=s.getScreenSize(ui);B(n,o.factor,n),n[0]*=t.pixelRatio,n[1]*=t.pixelRatio;const a=D(r.calculateRelativeScreenBounds(n,o.factorAlignment.scale*t.pixelRatio,si),e(0,t.fullWidth,.5+.5*c[0]),e(0,t.fullHeight,.5+.5*c[1])),l=this.marginFactor;if(0!==l){const i=l*Math.min(C(a),j(a));a[0]-=i,a[1]-=i,a[2]+=i,a[3]+=i}G(i,a,i)}_setGraphicVisibility(i,t){const e=i?.graphics3DGraphic;e&&!e.destroyed&&(e.setVisibilityFlag(this.visibilityGroup,F.DECONFLICTION,t),this.visibilityGroup===U.LABEL&&this.view.labeler.setLabelGraphicVisibility(e,t))}};function hi(i,t){const e=i.graphics3DGraphic;e.destroyed||e.setVisibilityFlag(t,F.DECONFLICTION,!0)}i([r({constructOnly:!0})],li.prototype,"view",void 0),i([r({type:Boolean,readOnly:!0})],li.prototype,"updating",null),i([r({readOnly:!0})],li.prototype,"_updatingHandles",void 0),li=i([c("esri.views.3d.layers.graphics.Deconflictor")],li);const ui=a();class di{constructor(){this.positionView=f(),this.positionNDC=f(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.distanceWithoutPolygonOffset=0,this.scaleInfo=new z}get isOutsideScreen(){const i=this.positionNDC;return i[0]<-1||i[1]<-1||i[2]<-1||i[0]>=1||i[1]>=1||i[2]>=1}}function pi(i,t,e){return d(ti.direction,i.positionView),u(ti.origin,0,0,0),!!x(t,ti,ei)&&i.distanceWithoutPolygonOffset>e}function fi(i,t){return t===U.LABEL?i.labelLayers:i.layers}const _i=new di;export{li as Deconflictor,oi as DeconflictorGraphic,ai as DeconflictorViewState,ni as State};
5
+ import{_ as i}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import{lerp as e}from"../../../../core/mathUtils.js";import{destroyMaybe as s}from"../../../../core/maybe.js";import{property as r}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as c}from"../../../../core/accessorSupport/decorators/subclass.js";import{transpose as o}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{t as l,g as h,i as u,c as d}from"../../../../chunks/vec32.js";import{ZEROS as p,create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{s as _,t as m,d as g}from"../../../../chunks/vec42.js";import{create as y}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{UpdatingHandles as v}from"../../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as b}from"../../../../geometry/ellipsoidUtils.js";import{create as O,empty as w,copy as I,offset as D,width as C,height as j,expand as G}from"../../../../geometry/support/aaBoundingRect.js";import{e as k,d as S,a as A}from"../../../../chunks/boundedPlane.js";import{create as Q}from"../../../../geometry/support/ray.js";import{a as N,c as P,l as T,i as x}from"../../../../chunks/sphere.js";import{DeconflictAABR as E}from"./DeconflictAABR.js";import{prepare as V,drawPoly as L}from"./deconflictorDebug.js";import{VisibilityGroup as U,VisibilityFlag as F}from"./enums.js";import R from"../../webgl/RenderCamera.js";import{GPUPointOcclusionQuery as H}from"../../webgl-engine/lib/GPUPointOcclusionQuery.js";import{applyPrecomputedScaleFactor as B}from"../../webgl-engine/lib/screenSizePerspectiveUtils.js";import{VertexAttribute as M}from"../../webgl-engine/lib/VertexAttribute.js";import{HUDMaterial as W}from"../../webgl-engine/materials/HUDMaterial.js";import{ScaleInfo as z}from"../../webgl-engine/materials/ScaleInfo.js";import{Yield as Y}from"../../../support/Yield.js";const q=f(),J=f(),K=y(),X=y(),Z=f(),$=n(),ii=P(),ti=Q(),ei=f(),si=O();class ri{constructor(i){this.id=i,this.aabr=O(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.culled=!1,this.visible=!1,this.priority=0}}function ci(i,t){const e=0!==i.distanceToOccluder&&i.distance>i.distanceToOccluder,s=0!==t.distanceToOccluder&&t.distance>t.distanceToOccluder;return e!==s?+e-+s:i.priority!==t.priority?t.priority-i.priority:i.distance!==t.distance?i.distance-t.distance:i.visible!==t.visible?+t.visible-+i.visible:i.id-t.id}class oi{constructor(i,t){this.graphics3DGraphic=i,this.slicePlaneEnabled=t,this._info=null,this._labelInfo=null}ensureInfo(i){let t=this.getInfo(i);return t||(t=new ri(this.graphics3DGraphic.graphic.uid),this._setInfo(i,t)),t}getInfo(i){return i===U.LABEL?this._labelInfo:this._info}removeInfo(i){this._setInfo(i,null)}_setInfo(i,t){i===U.LABEL?this._labelInfo=t:this._info=t}}var ni;!function(i){i[i.Idle=0]="Idle",i[i.CheckOcclusion=1]="CheckOcclusion",i[i.WaitOcclusion=2]="WaitOcclusion",i[i.Collect=3]="Collect",i[i.Deconflict=4]="Deconflict",i[i.NumStates=5]="NumStates"}(ni||(ni={}));class ai{constructor(){this.camera=new R,this.slicePlane=S(),this.slicePlaneEnabled=!1}copyFrom(i){this.camera.copyFrom(i.camera),A(i.slicePlane,this.slicePlane),this.slicePlaneEnabled=i.slicePlaneEnabled}}let li=class extends t{get dirty(){return this._dirty}get state(){return this._state}constructor(i){super(i),this._dirty=!1,this._viewState=new ai,this._state=ni.Idle,this._checkOcclusion=new Map,this._active=new Map,this._checkOcclusionIterator=null,this._activeIterator=null,this._occlusionQueryUids=new Array,this._updatingHandles=new v,this._deconflictor=new E(((i,t)=>{i.visible=t,this._setGraphicVisibility(this._active.get(i.id),t)}),((i,t)=>i.id!==t.id),ci),this._baseOccludedVisibility=10,this._altitudeFactor=2,this._minAltitudeDifference=100}initialize(){this._updatingHandles.add((()=>(this.view?.map?.ground?.opacity??0)>0),(()=>this.setDirty())),this._updatingHandles.add((()=>this.view.ready),(()=>this._occlusionQuery=null))}destroy(){this._occlusionQuery=null,this._updatingHandles.destroy(),this._deconflictor.destroy(),this._checkOcclusion.clear(),this._active.clear()}setDirty(){!this._dirty&&(this._active.size>0||this._checkOcclusion.size>0)&&(this._dirty=!0,this.notifyChange("updating"))}setPriority(i,t){const e=this._active.get(i.graphic.uid)?.getInfo(this.visibilityGroup);e&&(e.priority=t)}get updating(){return this._state!==ni.Idle||this._dirty||this._updatingHandles.updating}get updatingProgress(){if(!this.updating)return 1;const i=this._state/ni.NumStates;return this._dirty?.5*i:i}get running(){return this.view.ready&&null!=this.view.state&&this.updating}runTask(i){switch(this._state){case ni.Idle:this._startUpdate(),i.madeProgress();case ni.CheckOcclusion:if(this._state=ni.CheckOcclusion,!this._processCheckOcclusion(i))return;case ni.WaitOcclusion:if(this._state=ni.WaitOcclusion,this._occlusionQuery&&!this._occlusionQuery.done)return Y;this._readOcclusionQueryResult(),i.madeProgress();case ni.Collect:if(this._state=ni.Collect,!this._collectActiveGraphics(i))return;case ni.Deconflict:if(this._state=ni.Deconflict,this._deconflictor.run(i),!this._deconflictor.done)return;default:this._state=ni.Idle,this.notifyChange("updating")}}setGraphicsActive(i,t){t?i.forEach((i=>this.addToActiveGraphics(i))):i.forEach((i=>this.removeFromActiveGraphics(i)))}layerSupportsDeconfliction(i){if(null==i||"object3d"!==i.type)return!1;const t=i.stageObject;if(1!==(t?.geometries.length??0))return!1;const e=t?.geometries[0],s=e?.material;return s instanceof W}_startUpdate(){V(this.view),this._dirty=!1,this._viewState.copyFrom(this.viewState);const{fullWidth:i,fullHeight:t}=this._viewState.camera;this._deconflictor.reset(i,t),this._resetIterators(),this._occlusionQueryUids.length=0,this._checkOcclusion.size||(this._occlusionQuery=s(this._occlusionQuery))}addToActiveGraphics(i){i.ensureInfo(this.visibilityGroup),this._active.set(i.graphics3DGraphic.graphic.uid,i),this.setDirty()}removeFromActiveGraphics(i){hi(i,this.visibilityGroup),i.removeInfo(this.visibilityGroup),this._active.delete(i.graphics3DGraphic.graphic.uid),this.setDirty()}addToCheckOcclusion(i){this._checkOcclusion.set(i.graphics3DGraphic.graphic.uid,i),this.setDirty()}removeFromCheckOcclusion(i){this._checkOcclusion.delete(i.graphics3DGraphic.graphic.uid)}_processCheckOcclusion(i){if(0===this._checkOcclusion.size)return!0;const t=this._ensureCheckOcclusionIterator(),e=this._viewState.camera,r=o($,e.viewInverseTransposeMatrix),c=this.view.map.ground.opacity>0,n="global"===this.view.viewingMode&&c&&e.relativeElevation>0?ii:null;let a=0;null!=n&&(l(N(n),p,e.viewMatrix),n[3]=b(this.view.spatialReference).radius,a=T(n,p));const h=O();for(;;){if(i.done)return!1;i.madeProgress();const s=t.next();if(!0===s.done)break;const c=s.value,o=c.graphics3DGraphic;if(o.destroyed)continue;if(!o.isVisible(U.GRAPHIC,F.DECONFLICTION))continue;const u=fi(o,this.visibilityGroup);let d=null,p=!0;for(const i of u){if(!this.layerSupportsDeconfliction(i))continue;d=_i,this._projectHudLayer(i,e,d),w(h);const t=i.stageObject.geometries[0].material;if(this._expandBoundingRect(h,e,i,t,d),d.isOutsideScreen){p=!1;break}if(this._isCulledBySlice(c,d.positionView)){p=!1;break}if(null!=n&&pi(d,n,a)){p=!1;break}l(J,d.positionView,r),d.altitude=this.view.renderCoordsHelper.getAltitude(J);const s=c.ensureInfo(this.visibilityGroup);if(s.altitude=d.altitude,s.distance=d.distance,s.distanceToOccluder=d.distanceToOccluder,s.culled=!1,I(s.aabr,h),t.parameters.occlusionTest)break;this._ensureOcclusionQuery().addPosition(J)===this._occlusionQueryUids.length&&this._occlusionQueryUids.push(o.graphic.uid);break}if(this._active.has(o.graphic.uid)&&(!p||!d)){const i=c.ensureInfo(this.visibilityGroup);i.visible=!d,i.culled=!0}}return this._checkOcclusionIterator=null,this._occlusionQueryUids.length||(this._occlusionQuery=s(this._occlusionQuery)),this._occlusionQuery?.start(),!0}_readOcclusionQueryResult(){if(!this._occlusionQuery||!this._occlusionQueryUids.length)return;const i=this._viewState.camera,t=this.view.renderCoordsHelper.getAltitude(i.eye);for(let e=0;e<this._occlusionQueryUids.length;e++){const i=this._occlusionQueryUids[e],s=this._checkOcclusion.get(i);if(!s)continue;const r=this._occlusionQuery.getOcclusion(e)??-1,c=s.getInfo(this.visibilityGroup);c&&(c.distanceToOccluder=r>0?c.distance-r:0);const o=r<=0||this._occludedVisibility(c?.distanceToOccluder??0,c?.distance??r,c?.altitude??0,t);this._active.has(i)?c&&(c.culled=!o,c.visible=o):this._setGraphicVisibility(s,o)}this._occlusionQueryUids.length=0}_collectActiveGraphics(i){const t=this._ensureActiveGraphicsIterator(),e=this.visibilityGroup===U.LABEL;for(;!i.done;){i.madeProgress();const s=t.next();if(!0===s.done)return this._activeIterator=null,!0;const r=s.value,c=r.getInfo(this.visibilityGroup);if(!c)continue;!(!e||r.graphics3DGraphic.isVisible())||c.culled?(L(c.aabr,!1,!0),this._setGraphicVisibility(r,c.visible)):this._deconflictor.add(c)}return!1}_occludedVisibility(i,t,e,s){const r=Math.max(this._minAltitudeDifference,Math.abs(e-s))-this._minAltitudeDifference;return 0===i||t-i<=this._baseOccludedVisibility+this._altitudeFactor*r}_resetIterators(){this._checkOcclusionIterator=null,this._activeIterator=null}_ensureCheckOcclusionIterator(){return this._checkOcclusionIterator??=this._checkOcclusion.values(),this._checkOcclusionIterator}_ensureActiveGraphicsIterator(){return this._activeIterator??=this._active.values(),this._activeIterator}_ensureOcclusionQuery(){return this._occlusionQuery??=new H({view:this.view}),this._occlusionQueryUids.length||this._occlusionQuery.init(this._checkOcclusion.size,this._viewState.camera.eye),this._occlusionQuery}_projectHudLayer(i,t,e){const s=i.stageObject,r=s.geometries[0],c=r.material,o=N(s.boundingVolumeWorldSpace.bounds);l(q,o,t.viewMatrix);const n=r.attributes,a=n.get(M.NORMAL).data,d=n.get(M.CENTEROFFSETANDDISTANCE).data;c.applyShaderOffsetsView(q,a,s.transformation,d,t,e.scaleInfo,q),_(K,q[0],q[1],q[2],1),m(X,K,t.projectionMatrix),h(e.positionNDC,X,1/X[3]),c.applyShaderOffsetsNDC(e.positionNDC,d,t,e.positionNDC,Z),e.distanceWithoutPolygonOffset=t.depthNDCToWorld(Z[2]),e.distance=Z[2]===e.positionNDC[2]?e.distanceWithoutPolygonOffset:t.depthNDCToWorld(e.positionNDC[2]),_(X,e.positionNDC[0],e.positionNDC[1],e.positionNDC[2],1),m(K,X,t.inverseProjectionMatrix),g(K,K,1/K[3]),u(e.positionView,q[0],q[1],q[2])}_isCulledBySlice(i,t){return i.slicePlaneEnabled&&this._viewState.slicePlaneEnabled&&k(this._viewState.slicePlane,t)}_expandBoundingRect(i,t,s,r,{positionNDC:c,scaleInfo:o}){const n=s.getScreenSize(ui);B(n,o.factor,n),n[0]*=t.pixelRatio,n[1]*=t.pixelRatio;const a=D(r.calculateRelativeScreenBounds(n,o.factorAlignment.scale*t.pixelRatio,si),e(0,t.fullWidth,.5+.5*c[0]),e(0,t.fullHeight,.5+.5*c[1])),l=this.marginFactor;if(0!==l){const i=l*Math.min(C(a),j(a));a[0]-=i,a[1]-=i,a[2]+=i,a[3]+=i}G(i,a,i)}_setGraphicVisibility(i,t){const e=i?.graphics3DGraphic;e&&!e.destroyed&&(e.setVisibilityFlag(this.visibilityGroup,F.DECONFLICTION,t),this.visibilityGroup===U.LABEL&&this.view.labeler.setLabelGraphicVisibility(e,t))}};function hi(i,t){const e=i.graphics3DGraphic;e.destroyed||e.setVisibilityFlag(t,F.DECONFLICTION,!0)}i([r({constructOnly:!0})],li.prototype,"view",void 0),i([r({type:Boolean,readOnly:!0})],li.prototype,"updating",null),i([r({readOnly:!0})],li.prototype,"_updatingHandles",void 0),li=i([c("esri.views.3d.layers.graphics.Deconflictor")],li);const ui=a();class di{constructor(){this.positionView=f(),this.positionNDC=f(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.distanceWithoutPolygonOffset=0,this.scaleInfo=new z}get isOutsideScreen(){const i=this.positionNDC;return i[0]<-1||i[1]<-1||i[2]<-1||i[0]>=1||i[1]>=1||i[2]>=1}}function pi(i,t,e){return d(ti.direction,i.positionView),u(ti.origin,0,0,0),!!x(t,ti,ei)&&i.distanceWithoutPolygonOffset>e}function fi(i,t){return t===U.LABEL?i.labelLayers:i.layers}const _i=new di;export{li as Deconflictor,oi as DeconflictorGraphic,ai as DeconflictorViewState,ni as State};
@@ -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"../../../../core/Error.js";import{assertIsSome as t}from"../../../../core/maybe.js";import{MinPriority as r}from"../../../../core/MemCache.js";import{throwIfAborted as o}from"../../../../core/promiseUtils.js";import{generateUUID as n}from"../../../../core/uuid.js";import{normalFromMat4 as s}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{q as i}from"../../../../chunks/vec32.js";import{ONES as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{projectBoundingSphere as d}from"../../../../geometry/projection/projectBoundingSphere.js";import{isRelativeVertexSpace as c}from"../../../../geometry/support/meshVertexSpaceUtils.js";import{l as u}from"../../../../chunks/sphere.js";import{CachedMeshData as m}from"./CachedMeshData.js";import{convertMeshMaterialToPBRMaterial as h}from"./I3SClientMaterialUtil.js";class f{constructor(e,t,r,o){this._uid=e,this._worker=o,this._id2Meta=new Map,this._oid2Meta=new Map,this._indexSR=t.indexSR,this._vertexSR=t.vertexSR,this._renderSR=t.renderSR,this._memCache=r.newCache(`sl-client-mesh-data-${this._uid}`)}get uid(){return this._uid}get worker(){return this._worker}get indexSR(){return this._indexSR}get renderSR(){return this._renderSR}createMeshNodeInfo(e,t){const r=`mesh${t}`,o=e.extent,n=o.spatialReference,s=this._indexSR,a=y(o,e.origin);d(a,n,a,s);return{type:"mesh",id:r,version:w(e),oid:t,mbs:a,componentNodeIds:[],unloadedMesh:e,nodeIndex:null,loadMeshPromise:null}}addMeshNode(t,r){if(null!=this.getMeshNodeIndex(r.oid))throw new e("scenelayer",`I3SClientNodeLoader: client side mesh for feature oid=${r.oid} already exists`);r.nodeIndex=t,this._id2Meta.set(r.id,r),this._oid2Meta.set(r.oid,r)}getMeshNodeIndex(e){const t=this._oid2Meta.get(e);return null==t||"mesh"!==t.type?null:t.nodeIndex}getMeshNodeInfo(e){const t=this._oid2Meta.values();for(const r of t)if("mesh"===r.type&&r.id===e)return r;return null}removeNode(e){const t=this._id2Meta.get(e);null!=t&&(this._id2Meta.delete(e),"mesh"===t.type&&this._oid2Meta.delete(t.oid))}async loadNodeJSON(t){const r=this._id2Meta.get(t);if(null==r)throw new e("scenelayer",`I3SClientNodeLoader::loadNodeJSON unable to find node ${t}`);switch(r.type){case"mesh":return this._loadMeshNodeJSON(r);case"mesh-component":return p(r);default:throw new e("scenelayer",`I3SClientNodeLoader::loadNodeJSON unable to handle node ${t}`)}}async _loadMeshNodeJSON(e){const t=e.id,r=(await this._getMeshData(e)).loadedMesh;if(null==r.components||0===r.components.length)return{id:t,version:null,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:null};const o=[],n=r.components;for(let s=0;s<n.length;++s){const r=`${t}-component${s}`,n={type:"mesh-component",id:r,mbs:e.mbs,componentIndex:s,meshNodeInfo:e,textureData:new Map};this._id2Meta.set(n.id,n),e.componentNodeIds.push(r),o.push({id:n.id,href:null,mbs:n.mbs,obb:null})}return{id:t,version:null,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:o}}updateNodeIndex(e,t,r){const o=this._id2Meta.get(e);o&&"mesh"===o.type&&(o.nodeIndex=r)}async loadNodeData(r,n){const s=this._id2Meta.get(r);if(null==s||"mesh-component"!==s.type)throw new e("scenelayer",`Failed to load client node data for node ${r} (unexpected node info)`);const a=s.meshNodeInfo,i=await this._getMeshData(a),l=i.loadedMesh,d=a.oid;if(null==l.components)throw new e("scenelayer",`Failed to load client node data for node ${r} (unexpected null reference)`);const c=l.components[s.componentIndex],{material:u,requiredTextures:m,textureData:f}=await h(c.material);if(null!=f)for(const e of f)null!=e&&s.textureData.set(e.id,e);const p={params:{material:u},type:"ArrayBufferView"},{vertexSpace:y,origin:M,transform:w}=l,S=[M.x,M.y,M.z??0];i.projectionPromise||(t(this._worker,"SceneLayerWorker is needed to project mesh"),i.projectionPromise=this._worker.project({positions:l.vertexAttributes.position,localMatrix:w?.localMatrix,vertexSpace:y.toJSON(),origin:S,inSpatialReference:l.spatialReference.toJSON(),outSpatialReference:this._vertexSR.toJSON()},n));const{projected:b,original:_,projectedOrigin:N}=await i.projectionPromise;l.vertexAttributes.position=_;const{transformed:v,original:D}=await x(c,i,this._worker,n);l.vertexAttributes.normal=D,o(n);const{geometryBuffer:R,geometryDescriptor:j}=g(b,c.faces,v,l.vertexAttributes.uv,l.vertexAttributes.color,d);return{geometryData:{featureDataPosition:N,featureIds:[],geometries:[p]},attributeDataInfo:{attributeData:{},loadedAttributes:[]},geometryBuffer:R,geometryDescriptor:j,requiredTextures:m,textureData:f,normalReferenceFrame:this._vertexSR.isGeographic?"east-north-up":"vertex-reference-frame"}}async loadAttributes(e,t,r){const o=e.numFeatures,n={};for(const{field:{name:s}}of t)n[s]=new Array(o);return n}async loadTextures(e,t,r){const o=e.id,n=this._id2Meta.get(o);if(null==n||"mesh-component"!==n.type)throw new Error(`Failed to load textures for node ${e.id} (unexpected node info)`);const s=[];for(const a of t)s.push(n.textureData.get(a.id)||null);return s}async _getMeshData(e){const t=e.version,o=this._memCache.get(t);if(null==o){if(null!=e.loadMeshPromise)return e.loadMeshPromise;const o=async(o,n)=>{const s=e.unloadedMesh.clone();try{await s.load()}catch(i){n(i)}const a=new m(s);this._memCache.put(t,a,r),e.loadMeshPromise=null,o(a)};return e.loadMeshPromise=new Promise(((e,t)=>o(e,t))),e.loadMeshPromise}return o}}async function p(e){return{id:e.id,version:e.meshNodeInfo.version,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:null,isEmpty:!1}}function y(e,t){const{spatialReference:r}=e,o=[1,-1],n=[.5*e.width,.5*e.height,e.hasZ?.5*(e.zmax-e.zmin):0],s=r.isGeographic?r.metersPerUnit:1,a=e.center;let i=0;if(e.hasZ)for(let l=0;l<2;++l)for(let e=0;e<2;++e)for(let r=0;r<2;++r){const d=(a.x+o[l]*n[0]-t.x)*s,c=(a.y+o[e]*n[1]-t.y)*s,u=a.z+o[r]*n[2]-t.z;i=Math.max(d*d+c*c+u*u,i)}else for(let l=0;l<2;++l)for(let e=0;e<2;++e){const r=(a.x+o[l]*n[0]-t.x)*s,d=(a.y+o[e]*n[1]-t.y)*s;i=Math.max(r*r+d*d,i)}return u([t.x,t.y,t.z],Math.sqrt(i))}async function x(e,r,o,n){const{transform:d,vertexAttributes:c}=r.loadedMesh,u="source"===e.shading?c.normal:null;if(!(null!=u&&null!=d&&(0!==d.rotationAngle||!i(d.scale,l))))return{transformed:u,original:c.normal};if(!r.normalsTransformPromise){t(o,"SceneLayerWorker is needed to transform mesh normals");const e=a();s(e,d.localMatrix),r.normalsTransformPromise=o.transformNormals({normalMatrix:e,normals:u},n)}return r.normalsTransformPromise}function g(e,t,r,o,n,s){const a=1,i=(t?.length??0)/3,l=3*i;let d=0,c=0,u=!1,m=0,h=!1,f=0,p=!1,y=0,x=0,g=0;d+=S,d+=S,c=d,d+=3*l*b,null!=r&&(u=!0,m=d,d+=3*l*b),null!=o&&(h=!0,f=d,d+=2*l*b),null!=n&&(p=!0,y=d,d+=4*l*_),x=d,d+=a*N,g=d,d+=2*a*S;const w=new ArrayBuffer(d),v=new Uint8Array(w);M(v,0,l),M(v,S,a);const D=new Float32Array(w,c),R=null!=r?new Float32Array(w,m):null,j=null!=o?new Float32Array(w,f):null,I=null!=n?new Uint8Array(w,y):null;for(let M=0;M<i;++M){const s=3*M;for(let a=0;a<3;++a){const i=t[s+a],l=3*i,d=9*M+3*a;if(D[d]=e[l],D[d+1]=e[l+1],D[d+2]=e[l+2],R&&(R[d]=r[l],R[d+1]=r[l+1],R[d+2]=r[l+2]),j){const e=2*i,t=6*M+2*a;j[t]=o[e],j[t+1]=o[e+1]}if(I){const e=4*i,t=12*M+4*a;I[t]=n[e],I[t+1]=n[e+1],I[t+2]=n[e+2],I[t+3]=n[e+3]}}}M(v,x,s),M(v,x+S,s/2**32),M(v,g,0),M(v,g+S,i-1);return{geometryBuffer:w,geometryDescriptor:{isDraco:!1,isLegacy:!0,color:p,normal:u,uv0:h,uvRegion:!1,featureIndex:!0}}}function M(e,t,r){e[t]=255&r,e[t+1]=255&r>>8,e[t+2]=255&r>>16,e[t+3]=255&r>>24}function w(e){const t=e.metadata.displaySource?.source;if(null==t||!Array.isArray(t)||!t.length||t[0]instanceof File)return n();const r=t;let o="";for(const n of r)o+=n.makeHash();return o+JSON.stringify(e.transform?.toJSON()??"")+(c(e.vertexSpace)?JSON.stringify(e.vertexSpace.origin):"")+JSON.stringify(e.spatialReference)}const S=4,b=4,_=1,N=8;export{f as I3SClientNodeLoader,y as createSphereFromExtent,b as sizeOfFloat32,S as sizeOfInt32,N as sizeOfUInt64,_ as sizeOfUInt8,x as transformNormals};
5
+ import e from"../../../../core/Error.js";import{assertIsSome as t}from"../../../../core/maybe.js";import{MinPriority as r}from"../../../../core/MemCache.js";import{throwIfAborted as o}from"../../../../core/promiseUtils.js";import{generateUUID as n}from"../../../../core/uuid.js";import{normalFromMat4 as s}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{q as i}from"../../../../chunks/vec32.js";import{ONES as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{projectBoundingSphere as d}from"../../../../geometry/projection/projectBoundingSphere.js";import{isRelativeVertexSpace as c}from"../../../../geometry/support/meshVertexSpaceUtils.js";import{h as u}from"../../../../chunks/sphere.js";import{CachedMeshData as m}from"./CachedMeshData.js";import{convertMeshMaterialToPBRMaterial as h}from"./I3SClientMaterialUtil.js";class f{constructor(e,t,r,o){this._uid=e,this._worker=o,this._id2Meta=new Map,this._oid2Meta=new Map,this._indexSR=t.indexSR,this._vertexSR=t.vertexSR,this._renderSR=t.renderSR,this._memCache=r.newCache(`sl-client-mesh-data-${this._uid}`)}get uid(){return this._uid}get worker(){return this._worker}get indexSR(){return this._indexSR}get renderSR(){return this._renderSR}createMeshNodeInfo(e,t){const r=`mesh${t}`,o=e.extent,n=o.spatialReference,s=this._indexSR,a=y(o,e.origin);d(a,n,a,s);return{type:"mesh",id:r,version:w(e),oid:t,mbs:a,componentNodeIds:[],unloadedMesh:e,nodeIndex:null,loadMeshPromise:null}}addMeshNode(t,r){if(null!=this.getMeshNodeIndex(r.oid))throw new e("scenelayer",`I3SClientNodeLoader: client side mesh for feature oid=${r.oid} already exists`);r.nodeIndex=t,this._id2Meta.set(r.id,r),this._oid2Meta.set(r.oid,r)}getMeshNodeIndex(e){const t=this._oid2Meta.get(e);return null==t||"mesh"!==t.type?null:t.nodeIndex}getMeshNodeInfo(e){const t=this._oid2Meta.values();for(const r of t)if("mesh"===r.type&&r.id===e)return r;return null}removeNode(e){const t=this._id2Meta.get(e);null!=t&&(this._id2Meta.delete(e),"mesh"===t.type&&this._oid2Meta.delete(t.oid))}async loadNodeJSON(t){const r=this._id2Meta.get(t);if(null==r)throw new e("scenelayer",`I3SClientNodeLoader::loadNodeJSON unable to find node ${t}`);switch(r.type){case"mesh":return this._loadMeshNodeJSON(r);case"mesh-component":return p(r);default:throw new e("scenelayer",`I3SClientNodeLoader::loadNodeJSON unable to handle node ${t}`)}}async _loadMeshNodeJSON(e){const t=e.id,r=(await this._getMeshData(e)).loadedMesh;if(null==r.components||0===r.components.length)return{id:t,version:null,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:null};const o=[],n=r.components;for(let s=0;s<n.length;++s){const r=`${t}-component${s}`,n={type:"mesh-component",id:r,mbs:e.mbs,componentIndex:s,meshNodeInfo:e,textureData:new Map};this._id2Meta.set(n.id,n),e.componentNodeIds.push(r),o.push({id:n.id,href:null,mbs:n.mbs,obb:null})}return{id:t,version:null,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:o}}updateNodeIndex(e,t,r){const o=this._id2Meta.get(e);o&&"mesh"===o.type&&(o.nodeIndex=r)}async loadNodeData(r,n){const s=this._id2Meta.get(r);if(null==s||"mesh-component"!==s.type)throw new e("scenelayer",`Failed to load client node data for node ${r} (unexpected node info)`);const a=s.meshNodeInfo,i=await this._getMeshData(a),l=i.loadedMesh,d=a.oid;if(null==l.components)throw new e("scenelayer",`Failed to load client node data for node ${r} (unexpected null reference)`);const c=l.components[s.componentIndex],{material:u,requiredTextures:m,textureData:f}=await h(c.material);if(null!=f)for(const e of f)null!=e&&s.textureData.set(e.id,e);const p={params:{material:u},type:"ArrayBufferView"},{vertexSpace:y,origin:M,transform:w}=l,S=[M.x,M.y,M.z??0];i.projectionPromise||(t(this._worker,"SceneLayerWorker is needed to project mesh"),i.projectionPromise=this._worker.project({positions:l.vertexAttributes.position,localMatrix:w?.localMatrix,vertexSpace:y.toJSON(),origin:S,inSpatialReference:l.spatialReference.toJSON(),outSpatialReference:this._vertexSR.toJSON()},n));const{projected:b,original:_,projectedOrigin:N}=await i.projectionPromise;l.vertexAttributes.position=_;const{transformed:v,original:D}=await x(c,i,this._worker,n);l.vertexAttributes.normal=D,o(n);const{geometryBuffer:R,geometryDescriptor:j}=g(b,c.faces,v,l.vertexAttributes.uv,l.vertexAttributes.color,d);return{geometryData:{featureDataPosition:N,featureIds:[],geometries:[p]},attributeDataInfo:{attributeData:{},loadedAttributes:[]},geometryBuffer:R,geometryDescriptor:j,requiredTextures:m,textureData:f,normalReferenceFrame:this._vertexSR.isGeographic?"east-north-up":"vertex-reference-frame"}}async loadAttributes(e,t,r){const o=e.numFeatures,n={};for(const{field:{name:s}}of t)n[s]=new Array(o);return n}async loadTextures(e,t,r){const o=e.id,n=this._id2Meta.get(o);if(null==n||"mesh-component"!==n.type)throw new Error(`Failed to load textures for node ${e.id} (unexpected node info)`);const s=[];for(const a of t)s.push(n.textureData.get(a.id)||null);return s}async _getMeshData(e){const t=e.version,o=this._memCache.get(t);if(null==o){if(null!=e.loadMeshPromise)return e.loadMeshPromise;const o=async(o,n)=>{const s=e.unloadedMesh.clone();try{await s.load()}catch(i){n(i)}const a=new m(s);this._memCache.put(t,a,r),e.loadMeshPromise=null,o(a)};return e.loadMeshPromise=new Promise(((e,t)=>o(e,t))),e.loadMeshPromise}return o}}async function p(e){return{id:e.id,version:e.meshNodeInfo.version,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:null,isEmpty:!1}}function y(e,t){const{spatialReference:r}=e,o=[1,-1],n=[.5*e.width,.5*e.height,e.hasZ?.5*(e.zmax-e.zmin):0],s=r.isGeographic?r.metersPerUnit:1,a=e.center;let i=0;if(e.hasZ)for(let l=0;l<2;++l)for(let e=0;e<2;++e)for(let r=0;r<2;++r){const d=(a.x+o[l]*n[0]-t.x)*s,c=(a.y+o[e]*n[1]-t.y)*s,u=a.z+o[r]*n[2]-t.z;i=Math.max(d*d+c*c+u*u,i)}else for(let l=0;l<2;++l)for(let e=0;e<2;++e){const r=(a.x+o[l]*n[0]-t.x)*s,d=(a.y+o[e]*n[1]-t.y)*s;i=Math.max(r*r+d*d,i)}return u([t.x,t.y,t.z],Math.sqrt(i))}async function x(e,r,o,n){const{transform:d,vertexAttributes:c}=r.loadedMesh,u="source"===e.shading?c.normal:null;if(!(null!=u&&null!=d&&(0!==d.rotationAngle||!i(d.scale,l))))return{transformed:u,original:c.normal};if(!r.normalsTransformPromise){t(o,"SceneLayerWorker is needed to transform mesh normals");const e=a();s(e,d.localMatrix),r.normalsTransformPromise=o.transformNormals({normalMatrix:e,normals:u},n)}return r.normalsTransformPromise}function g(e,t,r,o,n,s){const a=1,i=(t?.length??0)/3,l=3*i;let d=0,c=0,u=!1,m=0,h=!1,f=0,p=!1,y=0,x=0,g=0;d+=S,d+=S,c=d,d+=3*l*b,null!=r&&(u=!0,m=d,d+=3*l*b),null!=o&&(h=!0,f=d,d+=2*l*b),null!=n&&(p=!0,y=d,d+=4*l*_),x=d,d+=a*N,g=d,d+=2*a*S;const w=new ArrayBuffer(d),v=new Uint8Array(w);M(v,0,l),M(v,S,a);const D=new Float32Array(w,c),R=null!=r?new Float32Array(w,m):null,j=null!=o?new Float32Array(w,f):null,I=null!=n?new Uint8Array(w,y):null;for(let M=0;M<i;++M){const s=3*M;for(let a=0;a<3;++a){const i=t[s+a],l=3*i,d=9*M+3*a;if(D[d]=e[l],D[d+1]=e[l+1],D[d+2]=e[l+2],R&&(R[d]=r[l],R[d+1]=r[l+1],R[d+2]=r[l+2]),j){const e=2*i,t=6*M+2*a;j[t]=o[e],j[t+1]=o[e+1]}if(I){const e=4*i,t=12*M+4*a;I[t]=n[e],I[t+1]=n[e+1],I[t+2]=n[e+2],I[t+3]=n[e+3]}}}M(v,x,s),M(v,x+S,s/2**32),M(v,g,0),M(v,g+S,i-1);return{geometryBuffer:w,geometryDescriptor:{isDraco:!1,isLegacy:!0,color:p,normal:u,uv0:h,uvRegion:!1,featureIndex:!0}}}function M(e,t,r){e[t]=255&r,e[t+1]=255&r>>8,e[t+2]=255&r>>16,e[t+3]=255&r>>24}function w(e){const t=e.metadata.displaySource?.source;if(null==t||!Array.isArray(t)||!t.length||t[0]instanceof File)return n();const r=t;let o="";for(const n of r)o+=n.makeHash();return o+JSON.stringify(e.transform?.toJSON()??"")+(c(e.vertexSpace)?JSON.stringify(e.vertexSpace.origin):"")+JSON.stringify(e.spatialReference)}const S=4,b=4,_=1,N=8;export{f as I3SClientNodeLoader,y as createSphereFromExtent,b as sizeOfFloat32,S as sizeOfInt32,N as sizeOfUInt64,_ as sizeOfUInt8,x as transformNormals};
@@ -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 has from"../../../../core/has.js";import e from"../../../../core/PooledArray.js";import{isAbortError as t}from"../../../../core/promiseUtils.js";import{projectBoundingSphere as i}from"../../../../geometry/projection/projectBoundingSphere.js";import{l as n,e as s,c as o,u as r}from"../../../../chunks/sphere.js";import{LodMetric as a,NodeBase as l,Node as d,NodeFilterImpact as h,NodeIMModificationImpact as u,NodeTraversalState as c}from"./I3SNode.js";import{invalidateMbs as g,addWraparound as _}from"./I3SUtil.js";import{ValidatedNode as f}from"./ValidatedNode.js";import{ElevationRange as m}from"../../support/ElevationRange.js";import{Obb as v}from"../../support/orientedBoundingBox.js";class N{constructor(e,t,i,n,s){this.childOffset=e,this.childCount=t,this.visibilityCache=i,this.ref=n,this.node=s,this.useAsHole=0,this.filterImpact=h.NotChecked,this.traversalState=null,this.parent=-1}invalidateBounds(){this.node?.invalidateServiceBVsInRenderSR(),this.ref?.invalidateServiceBVsInRenderSR()}}class p{constructor(e=new Array,t=new Array){this.nodes=e,this.children=t,this.lastTraversed=0,this.numNodesWithLoadedChildren=0}}class b{get _useNodePages(){return this._pageSize>0}constructor(t,i,n,s,o,r,l,d,h,u,c,g,_,f,m,v){this.viewingMode=t,this._layer=i,this._streamDataController=s,this._clientNodeLoader=o,this._viewportQueries=r,this._logger=l,this.holeFilling=d,this._isLoaded=h,this._isReloading=u,this._isSelected=c,this._enable=g,this._needsUpdate=_,this._canRequest=f,this._computeVisibilityObb=m,this._computeNodeFiltering=v,this._dirty=!0,this._nodePages=new Map,this._clientNodePage=null,this._pageSize=0,this._rootIndex=0,this._lodMetric=a.None,this._lodConversion=e=>e,this._isEditable=!1,this._urlPrefix="",this._loadingNodes=new Set,this._loadingPages=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.POSITIVE_INFINITY,this._version=x(0),this._visibilityCacheVersion=x(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._missingPagesAndNodes=new e({deallocator:null}),this._prefetchNodes=new e({deallocator:null}),this._updates=new y(this._missingPagesAndNodes),this._imModificationUncategorized=new e({deallocator:null}),this.ignoreServiceObb=!1,this.progressiveLoadPenalty=0,this._pageQueue=new Array,this._newPages=new Array,this.needNodeElevationRange=!1,this.layerHasModifications=!1,this._layerHasFilter=!1,this._frameNumber=0,this._traverseDescendantsQueue=[0],this._traverseDescendantsNestingLevel=0,this._isEditable=null!=i.associatedLayer?.infoFor3D,i.serviceUpdateTimeStamp?.lastUpdate&&(this._lastUpdate=`${i.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this._viewportQueries?this._viewportQueries.maxLodLevel:1,this._init(n)}_init(e){if("page"===e.type){const t=e.rootPage;switch(this._urlPrefix=e.urlPrefix,this._pageSize=e.pageSize,e.lodMetric){case"maxScreenThreshold":this._lodMetric=a.MaxScreenThreshold;break;case"maxScreenThresholdSQ":this._lodMetric=a.MaxScreenThreshold,this._lodConversion=F}if(this._isEditable){this._rootIndex=-1;const i=E(e.rootIndex,e.pageSize),n=t.nodes[i],s={nodes:[{index:this._rootIndex,children:[e.rootIndex],mesh:void 0,obb:n.obb,lodThreshold:n.lodThreshold}]};this._addPage(w(this._rootIndex,this._pageSize),s),this.getNode(-1).serviceObbInIndexSR=void 0}else this._rootIndex=e.rootIndex;this._addPage(w(e.rootIndex,this._pageSize),t),this._updateParentsAndLevel()}else if("node"===e.type){this._urlPrefix=e.urlPrefix;const t=new p;if(this._nodePages.set(0,t),this._isEditable){this._clientNodePage=new p;const t={id:"-1",version:null,mbs:e.rootNode.mbs,obb:e.rootNode.obb,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:[{id:"root",href:"../root",mbs:e.rootNode.mbs,obb:e.rootNode.obb}]};this._rootIndex=this._makeClientRefNode(new l(t.id,null),-1);const i=this._validateNode(t.id,t);i&&this._addNode(i,this._rootIndex)}else this._rootIndex=this._makeRefNode(new l(e.rootNode.id,null),-1);const i=this._validateNode(e.rootNode.id,e.rootNode);i&&this._addNode(i,0)}}addClientNodeToIndex(e,t){const i=-1,n=new l(e,t),s=this._makeClientRefNode(n,i);return this._linkChildToParentNode(i,s),this.requestUpdate(),s}removeClientNodeFromIndex(e,t,i){this._destroyClientRefNode(e,t,i),this.requestUpdate()}_loadPage(e){this._loadingPages.add(e);const i=this._urlPrefix+e;this._streamDataController.request(i,"json").then((t=>{this._pageQueue.push({pageIndex:e,page:t})})).catch((i=>{this._loadingPages.delete(e),t(i)||(this._failedPages.add(e),this._logger.error("#loadPage()",this._layer,`Error when loading page ${e}`,i))}))}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){const{pageIndex:t,page:i}=this._pageQueue.shift();this._addPage(t,i),this._loadingPages.delete(t),e.madeProgress(),this.needNodeElevationRange&&this._newPages.push(t)}this._updateParentsAndLevel()}_invalidateElevationRangeForNewPages(e){if(this.needNodeElevationRange)for(;this._newPages.length>0&&!e.done;){const e=this._nodePages.get(this._newPages.shift());e?.nodes.forEach((e=>{let t=e.parent;for(;null!=t&&t!==this._rootIndex;){const e=this.getNode(t);e&&!Number.isNaN(e?.elevationRangeMin)&&(e.invalidateElevationRange(),this.invalidateBoundingVolumeCache(t)),t=this.getParentIndex(t)}}))}}_addPage(e,t){const i=[],s=[],o=t.nodes.map(((t,o)=>{const r=i.length,a=t.children?t.children.length:0;s.push(this._rootIndex);for(let e=0;e<a;e++)i.push(t.children[e]);const l=`${t.index}`,h=v.fromJSON(t.obb),u=n(h.center,h.radius),c=t.mesh?.attribute,g=t.mesh?.geometry,_=t.mesh?.material,f={hasSharedResource:!1,isEmpty:null==g,attributes:null!=c?.resource?`${c.resource}`:void 0,geometry:null!=g?.resource?`${g.resource}`:void 0,texture:null!=_?.resource?`${_.resource}`:void 0,geometryDefinition:g?g.definition:-1,materialDefinition:_?_.definition:-1},m=new d(l,M(o,e,this._pageSize),u,a,0,f,this._lastUpdate,this._lodMetric,this._lodConversion(t.lodThreshold),g?.featureCount??null);return m.serviceObbInIndexSR=h,m.visibilityObbInRenderSR=this._computeVisibilityObb(m),m.vertexCount=g?g.vertexCount:0,new N(r,a,P(this._visibilityCacheVersion),null,m)})),r=new p(o,i);-1===e?this._clientNodePage=r:this._nodePages.set(e,r)}_updateParentsAndLevel(){const e=new Array,t=(t,i,n)=>{const s=this._getPage(t);if(null!=s){const o=E(t,this._pageSize),r=s.nodes[o];r.parent=null!=i?i:-1;const a=r.node;null!=a&&(a.level=n,e.push(t))}};for(t(this._rootIndex,null,0);e.length;){const i=e.pop(),n=this.getNode(i);if(null!=n)for(let e=0;e<n.childCount;e++){t(this.getChildIndex(n.index,e),i,n.level+1),this._maxLevel=Math.max(this._maxLevel,n.level+1)}}}_getPage(e){const t=w(e,this._pageSize);return this._getPageFromPageIndex(t)}_getPageFromPageIndex(e){return e<0?this._clientNodePage:this._nodePages.get(e)}_getNodeInternal(e){const t=this._getPage(e);return null==t?null:(t.lastTraversed=this._frameNumber,t.nodes[E(e,this._pageSize)])}_addNode(e,t){e.children&&this.populateChildren(t,e.children);const i=this.getParent(t),n=null!=i?i.level+1:0;this._maxLevel=Math.max(this._maxLevel,e.children?n+1:n);const{lodMetric:s,maxError:o}=O(e.lodSelection),r=this._getNodeInternal(t),a=new d(e.id,t,e.mbs,r.childCount,n,e.resources,e.version,s,o,e.numFeatures);r.node=a,e.obb&&(a.serviceObbInIndexSR=v.fromJSON(e.obb)),a.visibilityObbInRenderSR=this._computeVisibilityObb(a);const l=r.ref;return null!=l&&(null==l.serviceMbsInIndexSR&&(l.serviceMbsInIndexSR=e.mbs),a.shareServiceBVsInRenderSRWith(l),l.visibilityObbInRenderSR=a.visibilityObbInRenderSR),a}_makeRefNode(e,t){const i=this._nodePages.get(0);if(t<-1)return this._makeClientRefNode(e,t);if(null==i)return-1;const n=i.nodes.length,s=new N(0,0,P(this._visibilityCacheVersion),e,null);return i.nodes.push(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_makeClientRefNode(e,t){const i=this._clientNodePage;if(null==i)return-1;if(t>=0)throw new Error("I3SIndex::client side nodes can not be made children of service side nodes.");const n=-(i.nodes.length+1),s=new N(0,0,P(this._visibilityCacheVersion),e,null);return i.nodes.push(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_linkChildToParentNode(e,t){const i=this._clientNodePage;if(null==i||e>=0)return;const n=E(e,this._pageSize),s=E(t,this._pageSize),o=i.nodes[n],r=o.childOffset;i.children.splice(o.childOffset+o.childCount,0,t);const a=1;o.childCount+=a,null!=o.node&&(o.node.childCount+=a);for(const l of i.nodes)l.childOffset>r&&(l.childOffset+=a);i.nodes[s].parent=e,this._updateParentBoundingInformation(e)}_destroyClientRefNode(e,t,i){const n=this._clientNodePage;if(null==n)return;const s=this.getParentIndex(e);if(null==s)return;const o=new Set,r=new Map,a=e=>{const i=E(e,this._pageSize),s=n.nodes[i];if(s.childCount>0)for(let t=s.childOffset;t<s.childOffset+s.childCount;++t)a(n.children[t]);const r=s.node?.id??s.ref?.id;if(null==r)throw new Error("Node has no id");t(r,e),o.add(s)};a(e);const l=n.nodes,d=n.children,h=n.nodes.map((()=>-1)),u=[],c=[];for(let g=0;g<l.length;++g){const e=l[g];if(o.has(e))continue;const t=u.length,n=M(g,-1,this._pageSize),s=M(t,-1,this._pageSize);if(e.node&&(e.node.index=s),h[g]=s,u.push(e),n!==s){const t=e.node?.id??e.ref?.id;if(null==t)throw new Error("Node has no id");i(t,n,s),r.set(n,s)}}for(let g=0;g<u.length;++g){const e=M(g,-1,this._pageSize),t=u[g],i=c.length;for(let n=t.childOffset;n<t.childOffset+t.childCount;++n){const t=d[n];if(t>=0)c.push(t);else{const i=E(t,this._pageSize),n=l[i];if(o.has(n))continue;const s=h[i];c.push(s),n.parent=e}}t.childOffset=i,t.childCount=c.length-i,t.node&&(t.node.childCount=t.childCount)}n.nodes=u,n.children=c,this._updateParentBoundingInformation(h[E(s,this._pageSize)])}_updateParentBoundingInformation(e){let t=e;do{let e=null;const n=this._clientNodeLoader.indexSR,a=this._clientNodeLoader.renderSR,l=this._getNodeInternal(t);if(null==l)return;for(let o=0;o<l.childCount;o++){const l=this.getChildIndex(t,o),d=this._getNodeInternal(l),h=null!=d?d.ref||d.node:null;if(null!=h&&h.serviceMbsInIndexSR[3]>0)if(null==e)e=s(h.serviceMbsInIndexSR,D);else{const t=k,s=z,o=T;i(h.serviceMbsInIndexSR,n,t,a),i(e,n,s,a),r(t,s,o),i(o,a,e,n)}}const d=t=>{null!=t&&(t.serviceObbInIndexSR=null,null!=e?(t.serviceMbsInIndexSR??=o(),s(e,t.serviceMbsInIndexSR)):g(t.serviceMbsInIndexSR),t.invalidateServiceBVsInRenderSR(),t.geometryObbInRenderSR=null)};d(l.ref),d(l.node),this.invalidateNodeVisibilityCacheInternal(l),t=this.getParentIndex(t)}while(null!=t)}populateChildren(e,t){const i=this._getNodeInternal(e),n=this._getPage(e);i.childOffset=n.children.length,i.childCount=t.length;for(let s=0;s<t.length;s++){const i=this._makeRefNode(t[s],e);n.children.push(i)}}getNode(e){const t=this._getNodeInternal(e);return null!=t?t.node:null}getIndexById(e){let t;return this._forAllNodes(((i,n)=>{(null!=i.node&&i.node.id===e||null!=i.ref&&i.ref.id===e)&&(t=n)})),t}getNodeById(e){const t=this.getIndexById(e);return null!=t&&t>=0?this.getNode(t):null}getChildIndex(e,t){const i=this._getPage(e);if(null==i)return-1;const n=i.nodes[E(e,this._pageSize)];return i.children[n.childOffset+t]}getParentIndex(e){const t=this._getPage(e);return null!=t&&e!==this._rootIndex?t.nodes[E(e,this._pageSize)]?.parent:null}getParent(e){const t=this.getParentIndex(e);return null!=t?this.getNode(t):null}isLeaf(e){const t=this._getNodeInternal(e);return null!=t&&0===t.childCount}get rootNode(){return this.getNode(this._rootIndex)}get isEditable(){return this._isEditable}removeAllGeometryObbs(){this._forAllNodes((e=>{null!=e.node&&(e.node.geometryObbInRenderSR=null)}))}invalidateVisibilityCache(){this._visibilityCacheVersion=x(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(e){const t=this._getNodeInternal(e);null!=t&&this.invalidateNodeVisibilityCacheInternal(t)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=P(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(e){const t=this._getNodeInternal(e);null!=t&&(t?.invalidateBounds(),this.invalidateNodeVisibilityCacheInternal(t))}updateElevationChanged(e){const t=this._getNodeInternal(e);if(null==t)return;if(!this.needNodeElevationRange)return void this.invalidateBoundingVolumeCache(e);const i=null!=t.node?t.node:t.ref;null!=i&&i.invalidateElevationRange()}invalidateGeometryVisibility(e){const t=this._getNodeInternal(e),i=t?.node;i&&(i.geometryObbInRenderSR=null,i.invalidateServiceBVsInRenderSR())}invalidateVisibilityObbs(){null!=this.rootNode&&this.traverse(this.rootNode,(e=>(e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.geometryObbInRenderSR=null,!0)))}_isElevationRangeUpToDate(e){if(!this.needNodeElevationRange)return!0;const t=e?.node??e?.ref;return!t||t.elevationRangeValid}updateElevationRange(e){this._updateElevationRangeInternal(e,null)}_updateElevationRangeInternal(e,t){const i=this._getNodeInternal(e);if(!i)return!1;const n=i?.node??i?.ref;if(!n)return!1;if(n.elevationRangeValid)return t?.expandElevationRange(n),!0;const s=new m;let o=!1;for(let l=0;l<i.childCount;l++){const t=this.getChildIndex(e,l),i=this._updateElevationRangeInternal(t,s);o=o||!i}if(0===i.childCount||o){const e=!i.node?.resources.isEmpty;this._viewportQueries.expandElevationRange(n,e,s)}const r=n.elevationRangeMin,a=n.elevationRangeMax;return r===s.elevationRangeMin&&a===s.elevationRangeMax?(t?.expandElevationRange(n),!0):(i.node?.setElevationRange(s),i.ref?.setElevationRange(s),this.invalidateBoundingVolumeCache(e),t?.expandElevationRange(n),!0)}isNodeVisible(e){const t=this._getNodeInternal(e);if(null==t)return!0;const i=t.ref;if(null!=i&&!i.serviceMbsInIndexSR)return!0;if(this._isElevationRangeUpToDate(t)&&R(t.visibilityCache,this._visibilityCacheVersion))return C(t.visibilityCache);const n=t.node,s=this._viewportQueries;if(n){const e=s.ensureElevationAgnosticBoundingVolume(n),i=s.isElevationAgnosticBoundingVolumeVisible(e);let o=i;if(this.needNodeElevationRange&&i){const t=s.getNodeObbInRenderSRIndependentOfElevationOffset(n);null!=t&&(o=s.isObbVisibleIndependentOfElevation(e,t))}if(!o)return t.visibilityCache=S(!1,this._visibilityCacheVersion),!1}if(this._layerHasFilter&&this._computeNodeFiltering&&(null!=n||null!=i)&&t.filterImpact===h.NotChecked){const e=null!=n?n.serviceMbsInIndexSR:null!=i?i.serviceMbsInIndexSR:null;t.filterImpact=null!=e?this._computeNodeFiltering(e):h.Unmodified}const o=null!=n&&t.filterImpact===h.Culled;let r=!(null!=n&&n.imModificationImpact===u.Culled)&&!o;if(r){const t=!n||i&&!n.visibilityObbInRenderSR?i??null:n;if(null!=t){this.needNodeElevationRange&&this.updateElevationRange(e);r=s.isNodeVisible(t)}}return t.visibilityCache=S(r,this._visibilityCacheVersion),r}isGeometryVisible(e){if(!this.isNodeVisible(e))return!1;const t=this._getNodeInternal(e);return!!(null==t?.node?.geometryObbInRenderSR||this.layerHasModifications&&t.node.imModificationImpact===u.NotChecked)||this._viewportQueries.isGeometryVisible(t.node)}_traverseCoverage(e,t,i,n,s){const o=this._getPage(e);if(null==o||0===t.childCount)return;const r=t.childOffset+t.childCount,a=new Array;for(let l=t.childOffset;l<r;++l){const e=o.children[l],t=this._getNodeInternal(e);null!=t?.node&&this.isGeometryVisible(e)&&a.push(t)}n/=a.length;for(const l of a){const e=l.node.index;this._isLoaded(e)||this._isReloading(e)?(s.delta=Math.max(s.delta,i),s.coverage+=n):this._traverseCoverage(e,l,i+1,n,s)}}useNodeAsHole(e){if("off"===this.holeFilling)return!1;const t=this._getNodeInternal(e);if(null==t)return!1;if("always"===this.holeFilling)return!0;if(R(t.useAsHole,this._version))return C(t.useAsHole);const i={delta:0,coverage:0};this._traverseCoverage(e,t,0,1,i);const n=i.delta*i.coverage<=.5;return t.useAsHole=S(n,this._version),n}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.add.prune(),this._updates.update.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=x(this._version)}imModificationsChanged(e){this.layerHasModifications=e,this._forAllNodes((({node:e})=>{null!=e&&(e.imModificationImpact=u.NotChecked,e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.hasModifications&&this.invalidateGeometryVisibility(e.index))})),this.invalidateVisibilityCache()}layerFilterChanged(e){this._layerHasFilter=e,this._forAllNodes((e=>{if(null!=e){e.filterImpact=h.NotChecked;const t=e.node;null!=t&&this.invalidateNodeVisibilityCache(t.index)}})),this.invalidateVisibilityCache()}update(e,t,i){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(t),this._invalidateElevationRangeForNewPages(t),this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.NEGATIVE_INFINITY,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._updates.reset(e),I.clear();let n=!0;const s=new A,o=new L,r=this._imModificationUncategorized;r.clear();const a=new Set;let l=0;const d=(a,d,h)=>{const c=w(a,this._pageSize);if(null==d){let e=this._entryPriority(a);return e===1/0&&(e=this._entryPriority(h)),I.set(c,Math.max(e,I.get(c)||0)),this._loadingPages.has(c)||this._failedPages.has(c)||(this._missingPagesAndNodes.push(c),++l),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const g=d.node;if(this._updateNodeFeatureEstimate(g,o),null==g){const e=this._entryPriority(a);return this._loadingNodes.has(a)||this._failedNodes.has(a)||(this._missingPagesAndNodes.push(a),I.set(a,e)),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const _=this._getPage(a);if(0===this._missingPagesAndNodes.length&&!this._useNodePages)for(let e=0;e<d.childCount;e++){const t=_.children[d.childOffset+e],i=this._getNodeInternal(t);null!=i&&!i.node&&!this._loadingNodes.has(t)&&!this._failedNodes.has(t)&&t>=0&&(I.set(t,this._entryPriority(t)),this._prefetchNodes.push(t))}if(g.failed||g.resources.isEmpty)return void(n&&d.childCount>0&&this._isSelected(g)&&(n=!1));if(this._isLoaded(a)){if(s.known+=g.memory,++s.knownNodes,this._isSelected(g)?d.childCount>0&&(n=!1):(s.unremoved+=g.memory,n=!1),this._needsUpdate(g)){const e=this._entryPriority(a);I.set(a,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(a)}return}if(g.memory&&(s.known+=g.memory,++s.knownNodes),!this._isSelected(g))return void(this._isReloading(a)&&this._updates.remove.push(a));if(d.childCount>0&&(n=!1),g.memory?(s.missing+=g.memory,s.known+=g.memory,++s.knownNodes):++s.missingNodes,e.includes(g.index))return this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._entryPriority(a)),void(this._updates.cancel=this._updates.cancel.filter((e=>e!==g.index)));if(!t.done&&this._enable(g))return void t.madeProgress();const f=this._entryPriority(a);I.set(a,f),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,f),this._updates.add.push(a),this.layerHasModifications&&i&&null!=g&&g.imModificationImpact===u.NotChecked&&r.push(a)};this.traverseVisible(d,a),this._frameNumber++,this._missingPagesAndNodes.sort(((e,t)=>e-t)),this._missingPagesAndNodes.filterInPlace(((e,t)=>t<1||this._missingPagesAndNodes.data[t-1]!==e)),this._missingPagesAndNodes.sort(((e,t)=>I.get(e)-I.get(t))),this._missingPagesAndNodes.length>0&&(this._maxUnloadedPrio=I.get(this._missingPagesAndNodes.back()),this._prefetchNodes.clear()),this._removeUnusedNodePages(a,l);const h=this._updates.add;h.length>0&&this.layerHasModifications&&(r.length>0&&i?.(r),h.filterInPlace((e=>{const t=this._getNodeInternal(e),i=null==t?.node||t.node.imModificationImpact!==u.Culled;return i||this.invalidateNodeVisibilityCache(e),i}))),this._unloadedMemoryEstimate=s.missing-s.unremoved,s.knownNodes>3&&s.missingNodes>0&&(this._unloadedMemoryEstimate+=s.known/s.knownNodes*s.missingNodes),this._unloadedMemoryEstimate=.8*Math.max(0,this._unloadedMemoryEstimate),this._featureEstimate.estimate=this._computeFeatureEstimate(o),this._featureEstimate.leavesReached=n,this._updates.add.filterInPlace((e=>I.get(e)>=this._maxUnloadedPrio)).sort(((e,t)=>I.get(e)-I.get(t))),this._updates.update.sort(((e,t)=>I.get(e)-I.get(t))),this._indexMissing=this._loadingPages.size+this._loadingNodes.size+this._missingPagesAndNodes.length,this._dirty=this._indexMissing>0,I.clear()}checkFeatureTarget(e,t){const i=this._viewportQueries.updateScreenSpaceErrorBias(t);let n=t,s=t,o=i,r=10;for(;r--;){const i=new L;this._updateFeatureEstimate(n,i);if(this._computeFeatureEstimate(i)<=e){if(n>=t||i.missingNodes>0||0===r)break;o=n,n=.5*(n+s)}else s=n,n=.5*(n+o)}return this._version=x(this._version),this._viewportQueries.updateScreenSpaceErrorBias(i),Math.min(t,n)}_removeUnusedNodePages(e,t){if(!this._useNodePages)return;const i=e.size,n=this._nodePages,s=n.size+this._loadingPages.size+t;if(s>B&&s>i){const t=new Array;for(const[i,s]of n)0!==s.numNodesWithLoadedChildren||e.has(i)||t.push([s.lastTraversed,i]);t.sort(((e,t)=>e[0]-t[0])).some((e=>{const t=e[1];return this._deleteNodePage(t),n.size<=B}))}}_updateFeatureEstimate(e,t){this._version=x(this._version),this._viewportQueries.updateScreenSpaceErrorBias(e),this.traverseVisible(((e,i)=>this._updateNodeFeatureEstimate(i?.node,t)))}_updateNodeFeatureEstimate(e,t){null!=e&&!e.failed&&this._isSelected(e)&&(null!=e.numFeatures?(t.numFeatures+=e.numFeatures,++t.knownNodes):++t.missingNodes)}_computeFeatureEstimate(e){let t=e.numFeatures;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.numFeatures/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._missingPagesAndNodes)}prefetch(){return this._prefetchNodes.sort(((e,t)=>I.get(e)-I.get(t))),this._load(this._prefetchNodes)}_load(e){if(0===e.length||!this._canRequest())return!1;for(;e.length>0&&this._canRequest();){const t=e.pop();this._useNodePages&&t>=0?this._loadPage(t):this._loadNode(t)}return!0}get isLoading(){return this._indexMissing>0}get isPrefetching(){return this._prefetchNodes.length>0}get indexLoading(){return this._loadingPages.size+this._loadingNodes.size}get indexMissing(){return this._indexMissing}get unloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}get maxPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}nodeTraversalState(e){if(null==e)return null;const t=e.index,i=this._getNodeInternal(t);if(!i)return null;let n=i?.traversalState;if(n&&R(n.version,this._version))return n;const s=this._viewportQueries.getLodLevel(e),o=this._viewportQueries.hasLOD(e);let r=!0;if(o){const e=this.getParentIndex(t);if(null!=e){const t=this._getNodeInternal(e),i=t?.traversalState;r=!!i&&s>i.lodLevel}else r=s>0}else r=0===e.childCount;return n?(n.lodLevel=s,n.isChosen=r,n.version=S(!0,this._version),n):(n=new c(o,r,s,S(!0,this._version)),i.traversalState=n,n)}async _loadNode(e){this._loadingNodes.add(e);const i=this._getNodeInternal(e).ref;if(null==i)return void this._failedNodes.add(e);const n=i.id,s=this._urlPrefix+n,o=()=>{this._loadingNodes.delete(e),0===this._missingPagesAndNodes.length&&0===this._loadingNodes.size&&this.requestUpdate()};let r=null;try{r=e>=0?await this._streamDataController.request(s,"json"):await this._clientNodeLoader.loadNodeJSON(n)}catch(d){return o(),void(t(d)||(this._logger.error("#loadNode()",this._layer,"Error loading node: "+s),this._failedNodes.add(e)))}o();const a=this._validateNode(n,r);if(null==a)return;a.obb&&this.invalidateNodeVisibilityCache(e);const l=this._addNode(a,e);this.nodeTraversalState(l)}_validateNode(e,t){if(null==t||"object"!=typeof t||t.id!==e)return this._logger.error("#validateNode()",this._layer,`Invalid node. Wrong type or wrong id "${e}"`),null;if(!Array.isArray(t.mbs))return this._logger.error("#validateNode()",this._layer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&"./shared"!==t.sharedResource.href&&"./shared/"!==t.sharedResource.href&&this._logger.warn("#validateNode()",this._layer,`Invalid shared resource href on node "${e}"`);const i=t.geometryData;null==i||Array.isArray(i)&&0===i.length||Array.isArray(i)&&1===i.length&&"./geometries/0"===i[0].href||this._logger.warn("#validateNode()",this._layer,`Invalid geometry data on node "${e}"`);const n=t.attributeData,s=this._layer.attributeStorageInfo;null==n||Array.isArray(n)&&!n.some(((e,t)=>e.href!==`./attributes/${s?.[t]?.key??`f_${t}`}/0`))||this._logger.warn("#validateNode()",this._layer,`Invalid attribute data on node "${e}"`),t.featureData&&t.featureData.length>1&&this._logger.warn("#validateNode()",this._layer,`Node ${e} has ${t.featureData.length} bundles. Only the first bundle will be loaded.`);const o=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:void 0,r=t.featureData&&1===t.featureData.length&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:void 0,a=t=>{if(null==t)return null;const i=t=>this._logger.error("#validateNode()",this._layer,`Invalid node reference on node ${e}: ${t}`);if("number"==typeof t.id)i(`id ${t.id} is a number instead of a string.`);else if("string"!=typeof t.id||!Array.isArray(t.mbs))return i("Missing or invalid id."),null;if(!Array.isArray(t.mbs))return i(`Invalid bounding volume on reference ${t.id}.`),null;t.href&&t.href!=="../"+t.id&&this._logger.error("#validateNode()",this._layer,`Invalid node href on node "${e}"`);const n=new l(`${t.id}`,t.mbs);return n.serviceObbInIndexSR=!this.ignoreServiceObb&&t.hasOwnProperty("obb")&&t.obb?v.fromJSON(t.obb):null,n.visibilityObbInRenderSR=this._computeVisibilityObb(n),n},d=Array.isArray(t.children)?t.children.map(a).filter((e=>null!=e)):null,h=t.featureData?.length??!1,u=!0===t.isEmpty;return new f(e,t.mbs,o,"string"==typeof t.version?t.version:null,{isEmpty:!h&&u,hasSharedResource:null!=t.sharedResource,attributes:t.attributeData?e:void 0,texture:t.textureData&&t.textureData.length>0?e:void 0,geometry:null!=t.geometryData?e:void 0},d,Array.isArray(t.lodSelection)?t.lodSelection:null,r)}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes((e=>{null!=e.node&&(e.node.failed=!1)}))}_entryPriority(e){const t=this._getNodeInternal(e),i=this.getParentIndex(e);if(null==t||null==i&&null==t.node)return null==i?1/0:this._entryPriority(i);let n=0;if(t.node&&null!=i){const e=this._getNodeInternal(i).traversalState;null!=e&&(n=e.lodLevel)}let s=this.progressiveLoadPenalty;for(let r=e;null!=r;r=this.getParentIndex(r))if(this._isLoaded(r)){s=0;break}const o=null!=t.ref?this._viewportQueries.distToPOI(t.ref):null!=t.node?this._viewportQueries.distToPOI(t.node):0;return-o-n*(o+this.progressiveLoadPenalty)+s}traverseVisible(e,t){const i=this._getNodeInternal(this._rootIndex);null!=i?this._traverseVisible(this._rootIndex,null,i,e,t):e(this._rootIndex,null,null)}_traverseVisible(e,t,i,n,s){const o=w(e,this._pageSize);if(s&&s.add(o),i.node&&0===i.childCount)return void(this.isGeometryVisible(e)&&n(e,i,t));if(!this.isNodeVisible(e))return;if(n(e,i,t),null==i.node)return;const r=this.nodeTraversalState(i.node);if(r?.nodeHasLOD&&r.lodLevel===this._maxLodLevel)return;const a=this._getPageFromPageIndex(o);for(let l=0;l<i.childCount;l++){const t=a.children[i.childOffset+l],o=this._getNodeInternal(t);if(o)this._traverseVisible(t,e,o,n,s);else{if(s){const e=w(t,this._pageSize);s.add(e)}n(t,null,e)}}}traverse(e,t){t(e)&&this.traverseDescendants(e,t)}traverseDescendants(e,t){++this._traverseDescendantsNestingLevel;const i=e.index,n=this._pageSize,s=w(i,n),o=this._getPageFromPageIndex(s);if(null==o)return;const r=this._frameNumber,a=this._nodePages,l=E(i,n),d=o.nodes[l],h=d.childCount;if(o.lastTraversed=r,0===h)return;const u=new Array,c=1===this._traverseDescendantsNestingLevel?this._traverseDescendantsQueue:[0];let g=0;{const{childOffset:e,childCount:t}=d,{children:i}=o;c.length=2**Math.ceil(Math.log2(g+t));for(let n=e;n<e+t;++n){const e=i[n];e>=0?(c[g]=e,++g):u.push(e)}}if(u.length>0){const e=this._clientNodePage;if(e){const i=e.children;let n=0;for(;n<u.length;){const s=u[n];++n;const o=-s-1,r=e.nodes[o],a=r.node;if(!a||!t(a))continue;const{childCount:l}=r;if(0===l)continue;const{childOffset:d}=r,h=d+l;for(let e=d;e<h;++e)u.push(i[e])}}}if(g>0){let e=0;if(n>0){let i=s*n,l=o,d=l.nodes;for(;e<g;){const s=c[e];let o;if(++e,i<=s&&s<i+n)o=l;else{const e=s/n|0,t=a.get(e);if(void 0===t)continue;o=t,o.lastTraversed=r,l=o,d=l.nodes,i=n*e}const h=d[s-i],u=h.node;if(null==u||!1===t(u))continue;const{childCount:_}=h;if(0===_)continue;const f=g+_;for(c.length<f&&(c.length=2**Math.ceil(Math.log2(g+_)));c.length<g+_;)c.length+=c.length;const m=o.children,{childOffset:v}=h,N=v+_;for(let e=v;e<N;++e)c[g]=m[e],++g}}else{const i=a.get(0);if(i)for(;e<g;){const n=c[e++],s=i.nodes[n],o=s.node;if(!o||!t(o))continue;const{childCount:r}=s;if(0===r)continue;c.length=Math.max(c.length,2**Math.ceil(Math.log2(g+r)));const a=i.children,{childOffset:l}=s,d=l+r;for(let e=l;e<d;++e)c[g]=a[e],++g}}}--this._traverseDescendantsNestingLevel}updateChildrenLoaded(e,t){let i=this.getNode(e);for(;null!=i;){const e=i.childrenLoaded,n=e+t;i.childrenLoaded=n;const s=0===e?1:0===n?-1:0,o=i.index;if(0!==s){this._getPage(o).numNodesWithLoadedChildren+=s}i=this.getParent(o)}}checkChildrenLoadedInvariant(){return!0}updateElevationInfo(e,t){this.needNodeElevationRange=t&&!!e&&("relative-to-ground"===e.mode||"relative-to-scene"===e.mode||"on-the-ground"===e.mode),this._viewportQueries.updateElevationInfo(e),this.invalidateAllElevationRanges()}invalidateAllElevationRanges(){this._forAllNodes((e=>{e?.invalidateBounds(),e.node?.invalidateElevationRange(),e.ref?.invalidateElevationRange()}))}_forAllNodes(e){if(null!=this._clientNodePage){const t=this._clientNodePage;for(let i=0;i<t.nodes.length;i++)e(t.nodes[i],-(i+1))}for(const[t,i]of this._nodePages){const n=t*this._pageSize;for(let t=0;t<i.nodes.length;t++)e(i.nodes[t],n+t)}}clearCaches(){if(this._useNodePages){const e=this._nodePages,t=new Set;this.traverseVisible((e=>t.add(w(e,this._pageSize))));for(const[i,n]of e)if(0!==n.numNodesWithLoadedChildren||t.has(i))for(const e of n.nodes)e.traversalState=null;else this._deleteNodePage(i)}}_deleteNodePage(e){this._nodePages.delete(e)}get test(){}}const I=new Map;class y{constructor(t){this.missing=t,this.update=new e({deallocator:null}),this.add=new e({deallocator:null}),this.remove=new e({deallocator:null}),this.cancel=[]}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function P(e){return _(e,-2)}function x(e){return _(e,2)}function S(e,t){return t+(e?1:0)}function R(e,t){return(-2&e)===t}function C(e){return!(1&~e)}function w(e,t){return e<0?-1:t>0?e/t|0:0}function E(e,t){return e<0?-e-1:0===t?e:e%t}function M(e,t,i){return-1===t?-(e+1):0===i?e:t*i+e}const V=[["maxScreenThreshold",a.MaxScreenThreshold],["screenSpaceRelative",a.ScreenSpaceRelative],["removedFeatureDiameter",a.RemovedFeatureDiameter],["distanceRangeFromDefaultCamera",a.DistanceRangeFromDefaultCamera]];function O(e){if(e)for(let t=0;t<e.length;t++)for(const i of V)if(i[0]===e[t].metricType)return{lodMetric:i[1],maxError:e[t].maxError};return{lodMetric:a.None,maxError:0}}class A{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}class L{constructor(){this.numFeatures=0,this.knownNodes=0,this.missingNodes=0}}function F(e){return Math.sqrt(e*(4/Math.PI))}const D=o(),k=o(),z=o(),T=o(),B=has("esri-mobile")?100:300;export{b as I3SIndex,O as selectErrorMetric};
5
+ import has from"../../../../core/has.js";import e from"../../../../core/PooledArray.js";import{isAbortError as t}from"../../../../core/promiseUtils.js";import{projectBoundingSphere as i}from"../../../../geometry/projection/projectBoundingSphere.js";import{h as n,k as s,c as o,u as r}from"../../../../chunks/sphere.js";import{LodMetric as a,NodeBase as l,Node as d,NodeFilterImpact as h,NodeIMModificationImpact as u,NodeTraversalState as c}from"./I3SNode.js";import{invalidateMbs as g,addWraparound as _}from"./I3SUtil.js";import{ValidatedNode as f}from"./ValidatedNode.js";import{ElevationRange as m}from"../../support/ElevationRange.js";import{Obb as v}from"../../support/orientedBoundingBox.js";class N{constructor(e,t,i,n,s){this.childOffset=e,this.childCount=t,this.visibilityCache=i,this.ref=n,this.node=s,this.useAsHole=0,this.filterImpact=h.NotChecked,this.traversalState=null,this.parent=-1}invalidateBounds(){this.node?.invalidateServiceBVsInRenderSR(),this.ref?.invalidateServiceBVsInRenderSR()}}class p{constructor(e=new Array,t=new Array){this.nodes=e,this.children=t,this.lastTraversed=0,this.numNodesWithLoadedChildren=0}}class b{get _useNodePages(){return this._pageSize>0}constructor(t,i,n,s,o,r,l,d,h,u,c,g,_,f,m,v){this.viewingMode=t,this._layer=i,this._streamDataController=s,this._clientNodeLoader=o,this._viewportQueries=r,this._logger=l,this.holeFilling=d,this._isLoaded=h,this._isReloading=u,this._isSelected=c,this._enable=g,this._needsUpdate=_,this._canRequest=f,this._computeVisibilityObb=m,this._computeNodeFiltering=v,this._dirty=!0,this._nodePages=new Map,this._clientNodePage=null,this._pageSize=0,this._rootIndex=0,this._lodMetric=a.None,this._lodConversion=e=>e,this._isEditable=!1,this._urlPrefix="",this._loadingNodes=new Set,this._loadingPages=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.POSITIVE_INFINITY,this._version=x(0),this._visibilityCacheVersion=x(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._missingPagesAndNodes=new e({deallocator:null}),this._prefetchNodes=new e({deallocator:null}),this._updates=new y(this._missingPagesAndNodes),this._imModificationUncategorized=new e({deallocator:null}),this.ignoreServiceObb=!1,this.progressiveLoadPenalty=0,this._pageQueue=new Array,this._newPages=new Array,this.needNodeElevationRange=!1,this.layerHasModifications=!1,this._layerHasFilter=!1,this._frameNumber=0,this._traverseDescendantsQueue=[0],this._traverseDescendantsNestingLevel=0,this._isEditable=null!=i.associatedLayer?.infoFor3D,i.serviceUpdateTimeStamp?.lastUpdate&&(this._lastUpdate=`${i.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this._viewportQueries?this._viewportQueries.maxLodLevel:1,this._init(n)}_init(e){if("page"===e.type){const t=e.rootPage;switch(this._urlPrefix=e.urlPrefix,this._pageSize=e.pageSize,e.lodMetric){case"maxScreenThreshold":this._lodMetric=a.MaxScreenThreshold;break;case"maxScreenThresholdSQ":this._lodMetric=a.MaxScreenThreshold,this._lodConversion=F}if(this._isEditable){this._rootIndex=-1;const i=E(e.rootIndex,e.pageSize),n=t.nodes[i],s={nodes:[{index:this._rootIndex,children:[e.rootIndex],mesh:void 0,obb:n.obb,lodThreshold:n.lodThreshold}]};this._addPage(w(this._rootIndex,this._pageSize),s),this.getNode(-1).serviceObbInIndexSR=void 0}else this._rootIndex=e.rootIndex;this._addPage(w(e.rootIndex,this._pageSize),t),this._updateParentsAndLevel()}else if("node"===e.type){this._urlPrefix=e.urlPrefix;const t=new p;if(this._nodePages.set(0,t),this._isEditable){this._clientNodePage=new p;const t={id:"-1",version:null,mbs:e.rootNode.mbs,obb:e.rootNode.obb,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:[{id:"root",href:"../root",mbs:e.rootNode.mbs,obb:e.rootNode.obb}]};this._rootIndex=this._makeClientRefNode(new l(t.id,null),-1);const i=this._validateNode(t.id,t);i&&this._addNode(i,this._rootIndex)}else this._rootIndex=this._makeRefNode(new l(e.rootNode.id,null),-1);const i=this._validateNode(e.rootNode.id,e.rootNode);i&&this._addNode(i,0)}}addClientNodeToIndex(e,t){const i=-1,n=new l(e,t),s=this._makeClientRefNode(n,i);return this._linkChildToParentNode(i,s),this.requestUpdate(),s}removeClientNodeFromIndex(e,t,i){this._destroyClientRefNode(e,t,i),this.requestUpdate()}_loadPage(e){this._loadingPages.add(e);const i=this._urlPrefix+e;this._streamDataController.request(i,"json").then((t=>{this._pageQueue.push({pageIndex:e,page:t})})).catch((i=>{this._loadingPages.delete(e),t(i)||(this._failedPages.add(e),this._logger.error("#loadPage()",this._layer,`Error when loading page ${e}`,i))}))}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){const{pageIndex:t,page:i}=this._pageQueue.shift();this._addPage(t,i),this._loadingPages.delete(t),e.madeProgress(),this.needNodeElevationRange&&this._newPages.push(t)}this._updateParentsAndLevel()}_invalidateElevationRangeForNewPages(e){if(this.needNodeElevationRange)for(;this._newPages.length>0&&!e.done;){const e=this._nodePages.get(this._newPages.shift());e?.nodes.forEach((e=>{let t=e.parent;for(;null!=t&&t!==this._rootIndex;){const e=this.getNode(t);e&&!Number.isNaN(e?.elevationRangeMin)&&(e.invalidateElevationRange(),this.invalidateBoundingVolumeCache(t)),t=this.getParentIndex(t)}}))}}_addPage(e,t){const i=[],s=[],o=t.nodes.map(((t,o)=>{const r=i.length,a=t.children?t.children.length:0;s.push(this._rootIndex);for(let e=0;e<a;e++)i.push(t.children[e]);const l=`${t.index}`,h=v.fromJSON(t.obb),u=n(h.center,h.radius),c=t.mesh?.attribute,g=t.mesh?.geometry,_=t.mesh?.material,f={hasSharedResource:!1,isEmpty:null==g,attributes:null!=c?.resource?`${c.resource}`:void 0,geometry:null!=g?.resource?`${g.resource}`:void 0,texture:null!=_?.resource?`${_.resource}`:void 0,geometryDefinition:g?g.definition:-1,materialDefinition:_?_.definition:-1},m=new d(l,M(o,e,this._pageSize),u,a,0,f,this._lastUpdate,this._lodMetric,this._lodConversion(t.lodThreshold),g?.featureCount??null);return m.serviceObbInIndexSR=h,m.visibilityObbInRenderSR=this._computeVisibilityObb(m),m.vertexCount=g?g.vertexCount:0,new N(r,a,P(this._visibilityCacheVersion),null,m)})),r=new p(o,i);-1===e?this._clientNodePage=r:this._nodePages.set(e,r)}_updateParentsAndLevel(){const e=new Array,t=(t,i,n)=>{const s=this._getPage(t);if(null!=s){const o=E(t,this._pageSize),r=s.nodes[o];r.parent=null!=i?i:-1;const a=r.node;null!=a&&(a.level=n,e.push(t))}};for(t(this._rootIndex,null,0);e.length;){const i=e.pop(),n=this.getNode(i);if(null!=n)for(let e=0;e<n.childCount;e++){t(this.getChildIndex(n.index,e),i,n.level+1),this._maxLevel=Math.max(this._maxLevel,n.level+1)}}}_getPage(e){const t=w(e,this._pageSize);return this._getPageFromPageIndex(t)}_getPageFromPageIndex(e){return e<0?this._clientNodePage:this._nodePages.get(e)}_getNodeInternal(e){const t=this._getPage(e);return null==t?null:(t.lastTraversed=this._frameNumber,t.nodes[E(e,this._pageSize)])}_addNode(e,t){e.children&&this.populateChildren(t,e.children);const i=this.getParent(t),n=null!=i?i.level+1:0;this._maxLevel=Math.max(this._maxLevel,e.children?n+1:n);const{lodMetric:s,maxError:o}=O(e.lodSelection),r=this._getNodeInternal(t),a=new d(e.id,t,e.mbs,r.childCount,n,e.resources,e.version,s,o,e.numFeatures);r.node=a,e.obb&&(a.serviceObbInIndexSR=v.fromJSON(e.obb)),a.visibilityObbInRenderSR=this._computeVisibilityObb(a);const l=r.ref;return null!=l&&(null==l.serviceMbsInIndexSR&&(l.serviceMbsInIndexSR=e.mbs),a.shareServiceBVsInRenderSRWith(l),l.visibilityObbInRenderSR=a.visibilityObbInRenderSR),a}_makeRefNode(e,t){const i=this._nodePages.get(0);if(t<-1)return this._makeClientRefNode(e,t);if(null==i)return-1;const n=i.nodes.length,s=new N(0,0,P(this._visibilityCacheVersion),e,null);return i.nodes.push(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_makeClientRefNode(e,t){const i=this._clientNodePage;if(null==i)return-1;if(t>=0)throw new Error("I3SIndex::client side nodes can not be made children of service side nodes.");const n=-(i.nodes.length+1),s=new N(0,0,P(this._visibilityCacheVersion),e,null);return i.nodes.push(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_linkChildToParentNode(e,t){const i=this._clientNodePage;if(null==i||e>=0)return;const n=E(e,this._pageSize),s=E(t,this._pageSize),o=i.nodes[n],r=o.childOffset;i.children.splice(o.childOffset+o.childCount,0,t);const a=1;o.childCount+=a,null!=o.node&&(o.node.childCount+=a);for(const l of i.nodes)l.childOffset>r&&(l.childOffset+=a);i.nodes[s].parent=e,this._updateParentBoundingInformation(e)}_destroyClientRefNode(e,t,i){const n=this._clientNodePage;if(null==n)return;const s=this.getParentIndex(e);if(null==s)return;const o=new Set,r=new Map,a=e=>{const i=E(e,this._pageSize),s=n.nodes[i];if(s.childCount>0)for(let t=s.childOffset;t<s.childOffset+s.childCount;++t)a(n.children[t]);const r=s.node?.id??s.ref?.id;if(null==r)throw new Error("Node has no id");t(r,e),o.add(s)};a(e);const l=n.nodes,d=n.children,h=n.nodes.map((()=>-1)),u=[],c=[];for(let g=0;g<l.length;++g){const e=l[g];if(o.has(e))continue;const t=u.length,n=M(g,-1,this._pageSize),s=M(t,-1,this._pageSize);if(e.node&&(e.node.index=s),h[g]=s,u.push(e),n!==s){const t=e.node?.id??e.ref?.id;if(null==t)throw new Error("Node has no id");i(t,n,s),r.set(n,s)}}for(let g=0;g<u.length;++g){const e=M(g,-1,this._pageSize),t=u[g],i=c.length;for(let n=t.childOffset;n<t.childOffset+t.childCount;++n){const t=d[n];if(t>=0)c.push(t);else{const i=E(t,this._pageSize),n=l[i];if(o.has(n))continue;const s=h[i];c.push(s),n.parent=e}}t.childOffset=i,t.childCount=c.length-i,t.node&&(t.node.childCount=t.childCount)}n.nodes=u,n.children=c,this._updateParentBoundingInformation(h[E(s,this._pageSize)])}_updateParentBoundingInformation(e){let t=e;do{let e=null;const n=this._clientNodeLoader.indexSR,a=this._clientNodeLoader.renderSR,l=this._getNodeInternal(t);if(null==l)return;for(let o=0;o<l.childCount;o++){const l=this.getChildIndex(t,o),d=this._getNodeInternal(l),h=null!=d?d.ref||d.node:null;if(null!=h&&h.serviceMbsInIndexSR[3]>0)if(null==e)e=s(h.serviceMbsInIndexSR,D);else{const t=k,s=z,o=T;i(h.serviceMbsInIndexSR,n,t,a),i(e,n,s,a),r(t,s,o),i(o,a,e,n)}}const d=t=>{null!=t&&(t.serviceObbInIndexSR=null,null!=e?(t.serviceMbsInIndexSR??=o(),s(e,t.serviceMbsInIndexSR)):g(t.serviceMbsInIndexSR),t.invalidateServiceBVsInRenderSR(),t.geometryObbInRenderSR=null)};d(l.ref),d(l.node),this.invalidateNodeVisibilityCacheInternal(l),t=this.getParentIndex(t)}while(null!=t)}populateChildren(e,t){const i=this._getNodeInternal(e),n=this._getPage(e);i.childOffset=n.children.length,i.childCount=t.length;for(let s=0;s<t.length;s++){const i=this._makeRefNode(t[s],e);n.children.push(i)}}getNode(e){const t=this._getNodeInternal(e);return null!=t?t.node:null}getIndexById(e){let t;return this._forAllNodes(((i,n)=>{(null!=i.node&&i.node.id===e||null!=i.ref&&i.ref.id===e)&&(t=n)})),t}getNodeById(e){const t=this.getIndexById(e);return null!=t&&t>=0?this.getNode(t):null}getChildIndex(e,t){const i=this._getPage(e);if(null==i)return-1;const n=i.nodes[E(e,this._pageSize)];return i.children[n.childOffset+t]}getParentIndex(e){const t=this._getPage(e);return null!=t&&e!==this._rootIndex?t.nodes[E(e,this._pageSize)]?.parent:null}getParent(e){const t=this.getParentIndex(e);return null!=t?this.getNode(t):null}isLeaf(e){const t=this._getNodeInternal(e);return null!=t&&0===t.childCount}get rootNode(){return this.getNode(this._rootIndex)}get isEditable(){return this._isEditable}removeAllGeometryObbs(){this._forAllNodes((e=>{null!=e.node&&(e.node.geometryObbInRenderSR=null)}))}invalidateVisibilityCache(){this._visibilityCacheVersion=x(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(e){const t=this._getNodeInternal(e);null!=t&&this.invalidateNodeVisibilityCacheInternal(t)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=P(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(e){const t=this._getNodeInternal(e);null!=t&&(t?.invalidateBounds(),this.invalidateNodeVisibilityCacheInternal(t))}updateElevationChanged(e){const t=this._getNodeInternal(e);if(null==t)return;if(!this.needNodeElevationRange)return void this.invalidateBoundingVolumeCache(e);const i=null!=t.node?t.node:t.ref;null!=i&&i.invalidateElevationRange()}invalidateGeometryVisibility(e){const t=this._getNodeInternal(e),i=t?.node;i&&(i.geometryObbInRenderSR=null,i.invalidateServiceBVsInRenderSR())}invalidateVisibilityObbs(){null!=this.rootNode&&this.traverse(this.rootNode,(e=>(e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.geometryObbInRenderSR=null,!0)))}_isElevationRangeUpToDate(e){if(!this.needNodeElevationRange)return!0;const t=e?.node??e?.ref;return!t||t.elevationRangeValid}updateElevationRange(e){this._updateElevationRangeInternal(e,null)}_updateElevationRangeInternal(e,t){const i=this._getNodeInternal(e);if(!i)return!1;const n=i?.node??i?.ref;if(!n)return!1;if(n.elevationRangeValid)return t?.expandElevationRange(n),!0;const s=new m;let o=!1;for(let l=0;l<i.childCount;l++){const t=this.getChildIndex(e,l),i=this._updateElevationRangeInternal(t,s);o=o||!i}if(0===i.childCount||o){const e=!i.node?.resources.isEmpty;this._viewportQueries.expandElevationRange(n,e,s)}const r=n.elevationRangeMin,a=n.elevationRangeMax;return r===s.elevationRangeMin&&a===s.elevationRangeMax?(t?.expandElevationRange(n),!0):(i.node?.setElevationRange(s),i.ref?.setElevationRange(s),this.invalidateBoundingVolumeCache(e),t?.expandElevationRange(n),!0)}isNodeVisible(e){const t=this._getNodeInternal(e);if(null==t)return!0;const i=t.ref;if(null!=i&&!i.serviceMbsInIndexSR)return!0;if(this._isElevationRangeUpToDate(t)&&R(t.visibilityCache,this._visibilityCacheVersion))return C(t.visibilityCache);const n=t.node,s=this._viewportQueries;if(n){const e=s.ensureElevationAgnosticBoundingVolume(n),i=s.isElevationAgnosticBoundingVolumeVisible(e);let o=i;if(this.needNodeElevationRange&&i){const t=s.getNodeObbInRenderSRIndependentOfElevationOffset(n);null!=t&&(o=s.isObbVisibleIndependentOfElevation(e,t))}if(!o)return t.visibilityCache=S(!1,this._visibilityCacheVersion),!1}if(this._layerHasFilter&&this._computeNodeFiltering&&(null!=n||null!=i)&&t.filterImpact===h.NotChecked){const e=null!=n?n.serviceMbsInIndexSR:null!=i?i.serviceMbsInIndexSR:null;t.filterImpact=null!=e?this._computeNodeFiltering(e):h.Unmodified}const o=null!=n&&t.filterImpact===h.Culled;let r=!(null!=n&&n.imModificationImpact===u.Culled)&&!o;if(r){const t=!n||i&&!n.visibilityObbInRenderSR?i??null:n;if(null!=t){this.needNodeElevationRange&&this.updateElevationRange(e);r=s.isNodeVisible(t)}}return t.visibilityCache=S(r,this._visibilityCacheVersion),r}isGeometryVisible(e){if(!this.isNodeVisible(e))return!1;const t=this._getNodeInternal(e);return!!(null==t?.node?.geometryObbInRenderSR||this.layerHasModifications&&t.node.imModificationImpact===u.NotChecked)||this._viewportQueries.isGeometryVisible(t.node)}_traverseCoverage(e,t,i,n,s){const o=this._getPage(e);if(null==o||0===t.childCount)return;const r=t.childOffset+t.childCount,a=new Array;for(let l=t.childOffset;l<r;++l){const e=o.children[l],t=this._getNodeInternal(e);null!=t?.node&&this.isGeometryVisible(e)&&a.push(t)}n/=a.length;for(const l of a){const e=l.node.index;this._isLoaded(e)||this._isReloading(e)?(s.delta=Math.max(s.delta,i),s.coverage+=n):this._traverseCoverage(e,l,i+1,n,s)}}useNodeAsHole(e){if("off"===this.holeFilling)return!1;const t=this._getNodeInternal(e);if(null==t)return!1;if("always"===this.holeFilling)return!0;if(R(t.useAsHole,this._version))return C(t.useAsHole);const i={delta:0,coverage:0};this._traverseCoverage(e,t,0,1,i);const n=i.delta*i.coverage<=.5;return t.useAsHole=S(n,this._version),n}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.add.prune(),this._updates.update.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=x(this._version)}imModificationsChanged(e){this.layerHasModifications=e,this._forAllNodes((({node:e})=>{null!=e&&(e.imModificationImpact=u.NotChecked,e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.hasModifications&&this.invalidateGeometryVisibility(e.index))})),this.invalidateVisibilityCache()}layerFilterChanged(e){this._layerHasFilter=e,this._forAllNodes((e=>{if(null!=e){e.filterImpact=h.NotChecked;const t=e.node;null!=t&&this.invalidateNodeVisibilityCache(t.index)}})),this.invalidateVisibilityCache()}update(e,t,i){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(t),this._invalidateElevationRangeForNewPages(t),this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.NEGATIVE_INFINITY,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._updates.reset(e),I.clear();let n=!0;const s=new A,o=new L,r=this._imModificationUncategorized;r.clear();const a=new Set;let l=0;const d=(a,d,h)=>{const c=w(a,this._pageSize);if(null==d){let e=this._entryPriority(a);return e===1/0&&(e=this._entryPriority(h)),I.set(c,Math.max(e,I.get(c)||0)),this._loadingPages.has(c)||this._failedPages.has(c)||(this._missingPagesAndNodes.push(c),++l),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const g=d.node;if(this._updateNodeFeatureEstimate(g,o),null==g){const e=this._entryPriority(a);return this._loadingNodes.has(a)||this._failedNodes.has(a)||(this._missingPagesAndNodes.push(a),I.set(a,e)),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const _=this._getPage(a);if(0===this._missingPagesAndNodes.length&&!this._useNodePages)for(let e=0;e<d.childCount;e++){const t=_.children[d.childOffset+e],i=this._getNodeInternal(t);null!=i&&!i.node&&!this._loadingNodes.has(t)&&!this._failedNodes.has(t)&&t>=0&&(I.set(t,this._entryPriority(t)),this._prefetchNodes.push(t))}if(g.failed||g.resources.isEmpty)return void(n&&d.childCount>0&&this._isSelected(g)&&(n=!1));if(this._isLoaded(a)){if(s.known+=g.memory,++s.knownNodes,this._isSelected(g)?d.childCount>0&&(n=!1):(s.unremoved+=g.memory,n=!1),this._needsUpdate(g)){const e=this._entryPriority(a);I.set(a,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(a)}return}if(g.memory&&(s.known+=g.memory,++s.knownNodes),!this._isSelected(g))return void(this._isReloading(a)&&this._updates.remove.push(a));if(d.childCount>0&&(n=!1),g.memory?(s.missing+=g.memory,s.known+=g.memory,++s.knownNodes):++s.missingNodes,e.includes(g.index))return this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._entryPriority(a)),void(this._updates.cancel=this._updates.cancel.filter((e=>e!==g.index)));if(!t.done&&this._enable(g))return void t.madeProgress();const f=this._entryPriority(a);I.set(a,f),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,f),this._updates.add.push(a),this.layerHasModifications&&i&&null!=g&&g.imModificationImpact===u.NotChecked&&r.push(a)};this.traverseVisible(d,a),this._frameNumber++,this._missingPagesAndNodes.sort(((e,t)=>e-t)),this._missingPagesAndNodes.filterInPlace(((e,t)=>t<1||this._missingPagesAndNodes.data[t-1]!==e)),this._missingPagesAndNodes.sort(((e,t)=>I.get(e)-I.get(t))),this._missingPagesAndNodes.length>0&&(this._maxUnloadedPrio=I.get(this._missingPagesAndNodes.back()),this._prefetchNodes.clear()),this._removeUnusedNodePages(a,l);const h=this._updates.add;h.length>0&&this.layerHasModifications&&(r.length>0&&i?.(r),h.filterInPlace((e=>{const t=this._getNodeInternal(e),i=null==t?.node||t.node.imModificationImpact!==u.Culled;return i||this.invalidateNodeVisibilityCache(e),i}))),this._unloadedMemoryEstimate=s.missing-s.unremoved,s.knownNodes>3&&s.missingNodes>0&&(this._unloadedMemoryEstimate+=s.known/s.knownNodes*s.missingNodes),this._unloadedMemoryEstimate=.8*Math.max(0,this._unloadedMemoryEstimate),this._featureEstimate.estimate=this._computeFeatureEstimate(o),this._featureEstimate.leavesReached=n,this._updates.add.filterInPlace((e=>I.get(e)>=this._maxUnloadedPrio)).sort(((e,t)=>I.get(e)-I.get(t))),this._updates.update.sort(((e,t)=>I.get(e)-I.get(t))),this._indexMissing=this._loadingPages.size+this._loadingNodes.size+this._missingPagesAndNodes.length,this._dirty=this._indexMissing>0,I.clear()}checkFeatureTarget(e,t){const i=this._viewportQueries.updateScreenSpaceErrorBias(t);let n=t,s=t,o=i,r=10;for(;r--;){const i=new L;this._updateFeatureEstimate(n,i);if(this._computeFeatureEstimate(i)<=e){if(n>=t||i.missingNodes>0||0===r)break;o=n,n=.5*(n+s)}else s=n,n=.5*(n+o)}return this._version=x(this._version),this._viewportQueries.updateScreenSpaceErrorBias(i),Math.min(t,n)}_removeUnusedNodePages(e,t){if(!this._useNodePages)return;const i=e.size,n=this._nodePages,s=n.size+this._loadingPages.size+t;if(s>B&&s>i){const t=new Array;for(const[i,s]of n)0!==s.numNodesWithLoadedChildren||e.has(i)||t.push([s.lastTraversed,i]);t.sort(((e,t)=>e[0]-t[0])).some((e=>{const t=e[1];return this._deleteNodePage(t),n.size<=B}))}}_updateFeatureEstimate(e,t){this._version=x(this._version),this._viewportQueries.updateScreenSpaceErrorBias(e),this.traverseVisible(((e,i)=>this._updateNodeFeatureEstimate(i?.node,t)))}_updateNodeFeatureEstimate(e,t){null!=e&&!e.failed&&this._isSelected(e)&&(null!=e.numFeatures?(t.numFeatures+=e.numFeatures,++t.knownNodes):++t.missingNodes)}_computeFeatureEstimate(e){let t=e.numFeatures;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.numFeatures/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._missingPagesAndNodes)}prefetch(){return this._prefetchNodes.sort(((e,t)=>I.get(e)-I.get(t))),this._load(this._prefetchNodes)}_load(e){if(0===e.length||!this._canRequest())return!1;for(;e.length>0&&this._canRequest();){const t=e.pop();this._useNodePages&&t>=0?this._loadPage(t):this._loadNode(t)}return!0}get isLoading(){return this._indexMissing>0}get isPrefetching(){return this._prefetchNodes.length>0}get indexLoading(){return this._loadingPages.size+this._loadingNodes.size}get indexMissing(){return this._indexMissing}get unloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}get maxPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}nodeTraversalState(e){if(null==e)return null;const t=e.index,i=this._getNodeInternal(t);if(!i)return null;let n=i?.traversalState;if(n&&R(n.version,this._version))return n;const s=this._viewportQueries.getLodLevel(e),o=this._viewportQueries.hasLOD(e);let r=!0;if(o){const e=this.getParentIndex(t);if(null!=e){const t=this._getNodeInternal(e),i=t?.traversalState;r=!!i&&s>i.lodLevel}else r=s>0}else r=0===e.childCount;return n?(n.lodLevel=s,n.isChosen=r,n.version=S(!0,this._version),n):(n=new c(o,r,s,S(!0,this._version)),i.traversalState=n,n)}async _loadNode(e){this._loadingNodes.add(e);const i=this._getNodeInternal(e).ref;if(null==i)return void this._failedNodes.add(e);const n=i.id,s=this._urlPrefix+n,o=()=>{this._loadingNodes.delete(e),0===this._missingPagesAndNodes.length&&0===this._loadingNodes.size&&this.requestUpdate()};let r=null;try{r=e>=0?await this._streamDataController.request(s,"json"):await this._clientNodeLoader.loadNodeJSON(n)}catch(d){return o(),void(t(d)||(this._logger.error("#loadNode()",this._layer,"Error loading node: "+s),this._failedNodes.add(e)))}o();const a=this._validateNode(n,r);if(null==a)return;a.obb&&this.invalidateNodeVisibilityCache(e);const l=this._addNode(a,e);this.nodeTraversalState(l)}_validateNode(e,t){if(null==t||"object"!=typeof t||t.id!==e)return this._logger.error("#validateNode()",this._layer,`Invalid node. Wrong type or wrong id "${e}"`),null;if(!Array.isArray(t.mbs))return this._logger.error("#validateNode()",this._layer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&"./shared"!==t.sharedResource.href&&"./shared/"!==t.sharedResource.href&&this._logger.warn("#validateNode()",this._layer,`Invalid shared resource href on node "${e}"`);const i=t.geometryData;null==i||Array.isArray(i)&&0===i.length||Array.isArray(i)&&1===i.length&&"./geometries/0"===i[0].href||this._logger.warn("#validateNode()",this._layer,`Invalid geometry data on node "${e}"`);const n=t.attributeData,s=this._layer.attributeStorageInfo;null==n||Array.isArray(n)&&!n.some(((e,t)=>e.href!==`./attributes/${s?.[t]?.key??`f_${t}`}/0`))||this._logger.warn("#validateNode()",this._layer,`Invalid attribute data on node "${e}"`),t.featureData&&t.featureData.length>1&&this._logger.warn("#validateNode()",this._layer,`Node ${e} has ${t.featureData.length} bundles. Only the first bundle will be loaded.`);const o=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:void 0,r=t.featureData&&1===t.featureData.length&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:void 0,a=t=>{if(null==t)return null;const i=t=>this._logger.error("#validateNode()",this._layer,`Invalid node reference on node ${e}: ${t}`);if("number"==typeof t.id)i(`id ${t.id} is a number instead of a string.`);else if("string"!=typeof t.id||!Array.isArray(t.mbs))return i("Missing or invalid id."),null;if(!Array.isArray(t.mbs))return i(`Invalid bounding volume on reference ${t.id}.`),null;t.href&&t.href!=="../"+t.id&&this._logger.error("#validateNode()",this._layer,`Invalid node href on node "${e}"`);const n=new l(`${t.id}`,t.mbs);return n.serviceObbInIndexSR=!this.ignoreServiceObb&&t.hasOwnProperty("obb")&&t.obb?v.fromJSON(t.obb):null,n.visibilityObbInRenderSR=this._computeVisibilityObb(n),n},d=Array.isArray(t.children)?t.children.map(a).filter((e=>null!=e)):null,h=t.featureData?.length??!1,u=!0===t.isEmpty;return new f(e,t.mbs,o,"string"==typeof t.version?t.version:null,{isEmpty:!h&&u,hasSharedResource:null!=t.sharedResource,attributes:t.attributeData?e:void 0,texture:t.textureData&&t.textureData.length>0?e:void 0,geometry:null!=t.geometryData?e:void 0},d,Array.isArray(t.lodSelection)?t.lodSelection:null,r)}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes((e=>{null!=e.node&&(e.node.failed=!1)}))}_entryPriority(e){const t=this._getNodeInternal(e),i=this.getParentIndex(e);if(null==t||null==i&&null==t.node)return null==i?1/0:this._entryPriority(i);let n=0;if(t.node&&null!=i){const e=this._getNodeInternal(i).traversalState;null!=e&&(n=e.lodLevel)}let s=this.progressiveLoadPenalty;for(let r=e;null!=r;r=this.getParentIndex(r))if(this._isLoaded(r)){s=0;break}const o=null!=t.ref?this._viewportQueries.distToPOI(t.ref):null!=t.node?this._viewportQueries.distToPOI(t.node):0;return-o-n*(o+this.progressiveLoadPenalty)+s}traverseVisible(e,t){const i=this._getNodeInternal(this._rootIndex);null!=i?this._traverseVisible(this._rootIndex,null,i,e,t):e(this._rootIndex,null,null)}_traverseVisible(e,t,i,n,s){const o=w(e,this._pageSize);if(s&&s.add(o),i.node&&0===i.childCount)return void(this.isGeometryVisible(e)&&n(e,i,t));if(!this.isNodeVisible(e))return;if(n(e,i,t),null==i.node)return;const r=this.nodeTraversalState(i.node);if(r?.nodeHasLOD&&r.lodLevel===this._maxLodLevel)return;const a=this._getPageFromPageIndex(o);for(let l=0;l<i.childCount;l++){const t=a.children[i.childOffset+l],o=this._getNodeInternal(t);if(o)this._traverseVisible(t,e,o,n,s);else{if(s){const e=w(t,this._pageSize);s.add(e)}n(t,null,e)}}}traverse(e,t){t(e)&&this.traverseDescendants(e,t)}traverseDescendants(e,t){++this._traverseDescendantsNestingLevel;const i=e.index,n=this._pageSize,s=w(i,n),o=this._getPageFromPageIndex(s);if(null==o)return;const r=this._frameNumber,a=this._nodePages,l=E(i,n),d=o.nodes[l],h=d.childCount;if(o.lastTraversed=r,0===h)return;const u=new Array,c=1===this._traverseDescendantsNestingLevel?this._traverseDescendantsQueue:[0];let g=0;{const{childOffset:e,childCount:t}=d,{children:i}=o;c.length=2**Math.ceil(Math.log2(g+t));for(let n=e;n<e+t;++n){const e=i[n];e>=0?(c[g]=e,++g):u.push(e)}}if(u.length>0){const e=this._clientNodePage;if(e){const i=e.children;let n=0;for(;n<u.length;){const s=u[n];++n;const o=-s-1,r=e.nodes[o],a=r.node;if(!a||!t(a))continue;const{childCount:l}=r;if(0===l)continue;const{childOffset:d}=r,h=d+l;for(let e=d;e<h;++e)u.push(i[e])}}}if(g>0){let e=0;if(n>0){let i=s*n,l=o,d=l.nodes;for(;e<g;){const s=c[e];let o;if(++e,i<=s&&s<i+n)o=l;else{const e=s/n|0,t=a.get(e);if(void 0===t)continue;o=t,o.lastTraversed=r,l=o,d=l.nodes,i=n*e}const h=d[s-i],u=h.node;if(null==u||!1===t(u))continue;const{childCount:_}=h;if(0===_)continue;const f=g+_;for(c.length<f&&(c.length=2**Math.ceil(Math.log2(g+_)));c.length<g+_;)c.length+=c.length;const m=o.children,{childOffset:v}=h,N=v+_;for(let e=v;e<N;++e)c[g]=m[e],++g}}else{const i=a.get(0);if(i)for(;e<g;){const n=c[e++],s=i.nodes[n],o=s.node;if(!o||!t(o))continue;const{childCount:r}=s;if(0===r)continue;c.length=Math.max(c.length,2**Math.ceil(Math.log2(g+r)));const a=i.children,{childOffset:l}=s,d=l+r;for(let e=l;e<d;++e)c[g]=a[e],++g}}}--this._traverseDescendantsNestingLevel}updateChildrenLoaded(e,t){let i=this.getNode(e);for(;null!=i;){const e=i.childrenLoaded,n=e+t;i.childrenLoaded=n;const s=0===e?1:0===n?-1:0,o=i.index;if(0!==s){this._getPage(o).numNodesWithLoadedChildren+=s}i=this.getParent(o)}}checkChildrenLoadedInvariant(){return!0}updateElevationInfo(e,t){this.needNodeElevationRange=t&&!!e&&("relative-to-ground"===e.mode||"relative-to-scene"===e.mode||"on-the-ground"===e.mode),this._viewportQueries.updateElevationInfo(e),this.invalidateAllElevationRanges()}invalidateAllElevationRanges(){this._forAllNodes((e=>{e?.invalidateBounds(),e.node?.invalidateElevationRange(),e.ref?.invalidateElevationRange()}))}_forAllNodes(e){if(null!=this._clientNodePage){const t=this._clientNodePage;for(let i=0;i<t.nodes.length;i++)e(t.nodes[i],-(i+1))}for(const[t,i]of this._nodePages){const n=t*this._pageSize;for(let t=0;t<i.nodes.length;t++)e(i.nodes[t],n+t)}}clearCaches(){if(this._useNodePages){const e=this._nodePages,t=new Set;this.traverseVisible((e=>t.add(w(e,this._pageSize))));for(const[i,n]of e)if(0!==n.numNodesWithLoadedChildren||t.has(i))for(const e of n.nodes)e.traversalState=null;else this._deleteNodePage(i)}}_deleteNodePage(e){this._nodePages.delete(e)}get test(){}}const I=new Map;class y{constructor(t){this.missing=t,this.update=new e({deallocator:null}),this.add=new e({deallocator:null}),this.remove=new e({deallocator:null}),this.cancel=[]}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function P(e){return _(e,-2)}function x(e){return _(e,2)}function S(e,t){return t+(e?1:0)}function R(e,t){return(-2&e)===t}function C(e){return!(1&~e)}function w(e,t){return e<0?-1:t>0?e/t|0:0}function E(e,t){return e<0?-e-1:0===t?e:e%t}function M(e,t,i){return-1===t?-(e+1):0===i?e:t*i+e}const V=[["maxScreenThreshold",a.MaxScreenThreshold],["screenSpaceRelative",a.ScreenSpaceRelative],["removedFeatureDiameter",a.RemovedFeatureDiameter],["distanceRangeFromDefaultCamera",a.DistanceRangeFromDefaultCamera]];function O(e){if(e)for(let t=0;t<e.length;t++)for(const i of V)if(i[0]===e[t].metricType)return{lodMetric:i[1],maxError:e[t].maxError};return{lodMetric:a.None,maxError:0}}class A{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}class L{constructor(){this.numFeatures=0,this.knownNodes=0,this.missingNodes=0}}function F(e){return Math.sqrt(e*(4/Math.PI))}const D=o(),k=o(),z=o(),T=o(),B=has("esri-mobile")?100:300;export{b as I3SIndex,O as selectErrorMetric};