UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.19 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import{makeHandle as o,destroyHandle as s,abortHandle as i}from"../../../../core/handleUtils.js";import{debounce as n}from"../../../../core/promiseUtils.js";import{initial as r}from"../../../../core/reactiveUtils.js";import{property as l}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as a}from"../../../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as d}from"../../../../core/support/UpdatingHandles.js";import{ViewEventPriorities as c}from"../../../input/InputManager.js";const h={redo:"r",undo:"z"},p=Symbol(),m=Symbol(),u=Symbol();let _=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.view.cursor="pointer",this.addHandles(o((()=>this.view.cursor=null)),m)))}))}initialize(){this.addHandles(s(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)),c.TOOL),t.on("pointer-move",(e=>this._onPointerMove(e).catch((()=>{}))),c.TOOL),t.on("key-down",(e=>{e.key===h.undo&&this._tool?.canUndo()&&(this._tool.undo(),e.stopPropagation()),e.key===h.redo&&this._tool?.canRedo()&&(this._tool.redo(),e.stopPropagation())})),this._updatingHandles.add((()=>this._validatedSelectedElement),(e=>this._selectedElementChanged(e)),r),o((()=>{t.cursor=null,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.view.cursor=null))})))}_preferredInteractionToolChanged(){const{_tool:e}=this;e&&(this._preferredInteractionTool===e.type||this._updatingHandles.addPromise(this._recreateTool()))}async _recreateTool(){this.removeHandles(u),this._removeTool();const e=this._validatedSelectedElement;if(!e)return;const t=new AbortController;this.addHandles(i(t),u);const{TransformTool:s,ControlPointsTransformTool:n}=await import("../../interactive/editingTools.js");if(t.signal.aborted)return;const{view:r}=this;switch(this._preferredInteractionTool){case"transform":this._tool=new s({target:e,view:r});break;case"reshape":this._tool=new n({mediaElement:e,view:r})}this.addHandles(o((()=>{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()],_.prototype,"_validatedSelectedElement",null),e([l()],_.prototype,"_preferredInteractionTool",null),e([l({constructOnly:!0})],_.prototype,"view",void 0),e([l({constructOnly:!0})],_.prototype,"layer",void 0),e([l()],_.prototype,"selectedElement",void 0),e([l()],_.prototype,"enabled",void 0),e([l()],_.prototype,"options",void 0),e([l()],_.prototype,"updating",null),_=e([a("esri.views.2d.layers.support.MediaLayerInteraction")],_);export{_ as MediaLayerInteraction};