@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.57 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 e from"../../../../../core/Error.js";import t from"../../../../../layers/support/FieldsIndex.js";import{parseField as s,parseTransform as r}from"../../../../../rest/query/operations/pbfFeatureServiceParser.js";const n=268435455;class o{constructor(){this.hasFeatures=!1,this.exceededTransferLimit=!1,this.fieldCount=0,this.featureCount=0,this.objectIdFieldIndex=0,this.vertexCount=0,this.offsets={attributes:new Array,geometry:new Array},this.centroid=new Array}}function a(a,i,c=!1){const f=1,d=3,u=9,g=12,l=13,p=15,h=a.asUnsafe(),b=h.pos(),w=new o;let m=0,y=0;const k=1,x=2,I=4,L=3;let A=null,F=null,C=null,S=!1;const j=[];for(;h.next();)switch(h.tag()){case f:A=h.getString();break;case d:F=h.getString();break;case g:C=h.processMessage(r);break;case u:if(w.exceededTransferLimit=h.getBool(),w.exceededTransferLimit){w.offsets.geometry=c?new Float64Array(8e3):new Int32Array(8e3),w.centroid=c?new Float64Array(16e3):new Int32Array(16e3);for(let e=0;e<w.centroid.length;e++)w.centroid[e]=n}break;case l:{const e=h.processMessage(s);e.index=m++,j.push(e);break}case p:{const e=h.getLength(),t=h.pos()+e;if(!w.exceededTransferLimit){const e=w.offsets.geometry,t=w.centroid;e.push(0),t.push(n),t.push(n)}!S&&w.exceededTransferLimit&&(S=!0,w.offsets.attributes=c?new Float64Array(8e3*m):new Uint32Array(8e3*m));let s=y*m;for(;h.pos()<t&&h.next();)switch(h.tag()){case k:{if(S)w.offsets.attributes[s++]=h.pos();else{w.offsets.attributes.push(h.pos())}const e=h.getLength();h.skipLen(e);break}case x:if(i){const e=h.getLength(),t=h.pos()+e;for(;h.pos()<t&&h.next();)switch(h.tag()){case L:{h.getUInt32();const e=h.getSInt64(),t=h.getSInt64();w.centroid[2*y]=e,w.centroid[2*y+1]=t;break}default:h.skip()}}else{w.offsets.geometry[y]=h.pos();const e=h.getLength();w.vertexCount+=e,h.skipLen(e)}break;case I:{const e=h.getLength(),t=h.pos()+e;for(;h.pos()<t&&h.next();)switch(h.tag()){case L:{h.getUInt32();const e=h.getSInt64(),t=h.getSInt64();w.centroid[2*y]=e,w.centroid[2*y+1]=t;break}default:h.skip()}break}default:h.skip()}y++,w.hasFeatures=!0;break}default:h.skip()}const U=A||F;if(!U)throw new e("FeatureSet has no objectId or globalId field name");return w.fields=new t(j),w.featureCount=y,w.fieldCount=m,w.objectIdFieldIndex=w.fields.get(U)?.index,w.transform=C,w.displayIds=new Uint32Array(w.featureCount),w.groupIds=new Uint16Array(w.featureCount),h.move(b),w}export{o as FeatureSetHeader,a as parseHeader};