@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 2.78 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{squaredDistance as e}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{create as t}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{absoluteHeightElevationInfo as r}from"../../../support/elevationInfoUtils.js";import{fromAnyMapPoint as i,asVec2 as s,markAsTarget as n,fromValues as o}from"../sketch/normalizedPoint.js";import{defaults as l}from"./Settings.js";import{SnappingAlgorithm as a}from"./SnappingAlgorithm.js";import{isLine as c,editEdgeToSnappingEdge as h,squaredScreenDistance as p}from"./snappingUtils.js";import{ParallelLineSnappingCandidate as g}from"./candidates/ParallelLineSnappingCandidate.js";import{vectorToScreenPoint as f}from"../support/viewUtils.js";import{projectPointToLine as m}from"../../support/geometry2dUtils.js";class d extends a{snapNewVertex(e,t){const s=t.editGeometryOperations.data.parts.at(-1),n=[];if(!s)return n;const o=s.segments.length,l=s.vertices.length;if(o<2)return n;const{view:a}=this,p=f(e,t.spatialReference,r,a),g=s.vertices[0],m=s.vertices[l-1],d=c(m.leftSegment)?i(m.pos,a,t):null,u=c(g.rightSegment)?i(g.pos,a,t):null,v=s.segments[o-1];let x=v;do{if(c(x)&&this.edgeExceedsShortLineThreshold(x,t)){const r=h(x,a,t);d&&this._checkEdgeForParallelLines(r,d,e,p,t,n),u&&this._checkEdgeForParallelLines(r,u,e,p,t,n)}x=x.leftVertex.leftSegment}while(x&&x!==v);return n}snapExistingVertex(e,t){const s=[],n=t.vertexHandle,o=n.part;if(o.segments.length<3)return s;const{view:l}=this,a=f(e,t.spatialReference,r,l),p=n.leftSegment,g=n.rightSegment,m=o.vertices[0],d=i(m.pos,l,t),u=o.vertices.length,v=o.vertices[u-1],x=i(v.pos,l,t),L=o.segments[0];let S=L;do{if(c(S)&&S!==p&&S!==g&&this.edgeExceedsShortLineThreshold(S,t)){const r=h(S,l,t);c(p)&&this._checkEdgeForParallelLines(r,i(p.leftVertex.pos,l,t),e,a,t,s),c(g)&&this._checkEdgeForParallelLines(r,i(g.rightVertex.pos,l,t),e,a,t,s),n===m?this._checkEdgeForParallelLines(r,x,e,a,t,s):n===v&&this._checkEdgeForParallelLines(r,d,e,a,t,s)}S=S.rightVertex.rightSegment}while(S&&S!==L);return s}_checkEdgeForParallelLines(t,i,a,c,h,d){const x=t.left,L=t.right;if(m(v,s(i),s(x),s(L)),e(v,s(i))<l.parallelLineThreshold)return;m(v,s(a),s(x),s(L),s(i));const{spatialReference:S,pointer:P}=h,j=n(o(v[0],v[1],a[2]));if(p(c,f(j,S,r,this.view))<this.squaredProximityThreshold(P)){if(this.isVertical(j,i,h)||this.isVertical(x,L,h))return;if(u(t,d))return;d.push(new g({referenceLine:t,lineStart:i,targetPoint:j,isDraped:"on-the-ground"===h.elevationInfo?.mode}))}}}function u(t,r){const i=t.left,n=t.right;for(const o of r)if(m(v,s(n),s(o.constraint.start),s(o.constraint.end),s(i)),e(v,s(n))<l.parallelLineThreshold)return o.addReferenceLine(t),!0;return!1}const v=t();export{d as ParallelLineSnapper};