@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.88 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{P as e}from"../../../chunks/Point2D.js";import"../../../chunks/Envelope2D.js";import{G as t}from"../../../chunks/Geometry.js";import{E as n,P as a}from"../../../chunks/Envelope.js";import{M as s}from"../../../chunks/MultiPathImpl.js";import r from"../../Extent.js";import o from"../../Multipoint.js";import u from"../../Point.js";import i from"../../Polygon.js";import c from"../../Polyline.js";import"./initNoPeFactory.js";import{toGeometry as l,fromSpatialReference as h,fromGeometryToGXGeometry as m,fromGeometryToGXGeometryUsingImportOperator as f}from"./jsonConverter.js";const p="_gxVersion",g=2,y=1;function C(e){return Array.isArray(e)?e[0].spatialReference:e.spatialReference}function M(e){switch(e.type){case"point":return v(e);case"multipoint":return x(e);case"polyline":return Z(e);case"polygon":return P(e);case"extent":return V(e);default:throw new Error(`Unsupported geometry type: ${e.type}`)}}function V(e){if(!e.getCacheValue(p)){const t=new n;t.setCoords(e.xmin,e.ymin,e.xmax,e.ymax),e.hasM&&t.setInterval(g,0,e.mmin,e.mmax),e.hasZ&&t.setInterval(y,0,e.zmin,e.zmax),e.setCacheValue(p,t)}return e.getCacheValue(p)}function x(e){if(!e.getCacheValue(p)){const t=new s,n=new a,r=e.points,o=e.hasM,u=e.hasZ,i=u?3:2;for(let e=0,a=r.length;e<a;e++){const a=r[e];n.setXYCoords(a[0],a[1]),u&&n.setZ(a[2]??0),o&&n.setM(a[i]??NaN),t.add(n)}e.setCacheValue(p,t)}return e.getCacheValue(p)}function v(e){if(!e.getCacheValue(p)){const t=new a;t.setXYCoords(e.x,e.y),e.hasM&&t.setM(e.m),e.hasZ&&t.setZ(e.z),e.setCacheValue(p,t)}return e.getCacheValue(p)}function P(e){if(!e.getCacheValue(p)){const{curveRings:t,hasM:n,hasZ:a,rings:s}=e,r=m({curveRings:t,hasM:n,hasZ:a,rings:s});e.setCacheValue(p,r)}return e.getCacheValue(p)}function Z(e){if(!e.getCacheValue(p)){const{curvePaths:t,hasM:n,hasZ:a,paths:s}=e,r=m({curvePaths:t,hasM:n,hasZ:a,paths:s});e.setCacheValue(p,r)}return e.getCacheValue(p)}function j(e){if(!e.getCacheValue(p)){const{curvePaths:t,hasM:n,hasZ:a,paths:s}=e,r=f({curvePaths:t,hasM:n,hasZ:a,paths:s});e.setCacheValue(p,r)}return e.getCacheValue(p)}function w(e){return h(e)}function E(e,n){if(e)switch(e.getGeometryType()){case t.enumPoint:return z(e,n);case t.enumEnvelope:return R(e,n);case t.enumMultiPoint:return d(e,n);case t.enumPolyline:return Y(e,n);case t.enumPolygon:return X(e,n)}return null}function R(e,t){if(e.isEmpty())return null;const n=new r({xmin:e.getXMin(),ymin:e.getYMin(),xmax:e.getXMax(),ymax:e.getYMax(),spatialReference:t}),a=e.getDescription();if(a.hasM()){const t=e.queryInterval(g,0);n.mmin=t.vmin,n.mmax=t.vmax}if(a.hasZ()){const t=e.queryInterval(y,0);n.zmin=t.vmin,n.zmax=t.vmax}return n.setCacheValue(p,e),n}function d(e,t){if(e.isEmpty())return null;const n=e.getDescription(),s=n.hasM(),r=n.hasZ(),u=[],i=new a;for(let a=0,o=e.getPointCount();a<o;a++){e.getPointByVal(a,i);const t=[i.getX(),i.getY()];r&&t.push(i.getZ()),s&&t.push(i.getM()),u.push(t)}const c=new o({hasM:s,hasZ:r,points:u,spatialReference:t});return c.setCacheValue(p,e),c}function z(t,n){if(t instanceof e)return new u({x:t.x,y:t.y,spatialReference:n});if(t.isEmpty())return null;const a=new u({x:t.getX(),y:t.getY(),spatialReference:n}),s=t.getDescription();return s.hasM()&&(a.m=t.getM()),s.hasZ()&&(a.z=t.getZ()),a.setCacheValue(p,t),a}function X(e,t){if(e.isEmpty())return null;const n=i.fromJSON({...l(e,null),spatialReference:t});return n.setCacheValue(p,e),n}function Y(e,t){if(e.isEmpty())return null;const n=c.fromJSON({...l(e,null),spatialReference:t});return n.setCacheValue(p,e),n}export{V as fromExtent,M as fromGeometry,x as fromMultipoint,v as fromPoint,P as fromPolygon,Z as fromPolyline,j as fromPolylineUsingImportOperator,w as fromSpatialReference,C as getSpatialReference,R as toExtent,E as toGeometry,d as toMultipoint,z as toPoint,X as toPolygon,Y as toPolyline};