UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.59 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 t}from"../../chunks/tslib.es6.js";import e from"../../core/Error.js";import o from"../../core/Evented.js";import{property as r}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as i}from"../../core/accessorSupport/decorators/subclass.js";import{convertLayoutTypeToWebSupportedFormat as s}from"../../layers/knowledgeGraph/supportUtils.js";let a=class extends o.EventedAccessor{constructor(t){super(t),this._goToExtentController=null,this._scaleExtent=(t,e)=>{const o=t,r=(t.xmax-t.xmin)/2*(e-1),i=(t.ymax-t.ymin)/2*(e-1);return o.xmin=t.xmin-r,o.ymin=t.ymin-i,o.xmax=t.xmax+r,o.ymax=t.ymax+i,o},this.switchLayout=this.switchLayout.bind(this)}destroy(){this._cancelGoToExtent(),this.view=null}set view(t){this._set("view",t),t&&t.when().then((()=>{if(this.view===t){if(!this.view.map.linkChartProperties)throw new e("linkChartLayoutSwitcher:error","Link chart layouts are only supported on WebLinkCharts.");this.layout=s(this.view.map.linkChartProperties.layoutType)}}))}get state(){return this.view?this.view.map.linkChartProperties?"ready":"disabled":"loading"}get layout(){return this._get("layout")||"organic-standard"}set layout(t){this._set("layout",t)}get preventExtentUpdate(){return this._get("preventExtentUpdate")||!1}set preventExtentUpdate(t){this._set("preventExtentUpdate",t)}async switchLayout(t){if(!this.view||!this.view.map)throw new e("linkChartLayoutSwitcher:loading-state","Cannot change layout when link chart has not loaded.");if(this.layout=t,await this.view.map.applyLayout(t),!this.preventExtentUpdate&&this.view.map.diagramNodesExtent){const e="geographic-organic-standard"!==t?this._scaleExtent(this.view.map.diagramNodesExtent,1.4):this.view.map.diagramNodesExtent,r=new AbortController;this._goToExtentController=r;try{await this.view.when(),await this.view.goTo(e,{signal:r.signal})}catch(o){}this._goToExtentController=null}this.emit("switchLayout",{layout:t})}_cancelGoToExtent(){const{_goToExtentController:t}=this;t&&t.abort(),this._goToExtentController=null}};t([r()],a.prototype,"_goToExtentController",void 0),t([r()],a.prototype,"view",null),t([r({readOnly:!0})],a.prototype,"state",null),t([r()],a.prototype,"layout",null),t([r()],a.prototype,"preventExtentUpdate",null),a=t([i("esri.widgets.LinkChartLayoutSwitcher.LinkChartLayoutSwitcherViewModel")],a);const n=a;export{n as default};