import{F as k,cf as rt,aW as at,cg as nt,bg as ot,bi as ht,a as _,t as c,s as dt,c8 as L,b4 as f,h as D,k as l,g as j,D as X,c9 as ut,ch as x,b5 as O,aI as lt,A as m,ci as ct,X as _t,cj as pt}from"./index.6c049565.js";import{Q as A,L as H,ab as N,B as I,C as $,ae as U,af as B,ag as z,ah as C,an as q,ao as Et,O as xt,N as ft,ap as Rt}from"./enums.0295eb81.js";import{r as mt,i as gt}from"./TileContainer.282da507.js";import{n as vt,l as Tt,f as Y}from"./visualVariablesUtils.4b17aac7.js";import{m as T,o as bt,J as K,Q as G}from"./Utils.e8554a0e.js";import{D as Z,P as J,G as W,L as tt,M as yt,Y as St,V as kt}from"./enums.2d9e6f64.js";import{x as zt}from"./VertexArrayObject.729879be.js";import{E as et}from"./Texture.8e8dfb11.js";import{e as Ct,c as wt}from"./utils.eb2c3fd5.js";class Mt{acquire(t){return{refCount:1,version:-1,labelMat2d:k(),tileMat3:k(),dvs:k()}}release(t){}}class y extends mt{constructor(t,e,s,i){super(t,e,s,i,A,A)}destroy(){super.destroy(),this._transforms&&y.TransformCache.release(this.key.hash)}setTransform(t){const e=this.resolution/t.resolution,s=this.transforms.tileMat3,[i,r]=t.toScreenNoRotation([0,0],[this.x,this.y]),a=this.width/this.rangeX*e,n=this.height/this.rangeY*e;rt(s,a,0,0,0,n,0,i,r,1),at(this.transforms.dvs,t.displayViewMat3,s);const o=this.transforms.labelMat2d,d=window.devicePixelRatio,u=nt(ot(),a*d,0,0,n*d,i*d,r*d);ht(o,t.viewMat2d,u)}_createTransforms(){return y.TransformCache.acquire(this.key.hash)}}y.TransformCache=new Mt;const b=2147483647;class R{constructor(t){this._head=t,this._cursor=t}static from(t,e=0,s=t.byteLength/h.BYTES_PER_RECORD-e){const i=new h(new Int32Array(t,e*h.BYTES_PER_RECORD,s*h.ELEMENTS_PER_RECORD));return new R(i)}size(){let t=this._cursor,e=0;for(;t;)e+=t.size(),t=t._link;return e}get id(){return this._cursor.id}set id(t){this._cursor.id=t}get materialKey(){return this._cursor.materialKey}set materialKey(t){this._cursor.materialKey=t}get insertAfter(){return this._cursor.insertAfter}get indexFrom(){return this._cursor.indexFrom}set indexFrom(t){this._cursor.indexFrom=t}get indexCount(){return this._cursor.indexCount}set indexCount(t){this._cursor.indexCount=t}get vertexFrom(){return this._cursor.vertexFrom}set vertexFrom(t){this._cursor.vertexFrom=t}get vertexCount(){return this._cursor.vertexCount}set vertexCount(t){this._cursor.vertexCount=t}get sortKey(){return this._cursor.sortKey}set sortKey(t){this._cursor.sortKey=t}get index(){return this._cursor._indexStart+this._cursor._index}seekIndex(t){let e=t;for(this._cursor=this._head;this._cursor;){const s=this._cursor.size();if(e=this._packedRecords.length?0:this._packedRecords[t]}getCursor(){return this.copy()}copy(){const t=new h(this._packedRecords);return t._indexStart=this._indexStart,t._link=this._link,t._index=this._index,t._offsets=this._offsets,t._deletedCount=this._deletedCount,t}}h.ELEMENTS_PER_RECORD=H,h.BYTES_PER_RECORD=h.ELEMENTS_PER_RECORD*Int32Array.BYTES_PER_ELEMENT;const F=dt.getLogger("esri.views.2d.engine.webgl.AttributeStoreView"),w=vt(Tt,F);class Q{constructor(t,e,s){this._texture=null,this._lastTexture=null,this._fbos={},this.texelSize=4;const{buffer:i,pixelType:r,textureOnly:a}=t,n=T(r);this.shared=s,this.pixelType=r,this.size=e,this.textureOnly=a,a||(this.data=new n(l(i))),this._resetRange()}destroy(){f(this._texture,t=>t.dispose());for(const t in this._fbos)f(this._fbos[t],e=>{t==="0"&&e.detachColorTexture(),e.dispose()}),this._fbos[t]=null;this._texture=null}get _textureDesc(){return{target:yt.TEXTURE_2D,wrapMode:Z.CLAMP_TO_EDGE,pixelFormat:J.RGBA,dataType:this.pixelType,samplingMode:tt.NEAREST,width:this.size,height:this.size}}setData(t,e,s){const i=Y(t),r=l(this.data),a=i*this.texelSize+e;!r||a>=r.length||(r[a]=s,this.dirtyStart=Math.min(this.dirtyStart,i),this.dirtyEnd=Math.max(this.dirtyEnd,i))}getData(t,e){if(c(this.data))return null;const s=Y(t)*this.texelSize+e;return!this.data||s>=this.data.length?null:this.data[s]}getTexture(t){return O(this._texture,()=>this._initTexture(t))}getFBO(t,e=0){if(c(this._fbos[e])){const s={colorTarget:St.TEXTURE,depthStencilTarget:kt.NONE},i=e===0?this.getTexture(t):this._textureDesc;this._fbos[e]=new zt(t,s,i)}return this._fbos[e]}get locked(){return!(this.pixelType!==W.UNSIGNED_BYTE||!this.shared||this.textureOnly||!D("esri-atomics")||!this.data)&&Atomics.load(this.data,0)===1}get hasDirty(){const t=this.dirtyStart;return this.dirtyEnd>=t}updateTexture(t,e){if(!this.locked){try{const s=this.dirtyStart,i=this.dirtyEnd;if(!this.hasDirty)return;this._resetRange();const r=l(this.data).buffer,a=this.getTexture(t),n=4,o=(s-s%this.size)/this.size,d=(i-i%this.size)/this.size,u=o,E=this.size,g=d,v=o*this.size*n,S=(E+g*this.size)*n-v,P=T(this.pixelType),st=new P(r,v*P.BYTES_PER_ELEMENT,S),it=this.size,V=g-u+1;if(V>this.size)return void F.error(new j("mapview-webgl","Out-of-bounds index when updating AttributeData"));a.updateData(0,0,u,it,V,st)}catch{}e()}}update(t){const{data:e,start:s,end:i}=t;if(_(e)){const r=this.data,a=s*this.texelSize;for(let n=0;nnew Q(r,i,s));else for(let r=0;rL(t,e=>e.destroy())),f(this._defaultTexture,t=>t.dispose())}isEmpty(){const t=this._data;return c(t)}isUpdating(){const t=_(this._pendingAttributeUpdate),e=t;return D("esri-2d-log-updating")&&console.log(`Updating AttributeStoreView ${e} -> hasPendingUpdate ${t}`),e}getBlock(t){return c(this._data)?null:this._data[t]}setLabelMinZoom(t,e){this.setData(t,0,1,e)}getLabelMinZoom(t){return this.getData(t,0,1,255)}getFilterFlags(t){return this.getData(t,0,0,0)}getVVSize(t){return this.getData(t,N,0,0)}getData(t,e,s,i){if(!this._data)return 0;const r=l(this._data)[e];if(c(r))return 0;const a=r.getData(t,s);return _(a)?a:i}setData(t,e,s,i){const r=l(this._data)[e];l(r).setData(t,s,i)}lockTextureUpload(){this._locked=!0}unlockTextureUpload(){this._locked=!1}forceTextureUpload(){this._forceNextUpload=!0}async requestUpdate(t){if(this._pendingAttributeUpdate)return void F.error(new j("mapview-webgl","Tried to update attribute data with a pending update"));const e=X();return w("AttributeStoreView Update Requested",t),this._pendingAttributeUpdate={data:t,resolver:e},this._onUpdate(),e.promise}update(){if(this._initialized&&_(this._pendingAttributeUpdate)){D("esri-2d-update-debug")&&console.debug("AttributeStoreView::update");const{data:t,resolver:e}=this._pendingAttributeUpdate,s=l(this._data);for(let i=0;if(r,o=>{w(`Updating block ${i}`,o),n.update(o)}))}this._pendingAttributeUpdate=null,e(),this._onUpdate()}}bindTextures(t,e=!0){const s=this._getDefaultTexture(t);if(!this._initialized)return t.bindTexture(s,I),void(e&&(t.bindTexture(s,$),t.bindTexture(s,U),t.bindTexture(s,B),t.bindTexture(s,z),t.bindTexture(s,C),t.bindTexture(s,q)));const i=l(this._data);this._locked&&!this._forceNextUpload||(ut(i,r=>r.updateTexture(t,()=>this._onUpdate())),this._forceNextUpload=!1),t.bindTexture(x(i[Et],s,r=>r.getTexture(t)),I),e&&(t.bindTexture(x(i[xt],s,r=>r.getTexture(t)),q),t.bindTexture(x(i[ft],s,r=>r.getTexture(t)),$),t.bindTexture(x(i[N],s,r=>r.getTexture(t)),U),t.bindTexture(x(i[Rt],s,r=>r.getTexture(t)),B),t.bindTexture(x(i[z],s,r=>r.getTexture(t)),z),t.bindTexture(x(i[C],s,r=>r.getTexture(t)),C))}_getDefaultTexture(t){if(c(this._defaultTexture)){const e={wrapMode:Z.CLAMP_TO_EDGE,pixelFormat:J.RGBA,dataType:W.UNSIGNED_BYTE,samplingMode:tt.NEAREST,width:1,height:1};this._defaultTexture=new et(t,e,new Uint8Array(4))}return this._defaultTexture}}function M(p,t){const e=t.length;if(p{let s=1/0,i=0;for(const o in e.levels){const d=parseFloat(o),u=Math.abs(t-d);uthis.onAttributeStoreUpdate())}destroy(){this.children.forEach(t=>t.destroy()),this.removeAllChildren(),this.attributeView.destroy(),this._materialItemsRequestQueue.clear()}setRendererInfo(t,e,s){this._rendererInfo.setInfo(t,e,s),this.requestRender()}async getMaterialItems(t,e){if(!t||t.length===0)return null;const s=X();return this._materialItemsRequestQueue.push({items:t,abortOptions:e,resolver:s}),this.requestRender(),s.promise}doRender(t){if(t.context.capabilities.enable("textureFloat"),t.context.capabilities.enable("vao"),this._materialItemsRequestQueue.length>0){let e=this._materialItemsRequestQueue.pop();for(;e;)this._processMaterialItemRequest(t,e),e=this._materialItemsRequestQueue.pop()}super.doRender(t)}renderChildren(t){for(const e of this.children)e.commit(t);this._rendererInfo.update(t.state),super.renderChildren(t)}updateTransforms(t){if(this.children.some(e=>e.hasData))for(const e of this.children)e.setTransform(t)}createRenderParams(t){const e=super.createRenderParams(t);return e.rendererInfo=this._rendererInfo,e.attributeView=this.attributeView,e}onAttributeStoreUpdate(){}_processMaterialItemRequest(t,{items:e,abortOptions:s,resolver:i}){const{painter:r,pixelRatio:a}=t,n=e.map(o=>r.textureManager.rasterizeItem(o.symbol,a,o.glyphIds,s));Promise.all(n).then(o=>{if(!this.stage)return void i.reject();const d=o.map((u,E)=>({id:e[E].id,mosaicItem:u}));i.resolve(d)},i.reject)}}export{R as i,y as m,Bt as o};