UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 1.91 kB
import{unwrap as e}from"../../../core/maybe.js";import{absoluteHeightElevationInfo as t}from"../../../support/elevationInfoUtils.js";import{SnappingAlgorithm as s}from"./SnappingAlgorithm.js";import{anyMapPointToSnappingPoint as r,asSnappingPoint as i}from"./SnappingPoint.js";import{editEdgeToSnappingEdge as o,squaredScreenDistance as n}from"./snappingUtils.js";import{LineSnappingCandidate as d}from"./candidates/LineSnappingCandidate.js";import{vectorToScreenPoint as p}from"../support/viewUtils.js";import{projectPointToLineLike as a}from"../../support/geometry3dUtils.js";import{LineType as h}from"../../support/geometry2dUtils.js";class l extends s{snapNewVertex(e,s){const r=s.editGeometryOperations.data.components[0],i=r.edges.length,n=[];if(i<1)return n;const{spatialReference:d}=s,a=p(e,d,t,this.view),{view:h}=this,l=r.edges[i-1];let g=l;do{if(this.edgeExceedsShortLineThreshold(g,s)){const t=o(g,h,s);this._processCandidateProposal(t.left,t.right,e,a,s,n)}g=g.leftVertex.leftEdge}while(g&&g!==l);return n}snapExistingVertex(s,i){const n=[],d=e(i.vertexHandle),a=d.component;if(a.edges.length<2)return n;const{view:h}=this,{spatialReference:l}=i,g=p(s,l,t,h),m=d.leftEdge,f=d.rightEdge;m&&f&&this.edgeExceedsShortLineThreshold(m,i)&&this.edgeExceedsShortLineThreshold(f,i)&&this._processCandidateProposal(r(m.leftVertex.pos,h,i),r(f.rightVertex.pos,h,i),s,g,i,n);const c=a.edges[0];let x=c;do{if(x!==d.leftEdge&&x!==d.rightEdge&&this.edgeExceedsShortLineThreshold(x,i)){const e=o(x,h,i);this._processCandidateProposal(e.left,e.right,s,g,i,n)}x=x.rightVertex.rightEdge}while(x&&x!==c);return n}_processCandidateProposal(e,s,r,o,l,g){const{spatialReference:m,pointer:f}=l,c=i(a(r,{start:e,end:s,type:h.LINE}));n(o,p(c,m,t,this.view))<this.squaredProximityThreshold(f)&&g.push(new d({lineStart:e,lineEnd:s,targetPoint:c,isDraped:"on-the-ground"===l.elevationInfo?.mode}))}}export{l as LineSnapper};