ToolViewManager.js 5.1 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{_ as t}from"../chunks/tslib.es6.js";import o from"../core/Accessor.js";import e from"../core/Collection.js";import{HandleOwner as i}from"../core/HandleOwner.js";import{makeHandle as r}from"../core/handleUtils.js";import"../core/has.js";import s from"../core/Logger.js";import{isSome as a,isNone as n,destroyMaybe as l}from"../core/maybe.js";import{watch as h}from"../core/reactiveUtils.js";import{property as c}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/accessorSupport/ensureType.js";import{subclass as p}from"../core/accessorSupport/decorators/subclass.js";import{TextureCollection as u}from"./3d/support/TextureCollection.js";import{ViewEventPriorities as v}from"./input/InputManager.js";import{eventTypes as d}from"./input/ViewEvents.js";import{getToolCollectionHandles as m,areToolManipulatorsEditable as f}from"./interactive/interactiveToolUtils.js";import{EditableFlag as _}from"./interactive/interfaces.js";import T from"./interactive/ToolViewManagerManipulatorState.js";const E=s.getLogger("esri.views.ToolViewManager"),g="attached",w="tools";let y=class extends i{constructor(t){super(t),this._manipulatorState=new T,this.tools=new e,this.cursor=null,this._forEachTool=t=>{for(const o of this.tools.items)if(t(o))return}}initialize(){this.handles.add([this.view.on(d,(t=>{this._handleInputEvent(t)}),v.TOOL),...m(this.tools),this.tools.on("before-remove",(({item:t})=>{this._manipulatorState.clearPointers(t,this._forEachTool)})),this.tools.on("change",(()=>{this._refreshToolWatchers()}))])}destroy(){this.detach(),this.handles.removeAll()}set activeTool(t){if(a(t)&&!this.view.ready)return void E.error("Cannot set active tool while view is not ready.");if(t===this.activeTool)return;const o=this.activeTool;this._set("activeTool",t),a(o)&&o.deactivate(),a(t)&&t.activate(),this._removeIncompleteTools(t);const e=n(this.activeTool);for(const i of this.tools){i.setEditableFlag(_.MANAGER,e||i===this.activeTool);const t=f(i);!e&&t||this._manipulatorState.clearPointers(i,this._forEachTool,!t)}this._updateCursor()}get updating(){return this.updatingHandles.updating||this.tools.some((t=>t.updating))||(this.textures?.updating??!1)}attach(){"3d"===this.view.type?(this._set("textures",new u(this.view._stage,this.view.resourceController.scheduler)),this.handles.add([h((()=>{const{state:t}=this.view;return"camera"in t&&t.camera}),(()=>{this._forEachManipulator((t=>{null!=t.onViewChange&&t.onViewChange()}))})),this.view.elevationProvider.on("elevation-change",(t=>{this._forEachManipulator((o=>{null!=o.onElevationChange&&o.onElevationChange(t)}))})),r((()=>this._set("textures",l(this.textures))))],g)):this.handles.add(h((()=>this.view.extent),(()=>{this._forEachManipulator((t=>{null!=t.onViewChange&&t.onViewChange()}))})))}detach(){a(this.activeTool)&&(this.activeTool=null),this.tools.removeAll(),this.handles.remove(g)}_forEachManipulator(t){this._forEachTool((o=>{o.manipulators&&o.manipulators.forEach((({manipulator:e})=>t(e,o)))}))}_handleInputEvent(t){let o=!1;const e={...t,stopPropagation:()=>{o=!0,t.stopPropagation()}};a(this.activeTool)?this.activeTool.handleInputEvent&&this.activeTool.handleInputEvent(e):this._forEachTool((t=>{!o&&t.visible&&t.handleInputEvent(e)})),!o&&"key-down"===t.type&&"Escape"===t.key&&this.activeTool&&(t.stopPropagation(),this.activeTool=null),this._manipulatorState.handleInputEvent(e,{forEachTool:this._forEachTool,activeTool:this.activeTool,setActiveTool:t=>{this.activeTool=t},view:this.view}),!o&&a(this.activeTool)&&this.activeTool.handleInputEventAfter(e),this._manipulatorState.handleHoverEvent(e,this._forEachTool),this._updateCursor()}_refreshToolWatchers(){this.handles.remove(w),this._forEachTool((t=>{if(t instanceof o){const o=h((()=>[t.cursor,t.visible,t.editable]),(()=>{f(t)||this._manipulatorState.clearPointers(t,this._forEachTool),this._updateCursor()}));this.handles.add(o,w)}t.manipulators&&this.handles.add(t.manipulators.on("change",(o=>{o.removed.forEach((({id:o})=>{this._manipulatorState.clearPointers(t,this._forEachTool,!0,o)})),this._manipulatorState.updateHoveredStateFromKnownPointers(this._forEachTool),this._updateCursor()})),w)})),this._manipulatorState.updateHoveredStateFromKnownPointers(this._forEachTool),this._updateCursor()}_updateCursor(){const t=this._manipulatorState.cursor;let o=t;this._forEachTool((e=>!(!a(e.cursor)||!e.visible||!n(t)&&e.preferManipulatorCursor)&&(o=e.cursor,!0))),this._get("cursor")!==o&&this._set("cursor",o)}_removeIncompleteTools(t){this.tools.filter((o=>(n(t)||o!==t)&&!o.created&&o.removeIncompleteOnCancel)).forEach((t=>{this.tools.remove(t)}))}};t([c({constructOnly:!0,nonNullable:!0})],y.prototype,"view",void 0),t([c({readOnly:!0,nonNullable:!0})],y.prototype,"textures",void 0),t([c({value:null})],y.prototype,"activeTool",null),t([c({readOnly:!0,type:e})],y.prototype,"tools",void 0),t([c({readOnly:!0})],y.prototype,"cursor",void 0),t([c({readOnly:!0})],y.prototype,"updating",null),y=t([p("esri.views.ToolViewManager")],y);const j=y;export{j as default};