/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../chunks/tslib.es6","../../../core/Accessor","../../../core/Handles","../../../core/maybe","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../../../geometry/projection","../../../geometry/support/aaBoundingRect","../../../layers/support/layerUtils","../../ViewingMode","./TerrainConst","./terrainUtils"],(function(e,t,r,n,i,o,l,s,a,c,p,u,y,d,E,f,_){"use strict";function h(e,t){return e===E.ViewingMode.Global?new x(t):new w(t)}e.ExtentHelper=function(e){function r(t){var r;return(r=e.call(this,t)||this)._handles=new i,r}t._inheritsLoose(r,e);var n=r.prototype;return n.initialize=function(){this._handles.add([this.layerViews.on("change",(()=>this.notifyChange("stencilEnabledExtents")))])},n.destroy=function(){this._handles.destroy(),this._handles=null},n._computeStencilEnabledExtents=function(){const e=[];return this.layerViews.forEach((t=>{const r=t.layer;if("IntegratedMeshLayer"===r.operationalLayerType&&null!=this.viewSpatialReference){const t=g(r.fullExtent,this.viewSpatialReference);o.isSome(t)&&e.push(y.fromExtent(t))}})),e},t._createClass(r,[{key:"layerViewsExtent",get:function(){return this._computeLayerViewsExtent()}},{key:"tiledLayersExtent",get:function(){return this._computeTiledLayersExtent()}},{key:"stencilEnabledExtents",get:function(){return this._computeStencilEnabledExtents()}}]),r}(n),r.__decorate([l.property({readOnly:!0})],e.ExtentHelper.prototype,"layerViewsExtent",null),r.__decorate([l.property({readOnly:!0})],e.ExtentHelper.prototype,"tiledLayersExtent",null),r.__decorate([l.property({readOnly:!0})],e.ExtentHelper.prototype,"stencilEnabledExtents",null),r.__decorate([l.property()],e.ExtentHelper.prototype,"viewSpatialReference",void 0),r.__decorate([l.property()],e.ExtentHelper.prototype,"tilingScheme",void 0),r.__decorate([l.property()],e.ExtentHelper.prototype,"defaultTiledLayersExtent",void 0),r.__decorate([l.property({constructOnly:!0})],e.ExtentHelper.prototype,"layers",void 0),r.__decorate([l.property({constructOnly:!0})],e.ExtentHelper.prototype,"layerViews",void 0),e.ExtentHelper=r.__decorate([p.subclass("esri.views.3d.terrain.ExtentHelper")],e.ExtentHelper);let x=function(e){function r(){return e.apply(this,arguments)||this}t._inheritsLoose(r,e);var n=r.prototype;return n._computeLayerViewsExtent=function(){return this._globalExtent},n._computeTiledLayersExtent=function(){return this._globalExtent},t._createClass(r,[{key:"_globalExtent",get:function(){return this.viewSpatialReference.isWebMercator?f.WEBMERCATOR_WORLD_EXTENT:f.GEOGRAPHIC_WORLD_EXTENT}}]),r}(e.ExtentHelper);x=r.__decorate([p.subclass("esri.views.3d.terrain.ExtentHelperGlobal")],x);let w=function(e){function r(){return e.apply(this,arguments)||this}t._inheritsLoose(r,e);var n=r.prototype;return n._computeLayerViewsExtent=function(){const e=y.empty(),t=this.viewSpatialReference;this.layerViews.forEach((r=>{const n=r.layer;if(r.isResolved()&&("graphics"!==n.type||!n.internal)){const n=g("fullExtentInLocalViewSpatialReference"in r&&r.fullExtentInLocalViewSpatialReference||r.layer.fullExtent,t);y.expand(e,n,e)}}));const r=y.allFinite(e)?e:null,n=this._get("layerViewsExtent");return y.equals(r,n)?n:r},n._computeTiledLayersExtent=function(){const e=this.tilingScheme;if(!e)return null;const t=this.viewSpatialReference,r=y.empty();this.layers.forEach((n=>{if(n.loaded&&d.isTiledLayer(n)){const i=_.getTiledLayerInfo(n,t,E.ViewingMode.Local);if(o.isNone(i))return;const{tileInfo:l,fullExtent:s}=i;o.isSome(l)&&o.isSome(s)&&(_.isProjectableRasterLayer(n)||e.compatibleWith(l)&&s.spatialReference.equals(e.spatialReference))&&y.expand(r,s,r)}})),y.expand(r,this.defaultTiledLayersExtent,r);const n=y.allFinite(r)?r:null,i=this._get("tiledLayersExtent");return y.equals(n,i)?i:n},r}(e.ExtentHelper);function g(e,t){return o.isSome(e)&&!e.spatialReference.equals(t)?u.projectWithoutEngine(e,e.spatialReference,t):e}w=r.__decorate([p.subclass("esri.views.3d.terrain.ExtentHelperLocal")],w),e.create=h,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
