UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 5.47 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{allocateFlatGeometry as t,writeBezierCurveSegment as e,writeCircularArcSegment as s,writeEllipticArc7Segment as r}from"../../../geometry/FlatGeometry.js";import{featureGeometryTypeKebabDictionary as i}from"../../../geometry/support/typeUtils.js";import{zScale as h}from"../../../geometry/support/zscale.js";import{FlatFeature as o}from"../../../layers/graphics/FlatFeature.js";import{FlatFeatureSet as a}from"../../../layers/graphics/FlatFeatureSet.js";import _ from"../../../layers/graphics/OptimizedGeometry.js";import{createFeatureId as n}from"../../../layers/graphics/data/createFeatureId.js";import{makeAttributesClass as f,makeVertexTransformer as m}from"./pbfFeatureSetUtils.js";class u{constructor(t){this._options=t,this.featureSet=new a,this.parseOnly=null,this._idInfo=null,this._transformInPlace=null,this._transformInPlaceXY=null,this._push=u._pushXY,this._attributesClass=null,this._previousX=0,this._previousY=0,this._vertex=[],this._i=0,this._geometry=null,this._iVertex=0,this._iPart=0,this._isPolygon=!1,this._ringEndsAt=-1}queryGeometryType(){return this.featureSet.queryGeometryType}queryGeometry(){return this.featureSet.queryGeometry}idField(t){"string"==typeof t?this._idInfo??={type:"object-id",fieldName:t}:this._idInfo={type:"unique-id-simple",fieldName:t.name}}finish(){if(this._idInfo)for(const s of this.featureSet.features)s.objectId=n(s,this._idInfo);const{spatialReference:t,features:e}=this.featureSet;if(t)for(const{geometry:s}of e)s&&(s.spatialReference=t);this.featureSet.transform=null}feature(){this._attributesClass??=f(this.featureSet.fields?.map(t=>t.name)??[]),this.featureSet.features.push(new o(null,new this._attributesClass,null,0)),this._setVertexTransformer()}centroid(t){const{hasZ:e,hasM:s}=this.featureSet;this.featureSet.features.at(-1).centroid=new _([],t,e,s)}geometry(e,s,r){this._previousX=this._previousY=0,this._i=this._iVertex=this._iPart=0;let{hasZ:h,hasM:o}=this.featureSet;h??=!1,o??=!1,this._vertex=[0,0],h&&this._vertex.push(0),o&&this._vertex.push(0);const a=i.fromJSON(s);this._isPolygon="polygon"===a;const _=Number(this._isPolygon),n="point"===a?1:r.reduce((t,e)=>t+e-_,0),f=r.length;if(this._geometry=t(a,n,f,h,o,!1),this._push=h?o?u._pushXYZM:u._pushXYZ:o?u._pushXYM:u._pushXY,this._geometry.isMultipart()){this._geometry.partOffsets[0]=0;for(let t=0;t<f;++t)this._geometry.partOffsets[t+1]=this._geometry.partOffsets[t]+r[t]-_}this._ringEndsAt=_?this._geometry.partOffsets.at(1)??0:-1,1===e?(this.featureSet.queryGeometry=this._geometry,this.featureSet.queryGeometryType=s):this.featureSet.features.at(-1).geometry=this._geometry}coord(t){const e=this._vertex;e[this._i++]=t,this._i<e.length||(this._i=0,e[0]+=this._previousX,e[1]+=this._previousY,[this._previousX,this._previousY]=e,this._iVertex===this._ringEndsAt&&(++this._iPart,this._ringEndsAt=this._geometry.partOffsets[this._iPart+1],this._previousX=this._previousY=0,this._isPolygon)||(this._transformInPlace?.(e),this._push(this)))}curvedGeometry(e,s,r,h){let{hasZ:o,hasM:a}=this.featureSet;o??=!1,a??=!1,this._i=this._iVertex=this._iPart=0;const _=i.fromJSON(e);this._isPolygon="polygon"===_;const n=Number(!this._isPolygon),f=s.length;let m=0,u=0,l=n*f;for(let t=0;t<r.length;++t)switch(l+=h[t],r[t]){case 1:case 3:m+=h[t];continue;case 2:u+=h[t]}this._geometry=t(_,l,f,o,a,!0,m,u);const{partOffsets:p}=this._geometry;p[0]=0;for(let t=0,i=0;t<f;++t){p[t+1]=p[t]+n;for(let e=0;e<s[t];++e)p[t+1]+=h[i++]}switch(e){case"esriGeometryPoint":case"esriGeometryMultipoint":throw new Error(`Curved ${e} does not make sense`)}this.featureSet.features.at(-1).geometry=this._geometry}startCurvedPart(t){}finishCurvedPart(t){this._isPolygon||(this._transform(t,this._vertex),this._push(this)),++this._iPart}lineSegment(t,e){this._transform(t,this._vertex),this._push(this)}bezierSegment(t,s,r,i){this._transform(t,this._vertex),this._push(this),this._transformXY(s,y.b[0]),this._transformXY(r,y.b[1]),this._transformXY(i,y.b[2]),this._i=e(this._vertex,y,this._geometry,this._iVertex-1,this._i)}circularArcSegment(t,e,r){this._transform(t,this._vertex),this._push(this),this._transformXY(e,l.c[0]),this._transformXY(r,l.c[1]),this._i=s(this._vertex,l,this._geometry,this._iVertex-1,this._i)}ellipticArcSegment(t,e,s,i,h,o,a,_){this._transform(t,this._vertex),this._push(this),this._transformXY(e,p.a[0]),this._transformXY(s,p.a[1]),p.a[2]=i,p.a[3]=h,p.a[4]=o,p.a[5]=a,p.a[6]=_,this._i=r(this._vertex,p,this._geometry,this._iVertex-1,this._i)}static _pushXY(t){const e=t._iVertex++,{vertexXY:s}=t._geometry;[s[2*e],s[2*e+1]]=t._vertex}static _pushXYZ(t){const e=t._iVertex++,{vertexXY:s,vertexZ:r}=t._geometry;[s[2*e],s[2*e+1],r[e]]=t._vertex}static _pushXYM(t){const e=t._iVertex++,{vertexXY:s,vertexM:r}=t._geometry;[s[2*e],s[2*e+1],r[e]]=t._vertex}static _pushXYZM(t){const e=t._iVertex++,{vertexXY:s,vertexM:r,vertexZ:i}=t._geometry;[s[2*e],s[2*e+1],i[e],r[e]]=t._vertex}_setVertexTransformer(){const{sourceSpatialReference:t}=this._options,{spatialReference:e,hasZ:s,transform:r}=this.featureSet,i=s?h(t,e):1;this._transformInPlace??=m(this.featureSet,i),this._transformInPlaceXY??=m({transform:r})}_transform(t,e){for(let s=0;s<t.length;++s)e[s]=t[s];this._transformInPlace?.(e)}_transformXY(t,e){e[0]=t[0],e[1]=t[1],this._transformInPlaceXY?.(e)}}const l={c:[[0,0],[0,0]]},p={a:[[0,0],[0,0],0,0,0,0,0]},y={b:[[0,0],[0,0],[0,0]]};export{u as FlatFeatureSetParserContext};