@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 8.65 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__addDisposableResource as e,__disposeResources as t}from"tslib";import s from"../../../core/Error.js";import r from"../../../core/pbf.js";import{featureGeometryTypeKebabDictionary as n}from"../../../geometry/support/typeUtils.js";const a=["esriGeometryPoint","esriGeometryMultipoint","esriGeometryPolyline","esriGeometryPolygon"],o=["esriFieldTypeSmallInteger","esriFieldTypeInteger","esriFieldTypeSingle","esriFieldTypeDouble","esriFieldTypeString","esriFieldTypeDate","esriFieldTypeOID","esriFieldTypeGeometry","esriFieldTypeBlob","esriFieldTypeRaster","esriFieldTypeGUID","esriFieldTypeGlobalID","esriFieldTypeXML","esriFieldTypeBigInteger","esriFieldTypeDateOnly","esriFieldTypeTimeOnly","esriFieldTypeTimestampOffset"],i=["sqlTypeBigInt","sqlTypeBinary","sqlTypeBit","sqlTypeChar","sqlTypeDate","sqlTypeDecimal","sqlTypeDouble","sqlTypeFloat","sqlTypeGeometry","sqlTypeGUID","sqlTypeInteger","sqlTypeLongNVarchar","sqlTypeLongVarbinary","sqlTypeLongVarchar","sqlTypeNChar","sqlTypeNVarchar","sqlTypeOther","sqlTypeReal","sqlTypeSmallInt","sqlTypeSqlXml","sqlTypeTime","sqlTypeTimestamp","sqlTypeTimestamp2","sqlTypeTinyInt","sqlTypeVarbinary","sqlTypeVarchar"],c=["upperLeft","lowerLeft"];function l(e,t){const s=e.getEnum();return s<t.length?t[s]:void 0}function u(e,t){e.featureSet.geometryType=e.usesShortGeometryTypes?n.fromJSON(t):t}function g(e,t=e.featureSet.geometryType){return e.usesShortGeometryTypes?n.toJSON(t):t}function p(e){const t=e.asUnsafe();for(;t.next();)switch(t.tag()){case 1:return t.getString();case 2:return t.getFloat();case 3:return t.getDouble();case 4:return t.getSInt32();case 5:return t.getUInt32();case 6:return t.getInt64();case 7:return t.getUInt64();case 8:return t.getSInt64();case 9:return t.getBool();default:return t.skip(),null}return null}function f(e){const t=e.asUnsafe(),s={type:o[0]};for(;t.next();)switch(t.tag()){case 1:s.name=t.getString();break;case 2:s.type=l(t,o);break;case 3:s.alias=t.getString();break;case 4:s.sqlType=l(t,i);break;case 5:default:t.skip();break;case 6:s.defaultValue=t.getString()}return s}function y(e){const t={},s=e.asUnsafe();for(;s.next();)switch(s.tag()){case 1:t.name=s.getString();break;case 2:t.isSystemMaintained=s.getBool();break;default:s.skip()}return t}let d=[];function h(e,t,s){let r=g(t),n=0;const o=e.asUnsafe();for(;o.next();)switch(o.tag()){case 1:1===s?r=g(t,l(o,a)):o.skip();continue;case 2:for(const e=o.getPackedEnd();o.pos()<e;)d[n++]=o.getUInt32();continue;case 3:n>0?(d.length=n,null!=t.geometry(s,r,d)&&(d=[])):t.geometry(s,r,[]);for(const e=o.getPackedEnd();o.pos()<e;)t.coord(o.getSInt64());continue;default:o.skip()}}function m(e,t){const s=[],r=e.asUnsafe();for(;r.next();)if(3!==r.tag())r.skip();else for(const e=r.getPackedEnd();r.pos()<e;)s.push(r.getSInt64());t.centroid(s)}let k=[],T=[],b=[];function S(s,r){const n={stack:[],error:void 0,hasError:!1};try{let o=0;const i=d;let c=0;const l=s.asUnsafe(),u=e(n,l.clonePooled().asUnsafe(),!1);for(;l.next();)switch(l.tag()){case 2:for(const p=l.getPackedEnd();l.pos()<p;)i[o++]=l.getUInt32();continue;case 3:if(!("curvedGeometry"in r))throw new Error(`Tried to parse curved geometry in a ${r.constructor.name}, which doesn't support them.`);l.processMessageWithArgs(I,c++);continue;case 4:{const f=l.getUInt32(),y=l.pos()+f;if(0===c||0===o||0===f){l.move(y);continue}i.length=o,b.length=T.length=c,r.curvedGeometry(g(r),i,T,b);const{hasZ:h,hasM:m}=r.featureSet,S=[],q=[0,0];function w(){for(let e=0;e<q.length;++e)S[e]=q[e],q[e]=l.getSInt64()}h&&q.push(0),m&&q.push(0);const F=[0,0],U=[0,0],D=F,M=F;let x=0;for(let G=0;G<o;++G){w(),S.fill(0),r.startCurvedPart(q);for(const E=x+i[G];x<E;++x){const v=T[x],A=b[x];switch(v){case 0:for(let P=0;P<A;++P)w(),q[0]+=S[0],q[1]+=S[1],r.lineSegment(S,q);continue;case 1:for(let W=0;W<A;++W)w(),D[0]=l.getSInt64(),D[1]=l.getSInt64(),r.circularArcSegment(S,q,D);continue;case 2:for(let O=0;O<A;++O)w(),F[0]=l.getSInt64(),F[1]=l.getSInt64(),U[0]=l.getSInt64(),U[1]=l.getSInt64(),r.bezierSegment(S,q,F,U);continue;case 3:u.move(k[x]);if(u.getUInt32()<7*A)throw new Error("Not implemented: compressed full circle encoding");for(let B=0;B<A;++B){w(),M[0]=u.getDouble(),M[1]=u.getDouble();const N=u.getDouble(),V=u.getDouble(),L=u.getDouble(),C=u.getDouble(),R=u.getDouble();r.ellipticArcSegment(S,q,M,N,V,L,C,R)}continue}}r.finishCurvedPart(q)}continue}default:l.skip()}}catch(a){n.error=a,n.hasError=!0}finally{t(n)}}function I(e,t){const s=e.asUnsafe();let r=0,n=0,a=0;for(;s.next();)switch(s.tag()){case 1:r=s.getEnum();continue;case 2:n=s.getUInt32();continue;case 3:a=s.pos(),s.skip();continue;default:s.skip()}if(3===r&&0===a)throw new Error("An elliptic arc segment set did not include a parameters array");T[t]=r,b[t]=n,k[t]=a}function q(e,t){t.feature();const s=t.featureSet.features.at(-1);let r=0;const{fields:n}=t.featureSet;for(;e.next();)switch(e.tag()){case 1:if(null==n)throw new Error("A Feature had attributes but the FeatureResult didn't include any fields");s.attributes[n[r++].name]=e.processMessage(p);continue;case 2:e.processMessageWithArgs(h,t,0);continue;case 4:e.processMessageWithArgs(m,t);continue;case 7:e.processMessageWithArgs(S,t);continue;default:e.skip();continue}t.finishFeature?.()}function w(e){const t=[1,1,1,1],s=e.asUnsafe();for(;s.next();)switch(s.tag()){case 1:t[0]=s.getDouble();break;case 2:t[1]=s.getDouble();break;case 4:t[2]=s.getDouble();break;case 3:t[3]=s.getDouble();break;default:s.skip()}return t}function F(e){const t=[0,0,0,0],s=e.asUnsafe();for(;s.next();)switch(s.tag()){case 1:t[0]=s.getDouble();break;case 2:t[1]=s.getDouble();break;case 4:t[2]=s.getDouble();break;case 3:t[3]=s.getDouble();break;default:s.skip()}return t}function U(e){const t={originPosition:c[0]},s=e.asUnsafe();for(;s.next();)switch(s.tag()){case 1:t.originPosition=l(s,c);break;case 2:t.scale=s.processMessage(w);break;case 3:t.translate=s.processMessage(F);break;default:s.skip()}return t}function D(e){const t={},s=e.asUnsafe();for(;s.next();)switch(s.tag()){case 1:t.shapeAreaFieldName=s.getString();break;case 2:t.shapeLengthFieldName=s.getString();break;case 3:t.units=s.getString();break;default:s.skip()}return t}function M(e){const t={};for(;e.next();)switch(e.tag()){case 1:t.wkid=e.getUInt32();break;case 5:t.wkt=e.getString();break;case 2:t.latestWkid=e.getUInt32();break;case 3:t.vcsWkid=e.getUInt32();break;case 4:t.latestVcsWkid=e.getUInt32();break;default:e.skip()}return t}function x(e,t){const s=e.asUnsafe();if(t.featureSet.features.length=0,"features"===t.parseOnly?.type){const e=t.parseOnly.indices.values();let r=0,n=e.next().value;for(;s.next();)15===s.tag()&&r++===n?(n=e.next().value,s.processMessageWithArgs(q,t)):s.skip();return}let r=!1;for("metadata"===t.parseOnly?.type&&(r=!0,t.parseOnly.featureCount=0),u(t,"esriGeometryPoint");s.next();)switch(s.tag()){case 1:t.idField(s.getString());continue;case 3:t.featureSet.globalIdFieldName=s.getString();continue;case 4:t.featureSet.geohashFieldName=s.getString();continue;case 5:t.featureSet.geometryProperties=s.processMessage(D);continue;case 7:u(t,l(s,a));continue;case 8:t.featureSet.spatialReference=s.processMessageWithArgs(M);continue;case 10:t.featureSet.hasZ=s.getBool();continue;case 11:t.featureSet.hasM=s.getBool();continue;case 12:t.featureSet.transform=s.processMessage(U);continue;case 9:t.featureSet.exceededTransferLimit=s.getBool();continue;case 13:t.featureSet.fields??=[],t.featureSet.fields.push(s.processMessage(f));continue;case 15:if(r){++t.parseOnly.featureCount,s.skip();continue}s.processMessageWithArgs(q,t);continue;case 2:t.idField(s.processMessage(y));continue;default:s.skip()}}function G(e,t,s){let r=-1;for(;e.next();)switch(e.tag()){case 4:r=e.pos(),e.skip();continue;case 1:e.processMessageWithArgs(x,t);continue;default:e.skip()}if(-1!==r){if(!t.queryGeometry()){const s=e.pos();e.move(r),e.processMessageWithArgs(h,t,1),e.move(s)}s.queryGeometryType=t.queryGeometryType(),s.queryGeometry=t.queryGeometry()}t.finish(),s.featureResult=t.featureSet}function E(n,a){const o={stack:[],error:void 0,hasError:!1};try{e(o,{[Symbol.dispose](){d=[],k=[],T=[],b=[]}},!1);try{const s={stack:[],error:void 0,hasError:!1};try{const t=e(s,r.constructPooled(new Uint8Array(n),new DataView(n)),!1);let o;for(;t.next();)if(2===t.tag())o={},t.processMessageWithArgs(G,a,o);else t.skip();return o}catch(i){s.error=i,s.hasError=!0}finally{t(s)}}catch(c){throw new s("query:parsing-pbf","Error while parsing FeatureSet PBF payload",{error:c})}}catch(l){o.error=l,o.hasError=!0}finally{t(o)}}export{E as parseFeatureQuery,f as parseField,U as parseTransform};