UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 11.7 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/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{g as d,c as u,q as p,l as f,i as g,a as h,d as v,h as y,e as w}from"../../../../chunks/vec32.js";import{fromValues as S,create as j,ZEROS as b}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as x}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,computeOffsetForPoint as z,computeSegmentForMeasureType as A,computeOffsetAxis as _,dimensionStartToEnd as D,headingFromGeometry as F,computeGeometryFromDimension as L,computationToGeometryDependencies as k,directUp as E,directStartToEnd as G}from"./lengthDimensionUtils.js";import{getTransparentAccentColor as I,pointRadius as B,lengthFraction as N,minLengthMeters as V,linePaddingPx as W,focusedLinePaddingPx as q,orientationFocusMultiplier as J,orientationDiscScale as K,orientationCalloutWidth as Q,markerLineSizeFraction as X,orientationCalloutOffsetPx as Y,orientationSnapThresholdDegrees as Z}from"./settings.js";import{Manipulator3D as $}from"../../interactive/Manipulator3D.js";import{createManipulatorMaterial as ee,worldScaledManipulatorSettings as te,calculateTranslateRotateFromBases as re,rotateManipulatorDefaults as ne,calculateInputRotationTransform as ie}from"../../interactive/manipulatorUtils.js";import{RenderObject as oe}from"../../interactive/RenderObject.js";import{hideManipulatorWhileDragging as ae,screenToMap3D as se,screenToRenderPlane 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{RibbonLineMaterial as ve}from"../../webgl-engine/materials/RibbonLineMaterial.js";import{createManipulatorDragEventPipeline as ye,resetProperties as we,EventPipeline as Se}from"../../../interactive/dragEventPipeline.js";import{ManipulatorStateCustomFlags as je,ManipulatorStateFlags as be}from"../../../interactive/interfaces.js";class xe{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 He extends ${constructor(t,r){const n=ee(e.toUnitRGBA(I(t.effectiveTheme))),i=[new oe(pe(n,1,32,32),et)];super({view:t,renderObjects:i,metadata:r.metadata,available:!1,grabCursor:"crosshair",radius:B,collisionPriority:1}),this._themeHandle=o((()=>({color:e.toUnitRGBA(I(t.effectiveTheme))})),(e=>n.setParameters(e)))}destroy(){this._themeHandle.remove(),super.destroy()}}function Me(e,t){const r=[S(-.5,0,0),S(.5,0,0)],n=fe(t.unfocusedMaterial,r.map((e=>d(j(),e,N)))),i=n.instantiate({material:t.focusedMaterial});return new $({view:e,renderObjects:[new oe(n,be.Unfocused|be.Selected|et),new oe(i,be.Focused|et)],collisionType:{type:"line",paths:[r]},radius:Ze(t.lineSizePt)/2,metadata:t.metadata,available:!1,...te})}class Pe extends ${constructor(t,{lineSizePt:r,material:n,metadata:i}){super({view:t,autoScaleRenderObjects:!1,collisionPriority:1,metadata:i}),this._options={calloutColor:x(),lineSizePt:r,material:n},this._themeHandle=o((()=>e.toUnitRGBA(I(t.effectiveTheme))),(e=>{this._options.calloutColor=e,$e(this,Ce({...this._options,metadata:this.metadata}))}),a)}update({lineSizePt:e,material:t}){this._options.lineSizePt=e,this._options.material=t,$e(this,Ce({...this._options,metadata:this.metadata}))}destroy(){this._themeHandle.remove(),super.destroy()}}function Ce({calloutColor:e,lineSizePt:t,material:r,metadata:n}){return{calloutLength:.25*me*X*s(t)+Y,calloutColor:e,calloutWidth:Q,customStateMask:et,discScale:K,focusMultiplier:J,material:r,metadata:n}}function Te(e,t){const r=[S(-.5,0,0),S(.5,0,0)],n=fe(t.thinOffsetManipulatorMaterial,r),i=fe(t.unfocusedMaterial,r.map((e=>d(j(),e,N)))),o=i.instantiate({material:t.focusedMaterial});return new $({view:e,renderObjects:[new oe(i,be.Unfocused|et),new oe(o,be.Focused|et),new oe(n,et)],collisionType:{type:"line",paths:[r]},radius:Ze(t.lineSizePt)/2,available:!1,metadata:t.metadata,...te})}function Oe(e,{isStart:t,createSnappingPipelineStep:r,dimension:n,onUpdate:i,view:o}){const a=t?"startPoint":"endPoint",s=ye(e,((e,t,s,c)=>{const l=ae(e),{snappingStep:m,cancelSnapping:d}=r(c);s=s.next(l).next(we(n,[a,"measureType","orientation"])).next(d),t.next(l).next(se(o)).next(...m).next((e=>{const t=U(e.mapEnd,new H);i("startPoint"===a?{startPoint:t}:{endPoint:t})}))}));return[s]}function Ue(e,{computation:t,view:r}){return[ye(e,((e,n,i)=>{if(!R(t)||!e.selected)return;const{geometry:o,dimension:a}=t,s=ae(e);n.next(s).next(Le(r,a,o.dimensionSegment,o.primaryOffsetAxis)),i.next(s).next(we(a,["offset"]))}))]}function Re(e,{computation:t,view:r}){return[ye(e,((e,n,i)=>{_e({cancel:i,computation:t,settingHeading:!0,steps:n,view:r})}))]}function ze(e,{computation:t,view:r}){return[ye(e,((e,n,i)=>{_e({cancel:i,computation:t,settingHeading:!1,steps:n,view:r})})),e.events.on("immediate-click",(e=>{Ae(e,t,r)}))]}function Ae(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=L({...k(t),orientation:90},a),c=L({...k(t),orientation:270},a);if(null==s||null==c)return;const l=F(s,a),m=F(c,a),d=ke(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=j(),d=qe(j(),l,l.directSegment,s),p=Je(O.get(),{forHeading:n,geometry:l,renderCoordsHelper:s}),f=M(d,p,P()),g=n?c.orientation??F(l,a.renderCoordsHelper):c.orientation??0;o.next(ce(a,f)).next((e=>{"start"===e.action&&u(m,e.renderStart);const t=T(f),r=ie(m,e.renderEnd,d,t);let o=g-i(r);n||(o=De(o)),c.orientation=o})),t.next(we(c,["orientation"]))}function De(e){const t=n.normalize(e)%90;return t<Z?e-t:90-t<Z?e+(90-t):e}function Fe(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=z(m,n,l,i.renderCoordsHelper),c.orientation=0})),ye(e,((e,r,c)=>{if(!R(t))return;const{geometry:l,dimension:m}=t,{renderCoordsHelper:d}=i,u=A(it,n,t,d),p=_(O.get(),{measureType:n,directSegment:l.directSegment,renderCoordsHelper:d}),f=ae(e);r.next(f).next(Le(i,m,u,p)),c.next(f).next((e=>(m.measureType=o,m.offset=a,m.orientation=s,e)))}))]}function Le(e,t,r,n){const i=v(O.get(),r.endRenderSpace,r.startRenderSpace);y(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 Se;return m.next(ce(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 ke(e,t){const{directSegment:r}=e,{renderCoordsHelper:n}=t,i=E(O.get(),e,n),o=G(O.get(),e),a=y(O.get(),o,i),{viewForward:s}=t.state.camera;w(a,s)>0&&d(a,a,-1);const c=r.eval(.5,O.get());return n.headingAtPosition(c,a)}function Ee(e,t,r){const{dimensionSegment:n,primaryOffsetAxis:i}=t,o=D(tt,t),a=p(o,b)?c(nt):re(o,i,b,nt),s=Math.max(f(o),V/r.unitInMeters);l(a,a,g(tt,s,s,s)),e.modelTransform=a,e.renderLocation=n.eval(.5,tt)}function Ge(e,t,r){Be(e,t,r,{forHeading:!0})}function Ie(e,t,r){Be(e,t,r,{forHeading:!1})}function Be(e,t,r,{forHeading:n}){const{dimension:i,geometry:o}=t,{primaryOffsetAxis:a}=o,s=d(Ne,a,i.offset>=0?1:-1),c=Je(Ve,{forHeading:n,geometry:o,renderCoordsHelper:r});y(c,c,s);const l=re(s,c,b,nt);e.modelTransform=l,e.renderLocation=qe(tt,o,o.dimensionSegment,r)}const Ne=j(),Ve=j();function We(e,t,r,n){const{geometry:i}=t,o=A(it,r,t,n),a=_(tt,{measureType:r,directSegment:i.directSegment,renderCoordsHelper:n}),s=h(rt,o.endRenderSpace,o.startRenderSpace),c=re(s,a,b,nt),m=f(s);l(c,c,g(rt,m,m,m)),e.modelTransform=c,e.renderLocation=o.eval(.5,rt)}function qe(e,t,r,n){const{startRenderSpace:i,endRenderSpace:o}=r,a=Ke(t,n)?i:o;return u(e,a)}function Je(e,{forHeading:t,geometry:r,renderCoordsHelper:n}){return t?E(e,r,n):D(e,r,{invert:!0})}function Ke(e,t){const r=G(Qe,e),n=E(Xe,e,t);return w(r,n)>0}const Qe=j(),Xe=j();function Ye(e){return s(e)+W}function Ze(e){return s(e)+q}function $e(e,t){const r=t.material,n=t.focusMultiplier??ne.focusMultiplier,i=t.calloutLength??ne.calloutLength,o=ne.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??ne.calloutWidth,l=new ve({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??je.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 et=je.Custom1,tt=j(),rt=j(),nt=m(),it=new le;export{et as DidPointerMoveRecentlyFlag,xe as LengthDimensionManipulators,He as LengthDimensionPointManipulator,Pe as LineOfSightOrientationManipulator,ke as automaticHeadingFromCamera,Te as createMeasureTypeManipulator,Me as createOffsetManipulator,Ze as focusedOffsetWidth,Re as headingManipulatorHandles,Fe as measureTypeManipulatorHandles,Ue as offsetManipulatorHandles,Oe as pointManipulatorHandles,ze as rotationManipulatorHandles,De as snapOrientationToNearestRightAngle,Ye as unfocusedOffsetWidth,Ge as updateHeadingManipulatorTransform,We as updateMeasureTypeManipulatorTransform,Ee as updateOffsetManipulatorTransform,Ie as updateRotationManipulatorTransform};