UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.15 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import t from"../../../../../core/Handles.js";import{set as i,normalize as e}from"../../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as r}from"../../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{c as a,b as s,d as n,l as o,e as l}from"../../../../../chunks/vec32.js";import{create as c}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{d as h,a as p}from"../../../../../chunks/boundedPlane.js";import{getInfo as u}from"../../../../../geometry/support/spatialReferenceUtils.js";import{Manipulation as _,ManipulatorType as m}from"./Manipulation.js";import{onGrabChangedHandle as d}from"./utils.js";import{createManipulatorDragEventPipeline as f,screenToMap as v}from"../../../../interactive/dragEventPipeline.js";import{GraphicManipulator as g}from"../../../../interactive/GraphicManipulator.js";import{AccumulationBehavior as b}from"../../../../interactive/editGeometry/interfaces.js";import{AccumulationType as x}from"../../../../interactive/editGeometry/operations/UpdateVertices.js";import{apply as C}from"../../../../interactive/editGeometry/support/editPlaneUtils.js";const E=10,S=1e-6,y=.3;function j(t){const i=o(t.basis1),e=o(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=r(),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=>d(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,m.SCALE)}createDragPipeline(t,r){let c=null,h=null,_=null,m=0,d=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,m=E*this._view.resolution,p(c,y),p(h,w);const e=u(_.data.spatialReference);d=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]),r=a(this._resizeOriginCache,w.origin);s(r,r,w.basis1,-P[0]),s(r,r,w.basis2,-P[1]),n(e,e,r),n(i,i,r);const c=0!==P[0]&&0!==P[1],p=j(w),u=j(h)/p,_=(t,r)=>{if(0===t)return 1;let a=o(r),s=.5*t*l(r,e)/a;const n=s<0?-1:1;if(c){s+=(a-.5*t*l(r,i)/a)*n*u}const h=a<1.5*m?1:S;return a=Math.max(a-m,S),n>0&&(s-=E*this._view.resolution),n*Math.max(n*(s/a),h)},d=_(P[0],w.basis1),f=_(P[1],w.basis2);return{...t,direction:P,factor1:d,factor2:f}})).next(this._preserveAspectRatio.createDragEventPipelineStep(),this._preserveAspectRatio.next).next((t=>{const n=a(this._originCache,y.origin);s(n,n,y.basis1,-P[0]),s(n,n,y.basis2,-P[1]);const o=i(this._axisCache,y.basis1[0],y.basis1[1]);e(o,o);const l=_.data.allVertices,h="start"===t.action?b.NEW_STEP:b.ACCUMULATE_STEPS,u=_.scaleVertices(l,n,o,t.factor1,t.factor2,h,x.REPLACE);return d&&d<_.data.geometry.extent.width&&g?_.updateVertices(l,g):(p(y,c),C(u,c),g=u.operation,r(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};