@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.64 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import e from"../../../core/Error.js";import t from"../../../geometry/Multipoint.js";import o from"../../../geometry/Point.js";import s from"../../../geometry/Polygon.js";import r from"../../../geometry/Polyline.js";import{WasmGeometryTypeCodes as n}from"./KnowledgeWasmInterface.js";function a(e,o){const s={spatialReference:o},r=c(e,s),n=e.lengths,a=e.coords,h=n[0];s.points=[];let l=0;for(let t=0;t<h;t++){const e=[];for(let t=0;t<r;t++)e[t]=a[l],l++;s.points.push(e)}return new t(s)}function h(e,t){const s={spatialReference:t};let r=2;c(e,s);const n=e.coords;return s.x=n[0],s.y=n[1],e.has_z&&(s.z=n[r],r++),e.has_m&&(s.m=n[r]),new o(s)}function l(e,t){const{paths:o,hasM:s,hasZ:a}=p(e,n.ESRI_GEOMETRY_POLYLINE);return new r({paths:o,hasM:s,hasZ:a,spatialReference:t})}function i(e,t){const{paths:o,hasM:r,hasZ:a}=p(e,n.ESRI_GEOMETRY_POLYGON);return new s({rings:o,hasM:r,hasZ:a,spatialReference:t})}function p(t,o){const s={paths:[],hasM:!1,hasZ:!1},r=c(t,s),{coords:n,geometry_type:a,lengths:h}=t;if(a.value!==o)throw new e("KnowledgeGraph:illegal-geometry-type","Illegal Geometry type for multipath conversion");let l=0;return h.forEach((e=>{const t=[];for(let o=0;o<e;o++){const e=[];for(let t=0;t<r;t++)e[t]=n[l],l++;t.push(e)}s.paths.push(t)})),s}function c(e,t){let o=2;return e.has_z?(t.hasZ=e.has_z,o++):t.hasZ=!1,e.has_m?(t.hasM=e.has_m,o++):t.hasM=!1,o}export{a as wasmToMultipointGeometry,h as wasmToPointGeometry,i as wasmToPolygonGeometry,l as wasmToPolylineGeometry};