@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 7.61 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{shuffle as t}from"../../../../core/arrayUtils.js";import{baseObjectMemory as e}from"../../../../core/memoryEstimations.js";import{signal as s}from"../../../../core/signal.js";import{diameter as i,create as r}from"../../../../geometry/support/aaBoundingBox.js";import{fromExtent as a,intersects as u,copy as h,positiveInfinity as n,intersection as l,create as m}from"../../../../geometry/support/aaBoundingRect.js";import{numVertices as f,estimateSize as o,getObjectId as d,computeAABB as c}from"../../../../layers/graphics/dehydratedFeatures.js";import{computeMaxZ as _}from"../graphics/graphicUtils.js";import{SampledGeometryMaxDistanceRatio as g}from"./SampledGeometryMaxDistanceRatio.js";const F=16438;class p{constructor(t){this.descriptor=t,this._numVertices=0,this.exceededTransferLimit=s(!1),this._fetchFailed=s(!1),this._sorted=!1,this._numFeatures=s(y),this._emptyFeatureRatio=s(0),this._estimatedSize=-1,this._estimatedUnusedSize=0,this._estimatedUnusedSizeDirty=!1,this._sampledDensityEstimate=-1,this._displayingFeatures=null,this.alive=!0,this.filtered=!1,this._features=null,this._featuresLength=s(0),this._featureLimit=s(0),this._fetchStatus=0,this.fetchInformation=s(""),this.fetchingResolution=this.displayingResolution=t.resolution}get featuresMissing(){return this.fetchFailed||(this.hasPreciseFeatureCount?this._featuresLength.value<this.numFeatures:this.exceededTransferLimit.value)}get showsAllFeatures(){return!this.fetchFailed&&null!=this.displayingFeatures&&(this.hasPreciseFeatureCount?this.displayingFeatures.length===this.numFeatures:!this.exceededTransferLimit.value)}get missingAttributes(){return this._missingAttributes}get fetchFailed(){return this._fetchFailed.value}set fetchFailed(t){this._fetchFailed.value=t}get displayingFeatures(){return this._displayingFeatures}set displayingFeatures(t){this._displayingFeatures=t,this.extentIncludingBorrowedFeatures=null}get perTileMaximumNumberOfFeaturesExceeded(){const t=this.isFetched&&this.featuresMissing;return!this.filtered&&(t||this.hasFeatureLimit)}get features(){return this._features}get featureLimit(){return this._featureLimit.value}set featureLimit(t){this._featureLimit.value!==t&&(this._featureLimit.value=t,this._estimatedUnusedSizeDirty=!0)}get hasFeatureLimit(){return this.featureLimit!==this._featuresLength.value}get availableFields(){return this._availableFields}setFeatures(t,e,s,i){this._availableFields=s,this._features=t,this._featuresLength.value=t?.length??0,this._sorted=!1,this._estimatedSize=-1,this._estimatedUnusedSizeDirty=!0,this._sampledDensityEstimate=-1,this._missingAttributes=i,t&&t.length>0?(this._emptyFeatureRatio.value=e/(t.length+e),this._numVertices=t.reduce((t,e)=>t+f(e.geometry),0)):(this._emptyFeatureRatio.value=0,this._numVertices=0)}computeZQuantizationFactor(){if(this._features&&this._features.length>0){const t=this._features.reduce((t,{geometry:e})=>Math.max(t,_(e)??0),0);return Math.floor(t/this.descriptor.planetRadius)+1}return 1}get emptyFeatureRatio(){return this._emptyFeatureRatio.value}get numFeatures(){return this.hasPreciseFeatureCount?this._numFeatures.value:this._features?this._featuresLength.value:0}set numFeatures(t){this._numFeatures.value=t}get hasPreciseFeatureCount(){return this._numFeatures.value>y}get needsFeatureCount(){return this._numFeatures.value===y}get numVertices(){return this._numVertices}get id(){return this.descriptor.id}get estimatedSize(){return this.updateEstimates(),this._estimatedSize}get sampledDensityEstimate(){return this._sampledDensityEstimate}get estimatedUnusedSize(){return this._estimatedUnusedSize}updateEstimates(){if(this._estimatedSize<0||this._sampledDensityEstimate<0){this._estimatedSize=0,this._estimatedUnusedSize=0,this._sampledDensityEstimate=0;const t=Math.floor(Math.sqrt(z));if(this._features){let e=null;const s=new g(z,R*this.fetchingResolution),i=this._features.length;for(let r=0;r<i;++r){const a=this._features[r],u=o(a);if(this._estimatedSize+=u,r>=this.featureLimit&&(this._estimatedUnusedSize+=u),!s.done){const u=i-r;if(r%Math.ceil(u/Math.max(1,Math.floor(Math.sqrt(s.numRemainingSamples))))===0){const i=Math.max(Math.floor(s.numRemainingSamples/u),t);s.sampleGeometry(a.geometry,e,i)}}e=a.geometry}s.numSamples>=x?this._sampledDensityEstimate=s.ratio:this._sampledDensityEstimate=0}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+=o(this._features[t]);return!0}return!1}get fetchStatus(){return this._fetchStatus}requestFetch(){this._fetchStatus=0}requestRefetch(){this._fetchStatus=1}startFetch(){this._fetchStatus=this.needsRefetch?3:2}fetchDone(t){this._fetchStatus=t}get isFetching(){return 2===this._fetchStatus||3===this._fetchStatus}get isRefetching(){return 3===this._fetchStatus}get needsFetch(){return 0===this._fetchStatus||1===this._fetchStatus}get needsRefetch(){return 1===this._fetchStatus}get isFetched(){return 4===this._fetchStatus||5===this._fetchStatus}isFullyFetched(t){return!!this.features&&(this.features.length>=t||5===this.fetchStatus)}resetFetching(){this._fetchStatus=this.isRefetching?1:0}get needsDisplayUpdate(){return!!this._features&&!L(this._features,this.displayingFeatures,this.featureLimit)}intersects(t){return null==t||!this.descriptor.extent||(a(t,D),u(this.descriptor.extent,D))}intersectionIncludingBorrowed(t,e){const s=null!=this.extentIncludingBorrowedFeatures?this.extentIncludingBorrowedFeatures:this.descriptor.extent;return t||s?(null!=t?(a(t,e),l(e,s,e)):h(e,s),e):(h(e,n),e)}_shuffle(e){this._features?.sort((t,s)=>d(t,e)-d(s,e)),t(this._features,F)}_sortBySize(t){this._features?.sort((e,s)=>i(c(s.geometry,M))-i(c(e.geometry,M))||d(e,t)-d(s,t))}reduceFeatures(t,e,s,i){if(t<=0)return!1;if(!this._features)return this.featureLimit=0,!1;let r=!1;this.featureLimit=Math.ceil(this.numFeatures*t),this.featureLimit>this._features.length&&4===this._fetchStatus&&this._features.length>0&&(this._fetchStatus=1,r=!0),!this._sorted&&t<1&&(1===i?this._shuffle(s):this._sortBySize(s),this._sorted=!0,this._estimatedUnusedSizeDirty=!0);const a=Math.max(this.featureLimit,Math.ceil(e*this.numFeatures));return this._features.length>a&&(this._features.length=this._featuresLength.value=a,this.exceededTransferLimit.value=!1,5===this._fetchStatus&&(this._fetchStatus=4)),r}get cache(){return new v(this,this._features,this._numFeatures.value,this._emptyFeatureRatio.value)}set cache(t){this.requestController=null,this._availableFields=t.availableFields,this._features=t.features,this._featuresLength.value=t.features?.length??0,this._numFeatures.value=t.numFeatures,this._emptyFeatureRatio.value=t.emptyFeatureRatio,this._fetchStatus=t.fetchStatus,this.exceededTransferLimit.value=t.exceededTransferLimit,this._estimatedSize=-1,this._sampledDensityEstimate=-1,this._estimatedUnusedSizeDirty=!0,this.fetchInformation.value=t.fetchInformation}}const y=-1,S=-2;class v{constructor(t,s,i,r){this.features=s,this.numFeatures=i,this.emptyFeatureRatio=r,this.usedMemory=e+t.estimatedSize,this.resolution=t.displayingResolution,this.availableFields=t.availableFields,this.fetchStatus=t.fetchStatus,this.exceededTransferLimit=t.exceededTransferLimit.value,this.fetchInformation=t.fetchInformation.value}}function L(t,e,s){if(null==e||null==t||s!==e.length||s>t.length)return!1;for(let i=0;i<s;++i)if(t[i]!==e[i])return!1;return!0}const z=150,x=100,R=2,D=m(),M=r();export{p as FeatureTile,v as FeatureTileCacheItem,S as failedFeatureCount};