@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 6.82 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{segmentLength as e}from"../../../../../arcade/functions/measures.js";import{equals as t}from"../../../../../core/arrayUtils.js";import{fromArray as n}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getHeightUnitCorrectionFactor as s,interpolateM as r}from"../../../../geometry/coordUtils.js";import{segmentLength3d as a,distanceAlongLineSegmentWithZ as o,distanceAlongLineSegment as c}from"../../../../geometry/lineUtils.js";import i from"../../../../../geometry/Point.js";import f from"../../../../../geometry/Polyline.js";import{getLength as l}from"../../../../../geometry/support/coordsUtils.js";import{closestPointOnCurve as h}from"../../../../../geometry/support/curves/closestPointOnCurve.js";import{getPaths as p,getEndpoint as u,cloneCurve as m,isCoordinate as R,isCurvedGeometry as g}from"../../../../../geometry/support/curves/curveUtils.js";import{interpolate2D as y}from"../../../../../geometry/support/curves/interpolateCurve.js";function M(t){let n=0;const r=s(t.spatialReference);if(g(t)){const s=p(t);for(let a=0;a<s.length;a++){const o=s[a],c=o.length;for(let s=1;s<c;s++)n+=e(u(o[s-1]),o[s],t.hasZ,r)}return n}for(let e=0;e<t.paths.length;e++){const s=t.paths[e].length;for(let o=0;o<s;o++)o>0&&(n+=t.hasZ?a(t.paths[e][o-1],t.paths[e][o],r):l(t.paths[e][o-1],t.paths[e][o]))}return n}function Z(e){const t=e.geometry;return t.paths.map(n=>new f({spatialReference:e.geometry.spatialReference,paths:[n],hasZ:t.hasZ,hasM:t.hasM}))}function x(e){const t=[];for(const n of p(e))for(let s=1;s<n.length;s++){const r=[[u(n[s-1]).slice(),m(n[s])]];R(r[0][1])?t.push(new f({paths:r,spatialReference:e.spatialReference,hasZ:e.hasZ,hasM:e.hasM})):t.push(new f({curvePaths:r,spatialReference:e.spatialReference,hasZ:e.hasZ,hasM:e.hasM}))}return t}function w(e,t,n){const s=t[0],r=t[1],a=l(s,r),o=e.x+n*((t[1][0]-t[0][0])/a),c=e.y+n*((t[1][1]-t[0][1])/a),f={};return e.hasM&&(f.m=e.m),new i({x:o,y:c,spatialReference:e.spatialReference,...f})}function v(e,t,n,s){const r=t[0],o=t[1],c=a(r,o,s),f=e.x+n*((t[1][0]-t[0][0])/c),l=e.y+n*((t[1][1]-t[0][1])/c),h=e.z+n*((t[1][2]-t[0][2])/c),p={};return e.hasM&&(p.m=e.m),new i({x:f,y:l,z:h,spatialReference:e.spatialReference,...p})}function d(t,n,s,r,a){if(R(s))return j(t,[n,s],r);const o=h(n,s,[t.x,t.y]),c=e(n,s,!1,1),i=o.distance<c+a?o.distance+a:o.distance-a;return j(t,[n,y(n,s,i/c)],r)}function j(e,t,n){const s=t[0],r=t[1],a=[r[0]-s[0],r[1]-s[1]],o=Math.sqrt(a[0]**2+a[1]**2),c=[a[0]/o,a[1]/o];return e.x+=n*c[0],e.y+=n*c[1],e}function z(e,t,n,s){if(g(e))return P(e,t,n,s);if(t<=0){const s=[e.paths[0][0],e.paths[0][1]];let r=q(e,0,0);return r=w(r,s,t),j(r,s,n)}const a=e.hasM?e.hasZ?3:2:-1;let o=0,f=null;for(const R of e.paths)for(let s=0;s<R.length-1;s++){const h=l(R[s],R[s+1]),p=o+h;if(p===t)return f=new i({x:R[s+1][0],y:R[s+1][1],...e.hasM?{m:R[s+1][a]}:{},spatialReference:e.spatialReference}),0===n?f:j(f,[R[s],R[s+1]],n);if(p>t){const l=c(R[s],R[s+1],t-o);return f=new i({x:l[0],y:l[1],...a>-1?{m:r(R[s][a],R[s+1][a],h,t-o)??void 0}:{},spatialReference:e.spatialReference}),0===n?f:j(f,[R[s],R[s+1]],n)}o+=h}if(0===o)return null;const h=e.paths.length-1,p=e.paths[h].length-1,u=[e.paths[h][p-1],e.paths[h][p]];let m=q(e,h,p);return m=w(m,u,t-o),j(m,u,n)}function U(e,t,s,c,f){if(g(e))return C(e,t,s,c,f);if(t<=0){const n=[e.paths[0][0],e.paths[0][1]];let r=q(e,0,0);return r=v(r,n,t,c),j(r,n,s)}const l=e.hasM?e.hasZ?3:2:-1;let h=0;for(const g of e.paths)for(let f=0;f<g.length-1;f++){const p=a(g[f],g[f+1],c),u=h+p;if(u===t){const t=new i({x:g[f+1][0],y:g[f+1][1],z:g[f+1][2],...e.hasM?{m:g[f+1][l]}:{},hasZ:!0,spatialReference:e.spatialReference});return 0===s?t:j(t,[g[f],g[f+1]],s)}if(u>t){const a=o(n(g[f]),n(g[f+1]),t-h,c),u=new i({x:a[0],y:a[1],z:a[2],...l>-1?{m:r(g[f][l],g[f+1][l],p,t-h)}:{},hasZ:!0,spatialReference:e.spatialReference});return 0===s?u:j(u,[g[f],g[f+1]],s)}h+=p}if(0===h)return null;const p=e.paths.length-1,u=e.paths[p].length-1,m=[e.paths[p][u-1],e.paths[p][u]];let R=q(e,p,u);return R=v(R,m,t-h,c),j(R,m,s)}function P(t,n,s,a){const o=p(t);if(n<=0){let r=[u(o[0][0]),o[0][1]],c=q(t,0,0);if(R(r[1]))return c=w(c,r,n),j(c,r,s);const i=e(r[0],r[1],!1,1),f=y(r[0],r[1],a/i);return r=[r[0],f],c=w(c,r,n),j(c,r,s)}const c=t.hasM?t.hasZ?3:2:-1;let f=0,l=null;for(const p of o)for(let o=0;o<p.length-1;o++){const h=e(u(p[o]),p[o+1],!1,1),m=f+h;if(m===n){const e=u(p[o+1]);return l=new i({x:e[0],y:e[1],...t.hasM?{m:e[c]}:{},hasM:t.hasM,spatialReference:t.spatialReference}),0===s?l:d(l,u(p[o]),p[o+1],s,a)}if(m>n){const e=y(u(p[o]),p[o+1],(n-f)/h);return l=new i({x:e[0],y:e[1],...c>-1?{m:r(u(p[o])[c],u(p[o+1])[c],h,n-f)??void 0}:{},spatialReference:t.spatialReference}),0===s?l:d(l,u(p[o]),p[o+1],s,a)}f+=h}if(0===f)return null;const h=o.length-1,m=o[h].length-1;let g=[u(o[h][m-1]),o[h][m]],M=q(t,h,m);if(R(g[1]))return M=w(M,g,n-f),j(M,g,s);const Z=e(g[0],g[1],!1,1);return g=[y(g[0],g[1],(Z-a)/Z),u(g[1])],M=w(M,g,n-f),j(M,g,s)}function C(t,n,s,a,o){const c=p(t);if(n<=0){let r=[u(c[0][0]),c[0][1]],i=q(t,0,0);if(R(r[1]))return i=v(i,r,n,a),j(i,r,s);const f=e(r[0],r[1],!1,1),l=y(r[0],r[1],o/f);return l[2]=r[0][2],r=[r[0],l],i=v(i,r,n,a),j(i,r,s)}const f=t.hasM?t.hasZ?3:2:-1;let l=0;for(const p of c)for(let c=0;c<p.length-1;c++){const h=e(u(p[c]),p[c+1],!0,a),m=l+h;if(m===n){const e=u(p[c+1]),n=new i({x:e[0],y:e[1],z:e[2],...t.hasM?{m:e[f]}:{},hasZ:!0,hasM:t.hasM,spatialReference:t.spatialReference});return 0===s?n:d(n,u(p[c]),p[c+1],s,o)}if(m>n){const e=y(u(p[c]),p[c+1],(n-l)/h);e[2]=r(u(p[c])[2],u(p[c+1])[2],h,n-l);const a=new i({x:e[0],y:e[1],z:e[2],...f>-1?{m:r(u(p[c])[f],u(p[c+1])[f],h,n-l)}:{},hasZ:!0,spatialReference:t.spatialReference});return 0===s?a:d(a,u(p[c]),p[c+1],s,o)}l+=h}if(0===l)return null;const h=c.length-1,m=c[h].length-1;let g=[u(c[h][m-1]),c[h][m]],M=q(t,h,m);if(R(g[1]))return M=v(M,g,n-l,a),j(M,g,s);const Z=e(g[0],g[1],!0,a),x=y(g[0],g[1],(Z-o)/Z);return x[2]=u(g[1])[2],g=[x,u(g[1])],M=v(M,g,n-l,a),j(M,g,s)}function b(e,t,n){const s=u(p(e)[t][n]);return new i({spatialReference:e.spatialReference,x:s[0],y:s[1],hasZ:e.hasZ,hasM:e.hasM,z:e.hasZ?s[2]:void 0,m:e.hasM?e.hasZ?s[3]:s[2]:void 0})}function q(e,t,n){const s=u(p(e)[t][n]);return new i({spatialReference:e.spatialReference,x:s[0],y:s[1],hasZ:e.hasZ,hasM:e.hasM,z:e.hasZ?s[2]:void 0,m:e.hasM?e.hasZ?s[3]:s[2]:void 0})}function O(e){return t(u(e.at(0)),u(e.at(-1)))}export{M as computedTotalLength,Z as convertRadialToPolylines,x as convertToTwoPoint,j as offsetPointFromLineSegment,d as offsetPointFromSegment,z as pointAlongLineAndOffset,P as pointAlongLineWithCurvesAndOffset,C as pointAlongLineWithCurvesAndZAndOffset,U as pointAlongLineWithZAndOffset,b as pointFromPolygonVertex,q as pointFromPolylineVertex,O as sameStartEndPoint};