@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 5.17 kB
JavaScript
import{isNone as t,isSome as e}from"../../../../../core/maybe.js";import{convertFromFeatures as r,convertFromFeatureSet as s,convertToFeature as i,convertToGeometry as n,getQuantizedArea as o,unquantizeOptimizedGeometry as a}from"../../../../../layers/graphics/featureConversionUtils.js";import{hasGeometry as u}from"../../../../../layers/graphics/OptimizedFeature.js";import{FeatureSetReader as h}from"./FeatureSetReader.js";function d({coords:t,lengths:e}){let r=0;for(const s of e){for(let e=1;e<s;e++)t[2*(r+e)]+=t[2*(r+e)-2],t[2*(r+e)+1]+=t[2*(r+e)-1];r+=s}}class c extends h{static fromFeatures(t,e){const{objectIdField:s,geometryType:i}=e,n=r([],t,i,!1,!1,s);for(let r=0;r<n.length;r++)n[r].displayId=t[r].displayId;return c.fromOptimizedFeatures(n,e)}static fromFeatureSet(t,e){const r=s(t,e.objectIdField);return c.fromOptimizedFeatureSet(r,e)}static fromOptimizedFeatureSet(t,e){const{features:r}=t,s=c.fromOptimizedFeatures(r,e);s._exceededTransferLimit=t.exceededTransferLimit,s._transform=t.transform;for(const i of t.fields)"esriFieldTypeDate"===i.type&&s._dateFields.add(i.name);return s}static fromOptimizedFeatures(t,e,r){const s=h.createInstance(),i=new c(s,t,e);return i._transform=r,i}constructor(t,e,r){super(t,r),this._exceededTransferLimit=!1,this._featureIndex=-1,this._dateFields=new Set,this._geometryType=r?.geometryType,this._features=e}get _current(){return this._features[this._featureIndex]}get geometryType(){return this._geometryType}get hasFeatures(){return!!this._features.length}get hasNext(){return this._featureIndex+1<this._features.length}get exceededTransferLimit(){return this._exceededTransferLimit}get hasZ(){return!1}get hasM(){return!1}removeIds(t){const e=new Set(t);this._features=this._features.filter((t=>!(t.objectId&&e.has(t.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(){return this._current?.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 c(this.instance,this._features,this.fullSchema());return this.copyInto(t),t}next(){for(;++this._featureIndex<this._features.length&&!this._getExists(););return this._featureIndex<this._features.length}readLegacyFeature(){return i(this._current,this.geometryType,this.hasZ,this.hasM)}readOptimizedFeature(){return this._current}readLegacyPointGeometry(){return this.readGeometry()?{x:this.getX(),y:this.getY()}:null}readLegacyGeometry(){const t=this.readGeometry();return n(t,this.geometryType,this.hasZ,this.hasM)}readLegacyCentroid(){const e=this.readCentroid();return t(e)?null:{x:e.coords[0]*this._sx+this._tx,y:e.coords[1]*this._sy+this._ty}}readGeometryArea(){return u(this._current)?o(this._current.geometry,2):0}readUnquantizedGeometry(){const t=this.readGeometry();if("esriGeometryPoint"===this.geometryType||!t)return t;const e=t.clone();return d(e),e}readHydratedGeometry(){const r=this._current.geometry;if(t(r))return null;const s=r.clone();return e(this._transform)&&a(s,s,this.hasZ,this.hasM,this._transform),s}getXHydrated(){if(!u(this._current))return 0;const e=this._current.geometry.coords[0],r=this.getQuantizationTransform();return t(r)?e:e*r.scale[0]+r.translate[0]}getYHydrated(){if(!u(this._current))return 0;const e=this._current.geometry.coords[1],r=this.getQuantizationTransform();return t(r)?e:r.translate[1]-e*r.scale[1]}getX(){return u(this._current)?this._current.geometry.coords[0]*this._sx+this._tx:0}getY(){return u(this._current)?this._current.geometry.coords[1]*this._sy+this._ty:0}readGeometry(){if(!u(this._current)){if(e(this._current.centroid)){const[t,e]=this._current.centroid.coords;return this.createQuantizedExtrudedQuad(t,e)}return null}const t=this._current.geometry.clone();if(t.isPoint)return t.coords[0]=t.coords[0]*this._sx+this._tx,t.coords[1]=t.coords[1]*this._sy+this._ty,t;let r=0;for(const e of t.lengths)t.coords[2*r]=t.coords[2*r]*this._sx+this._tx,t.coords[2*r+1]=t.coords[2*r+1]*this._sy+this._ty,r+=e;return t}readCentroid(){return u(this._current)?this._computeCentroid():this._current.centroid}hasField(t){if(t in this._current.attributes)return!0;return this.getFieldNames().map((t=>t.toLowerCase())).includes(t.toLowerCase())}getFieldNames(){return Object.keys(this._current.attributes)}_readAttribute(t,e){const r=this._current.attributes[t];if(void 0!==r)return null!=r&&e&&this._dateFields.has(t)?new Date(r):r;const s=this.readAttributes(),i=t?.toLocaleLowerCase().trim();for(const n in s)if(n.toLocaleLowerCase().trim()===i){const t=this._current.attributes[n];return null!=t&&e&&this._dateFields.has(n)?new Date(t):t}}copyInto(t){super.copyInto(t),t._featureIndex=this._featureIndex,t._transform=this._transform,t._dateFields=this._dateFields}_readAttributes(){return this._current.attributes}}export{c as FeatureSetReaderJSON};