@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 2.23 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../core/Logger.js";import{watch as o,syncAndInitial as i,when as s}from"../../core/reactiveUtils.js";import{property as r,subclass as l}from"../../core/accessorSupport/decorators.js";const n=n=>{const u=n;let p=class extends u{constructor(t){super(t),this.tool=null,this._loggedUnsupportedErrorOnce=!1,null!=t?.visible&&(this.visible=t.visible)}initialize(){this.addHandles(o(()=>({ready:null!=this.view&&this.view.ready,supported:this.supported}),({ready:t,supported:e})=>{!t||e||this._loggedUnsupportedErrorOnce||(this.logError(this.unsupportedErrorMessage),this._loggedUnsupportedErrorOnce=!0)},i))}destroy(){this.removeTool(),this.view=null}get active(){return null!=this.tool&&this.tool.active}get disabled(){return null==this.view||!this.view.ready||!this.supported}get supported(){return null==this.view||this.view.type===this.supportedViewType}get view(){return this._get("view")}set view(t){if(t===this.view)return;this.removeTool(),this._set("view",t);const e="tools";this.removeHandles(e),null!=t&&this.addHandles(t.tools.on("after-remove",t=>{t.item===this.tool&&this._set("tool",null)}),e)}set visible(t){this._set("visible",t),null!=this.tool&&(this.tool.visible=t)}createTool(t={interactive:!1}){if(this.removeTool(),null==this.view||!this.view.ready||!this.supported)return;const e=this.constructTool();e.created?(this._set("tool",e),this.view.tools.add(e)):t.interactive?(this._set("tool",e),this.view.addAndActivateTool(e),s(()=>e.created,()=>{e.active&&null!=this.view&&(this.view.activeTool=null)},{initial:!0,once:!0})):e.destroy()}removeTool(){const t=this.tool;if(null==t)return;const e=this.view?.tools;null!=e?e.remove(t):t.destroy(),this._set("tool",null)}logError(...t){e.getLogger(this).error(...t)}};return t([r({constructOnly:!0})],p.prototype,"tool",void 0),t([r()],p.prototype,"active",null),t([r()],p.prototype,"disabled",null),t([r()],p.prototype,"supported",null),t([r({value:null})],p.prototype,"view",null),t([r({type:Boolean,value:!0})],p.prototype,"visible",null),p=t([l("esri.widgets.support.InteractiveToolViewModelMixin")],p),p};export{n as InteractiveToolViewModelMixin};