UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 5.44 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as t}from"tslib";import e from"../core/Accessor.js";import{clock as o}from"../core/clock.js";import i from"../core/Collection.js";import"../core/has.js";import a from"../core/Logger.js";import{removeMaybe as n}from"../core/maybe.js";import{watch as s}from"../core/reactiveUtils.js";import{property as r,subclass as l}from"../core/accessorSupport/decorators.js";import{UpdatingHandles as c}from"../core/support/UpdatingHandles.js";import{ViewEventPriorities as h}from"./input/InputManager.js";import{eventTypes as u}from"./input/ViewEvents.js";import{getToolCollectionHandles as p,areToolManipulatorsEditable as m,isCancelEvent as v}from"./interactive/interactiveToolUtils.js";import{ToolViewManagerManipulatorState as d}from"./interactive/ToolViewManagerManipulatorState.js";const g="attached",_="tools",T=1e3;let f=class extends e{constructor(t){super(t),this._updatingHandles=new c,this._clock=o,this._manipulatorState=new d,this.tools=new i,this._interacting=!1,this._interactingTimeout=T,this._interactingTimeoutHandle=null}initialize(){this.addHandles([this.view.on(u,t=>{this._handleInputEvent(t)},h.TOOL),...p(this.tools),this.tools.on("before-add",({item:t})=>{this._updateToolEditableFlag(t)}),this.tools.on("before-remove",({item:t})=>{this._manipulatorState.clearPointers(t,this._manipulatorStateEventArgs)}),this.tools.on("change",()=>{this._refreshToolWatchers()})])}destroy(){this.activeTool=null,this.tools.drain(t=>t.destroy()),this._clearInteractingTimeout(),this._interacting=!1,this._updatingHandles.destroy(),this._manipulatorState.destroy()}get _manipulatorStateEventArgs(){return{tools:this.tools,activeTool:this.activeTool,setActiveTool:t=>{this.activeTool=t},view:this.view,multiTouchActive:this.view.inputManager?.multiTouchActive}}set activeTool(t){if(null!=t&&!this.view.ready)return void a.getLogger(this).error("Cannot set active tool while view is not ready.");if(t===this.activeTool)return;const e=this.activeTool;this._set("activeTool",t),null!=e&&e.deactivate(),null!=t&&t.activate(),this._removeIncompleteTools(t);for(const o of this.tools){this._updateToolEditableFlag(o);const t=m(o);null!=this.activeTool&&t||this._manipulatorState.clearPointers(o,this._manipulatorStateEventArgs,!t)}}get cursor(){const t=this._manipulatorState.cursor;if(null!=t)return t;for(const e of this.tools)if(e.visible&&null!=e.cursor)return e.cursor;return null}get updating(){return this._updatingHandles.updating||this.tools.some(t=>t.updating)}get interacting(){return this._interacting}_clearInteractingTimeout(){this._interactingTimeoutHandle=n(this._interactingTimeoutHandle)}_startInteractingTimeout(){this._clearInteractingTimeout(),this._interactingTimeoutHandle=this._clock.setTimeout(()=>this._interacting=!1,this._interactingTimeout)}attach(){"3d"===this.view.type?this.addHandles([s(()=>{const{state:t}=this.view;return"camera"in t&&t.camera},()=>this._forEachManipulator(t=>t.onViewChange())),this.view.elevationProvider.on("elevation-change",t=>this._forEachManipulator(e=>e.onElevationChange(t)))],g):this.addHandles(s(()=>this.view.extent,()=>this._forEachManipulator(t=>t.onViewChange())))}detach(){this.activeTool=null,this.tools.removeAll(),this.removeHandles(g),this._clearInteractingTimeout(),this._interacting=!1}_forEachManipulator(t){for(const e of this.tools)e.manipulators&&e.manipulators.forEach(({manipulator:o})=>t(o,e))}_handleInputEvent(t){let e=!1;const o={...t,stopPropagation:()=>{e=!0,t.stopPropagation()}};if(null!=this.activeTool)this.activeTool.handleInputEvent&&this.activeTool.handleInputEvent(o);else for(const i of this.tools)!e&&i.visible&&i.handleInputEvent(o);!e&&v(t)&&this.activeTool&&(t.stopPropagation(),t.preventDefault(),this.activeTool.cancel(),this.activeTool=null),this._manipulatorState.handleInputEvent(o,this._manipulatorStateEventArgs),e||null==this.activeTool||this.activeTool.handleInputEventAfter(o),this._manipulatorState.handleHoverEvent(o,this.tools),"pointer-move"===t.type&&(this._manipulatorState.hasFocusedManipulators||this.activeTool)&&(this._interacting=!0,this._startInteractingTimeout())}_refreshToolWatchers(){this.removeHandles(_);for(const t of this.tools){if(t instanceof e){const e=s(()=>[t.cursor,t.visible,t.editable],()=>{m(t)||this._manipulatorState.clearPointers(t,this._manipulatorStateEventArgs)});this.addHandles(e,_)}t.manipulators&&this.addHandles([t.manipulators.on("after-remove",e=>{this._manipulatorState.clearPointers(t,this._manipulatorStateEventArgs,!0,e.item.manipulator)}),t.manipulators.on("change",()=>{this._manipulatorState.updateHoveredStateFromKnownPointers(this.tools)})],_)}this._manipulatorState.updateHoveredStateFromKnownPointers(this.tools)}_updateToolEditableFlag(t){t.setEditableFlag?.(1,null==this.activeTool||t===this.activeTool)}_removeIncompleteTools(t){this.tools.filter(e=>(null==t||e!==t)&&!e.created&&e.removeIncompleteOnCancel).forEach(t=>{this.tools.remove(t)})}get test(){}};t([r({constructOnly:!0,nonNullable:!0})],f.prototype,"view",void 0),t([r({value:null})],f.prototype,"activeTool",null),t([r({readOnly:!0,type:i})],f.prototype,"tools",void 0),t([r()],f.prototype,"cursor",null),t([r({readOnly:!0})],f.prototype,"updating",null),t([r()],f.prototype,"_interacting",void 0),t([r({readOnly:!0})],f.prototype,"interacting",null),f=t([l("esri.views.ToolViewManager")],f);export{f as ToolViewManager,T as interactingTimeout};