UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2.81 kB
import"../../../../core/byteSizeEstimations.js";import"../../../../core/has.js";import"../../../../geometry/SpatialReference.js";import"../../../../geometry/support/aaBoundingBox.js";import"../../../../core/mathUtils.js";import"../../../../geometry/Extent.js";import"../../../../geometry/Geometry.js";import"../../../../geometry/Multipoint.js";import"../../../../geometry/Point.js";import"../../../../geometry/Polygon.js";import"../../../../geometry/Polyline.js";import"../../../../geometry/support/typeUtils.js";import"../../../../layers/support/Field.js";import{equals as e}from"../../../../layers/graphics/dehydratedFeatureComparison.js";class t{get isReferenced(){return 0!==this.versions.length}get isSingle(){return 1===this.versions.length&&1===this.versions[0].refCount}constructor(e,t){this._highestResolutionVersion=null,this.versions=[],this.ref(e,t)}ref(t,s){const r=this.feature;i.oldVersion=r,this.feature&&Object.defineProperty(t,"uid",{value:this.feature.uid,configurable:!0});for(const n of this.versions)if(n.resolution===s){n.refCount++;const s=this._highestResolutionVersion===n&&!e(t,n.feature);return(s||this._highestResolutionVersion!==n)&&(n.feature=t),i.newVersion=s?t:r,i}const o={feature:t,resolution:s,refCount:1};return this.versions.push(o),!this._highestResolutionVersion||s<this._highestResolutionVersion.resolution?(i.newVersion=t,this._highestResolutionVersion=o):i.newVersion=r,i}unref(e){for(let t=0;t<this.versions.length;t++){const s=this.versions[t];if(s.resolution===e)return s.refCount--,i.oldVersion=this.feature,0===s.refCount&&(this.versions[t]=this.versions[this.versions.length-1],this.versions.length--,this._highestResolutionVersion===s&&(this._recalculateHighestResolutionVersion(),i.oldVersion=s.feature)),i.newVersion=this.feature,i}return null}get feature(){return this._highestResolutionVersion?this._highestResolutionVersion.feature:null}_recalculateHighestResolutionVersion(){if(0===this.versions.length)return void(this._highestResolutionVersion=null);let e=this.versions[0];for(let t=1;t<this.versions.length;t++){const s=this.versions[t];s.resolution<e.resolution&&(e=s)}this._highestResolutionVersion=e}}class s{get isReferenced(){return 0!==this._refCount}get isSingle(){return 1===this._refCount}constructor(e){this._feature=e,this._refCount=1}ref(t){return++this._refCount,i.oldVersion=this._feature,this.feature&&Object.defineProperty(t,"uid",{value:this.feature.uid,configurable:!0}),e(this._feature,t)||(this._feature=t),i.newVersion=this._feature,i}unref(){return i.oldVersion=this._feature,this._refCount>0&&(this._refCount--,!this.isReferenced)?(i.newVersion=null,i):(i.newVersion=this._feature,i)}get feature(){return this._feature}}const i={oldVersion:null,newVersion:null};export{t as MultiFeatureReference,s as SingleFeatureReference};