@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 5.59 kB
JavaScript
/*
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"../../../../../Color.js";import r from"../../../../../core/Evented.js";import a from"../../../../../core/Handles.js";import{makeHandle as e,handlesGroup as i}from"../../../../../core/handleUtils.js";import"../../../../../core/has.js";import{destroyMaybe as o}from"../../../../../core/maybe.js";import{watch as s,initial as n}from"../../../../../core/reactiveUtils.js";import{fromTranslation as l,fromZRotation as p,multiply as u,fromRotation as h,fromScaling as c}from"../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as m}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{i as f}from"../../../../../chunks/vec32.js";import{fromValues as d}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{sv3d as _,sm4d as g}from"../../../../../geometry/support/vectorStacks.js";import{Manipulator3D as M}from"../../Manipulator3D.js";import{RenderObject as w}from"../../RenderObject.js";import{screenToMapXYAtLocation as j}from"../dragEventPipeline3D.js";import{ManipulatorType as v}from"../ManipulatorType.js";import{discRadius as b,discTranslateArrowOffset as A,discTranslateArrowSize as T,discHeight as y}from"./config.js";import{Manipulation as I}from"./Manipulation.js";import{createManipulatedMoveDragPipeline as x}from"./moveUtils.js";import{CullFaceOptions as D}from"../../../webgl-engine/lib/basicInterfaces.js";import{createExtrudedTriangle as S,transformInPlace as E}from"../../../webgl-engine/lib/GeometryUtil.js";import{RenderOccludedFlag as P}from"../../../webgl-engine/lib/Material.js";import{ColorMaterial as O}from"../../../webgl-engine/materials/ColorMaterial.js";import{createManipulatorDragEventPipeline as R,dragAtLocation as U,constrainToMapAxis as L,addScreenDelta as k}from"../../../../interactive/dragEventPipeline.js";import{ManipulatorStateFlags as q}from"../../../../interactive/interfaces.js";class C extends I{constructor(t){super(),this._handles=new a,this._arrowManipulatorInfos=new Array,this._angle=0,this._scale=1,this._radius=b,this._updateAfterDrag=!1,this.events=new r,this._tool=t.tool,this._view=t.view,this._opaqueMaterial=this._createMaterial(),this._transparentMaterial=this._createMaterial(.5),null!=t.radius&&(this._radius=t.radius),this._createManipulators(),this.forEachManipulator((t=>this._tool.manipulators.add(t)))}set orthogonalAvailable(t){this._arrowManipulatorInfos.length>=3&&(this._arrowManipulatorInfos[1].manipulator.available=t,this._arrowManipulatorInfos[3].manipulator.available=t)}destroy(){this._handles=o(this._handles),this.forEachManipulator((t=>{this._tool.manipulators.remove(t),t.destroy()})),this._tool=null,this._view=null,this._arrowManipulatorInfos.length=0}forEachManipulator(t){for(const{manipulator:r}of this._arrowManipulatorInfos)t(r,v.TRANSLATE_XY)}createManipulatedObjectDragPipeline(t,r,a){if(!r.operations)return e();const i=r.operations.data.spatialReference,o=r.graphic;return x(r,a,(a=>this.createDragPipeline(((r,e,i,o,s)=>(({steps:e,cancel:i}=t(r,e,i,o,s)),a(r,e,i))),r.elevationInfo,i,o)))}createDragPipeline(t,r,a,e){return i(this._arrowManipulatorInfos.map((({manipulator:i},o)=>R(i,((i,s,n,l,p)=>{const u=s.next((t=>({...t,manipulatorType:v.TRANSLATE_XY}))).next(U(this._view,i.elevationAlignedLocation)).next(j(this._view,i.elevationAlignedLocation,r,a,e)).next(L(i.location,this.angle+(o+1)*Math.PI*.5)).next(k());t(i,u,n,l,p)})))))}get angle(){return this._angle}set angle(t){this._angle=t,this.dragging?this._updateAfterDrag=!0:this._updateManipulatorTransform()}get displayScale(){return this._scale}set displayScale(t){this._scale=t,this._updateManipulatorTransform()}get radius(){return this._radius}set radius(t){this._radius!==t&&(this._radius=t,this._updateManipulators())}_updateManipulators(){for(let t=0;t<this._arrowManipulatorInfos.length;t++)this._updateArrowManipulator(this._arrowManipulatorInfos[t],t);this._updateManipulatorTransform()}_updateArrowManipulator({manipulator:t,transform:r},a){const e=this._radius/b,i=T*e,o=i*Math.sqrt(3)/2,s=S(this._opaqueMaterial,o,i/2,i/2,y);E(s,l(g.get(),f(_.get(),0,-o/3,0))),t.renderObjects=[new w(s,q.Focused),new w(s.instantiate({material:this._transparentMaterial}),q.Unfocused)],t.radius=o/3*2*1.2;const n=p(g.get(),a*Math.PI/2),h=l(g.get(),f(_.get(),0,A*e,0));u(r,n,h)}_createManipulators(){for(let t=0;t<4;t++){const r=this._createArrowManipulator(t);this._arrowManipulatorInfos.push(r)}this._updateManipulatorTransform()}_updateManipulatorTransform(){const t=this.angle,r=h(g.get(),t,d(0,0,1));if(null==r)return;const a=c(g.get(),f(_.get(),this.displayScale,this.displayScale,this.displayScale)),e=u(g.get(),a,r);for(const i of this._arrowManipulatorInfos){const t=u(g.get(),e,i.transform);i.manipulator.modelTransform=t}}_createArrowManipulator(t){const r=new M({view:this._view,autoScaleRenderObjects:!1,worldOriented:!0,focusMultiplier:1,touchMultiplier:1,collisionType:{type:"disc",direction:d(0,0,1)}}),a={manipulator:r,transform:m()};return this._updateArrowManipulator(a,t),this._handles.add(r.events.on("drag",(t=>{this._updateAfterDrag&&"end"===t.action&&!this.dragging&&(this._updateManipulatorTransform(),this._updateAfterDrag=!1)}))),a}_createMaterial(r=1){const a=new O({cullFace:D.Back,renderOccluded:P.Transparent,isDecoration:!0});return this._handles.add(s((()=>t.toUnitRGBA(this._view.effectiveTheme.accentColor)),(t=>{t[3]*=r,a.setParameters({color:t})}),n)),a}get test(){}}export{C as MoveXYAxisManipulation};