@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.92 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{cyclicalPI as e,cyclical2PI as t}from"../../../core/Cyclical.js";import{valueInUnit as s,createAngle as r}from"../../../core/quantityUtils.js";import{create as i}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{absoluteHeightElevationInfo as o}from"../../../support/elevationInfoUtils.js";import{fromAnyMapPoint as n,markAsTarget as a,fromVec3 as d}from"../sketch/normalizedPoint.js";import{SnappingAlgorithm as l}from"./SnappingAlgorithm.js";import{editEdgeToSnappingEdge as p,squaredScreenDistance as h}from"./snappingUtils.js";import{LineSnappingCandidate as c}from"./candidates/LineSnappingCandidate.js";import{vectorToScreenPoint as g}from"../support/viewUtils.js";import{radiansGeographicBetweenVec as f,pointFromDistanceAlongAzimuth as m}from"../../support/angularMeasurementUtils.js";import{projectPointToLineLike as u}from"../../support/geometry3dUtils.js";import{LineType as x}from"../../support/geometry2dUtils.js";class E extends l{constructor(e,t,s){super(e,t),this._geodesicLengthMeasurementUtils=s}snapNewVertex(e,t){const s=t.editGeometryOperations.data.components[0],r=s.edges.length,i=[];if(r<1)return i;const{spatialReference:n}=t,a=g(e,n,o,this.view),{view:d}=this,l=s.edges[r-1];let h=l;do{if(this.edgeExceedsShortLineThreshold(h,t)){const s=p(h,d,t);this._processCandidateProposal(s.left,s.right,e,a,t,i)}h=h.leftVertex.leftEdge}while(h&&h!==l);return i}snapExistingVertex(e,t){const s=[],r=t.vertexHandle,i=r.component;if(i.edges.length<2)return s;const{view:a}=this,{spatialReference:d}=t,l=g(e,d,o,a),h=r.leftEdge,c=r.rightEdge;h&&c&&this.edgeExceedsShortLineThreshold(h,t)&&this.edgeExceedsShortLineThreshold(c,t)&&this._processCandidateProposal(n(h.leftVertex.pos,a,t),n(c.rightVertex.pos,a,t),e,l,t,s);const f=i.edges[0];let m=f;do{if(m!==r.leftEdge&&m!==r.rightEdge&&this.edgeExceedsShortLineThreshold(m,t)){const r=p(m,a,t);this._processCandidateProposal(r.left,r.right,e,l,t,s)}m=m.rightVertex.rightEdge}while(m&&m!==f);return s}_processCandidateProposal(e,t,s,r,n,l){const{spatialReference:p,pointer:f}=n,m=i();j(m,e,t,s,n,this._geodesicLengthMeasurementUtils);const u=a(d(m));h(r,g(u,p,o,this.view))<this.squaredProximityThreshold(f)&&l.push(new c({lineStart:e,lineEnd:t,targetPoint:u,isDraped:"on-the-ground"===n.elevationInfo?.mode}))}}function j(e,t,s,r,i,o){v(e,t,s,r,i,o)||w(e,r,t,s)}function v(i,o,n,a,{spatialReference:d},l){const p=f(o,n,d,d);if(null==p)return!1;const h=f(n,a,d,d);if(null==h)return!1;const c=l.geodesicDistance(n,a,d);if(null==c)return!1;const g=Math.abs(e.shortestSignedDiff(p,h))>Math.PI/2?t.normalize(p+Math.PI):p;return m(i,n,d,s(c,"meters"),r(g,"radians","geographic"),"geodesic"),i[2]=a[2],!0}function w(e,t,s,r){u(t,{start:s,end:r,type:x.LINE},e),e[2]=t[2]}export{E as LineSnapper};