UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.47 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{_ as e}from"../chunks/tslib.es6.js";import{on as t,watch as s,initial as i}from"../core/reactiveUtils.js";import{property as r}from"../core/accessorSupport/decorators/property.js";import{cast as o}from"../core/accessorSupport/decorators/cast.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as n}from"../core/accessorSupport/decorators/subclass.js";import a from"./Widget.js";import l from"./Legend/LegendViewModel.js";import d from"./Legend/styles/card/CardView.js";import p from"./Legend/styles/classic/ClassicView.js";import{globalCss as c}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as y}from"./support/decorators/messageBundle.js";import{tsx as h}from"./support/jsxFactory.js";const v={base:"esri-legend"};let g=class extends a{constructor(e,t){super(e,t),this.headingLevel=3,this.messages=null,this.style=new p,this.viewModel=new l}initialize(){this.addHandles([t((()=>this.view),"resize",(()=>this.scheduleRender())),t((()=>this.activeLayerInfos),"change",(()=>this._refreshActiveLayerInfos(this.activeLayerInfos))),s((()=>this.headingLevel),(e=>{const{style:t}=this;t&&(t.headingLevel=e)})),s((()=>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)}),i)])}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}castStyle(e){if(e instanceof d||e instanceof p)return e;if("string"==typeof e)return"card"===e?new d:new p;if(e&&"string"==typeof e.type){const t={...e};return delete t.type,"card"===e.type?new d(t):new p(t)}return new p}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}render(){return h("div",{class:this.classes(v.base,c.widget,this.style instanceof p?c.panel:null)},this.style.render())}_refreshActiveLayerInfos(e){e.forEach((e=>{this.removeHandles(`version_${e.layer.uid}`),this._renderOnActiveLayerInfoChange(e)})),this.scheduleRender()}_renderOnActiveLayerInfoChange(e){const r=s((()=>e.version),(()=>this.scheduleRender()));this.addHandles(r,`version_${e.layer.uid}`);const o=t((()=>e.children),"change",(()=>e.children.forEach((e=>this._renderOnActiveLayerInfoChange(e)))),i);this.addHandles(o,`version_${e.layer.uid}`),e.children.forEach((e=>this._renderOnActiveLayerInfoChange(e)))}};e([r()],g.prototype,"activeLayerInfos",null),e([r()],g.prototype,"basemapLegendVisible",null),e([r()],g.prototype,"groundLegendVisible",null),e([r()],g.prototype,"headingLevel",void 0),e([r()],g.prototype,"hideLayersNotInCurrentView",null),e([r()],g.prototype,"keepCacheOnDestroy",null),e([r()],g.prototype,"respectLayerDefinitionExpression",null),e([r()],g.prototype,"respectLayerVisibility",null),e([r()],g.prototype,"icon",null),e([r()],g.prototype,"label",null),e([r()],g.prototype,"layerInfos",null),e([r(),y("esri/widgets/Legend/t9n/Legend")],g.prototype,"messages",void 0),e([r()],g.prototype,"style",void 0),e([o("style")],g.prototype,"castStyle",null),e([r()],g.prototype,"view",null),e([r()],g.prototype,"viewModel",void 0),g=e([n("esri.widgets.Legend")],g);const u=g;export{u as default};