geometry.js 8.6 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import e from"../Dictionary.js";import r from"../Feature.js";import n from"../ImmutablePointArray.js";import{p as t,l as i,n as a,A as o,G as l,H as s,v as f,b as c,h as u,j as m,a as g,i as p,o as h,e as w,m as y,J as E}from"../../chunks/languageUtils.js";import R from"../../geometry/Extent.js";import I from"../../geometry/Geometry.js";import A from"../../geometry/Multipoint.js";import d from"../../geometry/Point.js";import F from"../../geometry/Polygon.js";import S from"../../geometry/Polyline.js";import{angle2D as G,angleBetween2D as j,bearing2D as O,bearingBetween2D as b,pathsSelfIntersecting as x}from"./centroid.js";import{fromJSON as N}from"../../geometry/support/jsonUtils.js";import{isClockwise as J}from"../../geometry/support/coordsUtils.js";function D(e){return e&&"esri.arcade.Feature"===e.arcadeDeclaredClass}function P(P,M){P.ringisclockwise=function(e,r){return M(e,r,(function(e,r,o){t(o,1,1);let l=[],s=!1,f=!1;if(null===o[0])return!1;if(i(o[0])){for(const e of o[0]){if(!(e instanceof d))throw new Error("Invalid Argument");l.push(e.hasZ?e.hasM?[e.x,e.y,e.z,e.m]:[e.x,e.y,e.z]:[e.x,e.y])}l.length>0&&(s=o[0][0].hasZ,f=o[0][0].hasM)}else if(o[0]instanceof n)l=o[0]._elements,l.length>0&&(s=o[0]._hasZ,f=o[0]._hasM);else{if(!a(o[0]))throw new Error("Invalid Argument");for(const e of o[0].toArray()){if(!(e instanceof d))throw new Error("Invalid Argument");l.push(e.hasZ?e.hasM?[e.x,e.y,e.z,e.m]:[e.x,e.y,e.z]:[e.x,e.y])}l.length>0&&(s=o[0].get(0).hasZ,f=o[0].get(0).hasM)}return!(l.length<3)&&J(l,f,s)}))},P.polygon=function(n,i){return M(n,i,(function(i,a,s){t(s,1,1);let f=null;if(s[0]instanceof e){if(f=o(r.parseGeometryFromDictionary(s[0]),n.spatialReference),f instanceof F==!1)throw new Error("Illegal Parameter")}else f=s[0]instanceof F?N(s[0].toJSON()):o(new F(JSON.parse(s[0])),n.spatialReference);if(null!==f&&!1===f.spatialReference.equals(n.spatialReference))throw new Error("Cannot create Geometry in this SpatialReference. Engine is using a different spatial reference.");return l(f)}))},P.polyline=function(n,i){return M(n,i,(function(i,a,s){t(s,1,1);let f=null;if(s[0]instanceof e){if(f=o(r.parseGeometryFromDictionary(s[0]),n.spatialReference),f instanceof S==!1)throw new Error("Illegal Parameter")}else f=s[0]instanceof S?N(s[0].toJSON()):o(new S(JSON.parse(s[0])),n.spatialReference);if(null!==f&&!1===f.spatialReference.equals(n.spatialReference))throw new Error("Cannot create Geometry in this SpatialReference. Engine is using a different spatial reference.");return l(f)}))},P.point=function(n,i){return M(n,i,(function(i,a,s){t(s,1,1);let f=null;if(s[0]instanceof e){if(f=o(r.parseGeometryFromDictionary(s[0]),n.spatialReference),f instanceof d==!1)throw new Error("Illegal Parameter")}else f=s[0]instanceof d?N(s[0].toJSON()):o(new d(JSON.parse(s[0])),n.spatialReference);if(null!==f&&!1===f.spatialReference.equals(n.spatialReference))throw new Error("Cannot create Geometry in this SpatialReference. Engine is using a different spatial reference.");return l(f)}))},P.multipoint=function(n,i){return M(n,i,(function(i,a,s){t(s,1,1);let f=null;if(s[0]instanceof e){if(f=o(r.parseGeometryFromDictionary(s[0]),n.spatialReference),f instanceof A==!1)throw new Error("Illegal Parameter")}else f=s[0]instanceof A?N(s[0].toJSON()):o(new A(JSON.parse(s[0])),n.spatialReference);if(null!==f&&!1===f.spatialReference.equals(n.spatialReference))throw new Error("Cannot create Geometry in this SpatialReference. Engine is using a different spatial reference.");return l(f)}))},P.extent=function(n,i){return M(n,i,(function(i,a,f){f=s(f),t(f,1,1);let c=null;if(f[0]instanceof e)c=o(r.parseGeometryFromDictionary(f[0]),n.spatialReference);else if(f[0]instanceof d){const e={xmin:f[0].x,ymin:f[0].y,xmax:f[0].x,ymax:f[0].y,spatialReference:f[0].spatialReference.toJSON()},r=f[0];r.hasZ?(e.zmin=r.z,e.zmax=r.z):r.hasM&&(e.mmin=r.m,e.mmax=r.m),c=N(e)}else c=f[0]instanceof F||f[0]instanceof S||f[0]instanceof A?N(f[0].extent.toJSON()):f[0]instanceof R?N(f[0].toJSON()):o(new R(JSON.parse(f[0])),n.spatialReference);if(null!==c&&!1===c.spatialReference.equals(n.spatialReference))throw new Error("Cannot create Geometry in this SpatialReference. Engine is using a different spatial reference.");return l(c)}))},P.geometry=function(n,i){return M(n,i,(function(i,a,s){t(s,1,1);let f=null;if(null===s[0])return null;if(f=D(s[0])?o(s[0].geometry(),n.spatialReference):s[0]instanceof e?o(r.parseGeometryFromDictionary(s[0]),n.spatialReference):o(N(JSON.parse(s[0])),n.spatialReference),null!==f&&!1===f.spatialReference.equals(n.spatialReference))throw new Error("Cannot create Geometry in this SpatialReference. Engine is using a different spatial reference.");return l(f)}))},P.setgeometry=function(e,r){return M(e,r,(function(e,r,n){if(t(n,2,2),!D(n[0]))throw new Error("Illegal Argument");if(!0===n[0].immutable)throw new Error("Feature is Immutable");if(!(n[1]instanceof I||null===n[1]))throw new Error("Illegal Argument");return n[0]._geometry=n[1],f}))},P.feature=function(n,t){return M(n,t,(function(t,i,a){if(0===a.length)throw new Error("Missing Parameters");let l=null;if(1===a.length)if(c(a[0]))l=r.fromJson(JSON.parse(a[0]));else if(D(a[0]))l=r.createFromArcadeFeature(a[0]);else if(a[0]instanceof I)l=r.createFromGraphicLikeObject(a[0],null,null);else{if(!(a[0]instanceof e))throw new Error("Illegal Argument");{let n=a[0].hasField("geometry")?a[0].field("geometry"):null,t=a[0].hasField("attributes")?a[0].field("attributes"):null;null!==n&&n instanceof e&&(n=r.parseGeometryFromDictionary(n)),null!==t&&(t=r.parseAttributesFromDictionary(t)),l=r.createFromGraphicLikeObject(n,t,null)}}else if(2===a.length){let n=null,t=null;if(null!==a[0])if(a[0]instanceof I)n=a[0];else{if(!(n instanceof e))throw new Error("Illegal Argument");n=r.parseGeometryFromDictionary(a[0])}if(null!==a[1]){if(!(a[1]instanceof e))throw new Error("Illegal Argument");t=r.parseAttributesFromDictionary(a[1])}l=r.createFromGraphicLikeObject(n,t,null)}else{let n=null;const t={};if(null!==a[0])if(a[0]instanceof I)n=a[0];else{if(!(n instanceof e))throw new Error("Illegal Argument");n=r.parseGeometryFromDictionary(a[0])}for(let e=1;e<a.length;e+=2){const r=u(a[e]),n=a[e+1];if(!(null==n||c(n)||isNaN(n)||m(n)||g(n)||p(n)))throw new Error("Illegal Argument");if(h(n)||!1===w(n))throw new Error("Illegal Argument");t[r]=n===f?null:n}l=r.createFromGraphicLikeObject(n,t,null)}return l._geometry=o(l.geometry(),n.spatialReference),l.immutable=!1,l}))},P.dictionary=function(r,n){return M(r,n,(function(r,n,t){if(0===t.length){const r=new e;return r.immutable=!1,r}if(1===t.length&&c(t[0]))try{const r=JSON.parse(t[0]),n=e.convertObjectToArcadeDictionary(r,!1);return n.immutable=!1,n}catch(s){throw new Error("Missing Parameters or Illegal Json")}if(t.length%2!=0)throw new Error("Missing Parameters");const o={};for(let e=0;e<t.length;e+=2){const r=u(t[e]),n=t[e+1];if(!(null==n||c(n)||isNaN(n)||m(n)||g(n)||p(n)||i(n)||a(n)))throw new Error("Illegal Argument");if(h(n))throw new Error("Illegal Argument");o[r]=n===f?null:n}const l=new e(o);return l.immutable=!1,l}))},P.haskey=function(r,n){return M(r,n,(function(r,n,i){t(i,2,2);const a=u(i[1]);if(D(i[0]))return i[0].hasField(a);if(i[0]instanceof e)return i[0].hasField(a);throw new Error("Illegal Argument")}))},P.indexof=function(e,r){return M(e,r,(function(e,r,n){t(n,2,2);const o=n[1];if(i(n[0])){for(let e=0;e<n[0].length;e++)if(y(o,n[0][e]))return e;return-1}if(a(n[0])){const e=n[0].length();for(let r=0;r<e;r++)if(y(o,n[0].get(r)))return r;return-1}throw new Error("Illegal Argument")}))},P.angle=function(e,r){return M(e,r,(function(e,r,n){if(n=s(n),t(n,2,3),!(n[0]instanceof d))throw new Error("Illegal Argument");if(!(n[1]instanceof d))throw new Error("Illegal Argument");if(n.length>2&&!(n[2]instanceof d))throw new Error("Illegal Argument");return 2===n.length?G(n[0],n[1]):j(n[0],n[1],n[2])}))},P.bearing=function(e,r){return M(e,r,(function(e,r,n){if(n=s(n),t(n,2,3),!(n[0]instanceof d))throw new Error("Illegal Argument");if(!(n[1]instanceof d))throw new Error("Illegal Argument");if(n.length>2&&!(n[2]instanceof d))throw new Error("Illegal Argument");return 2===n.length?O(n[0],n[1]):b(n[0],n[1],n[2])}))},P.isselfintersecting=function(e,r){return M(e,r,(function(r,n,o){o=s(o),t(o,1,1);let l=o[0];if(l instanceof F)return l.isSelfIntersecting;if(l instanceof S)return l=l.paths,x(l);if(l instanceof A){const e=l.points;for(let r=0;r<e.length;r++)for(let n=0;n<e.length;n++)if(n!==r){let t=!0;for(let i=0;i<e[r].length;i++)if(e[r][i]!==e[n][i]){t=!1;break}if(!0===t)return!0}}return!(!i(l)&&!a(l))&&(l=E(l,e.spatialReference),null!==l&&(l=l.paths),x(l))}))}}export{P as registerFunctions};