You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
5.8 KiB
15 lines
5.8 KiB
// All material copyright Esri, All Rights Reserved, unless otherwise specified. |
|
// See https://js.arcgis.com/4.30/esri/copyright.txt for details. |
|
//>>built |
|
define(["exports","./centroid","../../core/unitUtils","../../geometry/Point","../../geometry/Polygon"],function(w,l,v,t,A){function x(a,b,c){c=b[0]-a[0];a=b[1]-a[1];return Math.sqrt(c*c+a*a)}function y(a,b,c,d){b=[b[0]-a[0],b[1]-a[1],b[2]*d-a[2]*d];d=Math.sqrt(b[0]*b[0]+b[1]*b[1]+b[2]*b[2]);b=[b[0]/d,b[1]/d,b[2]/d];return[a[0]+b[0]*c,a[1]+b[1]*c,a[2]+b[2]*c]}function z(a,b,c){let d=b[0]-a[0];b=b[1]-a[1];const h=Math.sqrt(d*d+b*b);return[a[0]+d/h*c,a[1]+b/h*c]}w.distanceToCoordinate=function(a,b){if(!a)return null; |
|
switch(a.type){case "extent":case "multipoint":case "mesh":case "point":return null}var c="polygon"===a.type?a.rings:a.paths;if(0>b)return null;var d=1;if(a.spatialReference.vcsWkid||a.spatialReference.latestVcsWkid){var h=l.getMetersPerVerticalUnitForSR(a.spatialReference),p=v.getMetersPerUnitForSR(a.spatialReference);d=h/p}let q=0;h=a.hasZ?3:2;var k=a.hasZ?l.segmentLength3d:x;p=-1;if(0===b)return 0===c.length||0===c[0].length?null:{partId:0,coordinate:new t({hasZ:a.hasZ,hasM:a.hasM,spatialReference:a.spatialReference, |
|
x:c[0][0][0],y:c[0][0][1],...(a.hasZ?{z:c[0][0][2]}:{}),...(a.hasM?{m:c[0][0][h]}:{})}),segmentId:0};for(const g of c){p++;c=-1;for(let e=1;e<g.length;e++){c++;const f=k(g[e-1],g[e],d),m=q+f;if(m===b)return{partId:p,coordinate:new t({hasZ:a.hasZ,hasM:a.hasM,spatialReference:a.spatialReference,x:g[e][0],y:g[e][1],...(a.hasZ?{z:g[e][2]}:{}),...(a.hasM?{m:g[e][h]}:{})}),segmentId:c};if(m>b)return d=a.hasZ?y(g[e-1],g[e],b-q,d):z(g[e-1],g[e],b-q),d=[...d],k=g[e-1][h],b=k+(g[e][h]-k)/f*(b-q),d=[...d,b], |
|
{partId:p,coordinate:new t({hasZ:a.hasZ,hasM:a.hasM,spatialReference:a.spatialReference,x:d[0],y:d[1],...(a.hasZ?{z:d[2]}:{}),...(a.hasM?{m:d[h]}:{})}),segmentId:c};q=m}}return null};w.measureToCoordinate=function(a,b){if(!a)return null;switch(a.type){case "extent":case "multipoint":case "mesh":case "point":return null}var c="polygon"===a.type?a.rings:a.paths,d=1;if(a.spatialReference.vcsWkid||a.spatialReference.latestVcsWkid){d=l.getMetersPerVerticalUnitForSR(a.spatialReference);var h=v.getMetersPerUnitForSR(a.spatialReference); |
|
d/=h}if(0===c.length||0===c[0].length||!1===a.hasM)return null;h=-1;let p=0;const q=a.hasZ?l.segmentLength3d:x,k=a.hasZ?3:2;for(const e of c){h++;if(0<e.length&&e[0][k]===b)return{partId:h,distanceAlong:p,coordinate:new t({hasZ:a.hasZ,hasM:a.hasM,spatialReference:a.spatialReference,x:e[0][0],y:e[0][1],...(a.hasZ?{z:e[0][2]}:{}),...(a.hasM?{m:e[0][k]}:{})}),segmentId:0};c=-1;for(let f=1;f<e.length;f++){var g=q(e[f-1],e[f],d);c++;const m=e[f][k]-e[f-1][k],n=e[f][k];if(n===b)return{partId:h,distanceAlong:g+ |
|
p,coordinate:new t({hasZ:a.hasZ,hasM:a.hasM,spatialReference:a.spatialReference,x:e[f][0],y:e[f][1],...(a.hasZ?{z:e[f][2]}:{}),...(a.hasM?{m:e[f][k]}:{})}),segmentId:c};if(n>b&&b>e[f-1][k])return g*=(b-e[f-1][k])/m,g=a.hasZ?y(e[f-1],e[f],g,d):z(e[f-1],e[f],g),g=[...g,b],a=new t({hasZ:a.hasZ,hasM:a.hasM,spatialReference:a.spatialReference,x:g[0],y:g[1],...(a.hasZ?{z:g[2]}:{}),...(a.hasM?{m:g[k]}:{})}),{partId:h,distanceAlong:p+q(e[f-1],[a.x,a.y,...(a.hasZ?[a.z]:[]),...(a.hasM?[a.m]:[])],d),coordinate:a, |
|
segmentId:c};p+=g}}return null};w.pointToCoordinate=function(a,b){if(!a||!b)return null;if("extent"===a.type){var c=a;a=new A({spatialReference:a.spatialReference,rings:[[[c.xmin,c.ymin],[c.xmin,c.ymax],[c.xmax,c.ymax],[c.xmax,c.ymin],[c.xmin,c.ymin]]]})}switch(a.type){case "point":var d=a;if(d)if(b){a=1;if(b.spatialReference.vcsWkid||b.spatialReference.latestVcsWkid)a=l.getMetersPerVerticalUnitForSR(b.spatialReference),c=v.getMetersPerUnitForSR(b.spatialReference),a/=c;c=null;var h=0;c=d;h=d.hasZ&& |
|
b.hasZ?l.segmentLength3d([b.x,b.y,b.z],[d.x,d.y,d.z],a):l.segmentLength([b.x,b.y],[d.x,d.y],!1);b={coordinate:c,distance:h}}else b=null;else b=null;return b??null;case "multipoint":if(a&&b){c=1;if(b.spatialReference.vcsWkid||b.spatialReference.latestVcsWkid)c=l.getMetersPerVerticalUnitForSR(b.spatialReference),h=v.getMetersPerUnitForSR(b.spatialReference),c/=h;h=null;var p=0;p=Number.MAX_VALUE;var q=h=-1;for(d of a.points||[]){q++;var k=a.hasZ&&b.hasZ?l.segmentLength3dSqr([d[0],d[1],d[2]],[b.x,b.y, |
|
b.z],c):l.segmentLengthSqr([d[0],d[1]],[b.x,b.y],!1);k<p&&(p=k,h=q)}0>h?b=null:(h=a.getPoint(h),b={coordinate:h,distance:Math.sqrt(p)})}else b=null;return b??null;case "polygon":case "polyline":if((d=a)&&b){a="polygon"===d.type?d.rings:d.paths;c=1;if(b.spatialReference.vcsWkid||b.spatialReference.latestVcsWkid)c=l.getMetersPerVerticalUnitForSR(b.spatialReference),h=v.getMetersPerUnitForSR(b.spatialReference),c/=h;h=Number.MAX_VALUE;var g=p=-1;q=-1;k=d.hasZ&&b.hasZ;var e=null,f=k?[b.x,b.y,b.z]:[b.x, |
|
b.y];for(var m of a){g++;for(var n=1;n<m.length;n++){var r=k?l.closestPointOnLineSegmentWithZ(f,m[n-1],m[n]):l.closestPointOnLineSegment(f,m[n-1],m[n]),u=k?l.segmentLength3dSqr(r,f,c):l.segmentLengthSqr(r,f,!1);u<h&&(h=u,e=r,q=g,p=n-1)}}if(0>p)b=null;else{f=d.hasM&&d.hasZ?3:2;m=a[q][p];g=a[q][p+1];n=n=null;r=k?e[2]:null;if(d.hasM){n=m[f];u=k?l.segmentLength3d(m,g,c):l.segmentLength(m,g,!1);var B=k?l.segmentLength3d(m,e,c):l.segmentLength(m,e,!1);n+=(g[f]-n)/u*B}d.hasZ&&!1===b.hasZ&&(f=m[2],r=k?l.segmentLength3d(m, |
|
g,c):l.segmentLength(m,g,!1),u=k?l.segmentLength3d(m,e,c):l.segmentLength(m,e,!1),r=f+(g[2]-f)/r*u);n=new t({hasZ:k,hasM:d.hasM,spatialReference:b.spatialReference,x:e[0],y:e[1],...(d.hasZ?{z:r}:{}),...(d.hasM?{m:n}:{})});b=0;for(k=0;k<=q;k++)for(e=a[k],g=k===q?p:e.length-1,f=1;f<=g;f++)b+=d.hasZ?l.segmentLength3d(e[f-1],e[f],c):l.segmentLength([e[f-1][0],e[f-1][1]],[e[f][0],e[f][1]],!1);b+=d.hasZ?l.segmentLength3d(m,[n.x,n.y,n.z],c):l.segmentLength(m,[n.x,n.y],!1);b={partId:q,segmentId:p,coordinate:n, |
|
distance:Math.sqrt(h),distanceAlong:b}}}else b=null;return b??null;default:return null}};Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})}); |