UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 3.87 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import{destroyHandle as o,makeHandle as i,abortHandle as s}from"../../../../core/handleUtils.js";import{debounce as n}from"../../../../core/promiseUtils.js";import{initial as r}from"../../../../core/reactiveUtils.js";import{property as l,subclass as a}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as d}from"../../../../core/support/UpdatingHandles.js";import{ViewEventPriorities as h}from"../../../input/InputManager.js";const c={redo:"r",undo:"z"},p=Symbol(),m=Symbol(),_=Symbol();let u=class extends t{constructor(e){super(e),this._tool=null,this._updatingHandles=new d,this.enabled=!1,this._onPointerMove=n(async e=>{const t=await this._updatingHandles.addPromise(this._findElementAtScreenPoint(e));this.destroyed||(this.removeHandles(m),t&&t!==this.selectedElement&&this.addHandles(this.view.acquireCursor("pointer","high"),m))})}initialize(){this.addHandles(o(this._updatingHandles)),this._updatingHandles.add(()=>this.enabled,e=>this._setEnabled(e),r),this._updatingHandles.add(()=>this._preferredInteractionTool,()=>this._preferredInteractionToolChanged())}get _validatedSelectedElement(){const e=this.selectedElement;if(!e)return null;const{layer:{source:t}}=this;return t?"hasElement"in t?t.hasElement(e)?e:null:t===e?e:null:null}get _preferredInteractionTool(){return this.options?.tool??"transform"}get updating(){return this._updatingHandles.updating}_setEnabled(e){if(this.removeHandles(p),!e)return;const{view:t}=this;this.addHandles([t.on("immediate-click",e=>this._onClick(e),h.TOOL),t.on("pointer-move",e=>this._onPointerMove(e).catch(()=>{}),h.TOOL),t.on("key-down",e=>{e.key===c.undo&&this._tool?.canUndo()&&(this._tool.undo(),e.stopPropagation()),e.key===c.redo&&this._tool?.canRedo()&&(this._tool.redo(),e.stopPropagation())}),this._updatingHandles.add(()=>this._validatedSelectedElement,e=>this._selectedElementChanged(e),r),i(()=>{this.removeHandles(m),this._removeTool()})],p)}async _findElementAtScreenPoint(e){const t=(await this.view.hitTest(e,{include:[this.layer]})).results[0];return"media"===t?.type?t.element:null}async _onClick(e){await this._updatingHandles.addPromise(e.defer(async()=>{const t=await this._findElementAtScreenPoint(e);this.destroyed||(t&&e.stopPropagation(),this.selectedElement=t,this.selectedElement&&this.removeHandles(m))}))}_preferredInteractionToolChanged(){const{_tool:e}=this;e&&(this._preferredInteractionTool===e.type||this._updatingHandles.addPromise(this._recreateTool()))}async _recreateTool(){this.removeHandles(_),this._removeTool();const e=this._validatedSelectedElement;if(!e)return;const t=new AbortController;this.addHandles(s(t),_);const{TransformTool:o,ControlPointsTransformTool:n}=await import("../../interactive/editingTools.js");if(t.signal.aborted)return;const{view:r}=this;switch(this._preferredInteractionTool){case"transform":this._tool=new o({target:e,view:r});break;case"reshape":this._tool=new n({mediaElement:e,view:r})}this.addHandles(i(()=>{this._tool&&(r.tools.remove(this._tool),this._tool=null)}),this._tool),r.addAndActivateTool(this._tool)}_removeTool(){this._tool&&this.removeHandles(this._tool)}async _selectedElementChanged(e){e?.georeference?await this._updatingHandles.addPromise(this._recreateTool()):this._removeTool()}};e([l()],u.prototype,"_validatedSelectedElement",null),e([l()],u.prototype,"_preferredInteractionTool",null),e([l({constructOnly:!0})],u.prototype,"view",void 0),e([l({constructOnly:!0})],u.prototype,"layer",void 0),e([l()],u.prototype,"selectedElement",void 0),e([l()],u.prototype,"enabled",void 0),e([l()],u.prototype,"options",void 0),e([l()],u.prototype,"updating",null),u=e([a("esri.views.2d.layers.support.MediaLayerInteraction")],u);export{u as MediaLayerInteraction};