@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 3.88 kB
JavaScript
import{handlesGroup as e,destroyHandle as t,refHandle as a}from"../../../../core/handleUtils.js";import{deg2rad as n}from"../../../../core/mathUtils.js";import{isSome as i}from"../../../../core/maybe.js";import{watch as l}from"../../../../core/reactiveUtils.js";import{s as r,a as o,g as s}from"../../../../chunks/vec3.js";import{c as p}from"../../../../chunks/vec3f64.js";import{getGraphicEffectiveElevationInfo as c}from"../../../../support/elevationInfoUtils.js";import{Manipulator3D as m}from"../Manipulator3D.js";import{GrabbingState as h}from"./GrabbingState.js";import{ManipulatorState as u}from"./ManipulatorState.js";import{ManipulatorType as d}from"./ManipulatorType.js";import{settings as g}from"./settings.js";import{ExtendedLineVisualElement as f}from"../visualElements/ExtendedLineVisualElement.js";import{LaserlineVisualElement as v}from"../visualElements/LaserlineVisualElement.js";import{OutlineVisualElement as y}from"../visualElements/OutlineVisualElement.js";import{GraphicState as E}from"../../layers/graphics/GraphicState.js";import{RenderOccludedFlag as w}from"../../webgl-engine/lib/Material.js";function b(t){const{view:a,graphic:n}=t,i=new E({graphic:n}),l=j(t,i),r=[l,S(t,l.visualElement,i),a.maskOccludee(n),a.trackGraphicState(i)];return{visualElement:l.visualElement,remove:()=>e(r).remove()}}function j(a,n){const{view:i,graphic:r}=a,o=new y({view:i,geometry:L(r)?r.geometry:null,elevationInfo:c(r),attached:!1});g.visualElements.lineGraphics.shadowStyle.apply(o);const s=()=>{o.attached=n.displaying};g.visualElements.lineGraphics.outline.apply(o);const p=[l((()=>n.displaying),s),l((()=>n.isDraped),(e=>{o.isDraped=e})),n.on("changed",(()=>o.geometry=L(r)?r.geometry:null)),t(o)];return s(),{visualElement:o,remove:()=>e(p).remove()}}function S(i,r,o){const{graphic:s,view:p}=i,m=[],d=c(s),y="on-the-ground"===d.mode||!d.offset&&"absolute-height"!==d.mode,E=new u,b=new f({view:p,extensionType:g.visualElements.zVerticalLine.extensionType,innerWidth:1,attached:!1,writeDepthEnabled:!1,renderOccluded:w.OccludeAndTransparent});g.visualElements.pointGraphics.shadowStyle.apply(b);const j=n(g.visualElements.heightPlaneAngleCutoff),S=new v({view:p,attached:!1,angleCutoff:j});g.visualElements.heightPlane.apply(S);let T=1,A=1;const D=()=>{if(E.update(i),!o.displaying||y&&(o.isDraped||!L(s)||!s.geometry.hasZ))return r.laserlineEnabled=!1,b.attached=!1,void(S.attached=!1);r.laserlineEnabled=!0;const e=E.grabbingState&h.XY?g.visualElements.laserlineAlphaMultiplier:1;e!==T&&(T=e,g.visualElements.lineGraphics.shadowStyle.apply(r,e),g.visualElements.pointGraphics.shadowStyle.apply(b,e));const t=E.grabbingState&h.Z?g.visualElements.laserlineAlphaMultiplier:1;t!==A&&(A=t,g.visualElements.heightPlane.apply(S,t)),M(b,E),G(i,r,S,E)};g.visualElements.zVerticalLine.apply(b),m.push(o.on("changed",D),l((()=>o.displaying),D),r.events.on("attachment-origin-changed",D),t(b),t(S));const C=[],O=()=>{e(C).remove(),C.length=0,i.forEachManipulator((e=>C.push(e.events.on("grab-changed",D)))),i.forEachManipulator((e=>C.push(e.events.on("select-changed",D)))),D()};return O(),m.push(i.onManipulatorsChanged(O),a((()=>e(C)))),e(m)}function M(e,t){const a=1===t.numSelected?t.firstSelected:t.numSelected>1&&i(t.firstGrabbedXY)?t.firstGrabbedXY:null;i(a)?(e.setStartEndFromWorldDownAtLocation(a.renderLocation),e.attached=!0):e.attached=!1}function G(e,t,a,n){if(n.numSelected>0){r(T,0,0,0);let t=0;e.forEachManipulator(((e,a)=>{a===d.TRANSLATE_XY&&e.selected&&e instanceof m&&(o(T,T,e.renderLocation),t++)})),t>0?(a.heightManifoldTarget=s(T,T,1/t),a.attached=!0):a.attached=!1}else{const n=t.attachmentOrigin;i(n)&&e.view.renderCoordsHelper.toRenderCoords(n,T)?(a.heightManifoldTarget=T,a.attached=!0):a.attached=!1}}function L(e){return i(e.geometry)&&("polygon"===e.geometry.type||"polyline"===e.geometry.type)}const T=p();export{b as createVisualElements};