UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.08 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{LengthDimensionMeasureType as e}from"../../../../analysis/dimensionUtils.js";import"../../../../core/has.js";import{q as t,g as n,e as i,d as o,k as r}from"../../../../chunks/vec32.js";import a from"../../../../geometry/Point.js";import{sv3d as s}from"../../../../geometry/support/vectorStacks.js";import{automaticHeadingFromCamera as l}from"./lengthDimensionManipulatorUtils.js";import{isGeodesicDimension as c,directUp as d,directStartToEnd as u}from"./lengthDimensionUtils.js";import{constraintThresholdPx as m}from"./settings.js";var P;function p(e,t){return{enabled:t.effectiveFeatureEnabled,elevationAlignedStartPoint:e.elevationAlignedStartPoint,elevationAlignedEndPoint:e.elevationAlignedEndPoint,geometry:e.geometry}}function f(e,a){if(c(e))return P.Direct;if(!e.enabled)return null;const{geometry:l}=e;if(null==l||t(l.directSegment.startRenderSpace,l.directSegment.endRenderSpace))return null;const{camera:p}=a.state,f=d(s.get(),l,a.renderCoordsHelper),g=u(s.get(),l),S=n(s.get(),f,i(g,f)),v=o(s.get(),g,S),y=r(v),A=r(S),{startRenderSpace:R,endRenderSpace:z}=l.directSegment,j=Math.max(p.computeScreenPixelSizeAt(R)*m,p.computeScreenPixelSizeAt(z)*m)**2;return y<j?P.Vertical:A<j?P.Horizontal:null}function g(e,t,{constraint:n,view:i}){const{unconstrainedGeometry:o}=e;if(null==o)return;const{renderCoordsHelper:r,spatialReference:s}=i,{startRenderSpace:l,endRenderSpace:c}=o.directSegment,d=r.fromRenderCoords(l,new a({spatialReference:s})),u=r.fromRenderCoords(c,new a({spatialReference:s}));let m;m="start"===t?{startPoint:d}:{endPoint:u},S(e,m,{constraint:n,elevationAlignedStartPoint:e.elevationAlignedStartPoint,elevationAlignedEndPoint:e.elevationAlignedEndPoint,unconstrainedGeometry:o,view:i})}function S(t,n,i){const{constraint:o,elevationAlignedStartPoint:r,elevationAlignedEndPoint:a,unconstrainedGeometry:s,view:c}=i,{dimension:d,previousConstraint:u,preConstraintProperties:m}=t;if(null==r||null==a)return;const p=()=>{"startPoint"in n?d.startPoint=n.startPoint:"endPoint"in n&&(d.endPoint=n.endPoint)};if(null==o)p(),null!=u&&null!=m&&(d.measureType=m.measureType,d.orientation=m.orientation);else switch(d.measureType=e.Direct,o){case P.Horizontal:if(o!==u&&(d.orientation=0),"startPoint"in n){const e=n.startPoint;null!=e&&(e.z=a.z),d.startPoint=e}else if("endPoint"in n){const e=n.endPoint;null!=e&&(e.z=r.z),d.endPoint=e}break;case P.Vertical:if(o!==u&&(d.orientation=l(s,c)),"startPoint"in n){const e=n.startPoint;null!=e&&(e.x=a.x,e.y=a.y),d.startPoint=e}else if("endPoint"in n){const e=n.endPoint;null!=e&&(e.x=r.x,e.y=r.y),d.endPoint=e}break;case P.Direct:o!==u&&null!=m&&(d.orientation=m.orientation),p()}t.previousConstraint=o,t.unconstrainedGeometry=s}!function(e){e[e.Horizontal=0]="Horizontal",e[e.Vertical=1]="Vertical",e[e.Direct=2]="Direct"}(P||(P={}));export{P as LengthDimensionConstraint,S as applyConstraint,f as computeConstraint,p as constraintDependencies,g as reapplyConstraint};