UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 3.64 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as t}from"tslib";import{id as o}from"../../kernel.js";import e from"../../core/Error.js";import{JSONSupport as r}from"../../core/JSONSupport.js";import{createMD5Hash as s}from"../../core/MD5.js";import{isAbortError as i}from"../../core/promiseUtils.js";import{property as a,subclass as n}from"../../core/accessorSupport/decorators.js";import l from"../../portal/PortalItem.js";import{formatJsonMap as p}from"../../rest/support/fileFormat.js";import{fromJSON as u}from"../../rest/support/layoutTemplate.js";import{valueUnitKebabDict as m,fetchLayoutTemplateInfos as d}from"./utils.js";import{enumeration as y}from"../../core/accessorSupport/decorators/enumeration.js";let h=class extends r{constructor(t){super(t),this.description=null,this.format=null,this.state="not-loaded",this.label=null,this.layoutInfoTaskUrl=null,this.layout=null,this.layoutItem=null,this.layoutOptions=null,this.layoutTemplateInfo=null,this.type=null}get id(){return this.layoutItem?.id??`${this.layout}-${s(JSON.stringify(this.toJSON()))}`}get mapSurroundInfoOptions(){const t=this.layoutTemplateInfo?.layoutOptions?.mapSurroundInfos;if(!t)return null;const o={northArrow:[],scaleBar:[],legend:[]};for(const e of t)switch(e.type){case"cim-marker-north-arrow":o.northArrow.push(e);break;case"cim-scale-line":o.scaleBar.push(e);break;case"cim-group-element":e.elements?.some(t=>"cim-scale-line"===t.type)&&o.scaleBar.push(e);break;case"cim-legend":o.legend.push(e)}return o}get pageUnits(){return m.fromJSON(this.layoutTemplateInfo?.pageUnits?.toLowerCase())}_updateLayoutOptions(t){const o=this.layoutOptions?.legend??t.layoutOptions?.hasLegend,e=this.layoutOptions?.dynamicLegend??(this.mapSurroundInfoOptions?.legend.length?this.mapSurroundInfoOptions?.legend.some(({defaultLegendItem:t})=>t?.dynamicLegends):void 0),r=this.layoutOptions?.northArrow??(this.mapSurroundInfoOptions?.northArrow.length?this.mapSurroundInfoOptions?.northArrow.some(({visible:t})=>t):void 0),s=this.layoutOptions?.scaleBar??(this.mapSurroundInfoOptions?.scaleBar.length?this.mapSurroundInfoOptions?.scaleBar.some(({visible:t})=>t):void 0);this._set("layoutOptions",{legend:o,northArrow:r,scaleBar:s,dynamicLegend:e})}async fetchLayoutItemTemplateInfo(t){const{layoutItem:r}=this;if(r?.id&&!this.layoutTemplateInfo&&"loaded"!==this.state)try{this._set("state","loading");const s=this.layoutInfoTaskUrl;if(!s)throw new e("print:invalid-layout-info-task-url","Can't fetch layout template info",{url:s});"public"!==r.access&&o&&await o.getCredential(s);const i={Layout_Item_ID:JSON.stringify({id:r.id})},a=(await d(s,i,t))[0];this.setLayoutTemplateInfo(a)}catch(s){this._set("state",i(s)?"not-loaded":"error")}}setLayoutTemplateInfo(t){this._set("layoutTemplateInfo",t),this._updateLayoutOptions(t),this._set("state","loaded")}};t([a({json:{write:!0}})],h.prototype,"description",void 0),t([y(p)],h.prototype,"format",void 0),t([a({readOnly:!0})],h.prototype,"id",null),t([a({readOnly:!0})],h.prototype,"state",void 0),t([a({json:{write:!0}})],h.prototype,"label",void 0),t([a()],h.prototype,"layoutInfoTaskUrl",void 0),t([a({json:{read:u,write:!0}})],h.prototype,"layout",void 0),t([a({type:l,json:{write:!0}})],h.prototype,"layoutItem",void 0),t([a({readOnly:!0,json:{write:!0}})],h.prototype,"layoutOptions",void 0),t([a({readOnly:!0})],h.prototype,"layoutTemplateInfo",void 0),t([a({readOnly:!0})],h.prototype,"mapSurroundInfoOptions",null),t([a({readOnly:!0})],h.prototype,"pageUnits",null),t([a()],h.prototype,"type",void 0),h=t([n("esri.widgets.Print.CustomTemplate")],h);const c=h;export{c as default};