@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 5.21 kB
JavaScript
import{shuffle as t}from"../../../../core/arrayUtils.js";import{unwrapOr as e,isNone as s,isSome as i}from"../../../../core/maybe.js";import{create as r,fromExtent as u,intersects as a,copy as h,POSITIVE_INFINITY as n,intersection as f}from"../../../../geometry/support/aaBoundingRect.js";import{numVertices as _,estimateSize as d,getObjectId as m}from"../../../../layers/graphics/dehydratedFeatures.js";const l=16438,F=new Set;class E{get displayingFeatures(){return this._displayingFeatures}set displayingFeatures(t){this._displayingFeatures=t,this.extentIncludingBorrowedFeatures=null}get perTileMaximumNumberOfFeaturesExceeded(){return!this.filtered&&(this.featuresMissing||this.features&&this.featureLimit!==this.features.length)}get features(){return this._features}get featureLimit(){return this._featureLimit}set featureLimit(t){this._featureLimit!==t&&(this._featureLimit=t,this._estimatedUnusedSizeDirty=!0)}get availableFields(){return this._availableFields}setFeatures(t,s,i){this._availableFields=e(i,F),this._features=t,this._shuffled=!1,this._estimatedSize=-1,this._estimatedUnusedSizeDirty=!0,t&&t.length>0?(this._emptyFeatureRatio=s/(t.length+s),this._numVertices=t.reduce(((t,e)=>t+_(e.geometry)),0)):(this._emptyFeatureRatio=0,this._numVertices=0)}get emptyFeatureRatio(){return this._emptyFeatureRatio}get numFeatures(){return this.hasPreciseFeatureCount?this._numFeatures:this._features?this._features.length:0}set numFeatures(t){this._numFeatures=t}get hasPreciseFeatureCount(){return this._numFeatures>c}get needsFeatureCount(){return this._numFeatures===c}get numVertices(){return this._numVertices}constructor(t){this.descriptor=t,this.fetchStatus=o.FETCH_NEEDED,this._features=null,this._numVertices=0,this._featureLimit=0,this.featuresMissing=!0,this._shuffled=!1,this._numFeatures=c,this._emptyFeatureRatio=0,this._estimatedSize=-1,this._estimatedUnusedSize=0,this._estimatedUnusedSizeDirty=!1,this._availableFields=F,this._displayingFeatures=null,this.alive=!0,this.filtered=!1}get id(){return this.descriptor.id}get estimatedSize(){return this.updateMemoryEstimates(),this._estimatedSize}get estimatedUnusedSize(){return this._estimatedUnusedSize}updateMemoryEstimates(){if(this._estimatedSize<0){if(this._estimatedSize=0,this._estimatedUnusedSize=0,this._features)for(let t=0;t<this._features.length;++t){const e=d(this._features[t]);this._estimatedSize+=e,t>=this.featureLimit&&(this._estimatedUnusedSize+=e)}return!0}if(this._estimatedUnusedSizeDirty){if(this._estimatedUnusedSize=0,this._estimatedUnusedSizeDirty=!1,this._features)for(let t=this.featureLimit;t<this._features.length;++t)this._estimatedUnusedSize+=d(this._features[t]);return!0}return!1}get isFetching(){return this.fetchStatus===o.FETCHING||this.fetchStatus===o.REFETCHING}get isRefetching(){return this.fetchStatus===o.REFETCHING}get needsFetching(){return this.fetchStatus===o.FETCH_NEEDED||this.fetchStatus===o.REFETCH_NEEDED}get needsRefetching(){return this.fetchStatus===o.REFETCH_NEEDED}get isFetched(){return this.fetchStatus===o.DONE||this.fetchStatus===o.FULL}resetFetching(){this.fetchStatus=this.fetchStatus===o.REFETCHING?o.REFETCH_NEEDED:o.FETCH_NEEDED}get needsDisplayUpdate(){return!!this._features&&!S(this._features,this.displayingFeatures,this.featureLimit)}intersects(t){return!(!s(t)&&this.descriptor.extent)||(u(t,D),a(this.descriptor.extent,D))}intersectionIncludingBorrowed(t,e){const s=i(this.extentIncludingBorrowedFeatures)?this.extentIncludingBorrowedFeatures:this.descriptor.extent;return t||s?(i(t)?(u(t,e),f(e,s,e)):h(e,s),e):(h(e,n),e)}_shuffle(e){this._features.sort(((t,s)=>m(t,e)-m(s,e))),t(this._features,l),this._shuffled=!0,this._estimatedUnusedSizeDirty=!0}reduceFeatures(t,e,s){if(t<=0)return!1;if(!this._features)return this.featureLimit=0,!1;let i=!1;this.featureLimit=Math.ceil(this.numFeatures*t),this.featureLimit>this._features.length&&(this.featureLimit=this._features.length,this.fetchStatus===o.DONE&&this._features.length>0&&(this.fetchStatus=o.REFETCH_NEEDED,i=!0)),!this._shuffled&&t<1&&this._shuffle(s);const r=Math.max(this.featureLimit,Math.ceil(e*this.numFeatures));return this._features.length>r&&(this._features.length=r,this.featuresMissing=!0,this.fetchStatus===o.FULL&&(this.fetchStatus=o.DONE)),i}get cache(){return{availableFields:this._availableFields,features:this._features,numFeatures:this._numFeatures,emptyFeatureRatio:this._emptyFeatureRatio,fetchStatus:this.fetchStatus,featuresMissing:this.featuresMissing}}set cache(t){this.requestController=null,this._availableFields=t.availableFields,this._features=t.features,this._numFeatures=t.numFeatures,this._emptyFeatureRatio=t.emptyFeatureRatio,this.fetchStatus=t.fetchStatus,this.featuresMissing=t.featuresMissing,this._estimatedSize=-1,this._estimatedUnusedSizeDirty=!0}}const c=-1,g=-2;var o;function S(t,e,i){if(s(e)||s(t)||i!==e.length||i>t.length)return!1;for(let s=0;s<i;++s)if(t[s]!==e[s])return!1;return!0}!function(t){t[t.FETCH_NEEDED=0]="FETCH_NEEDED",t[t.REFETCH_NEEDED=1]="REFETCH_NEEDED",t[t.FETCHING=2]="FETCHING",t[t.REFETCHING=3]="REFETCHING",t[t.DONE=4]="DONE",t[t.FULL=5]="FULL"}(o||(o={}));const D=r();export{g as FAILED_FEATURE_COUNT,E as FeatureTile,o as FetchStatus};