import{l0 as ye,b3 as V,eL as D,aI as je,cD as ue,al as ae,jQ as ke,l1 as ee,hC as Ke,eB as He,ju as Ee,l2 as qe,fa as Ne,eI as k,Y as Ze,dm as Ye,eH as Xe,D as Qe,aC as v,L as We,l3 as Je,l4 as et,v as K,f as tt,bv as ge,$ as st,am as xe,as as _e,l5 as it,l6 as rt,ak as ve,an as te,l7 as nt,l8 as ot,l9 as at,A as C,B as F,C as lt,bk as dt}from"./index-b5c8f851.js";import{a as be,t as ht,b as ct,i as ut}from"./ExpandedCIM-0020ab0e.js";import{x as ft,j as pt}from"./projectionSupport-d15822a5.js";import{X as mt}from"./definitions-1467ba4a.js";import{P as fe,F as Z,j as le,H as yt,Y as gt,x as Q,R as xt,t as _t,S as Le}from"./color-0916c686.js";import{h as De}from"./FramebufferObject-4be671ef.js";import{F as vt}from"./enums-bdecffa2.js";import{f as bt}from"./ProgramTemplate-a9187eb2.js";import{m as Dt,r as Ct,T as Ce,_ as wt,i as Tt}from"./AttributeStoreView-b12ba31a.js";import{U as Ft}from"./GeometryUtils-7a7937c3.js";import{e as Y,o as Bt,x as Rt,a as St,i as It,E as Mt}from"./Matcher-dd0694f8.js";import{h as Lt,S as zt,r as At,k as $t}from"./ComputedAttributeStorage-07f34ef9.js";import{o as Gt,C as Ot,d as Pt,h as Ut,$ as Vt}from"./featureConversionUtils-6aca8295.js";import{L as jt,d as G}from"./quantizationUtils-50e37a76.js";import{t as ze}from"./OptimizedGeometry-d94e541f.js";const y=-1;let we=class{constructor(){this._dirties=[{vertexFrom:y,vertexCount:y,indexFrom:y,indexCount:y,allDirty:!1},{vertexFrom:y,vertexCount:y,indexFrom:y,indexCount:y,allDirty:!1},{vertexFrom:y,vertexCount:y,indexFrom:y,indexCount:y,allDirty:!1},{vertexFrom:y,vertexCount:y,indexFrom:y,indexCount:y,allDirty:!1},{vertexFrom:y,vertexCount:y,indexFrom:y,indexCount:y,allDirty:!1}]}hasDirty(){return this._dirties.some(e=>e.indexCount!==y||e.allDirty)}markAllClean(){for(const e of this._dirties)e.indexFrom=y,e.indexCount=y,e.vertexFrom=y,e.vertexCount=y,e.allDirty=!1}markAllDirty(){for(const e of this._dirties)e.allDirty=!0}forEach(e){for(let t=0;t0)&&(c.geometry={count:r,from:n,allDirty:a},l=!0),(a||i!==y&&s>0)&&(d={count:s,from:i,allDirty:a},l=!0),l&&e({indices:d,vertices:c},t)}}markDirtyIndices(e,t,s){const i=this._dirties[e],r=t,n=s;if(!i.allDirty)if(i.indexCount!==y){const a=Math.min(i.indexFrom,r),c=Math.max(i.indexFrom+i.indexCount,r+n)-a;i.indexFrom=a,i.indexCount=c}else i.indexFrom=r,i.indexCount=n}markDirtyVertices(e,t,s,i){const r=this._dirties[e],n=s,a=i;if(!r.allDirty)if(r.vertexCount!==y){const c=Math.min(r.vertexFrom,n),d=Math.max(r.vertexFrom+r.vertexCount,n+a)-c;r.vertexFrom=c,r.vertexCount=d}else r.vertexFrom=n,r.vertexCount=a}},kt=class{get largestRange(){return this._largestRange}constructor(e){this._largestRange=null,this._parent=e,this._updateLargestRange()}rangeCreated(e){(!this._largestRange||e.count>this._largestRange.count)&&(this._largestRange=e)}rangeResized(e,t){e===this._largestRange?e.countthis._largestRange.count)&&(this._largestRange=e)}findBestRange(e){let t=this._parent._freeHead,s=null;for(;t!==null;)t.count>=e&&(!s||t.count-e=a&&e+t<=c?(s=!1,i=!0):n!==null?(r=n,n=n.next):s=!1}return[r,n]}_updateLargestRange(){let e=null,t=this._parent._freeHead;for(;t!==null;)(!e||t.count>e.count)&&(e=t),t=t.next;this._largestRange=e}},H=class z{constructor(e,t){this._allocated=0,this._size=e,this._freeHead=e>0?{from:0,count:e,prev:null,next:null}:null,this._bookKeeper=t||new kt(this),this._freeHead&&this._bookKeeper.rangeCreated(this._freeHead)}allocate(e){const t=this._bookKeeper.findBestRange(e);if(t==null)return-1;const s=t.from,i=t.count;if(t.from+=e,t.count-=e,this._bookKeeper.rangeResized(t,s,i),this._allocated+=e,t.count===0){const r=t.prev!==null?this._freeHead:t.next;z._removeRange(t),this._freeHead=r}return s}free(e,t){const[s,i]=this._bookKeeper.findAdjacentRanges(e,t),r={from:e,count:t,prev:s??null,next:i??null};if(s!=null&&(s.next=r),i!=null&&(i.prev=r),this._bookKeeper.rangeCreated(r),this._allocated-=t,i!=null&&r.from+r.count===i.from){const n=r.from,a=r.count;z._fuse(r,i),z._removeRange(i),this._bookKeeper.rangeResized(r,n,a),this._bookKeeper.rangeResized(i,void 0,0)}if(s!=null&&s.from+s.count===r.from){const n=s.from,a=s.count;z._fuse(s,r),z._removeRange(r),this._bookKeeper.rangeResized(s,n,a),this._bookKeeper.rangeResized(r,void 0,0)}this._freeHead=r.prev!==null?this._freeHead:r}get fragmentation(){const e=this._size-this._allocated;return e===0?0:1-this._bookKeeper.largestRange.count/e}static _removeRange(e){e.prev!==null?e.next!==null?(e.prev.next=e.next,e.next.prev=e.prev):e.prev.next=null:e.next!==null&&(e.next.prev=null)}static _fuse(e,t){e.count+=t.count,e.next=t.next,t.from+=t.count,t.count=0,t.next!==null&&(t.next.prev=e)}};const U=["FILL","LINE","MARKER","TEXT","LABEL"];function Kt(o){const e=o.getStrides(),t={};for(let s=0;se.vertexCount?(this._freeVertices(n,e.vertexFrom,e.vertexCount),c=t.vertexCount,a=this._allocateVertices(n,c)):t.vertexCount===e.vertexCount?(a=e.vertexFrom,c=e.vertexCount):(this._freeVertices(n,e.vertexFrom+t.vertexCount,e.vertexCount-t.vertexCount),a=e.vertexFrom,c=t.vertexCount);let d,l,h,u=!0;if(e.indexFrom===void 0?(d=r,h=t.indexCount,l=this._allocateIndices(n,h)):t.indexCount>e.indexCount?(d=this._displayList.removeFromList(e),this._freeIndices(n,e.indexFrom,e.indexCount),h=t.indexCount,l=this._allocateIndices(n,h)):t.indexCount===e.indexCount?(u=!1,l=e.indexFrom,h=e.indexCount):(d=this._displayList.removeFromList(e),this._freeIndices(n,e.indexFrom+t.indexCount,e.indexCount-t.indexCount),l=e.indexFrom,h=t.indexCount),a!==-1&&l!==-1){const m=this._storageFor(n);if(le(a,l,m.vertexBuffers,m.indexBuffer,t,s,i),e.vertexFrom=a,e.indexFrom=l,e.vertexCount=t.vertexCount,e.indexCount=t.indexCount,this._dirtyMap){this._dirtyMap.markDirtyIndices(e.geometryType,e.indexFrom,e.indexCount);for(const p in s)this._dirtyMap.markDirtyVertices(e.geometryType,p,e.vertexFrom,e.vertexCount)}return u&&this._displayList.addToList(e,d),!0}return a!==-1&&this._freeVertices(n,a,c),l!==-1&&this._freeIndices(n,l,h),e.setMeshDataFromBuffers(t,s,i),e.vertexFrom=void 0,e.vertexCount=0,e.indexFrom=void 0,e.indexCount=0,!1}tryAddMeshData(e,t){const s=t.vertexBuffer,i=t.indexBuffer,r=U[e.geometryType],n=this._allocateVertices(r,e.vertexCount);if(n===-1)return this._freeVertices(r,n,e.vertexCount),!1;const a=this._allocateIndices(r,e.indexCount);if(a===-1)return this._freeVertices(r,n,e.vertexCount),this._freeIndices(r,a,e.indexCount),!1;const c=this._storageFor(r);if(le(n,a,c.vertexBuffers,c.indexBuffer,e,s,i),e.vertexFrom=n,e.indexFrom=a,this._dirtyMap){this._dirtyMap.markDirtyIndices(e.geometryType,e.indexFrom,e.indexCount);for(const d in s)this._dirtyMap.markDirtyVertices(e.geometryType,d,n,e.vertexCount)}return this._displayList.addToList(e),!0}_allocateVertices(e,t){var n,a;const s=this._storageFor(e),i=(n=s.vtxFreeList)==null?void 0:n.allocate(t);if(i==null||i===-1)return-1;const r=(a=s.vtxFreeList)==null?void 0:a.fragmentation;return r==null||r>Te?-1:i}_freeVertices(e,t,s){var r;(r=this._storageFor(e).vtxFreeList)==null||r.free(t,s)}_freeIndices(e,t,s){var r;(r=this._storageFor(e).idxFreeList)==null||r.free(t,s)}_allocateIndices(e,t){var n,a;const s=this._storageFor(e),i=(n=s.idxFreeList)==null?void 0:n.allocate(t);if(i==null||i===-1)return-1;const r=(a=s.idxFreeList)==null?void 0:a.fragmentation;return r==null||r>Te?-1:i}_storageFor(e){return this._freeListsAndStorage[e]}_stridesFor(e,t){return this._strides[e][t]}},Ht=class{constructor(e){this.geometryMap=yt(()=>({indexBuffer:De.createIndex(e,vt.STATIC_DRAW),vao:null}),(t,s)=>({vertexBuffer:De.createVertex(e,gt[s])}))}dispose(){var e,t,s;for(let i=0;i<5;i++){const r=this.geometryMap[i];if(r){(e=r.data.vao)==null||e.disposeVAOOnly(),(t=r.data.indexBuffer)==null||t.dispose();for(const n in r.buffers)(s=r.buffers[n])==null||s.data.vertexBuffer.dispose()}}}get(e){const t=this.geometryMap[e];return{getVAO(s,i,r){if(!t.data.vao){const n={};for(const a in t.buffers)n[a]=t.buffers[a].data.vertexBuffer;t.data.vao=new bt(s,r,i,n,t.data.indexBuffer)}return t.data.vao}}}has(e){return this.geometryMap[e]!=null}upload(e,t){t.forEach((s,i)=>{this._upload(s,i,e)})}_upload(e,t,s){if(e.indices&&(e.indices.allDirty?this._uploadIndices(s,t):e.indices.from!=null&&e.indices.count!=null&&this._uploadIndices(s,t,e.indices.from,e.indices.count)),e.vertices){const i=e.vertices;for(const r in i){const n=i[r];n.allDirty?this._uploadVertices(s,t,r):n.from!=null&&n.count!=null&&this._uploadVertices(s,t,r,n.from,n.count)}}}_uploadVertices(e,t,s,i,r){const n=this.geometryMap[t];if(!n)return;const a=e.geometries[t].vertexBuffer[s];if(!a)return;const{data:c,stride:d}=a;if(n.buffers[s]&&c.length>0){const l=d/c.BYTES_PER_ELEMENT;i!=null&&r!=null?n.buffers[s].data.vertexBuffer.setSubData(c,i*l,i*l,(i+r)*l):n.buffers[s].data.vertexBuffer.setData(c)}}_uploadIndices(e,t,s,i){const r=this.geometryMap[t];if(!r)return;const n=e.geometries[t].indexBuffer;r.data.indexBuffer&&n.length>0&&(s!=null&&i!=null?r.data.indexBuffer.setSubData(n,s,s,s+i):r.data.indexBuffer.setData(n))}};class Et extends Dt{constructor(){super(...arguments),this._data=null,this._displayList=null,this._lastCommitTime=0,this._hasData=!1,this._invalidated=!1,this._wglBuffers=null,this._dirtyMap=new we}destroy(){super.destroy(),this.clear()}get hasData(){return!!this._hasData}get displayObjects(){return this._displayObjects??[]}getGeometry(e){return this._wglBuffers&&this._wglBuffers.has(e)?this._wglBuffers.get(e):null}getDisplayList(){return this._displayList}patch(e){var i,r;if(e.clear===!0)return this.clear(),void(this._hasData=!1);const t=e.addOrUpdate,s=e.remove;!this._data&&((i=t==null?void 0:t.tileDisplayData)!=null&&i.displayObjects.length)?(t.tileDisplayData.computeDisplayList(),this._dirtyMap=new we,this._dispRecStore=Fe.fromTileData(t,this._dirtyMap),this._data=t,this._dirtyMap.markAllDirty(),this._hasData=!0,e.end&&this.ready()):this._data&&((r=t==null?void 0:t.tileDisplayData)!=null&&r.displayObjects.length||s.length)?this._doPatchData(e):e.end&&this.ready(),e.end&&!this._data&&this.clear(),this.requestRender(),this.emit("change")}commit(e){e.time&&e.time===this._lastCommitTime||(this._lastCommitTime=e.time,this.visible&&this._data&&(this._wglBuffers||(this._wglBuffers=new Ht(e.context)),(this._dirtyMap.hasDirty()||this._invalidated)&&(this._invalidated=!1,this._wglBuffers.upload(this._data.tileBufferData,this._dirtyMap),this._displayList=this._data.tileDisplayData.displayList.clone(),this._displayObjects=this._data.tileDisplayData.displayObjects.slice(),this._dirtyMap.markAllClean())))}clear(){this._data=null,this._displayList=null,this._dispRecStore=null,this._wglBuffers&&(this._wglBuffers.dispose(),this._wglBuffers=null)}_doPatchData(e){this._invalidated=!0,this._patchData(e)||(this._dirtyMap.markAllDirty(),this._data.reshuffle(),this._dispRecStore=Fe.fromTileData(this._data,this._dirtyMap)),this.requestRender()}_patchData(e){var a,c;let t=!0;const s=((c=(a=e.addOrUpdate)==null?void 0:a.tileDisplayData)==null?void 0:c.displayObjects)||[],i=(e.remove||[]).slice();for(const d of s)d.insertAfter!=null&&i.push(d.id);let r;i.length>0&&(r=new Set(i));const n=this._data.tileDisplayData;for(const d of i){const l=n.displayObjectRegistry.get(d);if(l){n.displayList.removeFromList(l.displayRecords);for(const h of l.displayRecords)this._dispRecStore.delete(h);n.displayObjectRegistry.delete(d)}}r!=null&&r.size&&(n.displayObjects=n.displayObjects.filter(d=>!r.has(d.id)));for(const d of s){let l,h=n.displayObjectRegistry.get(d.id);if(h){const m=h.displayRecords;h.set(d),h.displayRecords=m;const p=h.displayRecords.length;for(let f=0;f=d.displayRecords.length||x.geometryType!==g.geometryType||x.symbolLevel!==g.symbolLevel||x.zOrder!==g.zOrder||x.materialKey!==g.materialKey)&&(this._dispRecStore.delete(h.displayRecords[f]),f=0){const f=n.displayObjectRegistry.get(h.insertAfter);f?(m=p.indexOf(f)+1,m0?1:0;let x=0;for(let g=m-1;g>=0&&x=0&&xn.indexFrom&&i<=n.indexFrom+n.indexCount){if(i=0&&nc.indexFrom&&e.indexFromt.clone()),e.line=this.line&&this.line.map(t=>t.clone()),e.marker=this.marker&&this.marker.map(t=>t.clone()),e.text=this.text&&this.text.map(t=>t.clone()),e.label=this.label&&this.label.map(t=>t.clone()),e.unified=this.unified&&this.unified.map(t=>t.clone()),e}}let Nt=class Pe{constructor(){this.geometryDPInfo=new J}clone(){const e=new Pe;return e.zLevel=this.zLevel,e.geometryDPInfo=this.geometryDPInfo.clone(),e}};class pe{constructor(){this.zLevels=[]}clone(){const e=new pe;e.symbolLevel=this.symbolLevel;for(const t of this.zLevels)e.zLevels.push(t.clone());return e}}let Be=class{constructor(){this.vertexData=new Map,this.vertexCount=0,this.indexData=[]}clear(){this.vertexData.clear(),this.vertexCount=0,this.indexData=[]}update(e,t,s){for(const i in e)this.vertexData.set(i,e[i]);for(const i in this.vertexData)e[i]===null&&this.vertexData.delete(i);this.vertexCount=t,this.indexData=s}},he=class ce{constructor(e,t,s,i=0,r=0){this.id=e,this.geometryType=t,this.materialKey=s,this.minZoom=i,this.maxZoom=r,this.meshData=null,this.symbolLevel=0,this.zOrder=0,this.vertexFrom=0,this.vertexCount=0,this.indexFrom=0,this.indexCount=0,this._sortKey=null}get sortKey(){return this._sortKey==null&&this._computeSortKey(),this._sortKey}clone(){return this.copy()}copy(){const e=new ce(this.id,this.geometryType,this.materialKey);return e.vertexFrom=this.vertexFrom,e.vertexCount=this.vertexCount,e.indexFrom=this.indexFrom,e.indexCount=this.indexCount,e.zOrder=this.zOrder,e.symbolLevel=this.symbolLevel,e.meshData=this.meshData,e.minZoom=this.minZoom,e.maxZoom=this.maxZoom,e}setMeshDataFromBuffers(e,t,s){const i=new Be;for(const r in t){const n=t[r].stride,a=t[r].data;if(!a)continue;const c=[],d=Z(n);for(let l=0;lt.clone()),e.insertAfter=this.insertAfter,e}set(e){this.id=e.id,this.displayRecords=e.displayRecords,this.insertAfter=e.insertAfter}serialize(e){return e.push(this.id),Ue(e,this.displayRecords),e}static deserialize(e){const t=e.readInt32(),s=new X(t),i={id:t};return s.displayRecords=Zt(e,he,i)??[],s}};class j{constructor(){this.displayObjects=[],this._displayList=null}get displayObjectRegistry(){if(!this._displayObjectRegistry){this._displayObjectRegistry=new Map;for(const e of this.displayObjects)this._displayObjectRegistry.set(e.id,e)}return this._displayObjectRegistry}get displayList(){return this._displayList}computeDisplayList(){this._displayList=new qt;for(const e of this.displayObjects)for(const t of e.displayRecords)this._displayList.addToList(t)}clone(){const e=new j;return this.displayObjects&&(e.displayObjects=this.displayObjects.map(t=>t.clone())),e}serialize(e){return Ue(e,this.displayObjects),e}_deserializeObjects(e){const t=e.readInt32(),s=new Array(t),i=new Map;for(let r=0;r{const n=e.data[r];if(n!=null){const a=Ct.from(n.records).getCursor();for(;a.next();){const c=a.id,d=a.materialKey,l=a.indexFrom,h=a.indexCount,u=a.vertexFrom,m=a.vertexCount,p=i.get(c),f=new he(c,r,d);f.indexFrom=l,f.indexCount=h,f.vertexFrom=u,f.vertexCount=m,p.displayRecords.push(f)}s[r]=$.fromVertexData(n,r)}else s[r]=new Xt(r,0,Le.DEFAULT).intoBuffers()}),w.fromMeshData({displayObjects:t,vertexBuffersMap:s})}static fromMeshData(e){const t=new w,s=new j,i=new ie;s.displayObjects=e.displayObjects;for(const r in e.vertexBuffersMap){const n=r,a=e.vertexBuffersMap[n];i.geometries[n].indexBuffer=a.indexBuffer,i.geometries[n].vertexBuffer=a.namedBuffers}return t.tileDisplayData=s,t.tileBufferData=i,t}static bind(e,t){const s=new w;return s.tileDisplayData=e,s.tileBufferData=t,s}static create(e,t){const s=new w;s.tileDisplayData=new j,s.tileDisplayData.displayObjects=e;const i=[0,0,0,0,0],r=[0,0,0,0,0],n=[[],[],[],[],[]];for(const d of e)for(const l of d.displayRecords)n[l.geometryType].push(l),i[l.geometryType]+=l.meshData.vertexCount,r[l.geometryType]+=l.meshData.indexData.length;const a=new ie,c=Jt(t);for(let d=0;di?[D([o[0],o[1],i,o[3]]),D([s,o[1],s+o[2]-i,o[3]])]:o[0]!!a.geometry);for(const a of n){const c=ue(a.geometry);Gt(r,[a],c,!1,!1,t)}return new W(i,r,s)}constructor(e,t,s){super(e,t,null),this._transform=s}get geometryType(){const e=this._current;return e?e.geometryType:null}get insertAfter(){return this._current.insertAfter}readGraphic(){return this._current}getCursor(){return this.copy()}copy(){const e=new W(this.instance,this._features,this._transform);return this.copyInto(e),e}}const O=new ze,ne=new ze,Se="esriGeometryPolyline";function Ie(o){o.coords.length=0,o.lengths.length=0}class R{constructor(){this.bounds=D(),this.graphic=null}static acquire(e=null,t,s,i,r){let n;return R._pool.length===0?n=new R:(n=R._pool.pop(),this._set.delete(n)),n.acquire(e,t,s,i,r),n}static release(e){e&&!this._set.has(e)&&(e.release(),this._pool.push(e),this._set.add(e))}static getCentroidQuantized(e,t){if(ae(e.geometry)){const s=e.symbol;if(s==null)return null;if((s==null?void 0:s.layers.length)>0&&s.layers.some(i=>i.type==="text"||i.type==="marker")){const i=ke(e.geometry);return i!==null?jt(t,{},{x:i[0],y:i[1]},!1,!1):null}}return null}acquire(e=null,t,s,i,r){e&&this.set(e,t,s,i,r)}release(){this.graphic=null,this.symbolResource=null,this.geometry=null}get symbol(){return this.symbolResource.symbol}set(e,t,s,i,r){this.graphic=e,this.geometry=s,this.symbolResource=t,this.bounds=i,r&&(this.size=r)}getGeometryQuantized(e,t,s,i){const r=this.geometry,n=ue(r);if(n==null)return null;switch(n){case"esriGeometryPolygon":{const a=r,{rings:c}=a;if(!c||c.length===0)return null;let d;if(d=c.length===1&&c[0].length===2?G(e,{paths:[[c[0][0],c[0][1]]]}):G(e,this.geometry),!d){const l={x:c[0][0][0],y:c[0][0][1]};if(d=G(e,l),d){const{x:h,y:u}=d;return{rings:[[[h-1,u],[1,-1],[1,1],[-1,1],[-1,-1]]]}}}return d}case"esriGeometryPolyline":{const a=r;Ie(O),Ie(ne);const c=a.hasZ??!1,d=a.hasM??!1;return Ot(O,a),Pt(ne,O,c,d,Se,e.scale[0]),Ut(O,ne,c,d,Se,e),Vt(O,a.hasZ??!1,a.hasM??!1)}case"esriGeometryMultipoint":{const a=r,c=.5*i*Math.max(Math.abs(this.size[0])+this.size[2]-this.size[0],Math.abs(this.size[1])+this.size[3]-this.size[1]),d=V(s);let l=a.points;if(d){const[h,u]=d.valid,m=u-h;l=l.filter(p=>{if(p[0]+c>u||p[0]-cu?f[0]-=m:f[0]+=m,ee(t,p,c)||ee(t,f,c)}return ee(t,p,c)})}return l.length===0?{points:l}:G(e,{points:l})}}return G(e,this.geometry)}}R._pool=[],R._set=new Set;const P={minX:0,minY:0,maxX:0,maxY:0},L=D(),Me=1e-5;function N(o,e,t,s,i){return P.minX=e,P.minY=t,P.maxX=s,P.maxY=i,o.search(P)}function ns(o){return{minX:o.bounds[0],minY:o.bounds[1],maxX:o.bounds[2],maxY:o.bounds[3]}}class os{constructor(e,t,s,i,r,n,a){this._graphics=i,this._onAdd=r,this._onRemove=n,this._hashToCIM=a,this._index=Ke(9,ns),this._itemByGraphic=new Map,this._inflatedSizeHelper=new be,this._tileInfoView=e,this._uidFieldName=s;const c=e.getClosestInfoForScale(t);c&&(this._resolution=this._tileInfoView.getTileResolution(c.level))}setResourceManager(e){this._cimResourceManager=e,this._hittestDrawHelper=new ht(e)}hitTest(e,t,s,i,r){var p;e=He(e,this._tileInfoView.spatialReference);const n=.5*i*window.devicePixelRatio*s;L[0]=e-n,L[1]=t-n,L[2]=e+n,L[3]=t+n;const a=.5*i*(s+B),c=N(this._index,e-a,t-a,e+a,t+a);if(!c||c.length===0)return[];const d=[],l=D(),h=D();for(const f of c){const{geometry:x,symbolResource:g}=f;this._getSymbolBounds(l,g,x,h,r),h[3]=h[2]=h[1]=h[0]=0,Ee(l,L)&&((p=f.graphic)!=null&&p.visible)&&d.push(f)}if(d.length===0)return[];const u=this._hittestDrawHelper,m=[];for(const f of d){const{geometry:x,symbolResource:g}=f,{hash:_,textInfo:S}=g,T=this._hashToCIM.get(_);T&&u.hitTest(L,T.symbol,x,S,r,i)&&m.push(f)}return m.sort(as),m.map(f=>f.graphic)}getGraphicsData(e,t,s){const i=this._searchForItems(t);if(i.length===0||s.length===0)return[];i.sort((h,u)=>h.zorder-u.zorder),i[0].insertAfter=-1;for(let h=1;hh.graphic.uid-u.graphic.uid),s.sort((h,u)=>h.uid-u.uid);let r,n=0,a=0;const c=t.resolution,d=[],l={originPosition:"upperLeft",scale:[c,c],translate:[t.bounds[0],t.bounds[3]]};for(const h of s){for(a=-2;nh.zorder-u.zorder),d}queryTileData(e,t){if(this._graphics.length===0)return[];const{bounds:s,resolution:i}=t,r=this._searchForItems(t),n=[];return r.length===0||this._createTileGraphics(n,e,r,{originPosition:"upperLeft",scale:[i,i],translate:[s[0],s[3]]},t),n}has(e){return this._itemByGraphic.has(e)}getBounds(e){const t=this._itemByGraphic.get(e);return t?t.bounds:null}getAllBounds(){return Array.from(this._itemByGraphic.values()).filter(e=>e.graphic.visible).map(e=>e.bounds)}addOrModify(e,t,s){if(!e||t==null)return;this.has(e)&&this.remove(e),this._onAdd(e);const i=[0,0,0,0],r=this._getSymbolBounds(null,t,s,i,0),n=R.acquire(e,t,s,r??null,i);return this._itemByGraphic.set(e,n),s&&this._index.insert(n),n.bounds}remove(e){if(!this._itemByGraphic.has(e))return;this._onRemove(e);const t=this._itemByGraphic.get(e);t!=null&&t.bounds&&this._index.remove(t),this._itemByGraphic.delete(e)}updateZ(){const e=this._graphics.items;let t,s;for(let i=0;ip.zorder-f.zorder);for(let p=0;p{const t=Re(o.graphic),s=Re(e.graphic);return t===s?e.zorder-o.zorder:t-s},ls=Ze("esri-2d-graphic-debug");function oe(o,e,t){let s=t.get(o);return s||(s={tile:e,addedOrModified:[],removed:[]},t.set(o,s)),s}let b=class extends Ye(dt){constructor(o){super(o),this._storage=new At,this._displayIds=new Map,this._controller=new AbortController,this._tiles=new Map,this._graphicStoreUpdate=!1,this._graphicsSet=new Set,this._matcher=Promise.resolve(null),this._tileUpdateSet=new Set,this._tilesToUpdate=new Map,this._graphicIdToAbortController=new Map,this._attached=!1,this._updatingGraphicsTimer=null,this._hashToExpandedSymbol=new Map,this._hashToExpandedSymbolPromise=new Map,this._hashToCIMSymbolPromise=new Map,this._hashToCIM=new Map,this._processing=!1,this._needsProcessing=!1,this._pendingUpdate={added:new Set,updated:new Set,removed:new Set},this.lastUpdateId=-1,this.renderer=null,this.updateRequested=!1,this.defaultPointSymbolEnabled=!0,this.graphicUpdateHandler=this.graphicUpdateHandler.bind(this)}destroy(){this._updatingGraphicsTimer&&(clearTimeout(this._updatingGraphicsTimer),this._updatingGraphicsTimer=null,this.notifyChange("updating")),this._controller.abort(),this.container.destroy(),this._set("graphics",null),this._graphicStore.clear(),this._attributeStore=null,this._hashToExpandedSymbol.clear(),this.view=null,this.renderer=null,this._hashToCIM.clear(),this._hashToCIMSymbolPromise.clear(),this._hashToExpandedSymbolPromise.clear()}_createMatcher(o,e,t){if(o){const s=Ce(o),i=wt({indexCount:0,fields:{}},"feature",o,s);this._matcher=Bt(i,e,null,t)}}_createDisplayId(o){let e=this._displayIds.get(o);return e||(e=this._storage.createDisplayId(),this._displayIds.set(o,e)),e}initialize(){this._attributeStore=new $t({type:"local",initialize:i=>Promise.resolve(this.container.attributeView.initialize(i)),update:i=>this.container.attributeView.requestUpdate(i),render:()=>this.container.requestRender()},Xe("2d")),this.container.checkHighlight=()=>this._attributeStore.hasHighlight;const o=i=>{this._createDisplayId(i.uid),this._setFilterState(i.uid,i.visible)},e=i=>{const r=this._displayIds.get(i.uid);this._displayIds.delete(i.uid),this._storage.releaseDisplayId(r)},t=new Rt(this.container.getMaterialItems.bind(this.container),this.view.featuresTilingScheme.tileInfo);this._graphicStore=new os(this.view.featuresTilingScheme,this.view.state.scale,this.uid,this.graphics,o,e,this._hashToCIM),this._meshFactory=new St(null,this.uid,t),this._templateStore=t,this.addHandles([Qe(()=>this._effectiveRenderer,i=>{this._createMatcher(i,t,this.container.stage.resourceManager);for(const r of this.graphics)this._pendingUpdate.updated.add(r);this.requestUpdate()}),this.view.graphicsTileStore.on("update",this._onTileUpdate.bind(this)),this.container.on("attach",()=>{ls&&this.container.enableRenderingBounds(()=>this._graphicStore.getAllBounds()),this.graphics.items.length>0&&this._graphicsChangeHandler({target:this.graphics,added:this.graphics.items,removed:[],moved:[]}),this.addHandles(this.graphics.on("change",r=>this._graphicsChangeHandler(r)),"graphics");const i=this.container.stage.resourceManager;this._createMatcher(this._effectiveRenderer,t,i),this._graphicStore.setResourceManager(i),this._attached=!0,this.notifyChange("updating")})]);const s=this.view.graphicsTileStore.tiles;this._onTileUpdate({added:s,removed:[]})}get _effectiveRenderer(){return typeof this.renderer=="function"?this.renderer():this.renderer}get updating(){var o;return!this._attached||this._updatingGraphicsTimer!==null||this._pendingUpdate.added.size>0||this._pendingUpdate.removed.size>0||this._pendingUpdate.updated.size>0||this._tileUpdateSet.size>0||this._tilesToUpdate.size>0||((o=this._attributeStore)==null?void 0:o.updatingHandles.updating)||this._processing}hitTest(o){if(!this.view||this.view.suspended)return[];const{resolution:e,rotation:t}=this.view.state;return this._graphicStore.hitTest(o.x,o.y,2,e,t)}update(o){v(this._controller.signal);const e=o.state,{resolution:t}=e;if(this._graphicStore.updateLevel(t),this._graphicStoreUpdate=!0,this.updateRequested=!1,this._pendingUpdate.updated.size>0){if(!this._processing)return void this._updateGraphics();this._needsProcessing=!0}}viewChange(){this.requestUpdate()}requestUpdate(){this.updateRequested||(this.updateRequested=!0,this.requestUpdateCallback())}processUpdate(o){this.updateRequested&&(this.updateRequested=!1,this.update(o))}graphicUpdateHandler(o){const{graphic:e,property:t}=o;switch(t){case"attributes":case"geometry":case"symbol":this._pendingUpdate.updated.add(e),this.requestUpdate();break;case"visible":this._setFilterState(e.uid,e.visible),this._attributeStore.sendUpdates()}}setHighlight(o){const e=o.map(t=>this._displayIds.get(t)).filter(We);this._attributeStore.setHighlight(o,e)}_getIntersectingTiles(o){const e=this._graphicStore.getBounds(o);if(!e||Je(e)===0||et(e)===0)return[];const t=ts(e,this.view.spatialReference);return t!=null?[...new Set([...this.view.graphicsTileStore.boundsIntersections(t[0]),...this.view.graphicsTileStore.boundsIntersections(t[1])])]:this.view.graphicsTileStore.boundsIntersections(e)}async _updateTile(o){v(this._controller.signal);const e=o.tile,t=this._getGraphicsData(this._templateStore,e,o.addedOrModified),s=await this._processGraphics(e,t);return v(this._controller.signal),this._patchTile(e.key,{type:"update",addOrUpdate:s,remove:o.removed,end:!0,clear:!1,sort:!1}),s}_patchTile(o,e){const t=this._tiles.get(o);t&&(this.container.onTileData(t,e),this.container.requestRender())}_graphicsChangeHandler(o){const e=this._pendingUpdate;for(const t of o.added)e.added.add(t);for(const t of o.moved)e.updated.add(t);for(const t of o.removed)this._pendingUpdate.added.has(t)?e.added.delete(t):e.removed.add(t);this._processing?this._needsProcessing=!0:this._updateGraphics()}_getGraphicsToUpdate(){const o={added:[],removed:[],updated:[]};if(!this.graphics)return o;const e=this._pendingUpdate;for(const t of this.graphics.items)e.added.has(t)?o.added.push(t):e.updated.has(t)&&o.updated.push(t);for(const t of e.removed)this._graphicStore.has(t)&&o.removed.push(t);return e.added.clear(),e.removed.clear(),e.updated.clear(),o}async _updateGraphics(){this._processing=!0;const{added:o,removed:e,updated:t}=this._getGraphicsToUpdate(),s=this._tilesToUpdate;let i;try{if(!this._graphicStoreUpdate){const l=this.view.state,{resolution:h}=l;this._graphicStore.updateLevel(h)}const r=[],n=new Array(o.length+e.length);for(let l=0;l({name:t,alias:t,type:typeof o.attributes[t]=="string"?"esriFieldTypeString":"esriFieldTypeDouble"}));return o.geometry==null?null:{geometryType:ue(o.geometry),spatialReference:tt.fromJSON(o.geometry.spatialReference),fields:e}}_getSymbolForGraphic(o,e){return v(this._controller.signal),o.symbol!=null?Promise.resolve(o.symbol):this._effectiveRenderer!=null?this._effectiveRenderer.getSymbolAsync(o,{scale:this.view.state.scale,signal:e!=null?e.signal:null}):Promise.resolve(this._getNullSymbol(o))}_getCIMSymbol(o,e,t){let s=this._hashToCIM.get(e);if(s)return Promise.resolve(s);const i=ct(o);if(i!=null){if(i.type==="CIMSymbolReference")return s=i,this._hashToCIM.set(e,s),Promise.resolve(s);let r=this._hashToCIMSymbolPromise.get(e);return r||(r=i.fetchCIMSymbol(t).then(n=>(this._hashToCIM.set(e,n.data),this._hashToCIMSymbolPromise.delete(e),n)).catch(n=>(this._hashToCIMSymbolPromise.delete(e),ge(n),null)),this._hashToCIMSymbolPromise.set(e,r),r)}return Promise.resolve(null)}_expandCIMSymbol(o,e,t,s){const i=this._hashToExpandedSymbol.get(t);if(i)return Promise.resolve(i);let r=this._hashToExpandedSymbolPromise.get(t);if(r)return r;const n=this.container.stage,a=this._getArcadeInfo(e),c=Ce(null),d=Tt(o,c);return r=It(d,a,n.resourceManager,s),this._hashToExpandedSymbolPromise.set(t,r),r.then(l=>(this._hashToExpandedSymbol.set(t,l),this._hashToExpandedSymbolPromise.delete(t),l)),r}async _getSymbolResources(o,e){return v(this._controller.signal),this.container.stage?this._getSymbolForGraphic(o,e).then(t=>{if(!t)return null;const s=t.hash();return this._getCIMSymbol(t,s,e).then(i=>i==null?null:this._expandCIMSymbol(i,o,s,e).then(r=>{const n=r.layers.filter(a=>a.type==="text"&&typeof a.text=="string");if(n&&n.length>0){const a=new Array(n.length);for(let d=0;d{st(d);for(let l=0;l(ge(t),null)):null}async _projectAndNormalizeGeometry(o,e){if(v(this._controller.signal),o.geometry==null||o.geometry.type==="mesh")return null;let t=o.geometry;if(ae(t)){const r=t.rings;t.rings=r}else if(xe(t)){const r=t.paths;t.paths=r}else if(_e(t)){const r=await this._getSymbolForGraphic(o,e);v(this._controller.signal),r&&(is(r.type)||ss(r.type))?t=t.center:t=rs(t)}await ft(t.spatialReference,this.view.spatialReference);const s=it(t),i=pt(s,t.spatialReference,this.view.spatialReference);return i&&rt(i),i}_onTileUpdate(o){const e=V(this.view.spatialReference);if(o.added&&o.added.length>0)for(const t of o.added)this._addNewTile(t,e);if(o.removed&&o.removed.length>0)for(const t of o.removed)this._removeTile(t.key)}async _addGraphic(o){this._abortProcessingGraphic(o.uid),v(this._controller.signal);const e=new AbortController;this._graphicIdToAbortController.set(o.uid,e);const t={signal:e.signal};try{await this._addOrUpdateGraphic(o,t),v(this._controller.signal),this._graphicIdToAbortController.delete(o.uid)}catch(s){if(this._graphicIdToAbortController.delete(o.uid),!K(s))throw s}}_updateGraphic(o,e){v(this._controller.signal);const t=this._projectAndNormalizeGeometry(o,e),s=this._getSymbolResources(o,e);return Promise.all([t,s]).then(([i,r])=>{v(this._controller.signal),this._graphicStore.addOrModify(o,r,i)})}_addOrUpdateGraphic(o,e){v(this._controller.signal);const t=this._projectAndNormalizeGeometry(o,e),s=this._getSymbolResources(o,e);return Promise.all([t,s]).then(([i,r])=>{v(this._controller.signal),this._graphicsSet.has(o)&&this._graphicStore.addOrModify(o,r,i)})}_addTile(o){const e=this.view.featuresTilingScheme.getTileBounds(D(),o),t=this.view.featuresTilingScheme.getTileResolution(o.level),s=new Et(o,t,e[0],e[3]);return this._tiles.set(o,s),this.container.addChild(s),s}async _addNewTile(o,e){const t=this._addTile(o.key),s=this._graphicStore.queryTileData(this._templateStore,o);if(s.length===0)return;if(e){const r=Math.round((e.valid[1]-e.valid[0])/o.resolution);for(const n of s)n.geometry&&(ve(n.geometry)||te(n.geometry))&&this._wrapPoints(n,r)}const i=o.key;this._tileUpdateSet.add(o.key),this.notifyChange("updating");try{const r={type:"update",clear:!1,addOrUpdate:await this._processGraphics(o,s),remove:[],end:!0,sort:!1};t.patch(r),this._tileUpdateSet.delete(i),this.notifyChange("updating")}catch(r){if(this._tileUpdateSet.delete(i),this.notifyChange("updating"),!K(r))throw r}}_removeTile(o){if(!this._tiles.has(o))return;const e=this._tiles.get(o);this.container.removeChild(e),e.destroy(),this._tiles.delete(o)}_setFilterState(o,e){const t=this._displayIds.get(o),s=this._attributeStore.getHighlightFlag(o);this._attributeStore.setData(t,0,0,s|(e?mt:0))}_getGraphicsData(o,e,t){const s=this.view,i=V(s.spatialReference),r=this._graphicStore.getGraphicsData(o,e,t);if(i){const n=Math.round((i.valid[1]-i.valid[0])/e.resolution);for(const a of r)a.geometry&&(ve(a.geometry)||te(a.geometry))&&this._wrapPoints(a,n)}return r}_wrapPoints(o,e){const t=o.geometry;te(t)?this._wrapMultipoint(t,e):this._wrapPoint(o,e)}_wrapMultipoint(o,e){const t=o.points,s=[];let i=0,r=0;for(const[n,a]of t){if(s.push([n+i,a]),i=0,e===M){const c=5*B;n+rM-c&&(s.push([-e,0]),i=e)}else n+r<-B?(s.push([e,0]),i=-e):n+r>M+B&&(s.push([-e,0]),i=e);r+=n}o.points=s}_wrapPoint(o,e){const t=o.geometry;if(e===M){const s=5*B;t.xM-s&&(o.geometry={points:[[t.x,t.y],[-e,0]]})}else t.x<-B?o.geometry={points:[[t.x,t.y],[e,0]]}:t.x>M+B&&(o.geometry={points:[[t.x,t.y],[-e,0]]})}_processGraphics(o,e,t){if(!(e&&e.length)||!this._meshFactory)return Promise.resolve(null);const s=W.from(e,this.uid,o.transform),i=this._meshFactory;return this._matcher.then(r=>i.analyzeGraphics(s,this.container.stage.resourceManager,r,null,null,t).then(()=>(this._attributeStore.sendUpdates(),this._processAnalyzedGraphics(o,s))))}_processAnalyzedGraphics(o,e){const t=this._meshFactory,s=e.getSize(),i=e.getCursor(),r={features:s,records:s,metrics:0},n=new Mt(o.key.id,r,Le.DEFAULT,!1,!1),a=[];for(;i.next();){const h=i.readGraphic();h.insertAfter=h.insertAfter===-1?-1:this._displayIds.get(h.insertAfter),h.displayId=this._displayIds.get(h.attributes[this.uid]);const u=new Ve(h.displayId);u.insertAfter=h.insertAfter,a.push(u),t.writeGraphic(n,i,o.level,this.container.stage.resourceManager)}const c=o.tileInfoView.tileInfo.isWrappable,d=n.serialize(c);if(d.length!==1)return new w;const l=d[0].message;return w.fromVertexData(l,a)}_abortProcessingGraphic(o){var e;(e=this._graphicIdToAbortController.get(o))==null||e.abort()}_getNullSymbol(o){const e=o.geometry;return xe(e)?nt:ae(e)||_e(e)?ot:this.defaultPointSymbolEnabled?at:null}_flipUpdatingGraphics(){this._updatingGraphicsTimer&&clearTimeout(this._updatingGraphicsTimer),this._updatingGraphicsTimer=setTimeout(()=>{this._updatingGraphicsTimer=null,this.notifyChange("updating")},160),this.notifyChange("updating")}};C([F()],b.prototype,"_effectiveRenderer",null),C([F({constructOnly:!0})],b.prototype,"requestUpdateCallback",void 0),C([F()],b.prototype,"container",void 0),C([F({constructOnly:!0})],b.prototype,"graphics",void 0),C([F()],b.prototype,"renderer",void 0),C([F()],b.prototype,"updating",null),C([F()],b.prototype,"view",void 0),C([F()],b.prototype,"updateRequested",void 0),C([F()],b.prototype,"defaultPointSymbolEnabled",void 0),b=C([lt("esri.views.2d.layers.support.GraphicsView2D")],b);const Is=b;export{Is as r};