Files
ADHA_mobile_project/assets/FeatureStore2D-db06c1ba.js
T
2024-02-28 17:06:42 +05:00

2 lines
11 KiB
JavaScript

import{t as m}from"./CircularArray-ef508845.js";import{z as x,eg as y,gv as f,Y as b,hB as A,_ as C,be as S,fR as F,hC as D,ap as T}from"./index-b5c8f851.js";import{S as l}from"./ComputedAttributeStorage-07f34ef9.js";function v(i,e,t){var s;if(i==null)return null;const r=e.readArcadeFeature();e.contextTimeZone=(s=t.$view)==null?void 0:s.timeZone;try{return i.evaluate({...t,$feature:r},i.services)}catch(a){return x.getLogger("esri.views.2d.support.arcadeOnDemand").warn("Feature arcade evaluation failed:",a),null}}class w{constructor(e,t){this._canCacheExpressionValue=!1,this._sourceInfo=e,this._storage=t,this._bitsets={computed:t.getBitset(t.createBitset())}}get storage(){return this._storage}invalidate(){this._bitsets.computed.clear()}async updateSchema(e,t){const r=y(this._schema,t);if(this._schema=t,!t||r==null||!f(r,"attributes"))return;b("esri-2d-update-debug")&&console.debug("Applying Update - Store:",r),this._bitsets.computed.clear(),e.targets[t.name]=!0;const s=t.attributes,a=[],n=[];for(const d in s){const o=s[d];switch(o.type){case"field":break;case"expression":a.push(this._createArcadeComputedField(o));break;case"label-expression":a.push(this._createLabelArcadeComputedField(o));break;case"statistic":n.push(o)}}this._computedFields=await Promise.all(a),this._canCacheExpressionValue=!this._computedFields.some(d=>d.type==="expression"&&d.expression!=null&&d.expression.referencesScale()),this._statisticFields=n}setComputedAttributes(e,t,r,s,a){const n=this._bitsets.computed;if(!this._canCacheExpressionValue||!n.has(r)){n.set(r);for(const d of this._computedFields){const o=this._evaluateField(t,d,s,a);switch(d.resultType){case"numeric":e.setComputedNumericAtIndex(r,d.fieldIndex,o);break;case"string":e.setComputedStringAtIndex(r,d.fieldIndex,o)}}}}async _createArcadeComputedField(e){const t=this._sourceInfo.spatialReference,r=this._sourceInfo.fieldsIndex;return{...e,expression:await A(e.valueExpression,t,r)}}async _createLabelArcadeComputedField(e){const t=this._sourceInfo.spatialReference,r=this._sourceInfo.fieldsIndex,{createLabelFunction:s}=await C(()=>import("./labelFormatUtils-a66a1dc4.js"),["assets/labelFormatUtils-a66a1dc4.js","assets/index-b5c8f851.js","assets/index-86716609.css"]),a=await s(e.label,r,t);return{...e,builder:a}}_evaluateField(e,t,r,s){switch(t.type){case"label-expression":{const a=e.readArcadeFeature();return t.builder.evaluate(a,s)||""}case"expression":{const{expression:a}=t;return v(a,e,{$view:{scale:r,timeZone:s}})}}}}class _ extends l{static from(e,t){return new _(e.copy(),t)}constructor(e,t){super(l.createInstance(),e.fullSchema()),this._currentIndex=-1,this._reader=e,this._indices=t}get fields(){return this._reader.fields}get hasNext(){return this._currentIndex+1<this._indices.length}getSize(){return this._indices.length}getCursor(){return this.copy()}copy(){const e=new _(this._reader.copy(),this._indices);return e._currentIndex=this._currentIndex,e}next(){for(;this._nextIndex()&&!this._reader._getExists(););return this._currentIndex<this._indices.length}_nextIndex(){return++this._currentIndex<this._indices.length&&(this._reader.setIndex(this._indices[this._currentIndex]),!0)}setArcadeSpatialReference(e){this._reader.setArcadeSpatialReference(e)}attachStorage(e){this._reader.attachStorage(e)}get geometryType(){return this._reader.geometryType}get hasFeatures(){return this._reader.hasFeatures}get exceededTransferLimit(){return this._reader.exceededTransferLimit}get hasZ(){return this._reader.hasZ}get hasM(){return this._reader.hasM}get contextTimeZone(){return this._reader.contextTimeZone}set contextTimeZone(e){this._reader.contextTimeZone=e}getStorage(){return this._reader.getStorage()}getComputedNumeric(e){return this._reader.getComputedNumericAtIndex(0)}setComputedNumeric(e,t){return this._reader.setComputedNumericAtIndex(t,0)}getComputedString(e){return this._reader.getComputedStringAtIndex(0)}setComputedString(e,t){return this._reader.setComputedStringAtIndex(0,t)}getComputedNumericAtIndex(e){return this._reader.getComputedNumericAtIndex(e)}setComputedNumericAtIndex(e,t){this._reader.setComputedNumericAtIndex(e,t)}getComputedStringAtIndex(e){return this._reader.getComputedStringAtIndex(e)}setComputedStringAtIndex(e,t){return this._reader.setComputedStringAtIndex(e,t)}transform(e,t,r,s){const a=this.copy();return a._reader=this._reader.transform(e,t,r,s),a}readAttribute(e,t=!1){return this._reader.readAttribute(e,t)}readAttributes(){return this._reader.readAttributes()}joinAttributes(e){return this._reader.joinAttributes(e)}readArcadeFeature(){return this._reader.readArcadeFeature()}geometry(){return this._reader.geometry()}field(e){return this.readAttribute(e,!0)}hasField(e){return this._reader.hasField(e)}setField(e,t){return this._reader.setField(e,t)}keys(){return this._reader.keys()}castToText(e=!1){return this._reader.castToText(e)}getQuantizationTransform(){return this._reader.getQuantizationTransform()}getAttributeHash(){return this._reader.getAttributeHash()}getObjectId(){return this._reader.getObjectId()}getDisplayId(){return this._reader.getDisplayId()}setDisplayId(e){return this._reader.setDisplayId(e)}getGroupId(){return this._reader.getGroupId()}setGroupId(e){return this._reader.setGroupId(e)}getXHydrated(){return this._reader.getXHydrated()}getYHydrated(){return this._reader.getYHydrated()}getX(){return this._reader.getX()}getY(){return this._reader.getY()}setIndex(e){return this._reader.setIndex(e)}getIndex(){return this._reader.getIndex()}readLegacyFeature(){return this._reader.readLegacyFeature()}readOptimizedFeature(){return this._reader.readOptimizedFeature()}readLegacyPointGeometry(){return this._reader.readLegacyPointGeometry()}readLegacyGeometry(){return this._reader.readLegacyGeometry()}readLegacyCentroid(){return this._reader.readLegacyCentroid()}readGeometryArea(){return this._reader.readGeometryArea()}readUnquantizedGeometry(){return this._reader.readUnquantizedGeometry()}readHydratedGeometry(){return this._reader.readHydratedGeometry()}readGeometry(){return this._reader.readGeometry()}readCentroid(){return this._reader.readCentroid()}_readAttribute(e,t){throw new Error("Error: Should not be called. Underlying _reader should be used instead")}_readAttributes(){throw new Error("Error: Should not be called. Underlying _reader should be used instead")}}const g=S();function I(i,e){return i<<16|e}function c(i){return(4294901760&i)>>>16}function h(i){return 65535&i}const E={getObjectId:i=>i.getObjectId(),getAttributes:i=>i.readAttributes(),getAttribute:(i,e)=>i.readAttribute(e),getAttributeAsTimestamp:(i,e)=>i.readAttributeAsTimestamp(e),cloneWithGeometry:(i,e)=>i,getGeometry:i=>i.readHydratedGeometry(),getCentroid:(i,e)=>i.readCentroid()};class O extends w{constructor(e,t,r){super(e,t),this.featureAdapter=E,this.events=new F,this._featureSetsByInstance=new Map,this._objectIdToDisplayId=new Map,this._spatialIndexInvalid=!0,this._indexSearchCache=new m(50),this._index=D(9,s=>({minX:this._storage.getXMin(s),minY:this._storage.getYMin(s),maxX:this._storage.getXMax(s),maxY:this._storage.getYMax(s)})),this.mode=r}get storeStatistics(){let e=0,t=0,r=0;return this.forEach(s=>{const a=s.readGeometry();a&&(t+=a.isPoint?1:a.lengths.reduce((n,d)=>n+d,0),r+=a.isPoint?1:a.lengths.length,e+=1)}),{featureCount:e,vertexCount:t,ringCount:r}}hasInstance(e){return this._featureSetsByInstance.has(e)}onTileData(e,t,r){if(t.addOrUpdate==null)return t;if(t.addOrUpdate.attachStorage(this._storage),this.mode==="snapshot"){const a=t.addOrUpdate.getCursor();for(;a.next();){const n=a.getDisplayId();this.setComputedAttributes(this._storage,a,n,e.scale,r)}return t}this._featureSetsByInstance.set(t.addOrUpdate.instance,t.addOrUpdate);const s=t.addOrUpdate.getCursor();for(;s.next();)this._insertFeature(s,e.scale,r);return this._spatialIndexInvalid=!0,this.events.emit("changed"),t}search(e){this._rebuildIndex();const t=e.id,r=this._indexSearchCache.find(d=>d.tileId===t);if(r!=null)return r.readers;const s=new Map,a=this._searchIndex(e.bounds),n=[];for(const d of a){const o=this._storage.getInstanceId(d),u=c(o),p=h(o);s.has(u)||s.set(u,[]),s.get(u).push(p)}return s.forEach((d,o)=>{const u=this._featureSetsByInstance.get(o);n.push(_.from(u,d))}),this._indexSearchCache.enqueue({tileId:t,readers:n}),n}insert(e){const t=e.getCursor(),r=this._storage;for(;t.next();){const s=I(t.instance,t.getIndex()),a=t.getObjectId(),n=this._objectIdToDisplayId.get(a)??this._storage.createDisplayId();t.setDisplayId(n),r.setInstanceId(n,s),this._objectIdToDisplayId.set(a,n)}this._featureSetsByInstance.set(e.instance,e),this._spatialIndexInvalid=!0}remove(e){const t=this._objectIdToDisplayId.get(e);if(!t)return;const r=this._storage.getInstanceId(t),s=h(r),a=c(r),n=this._featureSetsByInstance.get(a);this._objectIdToDisplayId.delete(e),this._storage.releaseDisplayId(t),n.removeAtIndex(s),n.isEmpty&&this._featureSetsByInstance.delete(a),this._spatialIndexInvalid=!0}forEach(e){this._objectIdToDisplayId.forEach(t=>{const r=this._storage.getInstanceId(t),s=this._lookupFeature(r);e(s)})}forEachUnsafe(e){this._objectIdToDisplayId.forEach(t=>{const r=this._storage.getInstanceId(t),s=c(r),a=h(r),n=this._getFeatureSet(s);n.setIndex(a),e(n)})}forEachInBounds(e,t){const r=this._searchIndex(e);for(const s of r)t(this.lookupFeatureByDisplayId(s,this._storage))}forEachBounds(e,t){this._rebuildIndex();for(const r of e){if(!r.readGeometry())continue;const s=r.getDisplayId();T(g,this._storage.getXMin(s),this._storage.getYMin(s),this._storage.getXMax(s),this._storage.getYMax(s)),t(g)}}sweepFeatures(e,t,r){this._spatialIndexInvalid=!0,this._objectIdToDisplayId.forEach((s,a)=>{e.has(s)||(t.releaseDisplayId(s),r&&r.unsetAttributeData(s),this._objectIdToDisplayId.delete(a))}),this.events.emit("changed")}sweepFeatureSets(e){this._spatialIndexInvalid=!0,this._featureSetsByInstance.forEach((t,r)=>{e.has(r)||this._featureSetsByInstance.delete(r)})}lookupObjectId(e,t){const r=this.lookupFeatureByDisplayId(e,t);return r==null?null:r.getObjectId()}lookupDisplayId(e){return this._objectIdToDisplayId.get(e)}lookupFeatureByDisplayId(e,t){const r=t.getInstanceId(e);return this._lookupFeature(r)}lookupByDisplayIdUnsafe(e){const t=this._storage.getInstanceId(e),r=c(t),s=h(t),a=this._getFeatureSet(r);return a?(a.setIndex(s),a):null}_insertFeature(e,t,r){const s=this._storage,a=e.getObjectId(),n=I(e.instance,e.getIndex());s.getInstanceId(e.getDisplayId());let d=this._objectIdToDisplayId.get(a);d||(d=s.createDisplayId(),this._objectIdToDisplayId.set(a,d),this._spatialIndexInvalid=!0),e.setDisplayId(d),s.setInstanceId(d,n),this.setComputedAttributes(s,e,d,t,r)}_searchIndex(e){this._rebuildIndex();const t={minX:e[0],minY:e[1],maxX:e[2],maxY:e[3]};return this._index.search(t)}_rebuildIndex(){if(!this._spatialIndexInvalid)return;const e=[];this.mode==="snapshot"?this._featureSetsByInstance.forEach(t=>{const r=t.getCursor();for(;r.next();){const s=r.getDisplayId();this._storage.setBounds(s,r)&&e.push(s)}}):this._objectIdToDisplayId.forEach(t=>{const r=this._storage.getInstanceId(t);this._storage.setBounds(t,this._lookupFeature(r))&&e.push(t)}),this._index.clear(),this._index.load(e),this._indexSearchCache.clear(),this._spatialIndexInvalid=!1}_lookupFeature(e){const t=c(e),r=this._getFeatureSet(t);if(!r)return;const s=r.getCursor(),a=h(e);return s.setIndex(a),s}_getFeatureSet(e){return this._featureSetsByInstance.get(e)}}export{E as I,w as a,_ as r,O as u};