UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 4.42 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../core/Collection.js";import{deprecateWidget as i}from"../core/deprecate.js";import s from"../core/Logger.js";import{on as r,watch as o,initial as n}from"../core/reactiveUtils.js";import{property as l,subclass as a}from"../core/accessorSupport/decorators.js";import d from"./Widget.js";import y from"./Legend/LegendViewModel.js";import p from"./Legend/styles/card/CardView.js";import h from"./Legend/styles/classic/ClassicView.js";import c from"./Legend/support/ActiveLayerInfo.js";import{globalCss as g}from"./support/globalCss.js";import{tsx as v,messageBundle as L}from"./support/widget.js";const f={base:"esri-legend"};let u=class extends d{constructor(e,t){super(e,t),this.headingLevel=3,this.messages=null,this.viewModel=new y,this.style=new h,i(s.getLogger(this),"Legend","arcgis-legend",{version:"4.34"})}initialize(){this.addHandles([r(()=>this.view,"resize",()=>this.scheduleRender()),r(()=>this.activeLayerInfos,"change",()=>this._refreshActiveLayerInfos(this.activeLayerInfos)),o(()=>this.headingLevel,e=>{const{style:t}=this;t&&(t.headingLevel=e)}),o(()=>this.style,(e,t)=>{t&&e!==t&&t.destroy(),e&&(e.activeLayerInfos=this.activeLayerInfos,"card"===e.type&&(e.view=this.view),e.headingLevel=this.headingLevel)},n)])}destroy(){this.style?.destroy()}get activeLayerInfos(){return this.viewModel.activeLayerInfos}set activeLayerInfos(e){this.viewModel.activeLayerInfos=e}get basemapLegendVisible(){return this.viewModel.basemapLegendVisible}set basemapLegendVisible(e){this.viewModel.basemapLegendVisible=e}get groundLegendVisible(){return this.viewModel.groundLegendVisible}set groundLegendVisible(e){this.viewModel.groundLegendVisible=e}get hideLayersNotInCurrentView(){return this.viewModel.hideLayersNotInCurrentView}set hideLayersNotInCurrentView(e){this.viewModel.hideLayersNotInCurrentView=e}get keepCacheOnDestroy(){return this.viewModel.keepCacheOnDestroy}set keepCacheOnDestroy(e){this.viewModel.keepCacheOnDestroy=e}get respectLayerDefinitionExpression(){return this.viewModel.respectLayerDefinitionExpression}set respectLayerDefinitionExpression(e){this.viewModel.respectLayerDefinitionExpression=e}get respectLayerVisibility(){return this.viewModel.respectLayerVisibility}set respectLayerVisibility(e){this.viewModel.respectLayerVisibility=e}get icon(){return"legend"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layerInfos(){return this.viewModel.layerInfos}set layerInfos(e){this.viewModel.layerInfos=e}get style(){return this._get("style")}set style(e){const t=this._get("style");if(e!==t&&t?.destroy(),!(e instanceof p||e instanceof h))if("string"==typeof e)e="card"===e?new p:new h;else if(e&&"string"==typeof e.type){const t={...e};delete t.type,e="card"===e.type?new p(t):new h(t)}else e=new h;this._set("style",e)}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}render(){return v("div",{class:this.classes(f.base,g.widget,this.style instanceof h?g.panel:null)},this.style.render())}_refreshActiveLayerInfos(e){e.forEach(e=>{this.removeHandles(`version_${e.layer.uid}`),this._renderOnActiveLayerInfoChange(e)}),this.scheduleRender()}_renderOnActiveLayerInfoChange(e){const t=o(()=>e.version,()=>this.scheduleRender());this.addHandles(t,`version_${e.layer.uid}`);const i=r(()=>e.children,"change",()=>e.children.forEach(e=>this._renderOnActiveLayerInfoChange(e)),n);this.addHandles(i,`version_${e.layer.uid}`),e.children.forEach(e=>this._renderOnActiveLayerInfoChange(e))}};e([l({type:t.ofType(c)})],u.prototype,"activeLayerInfos",null),e([l()],u.prototype,"basemapLegendVisible",null),e([l()],u.prototype,"groundLegendVisible",null),e([l()],u.prototype,"headingLevel",void 0),e([l()],u.prototype,"hideLayersNotInCurrentView",null),e([l()],u.prototype,"keepCacheOnDestroy",null),e([l()],u.prototype,"respectLayerDefinitionExpression",null),e([l()],u.prototype,"respectLayerVisibility",null),e([l()],u.prototype,"icon",null),e([l()],u.prototype,"label",null),e([l()],u.prototype,"layerInfos",null),e([l(),L("esri/widgets/Legend/t9n/Legend")],u.prototype,"messages",void 0),e([l()],u.prototype,"style",null),e([l()],u.prototype,"view",null),e([l({type:y})],u.prototype,"viewModel",void 0),u=e([a("esri.widgets.Legend")],u);const w=u;export{w as default};