@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 5.2 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Collection.js";import{makeHandle as r}from"../../core/handleUtils.js";import{LRUCache as o}from"../../core/LRUCache.js";import{someMap as i,getOrCreateMapValue as s}from"../../core/MapUtils.js";import{MultiOriginJSONMixin as a}from"../../core/MultiOriginJSONSupport.js";import n from"../../core/ReactiveMap.js";import{watch as l}from"../../core/reactiveUtils.js";import{signal as p}from"../../core/signal.js";import{property as d}from"../../core/accessorSupport/decorators/property.js";import{Integer as y}from"../../core/accessorSupport/ensureType.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as c}from"../../core/accessorSupport/decorators/subclass.js";import h from"../Layer.js";import{BlendLayer as u}from"../mixins/BlendLayer.js";import{ScaleRangeLayer as m}from"../mixins/ScaleRangeLayer.js";import{legendEnabled as f,opacity as _}from"../support/commonProperties.js";import g from"../support/OrderByInfo.js";import{getAttributeComparator as j}from"../../statistics/utils.js";let v=class extends(m(u(a(h)))){constructor(e){super(e),this._layerCache=new o(20,(e=>e.destroy())),this._oidToReference=new n,this._layerToReference=new Map,this.legendEnabled=!0,this.layers=new t,this.maximumVisibleSublayers=10,this.opacity=1,this.parent=null,this.persistenceEnabled=!0,this.title="Layers in view",this.type="catalog-dynamic-group",this.visible=!0}initialize(){this.addHandles([this.layers.on("after-add",(({item:e})=>{e.parent=this})),this.layers.on("after-remove",(({item:e})=>{e.parent=null})),l((()=>this._orderBy),(()=>{this._updateLayerSortValues(),this._sortAllLayers()}))])}load(e){return this.addResolvingPromise(this.parent.load()),Promise.resolve(this)}destroy(){this._layerCache.destroy(),this._oidToReference.clear(),this._layerToReference.clear()}get _orderBy(){return this.parent?this.parent.orderBy?.find((e=>!e.valueExpression&&e.field))??new g({field:this.parent.objectIdField}):null}get _referenceComparator(){const e=this._orderBy;if(!this.parent||!e)return()=>0;const t=this.parent.fieldsIndex.get(e.field),r=j(t?.toJSON().type,"descending"===e.order),o=j("esriFieldTypeOID","descending"===e.order);return(e,t)=>r(t.sortValue,e.sortValue)||o(t.objectId,e.objectId)}get fullExtent(){return this.parent?.fullExtent??null}get updating(){return i(this._oidToReference,(({pending:e})=>null!=e))}acquireLayer(e){if(this.destroyed)return r();const t=this._getLayerReference(e);return t.count++,r((()=>{t.count--,t.count||this._destroyLayerReference(t)}))}_getLayerReference(e){const t=e.getObjectId();return s(this._oidToReference,t,(()=>{const t=e.getObjectId(),r=`${t}`,o=e.getAttribute(this.parent.itemSourceField),i=new b(e,t,o),s=this._layerCache.pop(r);return s?(this._addLayer(i,s),i):(i.pending=this.parent.createLayerFromFootprint(e).then((e=>{i.count?this._addLayer(i,e):(this.destroyed||this._layerCache.get(r)||this._layerCache.put(r,e),i.layer=null)})).catch((()=>{})).finally((()=>{i.pending=null})),i)}))}_destroyLayerReference(e){e.layer&&(this._layerToReference.delete(e.layer),this.layers.remove(e.layer),this.destroyed?e.layer.destroy():this._layerCache.put(`${e.objectId}`,e.layer),e.layer=null),this._oidToReference.delete(e.objectId)}_addLayer(e,t){e.layer=t,t.persistenceEnabled=!1,this._layerToReference.set(t,e),this._updateLayerSortValue(e),this.layers.add(t),this._sortAllLayers()}_updateLayerSortValues(){for(const e of this._layerToReference.values())this._updateLayerSortValue(e)}_updateLayerSortValue(e){this._orderBy&&(e.sortValue=e.footprint.getAttribute(this._orderBy.field))}_sortAllLayers(){this.layers.sort(((e,t)=>this._referenceComparator(this._layerToReference.get(e),this._layerToReference.get(t))))}};e([d()],v.prototype,"_orderBy",null),e([d({readOnly:!0})],v.prototype,"_referenceComparator",null),e([d(f)],v.prototype,"legendEnabled",void 0),e([d({type:["show","hide","hide-children"],json:{write:!0}})],v.prototype,"listMode",void 0),e([d({readOnly:!0})],v.prototype,"fullExtent",null),e([d({type:String,json:{origins:{service:{read:!1},"portal-item":{read:!1}},write:{ignoreOrigin:!0,isRequired:!0}}})],v.prototype,"id",void 0),e([d({readOnly:!0})],v.prototype,"layers",void 0),e([d({type:y,range:{min:0,max:50},json:{write:!0,default:10}})],v.prototype,"maximumVisibleSublayers",void 0),e([d(_)],v.prototype,"opacity",void 0),e([d({clonable:!1})],v.prototype,"parent",void 0),e([d({type:String,nonNullable:!0,json:{write:{ignoreOrigin:!0,isRequired:!0}}})],v.prototype,"title",void 0),e([d({json:{read:!1}})],v.prototype,"type",void 0),e([d({readOnly:!0})],v.prototype,"updating",null),e([d({type:Boolean,json:{name:"visibility",write:!0}})],v.prototype,"visible",void 0),v=e([c("esri.layers.catalog.CatalogDynamicGroupLayer")],v);class b{constructor(e,t,r){this.footprint=e,this.objectId=t,this.itemSource=r,this.count=0,this.layer=null,this.sortValue=void 0,this._pending=p(null)}get pending(){return this._pending.value}set pending(e){this._pending.value=e}}export{v as default};