@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.69 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as t}from"../../chunks/tslib.es6.js";import{id as o}from"../../kernel.js";import e from"../../core/Error.js";import r from"../../core/JSONSupport.js";import{createMD5Hash as s}from"../../core/MD5.js";import{isAbortError as a}from"../../core/promiseUtils.js";import{property as i}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{enumeration as n}from"../../core/accessorSupport/decorators/enumeration.js";import{subclass as l}from"../../core/accessorSupport/decorators/subclass.js";import p from"../../portal/PortalItem.js";import{formatJsonMap as u}from"../../rest/support/fileFormat.js";import{fromJSON as m}from"../../rest/support/layoutTemplate.js";import{valueUnitKebabDict as y,fetchLayoutTemplateInfos as d}from"./utils.js";let c=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"CIMMarkerNorthArrow":o.northArrow.push(e);break;case"CIMScaleLine":o.scaleBar.push(e);break;case"CIMGroupElement":e.elements?.some((t=>"CIMScaleLine"===t.type))&&o.scaleBar.push(e);break;case"CIMLegend":o.legend.push(e)}return o}get pageUnits(){return y.fromJSON(this.layoutTemplateInfo?.pageUnits?.toLowerCase())}_updateLayoutOptions(t){const o=this.layoutOptions?.legend??t.layoutOptions?.hasLegend,e=this.layoutOptions?.northArrow??(this.mapSurroundInfoOptions?.northArrow.length?this.mapSurroundInfoOptions?.northArrow.some((({visible:t})=>t)):void 0),r=this.layoutOptions?.scaleBar??(this.mapSurroundInfoOptions?.scaleBar.length?this.mapSurroundInfoOptions?.scaleBar.some((({visible:t})=>t)):void 0);this._set("layoutOptions",{legend:o,northArrow:e,scaleBar:r})}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 a={Layout_Item_ID:JSON.stringify({id:r.id})},i=(await d(s,a,t))[0];this.setLayoutTemplateInfo(i)}catch(s){this._set("state",a(s)?"not-loaded":"error")}}setLayoutTemplateInfo(t){this._set("layoutTemplateInfo",t),this._updateLayoutOptions(t),this._set("state","loaded")}};t([i({json:{write:!0}})],c.prototype,"description",void 0),t([n(u)],c.prototype,"format",void 0),t([i({readOnly:!0})],c.prototype,"id",null),t([i({readOnly:!0})],c.prototype,"state",void 0),t([i({json:{write:!0}})],c.prototype,"label",void 0),t([i()],c.prototype,"layoutInfoTaskUrl",void 0),t([i({json:{read:m,write:!0}})],c.prototype,"layout",void 0),t([i({type:p,json:{write:!0}})],c.prototype,"layoutItem",void 0),t([i({readOnly:!0,json:{write:!0}})],c.prototype,"layoutOptions",void 0),t([i({readOnly:!0})],c.prototype,"layoutTemplateInfo",void 0),t([i({readOnly:!0})],c.prototype,"mapSurroundInfoOptions",null),t([i({readOnly:!0})],c.prototype,"pageUnits",null),t([i()],c.prototype,"type",void 0),c=t([l("esri.widgets.Print.CustomTemplate")],c);const h=c;export{h as default};