12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import e from"../Dictionary.js";import n from"../Feature.js";import t from"../ImmutablePointArray.js";import{y as r,m as a,x as i,q as o,F as s,G as l,v as c,c as f,j as u,k as m,b as h,a as p,i as w,f as d,w as y,s as g,H as R}from"../../chunks/languageUtils.js";import I from"../../geometry/Extent.js";import v from"../../geometry/Geometry.js";import P from"../../geometry/Multipoint.js";import x from"../../geometry/Point.js";import b from"../../geometry/Polygon.js";import F from"../../geometry/Polyline.js";import{angle2D as j,angleBetween2D as O,bearing2D as S,bearingBetween2D as N,pathsSelfIntersecting as k}from"./centroid.js";import{fromJSON as J}from"../../geometry/support/jsonUtils.js";import{ArcadeExecutionError as G,ExecutionErrorCodes as z}from"../executionError.js";import D from"../ImmutablePathArray.js";import{isClockwise as _}from"../../geometry/support/coordsUtils.js";function M(e){return e&&"esri.arcade.Feature"===e.arcadeDeclaredClass}function C(D,C){D.ringisclockwise=function(e,n){return C(e,n,((o,s,l)=>{r(l,1,1,e,n);let c=[],f=!1,u=!1;if(null===l[0])return!1;if(a(l[0])){for(const t of l[0]){if(!(t instanceof x))throw new G(e,z.InvalidParameter,n);c.push(t.hasZ?t.hasM?[t.x,t.y,t.z,t.m]:[t.x,t.y,t.z]:[t.x,t.y])}c.length>0&&(f=l[0][0].hasZ,u=l[0][0].hasM)}else if(l[0]instanceof t)c=l[0]._elements,c.length>0&&(f=l[0]._hasZ,u=l[0]._hasM);else{if(!i(l[0]))throw new G(e,z.InvalidParameter,n);for(const t of l[0].toArray()){if(!(t instanceof x))throw new G(e,z.InvalidParameter,n);c.push(t.hasZ?t.hasM?[t.x,t.y,t.z,t.m]:[t.x,t.y,t.z]:[t.x,t.y])}c.length>0&&(f=l[0].get(0).hasZ,u=l[0].get(0).hasM)}return!(c.length<3)&&_(c,u,f)}))},D.polygon=function(t,a){return C(t,a,((i,l,c)=>{r(c,1,1,t,a);let f=null;if(c[0]instanceof e){if(f=o(n.parseGeometryFromDictionary(c[0]),t.spatialReference),f instanceof b==!1)throw new G(t,z.InvalidParameter,a)}else f=c[0]instanceof b?J(c[0].toJSON()):o(new b(JSON.parse(c[0])),t.spatialReference);if(null!==f&&!1===f.spatialReference.equals(t.spatialReference))throw new G(t,z.WrongSpatialReference,a);return s(f)}))},D.polyline=function(t,a){return C(t,a,((i,l,c)=>{r(c,1,1,t,a);let f=null;if(c[0]instanceof e){if(f=o(n.parseGeometryFromDictionary(c[0]),t.spatialReference),f instanceof F==!1)throw new G(t,z.InvalidParameter,a)}else f=c[0]instanceof F?J(c[0].toJSON()):o(new F(JSON.parse(c[0])),t.spatialReference);if(null!==f&&!1===f.spatialReference.equals(t.spatialReference))throw new G(t,z.WrongSpatialReference,a);return s(f)}))},D.point=function(t,a){return C(t,a,((i,l,c)=>{r(c,1,1,t,a);let f=null;if(c[0]instanceof e){if(f=o(n.parseGeometryFromDictionary(c[0]),t.spatialReference),f instanceof x==!1)throw new G(t,z.InvalidParameter,a)}else f=c[0]instanceof x?J(c[0].toJSON()):o(new x(JSON.parse(c[0])),t.spatialReference);if(null!==f&&!1===f.spatialReference.equals(t.spatialReference))throw new G(t,z.WrongSpatialReference,a);return s(f)}))},D.multipoint=function(t,a){return C(t,a,((i,l,c)=>{r(c,1,1,t,a);let f=null;if(c[0]instanceof e){if(f=o(n.parseGeometryFromDictionary(c[0]),t.spatialReference),f instanceof P==!1)throw new G(t,z.InvalidParameter,a)}else f=c[0]instanceof P?J(c[0].toJSON()):o(new P(JSON.parse(c[0])),t.spatialReference);if(null!==f&&!1===f.spatialReference.equals(t.spatialReference))throw new G(t,z.WrongSpatialReference,a);return s(f)}))},D.extent=function(t,a){return C(t,a,((i,c,f)=>{f=l(f),r(f,1,1,t,a);let u=null;if(f[0]instanceof e)u=o(n.parseGeometryFromDictionary(f[0]),t.spatialReference);else if(f[0]instanceof x){const e={xmin:f[0].x,ymin:f[0].y,xmax:f[0].x,ymax:f[0].y,spatialReference:f[0].spatialReference.toJSON()},n=f[0];n.hasZ?(e.zmin=n.z,e.zmax=n.z):n.hasM&&(e.mmin=n.m,e.mmax=n.m),u=J(e)}else u=f[0]instanceof b||f[0]instanceof F||f[0]instanceof P?J(f[0].extent?.toJSON()):f[0]instanceof I?J(f[0].toJSON()):o(new I(JSON.parse(f[0])),t.spatialReference);if(null!==u&&!1===u.spatialReference.equals(t.spatialReference))throw new G(t,z.WrongSpatialReference,a);return s(u)}))},D.geometry=function(t,a){return C(t,a,((i,l,c)=>{r(c,1,1,t,a);let f=null;if(null===c[0])return null;if(f=M(c[0])?o(c[0].geometry(),t.spatialReference):c[0]instanceof e?o(n.parseGeometryFromDictionary(c[0]),t.spatialReference):o(J(JSON.parse(c[0])),t.spatialReference),null!==f&&!1===f.spatialReference.equals(t.spatialReference))throw new G(t,z.WrongSpatialReference,a);return s(f)}))},D.setgeometry=function(e,n){return C(e,n,((t,a,i)=>{if(r(i,2,2,e,n),!M(i[0]))throw new G(e,z.InvalidParameter,n);if(!0===i[0].immutable)throw new G(e,z.Immutable,n);if(!(i[1]instanceof v||null===i[1]))throw new G(e,z.InvalidParameter,n);return i[0]._geometry=i[1],c}))},D.feature=function(t,r){return C(t,r,((a,i,s)=>{if(0===s.length)throw new G(t,z.WrongNumberOfParameters,r);let l=null;if(1===s.length)if(f(s[0]))l=n.fromJson(JSON.parse(s[0]));else if(M(s[0]))l=n.createFromArcadeFeature(s[0]);else if(s[0]instanceof v)l=n.createFromGraphicLikeObject(s[0],null,null);else{if(!(s[0]instanceof e))throw new G(t,z.InvalidParameter,r);{let t=s[0].hasField("geometry")?s[0].field("geometry"):null,r=s[0].hasField("attributes")?s[0].field("attributes"):null;null!==t&&t instanceof e&&(t=n.parseGeometryFromDictionary(t)),null!==r&&(r=n.parseAttributesFromDictionary(r)),l=n.createFromGraphicLikeObject(t,r,null)}}else if(2===s.length){let a=null,i=null;if(null!==s[0])if(s[0]instanceof v)a=s[0];else{if(!(a instanceof e))throw new G(t,z.InvalidParameter,r);a=n.parseGeometryFromDictionary(s[0])}if(null!==s[1]){if(!(s[1]instanceof e))throw new G(t,z.InvalidParameter,r);i=n.parseAttributesFromDictionary(s[1])}l=n.createFromGraphicLikeObject(a,i,null)}else{let a=null;const i={};if(null!==s[0])if(s[0]instanceof v)a=s[0];else{if(!(a instanceof e))throw new G(t,z.InvalidParameter,r);a=n.parseGeometryFromDictionary(s[0])}for(let e=1;e<s.length;e+=2){const n=u(s[e]),a=s[e+1];if(!(null==a||f(a)||isNaN(a)||m(a)||h(a)||p(a)))throw new G(t,z.InvalidParameter,r);if(w(a)||!1===d(a))throw new G(t,z.InvalidParameter,r);i[n]=a===c?null:a}l=n.createFromGraphicLikeObject(a,i,null)}return l._geometry=o(l.geometry(),t.spatialReference),l.immutable=!1,l}))},D.dictionary=function(n,t){return C(n,t,((r,o,s)=>{if(0===s.length){const n=new e;return n.immutable=!1,n}if(1===s.length&&f(s[0]))try{const n=JSON.parse(s[0]),t=e.convertObjectToArcadeDictionary(n,!1);return t.immutable=!1,t}catch(y){throw new G(n,z.InvalidParameter,t)}if(s.length%2!=0)throw new G(n,z.WrongNumberOfParameters,t);const l={};for(let e=0;e<s.length;e+=2){const r=u(s[e]),o=s[e+1];if(!(null==o||f(o)||isNaN(o)||m(o)||h(o)||p(o)||a(o)||i(o)))throw new G(n,z.InvalidParameter,t);if(w(o))throw new G(n,z.InvalidParameter,t);l[r]=o===c?null:o}const d=new e(l);return d.immutable=!1,d}))},D.haskey=function(n,t){return C(n,t,((a,i,o)=>{r(o,2,2,n,t);const s=u(o[1]);if(M(o[0]))return o[0].hasField(s);if(o[0]instanceof e)return o[0].hasField(s);if(o[0]instanceof v){const e=W(o[0],s,null,null,2);return!e||"notfound"!==e.keystate}throw new G(n,z.InvalidParameter,t)}))},D.hasvalue=function(n,t){return C(n,t,((a,i,o)=>{if(r(o,2,2,n,t),null===o[0]||null===o[1])return!1;const s=u(o[1]);if(y(o[0]))return!!o[0].hasField(s)&&null!==o[0].field(s);if(o[0]instanceof e)return!!o[0].hasField(s)&&null!==o[0].field(s);if(o[0]instanceof v){return null!==W(o[0],s,null,null,0)}return!1}))},D.indexof=function(e,n){return C(e,n,((t,o,s)=>{r(s,2,2,e,n);const l=s[1];if(a(s[0])){for(let e=0;e<s[0].length;e++)if(g(l,s[0][e]))return e;return-1}if(i(s[0])){const e=s[0].length();for(let n=0;n<e;n++)if(g(l,s[0].get(n)))return n;return-1}throw new G(e,z.InvalidParameter,n)}))},D.angle=function(e,n){return C(e,n,((t,a,i)=>{if(i=l(i),r(i,2,3,e,n),!(i[0]instanceof x))throw new G(e,z.InvalidParameter,n);if(!(i[1]instanceof x))throw new G(e,z.InvalidParameter,n);if(i.length>2&&!(i[2]instanceof x))throw new G(e,z.InvalidParameter,n);return 2===i.length?j(i[0],i[1]):O(i[0],i[1],i[2])}))},D.bearing=function(e,n){return C(e,n,((t,a,i)=>{if(i=l(i),r(i,2,3,e,n),!(i[0]instanceof x))throw new G(e,z.InvalidParameter,n);if(!(i[1]instanceof x))throw new G(e,z.InvalidParameter,n);if(i.length>2&&!(i[2]instanceof x))throw new G(e,z.InvalidParameter,n);return 2===i.length?S(i[0],i[1]):N(i[0],i[1],i[2])}))},D.isselfintersecting=function(e,n){return C(e,n,((t,o,s)=>{s=l(s),r(s,1,1,e,n);let c=s[0];if(c instanceof b)return c.isSelfIntersecting;if(c instanceof F)return c=c.paths,k(c);if(c instanceof P){const e=c.points;for(let n=0;n<e.length;n++)for(let t=0;t<e.length;t++)if(t!==n){let r=!0;for(let a=0;a<e[n].length;a++)if(e[n][a]!==e[t][a]){r=!1;break}if(!0===r)return!0}}return!(!a(c)&&!i(c))&&(c=R(c,e.spatialReference),null!==c&&(c=c.paths),k(c))}))}}let Z=0;function W(n,r,a,i,o=1){let s;switch(r=r.toLowerCase()){case"hasz":{const e=n.hasZ;return void 0!==e&&e}case"hasm":{const e=n.hasM;return void 0!==e&&e}case"spatialreference":{let t=n.spatialReference._arcadeCacheId;if(void 0===t){let e=!0;Object.freeze&&Object.isFrozen(n.spatialReference)&&(e=!1),e&&(Z++,n.spatialReference._arcadeCacheId=Z,t=Z)}const r=new e({wkt:n.spatialReference.wkt,wkid:n.spatialReference.wkid});return void 0!==t&&(r._arcadeCacheId="SPREF"+t.toString()),r}}switch(n.type){case"extent":switch(r){case"xmin":case"xmax":case"ymin":case"ymax":case"zmin":case"zmax":case"mmin":case"mmax":{const e=n[r];return void 0!==e?e:null}case"type":return"Extent"}break;case"polygon":switch(r){case"rings":s=n.cache._arcadeCacheId,void 0===s&&(Z++,s=Z,n.cache._arcadeCacheId=s);return new D(n.rings,n.spatialReference,!0===n.hasZ,!0===n.hasM,s);case"type":return"Polygon"}break;case"point":switch(r){case"x":case"y":case"z":case"m":return void 0!==n[r]?n[r]:null;case"type":return"Point"}break;case"polyline":switch(r){case"paths":s=n.cache._arcadeCacheId,void 0===s&&(Z++,s=Z,n.cache._arcadeCacheId=s);return new D(n.paths,n.spatialReference,!0===n.hasZ,!0===n.hasM,s);case"type":return"Polyline"}break;case"multipoint":switch(r){case"points":s=n.cache._arcadeCacheId,void 0===s&&(Z++,s=Z,n.cache._arcadeCacheId=s);return new t(n.points,n.spatialReference,!0===n.hasZ,!0===n.hasM,s,1);case"type":return"Multipoint"}}if(1===o)throw new G(a,z.InvalidIdentifier,i);return 2===o?{keystate:"notfound"}:null}export{W as geometryMember,C as registerFunctions};
|