UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2.33 kB
import t from"../../../../../core/Handles.js";import{c as i}from"../../../../../chunks/vec3.js";import{c as r}from"../../../../../chunks/vec3f64.js";import{Manipulation as e,ManipulatorType as o}from"./Manipulation.js";import{onGrabChangedHandle as a}from"./utils.js";import{getRotationAngle as n}from"../../../../draw/support/drawUtils.js";import{createManipulatorDragEventPipeline as s,screenToMap as l}from"../../../../interactive/dragEventPipeline.js";import{GraphicManipulator as p}from"../../../../interactive/GraphicManipulator.js";import{AccumulationBehaviour as h}from"../../../../interactive/editGeometry/interfaces.js";import{AccumulationType as c}from"../../../../interactive/editGeometry/operations/UpdateVertices.js";import{apply as u}from"../../../../interactive/editGeometry/support/editPlaneUtils.js";class m extends e{constructor(i){super(),this._handles=new t,this._originCache=r(),this._view=i.view,this._tool=i.tool,this._graphic=i.graphic,this._snapRotation=i.snapRotation,this._manipulator=this._createManipulator(),this._handles.add([this._manipulator.events.on("grab-changed",(t=>a(t,this._manipulator)))]),this.forEachManipulator((t=>this._tool.manipulators.add(t)))}destroy(){this._handles.destroy(),this.forEachManipulator((t=>{this._tool.manipulators.remove(t),t.destroy()})),this._tool=null,this._view=null,this._manipulator=null,this._snapRotation=null,this._graphic=null,this._handles=null,this._originCache=null}forEachManipulator(t){t(this._manipulator,o.ROTATE)}createDragPipeline(t,r){let e=null,o=null;return s(this._manipulator,((a,s)=>{s.next((i=>{if("start"===i.action){a.cursor="grabbing";const i=t();e=i.plane,o=i.editGeometryOperations}return i})).next(l(this._view)).next((t=>({...t,rotateAngle:n(t.mapStart,t.mapEnd,{x:e.origin[0],y:e.origin[1]},!0)}))).next(this._snapRotation.createDragEventPipelineStep(),this._snapRotation.next).next((t=>{const a=i(this._originCache,e.origin),n=[];for(const i of o.data.components)n.push(...i.vertices);const s="start"===t.action?h.NEW_STEP:h.ACCUMULATE_STEPS,l=o.rotateVertices(n,a,t.rotateAngle,s,c.REPLACE);return u(l,e),r(t,l),t})).next((t=>("end"===t.action&&(a.cursor="grab"),t)))}))}_createManipulator(){const t=this._view,i=this._graphic;return new p({view:t,graphic:i,selectable:!0,cursor:"grab"})}}export{m as RotateManipulation};