@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 11.9 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import e from"../../../../Color.js";import{lengthDimensionMeasureType as t,LengthDimensionMeasureType as r}from"../../../../analysis/dimensionUtils.js";import{cyclicalDegrees as n}from"../../../../core/Cyclical.js";import{rad2deg as i}from"../../../../core/mathUtils.js";import{watch as o,initial as a}from"../../../../core/reactiveUtils.js";import{pt2px as s}from"../../../../core/screenUtils.js";import{identity as c,scale as l}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as m}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{h as d,c as u,d as p,e as f,f as g,p as h,l as v,i as y,a as w}from"../../../../chunks/vec32.js";import{create as S,ZEROS as j,fromValues as x}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as b}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import H from"../../../../geometry/Point.js";import{fromPositionAndNormal as M,create as P,signedDistance as C,getNormal as T}from"../../../../geometry/support/plane.js";import{sv3d as O}from"../../../../geometry/support/vectorStacks.js";import{clonePoint as U}from"../../../../layers/graphics/hydratedFeatures.js";import{isValidComputation as R,computeGeometryFromDimension as z,computationToGeometryDependencies as A,headingFromGeometry as D,computeOffsetForPoint as _,computeSegmentForMeasureType as F,computeOffsetAxis as L,directUp as k,directStartToEnd as E,dimensionStartToEnd as I}from"./lengthDimensionUtils.js";import{getTransparentAccentColor as G,pointRadius as B,lengthFraction as N,markerLineSizeFraction as V,orientationCalloutOffsetPx as W,orientationCalloutWidth as q,orientationDiscScale as J,orientationFocusMultiplier as K,orientationSnapThresholdDegrees as Q,minLengthMeters as X,linePaddingPx as Y,focusedLinePaddingPx as Z}from"./settings.js";import{Manipulator3D as $}from"../../interactive/Manipulator3D.js";import{createManipulatorMaterial as ee,worldScaledManipulatorSettings as te,calculateInputRotationTransform as re,calculateTranslateRotateFromBases as ne,rotateManipulatorDefaults as ie}from"../../interactive/manipulatorUtils.js";import{RenderObject as oe}from"../../interactive/RenderObject.js";import{screenToMap3D as ae,screenToRenderPlane as se,hideManipulatorWhileDragging as ce}from"../../interactive/editingTools/dragEventPipeline3D.js";import{EuclideanSegment as le}from"../../interactive/visualElements/support/Segment.js";import{markerSizePerLineWidth as me}from"../../support/engineContent/marker.js";import{Attribute as de}from"../../webgl-engine/lib/Attribute.js";import{Geometry as ue}from"../../webgl-engine/lib/Geometry.js";import{createSphereGeometry as pe,createPolylineGeometry as fe}from"../../webgl-engine/lib/GeometryUtil.js";import{RenderOccludedFlag as ge}from"../../webgl-engine/lib/Material.js";import{VertexAttribute as he}from"../../webgl-engine/lib/VertexAttribute.js";import{ImageMaterial as ve}from"../../webgl-engine/materials/ImageMaterial.js";import{RibbonLineMaterial as ye}from"../../webgl-engine/materials/RibbonLineMaterial.js";import{createManipulatorDragEventPipeline as we,resetProperties as Se,EventPipeline as je}from"../../../interactive/dragEventPipeline.js";import{ManipulatorStateCustomFlags as xe,ManipulatorStateFlags as be}from"../../../interactive/interfaces.js";class He{constructor(e){this.start=e.start,this.end=e.end,this.offset=e.offset,this.heading=e.heading,this.rotation=e.rotation,this.direct=e.direct,this.horizontal=e.horizontal,this.vertical=e.vertical}manipulatorName(e){return Object.keys(this).find((t=>this.hasOwnProperty(t)&&e===this[t]))}values(){return[this.start,this.end,this.offset,this.heading,this.rotation,this.direct,this.horizontal,this.vertical]}forEachMeasureTypeManipulator(e){for(const r of t)e(this.manipulatorForMeasureType(r),r)}manipulatorForMeasureType(e){switch(e){case r.Direct:return this.direct;case r.Horizontal:return this.horizontal;case r.Vertical:return this.vertical}}}class Me extends ${constructor(t,r){const n=ee(e.toUnitRGBA(G(t.effectiveTheme))),i=[new oe(pe(n,1,32,32),tt)];super({view:t,renderObjects:i,metadata:r.metadata,available:!1,grabCursor:"crosshair",radius:B,collisionPriority:1}),this._themeHandle=o((()=>({color:e.toUnitRGBA(G(t.effectiveTheme))})),(e=>n.setParameters(e)))}destroy(){this._themeHandle.remove(),super.destroy()}}function Pe(e,t){const r=[x(-.5,0,0),x(.5,0,0)],n=fe(t.unfocusedMaterial,r.map((e=>d(S(),e,N)))),i=n.instantiate({material:t.focusedMaterial});return new $({view:e,renderObjects:[new oe(n,be.Unfocused|be.Selected|tt),new oe(i,be.Focused|tt)],collisionType:{type:"line",paths:[r]},radius:$e(t.lineSizePt)/2,metadata:t.metadata,available:!1,...te})}class Ce extends ${constructor(t,{lineSizePt:r,material:n,metadata:i}){super({view:t,autoScaleRenderObjects:!1,collisionPriority:1,metadata:i}),this._options={calloutColor:b(),lineSizePt:r,material:n},this._themeHandle=o((()=>e.toUnitRGBA(G(t.effectiveTheme))),(e=>{this._options.calloutColor=e,et(this,Te({...this._options,metadata:this.metadata}))}),a)}update({lineSizePt:e,material:t}){this._options.lineSizePt=e,this._options.material=t,et(this,Te({...this._options,metadata:this.metadata}))}destroy(){this._themeHandle.remove(),super.destroy()}}function Te({calloutColor:e,lineSizePt:t,material:r,metadata:n}){return{calloutLength:.25*me*V*s(t)+W,calloutColor:e,calloutWidth:q,customStateMask:tt,discScale:J,focusMultiplier:K,material:r,metadata:n}}function Oe(e,t){const r=[x(-.5,0,0),x(.5,0,0)],n=fe(t.thinOffsetManipulatorMaterial,r),i=fe(t.unfocusedMaterial,r.map((e=>d(S(),e,N)))),o=i.instantiate({material:t.focusedMaterial});return new $({view:e,renderObjects:[new oe(i,be.Unfocused|tt),new oe(o,be.Focused|tt),new oe(n,tt)],collisionType:{type:"line",paths:[r]},radius:$e(t.lineSizePt)/2,available:!1,metadata:t.metadata,...te})}function Ue(e,{isStart:t,createSnappingPipelineStep:r,dimension:n,onUpdate:i,view:o}){const a=t?"startPoint":"endPoint",s=we(e,((e,t,s,c)=>{const l=ce(e),{snappingStep:m,cancelSnapping:d}=r(c);s=s.next(l).next(Se(n,[a,"measureType","orientation"])).next(d),t.next(l).next(ae(o)).next(...m).next((e=>{const t=U(e.mapEnd,new H);i("startPoint"===a?{startPoint:t}:{endPoint:t})}))}));return[s]}function Re(e,{computation:t,view:r}){return[we(e,((e,n,i)=>{if(!R(t)||!e.selected)return;const{geometry:o,dimension:a}=t,s=ce(e);n.next(s).next(ke(r,a,o.dimensionSegment,o.primaryOffsetAxis)),i.next(s).next(Se(a,["offset"]))}))]}function ze(e,{computation:t,view:r}){return[we(e,((e,n,i)=>{_e({cancel:i,computation:t,settingHeading:!0,steps:n,view:r})}))]}function Ae(e,{computation:t,view:r}){return[we(e,((e,n,i)=>{_e({cancel:i,computation:t,settingHeading:!1,steps:n,view:r})})),e.events.on("immediate-click",(e=>{De(e,t,r)}))]}function De(e,t,r){const{dimension:i,geometry:o}=t;if(90===i.orientation||270===i.orientation)return i.orientation=0,void e.stopPropagation();if(null==o)return;const{renderCoordsHelper:a}=r,s=z({...A(t),orientation:90},a),c=z({...A(t),orientation:270},a);if(null==s||null==c)return;const l=D(s,a),m=D(c,a),d=Ee(o,r),u=n.shortestSignedDiff(d,l),p=n.shortestSignedDiff(d,m);i.orientation=Math.abs(u)<Math.abs(p)?90:270,e.stopPropagation()}function _e(e){const{cancel:t,computation:r,settingHeading:n,steps:o,view:a}=e;if(!R(r))return;const{renderCoordsHelper:s}=a,{dimension:c,geometry:l}=r,m=S(),d=Je(S(),l,l.directSegment,s),p=Ke(O.get(),{forHeading:n,geometry:l,renderCoordsHelper:s}),f=M(d,p,P()),g=n?c.orientation??D(l,a.renderCoordsHelper):c.orientation??0;o.next(se(a,f)).next((e=>{"start"===e.action&&u(m,e.renderStart);const t=T(f),r=re(m,e.renderEnd,d,t);let o=g-i(r);n||(o=Fe(o)),c.orientation=o})),t.next(Se(c,["orientation"]))}function Fe(e){const t=n.normalize(e)%90;return t<Q?e-t:90-t<Q?e+(90-t):e}function Le(e,{computation:t,manipulatorMeasureType:n,view:i}){let o=r.Direct,a=0,s=0;return[e.events.on("grab-changed",(r=>{if("start"!==r.action||!R(t))return;const{dimension:c,geometry:l}=t;o=c.measureType,a=c.offset,s=c.orientation;const m=u(O.get(),e.renderLocation);c.measureType=n,c.offset=_(m,n,l,i.renderCoordsHelper),c.orientation=0})),we(e,((e,r,c)=>{if(!R(t))return;const{geometry:l,dimension:m}=t,{renderCoordsHelper:d}=i,u=F(ot,n,t,d),p=L(O.get(),{measureType:n,directSegment:l.directSegment,renderCoordsHelper:d}),f=ce(e);r.next(f).next(ke(i,m,u,p)),c.next(f).next((e=>(m.measureType=o,m.offset=a,m.orientation=s,e)))}))]}function ke(e,t,r,n){const i=p(O.get(),r.endRenderSpace,r.startRenderSpace);f(i,i,n);const o=M(r.startRenderSpace,i,P()),a=M(r.startRenderSpace,n,P()),s=t.offset;let c,l=0;const m=new je;return m.next(se(e,o)).next((r=>{"start"===r.action&&(l=C(a,r.renderStart));const n=(C(a,r.renderEnd)-l)*e.renderCoordsHelper.unitInMeters;t.offset=s+n,c=r})),e=>(m.execute(e),c)}function Ee(e,t){const{directSegment:r}=e,{renderCoordsHelper:n}=t,i=k(O.get(),e,n),o=E(O.get(),e),a=f(O.get(),o,i),{viewForward:s}=t.state.camera;g(a,s)>0&&d(a,a,-1);const c=r.eval(.5,O.get());return n.headingAtPosition(c,a)}function Ie(e,t,r){const{dimensionSegment:n,primaryOffsetAxis:i}=t,o=I(rt,t),a=h(o,j)?c(it):ne(o,i,j,it),s=Math.max(v(o),X/r.unitInMeters);l(a,a,y(rt,s,s,s)),e.modelTransform=a,e.renderLocation=n.eval(.5,rt)}function Ge(e,t,r){Ne(e,t,r,{forHeading:!0})}function Be(e,t,r){Ne(e,t,r,{forHeading:!1})}function Ne(e,t,r,{forHeading:n}){const{dimension:i,geometry:o}=t,{primaryOffsetAxis:a}=o,s=d(Ve,a,i.offset>=0?1:-1),c=Ke(We,{forHeading:n,geometry:o,renderCoordsHelper:r});f(c,c,s);const l=ne(s,c,j,it);e.modelTransform=l,e.renderLocation=Je(rt,o,o.dimensionSegment,r)}const Ve=S(),We=S();function qe(e,t,r,n){const{geometry:i}=t,o=F(ot,r,t,n),a=L(rt,{measureType:r,directSegment:i.directSegment,renderCoordsHelper:n}),s=w(nt,o.endRenderSpace,o.startRenderSpace),c=ne(s,a,j,it),m=v(s);l(c,c,y(nt,m,m,m)),e.modelTransform=c,e.renderLocation=o.eval(.5,nt)}function Je(e,t,r,n){const{startRenderSpace:i,endRenderSpace:o}=r,a=Qe(t,n)?i:o;return u(e,a)}function Ke(e,{forHeading:t,geometry:r,renderCoordsHelper:n}){return t?k(e,r,n):I(e,r,{invert:!0})}function Qe(e,t){const r=E(Xe,e),n=k(Ye,e,t);return g(r,n)>0}const Xe=S(),Ye=S();function Ze(e){return s(e)+Y}function $e(e){return s(e)+Z}function et(e,t){const r=t.material??new ve({writeDepth:!1,textureId:t.texture?.id,renderOccluded:ge.Opaque,isDecoration:!0}),n=t.focusMultiplier??ie.focusMultiplier,i=t.calloutLength??ie.calloutLength,o=ie.discRadius*(t.discScale??1),a=o*n,s=(e,t)=>{const r=[0,1,2,2,3,0];return new ue(t,[[he.POSITION,new de([i-e,-e,0,i+e,-e,0,i+e,e,0,i-e,e,0],r,3,!0)],[he.UV0,new de([0,0,1,0,1,1,0,1],r,2,!0)]])},c=t.calloutWidth??ie.calloutWidth,l=new ye({width:c,color:t.calloutColor,renderOccluded:ge.OccludeAndTransparent,isDecoration:!0}),m=fe(l,[[0,0,0],[i-o,0,0]]),d=fe(l,[[0,0,0],[i-a,0,0]]),u=t.customStateMask??xe.None;e.collisionType={type:"disc",direction:[0,0,1],offset:[i,0,0]},e.focusMultiplier=n,e.metadata=t.metadata,e.radius=o,e.renderObjects=[new oe(s(o,r),be.Unfocused|u),new oe(m,be.Unfocused|u),new oe(s(a,r),be.Focused|u),new oe(d,be.Focused|u)]}const tt=xe.Custom1,rt=S(),nt=S(),it=m(),ot=new le;export{tt as DidPointerMoveRecentlyFlag,He as LengthDimensionManipulators,Me as LengthDimensionPointManipulator,Ce as LineOfSightOrientationManipulator,Ee as automaticHeadingFromCamera,Oe as createMeasureTypeManipulator,Pe as createOffsetManipulator,$e as focusedOffsetWidth,ze as headingManipulatorHandles,Le as measureTypeManipulatorHandles,Re as offsetManipulatorHandles,Ue as pointManipulatorHandles,Ae as rotationManipulatorHandles,Fe as snapOrientationToNearestRightAngle,Ze as unfocusedOffsetWidth,Ge as updateHeadingManipulatorTransform,qe as updateMeasureTypeManipulatorTransform,Ie as updateOffsetManipulatorTransform,Be as updateRotationManipulatorTransform};