UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 3.95 kB
import t from"../../../../../core/Handles.js";import{s as i,f as e}from"../../../../../chunks/vec2.js";import{a as s}from"../../../../../chunks/vec2f64.js";import{l as r,c as a,z as n,b as o,e as l}from"../../../../../chunks/vec3.js";import{c}from"../../../../../chunks/vec3f64.js";import{a as h,c as p}from"../../../../../chunks/boundedPlane.js";import{getInfo as u}from"../../../../../geometry/support/spatialReferenceUtils.js";import{Manipulation as _,ManipulatorType as d}from"./Manipulation.js";import{onGrabChangedHandle as m}from"./utils.js";import{createManipulatorDragEventPipeline as f,screenToMap as v}from"../../../../interactive/dragEventPipeline.js";import{GraphicManipulator as g}from"../../../../interactive/GraphicManipulator.js";import{AccumulationBehaviour as C}from"../../../../interactive/editGeometry/interfaces.js";import{AccumulationType as b}from"../../../../interactive/editGeometry/operations/UpdateVertices.js";import{apply as x}from"../../../../interactive/editGeometry/support/editPlaneUtils.js";const E=10,S=1e-6,y=.3;function j(t){const i=r(t.basis1),e=r(t.basis2);return y*Math.min(i,e)}class w extends _{constructor(i){super(),this._handles=new t,this._planeStart=h(),this._displayPlaneStart=h(),this._originCache=c(),this._axisCache=s(),this._renderStartCache=c(),this._renderEndCache=c(),this._resizeOriginCache=c(),this._view=i.view,this._tool=i.tool,this._graphic=i.graphic,this._direction=i.direction,this._preserveAspectRatio=i.preserveAspectRatio,this._manipulator=this._createManipulator(),this._handles.add([this._manipulator.events.on("grab-changed",(t=>m(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._graphic=null,this._manipulator=null,this._direction=null,this._handles=null,this._planeStart=null,this._displayPlaneStart=null,this._originCache=null,this._axisCache=null,this._renderStartCache=null,this._renderEndCache=null,this._resizeOriginCache=null,this._preserveAspectRatio=null}forEachManipulator(t){t(this._manipulator,d.SCALE)}createDragPipeline(t,s){let c=null,h=null,_=null,d=0,m=null,g=null;const y=this._planeStart,w=this._displayPlaneStart,P=this._direction;return f(this._manipulator,((f,M)=>{M.next((i=>{if("start"===i.action){f.cursor="grabbing";const i=t();c=i.plane,h=i.displayPlane,_=i.editGeometryOperations,d=E*this._view.resolution,p(c,y),p(h,w);const e=u(_.data.spatialReference);m=e?e.valid[1]-e.valid[0]-3*E*this._view.resolution:null}return i})).next(v(this._view)).next((t=>{const i=a(this._renderStartCache,[t.mapStart.x,t.mapStart.y,0]),e=a(this._renderEndCache,[t.mapEnd.x,t.mapEnd.y,0]),s=a(this._resizeOriginCache,w.origin);n(s,s,w.basis1,-P[0]),n(s,s,w.basis2,-P[1]),o(e,e,s),o(i,i,s);const c=0!==P[0]&&0!==P[1],p=j(w),u=j(h)/p,_=(t,s)=>{if(0===t)return 1;let a=r(s),n=.5*t*l(s,e)/a;const o=n<0?-1:1;if(c){n+=(a-.5*t*l(s,i)/a)*o*u}const h=a<1.5*d?1:S;return a=Math.max(a-d,S),o>0&&(n-=E*this._view.resolution),o*Math.max(o*(n/a),h)},m=_(P[0],w.basis1),f=_(P[1],w.basis2);return{...t,direction:P,factor1:m,factor2:f}})).next(this._preserveAspectRatio.createDragEventPipelineStep(),this._preserveAspectRatio.next).next((t=>{const r=a(this._originCache,y.origin);n(r,r,y.basis1,-P[0]),n(r,r,y.basis2,-P[1]);const o=i(this._axisCache,y.basis1[0],y.basis1[1]);e(o,o);const l=[];for(const i of _.data.components)l.push(...i.vertices);const h="start"===t.action?C.NEW_STEP:C.ACCUMULATE_STEPS,u=_.scaleVertices(l,r,o,t.factor1,t.factor2,h,b.REPLACE);return m&&m<_.data.geometry.extent.width&&g?_.updateVertices(l,g):(p(y,c),x(u,c),g=u.operation,s(t,u)),t})).next((t=>("end"===t.action&&(f.cursor="grab"),t)))}))}_createManipulator(){return new g({view:this._view,graphic:this._graphic,selectable:!0,cursor:"grab"})}}export{w as ScaleManipulation,j as calculateDiagonalResizeHandleScale};