import{s as $,e as P,i as L,n as Z,N as Q,I as Y}from"./featureConversionUtils-6aca8295.js";import{t as w,s as _}from"./OptimizedGeometry-d94e541f.js";import{Y as c,ep as J,ia as q,ib as V,$ as X,cy as U,z as W,i9 as K,eg as tt,aj as et,v as M,s as C,_ as st,au as rt}from"./index-b5c8f851.js";import{m as S,n as O,b as v}from"./TimeOnly-99f1af45.js";import{a as it,l as nt,c as at,u as ot,f as g,e as ut,i as ht,n as dt,b as lt,d as ct,s as B,g as h}from"./visualVariablesUtils-f4ae79f2.js";import{V as _t,W as ft,S as pt,t as R,Q as gt,R as mt}from"./definitions-1467ba4a.js";import{W as yt}from"./color-0916c686.js";import{U as f}from"./enums-bdecffa2.js";class y{static fromBuffer(t,e){return new y(t,e)}static create(t,e=4294967295){const s=new Uint32Array(Math.ceil(t/32));return new y(s,e)}constructor(t,e){this._mask=0,this._buf=t,this._mask=e}_getIndex(t){return Math.floor(t/32)}has(t){const e=this._mask&t;return!!(this._buf[this._getIndex(e)]&1<>>=1,r++}}countSet(){let t=0;return this.forEachSet(e=>{t++}),t}}let x=0;const F=c("featurelayer-simplify-thresholds")??[.5,.5,.5,.5],bt=F[0],xt=F[1],It=F[2],Tt=F[3],k=c("featurelayer-simplify-payload-size-factors")??[1,2,4],St=k[0],At=k[1],zt=k[2],Ft=c("featurelayer-simplify-mobile-factor")??2,Dt=c("esri-mobile");let G=class{constructor(t,e){this.type="FeatureSetReader",this.arcadeDeclaredClass="esri.arcade.Feature",this.seen=!1,this.instance=0,this._tx=0,this._ty=0,this._sx=1,this._sy=1,this._deleted=null,this._joined=[],this._objectIdToIndex=null,this._contextTimeZone=null,this._level=0,this.instance=t,this._layerSchema=e}static createInstance(){return x++,x=x>65535?0:x,x}get isEmpty(){return this._deleted!=null&&this._deleted.countSet()===this.getSize()}get contextTimeZone(){return this._contextTimeZone}set contextTimeZone(t){this._contextTimeZone=t}set level(t){this._level=t}getAreaSimplificationThreshold(t,e){let s=1;const r=Dt?Ft:1;e>4e6?s=zt*r:e>1e6?s=At*r:e>5e5?s=St*r:e>1e5&&(s=r);let i=0;t>4e3?i=Tt*s:t>2e3?i=It*s:t>100?i=xt:t>15&&(i=bt);let n=8;return this._level<4?n=1:this._level<5?n=2:this._level<6&&(n=4),i*n}createQuantizedExtrudedGeometry(t,e){return this.geometryType==="esriGeometryPolyline"?this._createQuantizedExtrudedLine(t,e):this._createQuantizedExtrudedQuad(t,e)}_createQuantizedExtrudedQuad(t,e){return new w([5],[t-1,e,1,-1,1,1,-1,1,-1,-1])}_createQuantizedExtrudedLine(t,e){return new w([2],[t-1,e+1,1,-1])}parseTimestampOffset(t){return t}setArcadeSpatialReference(t){this._arcadeSpatialReference=t}attachStorage(t){this._storage=t}getQuantizationTransform(){throw new Error("Unable to find transform for featureSet")}getStorage(){return this._storage}getComputedNumeric(t){return this.getComputedNumericAtIndex(0)}setComputedNumeric(t,e){return this.setComputedNumericAtIndex(e,0)}getComputedString(t){return this.getComputedStringAtIndex(0)}setComputedString(t,e){return this.setComputedStringAtIndex(0,e)}getComputedNumericAtIndex(t){return this._storage.getComputedNumericAtIndex(this.getDisplayId(),t)}setComputedNumericAtIndex(t,e){this._storage.setComputedNumericAtIndex(this.getDisplayId(),t,e)}getComputedStringAtIndex(t){return this._storage.getComputedStringAtIndex(this.getDisplayId(),t)}setComputedStringAtIndex(t,e){return this._storage.setComputedStringAtIndex(this.getDisplayId(),t,e)}transform(t,e,s,r){const i=this.copy();return i._tx+=t,i._ty+=e,i._sx*=s,i._sy*=r,i}readAttributeAsTimestamp(t){const e=this.readAttribute(t);return typeof e=="string"?new Date(e).getTime():typeof e=="number"||e==null?e:null}readAttribute(t,e=!1){const s=this._readAttribute(t,e);if(s!==void 0)return s;for(const r of this._joined){r.setIndex(this.getIndex());const i=r._readAttribute(t,e);if(i!==void 0)return i}}readAttributes(){const t=this._readAttributes();for(const e of this._joined){e.setIndex(this.getIndex());const s=e._readAttributes();for(const r of Object.keys(s))t[r]=s[r]}return t}joinAttributes(t){this._joined.push(t)}readArcadeFeature(){return this}hasField(t){return this.fields.has(t)}geometry(){const t=this.readHydratedGeometry(),e=$(t,this.geometryType,this.hasZ,this.hasM),s=J(e);return s&&(s.spatialReference=this._arcadeSpatialReference),s}autocastArcadeDate(t,e){return e&&e instanceof Date?this.isUnknownDateTimeField(t)?S.unknownDateJSToArcadeDate(e):S.dateJSAndZoneToArcadeDate(e,this.contextTimeZone??q):e}isUnknownDateTimeField(t){return this._layerSchema.fieldsIndex.getTimeZone(t)===V}field(t){let e=this.fields.get(t);if(e)switch(e.type){case"date-only":case"esriFieldTypeDateOnly":return v.fromReader(this.readAttribute(t,!1));case"time-only":case"esriFieldTypeTimeOnly":return O.fromReader(this.readAttribute(t,!1));case"esriFieldTypeTimestampOffset":case"timestamp-offset":return S.fromReaderAsTimeStampOffset(this.readAttribute(t,!1));case"date":case"esriFieldTypeDate":return this.autocastArcadeDate(t,this.readAttribute(t,!0));default:return this.readAttribute(t,!1)}for(const s of this._joined)if(s.setIndex(this.getIndex()),e=s.fields.get(t),e)switch(e.type){case"date-only":case"esriFieldTypeDateOnly":return v.fromReader(s._readAttribute(t,!1));case"time-only":case"esriFieldTypeTimeOnly":return O.fromReader(s._readAttribute(t,!1));case"esriFieldTypeTimestampOffset":case"timestamp-offset":return S.fromReaderAsTimeStampOffset(s._readAttribute(t,!1));case"date":case"esriFieldTypeDate":return this.autocastArcadeDate(t,s._readAttribute(t,!0));default:return this.readAttribute(t,!1)}throw new Error(`Field ${t} does not exist`)}setField(t,e){throw new Error("Unable to update feature attribute values, feature is readonly")}keys(){return this.fields.fields.map(t=>t.name)}castToText(t=!1){if(!t)return JSON.stringify(this.readLegacyFeature());const e=this.readLegacyFeature();if(!e)return JSON.stringify(null);const s={geometry:e.geometry,attributes:{...e.attributes??{}}};for(const r in s.attributes){const i=s.attributes[r];i instanceof Date&&(s.attributes[r]=i.getTime())}return JSON.stringify(s)}gdbVersion(){return null}fullSchema(){return this._layerSchema}castAsJson(t=null){var e;return{attributes:this._readAttributes(),geometry:(t==null?void 0:t.keepGeometryType)===!0?this.geometry():((e=this.geometry())==null?void 0:e.toJSON())??null}}castAsJsonAsync(t=null,e=null){return Promise.resolve(this.castAsJson(e))}removeIds(t){if(this._objectIdToIndex==null){const s=new Map,r=this.getCursor();for(;r.next();){const i=r.getObjectId();X(i),s.set(i,r.getIndex())}this._objectIdToIndex=s}const e=this._objectIdToIndex;for(const s of t)e.has(s)&&this.removeAtIndex(e.get(s))}removeAtIndex(t){this._deleted==null&&(this._deleted=y.create(this.getSize())),this._deleted.set(t)}readGeometryForDisplay(){return this.readUnquantizedGeometry(!0)}readLegacyGeometryForDisplay(){return this.readLegacyGeometry(!0)}*features(){const t=this.getCursor();for(;t.next();)yield t.readOptimizedFeature()}_getExists(){return this._deleted==null||!this._deleted.has(this.getIndex())}_computeCentroid(){if(this.geometryType!=="esriGeometryPolygon")return null;const t=this.readUnquantizedGeometry();if(!t||t.hasIndeterminateRingOrder)return null;const e=it.fromOptimized(t,this.geometryType);e.yFactor*=-1;const s=nt(e);return s?(s[1]*=-1,new w([],s)):null}copyInto(t){t.seen=this.seen,t._storage=this._storage,t._arcadeSpatialReference=this._arcadeSpatialReference,t._joined=this._joined,t._tx=this._tx,t._ty=this._ty,t._sx=this._sx,t._sy=this._sy,t._deleted=this._deleted,t._objectIdToIndex=this._objectIdToIndex,t.contextTimeZone=this.contextTimeZone}};function wt({coords:d,lengths:t}){let e=0;for(const s of t){for(let r=1;r!(s.objectId!=null&&e.has(s.objectId)))}append(t){for(const e of t)this._features.push(e)}getSize(){return this._features.length}getCursor(){return this.copy()}getQuantizationTransform(){return this._transform}getAttributeHash(){let t="";for(const e in this._current.attributes)t+=this._current.attributes[e];return t}getIndex(){return this._featureIndex}setIndex(t){this._featureIndex=t}getObjectId(){var t;return(t=this._current)==null?void 0:t.objectId}getDisplayId(){return this._current.displayId}setDisplayId(t){this._current.displayId=t}getGroupId(){return this._current.groupId}setGroupId(t){this._current.groupId=t}copy(){const t=new p(this.instance,this._features,this.fullSchema());return this.copyInto(t),t}next(){for(;++this._featureIndext(d(e))}class Ct{constructor(t,e,s,r){this.size=0,this.texelSize=4,this.dirtyStart=0,this.dirtyEnd=0;const{pixelType:i,layout:n,textureOnly:a}=r;this.textureOnly=a||!1,this.pixelType=i,this._ctype=e,this.layout=n,this._resetRange(),this._shared=t,this.size=s,a||(this.data=this._initData(i,s,t,e))}get buffer(){var t;return(t=this.data)==null?void 0:t.buffer}unsetComponentAllTexels(t,e){const s=this.data;for(let r=0;re)return null;this._resetRange();const r=!(this._shared||this._ctype==="local"),i=this.pixelType,n=this.layout,a=this.data;return{start:t,end:e,data:r&&a.slice(t*s,(e+1)*s)||null,pixelType:i,layout:n}}_initData(t,e,s,r){const i=s&&r!=="local"?SharedArrayBuffer:ArrayBuffer,n=yt(t),a=new n(new i(e*e*4*n.BYTES_PER_ELEMENT));for(let u=0;unull)}destroy(){this._abortController.abort(),this.updatingHandles.destroy()}get hasScaleExpr(){return this._hasScaleExpr}get _signal(){return this._abortController.signal}get hasHighlight(){return this._idsToHighlight.size>0}isUpdating(){const t=this.updatingHandles.updating||!!this._nextUpdate;return c("esri-2d-log-updating")&&console.log(`Updating AttributeStore: ${t} -> updatingHandles ${this.updatingHandles.updating} (currUpdate: ${!!this._currUpdate}) -> nextUpdate: ${!!this._nextUpdate} `),t}update(t,e){this.config=e;const s=e.schema.processors[0].storage,r=tt(this._schema,s);if((t.targets.feature||t.targets.aggregate)&&(t.storage.data=!0),r&&(c("esri-2d-update-debug")&&console.debug("Applying Update - AttributeStore:",r),t.storage.data=!0,this._schema=s,this._attributeComputeInfo=null,s!=null)){switch(s.target){case"feature":this._targetType=ot;break;case"aggregate":this._targetType=at}if(s.type==="subtype"){this._attributeComputeInfo={isSubtype:!0,subtypeField:s.subtypeField,map:new Map};for(const i in s.mapping){const n=s.mapping[i];if((n==null?void 0:n.vvMapping)!=null)for(const a of n.vvMapping)this._bindAttribute(a,parseInt(i,10))}}else{if(this._attributeComputeInfo={isSubtype:!1,map:new Map},s.vvMapping!=null)for(const i of s.vvMapping)this._bindAttribute(i);if(s.attributeMapping!=null)for(const i of s.attributeMapping)this._bindAttribute(i)}}}onTileData(t,e){if(e.addOrUpdate==null)return;const s=e.addOrUpdate.getCursor();for(;s.next();){const r=s.getDisplayId();this.setAttributeData(r,s)}}async setHighlight(t,e){const r=this._getBlock(0),i=e.map(n=>g(n));r.lock(),r.unsetComponentAllTexels(0,1),r.setComponent(0,1,i),r.unlock(),this._idsToHighlight.clear();for(const n of t)this._idsToHighlight.add(n);await this.sendUpdates()}async updateFilters(t,e,s){c("esri-2d-update-debug")&&console.debug("AttributeStore::updateFilters");const{service:r,spatialReference:i}=s,{filters:n}=e,a=n.map((o,l)=>this._updateFilter(o,l,r,i)),u=(await Promise.all(a)).some(o=>o);c("esri-2d-update-debug")&&console.debug("AttributeStore::updateFilters - finsihed"),u&&(t.storage.filters=!0,c("esri-2d-update-debug")&&console.debug("Applying Update - AttributeStore:","Filters changed"))}setData(t,e,s,r){const i=g(t);this._ensureSizeForTexel(i),this._getBlock(e).setData(t,s,r)}getData(t,e,s){return this._getBlock(e).getData(t,s)}getHighlightFlag(t){return this._idsToHighlight.has(t)?ft:0}unsetAttributeData(t){const e=g(t);this._getBlock(0).setData(e,0,0)}setAttributeData(t,e){const s=g(t);if(this._ensureSizeForTexel(s),this._getBlock(0).setData(s,0,this.getFilterFlags(e)),this._targetType!==ut(t))return;const r=this._attributeComputeInfo,i=this.config.supportsTextureFloat?1:2,n=4;let a=null;r&&(a=r.isSubtype?r.map.get(e.readAttribute(r.subtypeField)):r.map,a!=null&&a.size&&a.forEach((u,o)=>{const l=o*i%n,T=Math.floor(o*i/n),b=this._getBlock(T+pt),D=u(e);if(this.config.supportsTextureFloat)b.setData(s,l,D);else if(D===R)b.setData(s,l,255),b.setData(s,l+1,255);else{const N=rt(Math.round(D),-32767,32766)+32768,j=255&N,H=(65280&N)>>8;b.setData(s,l,j),b.setData(s,l+1,H)}}))}sendUpdates(){if(c("esri-2d-update-debug")&&console.debug("AttributeStore::sendUpdate"),this._nextUpdate)return this._nextUpdate.promise;if(this._currUpdate)return this._nextUpdate=et(),this.updatingHandles.addPromise(this._nextUpdate.promise),this._nextUpdate.promise;const t={blocks:this._blocks.map(e=>e!=null?e.toMessage():null)};return this._currUpdate=this._createResources().then(()=>{const e=()=>{if(this._currUpdate=null,this._nextUpdate){const r=this._nextUpdate;this._nextUpdate=null,this.sendUpdates().then(()=>r.resolve())}else c("esri-2d-update-debug")&&console.debug("AttributeStore::sendUpdate::No additional updates queued")};c("esri-2d-update-debug")&&console.debug("AttributeStore::sendUpdate::client.update");const s=this.updatingHandles.addPromise(this._client.update(t,this._signal).then(e).catch(e));return this._client.render(this._signal),s}).catch(e=>{if(M(e))return this._createResourcesPromise=null,this._createResources();m.error(new C("mapview-attribute-store","Encountered an error during client update",e))}),this._currUpdate}_ensureSizeForTexel(t){for(;t>=this._size*this._size;)if(this._expand())return}_bindAttribute(t,e){function s(){const{normalizationField:o}=t;return o?l=>{const T=l.readAttribute(o);return T?l.readAttribute(t.field)/T:null}:l=>l.readAttribute(t.field)}function r(){return t.normalizationField&&m.warn("mapview-arcade","Ignoring normalizationField specified with an arcade expression which is not supported."),o=>o.getComputedNumericAtIndex(t.fieldIndex)}let i;if(t.fieldIndex!=null)i=r();else{if(!t.field)return;i=s()}const{valueRepresentation:n}=t;n&&(i=E(i,o=>ct(o,n)));const a=o=>o===null||isNaN(o)||o===1/0||o===-1/0?R:o,u=this._attributeComputeInfo;if(u.isSubtype){const o=u.map.get(e)??new Map;o.set(t.binding,E(i,a)),u.map.set(e,o)}else u.map.set(t.binding,E(i,a))}_createResources(){if(this._createResourcesPromise!=null)return this._createResourcesPromise;this._getBlock(gt),this._getBlock(mt),A("Initializing AttributeStore");const t={shared:I.sharedArrayBuffer&&this._client.type!=="local",size:this._size,blocks:this._blocks.map(s=>s!=null?{textureOnly:s.textureOnly,buffer:s.buffer,pixelType:s.pixelType}:null)},e=this._client.initialize(t,this._signal).catch(s=>{M(s)?this._createResourcesPromise=null:m.error(new C("mapview-attribute-store","Encountered an error during client initialization",s))});return this._createResourcesPromise=e,e.then(()=>this._createResourcesPromise==null?this._createResources():void 0),e}_getBlock(t){const e=this._blocks[t];if(e!=null)return e;A(`Initializing AttributeBlock at index ${t}`);const s=I.sharedArrayBuffer,r=this._client.type,i=new Ct(s,r,this._size,this._blockDescriptors[t]);return this._blocks[t]=i,this._createResourcesPromise=null,i}_expand(){if(this._sizeimport("./FeatureFilter-575e642a.js"),["assets/FeatureFilter-575e642a.js","assets/index-b5c8f851.js","assets/index-86716609.css","assets/timeSupport-b4d06407.js","assets/projectionSupport-d15822a5.js","assets/json-48e3ea08.js","assets/featureConversionUtils-6aca8295.js","assets/OptimizedGeometry-d94e541f.js","assets/OptimizedFeatureSet-1d1ac4b9.js","assets/FeatureStore2D-db06c1ba.js","assets/CircularArray-ef508845.js","assets/TimeOnly-99f1af45.js","assets/visualVariablesUtils-f4ae79f2.js","assets/color-0916c686.js","assets/enums-f1a6a48a.js","assets/enums-bdecffa2.js","assets/VertexElementDescriptor-2925c6af.js","assets/definitions-1467ba4a.js"]),i=new r({geometryType:e.geometryType,hasM:!1,hasZ:!1,timeInfo:e.timeInfo,fieldsIndex:U.fromJSON(e.fieldsIndex)});return this._filters[t]=i,i}isVisible(t){return!!(2&this._getBlock(0).getData(t,0))}getFilterFlags(t){let e=0;const s=ht(t.getDisplayId());for(let i=0;it))for(;d.length<=t;)d.push(e)}class Pt{constructor(){this._numerics=[],this._strings=[],this._idGenerator=new Et,this._allocatedSize=256,this._bitsets=[],this._instanceIds=[],this._bounds=[]}createBitset(){const t=this._bitsets.length;return this._bitsets.push(y.create(this._allocatedSize,h)),t+1}getBitset(t){return this._bitsets[t-1]}_expand(){this._allocatedSize<<=1;for(const t of this._bitsets)t.resize(this._allocatedSize)}_ensureNumeric(t,e){this._numerics[t]||(this._numerics[t]=[]),z(this._numerics[t],e,0)}_ensureInstanceId(t){z(this._instanceIds,t,0)}_ensureString(t,e){this._strings[t]||(this._strings[t]=[]),z(this._strings[t],e,null)}createDisplayId(t=!1){const e=this._idGenerator.createId();return e>this._allocatedSize&&this._expand(),B(e,t)}releaseDisplayId(t){for(const e of this._bitsets)e.unset(t);return this._idGenerator.releaseId(t&h)}getComputedNumeric(t,e){return this.getComputedNumericAtIndex(t&h,0)}setComputedNumeric(t,e,s){return this.setComputedNumericAtIndex(t&h,s,0)}getComputedString(t,e){return this.getComputedStringAtIndex(t&h,0)}setComputedString(t,e,s){return this.setComputedStringAtIndex(t&h,0,s)}getComputedNumericAtIndex(t,e){const s=t&h;return this._ensureNumeric(e,s),this._numerics[e][s]}setComputedNumericAtIndex(t,e,s){const r=t&h;this._ensureNumeric(e,r),this._numerics[e][r]=s}getInstanceId(t){const e=t&h;return this._ensureInstanceId(e),this._instanceIds[e]}setInstanceId(t,e){const s=t&h;this._ensureInstanceId(s),this._instanceIds[s]=e}getComputedStringAtIndex(t,e){const s=t&h;return this._ensureString(e,s),this._strings[e][s]}setComputedStringAtIndex(t,e,s){const r=t&h;this._ensureString(e,r),this._strings[e][r]=s}getXMin(t){return this._bounds[4*(t&h)]}getYMin(t){return this._bounds[4*(t&h)+1]}getXMax(t){return this._bounds[4*(t&h)+2]}getYMax(t){return this._bounds[4*(t&h)+3]}setBounds(t,e){const s=e.readHydratedGeometry();if(!(s!=null&&s.coords.length))return!1;let r=1/0,i=1/0,n=-1/0,a=-1/0;s.forEachVertex((o,l)=>{r=Math.min(r,o),i=Math.min(i,l),n=Math.max(n,o),a=Math.max(a,l)});const u=t&h;return z(this._bounds,4*u+4,0),this._bounds[4*u]=r,this._bounds[4*u+1]=i,this._bounds[4*u+2]=n,this._bounds[4*u+3]=a,!0}}export{G as S,Bt as h,jt as k,Pt as r,y as t};