UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.74 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ 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 o,fromValues as n}from"../sketch/normalizedPoint.js";import{defaults as l}from"./Settings.js";import{SnappingAlgorithm as a}from"./SnappingAlgorithm.js";import{editEdgeToSnappingEdge as c,squaredScreenDistance as h}from"./snappingUtils.js";import{ParallelLineSnappingCandidate as d}from"./candidates/ParallelLineSnappingCandidate.js";import{vectorToScreenPoint as p}from"../support/viewUtils.js";import{projectPointToLine as g}from"../../support/geometry2dUtils.js";class f extends a{snapNewVertex(e,t){const s=t.editGeometryOperations.data.components[0],o=s.edges.length,n=s.vertices.length,l=[];if(o<2)return l;const{view:a}=this,h=p(e,t.spatialReference,r,a),d=i(s.vertices[n-1].pos,a,t),g=i(s.vertices[0].pos,a,t),f=s.edges[o-1];let m=f;do{if(this.edgeExceedsShortLineThreshold(m,t)){const r=c(m,a,t);this._checkEdgeForParallelLines(r,d,e,h,t,l),this._checkEdgeForParallelLines(r,g,e,h,t,l)}m=m.leftVertex.leftEdge}while(m&&m!==f);return l}snapExistingVertex(e,t){const s=[],o=t.vertexHandle,n=o.component;if(n.edges.length<3)return s;const{view:l}=this,a=p(e,t.spatialReference,r,l),h=o.leftEdge,d=o.rightEdge,g=n.vertices[0],f=i(g.pos,l,t),m=n.vertices.length,u=n.vertices[m-1],v=i(u.pos,l,t),x=n.edges[0];let E=x;do{if(E!==h&&E!==d&&this.edgeExceedsShortLineThreshold(E,t)){const r=c(E,l,t);h&&this._checkEdgeForParallelLines(r,i(h.leftVertex.pos,l,t),e,a,t,s),d&&this._checkEdgeForParallelLines(r,i(d.rightVertex.pos,l,t),e,a,t,s),o===g?this._checkEdgeForParallelLines(r,v,e,a,t,s):o===u&&this._checkEdgeForParallelLines(r,f,e,a,t,s)}E=E.rightVertex.rightEdge}while(E&&E!==x);return s}_checkEdgeForParallelLines(t,i,a,c,f,v){const x=t.left,E=t.right;if(g(u,s(i),s(x),s(E)),e(u,s(i))<l.parallelLineThreshold)return;g(u,s(a),s(x),s(E),s(i));const{spatialReference:L,pointer:P}=f,j=o(n(u[0],u[1],a[2]));if(h(c,p(j,L,r,this.view))<this.squaredProximityThreshold(P)){if(this.isVertical(j,i,f)||this.isVertical(x,E,f))return;if(m(t,v))return;v.push(new d({referenceLine:t,lineStart:i,targetPoint:j,isDraped:"on-the-ground"===f.elevationInfo?.mode}))}}}function m(t,r){const i=t.left,o=t.right;for(const n of r)if(g(u,s(o),s(n.constraint.start),s(n.constraint.end),s(i)),e(u,s(o))<l.parallelLineThreshold)return n.addReferenceLine(t),!0;return!1}const u=t();export{f as ParallelLineSnapper};