UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 5.28 kB
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 l,destroyMaybe as n}from"../core/maybe.js";import{watch as h}from"../core/reactiveUtils.js";import{property as c}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import{subclass as p}from"../core/accessorSupport/decorators/subclass.js";import{TextureCollection as u}from"./3d/support/TextureCollection.js";import{ViewEventPriorities as d}from"./input/InputManager.js";import{eventTypes as v}from"./input/ViewEvents.js";import{getToolCollectionHandles as m,areToolManipulatorsEditable as _}from"./interactive/interactiveToolUtils.js";import{EditableFlag as f}from"./interactive/interfaces.js";import{ToolViewManagerManipulatorState as T}from"./interactive/ToolViewManagerManipulatorState.js";const E="attached",g="tools";let w=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(v,(t=>{this._handleInputEvent(t)}),d.TOOL),...m(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._updateCursor()})),this.tools.on("change",(()=>{this._refreshToolWatchers()}))])}destroy(){this.detach(),this.handles.removeAll()}get _manipulatorStateEventArgs(){return{forEachTool:this._forEachTool,activeTool:this.activeTool,setActiveTool:t=>{this.activeTool=t},view:this.view}}set activeTool(t){if(a(t)&&!this.view.ready)return void s.getLogger(this.declaredClass).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);for(const e of this.tools){this._updateToolEditableFlag(e);const t=_(e);!l(this.activeTool)&&t||this._manipulatorState.clearPointers(e,this._manipulatorStateEventArgs,!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=>t.onViewChange())))),this.view.elevationProvider?.on("elevation-change",(t=>this._forEachManipulator((o=>o.onElevationChange(t))))),r((()=>this._set("textures",n(this.textures))))],E)):this.handles.add(h((()=>this.view.extent),(()=>this._forEachManipulator((t=>t.onViewChange())))))}detach(){a(this.activeTool)&&(this.activeTool=null),this.tools.removeAll(),this.handles.remove(E)}_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,this._manipulatorStateEventArgs),!o&&a(this.activeTool)&&this.activeTool.handleInputEventAfter(e),this._manipulatorState.handleHoverEvent(e,this._forEachTool),this._updateCursor()}_refreshToolWatchers(){this.handles.remove(g),this._forEachTool((t=>{if(t instanceof o){const o=h((()=>[t.cursor,t.visible,t.editable]),(()=>{_(t)||this._manipulatorState.clearPointers(t,this._manipulatorStateEventArgs),this._updateCursor()}));this.handles.add(o,g)}t.manipulators&&this.handles.add([t.manipulators.on("after-remove",(o=>{this._manipulatorState.clearPointers(t,this._manipulatorStateEventArgs,!0,o.item.manipulator)})),t.manipulators.on("change",(()=>{this._manipulatorState.updateHoveredStateFromKnownPointers(this._forEachTool),this._updateCursor()}))],g)})),this._manipulatorState.updateHoveredStateFromKnownPointers(this._forEachTool),this._updateCursor()}_updateToolEditableFlag(t){t.setEditableFlag?.(f.MANAGER,l(this.activeTool)||t===this.activeTool)}_updateCursor(){let t=this._manipulatorState.cursor;l(t)&&this._forEachTool((o=>!(!a(o.cursor)||!o.visible)&&(t=o.cursor,!0))),this._get("cursor")!==t&&this._set("cursor",t)}_removeIncompleteTools(t){this.tools.filter((o=>(l(t)||o!==t)&&!o.created&&o.removeIncompleteOnCancel)).forEach((t=>{this.tools.remove(t)}))}};t([c({constructOnly:!0,nonNullable:!0})],w.prototype,"view",void 0),t([c({readOnly:!0,nonNullable:!0})],w.prototype,"textures",void 0),t([c({value:null})],w.prototype,"activeTool",null),t([c({readOnly:!0,type:e})],w.prototype,"tools",void 0),t([c({readOnly:!0})],w.prototype,"cursor",void 0),t([c({readOnly:!0})],w.prototype,"updating",null),w=t([p("esri.views.ToolViewManager")],w);const y=w;export{y as default};