// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define(["../../../geometry/support/aaBoundingRect","./TileCache","./TileCoverage","./TileKey"],function(u,z,A,B){const l=new B(0,0,0,0),e=new Map,m=[],v=[];class C{constructor(a){this._previousScale=Number.POSITIVE_INFINITY;this.cachePolicy="keep";this.coveragePolicy="closest";this.resampling=!0;this.tileIndex=new Map;this.tiles=[];this.buffer=192;this.acquireTile=a.acquireTile;this.releaseTile=a.releaseTile;this.tileInfoView=a.tileInfoView;null!=a.resampling&&(this.resampling=a.resampling);a.cachePolicy&& (this.cachePolicy=a.cachePolicy);a.coveragePolicy&&(this.coveragePolicy=a.coveragePolicy);null!=a.buffer&&(this.buffer=a.buffer);a.cacheSize&&(this._tileCache=new z(a.cacheSize,this.tileInfoView,c=>{this.releaseTile(c)}))}destroy(){this.tileIndex.clear()}update(a){const {resampling:c,tileIndex:b}=this,{scale:f,center:r,resolution:D}=a.state,{minScale:E,maxScale:F}=this.tileInfoView,w=!a.stationary&&f>this._previousScale;this._previousScale=f;if(!c&&(f>E||fd.visible=!0);var t=0,p=0;if(0q,!p||!w&&t?!k&&p||m.push(n):n.isReady?k&&"purge"===this.cachePolicy&&this._hasReadyAncestor(l,q)?m.push(n):v.push(n):k&&m.push(n));for(const d of v)d.isReady&&e.set(d.key.id,d);for(const d of m)this._tileCache?this._tileCache.add(d):this.releaseTile(d),b.delete(d.key.id); for(const d of e.values())this.tiles.push(d);for(const d of b.values())e.has(d.key.id)||(d.visible=!1);this._tileCache?.prune(q,r,D);A.pool.release(a);v.length=0;m.length=0;e.clear()}else this.tiles.length=0,this.clear()}clear(){const {tileIndex:a}=this;for(const c of a.values())this.releaseTile(c);a.clear()}refresh(a){for(const c of this.tileIndex.values())this.tiles.includes(c)?a(c):m.push(c);for(const c of m)this.releaseTile(c),this.tileIndex.delete(c.key.id);this._tileCache?.clear()}updateCacheSize(a){this._tileCache&& (this._tileCache.maxSize=a)}_addParentTile(a,c){let b=null;for(;;){a=this.tileInfoView.getTileParentId(a);if(!a)break;if(this.tileIndex.has(a)){if(b=this.tileIndex.get(a),b?.isReady){c.has(b.key.id)||c.set(b.key.id,b);break}}else if(this._tileCache?.has(a)&&(b=this._tileCache.pop(a),this.tileIndex.set(a,b),b?.isReady)){c.has(b.key.id)||c.set(b.key.id,b);break}}}_hasReadyAncestor(a,c){const b=u.create();this.tileInfoView.getTileBounds(b,a,!0);for(const f of this.tileIndex.values())if(f.isReady&&f.key.level>= c&&f.key.level