@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.24 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import a from"../../../../core/Collection.js";import{getOrCreateMapValue as n}from"../../../../core/MapUtils.js";import r from"../../../../core/ReactiveMap.js";import{watch as i}from"../../../../core/reactiveUtils.js";import{createScreenPoint as o}from"../../../../core/screenUtils.js";import{property as l}from"../../../../core/accessorSupport/decorators/property.js";import{subclass as s}from"../../../../core/accessorSupport/decorators/subclass.js";import{DrawManipulator as p}from"../../DrawManipulator.js";import{InteractiveHandle as d}from"../InteractiveHandle.js";import{ManipulatorCollection as u}from"../../../interactive/ManipulatorCollection.js";const h=Symbol("manipulator-handle-watch");let c=class extends t{constructor(e){super(e),this._pluginConstraintRegistry=new r,this._pluginHandleRegistry=new r,this._handleManipulatorMap=new a,this.renderer=null,this.manipulators=new u,this.view=null,this.capturingHandle=null}initialize(){super.initialize()}destroy(){this._pluginConstraintRegistry.clear(),this._pluginHandleRegistry.forEach(e=>e.drain(e=>e.destroy())),this._pluginHandleRegistry.clear(),this._handleManipulatorMap.removeAll()}get customConstraints(){return Array.from(this._pluginConstraintRegistry.values()).flatMap(e=>Array.from(e.values()))}get focusedHandle(){return this.capturingHandle??this._handleManipulatorMap.find(({handle:e,manipulator:t})=>e.dragging||t.grabbing||t.selected||t.hovering)?.handle}get handleCount(){return this._handleManipulatorMap.length}get allhandles(){return this._handleManipulatorMap.map(({handle:e})=>e).toArray()}cycleManipulator(e){const{capturingHandle:t,_handleManipulatorMap:a}=this;if(!t)return void this.followHandle(a.at(0)?.handle);const n=a.findIndex(({handle:e})=>e===t),r="forward"===e?n+1:n-1;this.followHandle(a.at(r%a.length)?.handle)}toggleFollow(){const e=this.capturingHandle;if(e)return this.releaseHandle(e),!0;const t=this._handleManipulatorMap.find(e=>"grabbable-object"!==e.handle.defaultCaptureMode)?.handle;return!!t&&(this.followHandle(t),!0)}releaseHandle(e){e&&(e.captureMode="grabbable-object",e.drawToolDragging=!1),e&&e!==this.capturingHandle||(this.capturingHandle&&(this.capturingHandle.drawToolDragging=!1,this.capturingHandle.captureMode="grabbable-object"),this.capturingHandle=null)}followHandle(e){this._handleManipulatorMap.forEach(({handle:e})=>{"grabbable-object"!==e.captureMode&&(e.captureMode="grabbable-object")}),e&&(e.captureMode="grabbable-object"===e.defaultCaptureMode?"capture-always":e.defaultCaptureMode),"grabbable-object"!==e?.captureMode&&(this.capturingHandle=e)}findHandleByManipulator(e){return this._handleManipulatorMap.toArray().findLast(({handle:t,manipulator:a})=>"grabbable-object"===t.captureMode&&null!=a.intersectionDistance(e))?.handle}findHandleDragging(){return this._handleManipulatorMap.find(({handle:e})=>e.dragging)?.handle}async setupManipulatorForHandle(e,t,a){const{view:n}=this,{surfaceManager:r}=a,l=a.editGeometryOperations?.data.coordinateHelper;if(!n||!r||!l)return;const s=new p({renderer:this.renderer,managedHandle:e});this._handleManipulatorMap.push({handle:e,manipulator:s}),this.manipulators.add(s),e.addHandles([i(()=>s.dragging,t=>{e.manipulatorDragging=t,t||this.releaseHandle(e)})],h),e.following&&(this.capturingHandle=e);const d=(e.inputMapPosition&&this.view?.toScreen(e.inputMapPosition))??e.screenPosition??t??o(n?.width/2,n.height/2);await(e?.moveTo(d,{...a,pointerType:"mouse"}))}removeManipulatorForHandle(e){const t=this._handleManipulatorMap.find(t=>t.handle===e);t&&(this.manipulators.remove(t.manipulator),this._handleManipulatorMap.remove(t),t.manipulator.destroy()),e.removeHandles(h)}registerHandle(e,t){const r=n(this._pluginHandleRegistry,e,()=>new a),i=new d(t);return r.push(i),i}unregisterHandle(e,t){const a=this._pluginHandleRegistry.get(e);a&&(t?(a.remove(t),this.removeManipulatorForHandle(t),t.destroy()):(a.drain(e=>{this.removeManipulatorForHandle(e),e.destroy()}),this._pluginHandleRegistry.delete(e)))}registerCustomConstraint(e,t,a){n(this._pluginConstraintRegistry,e,()=>new r).set(t,a)}unregisterCustomConstraint(e,t){t?this._pluginConstraintRegistry.get(e)?.delete(t):(this._pluginConstraintRegistry.get(e)?.clear(),this._pluginConstraintRegistry.delete(e))}replaceEditSessions(e,t){const a=this._pluginHandleRegistry.get(e);if(a)for(const n of a)n.editSession=t}updateAllScreenPositions(){const{view:e}=this;this._handleManipulatorMap.forEach(({handle:t})=>{const a=t.outputMapPosition;a&&(t.screenPosition=e?.toScreen(a))})}reapplyPositions(e){this._handleManipulatorMap.forEach(({handle:t})=>t.refreshConstraint(e))}};e([l({constructOnly:!0})],c.prototype,"renderer",void 0),e([l({readOnly:!0})],c.prototype,"manipulators",void 0),e([l({constructOnly:!0})],c.prototype,"view",void 0),e([l()],c.prototype,"capturingHandle",void 0),e([l()],c.prototype,"customConstraints",null),e([l()],c.prototype,"focusedHandle",null),e([l()],c.prototype,"handleCount",null),e([l()],c.prototype,"allhandles",null),c=e([s("esri.views.draw.support.managers.InteractiveHandleManager")],c);export{c as InteractiveHandleManager};