createPolylineGeometry.js 12 KB

1
  1. define(["./when-b60132fc","./buildModuleUrl-8cce5713","./ArcType-f8a754c5","./Cartesian4-b0ddc4ba","./Color-e1e9e6aa","./FeatureDetection-ab6f364c","./Check-7b2a090c","./GeometryAttribute-923c2729","./GeometryAttributes-252e9929","./IndexDatatype-3565e02d","./Math-31e539c2","./EllipsoidGeodesic-1bbae6bf","./EllipsoidRhumbLine-3ee4574a","./Plane-5716a082","./VertexFormat-6446fca0","./WebGLConstants-aba9fc67"],(function(e,a,r,t,n,i,o,l,s,c,u,p,d,h,f,C){"use strict";var y={numberOfPoints:function(e,a,r){var n=t.Cartesian3.distance(e,a);return Math.ceil(n/r)},numberOfPointsRhumbLine:function(e,a,r){var t=Math.pow(e.longitude-a.longitude,2)+Math.pow(e.latitude-a.latitude,2);return Math.ceil(Math.sqrt(t/(r*r)))}},v=new t.Cartographic;y.extractHeights=function(e,a){for(var r=e.length,t=new Array(r),n=0;n<r;n++){var i=e[n];t[n]=a.cartesianToCartographic(i,v).height}return t};var m=new a.Matrix4,g=new t.Cartesian3,w=new t.Cartesian3,A=new h.Plane(t.Cartesian3.UNIT_X,0),T=new t.Cartesian3,_=new h.Plane(t.Cartesian3.UNIT_X,0),E=new t.Cartesian3,P=new t.Cartesian3,b=[];function x(e,a,r){var t,n=b;if(n.length=e,a===r){for(t=0;t<e;t++)n[t]=a;return n}var i=(r-a)/e;for(t=0;t<e;t++){var o=a+t*i;n[t]=o}return n}var D=new t.Cartographic,G=new t.Cartographic,S=new t.Cartesian3,V=new t.Cartesian3,k=new t.Cartesian3,L=new p.EllipsoidGeodesic,M=new d.EllipsoidRhumbLine;function F(e,a,r,n,i,o,l,s,c){var u=n.scaleToGeodeticSurface(e,V),p=n.scaleToGeodeticSurface(a,k),d=y.numberOfPoints(e,a,r),h=n.cartesianToCartographic(u,D),f=n.cartesianToCartographic(p,G),C=x(d,i,o);c>0&&(C=function(e,a){var r=b;r.length=e;for(var t=0;t<e;t++)r[t]=a*Math.sin(Math.PI*t/e);return r}(d,c)),L.setEndPoints(h,f);var v=L.surfaceDistance/d,m=s;h.height=i;var g=n.cartographicToCartesian(h,S);t.Cartesian3.pack(g,l,m),m+=3;for(var w=1;w<d;w++){var A=L.interpolateUsingSurfaceDistance(w*v,G);A.height=C[w],g=n.cartographicToCartesian(A,S),t.Cartesian3.pack(g,l,m),m+=3}return m}function R(e,a,r,n,i,o,l,s){var c=n.scaleToGeodeticSurface(e,V),u=n.scaleToGeodeticSurface(a,k),p=n.cartesianToCartographic(c,D),h=n.cartesianToCartographic(u,G),f=y.numberOfPointsRhumbLine(p,h,r),C=x(f,i,o);M.ellipsoid.equals(n)||(M=new d.EllipsoidRhumbLine(void 0,void 0,n)),M.setEndPoints(p,h);var v=M.surfaceDistance/f,m=s;p.height=i;var g=n.cartographicToCartesian(p,S);t.Cartesian3.pack(g,l,m),m+=3;for(var w=1;w<f;w++){var A=M.interpolateUsingSurfaceDistance(w*v,G);A.height=C[w],g=n.cartographicToCartesian(A,S),t.Cartesian3.pack(g,l,m),m+=3}return m}y.wrapLongitude=function(r,n){var i=[],o=[];if(e.defined(r)&&r.length>0){n=e.defaultValue(n,a.Matrix4.IDENTITY);var l=a.Matrix4.inverseTransformation(n,m),s=a.Matrix4.multiplyByPoint(l,t.Cartesian3.ZERO,g),c=t.Cartesian3.normalize(a.Matrix4.multiplyByPointAsVector(l,t.Cartesian3.UNIT_Y,w),w),u=h.Plane.fromPointNormal(s,c,A),p=t.Cartesian3.normalize(a.Matrix4.multiplyByPointAsVector(l,t.Cartesian3.UNIT_X,T),T),d=h.Plane.fromPointNormal(s,p,_),f=1;i.push(t.Cartesian3.clone(r[0]));for(var C=i[0],y=r.length,v=1;v<y;++v){var b=r[v];if(h.Plane.getPointDistance(d,C)<0||h.Plane.getPointDistance(d,b)<0){var x=h.IntersectionTests.lineSegmentPlane(C,b,u,E);if(e.defined(x)){var D=t.Cartesian3.multiplyByScalar(c,5e-9,P);h.Plane.getPointDistance(u,C)<0&&t.Cartesian3.negate(D,D),i.push(t.Cartesian3.add(x,D,new t.Cartesian3)),o.push(f+1),t.Cartesian3.negate(D,D),i.push(t.Cartesian3.add(x,D,new t.Cartesian3)),f=1}}i.push(t.Cartesian3.clone(r[v])),f++,C=b}o.push(f)}return{positions:i,lengths:o}},y.generateArc=function(r){e.defined(r)||(r={});var n=r.positions,i=n.length,o=e.defaultValue(r.ellipsoid,a.Ellipsoid.WGS84),l=e.defaultValue(r.height,0),s=Array.isArray(l);if(i<1)return[];if(1===i){var c=o.scaleToGeodeticSurface(n[0],V);if(0!==(l=s?l[0]:l)){var p=o.geodeticSurfaceNormal(c,S);t.Cartesian3.multiplyByScalar(p,l,p),t.Cartesian3.add(c,p,c)}return[c.x,c.y,c.z]}var d=r.minDistance;if(!e.defined(d)){var h=e.defaultValue(r.granularity,u.Math3D.RADIANS_PER_DEGREE);d=u.Math3D.chordLength(h,o.maximumRadius)}var f,C=0;for(f=0;f<i-1;f++)C+=y.numberOfPoints(n[f],n[f+1],d);var v=r.hMax,m=3*(C+1),g=new Array(m),w=0;for(f=0;f<i-1;f++){w=F(n[f],n[f+1],d,o,s?l[f]:l,s?l[f+1]:l,g,w,v)}b.length=0;var A=n[i-1],T=o.cartesianToCartographic(A,D);T.height=s?l[i-1]:l;var _=o.cartographicToCartesian(T,S);return t.Cartesian3.pack(_,g,m-3),g};var O=new t.Cartographic,I=new t.Cartographic;y.generateRhumbArc=function(r){e.defined(r)||(r={});var n=r.positions,i=n.length,o=e.defaultValue(r.ellipsoid,a.Ellipsoid.WGS84),l=e.defaultValue(r.height,0),s=Array.isArray(l);if(i<1)return[];if(1===i){var c=o.scaleToGeodeticSurface(n[0],V);if(0!==(l=s?l[0]:l)){var p=o.geodeticSurfaceNormal(c,S);t.Cartesian3.multiplyByScalar(p,l,p),t.Cartesian3.add(c,p,c)}return[c.x,c.y,c.z]}var d,h,f=e.defaultValue(r.granularity,u.Math3D.RADIANS_PER_DEGREE),C=0,v=o.cartesianToCartographic(n[0],O);for(d=0;d<i-1;d++)h=o.cartesianToCartographic(n[d+1],I),C+=y.numberOfPointsRhumbLine(v,h,f),v=t.Cartographic.clone(h,O);var m=3*(C+1),g=new Array(m),w=0;for(d=0;d<i-1;d++){w=R(n[d],n[d+1],f,o,s?l[d]:l,s?l[d+1]:l,g,w)}b.length=0;var A=n[i-1],T=o.cartesianToCartographic(A,D);T.height=s?l[i-1]:l;var _=o.cartographicToCartesian(T,S);return t.Cartesian3.pack(_,g,m-3),g},y.generateCartesianArc=function(e){for(var a=y.generateArc(e),r=a.length/3,n=new Array(r),i=0;i<r;i++)n[i]=t.Cartesian3.unpack(a,3*i);return n},y.generateCartesianRhumbArc=function(e){for(var a=y.generateRhumbArc(e),r=a.length/3,n=new Array(r),i=0;i<r;i++)n[i]=t.Cartesian3.unpack(a,3*i);return n};var N=[];function B(e,a,r,t,i){var o,l=N;l.length=i;var s=r.red,c=r.green,u=r.blue,p=r.alpha,d=t.red,h=t.green,f=t.blue,C=t.alpha;if(n.Color.equals(r,t)){for(o=0;o<i;o++)l[o]=n.Color.clone(r);return l}var y=(d-s)/i,v=(h-c)/i,m=(f-u)/i,g=(C-p)/i;for(o=0;o<i;o++)l[o]=new n.Color(s+o*y,c+o*v,u+o*m,p+o*g);return l}function U(i){var o,l,s=(i=e.defaultValue(i,e.defaultValue.EMPTY_OBJECT)).positions,c=i.colors,p=e.defaultValue(i.width,1),d=e.defaultValue(i.hMax,-1),h=e.defaultValue(i.colorsPerVertex,!1);this._positions=s,this._colors=c,this._width=p,this._hMax=d,this._colorsPerVertex=h,this._dist=i.dist,this._period=i.period,this._vertexFormat=f.VertexFormat.clone(e.defaultValue(i.vertexFormat,f.VertexFormat.DEFAULT)),this._followSurface=e.defaultValue(i.followSurface,!0),e.defined(i.followSurface)&&(o="PolylineGeometry.followSurface",l="PolylineGeometry.followSurface is deprecated and will be removed in 1.55. Use PolylineGeometry.arcType instead.",a.oneTimeWarning(o,l),i.arcType=i.followSurface?r.ArcType.GEODESIC:r.ArcType.NONE),this._arcType=e.defaultValue(i.arcType,r.ArcType.GEODESIC),this._followSurface=this._arcType!==r.ArcType.NONE,this._granularity=e.defaultValue(i.granularity,u.Math3D.RADIANS_PER_DEGREE),this._ellipsoid=a.Ellipsoid.clone(e.defaultValue(i.ellipsoid,a.Ellipsoid.WGS84)),this._workerName="createPolylineGeometry";var C=1+s.length*t.Cartesian3.packedLength;C+=e.defined(c)?1+c.length*n.Color.packedLength:1,this.packedLength=C+a.Ellipsoid.packedLength+f.VertexFormat.packedLength+4+2}U.pack=function(r,i,o){var l;o=e.defaultValue(o,0);var s=r._positions,c=s.length;for(i[o++]=c,l=0;l<c;++l,o+=t.Cartesian3.packedLength)t.Cartesian3.pack(s[l],i,o);var u=r._colors;for(c=e.defined(u)?u.length:0,i[o++]=c,l=0;l<c;++l,o+=n.Color.packedLength)n.Color.pack(u[l],i,o);return a.Ellipsoid.pack(r._ellipsoid,i,o),o+=a.Ellipsoid.packedLength,f.VertexFormat.pack(r._vertexFormat,i,o),o+=f.VertexFormat.packedLength,i[o++]=r._width,i[o++]=r._colorsPerVertex?1:0,i[o++]=r._arcType,i[o++]=r._granularity,i[o++]=r._hMax,i[o++]=r._dist,i[o]=r._period,i};var W=a.Ellipsoid.clone(a.Ellipsoid.UNIT_SPHERE),z=new f.VertexFormat,Y={positions:void 0,colors:void 0,ellipsoid:W,vertexFormat:z,width:void 0,colorsPerVertex:void 0,arcType:void 0,granularity:void 0};U.unpack=function(r,i,o){var l;i=e.defaultValue(i,0);var s=r[i++],c=new Array(s);for(l=0;l<s;++l,i+=t.Cartesian3.packedLength)c[l]=t.Cartesian3.unpack(r,i);var u=(s=r[i++])>0?new Array(s):void 0;for(l=0;l<s;++l,i+=n.Color.packedLength)u[l]=n.Color.unpack(r,i);var p=a.Ellipsoid.unpack(r,i,W);i+=a.Ellipsoid.packedLength;var d=f.VertexFormat.unpack(r,i,z);i+=f.VertexFormat.packedLength;var h=r[i++],C=1===r[i++],y=r[i++],v=r[i++],m=r[i++],g=1==r[i++],w=r[i];return e.defined(o)?(o._positions=c,o._colors=u,o._ellipsoid=a.Ellipsoid.clone(p,o._ellipsoid),o._vertexFormat=f.VertexFormat.clone(d,o._vertexFormat),o._width=h,o._colorsPerVertex=C,o._arcType=y,o._granularity=v,o._hMax=m,o._dist=g,o._period=w,o):(Y.positions=c,Y.colors=u,Y.width=h,Y.colorsPerVertex=C,Y.arcType=y,Y.granularity=v,Y.hMax=m,Y.dist=g,Y.period=w,new U(Y))};var q=new t.Cartesian3,H=new t.Cartesian3,X=new t.Cartesian3,J=new t.Cartesian3;return U.createGeometry=function(o){var p,d,h,f=o._width,C=o._hMax,v=o._vertexFormat,m=o._colors,g=o._colorsPerVertex,w=o._arcType,A=o._granularity,T=o._ellipsoid,_=o._dist,E=o._period,P=r.arrayRemoveDuplicates(o._positions,t.Cartesian3.equalsEpsilon),b=P.length;if(!(b<2||f<=0)){if(w===r.ArcType.GEODESIC||w===r.ArcType.RHUMB){var x,D;w===r.ArcType.GEODESIC?(x=u.Math3D.chordLength(A,T.maximumRadius),D=y.numberOfPoints):(x=A,D=y.numberOfPointsRhumbLine);var G=y.extractHeights(P,T);if(e.defined(m)){var S=1;for(p=0;p<b-1;++p)S+=D(P[p],P[p+1],x);var V=new Array(S),k=0;for(p=0;p<b-1;++p){var L=P[p],M=P[p+1],F=m[p],R=D(L,M,x);if(g&&p<S){var O=B(0,0,F,m[p+1],R),I=O.length;for(d=0;d<I;++d)V[k++]=O[d]}else for(d=0;d<R;++d)V[k++]=n.Color.clone(F)}V[k]=n.Color.clone(m[m.length-1]),m=V,N.length=0}P=w===r.ArcType.GEODESIC?y.generateCartesianArc({positions:P,minDistance:x,ellipsoid:T,height:G,hMax:C}):y.generateCartesianRhumbArc({positions:P,granularity:x,ellipsoid:T,height:G})}var U,W=4*(b=P.length)-4,z=new Float64Array(3*W),Y=new Float64Array(3*W),Z=new Float64Array(3*W),j=new Float32Array(2*W),K=v.st?new Float32Array(2*W):void 0,Q=e.defined(m)?new Uint8Array(4*W):void 0,$=_?new Float32Array(3*W):void 0,ee=0,ae=0,re=0,te=0,ne=0,ie=0;for(d=0;d<b;++d){var oe,le;0===d?(U=q,t.Cartesian3.subtract(P[0],P[1],U),t.Cartesian3.add(P[0],U,U)):U=P[d-1],t.Cartesian3.clone(U,X),t.Cartesian3.clone(P[d],H),d===b-1?(U=q,t.Cartesian3.subtract(P[b-1],P[b-2],U),t.Cartesian3.add(P[b-1],U,U)):U=P[d+1],t.Cartesian3.clone(U,J),e.defined(Q)&&(oe=0===d||g?m[d]:m[d-1],d!==b-1&&(le=m[d]));var se=d===b-1?2:4;for(h=0===d?2:0;h<se;++h){t.Cartesian3.pack(H,z,ee),t.Cartesian3.pack(X,Y,ee),t.Cartesian3.pack(J,Z,ee),ee+=3;var ce=h-2<0?-1:1,ue=h%2*2-1,pe=ue*d/b;if(j[ae++]=C>0?pe:ue,j[ae++]=ce*f,v.st&&(K[re++]=d/(b-1),K[re++]=Math.max(j[ae-2],0)),e.defined(Q)){var de=h<2?oe:le;Q[te++]=n.Color.floatToByte(de.red),Q[te++]=n.Color.floatToByte(de.green),Q[te++]=n.Color.floatToByte(de.blue),Q[te++]=n.Color.floatToByte(de.alpha)}_&&($[3*ne]=ie,ne++)}ie+=t.Cartesian3.distance(U,P[d])}if(_){var he=ie,fe=Math.random()*(E>0?E:he);for(d=0;d<W;d++)$[3*d+1]=he,$[3*d+2]=fe}var Ce=new s.GeometryAttributes;Ce.position=new l.GeometryAttribute({componentDatatype:i.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:z}),Ce.prevPosition=new l.GeometryAttribute({componentDatatype:i.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:Y}),Ce.nextPosition=new l.GeometryAttribute({componentDatatype:i.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:Z}),Ce.expandAndWidth=new l.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:j}),v.st&&(Ce.st=new l.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:K})),e.defined(Q)&&(Ce.color=new l.GeometryAttribute({componentDatatype:i.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:4,values:Q,normalize:!0})),_&&(Ce.dist=new l.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:$}));var ye=c.IndexDatatype.createTypedArray(W,6*b-6),ve=0,me=0,ge=b-1;for(d=0;d<ge;++d)ye[me++]=ve,ye[me++]=ve+2,ye[me++]=ve+1,ye[me++]=ve+1,ye[me++]=ve+2,ye[me++]=ve+3,ve+=4;return new l.Geometry({attributes:Ce,indices:ye,primitiveType:a.PrimitiveType.TRIANGLES,boundingSphere:a.BoundingSphere.fromPoints(P),geometryType:l.GeometryType.POLYLINES})}},function(r,t){return e.defined(t)&&(r=U.unpack(r,t)),r._ellipsoid=a.Ellipsoid.clone(r._ellipsoid),U.createGeometry(r)}}));