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.
33 lines
15 KiB
33 lines
15 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","../Dictionary","../executionError","../../chunks/languageUtils","../../core/maybe"],function(x,N,f,r,X){function D(a){if(!1===r.isString(a))throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.InvalidParameter,null);return a}function H(a,b){b=10**b;return Math.round(a*b)/b}function y(a){const b=parseFloat(a.toString().replace(Math.trunc(a).toString(),"0"))*Math.sign(a);return 0>a?{fraction:b,integer:Math.ceil(a)}:{fraction:b,integer:Math.floor(a)}}function z(a,b){switch(a){case h.north:return"SHORT"=== |
|
b?"N":"North";case h.east:return"SHORT"===b?"E":"East";case h.south:return"SHORT"===b?"S":"South";case h.west:return"SHORT"===b?"W":"West"}}function I(a,b){return a-Math.floor(a/b)*b}function J(a){switch(a){case e.truncated_degrees:case e.decimal_degrees:return 360;case e.radians:return Y;case e.gradians:return 400;case e.seconds:return 1296E3;case e.fractional_degree_minutes:return 60;case e.fractional_minute_seconds:return 60;default:throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError, |
|
null,{reason:"unsupported evaluations"});}}function O(a){switch(a.toUpperCase().trim()){case "NORTH":case "NORTHAZIMUTH":case "NORTH AZIMUTH":return g.north_azimuth;case "POLAR":return g.polar;case "QUADRANT":return g.quadrant;case "SOUTH":case "SOUTHAZIMUTH":case "SOUTH AZIMUTH":return g.south_azimuth}throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"unsupported directionType"});}function P(a){switch(a.toUpperCase().trim()){case "D":case "DD":case "DECIMALDEGREE":case "DECIMAL DEGREE":case "DEGREE":case "DECIMALDEGREES":case "DECIMAL DEGREES":case "DEGREES":return e.decimal_degrees; |
|
case "DMS":case "DEGREESMINUTESSECONDS":case "DEGREES MINUTES SECONDS":return e.degrees_minutes_seconds;case "R":case "RAD":case "RADS":case "RADIAN":case "RADIANS":return e.radians;case "G":case "GON":case "GONS":case "GRAD":case "GRADS":case "GRADIAN":case "GRADIANS":return e.gradians}throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"unsupported units"});}function Q(a,b,c){let d=null;switch(b){case e.decimal_degrees:d=w(a,3600);break;case e.seconds:d=a;break;case e.gradians:d= |
|
w(a,3240);break;case e.radians:d=w(a,R);break;default:throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"unexpected evaluation"});}switch(c){case e.decimal_degrees:return E(d,3600);case e.seconds:return d;case e.gradians:return E(d,3240);case e.radians:return d/R;default:throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"unexpected evaluation"});}}function F(a){X.assertIsSome(a);switch(a){case e.decimal_degrees:case e.truncated_degrees:case e.degrees_minutes_seconds:return e.decimal_degrees; |
|
case e.gradians:return e.gradians;case e.fractional_degree_minutes:return e.fractional_degree_minutes;case e.radians:return e.radians;case e.seconds:case e.fractional_minute_seconds:return e.seconds}}function Z(a){switch(r.toNumber(a)){case 1:return{first:h.north,second:h.east};case 2:return{first:h.south,second:h.east};case 3:return{first:h.south,second:h.west};case 4:return{first:h.north,second:h.west}}return null}function S(a){switch(a.toUpperCase().trim()){case "N":case "NORTH":return h.north; |
|
case "E":case "EAST":return h.east;case "S":case "SOUTH":return h.south;case "W":case "WEST":return h.west}return null}function A(a){a=parseFloat(a);if(r.isNumber(a)){if(isNaN(a))throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"invalid conversion"});return a}throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"invalid conversion"});}function K(a,b,c){const d=c===g.quadrant;let l=null;var m=null;let n=0;var k=0;k=0;if(d){if(2>a.length)throw new f.ArcadeExecutionError(null, |
|
f.ExecutionErrorCodes.LogicError,null,{reason:"conversion error"});k=1;(m=Z(r.toString(a[a.length-1])))?(l=m.first,m=m.second):(n=1,l=S(r.toString(a[0])),m=S(r.toString(a[a.length-1])));if(null===l||null===m)throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"invalid conversion"});}switch(b){case e.decimal_degrees:case e.radians:case e.gradians:if(0===a.length)break;return d?q.createFromAngleMeridianAndDirection(t.createFromAngleAndUnits(A(a[n]),F(b)),l,m):q.createFromAngleAndDirection(t.createFromAngleAndUnits(A(a[n]), |
|
F(b)),c);case e.degrees_minutes_seconds:k=a.length-k-n;if(3===k)return a=t.createFromDegreesMinutesSeconds(A(a[n]),A(a[n+1]),A(a[n+2])),d?q.createFromAngleMeridianAndDirection(a,l,m):q.createFromAngleAndDirection(a,c);if(1===k)return a=A(a[n]),a=v.numberToDms(a),a=t.createFromDegreesMinutesSeconds(a.m_degrees,a.m_minutes,a.m_seconds),d?q.createFromAngleMeridianAndDirection(a,l,m):q.createFromAngleAndDirection(a,c)}throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"invalid conversion"}); |
|
}function aa(a){const b=new Set([" ","-","/","'",'"',"\\","^","\u00b0",T,"\t","\r","\n","*"]);let c="";for(let d=0;d<a.length;d++){const l=a.charAt(d);c=b.has(l)?c+"RRSPLITRRSPLITRR":c+l}return c.split("RRSPLITRRSPLITRR").filter(d=>""!==d)}function L(a,b,c){const d={padding:0,rounding:0,newpos:b};let l=!1;for(;b<a.length;){const m=a[b];if(m===c)l?d.rounding++:d.padding++,b++;else if("."===m)l=!0,b++;else break}d.newpos=b-1;return d}const G=a=>(b,c,d)=>{d=d||14;return+a(b,c).toFixed(d)},ba=(a,b)=> |
|
a+b,ca=(a,b)=>a-b,da=(a,b)=>a*b,ea=(a,b)=>a/b,M=(a,b,c)=>G(ba)(a,b,c),w=(a,b,c)=>G(da)(a,b,c),E=(a,b,c)=>G(ea)(a,b,c),Y=2*Math.PI,R=648E3/Math.PI,T=String.fromCharCode(7501);var h;(function(a){a[a.north=0]="north";a[a.east=1]="east";a[a.south=2]="south";a[a.west=3]="west"})(h||={});var e;(function(a){a[a.decimal_degrees=1]="decimal_degrees";a[a.seconds=2]="seconds";a[a.degrees_minutes_seconds=3]="degrees_minutes_seconds";a[a.radians=4]="radians";a[a.gradians=5]="gradians";a[a.truncated_degrees=6]= |
|
"truncated_degrees";a[a.fractional_degree_minutes=7]="fractional_degree_minutes";a[a.fractional_minute_seconds=8]="fractional_minute_seconds"})(e||={});var g;(function(a){a[a.north_azimuth=1]="north_azimuth";a[a.polar=2]="polar";a[a.quadrant=3]="quadrant";a[a.south_azimuth=4]="south_azimuth"})(g||={});var U;(function(a){a[a.meridian=0]="meridian";a[a.direction=1]="direction"})(U||={});class v{constructor(a,b,c){this.m_degrees=a;this.m_minutes=b;this.m_seconds=c}getField(a){switch(a){case e.decimal_degrees:case e.truncated_degrees:return this.m_degrees; |
|
case e.fractional_degree_minutes:return this.m_minutes;case e.seconds:case e.fractional_minute_seconds:return this.m_seconds;default:throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"unexpected evaluation"});}}static secondsToDMS(a){const b=y(a).fraction;a=y(a).integer;const c=Math.floor(a/3600);a-=3600*c;const d=Math.floor(a/60);return new v(c,d,a-60*d+b)}static numberToDms(a){var b=y(a).fraction;a=y(a).integer;const c=w(y(100*b).fraction,100);b=y(100*b).integer; |
|
return new v(a,b,c)}format(a,b){b=H(this.m_seconds,b);let c=this.m_minutes,d=this.m_degrees;if(a===e.seconds||a===e.fractional_minute_seconds)60<=b&&(b-=60,++c),60<=c&&(c=0,++d),360<=d&&(d=0);else if(a===e.fractional_degree_minutes)b=0,c=30<=this.m_seconds?this.m_minutes+1:this.m_minutes,d=this.m_degrees,60<=c&&(c=0,++d),360<=d&&(d=0);else if(a===e.decimal_degrees||a===e.truncated_degrees)a=E(this.m_seconds,3600),b=E(this.m_minutes,60),d=Math.round(this.m_degrees+b+a),b=c=0;return new v(d,c,b)}static dmsToSeconds(a, |
|
b,c){return 3600*a+60*b+c}}class fa{constructor(a,b,c){this.meridian=a;this.angle=b;this.direction=c}fetchAzimuth(a){return a===U.meridian?this.meridian:this.direction}}class q{constructor(a){this._angle=a}static createFromAngleAndDirection(a,b){return new q(new t(q._convertDirectionFormat(a.extractAngularUnits(e.seconds),b,g.north_azimuth)))}getAngle(a){const b=this._angle.extractAngularUnits(e.seconds);switch(a){case g.north_azimuth:case g.south_azimuth:case g.polar:return new t(q._convertDirectionFormat(b, |
|
g.north_azimuth,a));case g.quadrant:return a=q.secondsNorthAzimuthToQuadrant(b),new t(a.angle)}}getMeridian(a){const b=this._angle.extractAngularUnits(e.seconds);switch(a){case g.north_azimuth:return h.north;case g.south_azimuth:return h.south;case g.polar:return h.east;case g.quadrant:return q.secondsNorthAzimuthToQuadrant(b).meridian}}getDirection(a){const b=this._angle.extractAngularUnits(e.seconds);switch(a){case g.north_azimuth:return h.east;case g.south_azimuth:return h.west;case g.polar:return h.north; |
|
case g.quadrant:return q.secondsNorthAzimuthToQuadrant(b).direction}}static secondsNorthAzimuthToQuadrant(a){const b=324E3>=a||972E3<=a?h.north:h.south;return new fa(b,b===h.north?Math.min(1296E3-a,a):Math.abs(a-648E3),648E3<a?h.west:h.east)}static createFromAngleMeridianAndDirection(a,b,c){return new q(new t(q.secondsQuadrantToNorthAzimuth(a.extractAngularUnits(e.seconds),b,c)))}static secondsQuadrantToNorthAzimuth(a,b,c){return b===h.north?c===h.east?a:1296E3-a:c===h.east?648E3-a:648E3+a}static _convertDirectionFormat(a, |
|
b,c){let d=0;switch(b){case g.north_azimuth:d=a;break;case g.polar:d=324E3-a;break;case g.quadrant:throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"unexpected evaluation"});case g.south_azimuth:d=a+648E3}a=0;switch(c){case g.north_azimuth:a=d;break;case g.polar:a=324E3-d;break;case g.quadrant:throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"unexpected evaluation"});case g.south_azimuth:a=d-648E3}a%=1296E3;return 0>a?1296E3+a: |
|
a}}class t{constructor(a){this._seconds=a}static createFromAngleAndUnits(a,b){return new t(Q(a,b,e.seconds))}extractAngularUnits(a){return Q(this._seconds,e.seconds,F(a))}static createFromDegreesMinutesSeconds(a,b,c){return new t(M(M(w(a,3600),w(b,60)),c))}}class V{constructor(a,b,c,d){this.view=a;this.angle=b;this.merdian=c;this.direction=d;this._formattedDms=this._dms=null}static createFromStringAndBearing(a,b,c){return new V(a,b.getAngle(c),b.getMeridian(c),b.getDirection(c))}fetchAngle(){return this.angle}fetchMeridian(){return this.merdian}fetchDirection(){return this.direction}fetchView(){return this.view}fetchDms(){null=== |
|
this._dms&&this._calculateDms();return this._dms}fetchFormattedDms(){null===this._formattedDms&&this._calculateDms();return this._formattedDms}_calculateDms(){var a=null;let b=e.truncated_degrees,c=0;for(a=0;a<this.view.length;a++){const d=this.view[a];switch(d){case "m":a=L(this.view,a,d);b=b===e.truncated_degrees?e.fractional_degree_minutes:b;a=a.newpos;continue;case "s":a=L(this.view,a,d),b=e.fractional_minute_seconds,c=c<a.rounding?a.rounding:c,a=a.newpos}}this._dms=v.secondsToDMS(this.angle.extractAngularUnits(e.seconds)); |
|
this._formattedDms=v.secondsToDMS(this.angle.extractAngularUnits(e.seconds)).format(b,c)}}x.convertDirection=function(a,b,c){if(!(b instanceof N))throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.InvalidParameter,null);if(!1===b.hasField("directionType"))throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"missing directionType"});if(!1===b.hasField("angleType"))throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"missing angleType"}); |
|
var d=O(D(b.field("directiontype")));b=P(D(b.field("angletype")));if(r.isNumber(a)){a=r.toNumber(a);if(d===g.quadrant)throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"conversion error"});b===e.degrees_minutes_seconds?(a=v.numberToDms(a),d=q.createFromAngleAndDirection(t.createFromDegreesMinutesSeconds(a.m_degrees,a.m_minutes,a.m_seconds),d)):d=q.createFromAngleAndDirection(t.createFromAngleAndUnits(a,F(b)),d)}else if(r.isString(a))d=K(aa(a),b,d);else if(r.isArray(a))d= |
|
K(a,b,d);else if(r.isImmutableArray(a))d=K(a.toArray(),b,d);else throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"conversion error"});if(!(c instanceof N))throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.InvalidParameter,null);if(!1===c.hasField("directionType"))throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"missing directionType"});if(!1===c.hasField("outputType"))throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError, |
|
null,{reason:"missing angleType"});a=O(D(c.field("directiontype")));b=c.hasField("angleType")?P(D(c.field("angletype"))):null;var l=D(c.field("outputType")).toUpperCase().trim();if(!a||!l)throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"conversion error"});if(!(b||"TEXT"===l&&c.hasField("format")))throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"invalid unit"});switch(l){case "VALUE":if(a===g.quadrant||b===e.degrees_minutes_seconds)return c= |
|
d.getAngle(a),a===g.quadrant&&b===e.degrees_minutes_seconds?(c=v.secondsToDMS(c.extractAngularUnits(e.seconds)),d=[z(d.getMeridian(a),"SHORT"),c.m_degrees,c.m_minutes,c.m_seconds,z(d.getDirection(a),"SHORT")]):b===e.degrees_minutes_seconds?(d=v.secondsToDMS(c.extractAngularUnits(e.seconds)),d=[d.m_degrees,d.m_minutes,d.m_seconds]):d=a===g.quadrant?[z(d.getMeridian(a),"SHORT"),c.extractAngularUnits(b),z(d.getDirection(a),"SHORT")]:[c.extractAngularUnits(b)],d;if((c=F(b))&&b!==e.degrees_minutes_seconds)d= |
|
d.getAngle(a).extractAngularUnits(c);else throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"conversion error"});return d;case "TEXT":l="";c.hasField("format")&&(l=r.toString(c.field("format")));if(null===l||""===l){c="";switch(b){case e.decimal_degrees:c=a===g.quadrant?"DD.DD\u00b0":"DDD.DD\u00b0";break;case e.degrees_minutes_seconds:c=a===g.quadrant?"dd\u00b0 mm' ss\"":"ddd\u00b0 mm' ss.ss\"";break;case e.radians:c="R.RR";break;case e.gradians:c="GGG.GG"+T;break; |
|
default:throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"conversion error"});}a===g.quadrant&&(c="p "+c+" b");l=c}c=l;var m="",n=null,k=null;b=V.createFromStringAndBearing(c,d,a);l={D:e.decimal_degrees,d:e.truncated_degrees,m:e.fractional_degree_minutes,s:e.fractional_minute_seconds,R:e.radians,G:e.gradians};for(k=0;k<c.length;k++){var p=c[k];switch(p){case "[":n=c;p={escaped:"",newpos:k};for(k++;k<n.length;){var B=n[k];k++;if("]"===B)break;p.escaped+=B}p.newpos= |
|
k-1;n=p;m+=n.escaped;k=n.newpos;continue;case "D":case "d":case "m":case "s":case "R":case "G":n=L(c,k,p);k=d.getAngle(a);a:{p=l[p];B=n.padding;var u=n.rounding,W=b;let C=null;switch(p){case e.decimal_degrees:case e.radians:case e.gradians:C=I(H(k.extractAngularUnits(p),u),J(p));k=C.toFixed(u).padStart(B+u+(0<u?1:0),"0");break a;case e.truncated_degrees:case e.fractional_degree_minutes:C=I(W.fetchFormattedDms().getField(p),J(p));k=C.toFixed(u).padStart(B+u+(0<u?1:0),"0");break a;case e.fractional_minute_seconds:C= |
|
I(H(W.fetchDms().getField(p),u),J(p));k=C.toFixed(u).padStart(B+u+(0<u?1:0),"0");break a;default:throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.LogicError,null,{reason:"unexpected evaluation"});}}m+=k;k=n.newpos;continue;case "P":case "p":m+=z(b.fetchMeridian(),"p"===p?"SHORT":"LONG");continue;case "B":case "b":m+=z(b.fetchDirection(),"b"===p?"SHORT":"LONG");continue;default:m+=p}}return m;default:throw new f.ArcadeExecutionError(null,f.ExecutionErrorCodes.InvalidParameter,null);}};x.preciseAdd= |
|
M;x.preciseDivide=E;x.preciseMinus=(a,b,c)=>G(ca)(a,b,c);x.preciseMultiply=w;Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})}); |