@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.65 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Error.js";import r from"../../../core/Loadable.js";import o from"../../../core/Logger.js";import{throwIfAborted as i}from"../../../core/promiseUtils.js";import{getFilename as a}from"../../../core/urlUtils.js";import{property as s}from"../../../core/accessorSupport/decorators/property.js";import{subclass as n}from"../../../core/accessorSupport/decorators/subclass.js";import l from"../../../geometry/SpatialReference.js";import{createDrawingInfo as p}from"./support/clientSideDefaults.js";import{inferGeometrySource as m}from"../../support/parquetLayerUtils.js";import{ParquetMetadata as c}from"../../../libs/parquet/parquet.js";import{toJSONGeometryType as u}from"../../../views/2d/layers/support/util.js";const d=["parquet"];let f=class extends r{constructor(e){super(e),this.type="parquet"}load(e){const t=null!=e?e.signal:null;return this.addResolvingPromise(this._initialize(t)),Promise.resolve(this)}async _initialize(e){const r=this.loadOptions.url;if(null==r)throw new t("missing-metadata","Unable to create parquet source: no url specified",this.loadOptions);const o=this.loadOptions.metadata??await c.create(r,(()=>this.customParameters));i(e);const s=this._createGeometrySource(o,this.loadOptions);if(null==s)throw new t("missing-metadata","Unable to create parquet source: cannot infer geometrySource",this.loadOptions);const n=[...o.fields];this.loadOptions.objectIdField||n.push({name:"__OBJECTID",type:"esriFieldTypeOID",alias:"__OBJECTID"}),this.geometryInfo=s,this.sourceJSON={name:a(r,d)||"parquet",drawingInfo:p(u(s.geometryType)),geometryType:u(s.geometryType),spatialReference:s.spatialReference,objectIdField:this.loadOptions.objectIdField??"__OBJECTID",fields:n}}_createGeometrySource(e,t){const r=t.geometrySourceInfo??m(e);if(!r)return null;switch(r.type){case"location":return this._createLocationInfo(r);case"geometry":return this._createGeometryInfo(r)}}_createLocationInfo(e){if(null==e.latitudeFieldName)throw new t("missing-metadata","Missing latitudeFieldName",e);if(null==e.longitudeFieldName)throw new t("missing-metadata","Missing longitudeFieldName",e);return{type:"location",latitudeFieldName:e.latitudeFieldName,longitudeFieldName:e.longitudeFieldName,geometryType:"point",spatialReference:e.spatialReference??l.WGS84}}_createGeometryInfo(e){if(null==e.geometryType)throw new t("missing-metadata","Missing geometryType",e);const r=e.spatialReference;if(null==r)throw new t("missing-metadata","Missing spatialReference",e);let i="toJSON"in r?e.spatialReference:l.fromJSON(e.spatialReference);if(i.wkid!==l.WGS84.wkid){if(!i.isGeographic&&!i.isWebMercator)throw new t("unsupported-spatial-reference","Only WGS84 and WebMercator are currently supported",e);o.getLogger("parquet-support").warn("Found a geographic projection that is not WGS84. Handling as WGS84.",e),i=l.WGS84}if(null==e.primaryFieldName)throw new t("missing-metadata","Missing primaryFieldName",e);if("WKB"!==e.format)throw new t("unsupported","Geometry encoding must be 'WKB'",e);return{type:"geometry",format:"WKB",spatialReference:i,primaryFieldName:e.primaryFieldName,geometryType:e.geometryType,multiscale:e.multiscale}}};e([s()],f.prototype,"type",void 0),e([s()],f.prototype,"loadOptions",void 0),e([s()],f.prototype,"sourceJSON",void 0),e([s()],f.prototype,"geometryInfo",void 0),e([s()],f.prototype,"customParameters",void 0),f=e([n("esri.layers.graphics.sources.ParquetSource")],f);export{f as ParquetSource};