Legend.js 3.7 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../chunks/tslib.es6.js";import s from"../core/Handles.js";import{destroyMaybe as t}from"../core/maybe.js";import{on as i,watch as r,initial as o}from"../core/reactiveUtils.js";import{aliasOf as n}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import{cast as a}from"../core/accessorSupport/decorators/cast.js";import{property as d}from"../core/accessorSupport/decorators/property.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import c from"./Widget.js";import p from"./Legend/LegendViewModel.js";import h from"./Legend/styles/Card.js";import y from"./Legend/styles/Classic.js";import"./support/widgetUtils.js";import{messageBundle as v}from"./support/decorators/messageBundle.js";import{tsx as f}from"./support/jsxFactory.js";const g={base:"esri-legend",widget:"esri-widget",panel:"esri-widget--panel",widgetIcon:"esri-icon-layer-list"};let m=class extends c{constructor(e,t){super(e,t),this._handles=new s,this.activeLayerInfos=null,this.basemapLegendVisible=!1,this.groundLegendVisible=!1,this.headingLevel=3,this.hideLayersNotInCurrentView=!1,this.keepCacheOnDestroy=!1,this.respectLayerVisibility=!0,this.iconClass=g.widgetIcon,this.label=void 0,this.layerInfos=null,this.messages=null,this.style=new y,this.view=null,this.viewModel=new p}initialize(){this.own([i((()=>this.view),"resize",(()=>this.scheduleRender())),i((()=>this.activeLayerInfos),"change",(()=>this._refreshActiveLayerInfos(this.activeLayerInfos))),r((()=>this.headingLevel),(e=>{const{style:s}=this;s&&(s.headingLevel=e)})),r((()=>this.style),((e,s)=>{s&&e!==s&&s.destroy(),e&&(e.activeLayerInfos=this.activeLayerInfos,"card"===e.type&&(e.view=this.view),e.headingLevel=this.headingLevel)}),o)])}destroy(){this._handles=t(this._handles)}castStyle(e){if(e instanceof h||e instanceof y)return e;if("string"==typeof e)return"card"===e?new h:new y;if(e&&"string"==typeof e.type){const s={...e};delete s.type;return new("card"===e.type?h:y)(s)}return new y}render(){return f("div",{class:this.classes(g.base,g.widget,this.style instanceof y?g.panel:null)},this.style.render())}_refreshActiveLayerInfos(e){this._handles.removeAll(),e.forEach((e=>this._renderOnActiveLayerInfoChange(e))),this.scheduleRender()}_renderOnActiveLayerInfoChange(e){const s=r((()=>e.version),(()=>this.scheduleRender()));this._handles.add(s,`version_${e.layer.uid}`);const t=i((()=>e.children),"change",(()=>e.children.forEach((e=>this._renderOnActiveLayerInfoChange(e)))),o);this._handles.add(t,`children_${e.layer.uid}`),e.children.forEach((e=>this._renderOnActiveLayerInfoChange(e)))}};e([n("viewModel.activeLayerInfos")],m.prototype,"activeLayerInfos",void 0),e([n("viewModel.basemapLegendVisible")],m.prototype,"basemapLegendVisible",void 0),e([n("viewModel.groundLegendVisible")],m.prototype,"groundLegendVisible",void 0),e([d()],m.prototype,"headingLevel",void 0),e([n("viewModel.hideLayersNotInCurrentView")],m.prototype,"hideLayersNotInCurrentView",void 0),e([n("viewModel.keepCacheOnDestroy")],m.prototype,"keepCacheOnDestroy",void 0),e([n("viewModel.respectLayerVisibility")],m.prototype,"respectLayerVisibility",void 0),e([d()],m.prototype,"iconClass",void 0),e([d({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],m.prototype,"label",void 0),e([n("viewModel.layerInfos")],m.prototype,"layerInfos",void 0),e([d(),v("esri/widgets/Legend/t9n/Legend")],m.prototype,"messages",void 0),e([d()],m.prototype,"style",void 0),e([a("style")],m.prototype,"castStyle",null),e([n("viewModel.view")],m.prototype,"view",void 0),e([d()],m.prototype,"viewModel",void 0),m=e([l("esri.widgets.Legend")],m);const L=m;export{L as default};