@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 6.16 kB
JavaScript
import"../../../../../geometry.js";import{ArcadeDate as e}from"../../../../../arcade/ArcadeDate.js";import{DateTimeReferenceFieldIndex as t}from"../../../../../arcade/arcadeTimeUtils.js";import has from"../../../../../core/has.js";import{isSome as r,isNone as s,unwrapOrThrow as i,unwrapOr as n}from"../../../../../core/maybe.js";import{getCentroidOptimizedGeometry as a}from"../../../../../layers/graphics/centroid.js";import{convertToGeometry as o}from"../../../../../layers/graphics/featureConversionUtils.js";import d from"../../../../../layers/graphics/OptimizedGeometry.js";import{StaticBitSet as h}from"./StaticBitSet.js";import{fromJSON as u}from"../../../../../geometry/support/jsonUtils.js";let c=0;const l=has("featurelayer-simplify-thresholds")??[.5,.5,.5,.5],m=l[0],f=l[1],g=l[2],y=l[3],_=has("featurelayer-simplify-payload-size-factors")??[1,2,4],p=_[0],x=_[1],I=_[2],A=has("featurelayer-simplify-mobile-factor")??2,S=has("esri-mobile");class b{constructor(e,t){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._level=0,this._datetimeMetadata=null,this.contextTimeReference=null,this.instance=e,this._layerSchema=t}static createInstance(){return c++,c=c>65535?0:c,c}get isEmpty(){return r(this._deleted)&&this._deleted.countSet()===this.getSize()}set level(e){this._level=e}getAreaSimplificationThreshold(e,t){let r=1;const s=S?A:1;t>4e6?r=I*s:t>1e6?r=x*s:t>5e5?r=p*s:t>1e5&&(r=s);let i=0;e>4e3?i=y*r:e>2e3?i=g*r:e>100?i=f:e>15&&(i=m);let n=8;return this._level<4?n=1:this._level<5?n=2:this._level<6&&(n=4),i*n}createQuantizedExtrudedQuad(e,t){return new d([5],[e-1,t,1,-1,1,1,-1,1,-1,-1])}setArcadeSpatialReference(e){this._arcadeSpatialReference=e}attachStorage(e){this._storage=e}getQuantizationTransform(){throw new Error("Unable to find transform for featureSet")}getStorage(){return this._storage}getComputedNumeric(e){return this.getComputedNumericAtIndex(0)}setComputedNumeric(e,t){return this.setComputedNumericAtIndex(t,0)}getComputedString(e){return this.getComputedStringAtIndex(0)}setComputedString(e,t){return this.setComputedStringAtIndex(0,t)}getComputedNumericAtIndex(e){return this._storage.getComputedNumericAtIndex(this.getDisplayId(),e)}setComputedNumericAtIndex(e,t){this._storage.setComputedNumericAtIndex(this.getDisplayId(),e,t)}getComputedStringAtIndex(e){return this._storage.getComputedStringAtIndex(this.getDisplayId(),e)}setComputedStringAtIndex(e,t){return this._storage.setComputedStringAtIndex(this.getDisplayId(),e,t)}transform(e,t,r,s){const i=this.copy();return i._tx+=e,i._ty+=t,i._sx*=r,i._sy*=s,i}readAttribute(e,t=!1){const r=this._readAttribute(e,t);if(void 0!==r)return r;for(const s of this._joined){s.setIndex(this.getIndex());const r=s._readAttribute(e,t);if(void 0!==r)return r}}readAttributes(){const e=this._readAttributes();for(const t of this._joined){t.setIndex(this.getIndex());const r=t._readAttributes();for(const t of Object.keys(r))e[t]=r[t]}return e}joinAttributes(e){this._joined.push(e)}readArcadeFeature(){return this}geometry(){const e=this.readHydratedGeometry(),t=o(e,this.geometryType,this.hasZ,this.hasM),r=u(t);return r&&(r.spatialReference=this._arcadeSpatialReference),r}get dateTimeReferenceFieldIndex(){return this._datetimeMetadata||(this._datetimeMetadata=t.create(this._layerSchema.fields,this._layerSchema)),this._datetimeMetadata}autocastArcadeDate(t,r){return r&&r instanceof Date?this.isUnknownDateTimeField(t)?e.unknownDateJSToArcadeDate(r):e.dateJSAndZoneToArcadeDate(r,this.contextTimeReference?.timeZone??"system"):r}isUnknownDateTimeField(e){return"unknown"===this.dateTimeReferenceFieldIndex?.fieldTimeZone(e)}fieldSourceTimeZone(e){return this.dateTimeReferenceFieldIndex?.fieldTimeZone(e)??""}get layerPreferredTimeZone(){return this.dateTimeReferenceFieldIndex?.layerPreferredTimeZone??""}field(e){if(this.hasField(e))return this.autocastArcadeDate(e,this.readAttribute(e,!0));for(const t of this._joined)if(t.setIndex(this.getIndex()),t.hasField(e)){const r=t._readAttribute(e,!0);return this.autocastArcadeDate(e,r)}throw new Error(`Field ${e} does not exist`)}setField(e,t){throw new Error("Unable to update feature attribute values, feature is readonly")}keys(){return this.getFieldNames()}castToText(e=!1){if(!e)return JSON.stringify(this.readLegacyFeature());const t=this.readLegacyFeature();if(!t)return JSON.stringify(null);const r={geometry:t.geometry,attributes:{...t.attributes?t.attributes:{}}};for(const s in r.attributes){const e=r.attributes[s];e instanceof Date&&(r.attributes[s]=e.getTime())}return JSON.stringify(r)}gdbVersion(){return null}fullSchema(){return this._layerSchema}castAsJson(e=null){return{attributes:this._readAttributes(),geometry:!0===e?.keepGeometryType?this.geometry():this.geometry()?.toJSON()??null}}castAsJsonAsync(e=null,t=null){return Promise.resolve(this.castAsJson(t))}removeIds(e){if(s(this._objectIdToIndex)){const e=new Map,t=this.getCursor();for(;t.next();){const r=i(t.getObjectId());e.set(r,t.getIndex())}this._objectIdToIndex=e}const t=this._objectIdToIndex;for(const r of e)t.has(r)&&this.removeAtIndex(t.get(r))}removeAtIndex(e){s(this._deleted)&&(this._deleted=h.create(this.getSize())),this._deleted.set(e)}readGeometryForDisplay(){return this.readUnquantizedGeometry(!0)}readLegacyGeometryForDisplay(){return this.readLegacyGeometry(!0)}*features(){const e=this.getCursor();for(;e.next();)yield e.readOptimizedFeature()}_getExists(){return s(this._deleted)||!this._deleted.has(this.getIndex())}_computeCentroid(){if("esriGeometryPolygon"!==this.geometryType)return null;const e=this.readUnquantizedGeometry();if(!e||e.hasIndeterminateRingOrder)return null;const t=n(this.getQuantizationTransform(),null);return a(new d,e,this.hasM,this.hasZ,t)}copyInto(e){e.seen=this.seen,e._storage=this._storage,e._arcadeSpatialReference=this._arcadeSpatialReference,e._joined=this._joined,e._tx=this._tx,e._ty=this._ty,e._sx=this._sx,e._sy=this._sy,e._deleted=this._deleted,e._objectIdToIndex=this._objectIdToIndex}}export{b as FeatureSetReader};