UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 5.38 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 e}from"../../chunks/tslib.es6.js";import{deprecatedProperty as o}from"../../core/deprecate.js";import{handlesGroup as t}from"../../core/handleUtils.js";import s from"../../core/Logger.js";import{removeMaybe as l}from"../../core/maybe.js";import{property as i}from"../../core/accessorSupport/decorators/property.js";import{cast as r}from"../../core/accessorSupport/decorators/cast.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as a}from"../../core/accessorSupport/decorators/subclass.js";import n from"../Widget.js";import{loadCalciteComponents as c}from"./componentsUtils.js";import{globalCss as d}from"./globalCss.js";import"./widgetUtils.js";import{messageBundle as p}from"./decorators/messageBundle.js";import{tsx as h}from"./jsxFactory.js";import u from"./SelectionToolbar/SelectionToolbarViewModel.js";const m={lassoTool:!0,rectangleTool:!0},v="esri-selection-toolbar",g={base:v,container:`${v}__container`,toolButton:`${v}__tool-button`};let T=class extends n{constructor(e,o){super(e,o),this._viewModelHandlesGroup=null,this.activeToolInfo=null,this.defaultLassoToolOptions={createTool:"polygon",mode:"freehand"},this.defaultRectangleToolOptions={createTool:"rectangle"},this.messages=null,this.toolConfigs=[],this.viewModel=new u,this.visibleElements={...m},this.scale="s",this.layout="horizontal",this._viewModelHandlesGroup=t([this.viewModel.on("complete",(e=>{this._set("activeToolInfo",null),this.emit("complete",e)}))])}destroy(){this._viewModelHandlesGroup=l(this._viewModelHandlesGroup)}loadDependencies(){return c({action:()=>import("@esri/calcite-components/dist/components/calcite-action")})}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layers(){return o(s.getLogger(this),"layers",{replacement:"Use SelectionToolbar.sources instead."}),this.viewModel.sources}set layers(e){o(s.getLogger(this),"layers",{replacement:"Use SelectionToolbar.sources instead."}),this.viewModel.sources=e}get layerViewPreferenceEnabled(){return this.viewModel.layerViewPreferenceEnabled}set layerViewPreferenceEnabled(e){this.viewModel.layerViewPreferenceEnabled=e}get sources(){return this.viewModel.sources}set sources(e){this.viewModel.sources=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}castVisibleElements(e){return{...m,...e}}get state(){return this.viewModel.state}get visibleToolCount(){const{view:e,toolConfigs:o,visibleElements:t}=this;return(o?.length??0)+("2d"===e?.type?(t.lassoTool?1:0)+(t.rectangleTool?1:0):0)}activate(e){if(this.cancel(),"disabled"!==this.state)switch(e){case"lasso":this._activateTool("lasso");break;case"rectangle":this._activateTool("rectangle");break;default:this._activateTool(e)}}cancel(){this.viewModel.cancel(),this._set("activeToolInfo",null)}render(){return h("div",{"aria-label":this.label,class:this.classes(g.base,d.widget)},h("div",{class:g.container},this._renderDefaultTools(),this._renderCustomTools()))}_renderDefaultTools(){if("2d"===this.view?.type)return[this._renderRectangleTool(),this._renderLassoTool()]}_renderCustomTools(){if(this.toolConfigs?.length)return this.toolConfigs.map((({toolName:e,icon:o,toolKey:t})=>this._renderToolWithTooltip(e,t,o)))}_renderLassoTool(){const{messages:e,visibleElements:o}=this;if(!o.lassoTool)return;const t=e.selectByLasso;return this._renderToolWithTooltip("lasso","lasso","lasso-select",t)}_renderRectangleTool(){const{messages:e,visibleElements:o}=this;if(!o.rectangleTool)return;const t=e.selectByRectangle;return this._renderToolWithTooltip("rectangle","rectangle","cursor-marquee",t)}_renderToolWithTooltip(e,o,t,s=e){const l=`${this.id}-tool-${o}`;return h("calcite-action",{active:this.activeToolInfo?.toolName===e,bind:this,class:g.toolButton,disabled:"disabled"===this.state,icon:t||"selection",id:l,key:l,onclick:()=>this._toggleTool(e),scale:this.scale,text:s,title:s})}_activateTool(e){const o=this._getToolOptions(e);if(!o)return;const t=this.viewModel.activate(o);t&&this._set("activeToolInfo",{toolName:e,operation:t})}_toggleTool(e){if(this.activeToolInfo){const o=this.activeToolInfo.toolName;if(this.cancel(),o===e)return}this._activateTool(e)}_getToolOptions(e){return"lasso"===e?this.defaultLassoToolOptions:"rectangle"===e?this.defaultRectangleToolOptions:this.toolConfigs.find((o=>o.toolName===e))}};e([i({readOnly:!0})],T.prototype,"activeToolInfo",void 0),e([i()],T.prototype,"defaultLassoToolOptions",void 0),e([i()],T.prototype,"defaultRectangleToolOptions",void 0),e([i()],T.prototype,"label",null),e([i()],T.prototype,"layers",null),e([i()],T.prototype,"layerViewPreferenceEnabled",null),e([i(),p("esri/widgets/support/SelectionToolbar/t9n/SelectionToolbar")],T.prototype,"messages",void 0),e([i()],T.prototype,"sources",null),e([i()],T.prototype,"toolConfigs",void 0),e([i()],T.prototype,"view",null),e([i()],T.prototype,"viewModel",void 0),e([i()],T.prototype,"visibleElements",void 0),e([r("visibleElements")],T.prototype,"castVisibleElements",null),e([i()],T.prototype,"scale",void 0),e([i()],T.prototype,"state",null),e([i()],T.prototype,"layout",void 0),e([i()],T.prototype,"visibleToolCount",null),T=e([a("esri.widgets.support.SelectionToolbar")],T);const f=T;export{f as default};