UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 5.9 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"../../../../Color.js";import r from"../../../../core/Handles.js";import{handlesGroup as e}from"../../../../core/handleUtils.js";import{deg2rad as i,clamp as a}from"../../../../core/mathUtils.js";import{destroyMaybe as o}from"../../../../core/maybe.js";import{watch as n,initial as s}from"../../../../core/reactiveUtils.js";import{fromYRotation as l,fromXRotation as c,fromScaling as u,fromZRotation as p,fromRotation as m,multiply as h}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as f}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{i as d,a as g,g as _}from"../../../../chunks/vec32.js";import{create as M,fromValues as b}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{f as v}from"../../../../chunks/boundedPlane.js";import{viewshedToolManipulatorConfiguration as j}from"./ViewshedConfiguration.js";import{getViewshedRotationMatrix as w,screenToCircleAngle as A}from"./viewshedToolUtils.js";import{Manipulator3D as V}from"../../interactive/Manipulator3D.js";import{RenderObject as E}from"../../interactive/RenderObject.js";import{ManipulatorType as O}from"../../interactive/editingTools/ManipulatorType.js";import{InteractiveManipulation as T}from"../../interactive/editingTools/manipulations/InteractiveManipulation.js";import{createPolylineGeometry as y}from"../../webgl-engine/lib/GeometryUtil.js";import{RenderOccludedFlag as U}from"../../webgl-engine/lib/Material.js";import{assert as R}from"../../webgl-engine/lib/Util.js";import{RibbonLineMaterial as S}from"../../webgl-engine/materials/RibbonLineMaterial.js";import{createManipulatorDragEventPipeline as x}from"../../../interactive/dragEventPipeline.js";import{ManipulatorStateFlags as P}from"../../../interactive/interfaces.js";class C extends T{constructor(t){super(),this._handles=new r,this._tool=t.tool,this._view=t.view,this._focusedArcMaterial=this._createArcMaterial(!0),this._unfocusedArcMaterial=this._createArcMaterial(!1),this._createManipulators(),this.forEachManipulator((t=>this._tool.manipulators.add(t)))}destroy(){this._handles=o(this._handles),this.forEachManipulator((t=>{this._tool.manipulators.remove(t),t.destroy()})),this._tool=null,this._view=null,this._manipulators=null}createDragPipeline(t,r){const i=Object.values(this._manipulators);return e(i.map((({manipulator:e,side:i})=>x(e,((e,a,o,n,s)=>{const l=k(i,r),c=a.next((t=>({...t,manipulatorType:O.SCALE,side:i}))),u=A(c,this._view,l,r);t(e,u,o)})))))}updateManipulatorsTransform(t){t.arcCentersPoints(J),this._forEachManipulatorInfo((r=>this._updateArcManipulatorTransform(r,t,J[r.side])))}updateManipulatorVisuals(t){this._forEachManipulatorInfo((r=>this._updateArcManipulatorVisuals(r,t)))}_updateArcManipulatorVisuals({manipulator:t,side:r},e){const i=[];if(null!=e){const[a,o]=F(r,e,this._unfocusedArcMaterial);i.push(new E(a,P.Unfocused),new E(a.instantiate({material:this._focusedArcMaterial}),P.Focused)),t.collisionType={type:"line",paths:[o]}}t.renderObjects=i,t.radius=j.collisionRadius}_updateArcManipulatorTransform({manipulator:t,side:r},e,a){const o=e.horizontalFieldOfView,n=i(e.verticalFieldOfView/2),s=i(o/2),g=z(r);t.renderLocation=a;const _=f(),M=t=>{h(_,t,_)};M(l(H,i(-90))),g||M(c(H,n));const b=e.farDistanceRenderSpace;let v,j;M(u(H,d(W,b,b,b))),M(p(H,L(r))),M(w(e,H)),g?(v=s,j=e.tiltedUpVector):(j=e.rightVector,v=n),v*="right"===r||"bottom"===r?-1:1;const A=m(H,v,j);null!=A&&M(A),t.modelTransform=_}_createManipulators(){const t=this._createArcManipulator("left"),r=this._createArcManipulator("right"),e=this._createArcManipulator("top"),i=this._createArcManipulator("bottom");this._manipulators={left:t,right:r,top:e,bottom:i};[[i.manipulator,e.manipulator],[t.manipulator,r.manipulator]].forEach((([t,r])=>{t.metadata={pairedManipulator:r},r.metadata={pairedManipulator:t}}))}_createArcManipulator(t){const r=new V({view:this._view,autoScaleRenderObjects:!1,worldSized:!0}),e={manipulator:r,side:t};return this._updateArcManipulatorVisuals(e),this._handles.add(r.events.on("focus-changed",(t=>{const e=r.metadata?.pairedManipulator;null!=e&&(e.hovering!==r.hovering&&(e.hovering=r.hovering),e.grabbing!==r.grabbing&&(e.grabbing=r.grabbing))}))),e}_createArcMaterial(r){const e=j.getFovArcWidth(r),i=new S({renderOccluded:U.OccludeAndTransparent,isDecoration:!0,width:e});return this._handles.add(n((()=>t.toUnitRGBA(this._view.effectiveTheme.accentColor)),(t=>i.setParameters({color:t})),s)),i}forEachManipulator(t){Object.values(this._manipulators).forEach((({manipulator:r})=>t(r,O.SCALE)))}_forEachManipulatorInfo(t){Object.values(this._manipulators).forEach((r=>t(r)))}get test(){return{manipulators:this._manipulators}}}function F(t,r,e){const{horizontalFieldOfView:o,verticalFieldOfView:n}=r,s=z(t),l=i(a((s?n:o)/2,0,15)),c=D(-l/2,l/2,s?1:Math.max(Math.sin(i(90-n/2)),.1));return[y(e,c),c]}function D(t,r,e,i=10){R(i>1,"createArcPolylineGeometry() needs at least 2 for numVertices");const a=r-t;if(a<=0||e<=0){return[b(0,0,.01),b(0,0,-.01)]}const o=[],n=a/i;for(let s=0;s<i;s++){let a=t+s*n;s===i-1&&(a=r);const l=Math.cos(a)*e,c=Math.sin(a)*e,u=b(l-e,0,c);o.push(u)}return o}function I(t){switch(t){case"left":return 0;case"bottom":return 1;case"right":return 2;case"top":return 3}}function L(t){return I(t)*B}function z(t){return"left"===t||"right"===t}function G(t){return"left"===t?"right":"right"===t?"left":"top"===t?"bottom":"top"}function k(t,{observerRenderSpace:r,targetRenderSpace:e,tiltedUpVector:i,rightVector:a,farDistanceRenderSpace:o}){const n=g(W,e,r),s=z(t)?a:i,l=_(q,s,o);return v(r,n,l)}const B=Math.PI/2,H=f(),W=M(),q=M(),J={top:M(),bottom:M(),left:M(),right:M()};export{C as FieldOfViewManipulation,D as createArcPolylineVertices,G as flipSide,z as isSideHorizontal,L as sideToRad};