@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.56 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import t from"../../../../core/Handles.js";import{handlesGroup as r}from"../../../../core/handleUtils.js";import{deg2rad as e,clamp as i}from"../../../../core/mathUtils.js";import{destroyMaybe as a}from"../../../../core/maybe.js";import{watch as o,initial as n}from"../../../../core/reactiveUtils.js";import{fromYRotation as s,fromXRotation as l,fromScaling as c,fromZRotation as u,fromRotation as p,multiply as m}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as h}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as d,sub as f,scale as _}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as g,fromValues as M}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{f as b}from"../../../../chunks/boundedPlane.js";import{viewshedToolManipulatorConfiguration as v}from"./ViewshedConfiguration.js";import{getViewshedRotationMatrix as j,screenToCircleAngle as w}from"./viewshedToolUtils.js";import{Manipulator3D as A}from"../../interactive/Manipulator3D.js";import{RenderObject as V}from"../../interactive/RenderObject.js";import{InteractiveManipulation as O}from"../../interactive/editingTools/manipulations/InteractiveManipulation.js";import{createPolylineGeometry as E}from"../../webgl-engine/lib/GeometryUtil.js";import{assert as y}from"../../webgl-engine/lib/Util.js";import{RibbonLineMaterial as R}from"../../webgl-engine/materials/RibbonLineMaterial.js";import{createManipulatorDragEventPipeline as T}from"../../../interactive/dragEventPipeline.js";class U extends O{constructor(r){super(),this._handles=new t,this._tool=r.tool,this._view=r.view,this._focusedArcMaterial=this._createArcMaterial(!0),this._unfocusedArcMaterial=this._createArcMaterial(!1),this._createManipulators(),this.forEachManipulator(t=>this._tool.manipulators.add(t))}destroy(){this._handles=a(this._handles),this.forEachManipulator(t=>{this._tool.manipulators.remove(t),t.destroy()}),this._tool=null,this._view=null,this._manipulators=null}createDragPipeline(t,e){const i=Object.values(this._manipulators);return r(i.map(({manipulator:r,side:i})=>T(r,(r,a,o,n,s)=>{const l=G(i,e),c=a.next(t=>({...t,manipulatorType:2,side:i})),u=w(c,this._view,l,e);t(r,u,o)})))}updateManipulatorsTransform(t){t.arcCentersPoints(B),this._forEachManipulatorInfo(r=>this._updateArcManipulatorTransform(r,t,B[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]=x(r,e,this._unfocusedArcMaterial);i.push(new V(a,1),new V(a.instantiate({material:this._focusedArcMaterial}),2)),t.collisionType={type:"line",paths:[o]}}t.renderObjects=i,t.radius=v.collisionRadius}_updateArcManipulatorTransform({manipulator:t,side:r},i,a){const o=i.horizontalFieldOfView,n=e(i.verticalFieldOfView/2),f=e(o/2),_=F(r);t.renderLocation=a;const g=h(),M=t=>{m(g,t,g)};M(s(C,e(-90))),_||M(l(C,n));const b=i.farDistanceRenderSpace;let v,w;M(c(C,d(L,b,b,b))),M(u(C,D(r))),M(j(i,C)),_?(v=f,w=i.tiltedUpVector):(w=i.rightVector,v=n),v*="right"===r||"bottom"===r?-1:1;const A=p(C,v,w);null!=A&&M(A),t.modelTransform=g}_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 A({view:this._view,autoScaleRenderObjects:!1,worldSized:!0}),e={manipulator:r,side:t};return this._updateArcManipulatorVisuals(e),this._handles.add(r.events.on(["focus-changed","grab-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(t){const r=v.getFovArcWidth(t),e=new R({renderOccluded:4,isDecoration:!0,width:r},this._view.state.isGlobal);return this._handles.add(o(()=>this._view.effectiveTheme.accentColor.toUnitRGBA(),t=>e.setParameters({color:t}),n)),e}forEachManipulator(t){Object.values(this._manipulators).forEach(({manipulator:r})=>t(r,2))}_forEachManipulatorInfo(t){Object.values(this._manipulators).forEach(r=>t(r))}get test(){return{manipulators:this._manipulators}}}function x(t,r,a){const{horizontalFieldOfView:o,verticalFieldOfView:n}=r,s=F(t),l=e(i((s?n:o)/2,0,15)),c=P(-l/2,l/2,s?1:Math.max(Math.sin(e(90-n/2)),.1));return[E(a,c),c]}function P(t,r,e,i=10){y(i>1,"createArcPolylineGeometry() needs at least 2 for numVertices");const a=r-t;if(a<=0||e<=0){const t=.01;return[M(0,0,t),M(0,0,-t)]}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=M(l-e,0,c);o.push(u)}return o}function S(t){switch(t){case"left":return 0;case"bottom":return 1;case"right":return 2;case"top":return 3}}function D(t){return S(t)*z}function F(t){return"left"===t||"right"===t}function I(t){return"left"===t?"right":"right"===t?"left":"top"===t?"bottom":"top"}function G(t,{observerRenderSpace:r,targetRenderSpace:e,tiltedUpVector:i,rightVector:a,farDistanceRenderSpace:o}){const n=f(L,e,r),s=F(t)?a:i,l=_(k,s,o);return b(r,n,l)}const z=Math.PI/2,C=h(),L=g(),k=g(),B={top:g(),bottom:g(),left:g(),right:g()};export{U as ViewshedFieldOfViewManipulation,P as createArcPolylineVertices,I as flipSide,F as isSideHorizontal,D as sideToRad};