UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 3.32 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{ProtoFeatureCollection as e,ProtoInboundFeatureCollectionRequiredAttributes as t,Feature as a,CompressedGeometry as s,Field as r,Transform as n}from"../ProtoFeatureCollection.js";import{EsriGeometryTypes as o,EsriFieldTypes as l}from"./WasmDataModelWrapperInterfaces.js";import{SqlTypeCode as i,WasmQuantizeOriginPositionTypeCode as c}from"./WasmSerializedLayerData.js";function d(s){const r=new e;r.version=s.version;const n=s.get_query_result();if(0!==n.results_type.value)throw new Error("Got a non-feature collection type");const l=n.get_feature_result(),i=r.queryResult.featureResult;i.objectIdFieldName=l.objectid_field_name,i.exceededTransferLimit=l.exceeded_transfer_limit,i.hasM=l.has_m,i.hasZ=l.has_z,i.geometryType=o[l.geometry_type.value],i.globalIdFieldName=l.globalid_field_name,i.geohashFieldName=l.geohash_field_name;const c=i.uniqueIdField,d=l.unique_id_field;c.name=d.name,c.isSystemMaintained=d.isSystemMaintained;const p=i.geometryProperties,_=l.geometry_properties;p.shapeAreaFieldName=_.shapeAreaFieldName,p.shapeLengthFieldName=_.shapeLengthFieldName,p.units=_.units;const y=i.spatialReference,h=l.spatial_reference;y.wkid=h.wkid,y.latestWkid=h.latestWkid,y.vcsWkid=h.vcsWkid,y.latestVcsWkid=h.latestVcsWkid,y.wkt=h.wkt,i.transform=g(l.transform);const v=i.fields,T=i.fieldNameToAttributeIndexMap,w=l.fields,z=w.size();for(let e=0;e<z;e++){const t=w.get(e),a=m(t);v.push(a),T[a.name]=e,t.delete()}w.delete();const F=i.values,S=l.values_count();for(let e=0;e<S;e++)F.push(l.get_value_at(e));const k=i.features,b=l.features,q=b.size();if(q>0)for(const e of t)if(void 0===T[e])throw new Error(`Feature collection missing required attribute: ${e}`);for(let e=0;e<q;e++){const t=new a,s=b.get(e),r=t.attributes,n=s.attributes_count();for(let e=0;e<n;e++)r.push(s.get_attribute_at(e));const o=s.get_compressed_geometry();o&&(t.compressedGeometry=u(o),t.centroid=u(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),a=u(t);l.push(a),t.delete()}i.delete(),k.push(t),s.delete()}b.delete();const W=i.geometryFields,x=l.geometry_fields,N=x.size();for(let e=0;e<N;e++){const t=x.get(e),a=f(t);W.push(a),t.delete()}return x.delete(),r}function u(e){const t=new s;t.geometryType=o[e.geometry_type.value];const a=[],r=[];for(let s=0;s<e.lengths.length;s++)a.push(e.lengths[s]);for(let s=0;s<e.coords.length;s++)r.push(e.coords[s]);return t.lengths=a,t.coords=r,t}function m(e){const t=new r;return t.name=e.name,t.alias=e.alias,t.fieldType=l[e.field_type.value],t.sqlType=i[e.sql_type.value],t.domain=e.domain,t.defaultValue=e.default_value,t}function f(e){const t=m(e);return t.geometryType=o[e.geometry_type.value],t}function g(e){const t=new n;t.quantizeOriginPosition=c[e.quantizeOriginPosition.value];const a=t.scale,s=e.scale;a.xScale=s.xScale,a.yScale=s.yScale,a.mScale=s.mScale,a.zScale=s.zScale;const r=t.translate,o=e.translate;return r.xTranslate=o.xTranslate,r.yTranslate=o.yTranslate,r.mTranslate=o.mTranslate,r.zTranslate=o.zTranslate,t}export{u as wasmToCompressedGeometry,m as wasmToField,f as wasmToGeometryField,d as wasmToProtoFeatureCollection,g as wasmToTransform};