UNPKG

@arcgis/core

Version:

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

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