UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 9.48 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__addDisposableResource as e,__disposeResources as t}from"tslib";import{a as n,G as s,h as o,t as r,d as i,g as a}from"./Geometry.js";import{m as c,a as m,c as l}from"./SideCalculator2D-BNwb5gvz.js";import{P as u,b as g,S as f,s as y}from"./MultiPathImpl.js";import{P as S,d,c as N,m as x}from"./Point2D.js";import{P as h,f as p}from"./Envelope.js";import{G as A}from"./GeometryCursor.js";import{O as C,j as P,_ as w,W as E,ah as _,ai as j,aj as T,a1 as G,U as I,ak as D,al as v,am as R,R as b,S as U,an as q,ao as k}from"./SpatialReference.js";import{O as B}from"./OperatorShapePreservingDensify.js";class F{getOperatorType(){return 10501}supportsCurves(){return!0}accelerateGeometry(e,t,n){return!1}canAccelerateGeometry(e){return!1}getNearestCoordinate(e,t,y,d,N,x){if(t.isNAN()&&n("NAN xy coordinates are not allowed"),e.isEmpty())return c();if(Number.isNaN(d)&&(d=0),d>=0||n("maxDeviationMeters"),0===e.getDimension())return this.getNearestVertex(e,t,y);const A=e.getGeometryType();if(A===s.enumGeometryCollection){const n=e;let s=c();for(let e=0,o=n.getGeometryCount();e<o;++e){const o=n.getGeometry(e),r=this.getNearestCoordinate(o,t,y,d,N,x);if(!r.isEmpty()){if(0===r.m_distance)return r;r.m_distance>=s.m_distance||(s=r,s.m_geometryIndex=e)}}return s}if(A===s.enumEnvelope){const n=new u;return n.addEnvelope(e,!1),this.getNearestCoordinate(n,t,y,d,N,x)}o(A)||r("Operation is not implemented for this geometry type");const D=e;if((N||x)&&A===s.enumPolygon){const n=()=>{const e=m(t,-1,0);return e.m_bRightSide=!0,e};if(y.isPannable()){const s=(new C).foldInto360Range(new h(t),y);if(s.isEmpty())return c();const o=(new C).foldInto360Range(e,y);if(o.isEmpty())return c();if((new P).execute(o,s,y,null)&&N)return n()}else{const e=(new C).clipToSpatialReference(new h(t),y,null,1);if(e.isEmpty())return c();const s=w(D,y,0,null);if(s.isEmpty())return c();if((new P).execute(s,e,y,null)&&N)return n()}}const v=y!==y.getGCS()?y.getSRToGCSTransform():null,R=new S;if(v?(new C).transform(v,[t],1,[R],!1):R.assign(t),R.isNAN())return c();const b=V(D,t,y,1);let U=b.m_distance;if(0===U)return b;Number.isNaN(U)?U=Number.POSITIVE_INFINITY:U*=1+1e-7;const q=y.getGCS(),k=q.getUnit().getUnitToBaseFactor(),F=R.clone();F.scale(k);const O=I();y.querySpheroidData(O);const M=E(O.majorSemiAxis,O.e2,F),L=_(O.majorSemiAxis,O.e2),z=new X(D.querySegmentIterator());0===d&&(d=.01);const W=O.majorSemiAxis*g(45),H=(new B).executeMany(z,y,W,d,0,null),J=[];let K=-1;const Q=new p,Z=new f;for(let n=H.next();null!==n;n=H.next()){if(n.isEmpty())continue;const t=H.getGeometryID(),s=e.getPathIndexFromPointIndex(t);e.isClosedPath(s)&&D.getPathEnd(s);const o=n;for(let e=0,n=o.getPathCount();e<n;++e){J.length=0;for(let t=o.getPathStart(e),r=o.getPathEnd(e);t<r;++t)J.push(o.getXY(t));if(v&&(new C).transform(v,J,J.length,J,!1),J.length>3){const e=Y(J,J.length,R,q,1);if(e.m_distance<U){U=e.m_distance,Q.assign(E(O.majorSemiAxis,O.e2,e.m_coordinate.mul(k))),K=t;let n=e.m_vertexIndex;n+1===J.length&&(n-=1),o.getSegmentBuffer(n,Z,!0)}}J.forEach(e=>e.mulThis(k));const n=E(O.majorSemiAxis,O.e2,J[0]),s=new p;for(let e=1,r=J.length;e<r;++e){const r=E(O.majorSemiAxis,O.e2,J[e]);if(j(L,M,n,r,s)<U){const{second:s}=T(O.majorSemiAxis,O.e2,M,n,r,2,null);if(s<=U){const s=new p,{second:i}=T(O.majorSemiAxis,O.e2,M,n,r,0,s);i<U&&(U=i,Q.assign(s),K=t,o.getSegmentBuffer(e-1,Z,!0))}}n.assign(r)}}}if(!Number.isFinite(U))return c();-1===K&&n("");const $=G(O.majorSemiAxis,O.e2,Q);$.divThis(k);const ee=$.clone(),te=y!==y.getGCS()?y.getGCSToSRTransform():null;te&&(new C).transform(te,[$],1,[ee],!1),ee.isNAN()&&i("closestPoint2DSr.isNAN()"),a(!Z.empty());const ne=Z.get().getClosestCoordinate(ee,!1);ee.assign(Z.get().getCoord2D(ne)),v?(new C).transform(v,[ee],1,[$],!1):$.assign(ee),a(!$.isNAN());const se=this.getNearestVertex(new h($),R,y.getGCS()),oe=m(ee,K,se.m_distance);if(x&&e.getDimension()>0){const n=l(e,t,-1,-1),s=0!==n&&3!==n;oe.m_bRightSide=s}return oe}getNearestVertex(e,t,o){if(t.isNAN()&&n("NAN xy coordinates are not allowed"),e.isEmpty())return c();switch(e.getGeometryType()){case s.enumPoint:return O(e,t,o);case s.enumMultiPoint:case s.enumPolyline:case s.enumPolygon:return V(e,t,o);default:r("")}}getNearestVertexPoint2D(e,t,n,s){return Y(e,t,n,s)}getNearestVertices(e,t,o,i,a){if(t.isNAN()&&n("NAN xy coordinates are not allowed"),e.isEmpty())return[];switch(e.getGeometryType()){case s.enumPoint:{const n=O(e,t,o);if(!n.isEmpty()&&n.m_distance<i&&a>=1){const e=[];return e.push(n),e}return[]}case s.enumMultiPoint:case s.enumPolyline:case s.enumPolygon:return M(e,t,o,i,a);default:r("")}}}function O(s,o,r){const i={stack:[],error:void 0,hasError:!1};try{if(0===r.getCoordinateSystemType()&&n("Cannot use local SR"),1!==r.getCoordinateSystemType()){const e=new Array(2);e[0]=s.getXY(),e[1]=o.clone();const t=x(S,2);2!==q(r,e,2,t)&&n("Point cannot be projected to GCS");const i=r.getGCS(),a=O(new h(t[0]),t[1],i);return m(a.m_coordinate,0,a.m_distance)}const t=r.getUnit().getUnitToBaseFactor(),a=s.getXY();a.scale(t);const c=o.clone();c.scale(t);const l=I();r.querySpheroidData(l);const u=e(i,new b,!1);U.geodeticDistance(l.majorSemiAxis,l.e2,a.x,a.y,c.x,c.y,u,null,null,k.PE_LINETYPE_GEODESIC);const g=s.getXY();return m(g,0,u.val)}catch(a){i.error=a,i.hasError=!0}finally{t(i)}}function V(s,o,r,i=0){0===r.getCoordinateSystemType()&&n("Cannot use local SR");let a=s.getAttributeStreamRef(0),c=s.getPointCount();const l=r.getGCS(),u=o.clone();if(1!==r.getCoordinateSystemType()){const e=r.getSRToGCSTransform();if(D(e,[o],1,[u],null),u.isNAN())return m(S.getNAN(),-1,Number.NaN);const t=(new C).execute(s,e,null);a=t.getAttributeStreamRef(0),c=t.getPointCount()}const g=l.getUnit().getUnitToBaseFactor(),f=d(c,0);for(let e=0;e<c;++e)f[e]=e;y(c,f);const x=I();l.querySpheroidData(x);const h=u.clone();h.scale(g);const A=E(x.majorSemiAxis,x.e2,h);let P=-1,w=Number.MAX_VALUE;const _=v(x.majorSemiAxis,x.e2);let j=c;const T=new S,G=new S;for(let e=0;e<j;){if(a.queryPoint2D(2*f[e],T),T.isNAN())continue;G.assign(T),G.scale(g);const t=E(x.majorSemiAxis,x.e2,G);if(p.distance(t,A)>w){f[j-1]=N(f[e],f[e]=f[j-1]),j--;continue}const n=R(_,t,A);n<w&&(P=f[e],w=n),e++}if(0!==x.e2){const n={stack:[],error:void 0,hasError:!1};try{const t=e(n,new b,!1);for(let e=0;e<j;e++){if(a.queryPoint2D(2*f[e],T),T.isNAN())continue;G.assign(T),G.scale(g);const n=E(x.majorSemiAxis,x.e2,G);p.distance(n,A)>w||(U.geodeticDistance(x.majorSemiAxis,x.e2,h.x,h.y,G.x,G.y,t,null,null,i),t.val<w&&(P=f[e],w=t.val))}}catch(k){n.error=k,n.hasError=!0}finally{t(n)}}const q=new S;return-1!==P&&q.assign(s.getXY(P)),m(q,P,w)}function Y(s,o,r,i,a=0){0===i.getCoordinateSystemType()&&n("Cannot use local SR");const l=i.getGCS(),u=r.clone();if(1!==i.getCoordinateSystemType()){const e=i.getSRToGCSTransform();if(D(e,[r],1,[u],null),u.isNAN())return c();const t=x(S,o);D(e,s,o,t,null);const n=Y(t,o,r,l,a);return n.isEmpty()?n:m(s[n.m_vertexIndex],n.m_vertexIndex,n.m_distance)}const g=l.getUnit().getUnitToBaseFactor(),f=d(o,0);for(let e=0;e<o;++e)f[e]=e;y(o,f);const h=I();l.querySpheroidData(h);const A=u.clone();A.scale(g);const C=E(h.majorSemiAxis,h.e2,A);let P=-1,w=Number.MAX_VALUE;const _=v(h.majorSemiAxis,h.e2);let j=o;for(let e=0;e<j;){const t=s[f[e]];if(t.isNAN())continue;const n=t.clone();n.scale(g);const o=E(h.majorSemiAxis,h.e2,n);if(p.distance(o,C)>w){f[j-1]=N(f[e],f[e]=f[j-1]),j--;continue}const r=R(_,o,C);r<w&&(P=f[e],w=r),e++}if(0!==h.e2){const n={stack:[],error:void 0,hasError:!1};try{const t=e(n,new b,!1);for(let e=0;e<j;e++){const n=s[f[e]];if(n.isNAN())continue;const o=n.clone();o.scale(g);const r=E(h.majorSemiAxis,h.e2,o);p.distance(r,C)>w||(U.geodeticDistance(h.majorSemiAxis,h.e2,A.x,A.y,o.x,o.y,t,null,null,a),t.val<w&&(P=f[e],w=t.val))}}catch(G){n.error=G,n.hasError=!0}finally{t(n)}}const T=new S;return-1!==P&&T.assign(s[P]),m(T,P,w)}function M(s,o,r,i,a){const c={stack:[],error:void 0,hasError:!1};try{0===r.getCoordinateSystemType()&&n("Cannot use local SR");let t=s.getAttributeStreamRef(0),l=s.getPointCount();const u=r.getGCS(),g=o.clone();if(1!==r.getCoordinateSystemType()){const e=r.getSRToGCSTransform();if(D(e,[o],1,[g],null),g.isNAN())return[];const n=(new C).execute(s,e,null);t=n.getAttributeStreamRef(0),l=n.getPointCount()}const f=u.getUnit().getUnitToBaseFactor(),x=d(l,0);for(let e=0;e<l;++e)x[e]=e;y(l,x);const h=I();u.querySpheroidData(h);const A=g.clone();A.scale(f);const P=E(h.majorSemiAxis,h.e2,A),w=[];let _=l;const j=new S,T=new S;for(let e=0;e<_;){if(t.queryPoint2D(2*x[e],j),j.isNAN())continue;T.assign(j),T.scale(f);const n=E(h.majorSemiAxis,h.e2,T);p.distance(n,P)>i?(x[_-1]=N(x[e],x[e]=x[_-1]),_--):e++}const G=(e,t)=>e.m_distance-t.m_distance,v=e(c,new b,!1);for(let e=0;e<_;e++)t.queryPoint2D(2*x[e],j),j.isNAN()||(U.geodeticDistance(h.majorSemiAxis,h.e2,A.x,A.y,j.x*f,j.y*f,v,null,null,k.PE_LINETYPE_GEODESIC),v.val<i&&w.push(m(j,x[e],v.val)));return w.sort(G),w.slice(0,a)}catch(l){c.error=l,c.hasError=!0}finally{t(c)}}class X extends A{constructor(e){super(),this.m_first=!0,this.m_segIter=e,this.m_segIter.stripAttributes()}tock(){return!0}getRank(){return 1}next(){if(this.m_first){if(!this.m_segIter.nextPath())return null;this.m_first=!1}for(;;){if(this.m_segIter.hasNextSegment())return this.m_segIter.nextSegment().clone();if(!this.m_segIter.nextPath())break}return null}getGeometryID(){return this.m_segIter.getStartPointIndex()}}export{F as OperatorProximityGeodesic};