UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 10 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{__decorate as e}from"tslib";import{formatNumber as t}from"../../intl.js";import{deprecatedProperty as o}from"../../core/deprecate.js";import{handlesGroup as i}from"../../core/handleUtils.js";import l from"../../core/Logger.js";import{removeMaybe as s}from"../../core/maybe.js";import{on as r}from"../../core/reactiveUtils.js";import{property as n,subclass as a}from"../../core/accessorSupport/decorators.js";import c from"../Widget.js";import{loadCalciteComponents as p}from"./componentsUtils.js";import{globalCss as d}from"./globalCss.js";import{messageBundle as u,tsx as h}from"./widget.js";import v from"./SelectionToolbar/SelectionToolbarViewModel.js";import m from"./SelectionToolbar/VisibleElements.js";const f="esri-selection-toolbar",g={base:f,container:`${f}__container`,toolButton:`${f}__tool-button`};let T=class extends c{constructor(e,t){super(e,t),this._viewModelHandlesGroup=null,this.availableOperationTypes=["replace","add","remove"],this.disabled=!1,this.layout="horizontal",this.messages=null,this.scale="s",this.viewModel=new v,this.visibleElements=new m}initialize(){this._viewModelHandlesGroup=i([r(()=>this.viewModel,"before-activate",e=>this.emit("before-activate",e)),r(()=>this.viewModel,"complete",e=>this.emit("complete",e)),r(()=>this.viewModel,"selection-change",e=>this.emit("selection-change",e))])}destroy(){this._viewModelHandlesGroup=s(this._viewModelHandlesGroup)}loadDependencies(){return p({action:()=>import("@esri/calcite-components/dist/components/calcite-action"),"action-bar":()=>import("@esri/calcite-components/dist/components/calcite-action-bar"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group"),chip:()=>import("@esri/calcite-components/dist/components/calcite-chip"),dropdown:()=>import("@esri/calcite-components/dist/components/calcite-dropdown"),"dropdown-item":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-item"),"dropdown-group":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-group"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon")})}get _effectiveDisabled(){return this.disabled||"disabled"===this.state}get _effectiveOperationType(){return this.activeOperation?.effectiveType||this.defaultOperationType}get activeOperation(){return this.viewModel.activeOperation}get continuousSelectionEnabled(){return this.viewModel.continuousSelectionEnabled}set continuousSelectionEnabled(e){this.viewModel.continuousSelectionEnabled=e}get defaultLassoToolOptions(){return this.viewModel.defaultLassoToolOptions}set defaultLassoToolOptions(e){this.viewModel.defaultLassoToolOptions=e}get defaultOperationType(){return this.viewModel.defaultOperationType}set defaultOperationType(e){this.viewModel.defaultOperationType=e}get defaultPointToolOptions(){return this.viewModel.defaultPointToolOptions}set defaultPointToolOptions(e){this.viewModel.defaultPointToolOptions=e}get defaultRectangleToolOptions(){return this.viewModel.defaultRectangleToolOptions}set defaultRectangleToolOptions(e){this.viewModel.defaultRectangleToolOptions=e}get effectiveSelectionManager(){return this.viewModel.effectiveSelectionManager}get effectiveSources(){return this.viewModel.effectiveSources}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layers(){return o(l.getLogger(this),"layers",{replacement:"Use SelectionToolbar.sources instead."}),this.viewModel.sources}set layers(e){o(l.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 persistSelection(){return this.viewModel.persistSelection}set persistSelection(e){this.viewModel.persistSelection=e}get returnFeatureTitleFields(){return this.viewModel.returnFeatureTitleFields}set returnFeatureTitleFields(e){this.viewModel.returnFeatureTitleFields=e}get returnGeometry(){return this.viewModel.returnGeometry}set returnGeometry(e){this.viewModel.returnGeometry=e}get selectOnComplete(){return this.viewModel.selectOnComplete}set selectOnComplete(e){this.viewModel.selectOnComplete=e}get selectionManager(){return this.viewModel.selectionManager}set selectionManager(e){this.viewModel.selectionManager=e}get state(){return this.viewModel.state}get sources(){return this.viewModel.sources}set sources(e){this.viewModel.sources=e}get toolConfigs(){return this.viewModel.toolConfigs}set toolConfigs(e){this.viewModel.toolConfigs=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}get visibleToolCount(){const{visibleElements:e}=this;return this.toolConfigs.length+(e.lassoTool?1:0)+(e.rectangleTool?1:0)}activate(e){if(this.cancel(),!this._effectiveDisabled)return this.viewModel.activate(e)}activateTool(e){if(!this._effectiveDisabled)return this.viewModel.activateTool(e)}cancel(){this.viewModel.cancel()}toggleTool(e){if(!this._effectiveDisabled)return this.viewModel.toggleTool(e)}render(){return h("div",{"aria-label":this.label,class:this.classes(g.base,d.widget)},h("div",{class:g.container},h("calcite-action-bar",{expandDisabled:!0,layout:"horizontal",overflowActionsDisabled:!0,scale:this.scale},this._renderOperationTypeControls(),this._renderToolsGroup(),this._renderChip())))}_renderToolsGroup(){return h("calcite-action-group",{key:"tools-group"},this._renderDefaultTools(),this._renderCustomTools())}_renderDefaultTools(){return[this._renderPanAction(),this._renderPointTool(),this._renderRectangleTool(),this._renderLassoTool()]}_renderPanAction(){if(!this.visibleElements.pan)return;const e=this.messages.pan,t=`${this.id}-tool-pan`;return this._renderAction({active:!this.activeOperation,disabled:this._effectiveDisabled,icon:"pan",id:t,key:t,onclick:()=>this.cancel(),text:e,title:e})}_renderChip(){if(!this.visibleElements.chip)return;const{effectiveSelectionManager:e}=this,o=e?.count??0,i=t(o);return h("calcite-chip",{appearance:"outline",closable:o>0,closed:0===o,disabled:this._effectiveDisabled||0===o,label:i,scale:this.scale,slot:"actions-end",title:this.messages.clearSelection,onCalciteChipClose:()=>e?.clear()},i)}_renderCustomTools(){return this.toolConfigs.map(({toolName:e,icon:t})=>this._renderToolWithTooltip(e,t))}_renderPointTool(){if(this.visibleElements.pointTool)return this._renderToolWithTooltip("point","selection-set",this.messages.selectByPoint)}_renderLassoTool(){if(this.visibleElements.lassoTool)return this._renderToolWithTooltip("lasso","lasso-select",this.messages.selectByLasso)}_renderRectangleTool(){if(this.visibleElements.rectangleTool)return this._renderToolWithTooltip("rectangle","cursor-marquee",this.messages.selectByRectangle)}_renderOperationTypeControls(){const{availableOperationTypes:e}=this;if(!this.visibleElements.operationTypeControls||!e.length)return;const{_effectiveOperationType:t,scale:o}=this,i=this._getIconForSelectionOperationType(t),l=this._getLabelForSelectionOperationType(t);return h("calcite-action-group",{key:"toggle-group"},h("calcite-dropdown",{overlayPositioning:"fixed",placement:"bottom-start",scale:o,topLayerDisabled:this.topLayerDisabled},h("calcite-action",{class:g.toolButton,disabled:this._effectiveDisabled,icon:i,scale:o,slot:"trigger",text:l,title:l},h("calcite-icon",{icon:"chevron-down",scale:"s"})),h("calcite-dropdown-group",null,e.map(e=>this._renderOperationTypeDropdownItem(e)))))}_renderOperationTypeDropdownItem(e){return h("calcite-dropdown-item",{iconStart:this._getIconForSelectionOperationType(e),selected:this.defaultOperationType===e,onCalciteDropdownItemSelect:()=>this.defaultOperationType=e},this._getLabelForSelectionOperationType(e))}_renderToolWithTooltip(e,t,o=e){const i=`${this.id}-tool-${e}`;return this._renderAction({active:this.activeOperation?.toolName===e,disabled:this._effectiveDisabled,icon:t||"selection",id:i,key:i,onclick:()=>this.toggleTool(e),text:o,title:o})}_renderAction(e){return h("calcite-action",{...e,bind:this,class:g.toolButton,scale:this.scale})}_getIconForSelectionOperationType(e){switch(e){case"replace":return"overwrite-features";case"add":return"cursor-plus";case"remove":return"cursor-minus"}}_getLabelForSelectionOperationType(e){const{messages:t}=this;switch(e){case"replace":return t.replaceSelection;case"add":return t.addToSelection;case"remove":return t.removeFromSelection}}};e([n()],T.prototype,"_effectiveDisabled",null),e([n()],T.prototype,"_effectiveOperationType",null),e([n()],T.prototype,"activeOperation",null),e([n()],T.prototype,"availableOperationTypes",void 0),e([n()],T.prototype,"continuousSelectionEnabled",null),e([n()],T.prototype,"defaultLassoToolOptions",null),e([n()],T.prototype,"defaultOperationType",null),e([n()],T.prototype,"defaultPointToolOptions",null),e([n()],T.prototype,"defaultRectangleToolOptions",null),e([n()],T.prototype,"disabled",void 0),e([n()],T.prototype,"effectiveSelectionManager",null),e([n()],T.prototype,"effectiveSources",null),e([n()],T.prototype,"label",null),e([n()],T.prototype,"layers",null),e([n()],T.prototype,"layerViewPreferenceEnabled",null),e([n()],T.prototype,"layout",void 0),e([n(),u("esri/widgets/support/SelectionToolbar/t9n/SelectionToolbar")],T.prototype,"messages",void 0),e([n()],T.prototype,"persistSelection",null),e([n()],T.prototype,"returnFeatureTitleFields",null),e([n()],T.prototype,"returnGeometry",null),e([n()],T.prototype,"selectOnComplete",null),e([n()],T.prototype,"scale",void 0),e([n()],T.prototype,"selectionManager",null),e([n()],T.prototype,"state",null),e([n()],T.prototype,"sources",null),e([n()],T.prototype,"toolConfigs",null),e([n()],T.prototype,"view",null),e([n()],T.prototype,"viewModel",void 0),e([n({type:m,nonNullable:!0})],T.prototype,"visibleElements",void 0),e([n()],T.prototype,"visibleToolCount",null),T=e([a("esri.widgets.support.SelectionToolbar")],T);const y=T;export{y as default};