@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.27 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{getKey as e}from"../../../core/object.js";import{ProtoFeatureCollection as t,ProtoInboundFeatureCollectionRequiredAttributes as s,Feature as a,Transform as r,Field as o,CompressedGeometry as n}from"../ProtoFeatureCollection.js";import{EsriGeometryTypes as l,EsriFieldTypes as i}from"../types.js";import{WasmQuantizeOriginPositionTypeCode as c,SqlTypeCode as d}from"./WasmSerializedLayerData.js";function u(r){const o=new t;o.version=r.version;const n=r.get_query_result();if(0!==n.results_type.value)throw new Error("Got a non-feature collection type");const i=n.get_feature_result(),c=o.queryResult.featureResult;c.objectIdFieldName=i.objectid_field_name,c.exceededTransferLimit=i.exceeded_transfer_limit,c.hasM=i.has_m,c.hasZ=i.has_z,c.geometryType=e(l,i.geometry_type.value),c.globalIdFieldName=i.globalid_field_name,c.geohashFieldName=i.geohash_field_name;const d=c.uniqueIdField,u=i.unique_id_field;d.name=u.name,d.isSystemMaintained=u.isSystemMaintained;const _=c.geometryProperties,y=i.geometry_properties;_.shapeAreaFieldName=y.shapeAreaFieldName,_.shapeLengthFieldName=y.shapeLengthFieldName,_.units=y.units;const h=c.spatialReference,v=i.spatial_reference;h.wkid=v.wkid,h.latestWkid=v.latestWkid,h.vcsWkid=v.vcsWkid,h.latestVcsWkid=v.latestVcsWkid,h.wkt=v.wkt,c.transform=p(i.transform);const T=c.fields,w=c.fieldNameToAttributeIndexMap,z=i.fields,F=z.size();for(let e=0;e<F;e++){const t=z.get(e),s=f(t);T.push(s),w[s.name]=e,t.delete()}z.delete();const S=c.values,b=i.values_count();for(let e=0;e<b;e++)S.push(i.get_value_at(e));const k=c.features,q=i.features,x=q.size();if(x>0)for(const e of s)if(void 0===w[e])throw new Error(`Feature collection missing required attribute: ${e}`);for(let e=0;e<x;e++){const t=new a,s=q.get(e),r=t.attributes,o=s.attributes_count();for(let e=0;e<o;e++)r.push(s.get_attribute_at(e));const n=s.get_compressed_geometry();n&&(t.compressedGeometry=m(n),t.centroid=m(s.get_centroid()));const l=t.aggregateGeometries,i=s.aggregate_geometries,c=i.size();for(let e=0;e<c;e++){const t=i.get(e),s=m(t);l.push(s),t.delete()}i.delete(),k.push(t),s.delete()}q.delete();const N=c.geometryFields,j=i.geometry_fields,W=j.size();for(let e=0;e<W;e++){const t=j.get(e),s=g(t);N.push(s),t.delete()}return j.delete(),o}function m(t){const s=new n;s.geometryType=e(l,t.geometry_type.value);const a=[],r=[];for(let e=0;e<t.lengths.length;e++)a.push(t.lengths[e]);for(let e=0;e<t.coords.length;e++)r.push(t.coords[e]);return s.lengths=a,s.coords=r,s}function f(t){const s=new o;return s.name=t.name,s.alias=t.alias,s.fieldType=e(i,t.field_type.value),s.sqlType=e(d,t.sql_type.value),s.domain=t.domain,s.defaultValue=t.default_value,s}function g(t){const s=f(t);return s.geometryType=e(l,t.geometry_type.value),s}function p(t){const s=new r;s.quantizeOriginPosition=e(c,t.quantizeOriginPosition.value);const a=s.scale,o=t.scale;a.xScale=o.xScale,a.yScale=o.yScale,a.mScale=o.mScale,a.zScale=o.zScale;const n=s.translate,l=t.translate;return n.xTranslate=l.xTranslate,n.yTranslate=l.yTranslate,n.mTranslate=l.mTranslate,n.zTranslate=l.zTranslate,s}export{m as wasmToCompressedGeometry,f as wasmToField,g as wasmToGeometryField,u as wasmToProtoFeatureCollection,p as wasmToTransform};