12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import i from"../../core/Accessor.js";import r from"../../core/Collection.js";import t from"../../core/Handles.js";import{watch as s,initial as a,when as n}from"../../core/reactiveUtils.js";import{property as o}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as l}from"../../core/accessorSupport/decorators/subclass.js";import y from"./support/ActiveLayerInfo.js";import{onLocaleChange as d}from"../../intl/locale.js";const h={state:"state",view:"view",allLayerViews:"all-layer-views",legendProperties:"legend-properties"},c=r.ofType(y),L=["esri.layers.BuildingSceneLayer","esri.layers.CSVLayer","esri.layers.FeatureLayer","esri.layers.GeoJSONLayer","esri.layers.GeoRSSLayer","esri.layers.GroupLayer","esri.layers.HeatmapLayer","esri.layers.ImageryLayer","esri.layers.ImageryTileLayer","esri.layers.MapImageLayer","esri.layers.OGCFeatureLayer","esri.layers.PointCloudLayer","esri.layers.StreamLayer","esri.layers.SceneLayer","esri.layers.SubtypeGroupLayer","esri.layers.TileLayer","esri.layers.VoxelLayer","esri.layers.WFSLayer","esri.layers.WMSLayer","esri.layers.WMTSLayer","esri.layers.WCSLayer"],u="view.basemapView.baseLayerViews",_="view.groundView.layerViews",f="view.basemapView.referenceLayerViews",p=[u,_,"view.layerViews",f];let v=class extends i{constructor(e){super(e),this._handles=new t,this._layerViewByLayerId={},this._layerInfosByLayerViewId={},this._activeLayerInfosByLayerViewId={},this._activeLayerInfosWithNoParent=new r,this.activeLayerInfos=new c,this.basemapLegendVisible=!1,this.groundLegendVisible=!1,this.hideLayersNotInCurrentView=!1,this.keepCacheOnDestroy=!1,this.respectLayerVisibility=!0,this.layerInfos=[],this.view=null}initialize(){this._handles.add(s((()=>this.view),(()=>this._viewHandles()),a),h.view),this._handles.add(d((()=>this._refresh())))}destroy(){this._destroyViewActiveLayerInfos(),this._handles.destroy(),this._handles=null,this.view=null}get state(){return this.get("view.ready")?"ready":"disabled"}_viewHandles(){this._handles.remove(h.state),this.view&&this._handles.add(s((()=>this.state),(()=>this._stateHandles()),a),h.state)}_stateHandles(){this._resetAll(),"ready"===this.state&&this._watchPropertiesAndAllLayerViews()}_resetAll(){this._handles.remove([h.allLayerViews,h.legendProperties]),this._destroyViewActiveLayerInfos(),this.activeLayerInfos.removeAll()}_destroyViewActiveLayerInfos(){Object.keys(this._activeLayerInfosByLayerViewId).forEach(this._destroyViewActiveLayerInfo,this)}_destroyViewActiveLayerInfo(e){this._handles.remove(e);const i=this._activeLayerInfosByLayerViewId[e];delete this._activeLayerInfosByLayerViewId[e],i&&i.parent&&i.parent.children.remove(i)}_watchPropertiesAndAllLayerViews(){const{allLayerViews:e}=this.view;e.length&&this._refresh(),this._handles.add(e.on("change",(e=>this._allLayerViewsChangeHandle(e))),h.allLayerViews),this._handles.add(s((()=>[this.layerInfos,this.basemapLegendVisible,this.groundLegendVisible]),(()=>this._propertiesChangeHandle())),h.legendProperties)}_allLayerViewsChangeHandle(e){e.removed.forEach((e=>this._destroyViewActiveLayerInfo(e.uid))),this._refresh()}_propertiesChangeHandle(){this._destroyViewActiveLayerInfos(),this._refresh()}_refresh(){this._layerInfosByLayerViewId={},this.activeLayerInfos.removeAll(),this._generateLayerViews().filter(this._filterLayerViewsByLayerInfos,this).filter(this._isLayerViewSupported,this).forEach(this._generateActiveLayerInfo,this),this._sortActiveLayerInfos(this.activeLayerInfos)}_sortActiveLayerInfos(e){if(e.length<2)return;const i=[];e.forEach((r=>{if(!r.parent){const t=r.layer.parent,s=t&&"uid"in t&&this._layerViewByLayerId[t.uid],a=s&&this._activeLayerInfosByLayerViewId[s.uid];a&&e.includes(a)&&(i.push(r),r.parent=a,a.children.add(r),this._sortActiveLayerInfos(a.children))}})),e.removeMany(i);const r={};this.view.allLayerViews.forEach(((e,i)=>r[e.layer.uid]=i)),e.sort(((e,i)=>{const t=r[e.layer.uid]||0;return(r[i.layer.uid]||0)-t}))}_generateLayerViews(){const e=[];return p.filter(this._filterLayerViews,this).map(this.get,this).filter((e=>null!=e)).forEach(this._collectLayerViews("layerViews",e)),e}_filterLayerViews(e){const i=!this.basemapLegendVisible&&(e===u||e===f),r=!this.groundLegendVisible&&e===_;return!i&&!r}_collectLayerViews(e,i){const r=t=>(t&&t.forEach((t=>{i.push(t),r(t[e])})),i);return r}_filterLayerViewsByLayerInfos(e){const i=this.layerInfos;return!i||!i.length||i.some((i=>this._hasLayerInfo(i,e)))}_hasLayerInfo(e,i){const r=this._isLayerUIDMatching(e.layer,i.layer.uid);return r&&(this._layerInfosByLayerViewId[i.uid]=e),r}_isLayerUIDMatching(e,i){return e&&(e.uid===i||this._hasLayerUID(e.layers,i))}_hasLayerUID(e,i){return e&&e.some((e=>this._isLayerUIDMatching(e,i)))}_isLayerViewSupported(e){return!!L.includes(e.layer.declaredClass)&&(this._layerViewByLayerId[e.layer.uid]=e,!0)}_generateActiveLayerInfo(e){this._isLayerActive(e)?this._buildActiveLayerInfo(e):(this._handles.remove(e.uid),this._handles.add(s((()=>[e.legendEnabled,e.layer?.legendEnabled]),(()=>this._layerActiveHandle(e))),e.uid))}_layerActiveHandle(e){this._isLayerActive(e)&&(this._handles.remove(e.uid),this._buildActiveLayerInfo(e))}_isLayerActive(e){return!this.respectLayerVisibility||e.legendEnabled&&e.get("layer.legendEnabled")}_buildActiveLayerInfo(e){const i=e.layer,r=e.uid,t=this._layerInfosByLayerViewId[r];let o=this._activeLayerInfosByLayerViewId[r];if(!o){const s=t&&void 0!==t.title&&t.layer.uid===i.uid;o=new y({layer:i,layerView:e,title:s?t.title:i.title,view:this.view,respectLayerVisibility:this.respectLayerVisibility,hideLayersNotInCurrentView:this.hideLayersNotInCurrentView,keepCacheOnDestroy:this.keepCacheOnDestroy,sublayerIds:t&&t.sublayerIds||[]}),this._activeLayerInfosByLayerViewId[r]=o}const l=i.parent&&"uid"in i.parent&&this._layerViewByLayerId[i.parent?.uid];if(o.parent=this._activeLayerInfosByLayerViewId[l?.uid],!this._handles.has(r)){const t=[s((()=>i.title),(e=>this._titleHandle(e,o))),s((()=>[i.opacity,"renderer"in i&&i.renderer,"pointSymbol"in i&&i.pointSymbol,"lineSymbol"in i&&i.lineSymbol,"polygonSymbol"in i&&i.polygonSymbol]),(()=>this._constructLegendElements(o))),n((()=>!0===this.view?.stationary),(()=>this._scaleHandle(o)),a),s((()=>e._effectiveRenderer),(()=>this._constructLegendElements(o))),s((()=>"effect"in i&&i.effect),(()=>this._constructLegendElements(o)))];if(this.respectLayerVisibility){const r=s((()=>e.legendEnabled),(e=>this._legendEnabledHandle(e,o))),a=s((()=>i.legendEnabled),(e=>this._legendEnabledHandle(e,o)));t.push(r,a)}this._handles.add(t,r)}o.isScaleDriven||this._constructLegendElements(o),this._addActiveLayerInfo(o)}_titleHandle(e,i){i.title=e,this._constructLegendElements(i)}_legendEnabledHandle(e,i){e?this._addActiveLayerInfo(i):this._removeActiveLayerInfo(i)}_scaleHandle(e){(e.isScaleDriven||e.hideLayersNotInCurrentView)&&this._constructLegendElements(e)}_addActiveLayerInfo(e){const{layerView:i,layer:r}=e;if(this._isLayerActive(i)&&!this.activeLayerInfos.includes(e)){const i=e.parent;if(i)i.children.includes(e)||i.children.push(e),this._sortActiveLayerInfos(i.children);else{const i=this.layerInfos?.some((e=>e.layer.uid===r.uid));r.parent&&"uid"in r.parent&&!i?this._activeLayerInfosWithNoParent.add(e):(this.activeLayerInfos.add(e),this._sortActiveLayerInfos(this.activeLayerInfos))}if(this._activeLayerInfosWithNoParent.length){const e=[];this._activeLayerInfosWithNoParent.forEach((i=>{const r=i.layer.parent,t=r&&"uid"in r&&this._layerViewByLayerId[r?.uid],s=this._activeLayerInfosByLayerViewId[t?.uid];s&&(e.push(i),i.parent=s)})),e.length&&(this._activeLayerInfosWithNoParent.removeMany(e),e.forEach((e=>this._addActiveLayerInfo(e))))}}}_removeActiveLayerInfo(e){const i=e.parent;i?i.children.remove(e):this.activeLayerInfos.remove(e)}_constructLegendElements(e){const i=e.layer;"featureCollections"in i&&i.featureCollections?e.buildLegendElementsForFeatureCollections(i.featureCollections):"featureReduction"in i&&i.featureReduction&&"renderer"in i.featureReduction&&("binning"===i.featureReduction.type||"cluster"===i.featureReduction.type)?e.buildLegendElementsForFeatureReduction(i.featureReduction):"renderer"in i&&i.renderer&&!("sublayers"in i)?e.buildLegendElementsForRenderer(i.renderer):"url"in i&&i.url?e.buildLegendElementsForTools():e.children.forEach((e=>this._constructLegendElements(e)))}};e([o({type:c})],v.prototype,"activeLayerInfos",void 0),e([o()],v.prototype,"basemapLegendVisible",void 0),e([o()],v.prototype,"groundLegendVisible",void 0),e([o()],v.prototype,"hideLayersNotInCurrentView",void 0),e([o()],v.prototype,"keepCacheOnDestroy",void 0),e([o()],v.prototype,"respectLayerVisibility",void 0),e([o()],v.prototype,"layerInfos",void 0),e([o({readOnly:!0})],v.prototype,"state",null),e([o()],v.prototype,"view",void 0),v=e([l("esri.widgets.Legend.LegendViewModel")],v);const I=v;export{I as default};
|