UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 1.8 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{generateUID as e}from"../../../core/uid.js";import{WorkerHandle as r}from"../../../core/workers/WorkerHandle.js";import s from"../../../geometry/SpatialReference.js";import o from"../../../layers/support/Field.js";class t{constructor(e){this._controller=e,this._handle=new n((r=>e.schedule(r)))}destroy(){this._handle.destroy()}invoke(r,t){return r.buffer&&0!==r.buffer.byteLength?(r.options.sourceSpatialReference&&r.options.sourceSpatialReference instanceof s&&(r.options={...r.options,sourceSpatialReference:r.options.sourceSpatialReference.toJSON()}),this._handle.invoke(r,t).then((r=>{let t=0,n=0;const i=s.fromJSON(r.spatialReference);r.spatialReference=i;const p=async s=>{const c=r.fields;if(c)for(;t<c.length;)if(c[t]=o.fromJSON(c[t]),t++,s.madeProgress())return this._controller.reschedule((e=>p(e)));const l=r.features;for(;n<l.length;){const r=l[n];++n,r.uid=e();const o=r.geometry;if(null!=o&&(o.spatialReference=i,a(o),s.madeProgress()))return this._controller.reschedule((e=>p(e)))}return r};return this._controller.schedule((e=>p(e)))}))):Promise.resolve(null)}}function a(e){switch(e.type){case"polyline":e.paths=e.hasZ&&e.hasM?e.paths.map((e=>e.map((e=>[e[0],e[1],e[2],e[3]])))):e.hasZ||e.hasM?e.paths.map((e=>e.map((e=>[e[0],e[1],e[2]])))):e.paths.map((e=>e.map((e=>[e[0],e[1]]))));break;case"polygon":e.rings=e.hasZ&&e.hasM?e.rings.map((e=>e.map((e=>[e[0],e[1],e[2],e[3]])))):e.hasZ||e.hasM?e.rings.map((e=>e.map((e=>[e[0],e[1],e[2]])))):e.rings.map((e=>e.map((e=>[e[0],e[1]]))))}}class n extends r{constructor(e){super("PBFDecoderWorker","_parseFeatureQuery",{_parseFeatureQuery:e=>[e.buffer]},e)}}export{t as PBFDecoder};