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