UNPKG

@arcgis/core

Version:

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

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