createPolygonOutlineGeometry.js 7.2 KB

1
  1. define(["./when-4bbc8319","./Matrix2-ccd5b911","./ArcType-98ec98bf","./GeometryOffsetAttribute-1772960d","./Transforms-d5c6ad6e","./RuntimeError-346a3079","./ComponentDatatype-93750d1a","./EllipsoidTangentPlane-e000bae1","./GeometryAttribute-c30799b8","./GeometryAttributes-7827a6c2","./GeometryInstance-5f4fe82b","./GeometryPipeline-548e76d2","./IndexDatatype-b7d979a6","./PolygonGeometryLibrary-d35c292d","./PolygonPipeline-83fb62b0","./combine-83860057","./WebGLConstants-1c8239cc","./AxisAlignedBoundingBox-883f9c89","./IntersectionTests-4d6f5c54","./Plane-18bb00f8","./AttributeCompression-1f045b73","./EncodedCartesian3-08b8d980","./arrayRemoveDuplicates-18786327","./EllipsoidRhumbLine-aa9e6266"],function(h,d,E,b,P,e,A,_,v,G,L,T,H,O,x,t,i,r,o,n,a,l,s,y){"use strict";var C=[],D=[];function c(e){var t,i=e.polygonHierarchy,r=h.defaultValue(e.ellipsoid,d.Ellipsoid.WGS84),o=h.defaultValue(e.granularity,A.CesiumMath.RADIANS_PER_DEGREE),n=h.defaultValue(e.perPositionHeight,!1),a=n&&h.defined(e.extrudedHeight),l=h.defaultValue(e.arcType,E.ArcType.GEODESIC),s=h.defaultValue(e.height,0),y=h.defaultValue(e.extrudedHeight,s);a||(t=Math.max(s,y),y=Math.min(s,y),s=t),this._ellipsoid=d.Ellipsoid.clone(r),this._granularity=o,this._height=s,this._extrudedHeight=y,this._arcType=l,this._polygonHierarchy=i,this._perPositionHeight=n,this._perPositionHeightExtrude=a,this._offsetAttribute=e.offsetAttribute,this._workerName="createPolygonOutlineGeometry",this.packedLength=O.PolygonGeometryLibrary.computeHierarchyPackedLength(i)+d.Ellipsoid.packedLength+8}c.pack=function(e,t,i){return i=h.defaultValue(i,0),i=O.PolygonGeometryLibrary.packPolygonHierarchy(e._polygonHierarchy,t,i),d.Ellipsoid.pack(e._ellipsoid,t,i),i+=d.Ellipsoid.packedLength,t[i++]=e._height,t[i++]=e._extrudedHeight,t[i++]=e._granularity,t[i++]=e._perPositionHeightExtrude?1:0,t[i++]=e._perPositionHeight?1:0,t[i++]=e._arcType,t[i++]=h.defaultValue(e._offsetAttribute,-1),t[i]=e.packedLength,t};var g=d.Ellipsoid.clone(d.Ellipsoid.UNIT_SPHERE),f={polygonHierarchy:{}};return c.unpack=function(e,t,i){t=h.defaultValue(t,0);var r=O.PolygonGeometryLibrary.unpackPolygonHierarchy(e,t);t=r.startingIndex,delete r.startingIndex;var o=d.Ellipsoid.unpack(e,t,g);t+=d.Ellipsoid.packedLength;var n=e[t++],a=e[t++],l=e[t++],s=1===e[t++],y=1===e[t++],u=e[t++],p=e[t++],t=e[t];return(i=!h.defined(i)?new c(f):i)._polygonHierarchy=r,i._ellipsoid=d.Ellipsoid.clone(o,i._ellipsoid),i._height=n,i._extrudedHeight=a,i._granularity=l,i._perPositionHeight=y,i._perPositionHeightExtrude=s,i._arcType=u,i._offsetAttribute=-1===p?void 0:p,i.packedLength=t,i},c.fromPositions=function(e){return new c({polygonHierarchy:{positions:(e=h.defaultValue(e,h.defaultValue.EMPTY_OBJECT)).positions},height:e.height,extrudedHeight:e.extrudedHeight,ellipsoid:e.ellipsoid,granularity:e.granularity,perPositionHeight:e.perPositionHeight,arcType:e.arcType,offsetAttribute:e.offsetAttribute})},c.createGeometry=function(e){var t=e._ellipsoid,i=e._granularity,r=e._polygonHierarchy,o=e._perPositionHeight,n=e._arcType,a=O.PolygonGeometryLibrary.polygonOutlinesFromHierarchy(r,!o,t);if(0!==a.length){var l,s,y,u,p,d,c=[],g=A.CesiumMath.chordLength(i,t.maximumRadius),f=e._height,m=e._extrudedHeight;if(e._perPositionHeightExtrude||!A.CesiumMath.equalsEpsilon(f,m,0,A.CesiumMath.EPSILON2))for(l=0;l<a.length;l++)(u=function(e,t,i,r,o){var n,a=_.EllipsoidTangentPlane.fromPoints(t,e).projectPointsOntoPlane(t,C);x.PolygonPipeline.computeWindingOrder2D(a)===x.WindingOrder.CLOCKWISE&&(a.reverse(),t=t.slice().reverse());var l=t.length,s=new Array(l),y=0;if(r)for(n=new Float64Array(2*l*3*2),b=0;b<l;++b){s[b]=y/3;var u=t[b],p=t[(b+1)%l];n[y++]=u.x,n[y++]=u.y,n[y++]=u.z,n[y++]=p.x,n[y++]=p.y,n[y++]=p.z}else{var d,c=0;if(o===E.ArcType.GEODESIC)for(b=0;b<l;b++)c+=O.PolygonGeometryLibrary.subdivideLineCount(t[b],t[(b+1)%l],i);else if(o===E.ArcType.RHUMB)for(b=0;b<l;b++)c+=O.PolygonGeometryLibrary.subdivideRhumbLineCount(e,t[b],t[(b+1)%l],i);for(n=new Float64Array(3*c*2),b=0;b<l;++b){s[b]=y/3,o===E.ArcType.GEODESIC?d=O.PolygonGeometryLibrary.subdivideLine(t[b],t[(b+1)%l],i,D):o===E.ArcType.RHUMB&&(d=O.PolygonGeometryLibrary.subdivideRhumbLine(e,t[b],t[(b+1)%l],i,D));for(var g=d.length,f=0;f<g;++f)n[y++]=d[f]}}for(var l=n.length/6,m=s.length,h=H.IndexDatatype.createTypedArray(l+m,2*(2*l+m)),y=0,b=0;b<l;++b)h[y++]=b,h[y++]=(b+1)%l,h[y++]=b+l,h[y++]=(b+1)%l+l;for(b=0;b<m;b++){var P=s[b];h[y++]=P,h[y++]=P+l}return new L.GeometryInstance({geometry:new v.Geometry({attributes:new G.GeometryAttributes({position:new v.GeometryAttribute({componentDatatype:A.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:n})}),indices:h,primitiveType:v.PrimitiveType.LINES})})}(t,a[l],g,o,n)).geometry=O.PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(u.geometry,f,m,t,o),h.defined(e._offsetAttribute)&&(s=u.geometry.attributes.position.values.length/3,y=new Uint8Array(s),y=e._offsetAttribute===b.GeometryOffsetAttribute.TOP?b.arrayFill(y,1,0,s/2):(d=e._offsetAttribute===b.GeometryOffsetAttribute.NONE?0:1,b.arrayFill(y,d)),u.geometry.attributes.applyOffset=new v.GeometryAttribute({componentDatatype:A.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:y})),c.push(u);else for(l=0;l<a.length;l++)(u=function(e,t,i,r,o){var n,a=_.EllipsoidTangentPlane.fromPoints(t,e).projectPointsOntoPlane(t,C);x.PolygonPipeline.computeWindingOrder2D(a)===x.WindingOrder.CLOCKWISE&&(a.reverse(),t=t.slice().reverse());var l=t.length,s=0;if(r)for(n=new Float64Array(2*l*3),m=0;m<l;m++){var y=t[m],u=t[(m+1)%l];n[s++]=y.x,n[s++]=y.y,n[s++]=y.z,n[s++]=u.x,n[s++]=u.y,n[s++]=u.z}else{var p,d=0;if(o===E.ArcType.GEODESIC)for(m=0;m<l;m++)d+=O.PolygonGeometryLibrary.subdivideLineCount(t[m],t[(m+1)%l],i);else if(o===E.ArcType.RHUMB)for(m=0;m<l;m++)d+=O.PolygonGeometryLibrary.subdivideRhumbLineCount(e,t[m],t[(m+1)%l],i);for(n=new Float64Array(3*d),m=0;m<l;m++){o===E.ArcType.GEODESIC?p=O.PolygonGeometryLibrary.subdivideLine(t[m],t[(m+1)%l],i,D):o===E.ArcType.RHUMB&&(p=O.PolygonGeometryLibrary.subdivideRhumbLine(e,t[m],t[(m+1)%l],i,D));for(var c=p.length,g=0;g<c;++g)n[s++]=p[g]}}for(var l=n.length/3,f=H.IndexDatatype.createTypedArray(l,2*l),s=0,m=0;m<l-1;m++)f[s++]=m,f[s++]=m+1;return f[s++]=l-1,f[s++]=0,new L.GeometryInstance({geometry:new v.Geometry({attributes:new G.GeometryAttributes({position:new v.GeometryAttribute({componentDatatype:A.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:n})}),indices:f,primitiveType:v.PrimitiveType.LINES})})}(t,a[l],g,o,n)).geometry.attributes.position.values=x.PolygonPipeline.scaleToGeodeticHeight(u.geometry.attributes.position.values,f,t,!o),h.defined(e._offsetAttribute)&&(p=u.geometry.attributes.position.values.length,p=new Uint8Array(p/3),d=e._offsetAttribute===b.GeometryOffsetAttribute.NONE?0:1,b.arrayFill(p,d),u.geometry.attributes.applyOffset=new v.GeometryAttribute({componentDatatype:A.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:p})),c.push(u);r=T.GeometryPipeline.combineInstances(c)[0],i=P.BoundingSphere.fromVertices(r.attributes.position.values);return new v.Geometry({attributes:r.attributes,indices:r.indices,primitiveType:r.primitiveType,boundingSphere:i,offsetAttribute:e._offsetAttribute})}},function(e,t){return(e=h.defined(t)?c.unpack(e,t):e)._ellipsoid=d.Ellipsoid.clone(e._ellipsoid),c.createGeometry(e)}});