/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{removeMaybe as e,destroyMaybe as r}from"../../../../core/maybe.js";import{memoryEstimators as t}from"../../layers/graphics/defaultSymbolComplexity.js";import{streamlinGeometryBatchSize as s}from"./constants.js";import{StreamlineResources3D as i}from"./StreamlineResources3D.js";import{RenderGeometry as a}from"../../webgl-engine/lib/RenderGeometry.js";import{TaskPriority as o}from"../../../support/Scheduler.js";class d extends i{constructor(e,r,s,i,a){super(e,r,s,i,t.LINE_ROUND.draped.bytesPerFeature),this._layerView=a,this._drapeRenderer=null,this.drapeSourceType=2,this.updatePolicy=0,this.renderGroup=0,this._frameTask=null,this._renderGeometries=[]}get _view(){return this._layerView.view}get layer(){return this._layerView.layer}get fullOpacity(){return this._layerView.fullOpacity}get attached(){return null!=this._drapeRenderer}get destroyed(){return this.attached}async attach(){const{geometries:e}=this;null!=e&&(this.detach(),this._frameTask=this._view.resourceController.scheduler.registerTask(o.FLOW_GENERATOR),await this._frameTask.scheduleGenerator(r=>this._addGeometryToOverlay(e,r)))}async*_addGeometryToOverlay(e,r){this._drapeRenderer=this._view.overlayManager.registerGeometryDrapeSource(this);for(let t=0;t<e.length;t+=s){const i=e.slice(t,t+s).map(e=>new a(e));this._drapeRenderer.addGeometries(i,0),this._renderGeometries.push(...i),this._drapeRenderer.commitChanges(),r.madeProgress(),r.done&&(r=yield)}}detach(){this._frameTask=e(this._frameTask),this._drapeRenderer&&(this._drapeRenderer.removeGeometries(this._renderGeometries,2),this._drapeRenderer.commitChanges(),this._renderGeometries.length=0),this.attached&&this._view.overlayManager.unregisterDrapeSource(this),this._drapeRenderer=r(this._drapeRenderer)}}export{d as StreamlineResources3DOverlay};
