UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.58 kB
/* 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{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 l from"./Widget.js";import a from"./Legend/LegendViewModel.js";import d from"./Legend/styles/card/CardView.js";import p from"./Legend/styles/classic/ClassicView.js";import{globalCss as y}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as c}from"./support/decorators/messageBundle.js";import{tsx as h}from"./support/jsxFactory.js";const g={base:"esri-legend"};let v=class extends l{constructor(e,t){super(e,t),this.headingLevel=3,this.messages=null,this.viewModel=new a,this.style=new p}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)])}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}set style(e){const t=this._get("style");e!==t&&t?.destroy(),this._set("style",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(g.base,y.widget,this.style instanceof p?y.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()],v.prototype,"activeLayerInfos",null),e([r()],v.prototype,"basemapLegendVisible",null),e([r()],v.prototype,"groundLegendVisible",null),e([r()],v.prototype,"headingLevel",void 0),e([r()],v.prototype,"hideLayersNotInCurrentView",null),e([r()],v.prototype,"keepCacheOnDestroy",null),e([r()],v.prototype,"respectLayerDefinitionExpression",null),e([r()],v.prototype,"respectLayerVisibility",null),e([r()],v.prototype,"icon",null),e([r()],v.prototype,"label",null),e([r()],v.prototype,"layerInfos",null),e([r(),c("esri/widgets/Legend/t9n/Legend")],v.prototype,"messages",void 0),e([r()],v.prototype,"style",null),e([o("style")],v.prototype,"castStyle",null),e([r()],v.prototype,"view",null),e([r()],v.prototype,"viewModel",void 0),v=e([n("esri.widgets.Legend")],v);const u=v;export{u as default};