@openglobus/og 0.20.2 → 0.20.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/og.css +55 -23
- package/lib/@openglobus/js/Globe.d.ts +3 -0
- package/lib/@openglobus/js/control/Atmosphere.d.ts +27 -3
- package/lib/@openglobus/js/control/AtmosphereConfig.d.ts +59 -0
- package/lib/@openglobus/js/control/index.d.ts +29 -29
- package/lib/@openglobus/js/scene/Planet.d.ts +6 -0
- package/lib/@openglobus/js/shaders/atmos.d.ts +19 -3
- package/lib/@openglobus/js/shaders/drawnode.d.ts +2 -1
- package/lib/@openglobus/js/webgl/Handler.d.ts +3 -1
- package/lib/@openglobus/og.css +1 -1
- package/lib/@openglobus/og.esm.js +1 -1
- package/lib/@openglobus/og.esm.js.map +1 -1
- package/lib/@openglobus/og.umd.js +1 -1
- package/lib/@openglobus/og.umd.js.map +1 -1
- package/lib/js/Globe.d.ts +3 -0
- package/lib/js/Globe.js +3 -1
- package/lib/js/control/Atmosphere.d.ts +27 -3
- package/lib/js/control/Atmosphere.js +109 -43
- package/lib/js/control/AtmosphereConfig.d.ts +59 -0
- package/lib/js/control/AtmosphereConfig.js +348 -0
- package/lib/js/control/DebugInfo.js +5 -4
- package/lib/js/control/Lighting.js +13 -5
- package/lib/js/control/index.d.ts +29 -29
- package/lib/js/control/index.js +29 -29
- package/lib/js/layer/Layer.js +2 -2
- package/lib/js/scene/Planet.d.ts +6 -0
- package/lib/js/scene/Planet.js +24 -10
- package/lib/js/shaders/atmos.d.ts +19 -3
- package/lib/js/shaders/atmos.js +40 -26
- package/lib/js/shaders/drawnode.d.ts +2 -1
- package/lib/js/shaders/drawnode.js +15 -12
- package/lib/js/ui/Slider.js +3 -3
- package/lib/js/webgl/Handler.d.ts +3 -1
- package/lib/js/webgl/Handler.js +38 -28
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=2*Math.PI,t=Math.PI/2,i=Number.MAX_VALUE||17976931348623157e292,n=Math.log(2),r=2147483647,s=549755748352,a=-s,o=Math.PI/180,l=180/Math.PI,h=2*l,c=.5*o,d=Math.sqrt(.5),_=1e-5,u=1e-10,f=1e-12,g=1e-14;function p(e,t,i){return Math.max(t,Math.min(e,i))}function m(e){return!(e&e-1)}function v(e,t=4096){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1>t?t:e+1}function y(e=0,t=1){return Math.floor(Math.random()*(t-e))+e}function x(e,t){return(e%t+t)%t}function b(t){const i=x(t,e);return Math.abs(i)<g&&Math.abs(t)>g?e:i}function w(e,t){return t<e?0:1}function T(e){const t=Math.abs(e);return t-Math.floor(t)}function C(e){return Math.pow(2,e)}function L(e,t,i){return i+e*(t-i)}function A(e){return e*e*e}function E(e){return e*e}function P(e){return e-360*Math.floor(e/360)}var M=Object.freeze({__proto__:null,ARCSECONDS_TO_RADIANS:484813681109536e-20,DEG2RAD:function(e){return e*o},DEGREES:l,DEGREES_DOUBLE:h,DEGREES_TO_HOURS:1/15,EPS1:.1,EPS10:u,EPS11:1e-11,EPS12:f,EPS13:1e-13,EPS14:g,EPS15:1e-15,EPS16:1e-16,EPS17:1e-17,EPS18:1e-18,EPS19:1e-19,EPS2:.01,EPS20:1e-20,EPS3:.001,EPS4:1e-4,EPS5:_,EPS6:1e-6,EPS7:1e-7,EPS8:1e-8,EPS9:1e-9,HOURS_TO_DEGREES:15,HOURS_TO_RADIANS:.26179938779914946,LOG2:n,MAX:s,MAX32:r,MAX_FLOAT:i,MIN:a,PI_TWO:t,RAD2DEG:function(e){return e*l},RADIANS:o,RADIANS_HALF:c,RADIANS_TO_HOURS:3.819718634205488,SQRT_HALF:d,TWO_PI:e,W:3,X:0,Y:1,Z:2,bezier1v:function(e,t,i,n,r){return A(1-e)*t+3*E(1-e)*e*i+3*(1-e)*E(e)*n+A(e)*r},bezier3v:function(e,t,i,n,r){let s=1-e,a=e*e,o=s*s,l=o*s,h=a*e;return t.scaleTo(l).addA(i.scaleTo(3*o*e)).addA(n.scaleTo(3*s*a)).addA(r.scaleTo(h))},clamp:p,cube:A,degToDec:function(e,t,i,n){return n?e+t/60+i/3600:-e-t/60-i/3600},exp2:C,frac:T,getAngleBetweenAzimuths:function(e,t){return(((e=b(e))-(t=b(t)))%360+360+180)%360-180},isPowerOfTwo:m,lerp:L,log:function(e,t){return Math.log(e)/Math.log(t)},log2:function(e){return Math.log(e)/n},mod:x,negativePItoPI:function(e){return b(e+Math.PI)-Math.PI},nextHighestPowerOfTwo:v,norm_lon:function(e){return e>180?(e+180)%360-180:e<-180?(e-180)%360+180:e},pow2i:function(e){return 2<<e-1},random:function(e=0,t=1){return Math.random()*(t-e)+e},randomi:y,rev:P,slice:function(e,t,i){return e*(t-i)},solve_iteration:function(e,t,i,n=50){let r=0,s=t;for(let t=0;t<n;t++)if(r=s,s=e(r),Math.abs(s-r)<i)return s;return s},solve_iteration_fixed:function(e,t,i){let n=0,r=t;for(let t=0;t<i;t++)n=r,r=e(n);return r},square:E,step:w,zeroTwoPI:b});const S=.5*Math.PI,B=180/Math.PI,k=2*B,R=Math.PI/360,I=B*S;class z{constructor(e=0,t=0,i=0){this.lon=0,this.lat=0,this.height=0,this.lon=e,this.lat=t,this.height=i}isZero(){return 0===this.lon&&0===this.lat&&0===this.height}static join(e){let t=[];for(let i=0;i<e.length;i++){let n=e[i];t[i]=new z(n[0],n[1],n[2])}return t}static createFromArray(e){return new z(e[0],e[1],e[2])}static toArray(e){return[e.lon,e.lat,e.height]}toArray(){return z.toArray(this)}static forwardMercator(e,t,i){return new z(e*V,Math.log(Math.tan((90+t)*R))*H,i)}static forwardMercatorRes(e,t){return t.lon=e.lon*V,t.lat=Math.log(Math.tan((90+e.lat)*R))*H,t.height=e.height,t}static inverseMercator(e,t,i=0){return new z(e*U,k*Math.atan(Math.exp(t*N))-I,i)}set(e=0,t=0,i=0){return this.lon=e,this.lat=t,this.height=i,this}copy(e){return this.lon=e.lon,this.lat=e.lat,this.height=e.height,this}clone(){return new z(this.lon,this.lat,this.height)}forwardMercator(){return z.forwardMercator(this.lon,this.lat,this.height)}forwardMercatorEPS01(){let e=this.lat;return e>89.9?e=89.9:e<-89.9&&(e=-89.9),new z(this.lon*V,Math.log(Math.tan((90+e)*R))*H)}inverseMercator(){return z.inverseMercator(this.lon,this.lat,this.height)}equal(e){return e.height?this.lon===e.lon&&this.lat===e.lat&&this.height===e.height:this.lon===e.lon&&this.lat===e.lat}}const F=20037508.34,D=2*F,N=Math.PI/F,H=F/Math.PI,O=.5*Math.PI,V=F/180,U=180/F,G=Math.PI/360,W=Math.PI/180,j=180/Math.PI,Y=2*F,q=1/Y;function X(e){return new z(e.lon*F/180,Math.log(Math.tan((90+e.lat)*G))*H,e.height)}function Z(e){return e*F/180}function $(e){return Math.log(Math.tan((90+e)*G))*H}function K(e){return j*(2*Math.atan(Math.exp(e*N))-O)}function Q(e,t,i){let n=D/(1<<i),r=new z(e*n-F,F-t*n-n);return new ie(r,new z(r.lon+n,r.lat+n))}const J=K(F),ee=-J;var te=Object.freeze({__proto__:null,INV_POLE_BY_180:U,MAX_LAT:J,MIN_LAT:ee,ONE_BY_POLE_DOUBLE:q,PI_BY_POLE:N,POLE:F,POLE2:D,POLE_BY_180:V,POLE_BY_PI:H,POLE_DOUBLE:Y,forward:X,forwardArray:function(e){let t=[];for(let i=0;i<e.length;i++)t.push(e[i].forwardMercator());return t},forward_lat:$,forward_lon:Z,getTileExtent:Q,getTileX:function(e,t){return Math.floor((e+180)/360*Math.pow(2,t))},getTileY:function(e,t){return Math.floor(.5*(1-Math.log(Math.tan(e*W)+1/Math.cos(e*W))/Math.PI)*Math.pow(2,t))},inverse_lat:K,inverse_lon:function(e){return 180*e/F}});class ie{constructor(e=new z,t=new z){this.southWest=e,this.northEast=t}static createFromArray(e){return new ie(new z(e[0],e[1]),new z(e[2],e[3]))}static createByCoordinates(e){let t=s,i=a,n=s,r=a;for(let s=0;s<e.length;s++){const a=e[s];a.lon<t&&(t=a.lon),a.lon>i&&(i=a.lon),a.lat<n&&(n=a.lat),a.lat>r&&(r=a.lat)}return new ie(new z(t,n),new z(i,r))}static createByCoordinatesArr(e){let t=s,i=a,n=s,r=a;for(let s=0;s<e.length;s++){const a=e[s];a[0]<t&&(t=a[0]),a[0]>i&&(i=a[0]),a[1]<n&&(n=a[1]),a[1]>r&&(r=a[1])}return new ie(new z(t,n),new z(i,r))}static fromTile(e,t,i,n=40075016.68,r=40075016.68){const s=1<<i,a=n/s,o=r/s,l=.5*-n+e*a,h=.5*r-t*o,c=l+a;return new ie(new z(l,h-o),new z(c,h))}setByCoordinates(e){let t=s,i=a,n=s,r=a;for(let s=0;s<e.length;s++){const a=e[s];a.lon<t&&(t=a.lon),a.lon>i&&(i=a.lon),a.lat<n&&(n=a.lat),a.lat>r&&(r=a.lat)}return this.southWest.lon=t,this.southWest.lat=n,this.northEast.lon=i,this.northEast.lat=r,this}isInside(e){const t=this.southWest,i=this.northEast;return e.lon>=t.lon&&e.lon<=i.lon&&e.lat>=t.lat&&e.lat<=i.lat}overlaps(e){const t=this.southWest,i=this.northEast;return t.lon<=e.northEast.lon&&i.lon>=e.southWest.lon&&t.lat<=e.northEast.lat&&i.lat>=e.southWest.lat}getWidth(){return this.northEast.lon-this.southWest.lon}getHeight(){return this.northEast.lat-this.southWest.lat}clone(){return new ie(this.southWest.clone(),this.northEast.clone())}getCenter(){const e=this.southWest,t=this.northEast;return new z(e.lon+.5*(t.lon-e.lon),e.lat+.5*(t.lat-e.lat))}getNorthWest(){return new z(this.southWest.lon,this.northEast.lat)}getNorthEast(){return new z(this.northEast.lon,this.northEast.lat)}getSouthWest(){return new z(this.southWest.lon,this.southWest.lat)}getSouthEast(){return new z(this.northEast.lon,this.southWest.lat)}getNorth(){return this.northEast.lat}getEast(){return this.northEast.lon}getWest(){return this.southWest.lon}getSouth(){return this.southWest.lat}equals(e){return this.southWest.lon===e.southWest.lon&&this.southWest.lat===e.southWest.lat&&this.northEast.lon===e.northEast.lon&&this.northEast.lat===e.northEast.lat}forwardMercator(){return new ie(this.southWest.forwardMercator(),this.northEast.forwardMercator())}inverseMercator(){return new ie(this.southWest.inverseMercator(),this.northEast.inverseMercator())}getCartesianBounds(e){let t=s,i=a,n=s,r=a,o=s,l=a;const h=[new z(this.southWest.lon,this.southWest.lat),new z(this.southWest.lon,this.northEast.lat),new z(this.northEast.lon,this.northEast.lat),new z(this.northEast.lon,this.southWest.lat)];for(let s=0;s<h.length;s++){const a=e.lonLatToCartesian(h[s]),c=a.x,d=a.y,_=a.z;c<t&&(t=c),c>i&&(i=c),d<n&&(n=d),d>r&&(r=d),_<o&&(o=_),_>l&&(l=_)}return[t,n,o,i,r,l]}toString(){return`[${this.southWest.lon.toFixed(5)}, ${this.southWest.lat.toFixed(5)}, ${this.northEast.lon.toFixed(5)}, ${this.northEast.lat.toFixed(5)}]`}}class ne{constructor(){this._m=[0,0,0,0,0,0,0,0,0]}set(e){return this._m[0]=e[0],this._m[1]=e[1],this._m[2]=e[2],this._m[3]=e[3],this._m[4]=e[4],this._m[5]=e[5],this._m[6]=e[6],this._m[7]=e[7],this._m[8]=e[8],this}clone(){let e=new ne;return e.set(this._m),e}copy(e){return this.set(e._m)}transposeTo(){let e=new ne,t=this._m;return e._m[0]=t[0],e._m[1]=t[3],e._m[2]=t[6],e._m[3]=t[1],e._m[4]=t[4],e._m[5]=t[7],e._m[6]=t[2],e._m[7]=t[5],e._m[8]=t[8],e}setIdentity(){return this._m[0]=1,this._m[1]=0,this._m[2]=0,this._m[3]=0,this._m[4]=1,this._m[5]=0,this._m[6]=0,this._m[7]=0,this._m[8]=1,this}mulVec(e){let t=e.x,i=e.y,n=e.z,r=this._m;return new oe(r[0]*t+r[3]*i+r[6]*n,r[1]*t+r[4]*i+r[7]*n,r[2]*t+r[5]*i+r[8]*n)}toMatrix4(){let e=new se,t=e._m,i=this._m;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=0,t[4]=i[3],t[5]=i[4],t[6]=i[5],t[7]=0,t[8]=i[6],t[9]=i[7],t[10]=i[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,e}}class re{constructor(e=0,t=0,i=0,n=0){this.x=e,this.y=t,this.z=i,this.w=n}static get identity(){return new re(0,0,0,1)}static fromVec(e){return new re(e[0],e[1],e[2],e[3])}toVec3(){return new oe(this.x,this.y,this.z)}clone(){return new re(this.x,this.y,this.z,this.w)}equal(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}toArray(){return[this.x,this.y,this.z,this.w]}toArray3(){return[this.x,this.y,this.z]}set(e,t,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,this}addA(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}subA(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}scale(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}affinity(){let e=1/this.w;return this.x*=e,this.y*=e,this.z*=e,this.w=1,this}scaleTo(e){return new re(this.x*e,this.y*e,this.z*e,this.w*e)}getStep(e){return new re(this.x<e?0:1,this.y<e?0:1,this.z<e?0:1,this.w<e?0:1)}getFrac(e){return new re(T(e.x),T(e.y),T(e.z),T(e.w))}dot(e){return e.x*this.x+e.y*this.y+e.z*this.z+e.w*this.w}isZero(){return!(this.x||this.y||this.z||this.w)}}class se{constructor(){this._m=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}static identity(){let e=new se;return e._m[0]=1,e._m[1]=0,e._m[2]=0,e._m[3]=0,e._m[4]=0,e._m[5]=1,e._m[6]=0,e._m[7]=0,e._m[8]=0,e._m[9]=0,e._m[10]=1,e._m[11]=0,e._m[12]=0,e._m[13]=0,e._m[14]=0,e._m[15]=1,e}set(e){return this._m[0]=e[0],this._m[1]=e[1],this._m[2]=e[2],this._m[3]=e[3],this._m[4]=e[4],this._m[5]=e[5],this._m[6]=e[6],this._m[7]=e[7],this._m[8]=e[8],this._m[9]=e[9],this._m[10]=e[10],this._m[11]=e[11],this._m[12]=e[12],this._m[13]=e[13],this._m[14]=e[14],this._m[15]=e[15],this}clone(){let e=new se;return e.set(this._m),e}copy(e){return this.set(e._m)}toMatrix3(){let e=new ne,t=this._m,i=e._m;return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[4],i[4]=t[5],i[5]=t[6],i[6]=t[8],i[7]=t[9],i[8]=t[10],e}mulVec3(e){let t=e.x,i=e.y,n=e.z;return new oe(this._m[0]*t+this._m[4]*i+this._m[8]*n+this._m[12],this._m[1]*t+this._m[5]*i+this._m[9]*n+this._m[13],this._m[2]*t+this._m[6]*i+this._m[10]*n+this._m[14])}mulVec4(e){let t=e.x,i=e.y,n=e.z,r=e.w;return new re(this._m[0]*t+this._m[4]*i+this._m[8]*n+this._m[12]*r,this._m[1]*t+this._m[5]*i+this._m[9]*n+this._m[13]*r,this._m[2]*t+this._m[6]*i+this._m[10]*n+this._m[14]*r,this._m[3]*t+this._m[7]*i+this._m[11]*n+this._m[15]*r)}toInverseMatrix3(){let e=this._m,t=e[0],i=e[1],n=e[2],r=e[4],s=e[5],a=e[6],o=e[8],l=e[9],h=e[10],c=h*s-a*l,d=-h*r+a*o,_=l*r-s*o,u=t*c+i*d+n*_;if(!u)return;u=1/u;let f=new ne;return f._m[0]=c*u,f._m[1]=(-h*i+n*l)*u,f._m[2]=(a*i-n*s)*u,f._m[3]=d*u,f._m[4]=(h*t-n*o)*u,f._m[5]=(-a*t+n*r)*u,f._m[6]=_*u,f._m[7]=(-l*t+i*o)*u,f._m[8]=(s*t-i*r)*u,f}inverseTo(e=new se){let t=this._m[0],i=this._m[1],n=this._m[2],r=this._m[3],s=this._m[4],a=this._m[5],o=this._m[6],l=this._m[7],h=this._m[8],c=this._m[9],d=this._m[10],_=this._m[11],u=this._m[12],f=this._m[13],g=this._m[14],p=this._m[15],m=t*a-i*s,v=t*o-n*s,y=t*l-r*s,x=i*o-n*a,b=i*l-r*a,w=n*l-r*o,T=h*f-c*u,C=h*g-d*u,L=h*p-_*u,A=c*g-d*f,E=c*p-_*f,P=d*p-_*g,M=1/(m*P-v*E+y*A+x*L-b*C+w*T);return e._m[0]=(a*P-o*E+l*A)*M,e._m[1]=(-i*P+n*E-r*A)*M,e._m[2]=(f*w-g*b+p*x)*M,e._m[3]=(-c*w+d*b-_*x)*M,e._m[4]=(-s*P+o*L-l*C)*M,e._m[5]=(t*P-n*L+r*C)*M,e._m[6]=(-u*w+g*y-p*v)*M,e._m[7]=(h*w-d*y+_*v)*M,e._m[8]=(s*E-a*L+l*T)*M,e._m[9]=(-t*E+i*L-r*T)*M,e._m[10]=(u*b-f*y+p*m)*M,e._m[11]=(-h*b+c*y-_*m)*M,e._m[12]=(-s*A+a*C-o*T)*M,e._m[13]=(t*A-i*C+n*T)*M,e._m[14]=(-u*x+f*v-g*m)*M,e._m[15]=(h*x-c*v+d*m)*M,e}transposeTo(){let e=new se;return e._m[0]=this._m[0],e._m[1]=this._m[4],e._m[2]=this._m[8],e._m[3]=this._m[12],e._m[4]=this._m[1],e._m[5]=this._m[5],e._m[6]=this._m[9],e._m[7]=this._m[13],e._m[8]=this._m[2],e._m[9]=this._m[6],e._m[10]=this._m[10],e._m[11]=this._m[14],e._m[12]=this._m[3],e._m[13]=this._m[7],e._m[14]=this._m[11],e._m[15]=this._m[15],e}setIdentity(){return this._m[0]=1,this._m[1]=0,this._m[2]=0,this._m[3]=0,this._m[4]=0,this._m[5]=1,this._m[6]=0,this._m[7]=0,this._m[8]=0,this._m[9]=0,this._m[10]=1,this._m[11]=0,this._m[12]=0,this._m[13]=0,this._m[14]=0,this._m[15]=1,this}mul(e){let t=this._m[0],i=this._m[1],n=this._m[2],r=this._m[3],s=this._m[4],a=this._m[5],o=this._m[6],l=this._m[7],h=this._m[8],c=this._m[9],d=this._m[10],_=this._m[11],u=this._m[12],f=this._m[13],g=this._m[14],p=this._m[15],m=e._m[0],v=e._m[1],y=e._m[2],x=e._m[3],b=e._m[4],w=e._m[5],T=e._m[6],C=e._m[7],L=e._m[8],A=e._m[9],E=e._m[10],P=e._m[11],M=e._m[12],S=e._m[13],B=e._m[14],k=e._m[15],R=new se;return R._m[0]=m*t+v*s+y*h+x*u,R._m[1]=m*i+v*a+y*c+x*f,R._m[2]=m*n+v*o+y*d+x*g,R._m[3]=m*r+v*l+y*_+x*p,R._m[4]=b*t+w*s+T*h+C*u,R._m[5]=b*i+w*a+T*c+C*f,R._m[6]=b*n+w*o+T*d+C*g,R._m[7]=b*r+w*l+T*_+C*p,R._m[8]=L*t+A*s+E*h+P*u,R._m[9]=L*i+A*a+E*c+P*f,R._m[10]=L*n+A*o+E*d+P*g,R._m[11]=L*r+A*l+E*_+P*p,R._m[12]=M*t+S*s+B*h+k*u,R._m[13]=M*i+S*a+B*c+k*f,R._m[14]=M*n+S*o+B*d+k*g,R._m[15]=M*r+S*l+B*_+k*p,R}translate(e){let t=e.x,i=e.y,n=e.z,r=this._m;return r[12]=r[0]*t+r[4]*i+r[8]*n+r[12],r[13]=r[1]*t+r[5]*i+r[9]*n+r[13],r[14]=r[2]*t+r[6]*i+r[10]*n+r[14],r[15]=r[3]*t+r[7]*i+r[11]*n+r[15],this}translateToPosition(e){let t=this._m;return t[12]=e.x,t[13]=e.y,t[14]=e.z,this}rotate(e,t){let i=Math.cos(t),n=Math.sin(t),r=new se,s=r._m;return s[0]=i+(1-i)*e.x*e.x,s[1]=(1-i)*e.y*e.x-n*e.z,s[2]=(1-i)*e.z*e.x+n*e.y,s[3]=0,s[4]=(1-i)*e.x*e.y+n*e.z,s[5]=i+(1-i)*e.y*e.y,s[6]=(1-i)*e.z*e.y-n*e.x,s[7]=0,s[8]=(1-i)*e.x*e.z-n*e.y,s[9]=(1-i)*e.y*e.z+n*e.x,s[10]=i+(1-i)*e.z*e.z,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,this.mul(r)}setRotation(e,t){let i=Math.cos(t),n=Math.sin(t),r=this._m;return r[0]=i+(1-i)*e.x*e.x,r[1]=(1-i)*e.y*e.x-n*e.z,r[2]=(1-i)*e.z*e.x+n*e.y,r[3]=0,r[4]=(1-i)*e.x*e.y+n*e.z,r[5]=i+(1-i)*e.y*e.y,r[6]=(1-i)*e.z*e.y-n*e.x,r[7]=0,r[8]=(1-i)*e.x*e.z-n*e.y,r[9]=(1-i)*e.y*e.z+n*e.x,r[10]=i+(1-i)*e.z*e.z,r[11]=0,r[12]=0,r[13]=0,r[14]=0,r[15]=1,this}rotateBetweenVectors(e,t){return ae.getRotationBetweenVectors(e,t).getMat4()}scale(e){let t=this._m;return t[0]=t[0]*e.x,t[1]=t[1]*e.x,t[2]=t[2]*e.x,t[3]=t[3]*e.x,t[4]=t[4]*e.y,t[5]=t[5]*e.y,t[6]=t[6]*e.y,t[7]=t[7]*e.y,t[8]=t[8]*e.z,t[9]=t[9]*e.z,t[10]=t[10]*e.z,t[11]=t[11]*e.z,this}setPerspective(e,t,i,n,r,s){let a=t-e,o=n-i,l=r-s,h=2*r,c=this._m;return c[0]=h/a,c[1]=0,c[2]=0,c[3]=0,c[4]=0,c[5]=h/o,c[6]=0,c[7]=0,c[8]=(t+e)/a,c[9]=(n+i)/o,c[10]=(s+r)/l,c[11]=-1,c[12]=0,c[13]=0,c[14]=h*s/l,c[15]=0,this}setOrtho(e,t,i,n,r,s){let a=1/(e-t),o=1/(i-n),l=1/(r-s),h=this._m;return h[0]=-2*a,h[1]=0,h[2]=0,h[3]=0,h[4]=0,h[5]=-2*o,h[6]=0,h[7]=0,h[8]=0,h[9]=0,h[10]=2*l,h[11]=0,h[12]=(e+t)*a,h[13]=(n+i)*o,h[14]=(s+r)*l,h[15]=1,this}eulerToMatrix(e,t,i){let n=Math.cos(e),r=Math.sin(e),s=Math.cos(t),a=Math.sin(t),o=Math.cos(i),l=Math.sin(i),h=n*a,c=r*a,d=this._m;return d[0]=s*o,d[1]=-s*l,d[2]=-a,d[4]=-c*o+n*l,d[5]=c*l+n*o,d[6]=-r*s,d[8]=h*o+r*l,d[9]=-h*l+r*o,d[10]=n*s,d[3]=d[7]=d[11]=d[12]=d[13]=d[14]=0,d[15]=1,this}}class ae{constructor(e=0,t=0,i=0,n=0){this.x=e,this.y=t,this.z=i,this.w=n}static get IDENTITY(){return new ae(0,0,0,1)}static xRotation(e){return e*=.5,new ae(Math.sin(e),0,0,Math.cos(e))}static yRotation(e){return e*=.5,new ae(0,Math.sin(e),0,Math.cos(e))}static zRotation(e){return e*=.5,new ae(0,0,Math.sin(e),Math.cos(e))}static axisAngleToQuat(e,t=0){let i=e.getNormal(),n=.5*t,r=Math.sin(n);return new ae(i.x*r,i.y*r,i.z*r,Math.cos(n))}static getLookRotation(e,t){let i=e.getNormal().negate(),n=t.cross(i).normalize(),r=i.cross(n),s=1+n.x+r.y+i.z;if(s>1e-6){let e=1/(2*Math.sqrt(s));return new ae((i.y-r.z)*e,(n.z-i.x)*e,(r.x-n.y)*e,.25/e)}if(n.x>r.y&&n.x>i.z){let e=1/(2*Math.sqrt(1+n.x-r.y-i.z));return new ae(.25/e,(r.x+n.y)*e,(n.z+i.x)*e,(i.y-r.z)*e)}if(r.y>i.z){let e=1/(2*Math.sqrt(1+r.y-n.x-i.z));return new ae((r.x+n.y)*e,.25/e,(i.y+r.z)*e,(n.z-i.x)*e)}let a=1/(2*Math.sqrt(1+i.z-n.x-r.y));return new ae((n.z+i.x)*a,(i.y+r.z)*a,.25/a,(r.x-n.y)*a)}static getLookAtSourceDest(e,t){let i=t.subA(e).normalize(),n=oe.FORWARD.dot(i);if(Math.abs(n- -1)<1e-6)return ae.axisAngleToQuat(oe.UP,Math.PI);if(Math.abs(n-1)<1e-6)return new ae(0,0,0,1);let r=Math.acos(n),s=oe.FORWARD.cross(i).normalize();return ae.axisAngleToQuat(s,r)}static getRotationBetweenVectors(e,t){let i=e.cross(t);return new ae(i.x,i.y,i.z,1+e.dot(t)).normalize()}static getRotationBetweenVectorsRes(e,t,i){let n=e.cross(t);return i.set(n.x,n.y,n.z,1+e.dot(t)),i.normalize()}static getRotationBetweenVectorsUp(e,t,i){let n=e.dot(t);if(Math.abs(n+1)<1e-6)return ae.axisAngleToQuat(i,Math.PI);if(Math.abs(n-1)<1e-6)return new ae(0,0,0,1);let r=Math.acos(n),s=e.cross(t).normalize();return ae.axisAngleToQuat(s,r)}isZero(){return 0===this.x&&0===this.y&&0===this.z&&0===this.w}clear(){return this.x=this.y=this.z=this.w=0,this}set(e,t,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,this}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}setIdentity(){return this.x=0,this.y=0,this.z=0,this.w=1,this}clone(){return new ae(this.x,this.y,this.z,this.w)}add(e){return new ae(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)}sub(e){return new ae(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)}scaleTo(e){return new ae(this.x*e,this.y*e,this.z*e,this.w*e)}scale(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}toVec(){return[this.x,this.y,this.z,this.w]}setFromSphericalCoords(e,t,i){let n=Math.sin(i/2),r=Math.cos(i/2),s=Math.sin(e),a=Math.cos(e),o=Math.sin(t),l=Math.cos(t);return this.x=n*a*o,this.y=n*s,this.z=n*s*l,this.w=r,this}setLookRotation(e,t){let i=e.getNormal().negate(),n=t.cross(i).normalize(),r=i.cross(n),s=1+n.x+r.y+i.z;if(s>1e-6){let e=1/(2*Math.sqrt(s));this.x=(i.y-r.z)*e,this.y=(n.z-i.x)*e,this.z=(r.x-n.y)*e,this.w=.25/e}else if(n.x>r.y&&n.x>i.z){let e=1/(2*Math.sqrt(1+n.x-r.y-i.z));this.x=.25/e,this.y=(r.x+n.y)*e,this.z=(n.z+i.x)*e,this.w=(i.y-r.z)*e}else if(r.y>i.z){let e=1/(2*Math.sqrt(1+r.y-n.x-i.z));this.x=(r.x+n.y)*e,this.y=.25/e,this.z=(i.y+r.z)*e,this.w=(n.z-i.x)*e}else{let e=1/(2*Math.sqrt(1+i.z-n.x-r.y));this.x=(n.z+i.x)*e,this.y=(i.y+r.z)*e,this.z=.25/e,this.w=(r.x-n.y)*e}return this}toSphericalCoords(){let e=this.w,t=Math.sqrt(1-e*e);Math.abs(t)<5e-4&&(t=1);let i,n=this.x/t,r=this.y/t,s=this.z/t,a=-Math.asin(r);return i=n*n+s*s<5e-4?0:Math.atan2(n,s),i<0&&(i+=360),{lat:a,lon:i,alpha:Math.acos(e)}}setFromAxisAngle(e,t){let i=e.getNormal(),n=.5*t,r=Math.sin(n);return this.set(i.x*r,i.y*r,i.z*r,Math.cos(n)),this}getAxisAngle(){let e,t,i=this.x,n=this.y,r=this.z,s=this.w,a=Math.sqrt(i*i+n*n+r*r);if(a>1e-7){let o=1/a;e=new oe(i*o,n*o,r*o),t=s<0?2*Math.atan2(-a,-s):2*Math.atan2(a,s)}else e=new oe(0,0,0),t=0;return{axis:e,angle:t}}setFromEulerAngles(e,t,i){let n=e*c,r=t*c,s=i*c,a=Math.cos(n),o=Math.cos(r),l=Math.cos(s),h=Math.sin(n),d=Math.sin(r),_=Math.sin(s),u=o*l,f=d*_;return this.w=a*u+h*f,this.x=h*u-a*f,this.y=a*d*l+h*o*_,this.z=a*o*_-h*d*l,this.normalize()}getEulerAngles(){let e=this.x,t=this.y,i=this.z,n=this.w,r=t*t,s=n*t-i*e;return s<-1?s=-1:s>1&&(s=1),{roll:Math.atan2(2*(n*e+t*i),1-2*(e*e+r)),pitch:Math.asin(2*s),yaw:Math.atan2(2*(n*i+e*t),1-2*(r+i*i))}}setFromMatrix4(e){let t,i,n,r,s,a=[],o=e._m,l=[1,2,0];return t=o[0]+o[5]+o[10],t>0?(i=Math.sqrt(t+1),this.w=i/2,i=.5/i,this.x=(o[6]-o[9])*i,this.y=(o[8]-o[2])*i,this.z=(o[1]-o[4])*i):(n=0,o[5]>o[0]&&(n=1),o[10]>o[5*n]&&(n=2),r=l[n],s=l[r],i=Math.sqrt(o[5*n]-(o[5*r]+o[5*s])+1),a[n]=.5*i,0!==i&&(i=.5/i),a[3]=(o[4*r+s]-o[4*s+r])*i,a[r]=(o[4*n+r]+o[4*r+n])*i,a[s]=(o[4*n+s]+o[4*s+n])*i,this.x=a[0],this.y=a[1],this.z=a[2],this.w=a[3]),this}getMat4(e=new se){let t=this.x+this.x,i=this.y+this.y,n=this.z+this.z,r=this.w*t,s=this.w*i,a=this.w*n,o=this.x*t,l=this.x*i,h=this.x*n,c=this.y*i,d=this.y*n,_=this.z*n;return e.set([1-(c+_),l-a,h+s,0,l+a,1-(o+_),d-r,0,h-s,d+r,1-(o+c),0,0,0,0,1])}getMat3(){let e=new ne,t=e._m,i=this.x,n=this.y,r=this.z,s=this.w,a=i+i,o=n+n,l=r+r,h=i*a,c=i*o;i*=l;let d=n*o;return n*=l,r*=l,a*=s,o*=s,s*=l,t[0]=1-(d+r),t[1]=c-s,t[2]=i+o,t[3]=c+s,t[4]=1-(h+r),t[5]=n-a,t[6]=i-o,t[7]=n+a,t[8]=1-(h+d),e}mulVec3(e){let t=e.x,i=e.y,n=e.z,r=this.x,s=this.y,a=this.z,o=this.w,l=o*t+s*n-a*i,h=o*i+a*t-r*n,c=o*n+r*i-s*t;return t=-r*t-s*i-a*n,new oe(l*o+t*-r+h*-a-c*-s,h*o+t*-s+c*-r-l*-a,c*o+t*-a+l*-s-h*-r)}mul(e){let t=this.x,i=this.y,n=this.z,r=this.w,s=e.x,a=e.y,o=e.z,l=e.w;return new ae(t*l+r*s+i*o-n*a,i*l+r*a+n*s-t*o,n*l+r*o+t*a-i*s,r*l-t*s-i*a-n*o)}mulA(e){let t=this.x,i=this.y,n=this.z,r=this.w,s=e.x,a=e.y,o=e.z,l=e.w;return this.x=t*l+r*s+i*o-n*a,this.y=i*l+r*a+n*s-t*o,this.z=n*l+r*o+t*a-i*s,this.w=r*l-t*s-i*a-n*o,this}conjugate(){return new ae(-this.x,-this.y,-this.z,this.w)}inverse(){let e=1/this.magnitude2();return new ae(-this.x*e,-this.y*e,-this.z*e,this.w*e)}magnitude(){let e=this.x,t=this.y,i=this.z,n=this.w;return Math.sqrt(e*e+t*t+i*i+n*n)}magnitude2(){let e=this.x,t=this.y,i=this.z,n=this.w;return e*e+t*t+i*i+n*n}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}normalize(){let e=this.x,t=this.y,i=this.z,n=this.w,r=Math.sqrt(e*e+t*t+i*i+n*n);return 0===r?(this.x=0,this.y=0,this.z=0,this.w=0,this):(r=1/r,this.x=e*r,this.y=t*r,this.z=i*r,this.w=n*r,this)}isEqual(e){let t=this.dot(e);return Math.abs(t-1)<.001}slerp(e,t){let i,n,r,s,a,o=this.x,l=this.y,h=this.z,c=this.w,d=e.x,_=e.y,u=e.z,f=e.w;return n=o*d+l*_+h*u+c*f,n<0&&(n=-n,d=-d,_=-_,u=-u,f=-f),1-n>1e-6?(i=Math.acos(n),r=Math.sin(i),s=Math.sin((1-t)*i)/r,a=Math.sin(t*i)/r):(s=1-t,a=t),new ae(s*o+a*d,s*l+a*_,s*h+a*u,s*c+a*f)}getRoll(e=!1){let t=this.x,i=this.y,n=this.z,r=this.w;if(e){let e=2*i,s=2*n,a=s*r,o=e*t,l=e*i,h=s*n;return Math.atan2(o+a,1-(l+h))}return Math.atan2(2*(t*i+r*n),r*r+t*t-i*i-n*n)}getPitch(e=!1){let t=this.x,i=this.y,n=this.z,r=this.w;if(e){let e=2*t,s=2*n,a=e*r,o=e*t,l=s*i,h=s*n;return Math.atan2(l+a,1-(o+h))}return Math.atan2(2*(i*n+r*t),r*r-t*t-i*i+n*n)}getYaw(e=!1){let t=this.x,i=this.y,n=this.z,r=this.w;if(e){let e=2*i,s=e*r,a=2*t*t,o=2*n*t,l=e*i;return Math.atan2(o+s,1-(a+l))}return Math.asin(-2*(t*n-r*i))}}class oe{constructor(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}static get UP(){return new oe(0,1,0)}static get DOWN(){return new oe(0,-1,0)}static get RIGHT(){return new oe(1,0,0)}static get LEFT(){return new oe(-1,0,0)}static get FORWARD(){return new oe(0,0,-1)}static get BACKWARD(){return new oe(0,0,1)}static get ZERO(){return new oe}static get UNIT_X(){return new oe(1,0,0)}static get UNIT_Y(){return new oe(0,1,0)}static get UNIT_Z(){return new oe(0,0,1)}static get NORTH(){return oe.UNIT_Z}static doubleToTwoFloats(e,t,i){let n=e.x,r=e.y,s=e.z;if(n>=0){let e=65536*Math.floor(n/65536);t.x=Math.fround(e),i.x=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t.x=Math.fround(-e),i.x=Math.fround(n+e)}if(r>=0){let e=65536*Math.floor(r/65536);t.y=Math.fround(e),i.y=Math.fround(r-e)}else{let e=65536*Math.floor(-r/65536);t.y=Math.fround(-e),i.y=Math.fround(r+e)}if(s>=0){let e=65536*Math.floor(s/65536);t.z=Math.fround(e),i.z=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t.z=Math.fround(-e),i.z=Math.fround(s+e)}}static doubleToTwoFloat32Array(e,t,i){let n=e.x,r=e.y,s=e.z;if(n>=0){let e=65536*Math.floor(n/65536);t[0]=Math.fround(e),i[0]=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t[0]=Math.fround(-e),i[0]=Math.fround(n+e)}if(r>=0){let e=65536*Math.floor(r/65536);t[1]=Math.fround(e),i[1]=Math.fround(r-e)}else{let e=65536*Math.floor(-r/65536);t[1]=Math.fround(-e),i[1]=Math.fround(r+e)}if(s>=0){let e=65536*Math.floor(s/65536);t[2]=Math.fround(e),i[2]=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t[2]=Math.fround(-e),i[2]=Math.fround(s+e)}}static fromVec(e){return new oe(e[0],e[1],e[2])}static angle(e,t){return Math.acos(e.dot(t)/Math.sqrt(e.length2()*t.length2()))}static lerp(e,t,i){return new oe(e.x+(t.x-e.x)*i,e.y+(t.y-e.y)*i,e.z+(t.z-e.z)*i)}static add(e,t){let i=new oe(e.x,e.y,e.z);return i.addA(t),i}static sub(e,t){let i=new oe(e.x,e.y,e.z);return i.subA(t),i}static scale(e,t){return e.scaleTo(t)}static mul(e,t){let i=new oe(e.x,e.y,e.z);return i.mulA(t),i}static noncollinear(e,t){return Boolean(e.y*t.z-e.z*t.y||e.z*t.x-e.x*t.z||e.x*t.y-e.y*t.z)}static proj_b_to_plane(e,t,i){let n=e.sub(t.scaleTo(t.dot(e)/t.dot(t)));return i&&n.isZero()?new oe(i.x,i.y,i.z):n}static proj_b_to_a(e,t){return t.scaleTo(t.dot(e)/t.dot(t))}static orthoNormalize(e,t){return(e=e.getNormal()).scale(t.dot(e)),t.subA(e).normalize()}static div(e,t){let i=new oe(e.x,e.y,e.z);return i.divA(t),i}static length2(e){return e.length2()}static dot(e,t){return e.dot(t)}toVec4(){return new re(this.x,this.y,this.z,1)}clone(){return new oe(this.x,this.y,this.z)}toString(){return`(${this.x},${this.y},${this.z})`}isZero(){return!(this.x||this.y||this.z)}projToVec(e){return e.scaleTo(e.dot(this)/e.dot(e))}equal(e){return this.x===e.x&&this.y===e.y&&this.z===e.z}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}length2(){return this.x*this.x+this.y*this.y+this.z*this.z}getQuat(){return new ae(this.x,this.y,this.z)}addA(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}add(e){return new oe(this.x+e.x,this.y+e.y,this.z+e.z)}subA(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}sub(e){return new oe(this.x-e.x,this.y-e.y,this.z-e.z)}scale(e){return this.x*=e,this.y*=e,this.z*=e,this}scaleTo(e){return new oe(this.x*e,this.y*e,this.z*e)}mulA(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}mul(e){return new oe(this.x*e.x,this.y*e.y,this.z*e.z)}divA(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}div(e){return new oe(this.x/e.x,this.y/e.y,this.z/e.z)}dot(e){return e.x*this.x+e.y*this.y+e.z*this.z}dotArr(e){return e[0]*this.x+e[1]*this.y+e[2]*this.z}cross(e){return new oe(this.y*e.z-this.z*e.y,this.z*e.x-this.x*e.z,this.x*e.y-this.y*e.x)}clear(){return this.x=this.y=this.z=0,this}getNormal(){let e=new oe;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normal(){let e=new oe;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegate(){let e=new oe;e.copy(this);let t=-1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegateScale(e){let t=new oe;t.copy(this);let i=-e/t.length();return t.x*=i,t.y*=i,t.z*=i,t}normalScale(e){let t=new oe;t.copy(this);let i=e/t.length();return t.x*=i,t.y*=i,t.z*=i,t}normalize(){let e=1/this.length();return this.x*=e,this.y*=e,this.z*=e,this}toVec(){return[this.x,this.y,this.z]}toArray(){return[this.x,this.y,this.z]}distance(e){let t=this.x-e.x,i=this.y-e.y,n=this.z-e.z;return Math.sqrt(t*t+i*i+n*n)}distance2(e){let t=this.x-e.x,i=this.y-e.y,n=this.z-e.z;return t*t+i*i+n*n}set(e,t,i){return this.x=e,this.y=t,this.z=i,this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}negateTo(){return new oe(-this.x,-this.y,-this.z)}projToRay(e,t){let i=oe.proj_b_to_a(oe.sub(this,e),t);return i.addA(e),i}angle(e){return oe.angle(this,e)}lerp(e,t){return new oe(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t,this.z+(e.z-this.z)*t)}smerp(e,t){let i=1-t;return new oe(this.x*t+e.x*i,this.y*t+e.y*i,this.z*t+e.z*i)}static get LERP_DELTA(){return 1e-6}slerp(e,t){let i,n,r,s,a=new oe;if(t<=0)return a.copy(this),a;if(t>=1)return a.copy(e),a;let o=this.dot(e);return 1-o>oe.LERP_DELTA?(i=Math.acos(o),n=Math.sin(i),r=Math.sin((1-t)*i)/n,s=Math.sin(t*i)/n):(r=1-t,s=t),oe.add(this.scaleTo(r),e.scale(s))}getRotationTo(e,t){let i=this.clone(),n=e.clone();i.normalize(),n.normalize();let r=i.dot(n);if(r>=1)return ae.IDENTITY.clone();if(r<-.999999){if(t.equal(oe.ZERO)){let e=oe.UNIT_X.cross(i);return e.isZero()&&(e=oe.UNIT_Y.cross(i)),e.normalize(),ae.axisAngleToQuat(e,Math.PI)}return ae.axisAngleToQuat(t,Math.PI)}{let e=Math.sqrt(2*(1+r)),t=1/e,s=i.cross(n),a=new ae(s.x*t,s.y*t,s.z*t,.5*e);return a.normalize(),a}}}class le{constructor(e=0,t=0){this.x=e,this.y=t}static get UP(){return new le(0,1)}static get DOWN(){return new le(0,-1)}static get RIGHT(){return new le(1,0)}static get LEFT(){return new le(-1,0)}static get ZERO(){return new le}static add(e,t){const i=new le(e.x,e.y);return i.addA(t),i}static sub(e,t){var i=new le(e.x,e.y);return i.subA(t),i}static scale(e,t){let i=new le(e.x,e.y);return i.scale(t),i}static mul(e,t){let i=new le(e.x,e.y);return i.mulA(t),i}static div(e,t){let i=new le(e.x,e.y);return i.divA(t),i}static proj_b_to_a(e,t){return t.scaleTo(t.dot(e)/t.dot(t))}static angle(e,t){return Math.acos(e.dot(t)/Math.sqrt(e.length2()*t.length2()))}static orthoNormalize(e,t){return(e=e.normal()).scale(t.dot(e)),t.sub(e).normalize()}toVector3(){return new oe(this.x,this.y,0)}clone(){return new le(this.x,this.y)}equal(e){return this.x===e.x&&this.y===e.y}copy(e){return this.x=e.x,this.y=e.y,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}length2(){return this.x*this.x+this.y*this.y}addA(e){return this.x+=e.x,this.y+=e.y,this}add(e){return new le(this.x+e.x,this.y+e.y)}subA(e){return this.x-=e.x,this.y-=e.y,this}sub(e){return new le(this.x-e.x,this.y-e.y)}scale(e){return this.x*=e,this.y*=e,this}scaleTo(e){return new le(this.x*e,this.y*e)}mulA(e){return this.x*=e.x,this.y*=e.y,this}mul(e){return new le(this.x*e.x,this.y*e.y)}divA(e){return this.x/=e.x,this.y/=e.y,this}dot(e){return e.x*this.x+e.y*this.y}dotArr(e){return e[0]*this.x+e[1]*this.y}cross(e){return this.x*e.y-this.y*e.x}clear(){return this.x=this.y=0,this}normal(){let e=new le;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e}normalize(){let e=1/this.length();return this.x*=e,this.y*=e,this}toVec(){return[this.x,this.y]}distance(e){return le.sub(this,e).length()}set(e,t){return this.x=e,this.y=t,this}negate(){return this.x=-this.x,this.y=-this.y,this}negateTo(){return new le(-this.x,-this.y)}projToRay(e,t){let i=le.proj_b_to_a(le.sub(this,e),t);return i.add(e),i}angle(e){return le.angle(this,e)}lerp(e,t,i){let n=this.clone();return i<=0?n.copy(e):i>=1?n.copy(t):n=le.add(e,le.sub(t,e).scale(i)),n}static get LERP_DELTA(){return 1e-6}slerp(e,t){let i,n,r,s,a=new le;if(t<=0)return a.copy(this),a;if(t>=1)return a.copy(e),a;let o=this.dot(e);return 1-o>le.LERP_DELTA?(i=Math.acos(o),n=Math.sin(i),r=Math.sin((1-t)*i)/n,s=Math.sin(t*i)/n):(r=1-t,s=t),le.add(this.scale(r),e.scale(s))}}const he={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4","indianred ":"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};function ce(e,t){return null!=e?e:t}function de(e){return null==e}function _e(e){return void 0===e}let ue=0;function fe(e){let t=e._openglobus_id;return t||(t=e._openglobus_id=++ue),t}function ge(e){return"string"==typeof e||e instanceof String}function pe(e){return e.toString(16).padStart(2,"0")}function me(e){let t,i,n;return e instanceof Array?(t=pe(e[0]),i=pe(e[1]),n=pe(e[2])):(t=pe(e.x),i=pe(e.y),n=pe(e.z)),`#${t}${i}${n}`}function ve(e,t){let i=he[e];if(i&&(e=i),"#"===e[0]){let i=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,n=e.replace(i,(function(e,t,i,n){return t+t+i+i+n+n})),r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return r?new re(parseInt(r[1],16)/255,parseInt(r[2],16)/255,parseInt(r[3],16)/255,de(t)?1:t):new re}{de(t)&&(t=1);let i=e.split(",");return new re(parseInt(i[0].split("(")[1])/255,parseInt(i[1])/255,parseInt(i[2])/255,de(i[3])?t:parseFloat(i[3]))}}function ye(e,t){let i=ve(e,t);return new Float32Array([i.x,i.y,i.z,i.w])}function xe(e){let t=he[e];if(t&&(e=t),"#"===e[0]){let t=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,i=e.replace(t,(function(e,t,i,n){return t+t+i+i+n+n})),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i);return n?new oe(parseInt(n[1],16)/255,parseInt(n[2],16)/255,parseInt(n[3],16)/255):new oe}{let t=e.split(",");return new oe(parseInt(t[0].split("(")[1])/255,parseInt(t[1])/255,parseInt(t[2])/255)}}function be(e,t){return e.replace(/{[^{}]+}/g,(function(e){return t[e.replace(/[{}]+/g,"")]||""}))}function we(e){let t=document.createElement("div");t.innerHTML=e;let i=[];for(let e=0;e<t.childNodes.length;e++)i.push(t.childNodes[e]),t.removeChild(t.childNodes[e]);return i}function Te(e,t,i,n){let r=document.getElementById(e);r||(r=document.createElement("div"),r.id=e,r.classList.add("defaultText"),document.body.appendChild(r)),r.innerHTML=t,r.style.left=`${i}px`,r.style.top=`${n}px`}function Ce(e){return"number"==typeof e}function Le(e,t=""){return e?e.trim():t}function Ae(e,t){if(e){if(Ce(e))return new oe(e,e,e);if(e instanceof oe)return e.clone();if(e instanceof Array)return oe.fromVec(e);if(e instanceof le)return new oe(e.x,e.y,0)}else if(t)return t;return new oe}function Ee(e,t){if(e){if(ge(e))return ve(e);if(e instanceof Array)return re.fromVec(e);if(e instanceof re)return e.clone()}else if(t)return t;return new re(1,1,1,1)}function Pe(e,t){if(e){if(ge(e))return xe(e);if(e instanceof Array)return oe.fromVec(e);if(e instanceof oe)return e.clone()}else if(t)return t;return new oe(1,1,1)}function Me(e,t){if(e){if(e instanceof Array)return new ie(Se(e[0]),Se(e[1]));if(e instanceof ie)return e.clone()}else if(t)return t;return new ie}function Se(e,t){if(e){if(e instanceof Array)return new z(e[0],e[1],e[2]);if(e instanceof z)return e.clone()}else if(t)return t;return new z}function Be(e,t){let i=0,n=e.length-1;for(;i<=n;){let r=Math.floor(.5*(i+n));if(Math.abs(e[r]-t)<.001)return r;e[r]<t?i=r+1:n=r-1}return-1}function ke(e,t,i){let n=0,r=e.length-1;for(;n<=r;){let s=r+n>>1,a=i(t,e[s],s);if(a>0)n=s+1;else{if(!(a<0))return s;r=s-1}}return-n-1}function Re(e,t,i){let n=ke(e,t,i);return n<0&&(n=~n),e.splice(n,0,t),n}function Ie(e,t,i,n,r=!1){let s=new z(t.lon-e.lon,t.lat-e.lat),a=new z(n.lon-i.lon,n.lat-i.lat),o=-s.lat,l=+s.lon,h=-(o*e.lon+l*e.lat),c=-a.lat,d=+a.lon,_=-(c*i.lon+d*i.lat),u=c*e.lon+d*e.lat+_,f=c*t.lon+d*t.lat+_,g=o*i.lon+l*i.lat+h,p=o*n.lon+l*n.lat+h;if(r&&(u*f>0||g*p>0))return;let m=u/(u-f);return new z(e.lon+m*s.lon,e.lat+m*s.lat)}const ze={string:function(e){return de(e)?e:e.toString()},date:function(e){return de(e)?e:new Date(1e3*e)},datetime:function(e){return de(e)?e:new Date(1e3*e)},time:function(e){return de(e)?e:parseInt(e)},integer:function(e){return de(e)?e:parseInt(e)},float:function(e){return de(e)?e:parseFloat(e)},boolean:function(e){if(null===e)return e;if("boolean"==typeof e)return!0===e;if("string"==typeof e){if(""===e)return!1;if("true"===(e=e.replace(/^\s+|\s+$/g,"")).toLowerCase()||"yes"===e.toLowerCase())return!0;e=(e=e.replace(/,/g,".")).replace(/^\s*\-\s*/g,"-")}return!isNaN(e)&&0!==parseFloat(e)}};function Fe(e,t=""){let i=1024,n=atob(e),r=n.length,s=Math.ceil(r/i),a=new Array(s);for(let e=0;e<s;++e){let t=e*i,s=Math.min(t+i,r),o=new Array(s-t);for(let e=t,i=0;e<s;++i,++e)o[i]=n[e].charCodeAt(0);a[e]=new Uint8Array(o)}return new Blob(a,{type:t})}function De(e,t,i=!1){let n,r=0;return function(){const s=arguments;r?(i&&clearTimeout(n),n=setTimeout((()=>{Date.now()-r>=t&&(e.apply(null,s),r=Date.now())}),t-(Date.now()-r))):(e.apply(null,s),r=Date.now())}}function Ne(e,t){let i=new e.constructor(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function He(e=[],t=[]){if(ArrayBuffer.isView(e))return Ne(e,t);for(let i=0;i<t.length;i++)e.push(t[i]);return e}function Oe(e,t=Float32Array){if(ArrayBuffer.isView(e))return e;{const i=new t(e.length);return i.set(e,0),i}}function Ve(e){return ArrayBuffer.isView(e)?Array.from(e):e}function Ue(e,t,i,n){if(ArrayBuffer.isView(e))return t<0&&(i=Math.abs(t),t+=e.length),Ge(e,t,i,n);{let r;return r=t<0?e.splice(t):e.splice(t,i),n&&(n.result=r),e}}function Ge(e,t,i,n){if(0===e.length)return e;const r=e.length-i,s=new e.constructor(r);return s.set(e.subarray(0,t)),s.set(e.subarray(t+i),t),n&&(n.result=e.subarray(t,t+i)),s}function We(e,t,i,n,r){const s=r+1,a=i+s,o=n+s;let l=new Float64Array(s*s*3),h=0;for(let r=i;r<a;r++)for(let i=n;i<o;i++){let n=3*(r*(t+1)+i);l[h++]=e[n],l[h++]=e[n+1],l[h++]=e[n+2]}return l}function je(e,t,i,n,r){const s=r+1,a=i+s,o=n+s;let l=new Float32Array(s*s*3),h=0;for(let r=i;r<a;r++)for(let i=n;i<o;i++){let n=3*(r*(t+1)+i);l[h++]=e[n],l[h++]=e[n+1],l[h++]=e[n+2]}return l}function Ye(e,t,i,n,r,s,a,o,l,h,c,d,_){const u=s+o+1,f=a+o+1;r+=1;let g=0,p=0;for(let o=s;o<u;o++)for(let s=a;s<f;s++){let a=o*r+s,u=3*a,f=e[u],m=e[u+1],v=e[u+2];n&&0!==n[a]?_[p]=1:(f<d.xmin&&(d.xmin=f),f>d.xmax&&(d.xmax=f),m<d.ymin&&(d.ymin=m),m>d.ymax&&(d.ymax=m),v<d.zmin&&(d.zmin=v),v>d.zmax&&(d.zmax=v)),p++,l[g]=f,c[g]=i[u],h[g++]=t[u],l[g]=m,c[g]=i[u+1],h[g++]=t[u+1],l[g]=v,c[g]=i[u+2],h[g++]=t[u+2]}}function qe(e){return e.map((e=>Array.isArray(e)?qe(e):e))}async function Xe(e){return new Promise((t=>{const i=new Image;return i.addEventListener("load",(()=>{t(i)})),i.src=e,i.crossOrigin="",i}))}function Ze(e){return e.complete&&0!==e.naturalHeight}function $e(e){if(e>1e3){return 0!==e-Math.floor(e)?[(e/1e3).toFixed(2),"km"]:[(e/1e3).toFixed(0),"km"]}return e>9?[Math.round(e).toString(),"m"]:e<=.01?["0","m"]:[e.toFixed(1),"m"]}function Ke(e){let t=new URLSearchParams(location.search).get(e);if(t)return Number(t)}var Qe=Object.freeze({__proto__:null,base64StringToBlog:function(e){let t=e.split(";"),i=t[0].split(":")[1];return Fe(t[1].split(",")[1],i)},base64toBlob:Fe,binaryInsert:Re,binarySearch:ke,binarySearchFast:Be,blerp:function(e,t,i,n,r,s,a=0,o=1,l=0,h=1){return(i*(o-e)*(h-t)+n*(e-a)*(h-t)+r*(o-e)*(t-l)+s*(e-a)*(t-l))/((o-a)*(h-l))},blerp2:function(e,t,i,n,r,s){return i*(1-e)*(1-t)+n*e*(1-t)+r*(1-e)*t+s*e*t},castType:ze,cloneArray:qe,concatArrays:He,concatTypedArrays:Ne,createColorRGB:Pe,createColorRGBA:Ee,createExtent:Me,createLonLat:Se,createVector3:Ae,createVector4:function(e,t){if(e){if(e instanceof re)return e.clone();if(e instanceof Array)return re.fromVec(e)}else if(t)return t;return new re},defaultString:Le,distanceFormat:function(e){return e>1e3?`${(e/1e3).toFixed(2)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`},distanceFormatExt:$e,extractElevationTiles:function(e,t,i){let n=Math.sqrt(t.length)-1,r=n+1,s=Math.sqrt(e.length/4),a=s/n,o=0,l=0;for(let h=0,c=0,d=e.length/4;h<d;h++){let d=e[4*h],_=Math.floor(h/s),u=h%s,f=Math.floor(u/n),g=Math.floor(_/n),p=i[g][f],m=_%n,v=u%n,y=(m+g)*r+v+f;if(p[y]=d,(_+g)%a==0&&(u+f)%a==0&&(t[c++]=d),(u+1)%n==0&&u!==s-1){o=e[4*(h+1)];let s=.5*(d+o);y=(m+g)*r+v+1,p[y]=s,(_+g)%a==0&&(t[c++]=s);let l=(m+g)*r+(v+1)%n;i[g][f+1][l]=s}if((_+1)%n==0&&_!==s-1){l=e[4*(h+s)];let o=.5*(d+l);y=(m+1)*r+v+f,p[y]=o,(u+f)%a==0&&(t[c++]=o);let _=(m+1)%n*r+v+f;i[g+1][f][_]=o}if((u+1)%n==0&&u!==s-1&&(_+1)%n==0&&_!==s-1){let a=.25*(d+o+l+e[4*(h+s+1)]);y=(m+1)*r+(v+1),p[y]=a,t[c++]=a;let _=(m+1)*r;i[g][f+1][_]=a;let u=n;i[g+1][f][u]=a;let x=0;i[g+1][f+1][x]=a}}},getDefault:ce,getHTML:function(e,t){return be(e,t)},getLinesIntersection2v:function(e,t,i,n,r){let s=t.sub(e),a=n.sub(i),o=-s.y,l=+s.x,h=-(o*e.x+l*e.y),c=-a.y,d=+a.x,_=-(c*i.x+d*i.y),u=c*e.x+d*e.y+_,f=c*t.x+d*t.y+_,g=o*i.x+l*i.y+h,p=o*n.x+l*n.y+h;if(r&&(u*f>0||g*p>0))return;let m=u/(u-f);return new le(e.x+m*s.x,e.y+m*s.y)},getLinesIntersectionLonLat:Ie,getMatrixSubArray32:je,getMatrixSubArray64:We,getMatrixSubArrayBoundsExt:Ye,getUrlParam:Ke,htmlColorToFloat32Array:ye,htmlColorToRgb:xe,htmlColorToRgba:ve,isEmpty:de,isImageLoaded:Ze,isNumber:Ce,isString:ge,isUndef:_e,isUndefExt:function(e,t){return _e(e)?t:e},loadImage:Xe,makeArray:Ve,makeArrayTyped:Oe,parseHTML:we,print2d:Te,rgbToStringHTML:me,spliceArray:Ue,spliceTypedArray:Ge,stamp:fe,stringTemplate:be,throttle:De,xmlToJson:function e(t){let i={};if(1===t.nodeType){if(t.attributes.length>0){i["@attributes"]={};for(let e=0;e<t.attributes.length;e++){let n=t.attributes.item(e);i["@attributes"][n.nodeName]=n.nodeValue}}}else 3===t.nodeType&&(i=t.nodeValue);if(t.hasChildNodes())for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes.item(n),s=r.nodeName;if(void 0===i[s])i[s]=e(r);else{if(void 0===i[s].push){let e=i[s];i[s]=[],i[s].push(e)}i[s].push(e(r))}}return i}});const Je=.001,et=1e3,tt=60,it=1/tt,nt=1/24,rt=3600,st=1/rt,at=12*rt,ot=1440,lt=1/ot,ht=86400,ct=864e5,dt=1.1574074074074074e-8,_t=1/ht,ut=2451545;function ft(e,t,i){let n=(t-14)/12|0,r=e+4800+n;return(1461*r/4|0)+(367*(t-2-12*n)/12|0)-(3*((r+100)/100|0)/4|0)+i-32075}function gt(e){let t=ft(e.getUTCFullYear(),e.getUTCMonth()+1,e.getUTCDate()),i=e.getUTCHours()-12;i<0&&(i+=24);let n=e.getUTCSeconds()+i*rt+e.getUTCMinutes()*tt+e.getUTCMilliseconds()*Je;n>=at&&t--;let r=n*_t|0;return t+=r,n-=ht*r,n<0&&(t--,n+=ht),t+n*_t}function pt(e){let t=wt,i=ke(t,e,(function(e,t){return e-t.jd}));i<0&&(i=~i),i>=t.length&&(i=t.length-1);let n=t[i].leapSeconds;return 0!==i&&(t[i].jd-e)*ht>n&&(n=t[i-1].leapSeconds),e+n*_t}function mt(e){let t=wt,i=ke(t,e,(function(e,t){return e-t.jd}));if(i<0&&(i=~i),i>=t.length)return e-t[i-1].leapSeconds*_t;if(0===i)return e-t[0].leapSeconds*_t;let n=(t[i].jd-e)*ht;return 0===n?e-t[i].leapSeconds*_t:n<=1?void 0:e-t[i-1].leapSeconds*_t}function vt(e){let t=0|e,i=(e-t)*ht;i>=at&&t++;let n=t+68569|0,r=4*n/146097|0;n=n-((146097*r+3)/4|0)|0;let s=4e3*(n+1)/1461001|0;n=n-(1461*s/4|0)+31|0;let a=80*n/2447|0,o=n-(2447*a/80|0)|0;n=a/11|0;let l=a+2-12*n|0,h=100*(r-49)+s+n|0,c=i*st|0,d=i-c*rt,_=d*it|0;d-=_*tt;let u=0|d,f=(d-u)*et|0;return c+=12,c>23&&(c-=24),new Date(Date.UTC(h,l-1,o,c,_,u,f))}function yt(e,t){return e+t*dt}function xt(e,t){return e+t*_t}function bt(e,t){return{jd:e,leapSeconds:t}}const wt=[bt(2441317.5,10),bt(2441499.5,11),bt(2441683.5,12),bt(2442048.5,13),bt(2442413.5,14),bt(2442778.5,15),bt(2443144.5,16),bt(2443509.5,17),bt(2443874.5,18),bt(2444239.5,19),bt(2444786.5,20),bt(2445151.5,21),bt(2445516.5,22),bt(2446247.5,23),bt(2447161.5,24),bt(2447892.5,25),bt(2448257.5,26),bt(2448804.5,27),bt(2449169.5,28),bt(2449534.5,29),bt(2450083.5,30),bt(2450630.5,31),bt(2451179.5,32),bt(2453736.5,33),bt(2454832.5,34),bt(2456109.5,35),bt(2457204.5,36)],Tt=pt(ut);var Ct=Object.freeze({__proto__:null,DAYS_PER_JULIAN_CENTURY:36525,DAYS_PER_JULIAN_YEAR:365.25,DateToTAI:function(e){return pt(gt(e))},DateToUTC:gt,HOURS_PER_DAY:24,J2000:ut,J2000TAI:Tt,MILLISECONDS_PER_DAY:ct,MILLISECONDS_PER_SECOND:et,MINUTES_PER_DAY:ot,MINUTES_PER_HOUR:60,MODIFIED_JULIAN_DATE_DIFFERENCE:2400000.5,ONE_BY_HOURS_PER_DAY:nt,ONE_BY_MILLISECONDS_PER_DAY:dt,ONE_BY_MINUTES_PER_DAY:lt,ONE_BY_SECONDS_PER_DAY:_t,ONE_BY_SECONDS_PER_HOUR:st,ONE_BY_SECONDS_PER_MINUTE:it,PICOSECOND:1e-9,SECONDS_PER_12_HOURS:at,SECONDS_PER_DAY:ht,SECONDS_PER_HOUR:rt,SECONDS_PER_MILLISECOND:Je,SECONDS_PER_MINUTE:tt,T:function(e){return(e-ut)/36525},TAItoDate:function(e){let t=mt(e);return t||(t=mt(xt(e,-1)),console.trace(`TAItoDate - can't convert ${e.toString()} to utc.`)),vt(t)},TAItoUTC:mt,UTCtoDate:vt,UTCtoTAI:pt,addDays:function(e,t){return e+t},addHours:function(e,t){return e+t*nt},addMilliseconds:yt,addMinutes:function(e,t){return e+t*ot},addSeconds:xt,daysToSeconds:function(e){return e*ht},getDayNumber:ft,getDays:function(e){return 0|e},getHours:function(e){let t=(e-(0|e))*ht,i=t*st|0,n=t-i*rt,r=n*it|0;n-=r*tt;let s=0|n;return i+=12+r/60+s/3600+((n-s)*et|0)/1e3,i>23&&(i-=24),i},getMilliseconds:function(e){let t=e-(0|e);return t*=ht,(t-(0|t))*et|0},getMinutes:function(e){return(e-(0|e))*ot|0},getSeconds:function(e){return(e-(0|e))*ht},secondsToDays:function(e){return e*_t}});class Lt{constructor(e){this.vertices=[new oe,new oe,new oe,new oe,new oe,new oe,new oe,new oe],e&&this.setFromBoundsArr(e)}copy(e){for(let t=0,i=this.vertices.length;t<i;t++)this.vertices[t].copy(e.vertices[t])}setFromBoundsArr(e){let t=e[0],i=e[3],n=e[1],r=e[4],s=e[2],a=e[5],o=this.vertices;o[0].set(t,n,s),o[1].set(i,n,s),o[2].set(i,n,a),o[3].set(t,n,a),o[4].set(t,r,s),o[5].set(i,r,s),o[6].set(i,r,a),o[7].set(t,r,a)}setFromExtent(e,t){this.setFromBoundsArr(t.getCartesianBounds(e))}}class At{constructor(e=0,t){this.radius=e,this.center=t?t.clone():new oe}setFromBounds(e){let t=new oe(e[0],e[1],e[2]);this.center.set(t.x+.5*(e[3]-t.x),t.y+.5*(e[3]-t.y),t.z+.5*(e[5]-t.z)),this.radius=this.center.distance(t)}setFromExtent(e,t){this.setFromBounds(t.getCartesianBounds(e))}}var Et=Object.freeze({__proto__:null,Box:Lt,Sphere:At});function Pt(e,t){return new Mt(e,t)}class Mt{constructor(e,t){this.__id=Mt.__counter__++,this._eventNames=[],e&&this.registerNames(e),this._sender=t||this,this._stopPropagation=!1,this._stampCache={}}bindSender(e){this._sender=e||this}registerNames(e){for(let t=0;t<e.length;t++)this[e[t]]={active:!0,handlers:[]},this._eventNames.push(e[t]);return this}_getStamp(e,t,i){return`${e}_${t}_${i}`}_stamp(e,t){let i=fe(t),n=this._getStamp(e,this.__id,i);return!this._stampCache[n]&&(this._stampCache[n]=i,!0)}on(e,t,i,n=0){if(this._stamp(e,t)&&this[e]){let r=t.bind(i||this._sender);r._openglobus_id=t._openglobus_id,r._openglobus_priority=n,Re(this[e].handlers,r,((e,t)=>(t._openglobus_priority||0)-(e._openglobus_priority||0)))}}off(e,t){if(t){let i=this._getStamp(e,this.__id,t._openglobus_id);if(t._openglobus_id&&this._stampCache[i]){let n=this[e].handlers,r=n.length,s=-1;for(;r--;){if(n[r]._openglobus_id===t._openglobus_id){s=r;break}}-1!==s&&(n.splice(s,1),this._stampCache[i]=void 0,delete this._stampCache[i])}}}dispatch(e,...t){let i=!0;if(e&&e.active&&!this._stopPropagation){let n=e.handlers.slice(0),r=n.length;for(;r--;)!1===n[r](...t)&&(i=!1)}return this._stopPropagation=!1,i}stopPropagation(){this._stopPropagation=!0}clear(){for(let e=0;e<this._eventNames.length;e++){let t=this[this._eventNames[e]];t.handlers.length=0,t.handlers=[]}this._eventNames.length=0,this._eventNames=[]}}Mt.__counter__=0;const St=["render"];class Bt{constructor(e={}){this.__id=Bt.__counter__++,this.events=Pt(St),this.model=e.model||null,this.template=e.template||"",this.parent=e.parent||null,this._classList=e.classList||[],this.el=null}static getHTML(e,t){return be(e,t)}static parseHTML(e){return we(e)}static insertAfter(e,t){Array.isArray(e)||(e=[e]);for(let i=0;i<e.length;i++)t.parentNode&&t.parentNode.insertBefore(e[i],t.nextSibling);return e}static insertBefore(e,t){Array.isArray(e)||(e=[e]);for(let i=0;i<e.length;i++)t.parentNode&&t.parentNode.insertBefore(e[i],t);return e}insertBefore(e){this.el||this.render(),this.el&&(e instanceof HTMLElement&&e.parentNode&&Bt.insertBefore(this.el,e),e instanceof Bt&&e.el&&e.el.parentNode&&Bt.insertBefore(this.el,e.el))}insertAfter(e){this.el||this.render(),this.el&&(e instanceof HTMLElement&&e.parentNode&&Bt.insertAfter(this.el,e),e instanceof Bt&&e.el&&e.el.parentNode&&Bt.insertAfter(this.el,e.el))}isEqual(e){return e.__id===this.__id}appendTo(e,t=!1,i=!1){return e&&(this.el||(this.beforeRender(e),this.render()),this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),t&&(e.innerHTML=""),this.el&&(i&&e.childNodes[0]?Bt.insertBefore(this.el,e.childNodes[0]):e.appendChild(this.el)),this.afterRender(e)),this}afterRender(e){}beforeRender(e){}stopPropagation(){this.events.stopPropagation()}renderTemplate(e){return Bt.parseHTML(Bt.getHTML(this.template,e||{}))[0]}render(e){this.el=this.renderTemplate(e);for(let e=0,t=this._classList.length;e<t;e++)this.el.classList.add(this._classList[e]);return this.events.dispatch(this.events.render,this),this}select(e){return this.el?this.el.querySelector(e):null}selectRemove(e){if(this.el){let t=this.select(e);if(t&&t.parentNode)return t.parentNode.removeChild(t),t}}selectAll(e,t){if(this.el){const i=this.el.querySelectorAll(e);if(t)for(let e=0,n=i.length;e<n;e++)t(i[e],e);return i}}remove(){this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el)}}Bt.__counter__=0;const kt=["click","mousedown","mouseup","touchstart","touchend","touchcancel"];class Rt extends Bt{constructor(e={}){super({template:be('<div class="og-button" title="{title}">\n <div class="og-button-icon">{icon}</div>\n <div class="og-button-text">{text}</div>\n </div>',{icon:e.icon||"",text:e.text||"",title:e.title||""}),...e}),this._onMouseDown=e=>{e.preventDefault(),this.events.dispatch(this.events.mousedown,this,e)},this._onMouseUp=e=>{e.preventDefault(),this.events.dispatch(this.events.mouseup,this,e)},this._onTouchStart=e=>{e.preventDefault(),this.events.dispatch(this.events.touchstart,this,e)},this._onTouchEnd=e=>{e.preventDefault(),this.events.dispatch(this.events.touchend,this,e)},this._onTouchCancel=e=>{e.preventDefault(),this.events.dispatch(this.events.touchcancel,this,e)},this._onMouseClick=e=>{this._mouseClickHandler(e)},this.events=this.events.registerNames(kt),this.el=null,this.name=e.name||"",this.$icon=null,this.$text=null}render(e){return super.render(e),this.$icon=this.select(".og-button-icon"),this.$text=this.select(".og-button-text"),this.el.__og_button__=this,this._initEvents(),this}_initEvents(){this.el&&(this.el.addEventListener("click",this._onMouseClick),this.el.addEventListener("mousedown",this._onMouseDown),this.el.addEventListener("mouseup",this._onMouseUp),this.el.addEventListener("touchstart",this._onTouchStart),this.el.addEventListener("touchend",this._onTouchEnd),this.el.addEventListener("touchcancel",this._onTouchCancel))}_mouseClickHandler(e){e.preventDefault(),this.events.dispatch(this.events.click,this,e)}remove(){this._clearEvents(),super.remove()}_clearEvents(){this.el&&this.el.removeEventListener("click",this._onMouseClick)}}class It{constructor(e={}){this.__id=It.__counter__++,this._name=e.name||`_control_${this.__id.toString()}`,this.planet=null,this._initialized=!1,this.renderer=null,this.autoActivate=e.autoActivate||!1,this._active=!1,this._deferredActive=!0}get name(){return this._name}oninit(){}onadd(){}onremove(){}onactivate(){}ondeactivate(){}addTo(e){e&&(this.renderer=e,e.controls[this.name]=this,this.onadd&&this.onadd(),e.isInitialized()&&(this._initialized=!0,this.oninit&&this.oninit(),this.autoActivate&&this.activate()))}remove(){this.deactivate(),this.onremove&&this.onremove();let e=this.renderer,t=this.name;if(!e)return;let i=e.controls[t];i&&this.isEqual(i)&&delete e.controls[t],this.renderer=null,this._active=!1,this._initialized=!1}activate(){this._active||(this._initialized||(this._initialized=!0,this.oninit&&this.oninit()),this._deferredActive?(this._active=!0,this.onactivate&&this.onactivate()):this._deferredActive=!0)}deactivate(){this._active?(this._active=!1,this.ondeactivate&&this.ondeactivate()):this._initialized||(this._deferredActive=!1)}isActive(){return this._active}isEqual(e){return e.__id===this.__id}}It.__counter__=0;class zt extends It{constructor(e={}){super(e),this._heading=0,this._svg=null}oninit(){let e=new Rt({classList:["og-map-button","og-compass-button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg\n xmlns:dc="http://purl.org/dc/elements/1.1/"\n xmlns:cc="http://creativecommons.org/ns#"\n xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n xmlns:svg="http://www.w3.org/2000/svg"\n xmlns="http://www.w3.org/2000/svg"\n xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"\n xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"\n viewBox="0 0 110.6 110.3"\n version="1.1"\n id="svg21"\n sodipodi:docname="aaa.svg"\n inkscape:version="0.92.3 (2405546, 2018-03-11)">\n <metadata\n id="metadata11">\n <rdf:RDF>\n <cc:Work\n rdf:about="">\n <dc:format>image/svg+xml</dc:format>\n <dc:type\n rdf:resource="http://purl.org/dc/dcmitype/StillImage" />\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs\n id="defs25" />\n <sodipodi:namedview\n pagecolor="#ffffff"\n bordercolor="#666666"\n borderopacity="1"\n objecttolerance="10"\n gridtolerance="10"\n guidetolerance="10"\n inkscape:pageopacity="0"\n inkscape:pageshadow="2"\n inkscape:window-width="1920"\n inkscape:window-height="1001"\n id="namedview23"\n showgrid="false"\n inkscape:zoom="9.4900968"\n inkscape:cx="28.376998"\n inkscape:cy="60.17054"\n inkscape:window-x="-9"\n inkscape:window-y="-9"\n inkscape:window-maximized="1"\n inkscape:current-layer="svg21" />\n <g\n id="Layer_2"\n data-name="Layer 2"\n transform="matrix(1,0,0,-1,0,110.3)">\n <g\n id="Слой_1"\n data-name="Слой 1">\n <g\n id="_Group_"\n data-name="<Group>">\n <g\n id="_Group_7"\n data-name="<Group>">\n <polygon\n id="_Path_7"\n data-name="<Path>"\n points="55.2,97.6 55.3,97.4 55.3,97.6 55.3,97.2 65.3,55.1 55.3,55.1 55.2,55.1 45.3,55.1 55.2,97.2 "\n style="fill:#ff2b45" />\n <polygon\n id="_Path_8"\n data-name="<Path>"\n points="55.3,12.7 55.3,12.9 55.2,12.7 55.2,13.1 45.3,55.1 55.2,55.1 55.3,55.1 65.3,55.1 55.3,13.1 "\n style="fill:#cecece;" />\n </g>\n </g>\n </g>\n </g>\n</svg>'});e.appendTo(this.renderer.div),e.events.on("click",this._onClick,this),this._svg=e.select("svg"),this.renderer.events.on("draw",this._draw,this)}_onClick(){const e=this.planet;let t=e.getCartesianFromPixelTerrain(this.renderer.handler.getCenter());t?e.flyCartesian(t.normal().scaleTo(t.length()+t.distance(e.camera.eye)),null,null,0,null,null,(()=>{e.camera.look(t)})):e.flyCartesian(e.camera.eye)}_draw(){this.setHeading(this.planet.camera.getHeading())}setHeading(e){this._heading!==e&&(this._heading=e,this._svg.style.transform=`rotateZ(${-e}deg)`)}}const Ft='<svg className="svg-icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor; overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">\n <path d="M777.856 280.192l-33.92-33.952-231.872 231.872-231.84-231.872-33.984 33.888 231.872 231.904-231.84 231.84 33.888 33.984 231.904-231.904 231.84 231.872 33.952-33.888-231.872-231.904z"/>\n</svg>',Dt=["resize","focus","visibility","dragstart","dragend"];class Nt extends Bt{constructor(e={}){super({template:be('<div class="og-ddialog" \n style="display:{display}; resize:{resize}; width: {width}px; {height}; top: {top}px; left: {left}px; min-height: {minHeight}; max-height: {maxHeight}; min-width: {minWidth}; max-width: {maxWidth};">\n <div class="og-ddialog-header">\n <div class="og-ddialog-header__title">{title}</div> \n <div class="og-ddialog-header__buttons"></div> \n </div>\n <div class="og-ddialog-container"></div>\n </div>>',{title:e.title||"",display:ce(e.visible,!0)?"flex":"none",resize:ce(e.resizable,!0)?"both":"none",width:e.width||300,height:e.height?`height: ${e.height||200}px`:"",left:e.left||0,top:e.top||0,minHeight:e.minHeight?`${e.minHeight}px`:"unset",maxHeight:e.maxHeight?`${e.maxHeight}px`:"unset",minWidth:e.minWidth?`${e.minWidth}px`:"unset",maxWidth:e.maxWidth?`${e.maxWidth}px`:"unset"}),...e}),this._onCloseBtnClick=()=>{this.close()},this._onMouseDownAll=()=>{this.bringToFront()},this._onMouseDown=e=>{e.preventDefault(),this._startDragging(),this._startPosX=e.clientX,this._startPosY=e.clientY,document.addEventListener("mousemove",this._onMouseMove),document.addEventListener("mouseup",this._onMouseUp)},this._onMouseMove=e=>{e.preventDefault();let t=this._startPosX-e.clientX,i=this._startPosY-e.clientY;this._startPosX=e.clientX,this._startPosY=e.clientY,this.setPosition(this.el.offsetLeft-t,this.el.offsetTop-i)},this._onMouseUp=()=>{this._clearDragging(),document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove)},this.events=this.events.registerNames(Dt),this._startPosX=0,this._startPosY=0,this.$header=null,this.$title=null,this.$container=null,this.$buttons=null,this._closeBtn=new Rt({icon:Ft,classList:["og-button-size__20"]}),this.useHide=e.useHide||!1,this._visibility=ce(e.visible,!0)}setContainer(e){this.$container.innerHTML=e}get container(){return this.$container}get width(){return this.el?parseFloat(this.el.style.width):0}get height(){return this.el?parseFloat(this.el.style.height):0}bringToFront(){this.el.style.zIndex=String(Nt.__zIndex__++)}render(e){return super.render(e),this.bringToFront(),this.$header=this.select(".og-ddialog-header"),this.$title=this.select(".og-ddialog-header__title"),this.$container=this.select(".og-ddialog-container"),this.$buttons=this.select(".og-ddialog-header__buttons"),this._initEvents(),this._initButtons(),this}show(){this._visibility||(this._visibility=!0,this.el.style.display="flex",this.bringToFront(),this.events.dispatch(this.events.visibility,!0,this))}hide(){this._visibility&&(this._visibility=!1,this.el.style.display="none",this.events.dispatch(this.events.visibility,!1,this))}close(){this.useHide?this.hide():this.remove()}setVisibility(e){e?this.show():this.hide()}_initButtons(){this._closeBtn.events.on("click",this._onCloseBtnClick),this._closeBtn.appendTo(this.$buttons)}_initEvents(){this.$header.addEventListener("mousedown",this._onMouseDown),this.el.addEventListener("mousedown",this._onMouseDownAll)}setPosition(e,t){null!=e&&(this.el.style.left=`${e}px`),null!=t&&(this.el.style.top=`${t}px`)}_startDragging(){this.el.classList.contains("dragging")||(this.el.classList.add("dragging"),this.events.dispatch(this.events.dragstart,this))}_clearDragging(){this.el.classList.contains("dragging")&&(this.events.dispatch(this.events.dragend,this),this.el.classList.remove("dragging"))}remove(){this._clearDragging(),this._clearEvents(),super.remove()}_clearEvents(){this._closeBtn.events.off("click",this._onCloseBtnClick),document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove),this.$header.removeEventListener("mousedown",this._onMouseDown),this.el.removeEventListener("mousedown",this._onMouseDownAll)}}Nt.__zIndex__=0;const Ht=["change"];class Ot extends Rt{constructor(e){super({...e}),this._onMouseClick=e=>{this.preventClick||(this._mouseClickHandler(e),this.setActive(!this.isActive))},this.events=this.events.registerNames(Ht),this._isActive=e.isActive||!1,this.preventClick=e.preventClick||!1}setActive(e,t=!1){e!==this._isActive&&(this._isActive=e,this._toggle(),t||this.events.dispatch(this.events.change,e,this))}_toggle(){this.el&&this.el.classList.toggle("og-button__active")}get isActive(){return this._isActive}render(e){return super.render(e),this._isActive&&this._toggle(),this}}const Vt=[2,3,0,1],Ut=[[-1,-1,0,1],[1,-1,3,-1],[2,3,-1,-1],[-1,0,-1,2]],Gt=[[2,3,0,1],[1,0,3,2],[2,3,0,1],[1,0,3,2]],Wt=[[0,1,0,0],[1,0,0,0],[0,1,0,1],[1,1,1,1]];class jt{constructor(e,t){this.segment=e,this.layer=t,this.isReady=!1,this.isLoading=!1,this.texture=null,this.pickingMask=null,this.textureExists=!1,this.appliedNodeId=0,this.appliedNode=null,this.texOffset=[0,0,1,1],this.loadingAttempts=0,this._updateTexture=null,this._updatePickingMask=null,this.pickingReady=!1}abortLoading(){this.layer.abortMaterialLoading(this)}_createTexture(e){return this.layer._planet&&this.layer.createTexture(e,this.layer._internalFormat,this.isReady?this.texture:null)}applyImage(e){this.segment.initialized&&(this._updateTexture=null,this.texture=this._createTexture(e),this.isReady=!0,this.pickingReady=!0,this.textureExists=!0,this.isLoading=!1,this.appliedNodeId=this.segment.node.nodeId,this.texOffset=[0,0,1,1])}applyTexture(e,t){this.segment.initialized&&(this.texture=e,this._updateTexture=null,this.pickingMask=t||null,this._updatePickingMask=null,this.isReady=!0,this.pickingReady=!0,this.textureExists=!0,this.isLoading=!1,this.appliedNodeId=this.segment.node.nodeId,this.texOffset=[0,0,1,1])}textureNotExists(){this.segment.initialized&&(this.pickingReady=!0,this.isLoading=!1,this.isReady=!0,this.textureExists=!1)}clear(){this.loadingAttempts=0,this.layer.clearMaterial(this)}}const Yt=15.8;class qt{constructor(e,t={}){if(this.isVector=!1,this.__id=qt.__counter__++,this._iconSrc=t.iconSrc||null,this.events=Pt(Xt,this),this.name=e||"noname",this.properties=t.properties||{},this.hideInLayerSwitcher=t.hideInLayerSwitcher||!1,this._hasImageryTiles=!0,this._opacity=t.opacity||1,this.minZoom=t.minZoom||0,this.maxZoom=t.maxZoom||50,this._planet=null,this.isVector=!1,this._attribution=t.attribution||"",this._zIndex=t.zIndex||0,this._isBaseLayer=t.isBaseLayer||!1,this._defaultTextures=t.defaultTextures||[null,null],this._visibility=void 0===t.visibility||t.visibility,this._fading=t.fading||!1,this._fadingFactor=this._opacity/Yt,this._fading?this._fadingOpacity=this._visibility?this._opacity:0:this._fadingOpacity=this._opacity,this._height=t.height||0,this._extent=new ie,this.createTexture=null,this._textureFilter=t.textureFilter?t.textureFilter.trim().toUpperCase():"MIPMAP",this._isSRGB=null!=t.isSRGB&&t.isSRGB,this._internalFormat=null,this._extentMerc=new ie,this.setExtent(Me(t.extent,new ie(new z(-180,-90),new z(180,90)))),this._pickingColor=new oe,this._pickingEnabled=void 0===t.pickingEnabled||t.pickingEnabled,this._isPreloadDone=!1,this._preLoadZoomLevels=t.preLoadZoomLevels||[0,1],this._ambient=null,this._diffuse=null,this._specular=null,t.ambient){let e=Pe(t.ambient,new oe(.2,.2,.2));this._ambient=new Float32Array([e.x,e.y,e.z])}if(t.diffuse){let e=Pe(t.diffuse,new oe(.8,.8,.8));this._diffuse=new Float32Array([e.x,e.y,e.z])}if(t.specular){let e=Pe(t.specular,new oe(3e-4,3e-4,3e-4)),i=t.shininess||20;this._specular=new Float32Array([e.x,e.y,e.z,i])}this.nightTextureCoefficient=t.nightTextureCoefficient||1}get iconSrc(){return this._iconSrc}set iconSrc(e){this._iconSrc=e}set diffuse(e){if(e){let t=Pe(e);this._diffuse=new Float32Array(t.toArray())}else this._diffuse=null}set ambient(e){if(e){let t=Pe(e);this._ambient=new Float32Array(t.toArray())}else this._ambient=null}set specular(e){if(e){let t=Pe(e);this._specular=new Float32Array([t.x,t.y,t.y,this._specular?this._specular[3]:0])}else this._specular=null}set shininess(e){this._specular&&(this._specular[3]=e)}static getTMS(e,t,i){return{x:e,y:(1<<i)-t-1,z:i}}static getTileIndex(e,t,i,n){return`${n}::${e}_${t}_${i}`}get instanceName(){return"Layer"}get rendererEvents(){return this.events}set opacity(e){e!==this._opacity&&(this._fading?(e>this._opacity||e<this._opacity)&&(this._fadingFactor=(e-this._opacity)/Yt):this._fadingOpacity=e,this._opacity=e)}set pickingEnabled(e){this._pickingEnabled=e}get pickingEnabled(){return this._pickingEnabled}hasImageryTiles(){return this._hasImageryTiles}getID(){return this.__id}get id(){return this.__id}get _id(){return this.__id}isEqual(e){return e.__id===this.__id}_assignPlanet(e){this._planet=e,e._layers.push(this),e.renderer&&e.renderer.isInitialized()&&(this._isSRGB?this._internalFormat=e.renderer.handler.gl.SRGB8_ALPHA8:this._internalFormat=e.renderer.handler.gl.RGBA8,this.createTexture=e.renderer.handler.createTexture[this._textureFilter],this.events.on("visibilitychange",e._onLayerVisibilityChanged,e),this._isBaseLayer&&this._visibility&&e.setBaseLayer(this),e.events.dispatch(e.events.layeradd,this),this.events.dispatch(this.events.add,e),e.updateVisibleLayers(),this._bindPicking(),this._visibility&&this.hasImageryTiles()&&this._preLoad())}get isIdle(){return this._planet&&this._planet._terrainCompletedActivated||!1}_bindPicking(){this._planet&&this._planet.renderer&&this._planet.renderer.assignPickingColor(this)}addTo(e){this._planet||this._assignPlanet(e)}remove(){let e=this._planet;if(e)for(let t=0;t<e._layers.length;t++)if(this.isEqual(e._layers[t]))return e.renderer&&e.renderer.clearPickingColor(this),e._layers.splice(t,1),e.updateVisibleLayers(),this.clear(),e.events.dispatch(e.events.layerremove,this),this.events.dispatch(this.events.remove,e),this._planet=null,this._internalFormat=null,this.createTexture=null,this;return this}clear(){this._planet&&this._planet._clearLayerMaterial(this)}get planet(){return this._planet}setAttribution(e){this._attribution!==e&&(this._attribution=e,this._planet&&this._planet.updateAttributionsList())}getAttribution(){return this._attribution}setHeight(e){this._height=e,this._planet&&this._planet.updateVisibleLayers()}getHeight(){return this._height}setZIndex(e){this._zIndex=e,this._planet&&this._planet.updateVisibleLayers()}getZIndex(){return this._zIndex}bringToFront(){if(this._planet){let e=this._planet.visibleTileLayers,t=e[e.length-1];t.isEqual(this)||this.setZIndex(t.getZIndex()+1)}}isBaseLayer(){return this._isBaseLayer}setBaseLayer(e){this._isBaseLayer=e,this._planet&&(!e&&this._planet.baseLayer&&this.isEqual(this._planet.baseLayer)&&(this._planet.baseLayer=null),this._planet.updateVisibleLayers())}setVisibility(e){e!==this._visibility&&(this._visibility=e,this._planet&&(this._isBaseLayer&&e&&this._planet.setBaseLayer(this),this._planet.updateVisibleLayers(),!e||this._isPreloadDone||this.isVector||(this._isPreloadDone=!0,this._preLoad())),this.events.dispatch(this.events.visibilitychange,this))}_forceMaterialApply(e){let t=e.materials,i=t[this.__id];i||(i=t[this.__id]=this.createMaterial(e)),i.isReady||(this._planet._renderCompleted=!1),this.applyMaterial(i,!0)}clearMaterial(e){}loadMaterial(e,t=!1){}applyMaterial(e,t=!1){return[0,0,1,1]}_preLoadRecursive(e,t){if(!(e.segment.tileZoom>t)){this._preLoadZoomLevels.includes(e.segment.tileZoom)&&this._forceMaterialApply(e.segment);for(let i=0,n=e.nodes.length;i<n;i++)e.nodes[i]&&this._preLoadRecursive(e.nodes[i],t)}}_preLoad(){if(this._planet&&this._preLoadZoomLevels.length){let e=this._planet,t=Math.max(...this._preLoadZoomLevels);for(let i=0,n=e.quadTreeStrategy.quadTreeList.length;i<n;i++)this._preLoadRecursive(e.quadTreeStrategy.quadTreeList[i],t)}}getVisibility(){return this._visibility}setExtent(e){let t=e.southWest.clone(),i=e.northEast.clone();t.lat<ee&&(t.lat=ee),i.lat>J&&(i.lat=J),this._extent=e.clone(),this._extentMerc=new ie(t.forwardMercator(),i.forwardMercator()),this._correctFullExtent()}getExtent(){return this._extent}getExtentMerc(){return this._extentMerc}flyExtent(){this._planet?.flyExtent(this.getExtent())}viewExtent(){this._planet?.viewExtent(this.getExtent())}_correctFullExtent(){}get opacity(){return this._opacity}get screenOpacity(){return this._fading?this._fadingOpacity:this._opacity}_refreshFadingOpacity(){let e=this._planet;return this._visibility&&e.getViewExtent().overlaps(this._extent)&&e.maxCurrZoom>=this.minZoom&&e.minCurrZoom<=this.maxZoom?(this._fadingOpacity+=this._fadingFactor,(this._fadingFactor>0&&this._fadingOpacity>this._opacity||this._fadingFactor<0&&this._fadingOpacity<this._opacity)&&(this._fadingOpacity=this._opacity),!1):(this._fadingOpacity=0,!this._visibility)}createMaterial(e){return new jt(e,this)}redraw(){this._planet&&this._planet.quadTreeStrategy.clearLayerMaterial(this)}abortMaterialLoading(e){}abortLoading(){}}qt.__counter__=0;const Xt=["visibilitychange","add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"],Zt=["load","loadend"];class $t extends qt{constructor(e,t){super(e,t),this.events=this.events.registerNames(Zt),this.animated=t.animated||!1,this.minNativeZoom=t.minNativeZoom||0,this.maxNativeZoom=t.maxNativeZoom||100,this._counter=0,this._pendingsQueue=[],this.drawTile=t.drawTile,this._onLoadend_=null}addTo(e){return this._onLoadend_=this._onLoadend.bind(this),this.events.on("loadend",this._onLoadend_,this),super.addTo(e)}remove(){return this.events.off("loadend",this._onLoadend_),this._onLoadend_=null,super.remove()}_onLoadend(){this._planet&&this._planet._terrainCompletedActivated&&this._planet.events.dispatch(this._planet.events.layerloadend,this)}get instanceName(){return"CanvasTiles"}get isIdle(){return super.isIdle&&0===this._counter}abortLoading(){this._pendingsQueue.forEach((e=>{this.abortMaterialLoading(e)})),this._pendingsQueue=[]}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),e||this.abortLoading())}loadMaterial(e){let t=e.segment;this._isBaseLayer?e.texture=t._isNorth?t.planet.solidTextureOne:t.planet.solidTextureTwo:e.texture=t.planet.transparentTexture,(this._planet.layerLock.isFree()||e.segment.tileZoom<2)&&(e.isReady=!1,e.isLoading=!0,$t.__requestsCounter>=$t.MAX_REQUESTS&&this._counter?this._pendingsQueue.push(e):this._exec(e))}_exec(e){$t.__requestsCounter++,this._counter++;const t=this.events.load;t.handlers.length&&this.events.dispatch(t,e),requestAnimationFrame((()=>{this.drawTile(e,(t=>{this._counter--,$t.__requestsCounter--,this._correctCounter(),e.isLoading&&e.applyImage(t),this._dequeueRequest()}))}))}_correctCounter(){this._counter<0&&(this._counter=0),$t.__requestsCounter<0&&($t.__requestsCounter=0)}abortMaterialLoading(e){e.isLoading&&(this._counter--,$t.__requestsCounter--,this._correctCounter(),this._dequeueRequest()),e.isLoading=!1,e.isReady=!1}_dequeueRequest(){if(this._pendingsQueue.length){if($t.__requestsCounter<$t.MAX_REQUESTS){const e=this._whilePendings();e&&this._exec(e)}}else 0===this._counter&&this._planet&&this._planet._terrainCompletedActivated&&this.events.dispatch(this.events.loadend)}_whilePendings(){for(;this._pendingsQueue.length;){const e=this._pendingsQueue.pop();if(e&&e.segment&&e.segment.node){if(e.segment.initialized&&1===e.segment.node.getState())return e;e.isLoading=!1}}return null}applyMaterial(e){if(e.isReady)return e.layer.animated&&requestAnimationFrame((()=>{this.drawTile(e,(function(t){e.applyImage(t)}))})),e.texOffset;if(e.segment.tileZoom<this.minNativeZoom)e.textureNotExists();else{let t=e.segment,i=t.node,n=!1,r=e.layer.maxNativeZoom;t.passReady&&!e.isLoading&&t.tileZoom<=r&&this.loadMaterial(e);let s=this._id,a=e;for(;i.parentNode;)if(i=i.parentNode,a=i.segment.materials[s],a&&a.textureExists){n=!0;break}if(t.passReady)if(i.segment.tileZoom===r)t.tileZoom>r&&e.textureNotExists();else if(i.segment.tileZoom<r){let i=t.node;for(;i.segment.tileZoom>r;)i=i.parentNode;let n=i.segment.materials[s];n?!n.isLoading&&!n.isReady&&this.loadMaterial(n):(n=i.segment.materials[e.layer._id]=e.layer.createMaterial(i.segment),this.loadMaterial(n))}if(n){e.layer.animated&&requestAnimationFrame((()=>{this.drawTile(e,(function(t){e.applyImage(t)}))})),e.appliedNodeId=i.nodeId,e.texture=a.texture;let n=1/(2<<t.tileZoom-i.segment.tileZoom-1);e.texOffset[0]=t.tileX*n-i.segment.tileX,e.texOffset[1]=t.tileY*n-i.segment.tileY,e.texOffset[2]=n,e.texOffset[3]=n}else e.texture=t.planet.transparentTexture,e.texOffset[0]=0,e.texOffset[1]=0,e.texOffset[2]=1,e.texOffset[3]=1}return e.texOffset}clearMaterial(e){e.isReady&&(e.isReady=!1,e.textureExists&&e.texture&&!e.texture.default&&(e.segment.handler.gl.deleteTexture(e.texture),e.texture=null)),this.abortMaterialLoading(e),e.isLoading=!1,e.textureExists=!1,e.layer=null,e.segment=null}}$t.MAX_REQUESTS=20,$t.__requestsCounter=0;const Kt=["change"];class Qt{constructor(e={}){this._onChange=(e,t)=>{if(e){t.preventClick=!0;for(let e=0;e<this._buttons.length;e++){let i=this._buttons[e];i.isEqual(t)||(i.setActive(!1),i.preventClick=!1)}this.events.dispatch(this.events.change,t)}},this.events=Pt(Kt),this._buttons=e.buttons||[];for(let e=0;e<this._buttons.length;e++)this._bindButton(this._buttons[e])}_bindButton(e){e.events.on("change",this._onChange)}add(e){this._buttons.push(e),this._bindButton(e)}remove(e){for(let t=0;t<this._buttons.length;t++)if(this._buttons[t].isEqual(e))return this._buttons.splice(t),void e.events.off("change",this._onChange)}}class Jt{constructor(e=2,t){this._sourceId=0,this._source=new Map,this._pendingQueue=[],this._numWorkers=e,this._workerQueue=[],t&&this.setProgram(t)}check(){this._pendingQueue.length&&this.make(this._pendingQueue.pop())}setProgram(e){let t=new Blob([e],{type:"application/javascript"});for(let e=0;e<this._numWorkers;e++){let e=new Worker(URL.createObjectURL(t));e.onmessage=e=>{this._onMessage(e),this._workerQueue&&this._workerQueue.unshift(e.target),this.check()},this._workerQueue.push(e)}}make(e){}_onMessage(e){}destroy(){for(let e=0;e<this._workerQueue.length;e++){const t=this._workerQueue[e];t.onmessage=null,t.terminate()}this._pendingQueue=null,this._workerQueue=null}get pendingQueue(){return this._pendingQueue}}const ei=-2,ti=-1;class ii extends Jt{constructor(e=4){super(e,ni)}_onMessage(e){let t=this._source.get(e.data.id);t.label._lockId===ei?requestAnimationFrame((()=>{this.make({handler:t.handler,label:t.label})})):t.handler.workerCallback(e.data,t.label),this._source.delete(e.data.id)}make(e){let t=e.label;if(e.handler._entityCollection){let i=t.serializeWorkerData(this._sourceId);if(i)if(this._workerQueue.length){let n=this._workerQueue.pop();this._source.set(this._sourceId,e),t._lockId=this._sourceId,this._sourceId++,n.postMessage({labelData:i},[i.buffer])}else this._pendingQueue.push(e)}}}const ni="'use strict';\n\n function concatTypedArrays(dest, index, source) {\n let len = source.length,\n offset = index * len;\n for(let i = 0; i < len; i++) {\n dest[offset + i] = source[i];\n }\n }\n\n self.onmessage = function (e) {\n var labelData = e.data.labelData,\n id = labelData[0],\n maxLetters = labelData[1],\n isVisible = labelData[2],\n /*3, 4, 5*/_positionHigh_x = labelData[3], _positionHigh_y = labelData[4], _positionHigh_z = labelData[5],\n /*6, 7, 8*/_positionLow_x = labelData[6], _positionLow_y = labelData[7], _positionLow_z = labelData[8],\n /*9*/_size = labelData[9],\n /*10, 11, 12*/_offset_x = labelData[10], _offset_y = labelData[11], _offset_z = labelData[12],\n /*13, 14, 15, 16*/_color_x = labelData[13], _color_y = labelData[14], _color_z = labelData[15], _color_w = labelData[16],\n /*17*/_rotation = labelData[17],\n /*18, 19, 20*/_alignedAxis_x = labelData[18], _alignedAxis_y = labelData[19], _alignedAxis_z = labelData[20],\n /*21*/_fontIndex = labelData[21],\n /*22*/_outline = labelData[22],\n /*23, 24, 25, 26*/_outlineColor_x = labelData[23], _outlineColor_y = labelData[24], _outlineColor_z = labelData[25], _outlineColor_w = labelData[26],\n /*27, 28, 29*/_pickingColor_x = labelData[27], _pickingColor_y = labelData[28], _pickingColor_z = labelData[29]\n \n\n let _vertexArr = new Float32Array(maxLetters * 12),\n _texCoordArr = new Float32Array(maxLetters * 24),\n _gliphParamArr = new Float32Array(maxLetters * 24),\n _positionHighArr = new Float32Array(maxLetters * 18),\n _positionLowArr = new Float32Array(maxLetters * 18),\n _sizeArr = new Float32Array(maxLetters * 6),\n _offsetArr = new Float32Array(maxLetters * 18),\n _rgbaArr = new Float32Array(maxLetters * 24),\n _rotationArr = new Float32Array(maxLetters * 6),\n _alignedAxisArr = new Float32Array(maxLetters * 18),\n _fontIndexArr = new Float32Array(maxLetters * 6),\n _outlineArr = new Float32Array(maxLetters * 6),\n _outlineColorArr = new Float32Array(maxLetters * 24),\n _pickingColorArr = new Float32Array(maxLetters * 18);\n \n for (let i = 0; i < maxLetters; i++) {\n if (isVisible !== 0) {\n concatTypedArrays(_vertexArr, i, [0, 0, 0, -1, 1, -1, 1, -1, 1, 0, 0, 0]);\n } else {\n concatTypedArrays(_vertexArr, i, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);\n }\n\n concatTypedArrays(_texCoordArr, i, [0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0]);\n concatTypedArrays(_gliphParamArr, i, [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]);\n\n var x = _positionHigh_x, y = _positionHigh_y, z = _positionHigh_z, w;\n concatTypedArrays(_positionHighArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _positionLow_x; y = _positionLow_y; z = _positionLow_z;\n concatTypedArrays(_positionLowArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _size;\n concatTypedArrays(_sizeArr, i, [x, x, x, x, x, x]);\n\n x = _offset_x; y = _offset_y; z = _offset_z;\n concatTypedArrays(_offsetArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _color_x; y = _color_y; z = _color_z; w = _color_w;\n concatTypedArrays(_rgbaArr, i, [x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w]);\n\n x = _rotation;\n concatTypedArrays(_rotationArr, i, [x, x, x, x, x, x]);\n\n x = _alignedAxis_x; y = _alignedAxis_y; z = _alignedAxis_z;\n concatTypedArrays(_alignedAxisArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _fontIndex;\n concatTypedArrays(_fontIndexArr, i, [x, x, x, x, x, x]);\n\n x = _outline;\n concatTypedArrays(_outlineArr, i, [x, x, x, x, x, x]);\n\n x = _outlineColor_x; y = _outlineColor_y; z = _outlineColor_z; w = _outlineColor_w;\n concatTypedArrays(_outlineColorArr, i, [x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w]);\n\n x = _pickingColor_x / 255; y = _pickingColor_y / 255; z = _pickingColor_z / 255;\n concatTypedArrays(_pickingColorArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n }\n\n self.postMessage({\n id: id,\n vertexArr: _vertexArr,\n texCoordArr: _texCoordArr,\n gliphParamArr: _gliphParamArr,\n positionHighArr: _positionHighArr,\n positionLowArr: _positionLowArr,\n sizeArr: _sizeArr,\n offsetArr: _offsetArr,\n rgbaArr: _rgbaArr,\n rotationArr: _rotationArr,\n alignedAxisArr: _alignedAxisArr,\n fontIndexArr: _fontIndexArr,\n outlineArr: _outlineArr,\n outlineColorArr: _outlineColorArr,\n pickingColorArr: _pickingColorArr\n }, [\n _vertexArr.buffer,\n _texCoordArr.buffer,\n _gliphParamArr.buffer,\n _positionHighArr.buffer,\n _positionLowArr.buffer,\n _sizeArr.buffer,\n _offsetArr.buffer,\n _rgbaArr.buffer,\n _rotationArr.buffer,\n _alignedAxisArr.buffer,\n _fontIndexArr.buffer,\n _outlineArr.buffer,\n _outlineColorArr.buffer,\n _pickingColorArr.buffer\n ]);\n }";class ri{constructor(e={}){this.__id=ri.__counter__++,this._position=Ae(e.position),this._positionHigh=new oe,this._positionLow=new oe,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._rotation=e.rotation||0,this._color=Ee(e.color),this._alignedAxis=Ae(e.alignedAxis),this._offset=Ae(e.offset),this._visibility=null==e.visibility||e.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1,this._isReady=!1,this._lockId=ti}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):this._lockId!==ti&&(this._lockId=ei)}setPosition3v(e){this._position.x=e.x,this._position.y=e.y,this._position.z=e.z,oe.doubleToTwoFloats(e,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):this._lockId!==ti&&(this._lockId=ei)}getPosition(){return this._position}setOffset(e,t,i){this._offset.x=e,this._offset.y=t,null!=i&&(this._offset.z=i),this._isReady&&this._handler?this._handler.setOffsetArr(this._handlerIndex,this._offset):this._lockId!==ti&&(this._lockId=ei)}setOffset3v(e){this.setOffset(e.x,e.y,e.z)}getOffset(){return this._offset}setRotation(e){e!==this._rotation&&(this._rotation=e,this._isReady&&this._handler?this._handler.setRotationArr(this._handlerIndex,e):this._lockId!==ti&&(this._lockId=ei))}getRotation(){return this._rotation}setOpacity(e){e!==this._color.w&&(null!=e&&(this._color.w=e),this._isReady&&this._handler?this._handler.setRgbaArr(this._handlerIndex,this._color):this._lockId!==ti&&(this._lockId=ei))}setColor(e,t,i,n){n===this._color.w&&e===this._color.x&&t===this._color.y&&this._color.z===i||(this._color.x=e,this._color.y=t,this._color.z=i,null!=n&&(this._color.w=n),this._isReady&&this._handler?this._handler.setRgbaArr(this._handlerIndex,this._color):this._lockId!==ti&&(this._lockId=ei))}setColor4v(e){this.setColor(e.x,e.y,e.z,e.w)}setColorHTML(e){this.setColor4v(ve(e))}getColor(){return this._color}setVisibility(e){e!==this._visibility&&(this._visibility=e,this._isReady&&this._handler?this._handler.setVisibility(this._handlerIndex,e):this._lockId!==ti&&(this._lockId=ei))}getVisibility(){return this._visibility}setAlignedAxis(e,t,i){this._alignedAxis.x=e,this._alignedAxis.y=t,this._alignedAxis.z=i,this._isReady&&this._handler?this._handler.setAlignedAxisArr(this._handlerIndex,this._alignedAxis):this._lockId!==ti&&(this._lockId=ei)}setAlignedAxis3v(e){this.setAlignedAxis(e.x,e.y,e.z)}getAlignedAxis(){return this._alignedAxis}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._isReady&&this._handler?this._handler.setPickingColorArr(this._handlerIndex,e):this._lockId!==ti&&(this._lockId=ei)}serializeWorkerData(e){return this._handler?new Float32Array([]):null}}ri.__counter__=0;class si extends ri{constructor(e={}){super(e),this._handler=null,this._src=e.src||null,this._image=e.image||null,this._scale=1,this._width=e.width||(e.size?e.size[0]:30),this._height=e.height||(e.size?e.size[1]:30)}setSrc(e){this._src=e;let t=this._handler;if(t&&e&&e.length){let i=t._entityCollection.renderNode;if(i&&i.renderer){let n=i.renderer.billboardsTextureAtlas,r=this;n.loadImage(e,(function(e){null!=e.__nodeIndex&&n.get(e.__nodeIndex)?(r._image=e,t.setTexCoordArr(r._handlerIndex,n.get(r._image.__nodeIndex).texCoords)):(n.addImage(e),n.createTexture(),r._image=e,i.updateBillboardsTexCoords())}))}}}getSrc(){return this._src}setImage(e){this.setSrc(e.src)}getImage(){return this._image}setSize(e,t){this._width=e,this._height=t,this._handler&&this._handler.setSizeArr(this._handlerIndex,e*this._scale,t*this._scale)}getSize(){return{width:this._width,height:this._height}}setWidth(e){this.setSize(e,this._height)}getWidth(){return this._width}setHeight(e){this.setSize(this._width,e)}getHeight(){return this._height}}var ai;!function(e){e[e.POINT=1]="POINT",e[e.LINESTRING=2]="LINESTRING",e[e.POLYGON=3]="POLYGON",e[e.MULTIPOLYGON=4]="MULTIPOLYGON",e[e.MULTILINESTRING=5]="MULTILINESTRING"}(ai||(ai={}));const oi={POINT:1,LINESTRING:2,POLYGON:3,MULTIPOLYGON:4,MULTILINESTRING:5};class li{constructor(e={}){this.__id=li.__counter__++,this._entity=null,this._handler=null,this._handlerIndex=-1,this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyVerticesLength=-1,this._polyIndexesLength=-1,this._polyVerticesHandlerIndex=-1,this._polyIndexesHandlerIndex=-1,this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineVerticesLength=-1,this._lineOrdersLength=-1,this._lineIndexesLength=-1,this._lineColorsLength=-1,this._lineThicknessLength=-1,this._lineVerticesHandlerIndex=-1,this._lineOrdersHandlerIndex=-1,this._lineIndexesHandlerIndex=-1,this._lineThicknessHandlerIndex=-1,this._lineColorsHandlerIndex=-1,this._type=e.type&&li.getType(e.type)||ai.POINT,this._coordinates=e.coordinates||[],this._extent=li.getExtent({type:e.type||"POINT",coordinates:e.coordinates||[]},this._coordinates),e.style=e.style||{},this._style={fillColor:Ee(e.style.fillColor,new re(.19,.62,.85,.4)),lineColor:Ee(e.style.lineColor,new re(.19,.62,.85,1)),strokeColor:Ee(e.style.strokeColor,new re(1,1,1,.95)),lineWidth:e.style.lineWidth||3,strokeWidth:e.style.strokeWidth||0},this._visibility=e.visibility||!0,this._pickingReady=!1}get id(){return this.__id}get type(){return this._type}static getType(e){return oi[e.toUpperCase()]}static getExtent(e,t){let i=new ie(new z(180,90),new z(-180,-90)),n=li.getType(e.type);if(n===ai.POINT){let n=e.coordinates[0],r=e.coordinates[1];i.southWest.lon=n,i.southWest.lat=r,i.northEast.lon=n,i.northEast.lat=r,t&&(t[0]=n)&&(t[1]=r)}else if(n===ai.LINESTRING){let n=e.coordinates;for(let e=0;e<n.length;e++){let r=n[e][0],s=n[e][1];r<i.southWest.lon&&(i.southWest.lon=r),s<i.southWest.lat&&(i.southWest.lat=s),r>i.northEast.lon&&(i.northEast.lon=r),s>i.northEast.lat&&(i.northEast.lat=s),t&&(t[e]=[r,s])}}else if(n===ai.POLYGON){let n=e.coordinates;for(let e=0;e<n.length;e++){let r=n[e];t&&(t[e]=[]);for(let n=0;n<r.length;n++){let s=r[n],a=s[0],o=s[1];a<i.southWest.lon&&(i.southWest.lon=a),o<i.southWest.lat&&(i.southWest.lat=o),a>i.northEast.lon&&(i.northEast.lon=a),o>i.northEast.lat&&(i.northEast.lat=o),t&&(t[e][n]=[a,o])}}}else if(n===ai.MULTIPOLYGON){let n=e.coordinates;for(let e=0;e<n.length;e++){let r=n[e];t&&(t[e]=[]);for(let n=0;n<r.length;n++){let s=r[n];t&&(t[e][n]=[]);for(let r=0;r<s.length;r++){let a=s[r],o=a[0],l=a[1];o<i.southWest.lon&&(i.southWest.lon=o),l<i.southWest.lat&&(i.southWest.lat=l),o>i.northEast.lon&&(i.northEast.lon=o),l>i.northEast.lat&&(i.northEast.lat=l),t&&(t[e][n][r]=[o,l])}}}}else if(n===ai.MULTILINESTRING){let n=e.coordinates;for(let e=0;e<n.length;e++){let r=n[e];t&&(t[e]=[]);for(let n=0;n<r.length;n++){let s=r[n],a=s[0],o=s[1];a<i.southWest.lon&&(i.southWest.lon=a),o<i.southWest.lat&&(i.southWest.lat=o),a>i.northEast.lon&&(i.northEast.lon=a),o>i.northEast.lat&&(i.northEast.lat=o),t&&(t[e][n]=[a,o])}}}else i.southWest.lon=i.southWest.lat=i.northEast.lon=i.northEast.lat=0,t&&(t[0]=0)&&(t[1]=0);return i}setGeometry(e){let t=this._handler;return t&&(this.remove(),this._type=li.getType(e.type||"Point"),this._extent=li.getExtent(e,this._coordinates),t.add(this)),this}setFillColor(e,t,i,n=1){let r=this._style.fillColor;return(0===r.w&&0!==n||0!==r.w&&0===n)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=n,this._handler&&this._handler.setPolyColorArr(this,r),this}overlaps(e){return this._extent.overlaps(e)}setFillColor4v(e){return this.setFillColor(e.x,e.y,e.z,e.w)}setStrokeColor(e,t,i,n=1){let r=this._style.strokeColor;return(0===r.w&&0!==n||0!==r.w&&0===n)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=n,this._handler&&this._handler.setLineStrokeColorArr(this,r),this}setLineColor(e,t,i,n=1){let r=this._style.lineColor;return(0===r.w&&0!==n||0!==r.w&&0===n)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=n,this._handler&&this._handler.setLineColorArr(this,r),this}setStrokeColor4v(e){return this.setStrokeColor(e.x,e.y,e.z,e.w)}setLineColor4v(e){return this.setLineColor(e.x,e.y,e.z,e.w)}setStrokeOpacity(e){let t=this._style.strokeColor;return t.w=e,this.setStrokeColor(t.x,t.y,t.z,e)}setLineOpacity(e){let t=this._style.lineColor;return t.w=e,this.setLineColor(t.x,t.y,t.z,e)}setStrokeWidth(e){return this._style.strokeWidth=e,this._pickingReady=!1,this._handler&&this._handler.setLineStrokeArr(this,e),this}bringToFront(){return this._handler&&this._handler.bringToFront(this),this}setLineWidth(e){return this._style.lineWidth=e,this._pickingReady=!1,this._handler&&this._handler.setLineThicknessArr(this,e),this}setFillOpacity(e){let t=this._style.fillColor;return(0===t.w&&0!==e||0!==t.w&&0===e)&&(this._pickingReady=!1),t.w=e,this._handler&&this._handler.setPolyColorArr(this,t),this}setVisibility(e){return this._visibility=e,this._handler&&this._handler.setGeometryVisibility(this),this}getVisibility(){return this._visibility}remove(){this._handler&&this._handler.remove(this)}getExtent(){return this._extent.clone()}getType(){return this._type}}li.__counter__=0;class hi{constructor(e=0,t=0,i=0){this.a=e,this.b=t,this.c=i}static get(e,t){return new hi(t.y-e.y,e.x-t.x,t.x*e.y-e.x*t.y)}static getParallel(e,t){return new hi(e.a,e.b,-e.a*t.x-e.b*t.y)}static getIntersection(e,t){let i=(t.b*e.c-e.b*t.c)/(e.b*t.a-t.b*e.a);return new le(i,-(e.c+e.a*i)/e.b)}intersects(e){return hi.getIntersection(this,e)}}class ci{constructor(e,t){this.p0=e||new oe,this.p1=t||new oe}getMagnitude(){return this.p0.distance(this.p1)}getSphereIntersection(e){let t=this.p0,i=this.p1,n=e.center.x,r=e.center.y,s=e.center.z,a=t.x,o=t.y,l=t.z,h=i.x-a,c=i.y-o,d=i.z-l,_=h*h+c*c+d*d,u=2*(a*h+o*c+l*d-h*n-c*r-d*s),f=u*u-4*_*(a*a-2*a*n+n*n+o*o-2*o*r+r*r+l*l-2*l*s+s*s-e.radius*e.radius);if(f<0)return[];let g=(-u-Math.sqrt(f))/(2*_),p=new oe(t.x*(1-g)+g*i.x,t.y*(1-g)+g*i.y,t.z*(1-g)+g*i.z);if(0==f)return[p];let m=(-u+Math.sqrt(f))/(2*_),v=new oe(t.x*(1-m)+m*i.x,t.y*(1-m)+m*i.y,t.z*(1-m)+m*i.z);return Math.abs(g-.5)<Math.abs(m-.5)?[p,v]:[v,p]}intersects(e,t,i){let n=this.p0.sub(e.p0),r=e.p1.sub(e.p0);if(Math.abs(r.x)<u&&Math.abs(r.y)<u&&Math.abs(r.z)<u)return!1;let s=this.p1.sub(this.p0);if(Math.abs(s.x)<u&&Math.abs(s.y)<u&&Math.abs(s.z)<u)return!1;let a=n.x*r.x+n.y*r.y+n.z*r.z,o=r.x*s.x+r.y*s.y+r.z*s.z,l=n.x*s.x+n.y*s.y+n.z*s.z,h=r.x*r.x+r.y*r.y+r.z*r.z,c=(s.x*s.x+s.y*s.y+s.z*s.z)*h-o*o;if(Math.abs(c)<u)return!1;let d=(a*o-l*h)/c;if(t.x=this.p0.x+d*s.x,t.y=this.p0.y+d*s.y,t.z=this.p0.z+d*s.z,i){let t=(a+o*d)/h;i.x=e.p0.x+t*r.x,i.y=e.p0.y+t*r.y,i.z=e.p0.z+t*r.z}return!0}getNearestDistancePoint(e,t){let i=this.p0,n=this.p1,r=this.getMagnitude(),s=((e.x-i.x)*(n.x-i.x)+(e.y-i.y)*(n.y-i.y)+(e.z-i.z)*(n.z-i.z))/(r*r);return t.x=i.x+s*(n.x-i.x),t.y=i.y+s*(n.y-i.y),t.z=i.z+s*(n.z-i.z),!(s<0||s>1)}}class di{constructor(e,t){this.p=e?e.clone():new oe,this.n=t?t.clone():this.p.normal()}set(e,t){this.p.copy(e),this.n.copy(t)}getNormal(){return this.n.clone()}distance(e){let t=this.getProjection(e);return e.distance(t)}getProjection(e,t){return oe.proj_b_to_plane(e,this.n,t)}getProjectionPoint(e,t){let i=e.sub(this.p),n=this.n,r=i.dot(n);return t?t.copy(n.scale(r)):t=n.scale(r),e.sub(t)}getIntersection(e,t,i){let n,r=e.n.cross(t.n),s=r.x>=0?r.x:-r.x,a=r.y>=0?r.y:-r.y,o=r.z>=0?r.z:-r.z;if(s+a+o<_){let i=t.p.sub(e.p);return 0==e.n.dot(i)?1:0}n=s>a?s>o?1:3:a>o?2:3;let l,h,c=new oe;return l=-e.n.dot(e.p),h=-t.n.dot(t.p),1===n?(c.x=0,c.y=(h*e.n.z-l*t.n.z)/r.x,c.z=(l*t.n.y-h*e.n.y)/r.x):2===n?(c.x=(l*t.n.z-h*e.n.z)/r.y,c.y=0,c.z=(h*e.n.x-l*t.n.x)/r.y):3===n&&(c.x=(h*e.n.y-l*t.n.y)/r.z,c.y=(l*t.n.x-h*e.n.x)/r.z,c.z=0),i.p0.copy(c),i.p1.copy(c.add(r)),2}}let _i=class e{constructor(e=oe.ZERO,t=oe.ZERO){this.origin=e,this.direction=t}static get OUTSIDE(){return 0}static get INSIDE(){return 1}static get INPLANE(){return 2}static get AWAY(){return 3}set(e,t){return this.origin=e,this.direction=t,this}getPoint(e){return oe.add(this.origin,this.direction.scaleTo(e))}hitTriangle(t,i,n,r){let s=i.sub(t),a=n.sub(t),o=s.cross(a),l=this.origin.sub(t),h=-o.dot(l),c=o.dot(this.direction);if(Math.abs(c)<u)return 0===h?(r.copy(this.origin),e.INPLANE):e.OUTSIDE;let d=h/c;if(r.copy(this.origin.add(this.direction.scaleTo(d))),d<0)return e.AWAY;let _=s.dot(s),f=s.dot(a),g=a.dot(a),p=r.sub(t),m=p.dot(s),v=p.dot(a),y=f*f-_*g,x=(f*v-g*m)/y;if(x<0||x>1)return e.OUTSIDE;let b=(f*m-_*v)/y;return b<0||x+b>1?e.OUTSIDE:e.INSIDE}hitPlane(t,i,n,r){let s=oe.sub(i,t),a=oe.sub(n,t),o=s.cross(a),l=oe.sub(this.origin,t),h=-o.dot(l),c=o.dot(this.direction);if(Math.abs(c)<u&&0===h)return e.OUTSIDE;let d=h/c;if(d<0)return e.OUTSIDE;let _=this.direction.scaleTo(d);return r.x=this.origin.x+_.x,r.y=this.origin.y+_.y,r.z=this.origin.z+_.z,e.INSIDE}hitSphere(e){let t=e.radius,i=e.center,n=this.origin,r=this.direction,s=oe.sub(i,n);if(s.dot(r)<0){var a=s.length();if(a>t)return null;if(a===t)return n.clone();let e=i.projToRay(n,s);var o=oe.sub(e,i).length();let l=Math.sqrt(t*t-o*o)-oe.sub(e,n).length();return oe.add(n,r.scaleTo(l))}{let a=i.projToRay(n,r);var l=oe.sub(i,a).length();if(l>e.radius)return null;{let e,i=Math.sqrt(t*t-l*l);return a.subA(n),e=s.length()>t?a.length()-i:a.length()+i,oe.add(n,r.scaleTo(e))}}}hitBox(e){}};function ui(e){const t=[[0,0,0]],i=[[0,0]],n=[[0,0,0]],r=[t,i,n];let s=[[],[],[]];const a=[],o=[];let l,h=["default"],c="default",d="default";function _(){l&&l.data.vertices.length&&(l=null)}function u(e){e.split("/").forEach(((e,t)=>{if(!e)return;const i=parseInt(e),n=i+(i>=0?0:r[t].length);s[t].push(...r[t][n])}))}const f={v(e){t.push(e.map(parseFloat))},vn(e){n.push(e.map(parseFloat))},vt(e){i.push(e.map(parseFloat))},f(e){!function(){if(!l){const e=[],t=[],i=[];s=[e,t,i],l={object:d,groups:h,material:c,data:{vertices:e,textures:t,normals:i}},o.push(l)}}();const t=e.length-2;for(let i=0;i<t;++i)u(e[0]),u(e[i+1]),u(e[i+2])},s:()=>{},mtllib(e,t){a.push(t)},usemtl(e,t){c=t,_()},g(e){h=e,_()},o(e,t){d=t,_()}},g=/(\w*)(?: )*(.*)/,p=e.split("\n");for(let e=0;e<p.length;++e){const t=p[e].trim();if(""===t||t.startsWith("#"))continue;const i=g.exec(t);if(!i)continue;const[,n,r]=i,s=t.split(/\s+/).slice(1),a=f[n];a?a(s,r):console.warn("unhandled keyword:",n)}for(const e of o)e.data=Object.fromEntries(Object.entries(e.data).filter((([e,t])=>t.length>0)));return{geometries:o,materialLibs:a}}function fi(e){const t=e.geometries.map((e=>{const t=e.data.vertices,i=e.data.normals,n=e.data.textures;!function(e,t){const i=Math.cos(t),n=Math.sin(t),r=e.vertices,s=e.normals;for(let e=0;e<r.length;e+=3){const t=r[e],a=r[e+1],o=r[e+2];r[e]=t*i+o*n,r[e+1]=a,r[e+2]=-t*n+o*i;const l=s[e],h=s[e+1],c=s[e+2];s[e]=l*i+c*n,s[e+1]=h,s[e+2]=-l*n+c*i}}(e.data,0);let r=[],s=[],a=[];for(let e=0;e<t.length;e+=3){const i=t[e],n=t[e+1],s=t[e+2];r.push(i,n,s)}for(let e=0;e<i.length;e+=3){const t=i[e],n=i[e+1],r=i[e+2];s.push(t,n,-r)}for(let e=0;e<n.length;e+=2){const t=n[e],i=1-n[e+1];a.push(t,i)}return{object:e.object,groups:e.groups,material:e.material,data:{vertices:r,normals:s,textures:a}}}));return{geometries:t,materialLibs:e.materialLibs}}class gi{constructor(e={}){var t;if(this._name=e.name||"noname",this._vertices=e.vertices||[],this._numVertices=this._vertices.length/3,this._texCoords=e.texCoords||new Array(2*this._numVertices),e.center&&gi.centering(this._vertices),this._src=e.src||null,this.color=(t=e.color)instanceof Array?new Float32Array(t):"string"==typeof t?ye(t):new Float32Array([1,1,1,1]),e.scale&&gi.scale(this._vertices,e.scale),e.indices)this._indices=e.indices,this._normals=e.normals||[];else{this._normals=gi.getNormals(this._vertices),this._indices=new Array(this._vertices.length/3);for(let e=0,t=this._indices.length;e<t;e++)this._indices[e]=e}}static centering(e){let t=s,i=s,n=s,r=a,o=a,l=a;for(let s=0,a=e.length;s<a;s+=3){let a=e[s],h=e[s+1],c=e[s+2];a<t&&(t=a),h<i&&(i=h),c<n&&(n=c),a>r&&(r=a),h>o&&(o=h),c>l&&(l=c)}let h=t+.5*(r-t),c=i+.5*(o-i),d=n+.5*(l-n);for(let t=0,i=e.length;t<i;t+=3)e[t]-=h,e[t+1]-=c,e[t+2]-=d}get src(){return this._src}set src(e){this._src=e}get name(){return this._name}get vertices(){return this._vertices}get normals(){return this._normals}get indices(){return this._indices}get texCoords(){return this._texCoords}get numVertices(){return this._numVertices}static scale(e,t){for(let i=0;i<e.length;i++)e[i]*=t}static centroid(e){let t=1e3,i=1e3,n=1e3,r=-1e3,s=-1e3,a=-1e3;for(let o=0;o<e.length;o+=3){let l=e[o],h=e[o+1],c=e[o+2];l<t&&(t=l),h<i&&(i=h),c<n&&(n=c),l>r&&(r=l),h>s&&(s=h),c>a&&(a=c)}return[t+.5*(r-t),i+.5*(s-i),n+.5*(a-n)]}static translate(e,t){for(let i=0;i<e.length;i+=3)e[i]-=t[0],e[i+1]-=t[1],e[i+2]-=t[2]}static getNormals(e){let t=new Array(e.length);for(let i=0;i<e.length;i+=9){let n=i,r=i+3,s=i+6,a=e[n],o=e[n+1],l=e[n+2],h=e[r]-a,c=e[r+1]-o,d=e[r+2]-l,_=e[s]-a,u=e[s+1]-o,f=e[s+2]-l,g=c*f-d*u,p=d*_-h*f,m=h*u-c*_,v=Math.sqrt(g*g+p*p+m*m);g/=v,p/=v,m/=v,t[n]=g,t[n+1]=p,t[n+2]=m,t[r]=g,t[r+1]=p,t[r+2]=m,t[s]=g,t[s+1]=p,t[s+2]=m}return t}static createSphere(e=16,t=16,i=1,n=0,r=0,s=0){let a=[],o=[],l=[];for(let o=0;o<=t;o++){let h=o*Math.PI/t,c=Math.sin(h),d=Math.cos(h);for(let t=0;t<=e;t++){let o=2*t*Math.PI/e,h=Math.sin(o),_=Math.cos(o)*c+n,u=d+r,f=h*c+s;l.push(_),l.push(u),l.push(f),a.push(i*_),a.push(i*u),a.push(i*f)}}for(let i=0;i<t;i++)for(let t=0;t<e;t++){let n=i*(e+1)+t,r=n+e+1;o.push(n),o.push(n+1),o.push(r),o.push(r),o.push(n+1),o.push(r+1)}return new gi({vertices:a,normals:l,indices:o})}static createDisc(e=1,t=0,i=8,n=!0,r=0,s=0,a=0,o=0){let l=[],h=[],c=[],d=2*Math.PI,_=n?1:-1,u=r;for(let e=1;e<=i;e++)l.push(s,t*_+a,o),c.push(0,_,0),r++;let f=r;for(let n=0;n<=i;n++){let h=n/i*d+0,u=Math.cos(h),f=Math.sin(h);l.push(e*f+s,t*_+a,e*u+o),c.push(0,_,0),r++}for(let e=0;e<i;e++){let t=u+e,i=f+e;n?h.push(i,i+1,t):h.push(i+1,i,t)}return new gi({vertices:l,normals:c,indices:h})}static getFrustumScaleByCameraAngles(e,t,i){return new oe(2*e*Math.tan(c*t),2*e*Math.tan(c*i),e)}static getFrustumScaleByCameraAspectRatio(e,t,i){let n=h*Math.atan(Math.tan(c*t)/i);return gi.getFrustumScaleByCameraAngles(e,t,n)}static createFrustum(e=1,t=1,i=1,n=0,r=0,s=0){return new gi({vertices:[0+n,0+r,0+s,-1*(t*=.5)+n,1*(i*=.5)+r,-1*e+s,1*t+n,1*i+r,-1*e+s,0+n,0+r,0+s,1*t+n,-1*i+r,-1*e+s,-1*t+n,-1*i+r,-1*e+s,0+n,0+r,0+s,1*t+n,1*i+r,-1*e+s,1*t+n,-1*i+r,-1*e+s,0+n,0+r,0+s,-1*t+n,-1*i+r,-1*e+s,-1*t+n,1*i+r,-1*e+s,0+n,0+r,0+s,1*t+n,1*i+r,-1*e+s,-1*t+n,1*i+r,-1*e+s,0+n,0+r,0+s,-1*t+n,-1*i+r,-1*e+s,1*t+n,-1*i+r,-1*e+s,0+n,0+r,0+s,1*t+n,-1*i+r,-1*e+s,1*t+n,1*i+r,-1*e+s,0+n,0+r,0+s,-1*t+n,1*i+r,-1*e+s,-1*t+n,-1*i+r,-1*e+s]})}static createCylinder(e=1,t=1,i=1,n=32,r=1,s=!0,a=!0,o=0,l=0,h=0){let c=[],d=[],_=[],u=2*Math.PI,f=0,g=[],p=new oe,m=(t-e)/i;for(let s=0;s<=r;s++){let a=[],d=s/r,v=d*(t-e)+e;for(let e=0;e<=n;e++){let t=e/n*u+0,r=Math.sin(t),s=Math.cos(t);c.push(v*r+o,-d*i+i+l,v*s+h),p.set(r,m,s).normalize(),_.push(p.x,p.y,p.z),a.push(f++)}g.push(a)}for(let e=0;e<n;e++)for(let t=0;t<r;t++){let i=g[t][e],n=g[t+1][e],r=g[t+1][e+1],s=g[t][e+1];d.push(i,n,s),d.push(n,r,s)}if(0!==e&&s){let t=gi.createDisc(e,i,n,!0,f,o,l,h);c.push(...t.vertices),_.push(...t.normals),d.push(...t.indices)}if(0!==t&&a){let e=gi.createDisc(t,0,n,!1,f+(s?1+2*n:0),o,l,h);c.push(...e.vertices),_.push(...e.normals),d.push(...e.indices)}return new gi({vertices:c,normals:_,indices:d})}static createCube(e=1,t=1,i=1,n=0,r=0,s=0){let a=.5*e+n,o=.5*t+r,l=.5*i+s;return new gi({vertices:[-a,-o,l,a,-o,-l,a,-o,l,-a,-o,l,-a,-o,-l,a,-o,-l,-a,o,l,a,o,l,a,o,-l,-a,o,l,a,o,-l,-a,o,-l,-a,-o,l,a,-o,l,-a,o,l,-a,o,l,a,-o,l,a,o,l,-a,-o,-l,-a,o,-l,a,-o,-l,-a,o,-l,a,o,-l,a,-o,-l,a,-o,l,a,-o,-l,a,o,l,a,o,l,a,-o,-l,a,o,-l,-a,-o,l,-a,o,l,-a,-o,-l,-a,o,l,-a,o,-l,-a,-o,-l]})}static createArrow(e=0,t=2.1,i=-15){return new gi({vertices:[0,t,0,7,0,6,0,0,i,0,0,e,7,0,6,0,t,0,-7,0,6,0,0,e,0,t,0,-7,0,6,0,t,0,0,0,i,-7,0,6,0,0,i,0,0,e,0,0,e,0,0,i,7,0,6]})}static async loadObj(e){return(await fetch(e,{mode:"cors"}).then((e=>e.text())).then((e=>fi(ui(e)))).catch((()=>[]))).geometries.map((({data:{vertices:e,normals:t,textures:i}})=>new gi({vertices:e,normals:t,texCoords:i})))}}class pi{constructor(e){this._handlerIndex=-1,this._tag=e.tag||"none",this.instanced=!0,this._entity=null,this._position=Ae(e.position),this._positionHigh=new oe,this._positionLow=new oe,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._pitch=e.pitch||0,this._yaw=e.yaw||0,this._roll=e.roll||0,this._scale=Ae(e.scale,new oe(1,1,1)),this._color=Ee(e.color),this._direction=new oe(0,1,0),this._handler=null,this._handlerIndex=-1,this._tagData=null,this._tagDataIndex=-1;let t=e.object3d;e.object3d&&0!==e.object3d?.vertices.length||(t=new gi),e.objSrc&&(this.setObjectSrc(e.objSrc),this._objectSrc=e.objSrc),this._object3d=t,e.textureSrc&&this.setTextureSrc(e.textureSrc),this._visibility=null==e.visibility||e.visibility,this._qNorthFrame=new ae}get tag(){return this._tag}getPosition(){return this._position}getPitch(){return this._pitch}getYaw(){return this._yaw}getRoll(){return this._roll}getDirection(){return this._direction}get object3d(){return this._object3d}get vertices(){return this._object3d.vertices}get normals(){return this._object3d.normals}get texCoords(){return this._object3d.texCoords}get indices(){return this._object3d.indices}setOpacity(e){this._color.w=e,this.setColor(this._color.x,this._color.y,this._color.z,e)}setColor(e,t,i,n){this._color.x=e,this._color.y=t,this._color.z=i,null!=n&&(this._color.w=n),this._handler&&this._handler.setRgbaArr(this._tagData,this._tagDataIndex,this._color)}setColor4v(e){this._color.x=e.x,this._color.y=e.y,this._color.z=e.z,null!=e.w&&(this._color.w=e.w),this._handler&&this._handler.setRgbaArr(this._tagData,this._tagDataIndex,this._color)}setVisibility(e){this._visibility=e,this._handler&&this._handler.setVisibility(this._tagData,this._tagDataIndex,e)}getVisibility(){return this._visibility}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._handler&&this._handler.setPositionArr(this._tagData,this._tagDataIndex,this._positionHigh,this._positionLow),this.updateDirection()}setPosition3v(e){this._position.x=e.x,this._position.y=e.y,this._position.z=e.z,oe.doubleToTwoFloats(e,this._positionHigh,this._positionLow),this._handler&&this._handler.setPositionArr(this._tagData,this._tagDataIndex,this._positionHigh,this._positionLow),this.updateDirection()}setYaw(e){this._yaw=e,this.updateDirection()}setObject(e){this._object3d=e}setObjectSrc(e){this._objectSrc=e,this._handler&&this._handler.setObjectSrc(e,this.tag)}setTextureSrc(e){this._textureSrc=e,this._object3d&&(this._object3d.src=e),this._handler&&this._handler.setTextureTag(e,this.tag)}setColorHTML(e){this.setColor4v(ve(e))}setPitch(e){this._pitch=e,this._handler&&this._handler.setPitchRollArr(this._tagData,this._tagDataIndex,e,this._roll)}setRoll(e){this._roll=e,this._handler&&this._handler.setPitchRollArr(this._tagData,this._tagDataIndex,this._pitch,e)}setPitchYawRoll(e,t,i){this.setPitch(e),this.setYaw(t),this.setRoll(i)}setScale(e){this._scale.x=this._scale.y=this._scale.z=e,this._handler&&this._handler.setScaleArr(this._tagData,this._tagDataIndex,this._scale)}setScale3v(e){this._scale.copy(e),this._handler&&this._handler.setScaleArr(this._tagData,this._tagDataIndex,e)}getScale(){return this._scale}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._handler&&this._handler.setPickingColorArr(this._tagData,this._tagDataIndex,e)}updateDirection(){if(this._handler&&this._handler._planet){this._qNorthFrame=this._handler._planet.getNorthFrameRotation(this._position);let e=ae.yRotation(this._yaw).mul(this._qNorthFrame).conjugate();this._direction=e.mulVec3(new oe(0,0,-1)).normalize(),this._handler.setDirectionArr(this._tagData,this._tagDataIndex,this._direction)}}}const mi={RIGHT:0,LEFT:1,CENTER:2},vi={left:mi.LEFT,right:mi.RIGHT,center:mi.CENTER};class yi extends ri{constructor(e={}){super(e),this._handler=null,this._text=e.text||"",this._face=Le(e.face,"arial"),this._size=e.size||24,this._outline=null!=e.outline?e.outline:0,this._outlineColor=Ee(e.outlineColor,new re(0,0,0,1)),this._align=e.align&&vi[e.align.trim().toLowerCase()]||mi.RIGHT,this._fontIndex=0,this._fontAtlas=null,this._isRTL=e.isRTL||!1}setText(e){this._text=e.toString(),this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,e,this._fontIndex,this._align,this._isRTL)}setRtl(e){this._isRTL=e,this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._isRTL)}getText(){return this._text}setAlign(e){this._align=vi[e.trim().toLowerCase()],this._isReady&&this._handler?this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._isRTL):this._lockId!==ti&&(this._lockId=ei)}getAlign(){return this._align}setFace(e){this._face=e.trim(),this.update()}getFace(){return this._face}setSize(e){e!==this._size&&(this._size=e,this._isReady&&this._handler?this._handler.setSizeArr(this._handlerIndex,e):this._lockId!==ti&&(this._lockId=ei))}getSize(){return this._size}setOutline(e){this._outline=e,this._isReady&&this._handler?this._handler.setOutlineArr(this._handlerIndex,e):this._lockId!==ti&&(this._lockId=ei)}getOutline(){return this._outline}setOpacity(e){super.setOpacity(e),this.setOutlineOpacity(e)}setOutlineColor(e,t,i,n){n===this._outlineColor.w&&e===this._outlineColor.x&&t===this._outlineColor.y&&i===this._outlineColor.z||(this._outlineColor.x=e,this._outlineColor.y=t,this._outlineColor.z=i,this._outlineColor.w=n,this._isReady&&this._handler?this._handler.setOutlineColorArr(this._handlerIndex,this._outlineColor):this._lockId!==ti&&(this._lockId=ei))}setOutlineColor4v(e){this.setOutlineColor(e.x,e.y,e.z,e.w)}setOutlineColorHTML(e){this.setOutlineColor4v(ve(e))}getOutlineColor(){return this._outlineColor}setOutlineOpacity(e){e!==this._outlineColor.w&&(this._outlineColor.w=e,this._isReady&&this._handler?this._handler.setOutlineColorArr(this._handlerIndex,this._outlineColor):this._lockId!==ti&&(this._lockId=ei))}getOutlineOpacity(){return this._outlineColor.w}async update(){if(this._fontAtlas){const e=await this._fontAtlas.getFontIndex(this._face);this._applyFontIndex(e)}}_applyFontIndex(e){this._fontIndex=e,this._isReady&&this._handler?(this._handler.setFontIndexArr(this._handlerIndex,this._fontIndex),this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._isRTL)):this._lockId!==ti&&(this._lockId=ei)}assignFontAtlas(e){this._fontAtlas||(this._fontAtlas=e),this.update()}serializeWorkerData(e){return this._handler?new Float32Array([e,this._handler._maxLetters,this.getVisibility()?1:0,this._positionHigh.x,this._positionHigh.y,this._positionHigh.z,this._positionLow.x,this._positionLow.y,this._positionLow.z,this._size,this._offset.x,this._offset.y,this._offset.z,this._color.x,this._color.y,this._color.z,this._color.w,this._rotation,this._alignedAxis.x,this._alignedAxis.y,this._alignedAxis.z,this._fontIndex,this._outline,this._outlineColor.x,this._outlineColor.y,this._outlineColor.z,this._outlineColor.w,this._entity._pickingColor.x,this._entity._pickingColor.y,this._entity._pickingColor.z]):null}}class xi{constructor(e={}){this.__id=xi.__counter__++,this.visibility=null==e.visibility||e.visibility,this.pointSize=e.pointSize||3,this.pickingScale=e.pickingScale||0,this._renderNode=null,this._entity=null,this._points=[],this._coordinatesData=[],this._colorData=[],this._pickingColorData=[],this._coordinatesBuffer=null,this._colorBuffer=null,this._pickingColorBuffer=null,this._handler=null,this._handlerIndex=-1,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this._createCoordinatesBuffer,this._buffersUpdateCallbacks[1]=this._createColorBuffer,this._buffersUpdateCallbacks[2]=this._createPickingColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length),e.points&&this.setPoints(e.points)}clear(){this._points.length=0,this._points=[],this._coordinatesData.length=0,this._coordinatesData=[],this._colorData.length=0,this._colorData=[],this._pickingColorData.length=0,this._pickingColorData=[],this._deleteBuffers()}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){this._renderNode=e,this._setPickingColors()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPoints(e){this.clear();for(let t=0;t<e.length;t++){let i=e[t],n=new oe(i[0],i[1],i[2]),r=new re(i[3],i[4],i[5],null==i[6]?255:i[6]);this._coordinatesData.push(n.x,n.y,n.z),this._colorData.push(r.x/255,r.y/255,r.z/255,r.w/255);let s={_entity:this._entity,_pickingColor:new oe,_entityCollection:this._entity?this._entity._entityCollection:null,index:t,position:n,color:r,pointCloud:this,properties:i[7]||{}};this._points.push(s),this._renderNode&&this._renderNode.renderer&&(this._renderNode.renderer.assignPickingColor(s),this._pickingColorData.push(s._pickingColor.x/255,s._pickingColor.y/255,s._pickingColor.z/255,1))}this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}setPointPosition(e,t,i,n){this._changedBuffers[0]=!0}setPointColor(e,t,i,n,r){this._changedBuffers[1]=!0}addPoints(e){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}addPoint(e,t){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}getPoint(e){return this._points[e]}removePoint(e){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}insertPoint(e,t){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}draw(){if(this.visibility&&this._coordinatesData.length){this._update();let e=this._renderNode.renderer,t=e.handler.programs.pointCloud,i=t._program,n=e.handler.gl,r=i.attributes,s=i.uniforms;t.activate(),n.uniformMatrix4fv(s.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),n.uniform1f(s.opacity,this._handler._entityCollection._fadingOpacity),n.uniform1f(s.pointSize,this.pointSize),n.bindBuffer(n.ARRAY_BUFFER,this._coordinatesBuffer),n.vertexAttribPointer(r.coordinates,this._coordinatesBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._colorBuffer),n.vertexAttribPointer(r.colors,this._colorBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.POINTS,0,this._coordinatesBuffer.numItems)}}drawPicking(){if(this.visibility&&this._coordinatesData.length){let e=this._renderNode.renderer,t=e.handler.programs.pointCloud,i=t._program,n=e.handler.gl,r=i.attributes,s=i.uniforms;t.activate(),n.uniformMatrix4fv(s.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),n.uniform1f(s.opacity,this._handler._entityCollection._fadingOpacity),n.uniform1f(s.pointSize,this.pointSize+this.pickingScale),n.bindBuffer(n.ARRAY_BUFFER,this._coordinatesBuffer),n.vertexAttribPointer(r.coordinates,this._coordinatesBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._pickingColorBuffer),n.vertexAttribPointer(r.colors,this._pickingColorBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.POINTS,0,this._coordinatesBuffer.numItems)}}_update(){if(this._renderNode){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}_deleteBuffers(){if(this._renderNode){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._coordinatesBuffer),e.deleteBuffer(this._colorBuffer),e.deleteBuffer(this._pickingColorBuffer)}this._coordinatesBuffer=null,this._colorBuffer=null,this._pickingColorBuffer=null}_createCoordinatesBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._coordinatesBuffer),this._coordinatesBuffer=e.createArrayBuffer(new Float32Array(this._coordinatesData),3,this._coordinatesData.length/3)}_createColorBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._colorBuffer),this._colorBuffer=e.createArrayBuffer(new Float32Array(this._colorData),4,this._colorData.length/4)}_createPickingColorBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorBuffer=e.createArrayBuffer(new Float32Array(this._pickingColorData),4,this._pickingColorData.length/4)}_setPickingColors(){if(this._renderNode&&this._renderNode.renderer){for(let e=0;e<this._points.length;e++){let t=this._points[e];t._entity=this._entity,t._entityCollection=this._entity._entityCollection,this._renderNode.renderer.assignPickingColor(t),this._pickingColorData.push(t._pickingColor.x/255,t._pickingColor.y/255,t._pickingColor.z/255,1)}this._changedBuffers[2]=!0}}}xi.__counter__=0;class bi{constructor(e={}){this.__id=bi.__counter__++,this.altitude=e.altitude||0,this.thickness=e.thickness||1.5,this._opacity=null!=e.opacity?e.opacity:1,this._defaultColor=ye(e.color||"#0000FF",e.opacity),this.visibility=null==e.visibility||e.visibility,this._closedLine=e.isClosed||!1,this._path3v=[],this._pathLengths=[],this._pathLonLat=[],this._pathLonLatMerc=[],this._pathColors=e.pathColors?qe(e.pathColors):[],this._extent=new ie,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null,this._pickingColor=[0,0,0],this._renderNode=null,this._entity=null,this._handler=null,this._handlerIndex=-1,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this._createVerticesBuffer,this._buffersUpdateCallbacks[1]=this._createIndexBuffer,this._buffersUpdateCallbacks[2]=this._createColorsBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length),e.pathLonLat?this.setPathLonLat(e.pathLonLat):e.path3v&&this.setPath3v(e.path3v),this._refresh()}static appendLineData3v(e,t,i,n,r,s,a,o,l,h,c,d,_,u){var f=0,g=new oe,p=new oe;_&&(_.southWest.set(180,90),_.northEast.set(-180,-90)),o.length>0?(f=o[o.length-5]+9,o.push(f,f)):o.push(0,0);for(let A=0,E=e.length;A<E;A++){var m=e[A],v=t[A];if(h[A]=[],d[A]=[],c[A]=[],0===m.length)continue;var y,x=f;if(n)(y=m[m.length-1])instanceof Array&&(y=new oe(y[0],y[1],y[2]));else{var b=m[0],w=m[1]||b;b instanceof Array&&(b=new oe(b[0],b[1],b[2])),w instanceof Array&&(w=new oe(w[0],w[1],w[2])),y=new oe(b.x+b.x-w.x,b.y+b.y-w.y,b.z+b.z-w.z)}let E=i;v&&v[0]&&(E=v[0]),oe.doubleToTwoFloats(y,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z);let P=E[0],M=E[1],S=E[2],B=null!=E[3]?E[3]:1;A>0&&u.push(P,M,S,B,P,M,S,B,P,M,S,B,P,M,S,B),a.push(1,-1,2,-2);for(let e=0,t=m.length;e<t;e++){var T=m[e];if(T instanceof Array&&(T=new oe(T[0],T[1],T[2])),c[A].push(T),l){var C=l.cartesianToLonLat(T);h[A].push(C),d[A].push(C.forwardMercator()),C.lon<_.southWest.lon&&(_.southWest.lon=C.lon),C.lat<_.southWest.lat&&(_.southWest.lat=C.lat),C.lon>_.northEast.lon&&(_.northEast.lon=C.lon),C.lat>_.northEast.lat&&(_.northEast.lat=C.lat)}v&&v[e]&&(E=v[e]),P=E[0],M=E[1],S=E[2],B=null!=E[3]?E[3]:1,oe.doubleToTwoFloats(T,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(P,M,S,B,P,M,S,B,P,M,S,B,P,M,S,B),a.push(1,-1,2,-2),o.push(f++,f++,f++,f++)}var L;if(n)(L=m[0])instanceof Array&&(L=new oe(L[0],L[1],L[2])),o.push(x,x+1,x+1,x+1);else{let e=m[m.length-1],t=m[m.length-2]||e;e instanceof Array&&(e=new oe(e[0],e[1],e[2])),t instanceof Array&&(t=new oe(t[0],t[1],t[2])),L=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),o.push(f-1,f-1,f-1,f-1)}v&&v[m.length-1]&&(E=v[m.length-1]),P=E[0],M=E[1],S=E[2],B=null!=E[3]?E[3]:1,oe.doubleToTwoFloats(L,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(P,M,S,B,P,M,S,B,P,M,S,B,P,M,S,B),a.push(1,-1,2,-2),A<e.length-1&&0!==e[A+1].length&&(f+=8,o.push(f,f))}}static appendPoint3v(e,t,i,n,r,s,a,o,l,h,c,d,_,u){var f=new oe,g=new oe,p=h.length-4,m=h[p-1]+1;0===e.length?(e.push([]),i[0]||(i[0]=[])):i[e.length-1]||(i[e.length-1]=[]);var v=e[e.length-1],y=v.length;v.push(t);let x=n[0],b=n[1],w=n[2],T=null!=n[3]?n[3]:1,C=i[e.length-1];if(C[y]?(C[y][0]=x,C[y][1]=b,C[y][2]=w,C[y][3]=T):C.push(n),1===y){var L;if(r)(L=v[y-1])instanceof Array&&(L=new oe(L[0],L[1],L[2]));else{let e=v[0],t=v[1]||e;e instanceof Array&&(e=new oe(e[0],e[1],e[2])),t instanceof Array&&(t=new oe(t[0],t[1],t[2])),L=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}oe.doubleToTwoFloats(L,f,g);let e=s.length-36;s[e]=f.x,s[e+1]=f.y,s[e+2]=f.z,s[e+3]=f.x,s[e+4]=f.y,s[e+5]=f.z,s[e+6]=f.x,s[e+7]=f.y,s[e+8]=f.z,s[e+9]=f.x,s[e+10]=f.y,s[e+11]=f.z,a[e]=g.x,a[e+1]=g.y,a[e+2]=g.z,a[e+3]=g.x,a[e+4]=g.y,a[e+5]=g.z,a[e+6]=g.x,a[e+7]=g.y,a[e+8]=g.z,a[e+9]=g.x,a[e+10]=g.y,a[e+11]=g.z}var A=m;if(c){0===d.length&&d.push([]),0===_.length&&_.push([]);var E=d[d.length-1],P=_[_.length-1];let e=c.cartesianToLonLat(t);E.push(e),P.push(e.forwardMercator()),e.lon<u.southWest.lon&&(u.southWest.lon=e.lon),e.lat<u.southWest.lat&&(u.southWest.lat=e.lat),e.lon>u.northEast.lon&&(u.northEast.lon=e.lon),e.lat>u.northEast.lat&&(u.northEast.lat=e.lat)}oe.doubleToTwoFloats(t,f,g);let M=s.length-12;s[M]=f.x,s[M+1]=f.y,s[M+2]=f.z,s[M+3]=f.x,s[M+4]=f.y,s[M+5]=f.z,s[M+6]=f.x,s[M+7]=f.y,s[M+8]=f.z,s[M+9]=f.x,s[M+10]=f.y,s[M+11]=f.z,a[M]=g.x,a[M+1]=g.y,a[M+2]=g.z,a[M+3]=g.x,a[M+4]=g.y,a[M+5]=g.z,a[M+6]=g.x,a[M+7]=g.y,a[M+8]=g.z,a[M+9]=g.x,a[M+10]=g.y,a[M+11]=g.z;let S=o.length-16;var B;if(o[S]=x,o[S+1]=b,o[S+2]=w,o[S+3]=T,o[S+4]=x,o[S+5]=b,o[S+6]=w,o[S+7]=T,o[S+8]=x,o[S+9]=b,o[S+10]=w,o[S+11]=T,o[S+12]=x,o[S+13]=b,o[S+14]=w,o[S+15]=T,h[p]=m++,h[p+1]=m++,h[p+2]=m++,h[p+3]=m++,r)B=v[0],h.push(A,A+1,A+1,A+1);else{let e=v[v.length-1],t=v[v.length-2]||e;B=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),h.push(m-1,m-1,m-1,m-1)}oe.doubleToTwoFloats(B,f,g),s.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),a.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),o.push(x,b,w,T,x,b,w,T,x,b,w,T,x,b,w,T),l.push(1,-1,2,-2)}static setPathColors(e,t,i,n){for(let o=0,l=e.length;o<l;o++){var r=e[o],s=t[o];if(0===r.length)continue;let l=i;s&&s[0]&&(l=s[0]);let h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1;o>0&&n.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_);for(let e=0,t=r.length;e<t;e++){var a=r[e];a instanceof Array&&(a=new z(a[0],a[1],a[2])),s&&s[e]&&(l=s[e]),h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1,n.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_)}s&&s[r.length-1]&&(l=s[r.length-1]),h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1,n.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_)}}static appendLineDataLonLat(e,t,i,n,r,s,a,o,l,h,c,d,_,u){var f=0,g=new oe,p=new oe;_&&(_.southWest.set(180,90),_.northEast.set(-180,-90)),o.length>0?(f=o[o.length-5]+9,o.push(f)):o.push(0);for(let C=0,L=e.length;C<L;C++){var m=e[C],v=t[C];if(h[C]=[],d[C]=[],c[C]=[],0===m.length)continue;var y,x=f;if(n){let e=m[m.length-1];y=e instanceof Array?l.lonLatToCartesian(new z(e[0],e[1],e[2])):l.lonLatToCartesian(e)}else{let e,t,i=m[0];e=i instanceof Array?l.lonLatToCartesian(new z(i[0],i[1],i[2])):l.lonLatToCartesian(i),i=m[1],i||(i=m[0]),t=i instanceof Array?l.lonLatToCartesian(new z(i[0],i[1],i[2])):l.lonLatToCartesian(i),y=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}let L=i;v&&v[0]&&(L=v[0]),oe.doubleToTwoFloats(y,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z);let A=L[0],E=L[1],P=L[2],M=null!=L[3]?L[3]:1;C>0&&u.push(A,E,P,M,A,E,P,M,A,E,P,M,A,E,P,M),a.push(1,-1,2,-2);for(let e=0,t=m.length;e<t;e++){var b=m[e];b instanceof Array&&(b=new z(b[0],b[1],b[2])),v&&v[e]&&(L=v[e]),A=L[0],E=L[1],P=L[2],M=null!=L[3]?L[3]:1;var w=l.lonLatToCartesian(b);h[C].push(w),c[C].push(b),d[C].push(b.forwardMercator()),oe.doubleToTwoFloats(w,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(A,E,P,M,A,E,P,M,A,E,P,M,A,E,P,M),a.push(1,-1,2,-2),o.push(f++,f++,f++,f++),b.lon<_.southWest.lon&&(_.southWest.lon=b.lon),b.lat<_.southWest.lat&&(_.southWest.lat=b.lat),b.lon>_.northEast.lon&&(_.northEast.lon=b.lon),b.lat>_.northEast.lat&&(_.northEast.lat=b.lat)}var T;if(n){let e=m[0];T=e instanceof Array?l.lonLatToCartesian(new z(e[0],e[1],e[2])):l.lonLatToCartesian(e),o.push(x,x+1,x+1,x+1)}else{let e,t,i=m[m.length-1];e=i instanceof Array?l.lonLatToCartesian(new z(i[0],i[1],i[2])):l.lonLatToCartesian(i),i=m[m.length-2],i||(i=m[0]),t=i instanceof Array?l.lonLatToCartesian(new z(i[0],i[1],i[2])):l.lonLatToCartesian(i),T=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),o.push(f-1,f-1,f-1,f-1)}v&&v[m.length-1]&&(L=v[m.length-1]),A=L[0],E=L[1],P=L[2],M=null!=L[3]?L[3]:1,oe.doubleToTwoFloats(T,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(A,E,P,M,A,E,P,M,A,E,P,M,A,E,P,M),a.push(1,-1,2,-2),C<e.length-1&&0!==e[C+1].length&&(f+=8,o.push(f,f))}}_setEqualPath3v(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new oe,n=new oe,r=this._verticesHigh,s=this._verticesLow,a=this._pathLonLat,o=this._pathLonLatMerc,l=0,h=this._renderNode.ellipsoid;for(let m=0;m<e.length;m++){var c,d,_=e[m];c=this._closedLine?_[_.length-1]:new oe(_[0].x+_[0].x-_[1].x,_[0].y+_[0].y-_[1].y,_[0].z+_[0].z-_[1].z),oe.doubleToTwoFloats(c,i,n),r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z;for(let e=0;e<_.length;e++){var u=_[e],f=this._path3v[m][e];if(f.x=u.x,f.y=u.y,f.z=u.z,h){var g=h.cartesianToLonLat(u);this._pathLonLat[m][e]=g,a[m][e]=g,o[m][e]=g.forwardMercator(),g.lon<t.southWest.lon&&(t.southWest.lon=g.lon),g.lat<t.southWest.lat&&(t.southWest.lat=g.lat),g.lon>t.northEast.lon&&(t.northEast.lon=g.lon),g.lat>t.northEast.lat&&(t.northEast.lat=g.lat)}oe.doubleToTwoFloats(u,i,n),r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z}if(this._closedLine)d=_[0];else{var p=_.length-1;d=new oe(_[p].x+_[p].x-_[p-1].x,_[p].y+_[p].y-_[p-1].y,_[p].z+_[p].z-_[p-1].z)}oe.doubleToTwoFloats(d,i,n),r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z}}_setEqualPathLonLat(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new oe,n=new oe,r=this._verticesHigh,s=this._verticesLow,a=this._pathLonLat,o=this._pathLonLatMerc,l=this._path3v,h=0,c=this._renderNode.ellipsoid;for(let p=0;p<e.length;p++){var d,_,u=e[p];if(this._closedLine)d=c.lonLatToCartesian(u[u.length-1]);else{let e=c.lonLatToCartesian(u[0]),t=c.lonLatToCartesian(u[1]);d=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}oe.doubleToTwoFloats(d,i,n),r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z;for(let e=0;e<u.length;e++){var f=u[e],g=c.lonLatToCartesian(f);l[p][e]=g,o[p][e]=f.forwardMercator(),a[p][e]=f,oe.doubleToTwoFloats(g,i,n),r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,f.lon<t.southWest.lon&&(t.southWest.lon=f.lon),f.lat<t.southWest.lat&&(t.southWest.lat=f.lat),f.lon>t.northEast.lon&&(t.northEast.lon=f.lon),f.lat>t.northEast.lat&&(t.northEast.lat=f.lat)}if(this._closedLine)_=c.lonLatToCartesian(u[0]);else{let e=c.lonLatToCartesian(u[u.length-1]),t=c.lonLatToCartesian(u[u.length-2]);_=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}oe.doubleToTwoFloats(_,i,n),r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z}}setPointLonLat(e,t,i){if(this._renderNode&&this._renderNode.ellipsoid){let o=this._pathLonLat,l=this._pathLonLatMerc;o[i][t]=e,l[i][t]=e.forwardMercator();var n=this._extent;n.southWest.set(180,90),n.northEast.set(-180,-90);for(let e=0;e<o.length;e++){var r=o[e];for(let e=0;e<r.length;e++){var s=r[e].lon,a=r[e].lat;s>n.northEast.lon&&(n.northEast.lon=s),a>n.northEast.lat&&(n.northEast.lat=a),s<n.southWest.lon&&(n.southWest.lon=s),a<n.southWest.lat&&(n.southWest.lat=a)}}this.setPoint3v(this._renderNode.ellipsoid.lonLatToCartesian(e),t,i,!0)}else{let n=this._pathLonLat[i];n[t].lon=e.lon,n[t].lat=e.lat,n[t].height=e.height}}setPoint3v(e,t=0,i=0,n=!1){if(this._renderNode){var r,s=new oe,a=new oe,o=this._verticesHigh,l=this._verticesLow,h=this._pathLonLat,c=this._pathLonLatMerc,d=0;r=12*this._pathLengths[i]+24*i;let x=this._path3v[i];x[t].x=e.x,x[t].y=e.y,x[t].z=e.z;let b=this._closedLine||1===x.length;var _;if(0===t||1===t)_=b?x[x.length-1]:new oe(x[0].x+x[0].x-x[1].x,x[0].y+x[0].y-x[1].y,x[0].z+x[0].z-x[1].z),d=r,oe.doubleToTwoFloats(_,s,a),o[d]=s.x,o[d+1]=s.y,o[d+2]=s.z,o[d+3]=s.x,o[d+4]=s.y,o[d+5]=s.z,o[d+6]=s.x,o[d+7]=s.y,o[d+8]=s.z,o[d+9]=s.x,o[d+10]=s.y,o[d+11]=s.z,l[d]=a.x,l[d+1]=a.y,l[d+2]=a.z,l[d+3]=a.x,l[d+4]=a.y,l[d+5]=a.z,l[d+6]=a.x,l[d+7]=a.y,l[d+8]=a.z,l[d+9]=a.x,l[d+10]=a.y,l[d+11]=a.z;if(!n&&this._renderNode.ellipsoid){var u=this._renderNode.ellipsoid.cartesianToLonLat(e);h[i][t]=u,c[i][t]=u.forwardMercator();var f=this._extent;f.southWest.set(180,90),f.northEast.set(-180,-90);for(let e=0;e<h.length;e++){var g=h[e];for(let e=0;e<g.length;e++){var p=g[e].lon,m=g[e].lat;p>f.northEast.lon&&(f.northEast.lon=p),m>f.northEast.lat&&(f.northEast.lat=m),p<f.southWest.lon&&(f.southWest.lon=p),m<f.southWest.lat&&(f.southWest.lat=m)}}}if(d=r+12*t+12,oe.doubleToTwoFloats(e,s,a),o[d]=s.x,o[d+1]=s.y,o[d+2]=s.z,o[d+3]=s.x,o[d+4]=s.y,o[d+5]=s.z,o[d+6]=s.x,o[d+7]=s.y,o[d+8]=s.z,o[d+9]=s.x,o[d+10]=s.y,o[d+11]=s.z,l[d]=a.x,l[d+1]=a.y,l[d+2]=a.z,l[d+3]=a.x,l[d+4]=a.y,l[d+5]=a.z,l[d+6]=a.x,l[d+7]=a.y,l[d+8]=a.z,l[d+9]=a.x,l[d+10]=a.y,l[d+11]=a.z,t===x.length-1||t===x.length-2){var v;if(b)v=x[0];else{var y=x.length-1;v=new oe(x[y].x+x[y].x-x[y-1].x,x[y].y+x[y].y-x[y-1].y,x[y].z+x[y].z-x[y-1].z)}d=r+12*x.length+12,oe.doubleToTwoFloats(v,s,a),o[d]=s.x,o[d+1]=s.y,o[d+2]=s.z,o[d+3]=s.x,o[d+4]=s.y,o[d+5]=s.z,o[d+6]=s.x,o[d+7]=s.y,o[d+8]=s.z,o[d+9]=s.x,o[d+10]=s.y,o[d+11]=s.z,l[d]=a.x,l[d+1]=a.y,l[d+2]=a.z,l[d+3]=a.x,l[d+4]=a.y,l[d+5]=a.z,l[d+6]=a.x,l[d+7]=a.y,l[d+8]=a.z,l[d+9]=a.x,l[d+10]=a.y,l[d+11]=a.z}this._changedBuffers[0]=!0}else{let n=this._path3v[i];n[t].x=e.x,n[t].y=e.y,n[t].z=e.z}}_resizePathLengths(e=0){this._pathLengths[0]=0;for(let t=e+1,i=this._path3v.length;t<=i;t++)this._pathLengths[t]=this._pathLengths[t-1]+this._path3v[t-1].length}removeSegment(e){this._path3v.splice(e,1),this.setPath3v([].concat(this._path3v))}removePoint(e,t=0){this._path3v[t].splice(e,1),0===this._path3v[t].length&&this._path3v.splice(t,1),this.setPath3v([].concat(this._path3v))}insertPoint3v(e,t=0,i,n=0){let r=[].concat(this._path3v),s=r[n];if(s){let a=[].concat(this._pathColors);if(s.splice(t,0,e),i){let e=a[n];e||(e=new Array(s.length)),e.splice(t,0,i)}this.setPath3v(r,a)}else this.addPoint3v(e,n)}appendPoint3v(e,t,i){0!==this._path3v.length&&this._renderNode?(this._verticesHigh=Ve(this._verticesHigh),this._verticesLow=Ve(this._verticesLow),this._colors=Ve(this._colors),this._orders=Ve(this._orders),this._indexes=Ve(this._indexes),bi.appendPoint3v(this._path3v,e,this._pathColors,t||this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._colors,this._orders,this._indexes,i?null:this._renderNode.ellipsoid,this._pathLonLat,this._pathLonLatMerc,this._extent),this._pathLengths[this._path3v.length]+=1,this._changedBuffers[0]=!0,this._changedBuffers[2]=!0,this._changedBuffers[1]=!0):(this._pathColors.push([t||this._defaultColor]),this.addPoint3v(e))}addPoint3v(e,t=0){t>=this._path3v.length&&this._path3v.push([]),this._path3v[t].push(e),this.setPath3v([].concat(this._path3v))}addPointLonLat(e,t=0){t>=this._pathLonLat.length&&this._pathLonLat.push([]),this._pathLonLat[t].push(e),this.setPathLonLat([].concat(this._pathLonLat))}clear(){this._clearData()}setPointColor(e,t=0,i=0){if(this._renderNode&&t<this._path3v[i].length){let n=this._pathColors[i];if(!n){if(!(this._path3v[i]&&t<this._path3v[i].length))return;this._pathColors[i]=new Array(this._path3v[i].length)}n[t]?(n[t][0]=e[0],n[t][1]=e[1],n[t][2]=e[2],n[t][3]=e[3]||1):n[t]=[e[0],e[1],e[2],e[3]||1];let r=this._colors,s=16*t+16*this._pathLengths[i]+32*i;r[s]=r[s+4]=r[s+8]=r[s+12]=e[0],r[s+1]=r[s+5]=r[s+9]=r[s+13]=e[1],r[s+2]=r[s+6]=r[s+10]=r[s+14]=e[2],r[s+3]=r[s+7]=r[s+11]=r[s+15]=e[3]||1,this._changedBuffers[2]=!0}else{this._pathColors[i][t]=e}}setOpacity(e){this._opacity=e}setAltitude(e){this.altitude=e}setThickness(e){this.thickness=e}getThickness(){return this.thickness}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){e&&(this._renderNode=e,this._pathLonLat.length?this._createDataLonLat([].concat(this._pathLonLat)):this._createData3v([].concat(this._path3v)),this._refresh(),e.renderer&&e.renderer.isInitialized()&&this._update())}_clearData(){this._verticesHigh=null,this._verticesLow=null,this._orders=null,this._indexes=null,this._colors=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._path3v.length=0,this._pathLonLat.length=0,this._pathLonLatMerc.length=0,this._path3v=[],this._pathLonLat=[],this._pathLonLatMerc=[]}_createData3v(e){this._clearData(),bi.appendLineData3v(e,this._pathColors,this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._orders,this._indexes,this._renderNode.ellipsoid,this._pathLonLat,this._path3v,this._pathLonLatMerc,this._extent,this._colors),this._resizePathLengths(0)}_createDataLonLat(e){this._clearData(),bi.appendLineDataLonLat(e,this._pathColors,this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._orders,this._indexes,this._renderNode.ellipsoid,this._path3v,this._pathLonLat,this._pathLonLatMerc,this._extent,this._colors),this._resizePathLengths(0)}remove(){this._entity=null,this._pathColors.length=0,this._pathColors=[],this._verticesHigh=null,this._verticesLow=null,this._orders=null,this._indexes=null,this._colors=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._deleteBuffers(),this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._pickingColor[0]=e.x/255,this._pickingColor[1]=e.y/255,this._pickingColor[2]=e.z/255}getExtent(){return this._extent.clone()}getPath3v(){return this._path3v}getPathLonLat(){return this._pathLonLat}getPathColors(){return this._pathColors}setPathColors(e){e&&(this._colors=[],this._pathColors=[].concat(e),bi.setPathColors(this._pathLonLat,e,this._defaultColor,this._colors),this._changedBuffers[2]=!0)}setColorHTML(e){this._defaultColor=ye(e);let t=ve(e),i=this._pathColors;for(let e=0,n=i.length;e<n;e++){let n=i[e];for(let e=0,i=n.length;e<i;e++)n[e][0]=t.x,n[e][1]=t.y,n[e][2]=t.z,n[e][3]=t.w}let n=this._colors;for(let e=0,i=n.length;e<i;e+=4)n[e]=t.x,n[e+1]=t.y,n[e+2]=t.z,n[e+3]=t.w;this._changedBuffers[2]=!0}setPathLonLat(e,t=!1){this._renderNode&&this._renderNode.ellipsoid?t?(this._setEqualPathLonLat(e),this._changedBuffers[0]=!0,this._changedBuffers[2]=!0):(this._createDataLonLat(e),this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0):this._pathLonLat=[].concat(e)}setPath3v(e,t,i=!1){t&&(this._pathColors=[].concat(t)),this._renderNode?i?(this._setEqualPath3v(e),this._changedBuffers[0]=!0,this._changedBuffers[2]=!0):(this._createData3v(e),this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0):this._path3v=[].concat(e)}draw(){if(this.visibility&&this._path3v.length){this._update();let e=this._renderNode,t=e.renderer,i=t.handler.programs.polyline_screen,n=i._program,r=t.handler.gl,s=n.attributes,a=n.uniforms,o=this._handler._entityCollection;i.activate(),r.disable(r.CULL_FACE),r.uniform1f(a.depthOffset,o.polygonOffsetUnits),r.uniformMatrix4fv(a.proj,!1,t.activeCamera.getProjectionMatrix()),r.uniformMatrix4fv(a.view,!1,t.activeCamera.getViewMatrix()),r.uniform3fv(a.eyePositionHigh,t.activeCamera.eyeHigh),r.uniform3fv(a.eyePositionLow,t.activeCamera.eyeLow),r.uniform2fv(a.uFloatParams,[e._planetRadius2||0,t.activeCamera._tanViewAngle_hradOneByHeight]),r.uniform2fv(a.viewport,[t.handler.canvas.width,t.handler.canvas.height]),r.uniform1f(a.thickness,.5*this.thickness),r.uniform1f(a.opacity,this._opacity*o._fadingOpacity),r.bindBuffer(r.ARRAY_BUFFER,this._colorsBuffer),r.vertexAttribPointer(s.color,this._colorsBuffer.itemSize,r.FLOAT,!1,0,0);let l=this._verticesHighBuffer;r.bindBuffer(r.ARRAY_BUFFER,l),r.vertexAttribPointer(s.prevHigh,l.itemSize,r.FLOAT,!1,12,0),r.vertexAttribPointer(s.currentHigh,l.itemSize,r.FLOAT,!1,12,48),r.vertexAttribPointer(s.nextHigh,l.itemSize,r.FLOAT,!1,12,96),l=this._verticesLowBuffer,r.bindBuffer(r.ARRAY_BUFFER,l),r.vertexAttribPointer(s.prevLow,l.itemSize,r.FLOAT,!1,12,0),r.vertexAttribPointer(s.currentLow,l.itemSize,r.FLOAT,!1,12,48),r.vertexAttribPointer(s.nextLow,l.itemSize,r.FLOAT,!1,12,96),r.bindBuffer(r.ARRAY_BUFFER,this._ordersBuffer),r.vertexAttribPointer(s.order,this._ordersBuffer.itemSize,r.FLOAT,!1,4,0),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),r.drawElements(r.TRIANGLE_STRIP,this._indexesBuffer.numItems,r.UNSIGNED_INT,0),r.enable(r.CULL_FACE)}}drawPicking(){if(this.visibility&&this._path3v.length){let e=this._renderNode,t=e.renderer,i=t.handler.programs.polyline_picking,n=i._program,r=t.handler.gl,s=n.attributes,a=n.uniforms;i.activate(),r.disable(r.CULL_FACE),r.uniform1f(a.depthOffset,this._handler._entityCollection.polygonOffsetUnits),r.uniformMatrix4fv(a.proj,!1,t.activeCamera.getProjectionMatrix()),r.uniformMatrix4fv(a.view,!1,t.activeCamera.getViewMatrix()),r.uniform4fv(a.color,[this._pickingColor[0],this._pickingColor[1],this._pickingColor[2],1]),r.uniform3fv(a.eyePositionHigh,t.activeCamera.eyeHigh),r.uniform3fv(a.eyePositionLow,t.activeCamera.eyeLow),r.uniform2fv(a.uFloatParams,[e._planetRadius2||0,t.activeCamera._tanViewAngle_hradOneByHeight]),r.uniform2fv(a.viewport,[t.handler.canvas.width,t.handler.canvas.height]),r.uniform1f(a.thickness,.5*this.thickness);let o=this._verticesHighBuffer;r.bindBuffer(r.ARRAY_BUFFER,o),r.vertexAttribPointer(s.prevHigh,o.itemSize,r.FLOAT,!1,12,0),r.vertexAttribPointer(s.currentHigh,o.itemSize,r.FLOAT,!1,12,48),r.vertexAttribPointer(s.nextHigh,o.itemSize,r.FLOAT,!1,12,96),o=this._verticesLowBuffer,r.bindBuffer(r.ARRAY_BUFFER,o),r.vertexAttribPointer(s.prevLow,o.itemSize,r.FLOAT,!1,12,0),r.vertexAttribPointer(s.currentLow,o.itemSize,r.FLOAT,!1,12,48),r.vertexAttribPointer(s.nextLow,o.itemSize,r.FLOAT,!1,12,96),r.bindBuffer(r.ARRAY_BUFFER,this._ordersBuffer),r.vertexAttribPointer(s.order,this._ordersBuffer.itemSize,r.FLOAT,!1,4,0),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),r.drawElements(r.TRIANGLE_STRIP,this._indexesBuffer.numItems,r.UNSIGNED_INT,0),r.enable(r.CULL_FACE)}}_refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_update(){if(this._renderNode){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}_deleteBuffers(){if(this._renderNode){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer),e.deleteBuffer(this._ordersBuffer),e.deleteBuffer(this._indexesBuffer),e.deleteBuffer(this._colorsBuffer),this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null}}_createVerticesBuffer(){let e=this._renderNode.renderer.handler,t=this._verticesHigh.length/3;this._verticesHighBuffer&&this._verticesHighBuffer.numItems===t||(e.gl.deleteBuffer(this._verticesHighBuffer),e.gl.deleteBuffer(this._verticesLowBuffer),this._verticesHighBuffer=e.createStreamArrayBuffer(3,t),this._verticesLowBuffer=e.createStreamArrayBuffer(3,t)),this._verticesHigh=Oe(this._verticesHigh),this._verticesLow=Oe(this._verticesLow),e.setStreamArrayBuffer(this._verticesHighBuffer,this._verticesHigh),e.setStreamArrayBuffer(this._verticesLowBuffer,this._verticesLow)}_createIndexBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._ordersBuffer),e.gl.deleteBuffer(this._indexesBuffer),this._orders=Oe(this._orders),this._ordersBuffer=e.createArrayBuffer(this._orders,1,this._orders.length/2),this._indexes=Oe(this._indexes,Uint32Array),this._indexesBuffer=e.createElementArrayBuffer(this._indexes,1,this._indexes.length)}_createColorsBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._colorsBuffer),this._colors=Oe(this._colors),this._colorsBuffer=e.createArrayBuffer(new Float32Array(this._colors),4,this._colors.length/4)}}bi.__counter__=0;class wi{constructor(e={}){this.__id=wi.__counter__++,this._thickness=e.thickness||2,this._startPosition=Ae(e.startPosition),this._startPositionHigh=new oe,this._startPositionLow=new oe,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._endPosition=Ae(e.endPosition),this._endPositionHigh=new oe,this._endPositionLow=new oe,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._startColor=Ee(e.startColor),this._endColor=Ee(e.endColor),this._visibility=null==e.visibility||e.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1}setStartPosition(e,t,i){this._startPosition.x=e,this._startPosition.y=t,this._startPosition.z=i,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._handler&&this._handler.setStartPositionArr(this._handlerIndex,this._startPositionHigh,this._startPositionLow)}getLength(){return this._startPosition.distance(this._endPosition)}setStartPosition3v(e){this._startPosition.x=e.x,this._startPosition.y=e.y,this._startPosition.z=e.z,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._handler&&this._handler.setStartPositionArr(this._handlerIndex,this._startPositionHigh,this._startPositionLow)}setEndPosition(e,t,i){this._endPosition.x=e,this._endPosition.y=t,this._endPosition.z=i,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._handler&&this._handler.setEndPositionArr(this._handlerIndex,this._endPositionHigh,this._endPositionLow)}setEndPosition3v(e){this._endPosition.x=e.x,this._endPosition.y=e.y,this._endPosition.z=e.z,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._handler&&this._handler.setEndPositionArr(this._handlerIndex,this._endPositionHigh,this._endPositionLow)}setThickness(e){this._thickness=e,this._handler&&this._handler.setThicknessArr(this._handlerIndex,e)}setColors4v(e,t){e&&(this._startColor.x=e.x,this._startColor.y=e.y,this._startColor.z=e.z,this._startColor.w=e.w),t&&(this._endColor.x=t.x,this._endColor.y=t.y,this._endColor.z=t.z,this._endColor.w=t.w),this._handler&&this._handler.setRgbaArr(this._handlerIndex,this._startColor,this._endColor)}setColorsHTML(e,t){e&&(this._startColor=ve(e)),t&&(this._endColor=ve(t)),this._handler&&this._handler.setRgbaArr(this._handlerIndex,this._startColor,this._endColor)}getStartPosition(){return this._startPosition}getEndPosition(){return this._endPosition}setVisibility(e){this._visibility=e,this._handler&&this._handler.setVisibility(this._handlerIndex,e)}getVisibility(){return this._visibility}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._handler&&this._handler.setPickingColorArr(this._handlerIndex,e)}}wi.__counter__=0;let Ti=new oe,Ci=new oe;class Li{constructor(e={}){if(this.__id=Li.__counter__++,this.visibility=null==e.visibility||e.visibility,this.color=new Float32Array([1,1,1,.5]),e.color){let t=Ee(e.color);this.setColor(t.x,t.y,t.z,t.w)}e.opacity&&this.setOpacity(e.opacity),this._renderNode=null,this._entity=null,this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._indexBuffer=null,this._verticesHigh=[],this._verticesLow=[],this._indexes=[],this._path=[],this._pickingColor=new Float32Array(4),this._gridSize=1,this._handler=null,this._handlerIndex=-1,e.path&&this.setPath(e.path)}setPickingColor3v(e){this._pickingColor[0]=e.x/255,this._pickingColor[1]=e.y/255,this._pickingColor[2]=e.z/255,this._pickingColor[3]=1}clear(){this._path.length=0,this._path=[],this._verticesHigh.length=0,this._verticesHigh=[],this._verticesLow.length=0,this._verticesLow=[],this._indexes.length=0,this._indexes=[],this._deleteBuffers()}setColor4v(e){this.setColor(e.x,e.y,e.z,e.w)}setColorHTML(e){this.setColor4v(ve(e))}setColor(e,t,i,n){n=n||this.color[3],this.color[0]=e,this.color[1]=t,this.color[2]=i,this.color[3]=n}setOpacity(e){this.color[3]=e||0}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){this._renderNode=e,this._createBuffers()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}draw(){if(this.visibility&&this._verticesHigh.length){let e=this._renderNode.renderer,t=e.handler.gl,i=e.handler.programs.strip,n=i._program,r=n.attributes,s=n.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(s.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(s.eyePositionLow,e.activeCamera.eyeLow),t.uniform4fv(s.uColor,this.color),t.uniform1f(s.uOpacity,this._entity._entityCollection._fadingOpacity),t.bindBuffer(t.ARRAY_BUFFER,this._verticesHighBuffer),t.vertexAttribPointer(r.aVertexPositionHigh,this._verticesHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._verticesLowBuffer),t.vertexAttribPointer(r.aVertexPositionLow,this._verticesLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indexBuffer),t.drawElements(e.handler.gl.TRIANGLE_STRIP,this._indexBuffer.numItems,t.UNSIGNED_INT,0),t.enable(t.CULL_FACE)}}drawPicking(){if(this.visibility&&this._verticesHigh.length){let e=this._renderNode.renderer,t=e.handler.gl,i=e.handler.programs.strip,n=i._program,r=n.attributes,s=n.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(s.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(s.eyePositionLow,e.activeCamera.eyeLow),t.uniform1f(s.uOpacity,0!=this._entity._entityCollection._fadingOpacity?1:0),t.uniform4fv(s.uColor,this._pickingColor),t.bindBuffer(t.ARRAY_BUFFER,this._verticesHighBuffer),t.vertexAttribPointer(r.aVertexPositionHigh,this._verticesHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._verticesLowBuffer),t.vertexAttribPointer(r.aVertexPositionLow,this._verticesLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indexBuffer),t.drawElements(e.handler.gl.TRIANGLE_STRIP,this._indexBuffer.numItems,t.UNSIGNED_INT,0),t.enable(t.CULL_FACE)}}_deleteBuffers(){if(this._renderNode&&this._renderNode.renderer){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._indexBuffer),e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer)}this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._indexBuffer=null}_createBuffers(){if(this._renderNode&&this._renderNode.renderer&&this._renderNode.renderer.isInitialized()){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._indexBuffer),e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer),this._verticesHighBuffer=this._renderNode.renderer.handler.createArrayBuffer(new Float32Array(this._verticesHigh),3,this._verticesHigh.length/3),this._verticesLowBuffer=this._renderNode.renderer.handler.createArrayBuffer(new Float32Array(this._verticesLow),3,this._verticesLow.length/3),this._indexBuffer=this._renderNode.renderer.handler.createElementArrayBuffer(new Uint32Array(this._indexes),1,this._indexes.length)}}addEdge3v(e,t){let i=this._path.length;if(0===i)this._path.push([e.clone(),t.clone()]);else{let n=this._path[i-1][0],r=this._path[i-1][1];this._path.push([e.clone(),t.clone()]);let s=this._verticesHigh,a=this._verticesLow,o=this._gridSize,l=o+1,h=new oe,c=this._verticesHigh.length/3,d=c,_=Math.abs(n.sub(r).normal().dot(e.sub(n).normal()));for(let i=0;i<l;i++){let u=i/o,f=n.lerp(e,u),g=r.lerp(t,u);for(let u=0;u<l;u++){let p=u/o,m=n.lerp(r,p),v=e.lerp(t,p);1!==_?new ci(f,g).intersects(new ci(m,v),h):h=v,d=c+i*l+u,oe.doubleToTwoFloats(h,Ti,Ci);let y=3*d;s[y]=Ti.x,s[y+1]=Ti.y,s[y+2]=Ti.z,a[y]=Ci.x,a[y+1]=Ci.y,a[y+2]=Ci.z,i<o&&this._indexes.push(d,d+l)}i<o&&this._indexes.push(d+l,d+1)}this._createBuffers()}}setEdge3v(e,t,i){if(i!==this._path.length)if(this._path[i]){if(this._path[i][0]=e,this._path[i][1]=t,this._path.length>1){let n=this._gridSize,r=n+1,s=r*r,a=new oe,o=this._verticesHigh,l=this._verticesLow;if(i===this._path.length-1){let h=this._path[i-1][0],c=this._path[i-1][1],d=this._verticesHigh.length/3-s,_=d,u=Math.abs(h.sub(c).normal().dot(e.sub(h).normal()));for(let i=0;i<r;i++){let s=i/n,f=h.lerp(e,s),g=c.lerp(t,s);for(let s=0;s<r;s++){let p=s/n,m=h.lerp(c,p),v=e.lerp(t,p);1!==u?new ci(f,g).intersects(new ci(m,v),a):a=v,_=d+i*r+s,oe.doubleToTwoFloats(a,Ti,Ci);let y=3*_;o[y]=Ti.x,o[y+1]=Ti.y,o[y+2]=Ti.z,l[y]=Ci.x,l[y+1]=Ci.y,l[y+2]=Ci.z}}}else if(0===i){let i=0,s=e,h=t;e=this._path[1][0],t=this._path[1][1];for(let c=0;c<r;c++){let d=c/n,_=s.lerp(e,d),u=h.lerp(t,d);for(let d=0;d<r;d++){let f=d/n,g=s.lerp(h,f),p=e.lerp(t,f);new ci(_,u).intersects(new ci(g,p),a),i=c*r+d,oe.doubleToTwoFloats(a,Ti,Ci);let m=3*i;o[m]=Ti.x,o[m+1]=Ti.y,o[m+2]=Ti.z,l[m]=Ci.x,l[m+1]=Ci.y,l[m+2]=Ci.z}}}else if(i>0&&i<this._path.length){let h=this._path[i-1][0],c=this._path[i-1][1],d=this._path[i+1][0],_=this._path[i+1][1],u=i*s,f=(i-1)*s,g=f;for(let i=0;i<r;i++){let s=i/n,p=h.lerp(e,s),m=t.lerp(_,s),v=e.lerp(d,s),y=c.lerp(t,s);for(let s=0;s<r;s++){let x=s/n,b=h.lerp(c,x),w=e.lerp(t,x);new ci(p,y).intersects(new ci(b,w),a);let T=i*r+s;g=f+T,oe.doubleToTwoFloats(a,Ti,Ci);let C=3*g;o[C]=Ti.x,o[C+1]=Ti.y,o[C+2]=Ti.z,l[C]=Ci.x,l[C+1]=Ci.y,l[C+2]=Ci.z;let L=d.lerp(_,x);w=e.lerp(t,x),new ci(v,m).intersects(new ci(w,L),a),g=u+T,oe.doubleToTwoFloats(a,Ti,Ci),C=3*g,o[C]=Ti.x,o[C+1]=Ti.y,o[C+2]=Ti.z,l[C]=Ci.x,l[C+1]=Ci.y,l[C+2]=Ci.z}}}this._createBuffers()}}else console.warn(`strip index ${i} is out of range`);else this.addEdge3v(e,t)}removeEdge(e){this._path.splice(e,1),this.setPath([].concat(this._path))}setGridSize(e){this._gridSize=e,this.setPath([].concat(this._path))}getPath(){return this._path}setPath(e){this._verticesHigh=[],this._verticesLow=[],this._indexes=[],this._path=[];for(let t=0;t<e.length;t++){let i=e[t][0],n=e[t][1];i instanceof Array&&(i=new oe(i[0],i[1],i[2])),n instanceof Array&&(n=new oe(n[0],n[1],n[2])),this.addEdge3v(i,n)}}insertEdge3v(e,t,i){if(i<this._path.length){let n=[].concat(this._path);n.splice(i,0,[e,t]),this.setPath(n)}else i===this._path.length&&this.addEdge3v(e,t)}}Li.__counter__=0;class Ai{constructor(e={}){e.properties=e.properties||{},this.__id=Ai.__counter__++,this.properties=e.properties||{},this.properties.name=null!=this.properties.name?this.properties.name:"",this.childrenNodes=[],this.parent=null,this._cartesian=Ae(e.cartesian),this._lonLat=Se(e.lonlat),this._lonLatMerc=new z,this._altitude=e.altitude||0,this._visibility=null==e.visibility||e.visibility,this._entityCollection=null,this._entityCollectionIndex=-1,this._layer=null,this._layerIndex=-1,this._pickingColor=new oe(0,0,0),this._featureConstructorArray={billboard:[si,this.setBillboard],label:[yi,this.setLabel],polyline:[bi,this.setPolyline],pointCloud:[xi,this.setPointCloud],geometry:[li,this.setGeometry],geoObject:[pi,this.setGeoObject],strip:[Li,this.setStrip],ray:[wi,this.setRay]},this.billboard=this._createOptionFeature("billboard",e.billboard),this.label=this._createOptionFeature("label",e.label),this.polyline=this._createOptionFeature("polyline",e.polyline),this.ray=this._createOptionFeature("ray",e.ray),this.pointCloud=this._createOptionFeature("pointCloud",e.pointCloud),this.geometry=this._createOptionFeature("geometry",e.geometry),this.geoObject=this._createOptionFeature("geoObject",e.geoObject),this.strip=this._createOptionFeature("strip",e.strip)}get id(){return this.__id}isEqual(e){return this.__id===e.__id}get layerIndex(){return this._layerIndex}get instanceName(){return"Entity"}_createOptionFeature(e,t){if(t){let i=this._featureConstructorArray[e];return i[1].call(this,new i[0](t))}return null}getCollectionIndex(){return this._entityCollectionIndex}addTo(e,t=!1){return e.add(this,t),this}remove(){this._layer&&this._layer.removeEntity(this),this._entityCollection&&this._entityCollection.removeEntity(this)}setVisibility(e){this._visibility=e,this.billboard&&this.billboard.setVisibility(e),this.geoObject&&this.geoObject.setVisibility(e),this.label&&this.label.setVisibility(e),this.polyline&&this.polyline.setVisibility(e),this.ray&&this.ray.setVisibility(e),this.geometry&&this.geometry.setVisibility(e);for(let t=0;t<this.childrenNodes.length;t++)this.childrenNodes[t].setVisibility(e)}getVisibility(){return this._visibility}setCartesian3v(e){this.setCartesian(e.x,e.y,e.z)}setCartesian(e,t,i){let n=this._cartesian;n.x=e||0,n.y=t||0,n.z=i||0,this.billboard&&this.billboard.setPosition3v(n),this.geoObject&&this.geoObject.setPosition3v(n),this.label&&this.label.setPosition3v(n);for(let n=0;n<this.childrenNodes.length;n++)this.childrenNodes[n].setCartesian(e,t,i);let r=this._entityCollection;r&&r.renderNode&&r.renderNode.ellipsoid&&(this._lonLat=r.renderNode.ellipsoid.cartesianToLonLat(n),Math.abs(this._lonLat.lat)<J?this._lonLatMerc=this._lonLat.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=this._lonLatMerc.height=0)}_setCartesian3vSilent(e,t=!1){let i=this._cartesian;i.x=e.x||0,i.y=e.y||0,i.z=e.z||0,this.billboard&&this.billboard.setPosition3v(i),this.geoObject&&this.geoObject.setPosition3v(i),this.label&&this.label.setPosition3v(i);for(let e=0;e<this.childrenNodes.length;e++)this.childrenNodes[e].setCartesian(i.x,i.y,i.z);let n=this._entityCollection;!t&&n&&n.renderNode&&n.renderNode.ellipsoid&&(this._lonLat=n.renderNode.ellipsoid.cartesianToLonLat(i),Math.abs(this._lonLat.lat)<J&&(this._lonLatMerc=this._lonLat.forwardMercator()))}getLonLat(){return this._lonLat.clone()}setLonLat(e){let t=this._lonLat;t.lon=e.lon,t.lat=e.lat,t.height=e.height;let i=this._entityCollection;i&&i.renderNode&&i.renderNode.ellipsoid&&(Math.abs(t.lat)<J&&(this._lonLatMerc=t.forwardMercator()),i.renderNode.ellipsoid.lonLatToCartesianRes(t,this._cartesian),this.setCartesian3v(this._cartesian))}setLonLat2(e,t,i){let n=this._lonLat;n.lon=e,n.lat=t,n.height=null!=i?i:n.height;let r=this._entityCollection;r&&r.renderNode&&r.renderNode.ellipsoid&&(Math.abs(n.lat)<J?this._lonLatMerc=n.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=this._lonLatMerc.height=0,r.renderNode.ellipsoid.lonLatToCartesianRes(n,this._cartesian),this.setCartesian3v(this._cartesian))}setAltitude(e){this._altitude=e}getAltitude(){return this._altitude}getCartesian(){return this._cartesian.clone()}setBillboard(e){return this.billboard&&this.billboard.remove(),this.billboard=e,this.billboard._entity=this,this.billboard.setPosition3v(this._cartesian),this.billboard.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.billboardHandler.add(e),e}setLabel(e){return this.label&&this.label.remove(),this.label=e,this.label._entity=this,this.label.setPosition3v(this._cartesian),this.label.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.labelHandler.add(e),e}setRay(e){return this.ray&&this.ray.remove(),this.ray=e,this.ray._entity=this,this.ray.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.rayHandler.add(e),e}setPolyline(e){return this.polyline&&this.polyline.remove(),this.polyline=e,this.polyline._entity=this,this.polyline.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.polylineHandler.add(e),e}setPointCloud(e){return this.pointCloud&&this.pointCloud.remove(),this.pointCloud=e,this.pointCloud._entity=this,this.pointCloud.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.pointCloudHandler.add(e),e}setGeometry(e){this.geometry&&this.geometry.remove(),this.geometry=e,this.geometry._entity=this,this.geometry.setVisibility(this._visibility);let t=this._layer;return this._layer&&this._layer.removeEntity(this),t&&t.add(this),e}setGeoObject(e){return this.geoObject&&this.geoObject.remove(),this.geoObject=e,this.geoObject._entity=this,this.geoObject.setPosition3v(this._cartesian),this.geoObject.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.geoObjectHandler.add(e),e}setStrip(e){return this.strip&&this.strip.remove(),this.strip=e,this.strip._entity=this,this.strip.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.stripHandler.add(e),e}get layer(){return this._layer}get rendererEvents(){return this._layer?this._layer.events:this._entityCollection?this._entityCollection.events:null}appendChild(e){e._entityCollection=this._entityCollection,e._pickingColor=this._pickingColor,e.parent=this,this.childrenNodes.push(e),this._entityCollection&&this._entityCollection.appendChildEntity(e)}setPickingColor(){let e=this._pickingColor;this.billboard&&this.billboard.setPickingColor3v(e),this.label&&this.label.setPickingColor3v(e),this.polyline&&this.polyline.setPickingColor3v(e),this.ray&&this.ray.setPickingColor3v(e),this.strip&&this.strip.setPickingColor3v(e),this.geoObject&&this.geoObject.setPickingColor3v(e);for(let e=0;e<this.childrenNodes.length;e++)this.childrenNodes[e].setPickingColor()}getExtent(){let e,t=this._lonLat;e=this.billboard||this.label?new ie(new z(t.lon,t.lat),new z(t.lon,t.lat)):new ie(new z(180,90),new z(-180,-90));let i=e.southWest,n=e.northEast;if(this.polyline){let e=this.polyline.getExtent();e.southWest.lon<i.lon&&(i.lon=e.southWest.lon),e.southWest.lat<i.lat&&(i.lat=e.southWest.lat),e.northEast.lon>n.lon&&(n.lon=e.northEast.lon),e.northEast.lat>n.lat&&(n.lat=e.northEast.lat)}if(this.geometry){let e=this.geometry.getExtent();e.southWest.lon<i.lon&&(i.lon=e.southWest.lon),e.southWest.lat<i.lat&&(i.lat=e.southWest.lat),e.northEast.lon>n.lon&&(n.lon=e.northEast.lon),e.northEast.lat>n.lat&&(n.lat=e.northEast.lat)}for(let e=0;e<this.childrenNodes.length;e++){let t=this.childrenNodes[e].getExtent();t.southWest.lon<i.lon&&(i.lon=t.southWest.lon),t.southWest.lat<i.lat&&(i.lat=t.southWest.lat),t.northEast.lon>n.lon&&(n.lon=t.northEast.lon),t.northEast.lat>n.lat&&(n.lat=t.northEast.lat)}return e}}Ai.__counter__=0;class Ei{constructor(e){this.__id=Ei.__counter__++,this._name=e||`nonameNode:${this.__id}`,this.topNode=this,this._dictionary={},this._dictionary[this._name]=this,this.childNodes=[],this.parentNode=null}get name(){return this._name}addNode(e){null==this.parentNode?e.topNode=this:e.topNode=this.topNode,e.parentNode=this,e._dictionary=this.topNode._dictionary,this.childNodes.push(e),this.topNode._dictionary[e.name]=e}destroy(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e].destroy();this._clear()}getNodeByName(e){return this._dictionary[e]}_clear(){this.parentNode=null,this.topNode=this,this.childNodes.length=0}isEqual(e){return e.__id===this.__id}}Ei.__counter__=0;class Pi extends Ei{constructor(e){super(e),this.childNodes=[],this.renderer=null,this.drawMode=0,this.show=!0,this._isActive=!0,this.lightEnabled=!1,this._lights=[],this._lightsNames=[],this._lightsPositions=[],this._lightsParamsv=[],this._lightsParamsf=[],this.entityCollections=[],this._pickingId=-1}addNode(e){super.addNode(e),this.renderer&&e.assign(this.renderer)}assign(e){this.renderer=e,this._pickingId=e.addPickingCallback(this,this._entityCollectionPickingCallback),this.initialize()}initialize(){if(this.renderer&&this.renderer.isInitialized()){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].bindRenderNode(this);this.init()}}init(){}onremove(){}remove(){let e=this.renderer,t=this.name;if(e){e.renderNodes[t]&&e.renderNodes[t].isEqual(this)&&(e.renderNodes[t]=null,delete e.renderNodes[t]);for(let t=0;t<e._renderNodesArr.length;t++)if(e._renderNodesArr[t].isEqual(this)){e._renderNodesArr.splice(t,1);break}e.removePickingCallback(this._pickingId),this._pickingId=-1,this.onremove&&this.onremove()}}addEntityCollection(e,t){return e.addTo(this,t),this}removeEntityCollection(e){e.remove()}addLight(e){return e.addTo(this),this}getLightByName(e){let t=this._lightsNames.indexOf(e);return this._lights[t]}removeLight(e){e.remove()}preDrawNode(){this._isActive&&this._preDrawNodes()}drawNode(){this._isActive&&this._drawNodes()}isActive(){return this._isActive}setActive(e){this._isActive=e,this.renderer&&(this._isActive&&-1===this._pickingId?this._pickingId=this.renderer.addPickingCallback(this,this._entityCollectionPickingCallback):this._isActive||-1===this._pickingId||(this.renderer.removePickingCallback(this._pickingId),this._pickingId=-1));for(let t=0;t<this.childNodes.length;t++)this.childNodes[t].setActive(e)}setDrawMode(e){this.drawMode=e;for(let t=0;t<this.childNodes.length;t++)this.childNodes[t].setDrawMode(e)}transformLights(){for(let e=0;e<this._lights.length;e++){let t,i=3*e;t=this._lights[e]._position,this._lightsPositions[i]=t.x,this._lightsPositions[i+1]=t.y,this._lightsPositions[i+2]=t.z}}updateBillboardsTexCoords(){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].billboardHandler.refreshTexCoordsArr()}frame(){}preFrame(){}_preDrawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._preDrawNodes();this.show&&(this.preFrame(),this.drawEntityCollections(this.entityCollections))}_drawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._drawNodes();this.show&&this.frame()}drawEntityCollections(e){this.renderer.enqueueEntityCollectionsToDraw(e)}drawPickingEntityCollections(e){if(e.length){let t=e.length;for(;t--;)e[t]._fadingOpacity&&e[t].billboardHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].geoObjectHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].labelHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].rayHandler.drawPicking();for(t=e.length;t--;)e[t]._visibility&&e[t].polylineHandler.drawPicking();for(t=e.length;t--;)e[t]._visibility&&e[t].stripHandler.drawPicking()}}_entityCollectionPickingCallback(){this.drawPickingEntityCollections(this.entityCollections)}}const Mi=new class{constructor(){this._container=document.createElement("div"),this._container.classList.add("ogConsole"),this._container.style.display="none",document.body&&document.body.appendChild(this._container),this._visibility=!1}getVisibility(){return this._visibility}setVisibility(e){this._visibility!=e&&(this._visibility=e,this._visibility?this.show():this.hide())}show(){this._container.parentNode||document.body&&document.body.appendChild(this._container),this._container.style.display="block",this._visibility=!0}hide(){this._container.style.display="none",this._visibility=!1}logErr(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.classList.add("ogConsole-error"),t.innerHTML="error: "+e,console.trace(t.innerHTML),this._container.appendChild(t),this.show()}logWrn(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.classList.add("ogConsole-warning"),t.innerHTML="warning: "+e,console.trace(t.innerHTML),this._container.appendChild(t),this.show()}log(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.innerHTML=e,console.trace(e),this._container.appendChild(t),this.show()}};let Si=["FLOAT","DOUBLE","BOOL","INT","UINT","VEC2","VEC3","VEC4","DVEC2","DVEC3","DVEC4","BVEC2","BVEC3","BVEC4","IVEC2","IVEC3","IVEC4","UVEC2","UVEC3","UVEC4","MAT2","DMAT2","MAT3","DMAT3","MAT4","DMAT4","MAT2X3","MAT2X4","MAT3X2","MAT3X4","MAT4X2","MAT4X3","DMAT2X3","DMAT2X4","DMAT3X2","DMAT3X4","DMAT4X2","DMAT4X3","SAMPLER1D","SAMPLER2D","SAMPLER3D","SAMPLERCUBE","SAMPLER2DSHADOW","SAMPLER2DARRAY","INTXX","FLOATXX"];const Bi={};for(let e=0;e<Si.length;e++)Bi[Si[e]]=e;const ki={};for(let e=0;e<Si.length;e++)ki[Si[e].toLowerCase()]=Bi[Si[e]];const Ri={u:[],a:[]};Ri.u[Bi.MAT4]=function(e,t){e.gl.uniformMatrix4fv(t._pName,!1,t.value)},Ri.u[Bi.MAT3]=function(e,t){e.gl.uniformMatrix3fv(t._pName,!1,t.value)},Ri.u[Bi.FLOAT]=function(e,t){e.gl.uniform1f(t._pName,t.value)},Ri.u[Bi.INT]=function(e,t){e.gl.uniform1i(t._pName,t.value)},Ri.u[Bi.VEC2]=function(e,t){e.gl.uniform2fv(t._pName,t.value)},Ri.u[Bi.VEC3]=function(e,t){e.gl.uniform3fv(t._pName,t.value)},Ri.u[Bi.VEC4]=function(e,t){e.gl.uniform4fv(t._pName,t.value)},Ri.u[Bi.SAMPLER2D]=function(e,t){let i=e.gl;i.activeTexture(i.TEXTURE0+e._textureID),i.bindTexture(i.TEXTURE_2D,t.value),i.uniform1i(t._pName,e._textureID),e._textureID++},Ri.u[Bi.SAMPLERCUBE]=function(e,t){let i=e.gl;i.activeTexture(i.TEXTURE0+e._textureID),i.bindTexture(i.TEXTURE_CUBE_MAP,t.value),i.uniform1i(t._pName,e._textureID),e._textureID++},Ri.u[Bi.SAMPLER2DARRAY]=function(e,t){let i=t.value,n=e.gl,r=i.length,s=new Int32Array(r);for(let t=0;t<r;t++)n.activeTexture(n.TEXTURE0+e._textureID+t),n.bindTexture(n.TEXTURE_2D,i[t]),s[t]=t;n.uniform1iv(t._pName,s)},Ri.u[Bi.INTXX]=function(e,t){e.gl.uniform1iv(t._pName,t.value)},Ri.u[Bi.FLOATXX]=function(e,t){e.gl.uniform1fv(t._pName,t.value)},Ri.a[Bi.FLOAT]=function(e,t){e.gl.vertexAttrib1f(t._pName,t.value)},Ri.a[Bi.VEC2]=function(e,t){e.gl.vertexAttrib2fv(t._pName,t.value)},Ri.a[Bi.VEC3]=function(e,t){e.gl.vertexAttrib3fv(t._pName,t.value)};const Ii=["BYTE","SHORT","UNSIGNED_BYTE","UNSIGNED_SHORT","FLOAT","HALF_FLOAT"];class zi{constructor(e,t){this.name=e,this._attributes={};for(let e in t.attributes)"string"==typeof t.attributes[e]||"number"==typeof t.attributes[e]?this._attributes[e]={type:t.attributes[e]}:this._attributes[e]=t.attributes[e];this._uniforms={};for(let e in t.uniforms)"string"==typeof t.uniforms[e]||"number"==typeof t.uniforms[e]?this._uniforms[e]={type:t.uniforms[e]}:this._uniforms[e]=t.uniforms[e];this.vertexShader=t.vertexShader,this.fragmentShader=t.fragmentShader,this.gl=null,this._variables={},this._p=null,this._textureID=0,this._attribArrays=[],this._attribDivisor=[],this.attributes={},this.uniforms={},this.vertexAttribDivisor=null,this.drawElementsInstanced=null}static bindBuffer(e,t){let i=e.gl;i&&(i.bindBuffer(i.ARRAY_BUFFER,t.value),i.vertexAttribPointer(t._pName,t.value.itemSize,t.itemType,t.normalized,0,0))}use(){this.gl&&this.gl.useProgram(this._p)}set(e){this._textureID=0;for(let t in e)this._variables[t].value=e[t],this._variables[t].func(this,this._variables[t])}apply(){this._textureID=0;let e=this._variables;for(let t in e)e[t].func(this,e[t])}drawIndexBuffer(e,t){let i=this.gl;i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,t),i.drawElements(e,t.numItems,i.UNSIGNED_SHORT,0)}drawArrays(e,t){this.gl.drawArrays(e,0,t)}_getShaderCompileStatus(e,t){return!!this.gl&&(this.gl.shaderSource(e,t),this.gl.compileShader(e),!!this.gl.getShaderParameter(e,this.gl.COMPILE_STATUS)||(Mi.logErr(`Shader program "${this.name}":${this.gl.getShaderInfoLog(e)}.`),!1))}_createVertexShader(e){if(!this.gl)return;let t=this.gl.createShader(this.gl.VERTEX_SHADER);return t&&this._getShaderCompileStatus(t,e)?t:void 0}_createFragmentShader(e){if(!this.gl)return;let t=this.gl.createShader(this.gl.FRAGMENT_SHADER);return t&&this._getShaderCompileStatus(t,e)?t:void 0}disableAttribArrays(){let e=this.gl,t=this._attribArrays;for(let i=0,n=t.length;i<n;i++)e.disableVertexAttribArray(t[i]),this.vertexAttribDivisor(t[i],0)}enableAttribArrays(){let e=this.gl,t=this._attribArrays,i=this._attribDivisor;for(let n=0,r=t.length;n<r;n++)e.enableVertexAttribArray(t[n]),this.vertexAttribDivisor(t[n],i[n])}delete(){this.gl&&this.gl.deleteProgram(this._p)}createProgram(e){if(this.gl=e,this._p=this.gl.createProgram(),!this._p)return;let t=this._createFragmentShader(this.fragmentShader),i=this._createVertexShader(this.vertexShader);if(t&&i){if(e.attachShader(this._p,t),e.attachShader(this._p,i),e.linkProgram(this._p),!this.drawElementsInstanced)if(e.drawElementsInstanced)this.drawElementsInstanced=e.drawElementsInstanced.bind(e);else{let t=e.getExtension("ANGLE_instanced_arrays");t&&(this.drawElementsInstanced=t.drawElementsInstancedANGLE.bind(t))}if(!this.vertexAttribDivisor)if(e.vertexAttribDivisor)this.vertexAttribDivisor=e.vertexAttribDivisor.bind(e);else{let t=e.getExtension("ANGLE_instanced_arrays");t&&(this.vertexAttribDivisor=t.vertexAttribDivisorANGLE.bind(t))}if(!e.getProgramParameter(this._p,e.LINK_STATUS))return Mi.logErr(`Shader program "${this.name}": initialization failed. ${e.getProgramInfoLog(this._p)}.`),void e.deleteProgram(this._p);this.use();for(let t in this._attributes){this._variables[t]=this._attributes[t],this._attributes[t].func=zi.bindBuffer;let i=this._attributes[t].itemType,n=i?i.trim().toUpperCase():"FLOAT";if(-1==Ii.indexOf(n)?(Mi.logErr(`Shader program "${this.name}": attribute '${t}', item type '${this._attributes[t].itemType}' not exists.`),this._attributes[t].itemType=e.FLOAT):this._attributes[t].itemType=e[n],this._attributes[t].normalized=this._attributes[t].normalized||!1,this._attributes[t].divisor=this._attributes[t].divisor||0,this._p[t]=e.getAttribLocation(this._p,t),null==this._p[t])return Mi.logErr(`Shader program "${this.name}": attribute '${t}' not exists.`),void e.deleteProgram(this._p);let r=this._attributes[t].type;"string"==typeof r&&(r=ki[r.trim().toLowerCase()]);let s=this._attributes[t].divisor;if(r===Bi.MAT4){let e=this._p[t];this._attribArrays.push(e,e+1,e+2,e+3),this._attribDivisor.push(s,s,s,s)}else this._attribArrays.push(this._p[t]),this._attribDivisor.push(s);e.enableVertexAttribArray(this._p[t]),this._attributes[t]._pName=this._p[t],this.attributes[t]=this._p[t]}for(let t in this._uniforms){if("string"==typeof this._uniforms[t].type){let e=this._uniforms[t].type;this._uniforms[t].func=Ri.u[ki[e.trim().toLowerCase()]]}else this._uniforms[t].func=Ri.u[this._uniforms[t].type];if(this._variables[t]=this._uniforms[t],this._p[t]=e.getUniformLocation(this._p,t),null==this._p[t])return Mi.logErr(`Shader program "${this.name}": uniform '${t}' not exists.`),void e.deleteProgram(this._p);this._uniforms[t]._pName=this._p[t],this.uniforms[t]=this._p[t]}e.detachShader(this._p,t),e.detachShader(this._p,i),e.deleteShader(t),e.deleteShader(i)}}}const Fi="vec2 project(vec4 p) {\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }",Di="mat2 rotate2d(float angle) {\n return mat2(cos(angle), -sin(angle),\n sin(angle), cos(angle));\n }";class Ni{constructor(e){this.__id=Ni.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._billboards=[],this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._texCoordBuffer=null,this._vertexBuffer=null,this._pickingColorBuffer=null,this._texCoordArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._pickingColorArr=new Float32Array([]),this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this.createPickingColorBuffer,this._buffersUpdateCallbacks[1]=this.createPositionBuffer,this._buffersUpdateCallbacks[2]=this.createSizeBuffer,this._buffersUpdateCallbacks[3]=this.createOffsetBuffer,this._buffersUpdateCallbacks[4]=this.createRgbaBuffer,this._buffersUpdateCallbacks[5]=this.createRotationBuffer,this._buffersUpdateCallbacks[6]=this.createTexCoordBuffer,this._buffersUpdateCallbacks[7]=this.createVertexBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}isEqual(e){return e&&e.__id===this.__id}static concArr(e,t){for(let i=0;i<t.length;i++)e.push(t[i])}initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.billboard||this._renderer.handler.addProgram(new zi("billboard",{uniforms:{viewport:"vec2",u_texture:"sampler2d",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",uScaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_vertices:"vec2",a_texCoord:"vec2",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"vec2",a_rotation:"float",a_rgba:"vec4"},vertexShader:`precision highp float;\n attribute vec2 a_vertices;\n attribute vec2 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute vec2 a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec2 v_texCoords;\n varying vec4 v_rgba;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform float opacity;\n uniform float planetRadius;\n uniform vec2 viewport;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Fi}\n\n ${Di}\n\n void main() {\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_texCoords = a_texCoord;\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgba = a_rgba;\n\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n //vec3 up = vec3( viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1] );\n //vec3 right = vec3( viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0] );\n\n float scd = (1.0 - smoothstep(uScaleByDistance[0], uScaleByDistance[1], lookDist)) * (1.0 - step(uScaleByDistance[2], lookDist));\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02;\n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n\n vec2 v = screenPos + rotate2d(a_rotation) * (a_vertices * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n uniform sampler2D u_texture;\n varying vec2 v_texCoords;\n varying vec4 v_rgba;\n void main () {\n vec4 color = texture2D(u_texture, v_texCoords);\n if(color.a < 0.1)\n discard;\n gl_FragColor = color * v_rgba;\n }"})),this._renderer.handler.programs.billboardPicking||this._renderer.handler.addProgram(new zi("billboardPicking",{uniforms:{viewport:"vec2",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",uScaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_vertices:"vec2",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"vec2",a_rotation:"float",a_rgba:"vec4"},vertexShader:`precision highp float;\n attribute vec2 a_vertices;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute vec2 a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec3 v_rgb;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform float opacity;\n uniform float planetRadius;\n uniform vec2 viewport;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Fi}\n\n ${Di}\n\n void main() {\n\n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgb = a_rgba.rgb;\n\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n //vec3 up = vec3( viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1] );\n //vec3 right = vec3( viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0] );\n\n float scd = (1.0 - smoothstep(uScaleByDistance[0], uScaleByDistance[1], lookDist)) * (1.0 - step(uScaleByDistance[2], lookDist));\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02;\n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n\n vec2 v = screenPos + rotate2d(a_rotation) * (a_vertices * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n varying vec3 v_rgb;\n void main () {\n gl_FragColor = vec4(v_rgb, 1.0);\n }"})))}setRenderer(e){this._renderer=e,this.initProgram()}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_removeBillboards(){let e=this._billboards.length;for(;e--;){let t=this._billboards[e];t._handlerIndex=-1,t._handler=null,t._isReady=!1,t._lockId=ti}this._billboards.length=0,this._billboards=[]}clear(){this._texCoordArr=null,this._vertexArr=null,this._positionHighArr=null,this._positionLowArr=null,this._sizeArr=null,this._offsetArr=null,this._rgbaArr=null,this._rotationArr=null,this._pickingColorArr=null,this._texCoordArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._pickingColorArr=new Float32Array([]),this._removeBillboards(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e.deleteBuffer(this._positionHighBuffer),e.deleteBuffer(this._positionLowBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._offsetBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._rotationBuffer),e.deleteBuffer(this._vertexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._pickingColorBuffer)}this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._vertexBuffer=null,this._texCoordBuffer=null,this._pickingColorBuffer=null}update(){if(this._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}add(e){-1==e._handlerIndex&&(e._isReady=!0,e._handler=this,e._handlerIndex=this._billboards.length,this._billboards.push(e))}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.billboard.activate();let i=t.programs.billboard._program,n=i.attributes,r=i.uniforms,s=t.gl,a=this._entityCollection;s.disable(s.CULL_FACE),s.uniform1f(r.depthOffset,a.polygonOffsetUnits),s.uniform1i(r.u_texture,0),s.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),s.uniform3fv(r.uScaleByDistance,a.scaleByDistance),s.uniform1f(r.opacity,a._fadingOpacity),s.bindBuffer(s.ARRAY_BUFFER,this._texCoordBuffer),s.vertexAttribPointer(n.a_texCoord,this._texCoordBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._vertexBuffer),s.vertexAttribPointer(n.a_vertices,this._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionHighBuffer),s.vertexAttribPointer(n.a_positionsHigh,this._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionLowBuffer),s.vertexAttribPointer(n.a_positionsLow,this._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._rgbaBuffer),s.vertexAttribPointer(n.a_rgba,this._rgbaBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._sizeBuffer),s.vertexAttribPointer(n.a_size,this._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._offsetBuffer),s.vertexAttribPointer(n.a_offset,this._offsetBuffer.itemSize,s.FLOAT,!1,0,0),s.uniform1f(r.planetRadius,a.renderNode._planetRadius2||0),s.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),s.bindBuffer(s.ARRAY_BUFFER,this._rotationBuffer),s.vertexAttribPointer(n.a_rotation,this._rotationBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.enable(s.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.billboardPicking.activate();let i=t.programs.billboardPicking._program,n=i.attributes,r=i.uniforms,s=t.gl,a=this._entityCollection;s.disable(s.CULL_FACE),s.uniform1f(r.depthOffset,a.polygonOffsetUnits),s.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),s.uniform3fv(r.uScaleByDistance,a.scaleByDistance),s.uniform1f(r.opacity,a._fadingOpacity),s.bindBuffer(s.ARRAY_BUFFER,this._vertexBuffer),s.vertexAttribPointer(n.a_vertices,this._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionHighBuffer),s.vertexAttribPointer(n.a_positionsHigh,this._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionLowBuffer),s.vertexAttribPointer(n.a_positionsLow,this._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._pickingColorBuffer),s.vertexAttribPointer(n.a_rgba,this._pickingColorBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._sizeBuffer),s.vertexAttribPointer(n.a_size,this._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._offsetBuffer),s.vertexAttribPointer(n.a_offset,this._offsetBuffer.itemSize,s.FLOAT,!1,0,0),s.uniform1f(r.planetRadius,a.renderNode._planetRadius2||0),s.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),s.bindBuffer(s.ARRAY_BUFFER,this._rotationBuffer),s.vertexAttribPointer(n.a_rotation,this._rotationBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.enable(s.CULL_FACE)}draw(){this._billboards.length&&(this.update(),this._displayPASS())}drawPicking(){this._billboards.length&&this.pickingEnabled&&this._pickingPASS()}reindexBillboardsArray(e){let t=this._billboards;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}_removeBillboard(e){let t=e._handlerIndex;this._billboards.splice(t,1);let i=24*t;this._rgbaArr=Ge(this._rgbaArr,i,24),i=18*t,this._positionHighArr=Ge(this._positionHighArr,i,18),this._positionLowArr=Ge(this._positionLowArr,i,18),this._offsetArr=Ge(this._offsetArr,i,18),this._pickingColorArr=Ge(this._pickingColorArr,i,18),i=12*t,this._vertexArr=Ge(this._vertexArr,i,12),this._sizeArr=Ge(this._sizeArr,i,12),this._texCoordArr=Ge(this._texCoordArr,i,12),i=6*t,this._rotationArr=Ge(this._rotationArr,i,6),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1,e._lockId=ti}setAlignedAxisArr(e,t){}remove(e){e._handler&&(e._isReady&&this.__id===e._handler.__id?this._removeBillboard(e):e._handler=null)}setPositionArr(e,t,i){let n=18*e,r=this._positionHighArr,s=t.x,a=t.y,o=t.z;r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,r=this._positionLowArr,s=i.x,a=i.y,o=i.z,r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,this._changedBuffers[1]=!0}setPickingColorArr(e,t){let i=18*e,n=this._pickingColorArr,r=t.x/255,s=t.y/255,a=t.z/255;n[i]=r,n[i+1]=s,n[i+2]=a,n[i+3]=r,n[i+4]=s,n[i+5]=a,n[i+6]=r,n[i+7]=s,n[i+8]=a,n[i+9]=r,n[i+10]=s,n[i+11]=a,n[i+12]=r,n[i+13]=s,n[i+14]=a,n[i+15]=r,n[i+16]=s,n[i+17]=a,this._changedBuffers[0]=!0}setSizeArr(e,t,i){let n=12*e,r=this._sizeArr,s=t,a=i;r[n]=s,r[n+1]=a,r[n+2]=s,r[n+3]=a,r[n+4]=s,r[n+5]=a,r[n+6]=s,r[n+7]=a,r[n+8]=s,r[n+9]=a,r[n+10]=s,r[n+11]=a,this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e,n=this._offsetArr,r=t.x,s=t.y,a=t.z;n[i]=r,n[i+1]=s,n[i+2]=a,n[i+3]=r,n[i+4]=s,n[i+5]=a,n[i+6]=r,n[i+7]=s,n[i+8]=a,n[i+9]=r,n[i+10]=s,n[i+11]=a,n[i+12]=r,n[i+13]=s,n[i+14]=a,n[i+15]=r,n[i+16]=s,n[i+17]=a,this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e,n=this._rgbaArr,r=t.x,s=t.y,a=t.z,o=t.w;n[i]=r,n[i+1]=s,n[i+2]=a,n[i+3]=o,n[i+4]=r,n[i+5]=s,n[i+6]=a,n[i+7]=o,n[i+8]=r,n[i+9]=s,n[i+10]=a,n[i+11]=o,n[i+12]=r,n[i+13]=s,n[i+14]=a,n[i+15]=o,n[i+16]=r,n[i+17]=s,n[i+18]=a,n[i+19]=o,n[i+20]=r,n[i+21]=s,n[i+22]=a,n[i+23]=o,this._changedBuffers[4]=!0}setRotationArr(e,t){let i=6*e,n=this._rotationArr;n[i]=t,n[i+1]=t,n[i+2]=t,n[i+3]=t,n[i+4]=t,n[i+5]=t,this._changedBuffers[5]=!0}setTexCoordArr(e,t){let i=12*e,n=this._texCoordArr;n[i]=t[0],n[i+1]=t[1],n[i+2]=t[2],n[i+3]=t[3],n[i+4]=t[4],n[i+5]=t[5],n[i+6]=t[6],n[i+7]=t[7],n[i+8]=t[8],n[i+9]=t[9],n[i+10]=t[10],n[i+11]=t[11],this._changedBuffers[6]=!0}setVisibility(e,t){let i;i=t?[-.5,.5,-.5,-.5,.5,-.5,.5,-.5,.5,.5,-.5,.5]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e,n=this._vertexArr;n[i]=t[0],n[i+1]=t[1],n[i+2]=t[2],n[i+3]=t[3],n[i+4]=t[4],n[i+5]=t[5],n[i+6]=t[6],n[i+7]=t[7],n[i+8]=t[8],n[i+9]=t[9],n[i+10]=t[10],n[i+11]=t[11],this._changedBuffers[7]=!0}createPositionBuffer(){let e=this._renderer.handler,t=this._positionHighArr.length/3;this._positionHighBuffer&&this._positionHighBuffer.numItems===t||(e.gl.deleteBuffer(this._positionHighBuffer),e.gl.deleteBuffer(this._positionLowBuffer),this._positionHighBuffer=e.createStreamArrayBuffer(3,t),this._positionLowBuffer=e.createStreamArrayBuffer(3,t)),e.setStreamArrayBuffer(this._positionHighBuffer,this._positionHighArr),e.setStreamArrayBuffer(this._positionLowBuffer,this._positionLowArr)}createSizeBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createArrayBuffer(this._sizeArr,2,this._sizeArr.length/2)}createOffsetBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._offsetBuffer),this._offsetBuffer=e.createArrayBuffer(this._offsetArr,3,this._offsetArr.length/3)}createRgbaBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaBuffer=e.createArrayBuffer(this._rgbaArr,4,this._rgbaArr.length/4)}createRotationBuffer(){let e=this._renderer.handler;this._rotationBuffer&&this._rotationBuffer.numItems===this._rotationArr.length||(e.gl.deleteBuffer(this._rotationBuffer),this._rotationBuffer=e.createStreamArrayBuffer(1,this._rotationArr.length)),e.setStreamArrayBuffer(this._rotationBuffer,this._rotationArr)}createVertexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,2,this._vertexArr.length/2)}createTexCoordBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,2,this._texCoordArr.length/2)}createPickingColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}refreshTexCoordsArr(){}}Ni.__counter__=0;class Hi extends Ni{constructor(e){super(e),this._billboards=[]}add(e){if(-1==e._handlerIndex){super.add(e),this._addBillboardToArrays(e),this.refresh();let t=e.getSrc()||e.getImage()&&e.getImage().src;t&&e.setSrc(t)}}_addBillboardToArrays(e){e.getVisibility()?this._vertexArr=Ne(this._vertexArr,[-.5,.5,-.5,-.5,.5,-.5,.5,-.5,.5,.5,-.5,.5]):this._vertexArr=Ne(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]),this._texCoordArr=Ne(this._texCoordArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t,i=e._positionHigh.x,n=e._positionHigh.y,r=e._positionHigh.z;this._positionHighArr=Ne(this._positionHighArr,[i,n,r,i,n,r,i,n,r,i,n,r,i,n,r,i,n,r]),i=e._positionLow.x,n=e._positionLow.y,r=e._positionLow.z,this._positionLowArr=Ne(this._positionLowArr,[i,n,r,i,n,r,i,n,r,i,n,r,i,n,r,i,n,r]),i=e._width,n=e._height,this._sizeArr=Ne(this._sizeArr,[i,n,i,n,i,n,i,n,i,n,i,n]),i=e._offset.x,n=e._offset.y,r=e._offset.z,this._offsetArr=Ne(this._offsetArr,[i,n,r,i,n,r,i,n,r,i,n,r,i,n,r,i,n,r]),i=e._color.x,n=e._color.y,r=e._color.z,t=e._color.w,this._rgbaArr=Ne(this._rgbaArr,[i,n,r,t,i,n,r,t,i,n,r,t,i,n,r,t,i,n,r,t,i,n,r,t]),i=e._rotation,this._rotationArr=Ne(this._rotationArr,[i,i,i,i,i,i]),i=e._entity._pickingColor.x/255,n=e._entity._pickingColor.y/255,r=e._entity._pickingColor.z/255,this._pickingColorArr=Ne(this._pickingColorArr,[i,n,r,i,n,r,i,n,r,i,n,r,i,n,r,i,n,r])}get billboards(){return this._billboards}refreshTexCoordsArr(){if(this._entityCollection&&this._renderer){let e=this._renderer.billboardsTextureAtlas;for(let t=0;t<this._billboards.length;t++){let i=this._billboards[t],n=i.getImage();if(n){let t=e.get(n.__nodeIndex);t&&this.setTexCoordArr(i._handlerIndex,t.texCoords)}}}}}function Oi(e,t=0,i=0,n=1,...r){const s=t*i;for(let t=s,a=s+i;t<a;t++)e[t]=r[t%n];return e}class Vi{constructor(e){this.isFree=!0,this._geoObjectHandler=e,this.geoObjects=[],this.numInstances=0,this._texture=null,this._textureSrc=null,this._pitchRollArr=[],this._sizeArr=[],this._vertexArr=[],this._positionHighArr=[],this._positionLowArr=[],this._directionArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._pitchRollBuffer=null,this._sizeBuffer=null,this._vertexBuffer=null,this._positionHighBuffer=null,this._positionLowBuffer=null,this._directionBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[8]=this.createPickingColorBuffer,this._buffersUpdateCallbacks[1]=this.createPositionBuffer,this._buffersUpdateCallbacks[5]=this.createDirectionBuffer,this._buffersUpdateCallbacks[3]=this.createNormalsBuffer,this._buffersUpdateCallbacks[2]=this.createRgbaBuffer,this._buffersUpdateCallbacks[4]=this.createIndicesBuffer,this._buffersUpdateCallbacks[0]=this.createVertexBuffer,this._buffersUpdateCallbacks[7]=this.createSizeBuffer,this._buffersUpdateCallbacks[6]=this.createPitchRollBuffer,this._buffersUpdateCallbacks[9]=this.createVisibleBuffer,this._buffersUpdateCallbacks[10]=this.createTexCoordBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}createTexture(e){this._geoObjectHandler&&this._geoObjectHandler._planet&&(this._texture=this._geoObjectHandler._planet.renderer.handler.createTextureDefault(e))}clear(){this.numInstances=0,this.geoObjects=[],this._pitchRollArr=[],this._sizeArr=[],this._vertexArr=[],this._positionHighArr=[],this._positionLowArr=[],this._directionArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._deleteBuffers(),this.isFree=!1}_deleteBuffers(){if(this._geoObjectHandler&&this._geoObjectHandler._planet&&this._geoObjectHandler._planet.renderer){let e=this._geoObjectHandler._planet.renderer.handler,t=e.gl;e.deleteTexture(this._texture),this._texture=null,t.deleteBuffer(this._pitchRollBuffer),t.deleteBuffer(this._sizeBuffer),t.deleteBuffer(this._vertexBuffer),t.deleteBuffer(this._positionHighBuffer),t.deleteBuffer(this._positionLowBuffer),t.deleteBuffer(this._directionBuffer),t.deleteBuffer(this._rgbaBuffer),t.deleteBuffer(this._normalsBuffer),t.deleteBuffer(this._indicesBuffer),t.deleteBuffer(this._pickingColorBuffer),t.deleteBuffer(this._visibleBuffer),t.deleteBuffer(this._texCoordBuffer)}this._pitchRollBuffer=null,this._sizeBuffer=null,this._vertexBuffer=null,this._positionHighBuffer=null,this._positionLowBuffer=null,this._directionBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null}createVertexBuffer(){const e=this._geoObjectHandler._planet.renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexArr=Oe(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,3,this._vertexArr.length/3)}createPitchRollBuffer(){let e=this._geoObjectHandler._planet.renderer.handler,t=this._pitchRollArr.length/2;this._pitchRollBuffer&&this._pitchRollBuffer.numItems===t||(e.gl.deleteBuffer(this._pitchRollBuffer),this._pitchRollBuffer=e.createStreamArrayBuffer(2,t)),this._pitchRollArr=Oe(this._pitchRollArr),e.setStreamArrayBuffer(this._pitchRollBuffer,this._pitchRollArr)}createVisibleBuffer(){const e=this._geoObjectHandler._planet.renderer.handler,t=this._visibleArr.length;this._visibleBuffer&&this._visibleBuffer.numItems===t||(e.gl.deleteBuffer(this._visibleBuffer),this._visibleBuffer=e.createStreamArrayBuffer(1,t)),this._visibleArr=Oe(this._visibleArr),e.setStreamArrayBuffer(this._visibleBuffer,this._visibleArr)}createSizeBuffer(){let e=this._geoObjectHandler._planet.renderer.handler,t=this._sizeArr.length/3;this._sizeBuffer&&this._sizeBuffer.numItems===t||(e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createStreamArrayBuffer(3,t)),this._sizeArr=Oe(this._sizeArr),e.setStreamArrayBuffer(this._sizeBuffer,this._sizeArr)}createTexCoordBuffer(){const e=this._geoObjectHandler._planet.renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordArr=Oe(this._texCoordArr),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,2,this._texCoordArr.length/2)}createPositionBuffer(){let e=this._geoObjectHandler._planet.renderer.handler,t=this._positionHighArr.length/3;this._positionHighBuffer&&this._positionHighBuffer.numItems===t||(e.gl.deleteBuffer(this._positionHighBuffer),e.gl.deleteBuffer(this._positionLowBuffer),this._positionHighBuffer=e.createStreamArrayBuffer(3,t),this._positionLowBuffer=e.createStreamArrayBuffer(3,t)),this._positionHighArr=Oe(this._positionHighArr),this._positionLowArr=Oe(this._positionLowArr),e.setStreamArrayBuffer(this._positionHighBuffer,this._positionHighArr),e.setStreamArrayBuffer(this._positionLowBuffer,this._positionLowArr)}createRgbaBuffer(){let e=this._geoObjectHandler._planet.renderer.handler,t=this._rgbaArr.length/4;this._rgbaBuffer&&this._rgbaBuffer.numItems===t||(e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaBuffer=e.createStreamArrayBuffer(4,t)),this._rgbaArr=Oe(this._rgbaArr),e.setStreamArrayBuffer(this._rgbaBuffer,this._rgbaArr)}createDirectionBuffer(){let e=this._geoObjectHandler._planet.renderer.handler,t=this._directionArr.length/3;this._directionBuffer&&this._directionBuffer.numItems===t||(e.gl.deleteBuffer(this._directionBuffer),this._directionBuffer=e.createStreamArrayBuffer(3,t)),this._directionArr=Oe(this._directionArr),e.setStreamArrayBuffer(this._directionBuffer,this._directionArr)}createNormalsBuffer(){const e=this._geoObjectHandler._planet.renderer.handler;e.gl.deleteBuffer(this._normalsBuffer),this._normalsArr=Oe(this._normalsArr),this._normalsBuffer=e.createArrayBuffer(this._normalsArr,3,this._normalsArr.length/3)}createIndicesBuffer(){const e=this._geoObjectHandler._planet.renderer.handler;e.gl.deleteBuffer(this._indicesBuffer),this._indicesArr=Oe(this._indicesArr,Uint32Array),this._indicesBuffer=e.createElementArrayBuffer(this._indicesArr,1,this._indicesArr.length)}createPickingColorBuffer(){const e=this._geoObjectHandler._planet.renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=Oe(this._pickingColorArr),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}update(){if(this._geoObjectHandler._planet){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1);this.isFree=!0}}}class Ui{constructor(e){this.__id=Ui.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._planet=null,this._geoObjects=[],this._instanceDataMap=new Map,this._instanceDataMapValues=[],this._dataTagUpdateQueue=[]}initProgram(){this._planet&&this._planet.renderer&&(this._planet.renderer.handler.programs.geo_object||this._planet.renderer.handler.addProgram(new zi("geo_object",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",eyePositionHigh:"vec3",eyePositionLow:"vec3",lightsPositions:"vec3",lightsParamsv:"vec3",lightsParamsf:"float",uTexture:"sampler2d",uUseTexture:"float"},attributes:{aVertexPosition:"vec3",aVertexNormal:"vec3",aTexCoord:"vec2",aPositionHigh:{type:"vec3",divisor:1},aPositionLow:{type:"vec3",divisor:1},aDirection:{type:"vec3",divisor:1},aPitchRoll:{type:"vec2",divisor:1},aColor:{type:"vec4",divisor:1},aScale:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1}},vertexShader:"precision highp float;\n \n attribute vec3 aVertexPosition;\n attribute vec3 aVertexNormal; \n attribute vec3 aPositionHigh;\n attribute vec3 aPositionLow; \n attribute vec3 aDirection;\n attribute vec2 aPitchRoll;\n attribute vec4 aColor;\n attribute vec3 aScale;\n attribute float aDispose;\n attribute float aUseTexture;\n attribute vec2 aTexCoord;\n \n uniform vec3 uScaleByDistance;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n \n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n\n varying vec3 cameraPosition;\n varying vec3 vNormal;\n varying vec3 v_vertex; \n varying vec4 vColor;\n varying float vDispose;\n varying vec2 vTexCoords;\n //varying float useLighting;\n \n const float PI = 3.141592653589793;\n \n const float RADIANS = PI / 180.0;\n \n void main(void) {\n \n if (aDispose == 0.0) {\n return;\n }\n \n vec3 position = aPositionHigh + aPositionLow;\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 look = cameraPosition - position;\n float lookLength = length(look);\n\n // useLighting = 1.0; \n // if(lookLength > 2000000.0){\n // useLighting = 0.0;\n // }\n\n \n vColor = aColor;\n vTexCoords = aTexCoord;\n \n float cos_roll = cos(aPitchRoll.y);\n float sin_roll = sin(aPitchRoll.y);\n \n mat3 rotZ = mat3(\n vec3(cos_roll, sin_roll, 0.0),\n vec3(-sin_roll, cos_roll, 0.0), \n vec3(0.0, 0.0, 1.0) \n );\n\n float cos_pitch = cos(aPitchRoll.x);\n float sin_pitch = sin(aPitchRoll.x);\n\n mat3 rotX = mat3(\n vec3(1.0, 0.0, 0.0),\n vec3(0.0, cos_pitch, sin_pitch), \n vec3(0.0, -sin_pitch, cos_pitch) \n );\n\n vec3 r = cross(normalize(-position), aDirection);\n mat3 modelMatrix = mat3(r, normalize(position), -aDirection) * rotX * rotZ;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = aPositionHigh - eyePositionHigh;\n vec3 lowDiff = aPositionLow - eyePositionLow;\n \n vNormal = modelMatrix * aVertexNormal;\n \n // if(lookLength > uScaleByDistance[1])\n // {\n // scd = uScaleByDistance[1] / uScaleByDistance[0];\n // }\n // else if(lookLength > uScaleByDistance[0])\n // {\n // scd = lookLength / uScaleByDistance[0];\n // }\n // ... is the same math\n float scd = uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];\n \n vec3 vert = modelMatrix * (aVertexPosition * aScale) * scd;\n \n vert += lowDiff;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + vert, 1.0);\n \n v_vertex = position + vert;\n }",fragmentShader:"precision highp float;\n\n #define MAX_POINT_LIGHTS 1\n \n uniform vec3 lightsPositions[MAX_POINT_LIGHTS];\n uniform vec3 lightsParamsv[MAX_POINT_LIGHTS * 3];\n uniform float lightsParamsf[MAX_POINT_LIGHTS];\n uniform sampler2D uTexture;\n uniform float uUseTexture;\n \n varying vec3 cameraPosition;\n varying vec3 v_vertex; \n varying vec4 vColor;\n varying vec3 vNormal;\n varying vec2 vTexCoords;\n //varying float useLighting;\n \n void main(void) { \n \n vec3 lightWeighting = vec3(1.0);\n \n //if(useLighting != 0.0){\n vec3 normal = normalize(vNormal);\n vec3 lightDir = normalize(lightsPositions[0]);\n vec3 viewDir = normalize(cameraPosition - v_vertex); \n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n float specularLightWeighting = pow( reflection, lightsParamsf[0]); \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0);\n lightWeighting = lightsParamsv[0] + lightsParamsv[1] * diffuseLightWeighting + lightsParamsv[2] * specularLightWeighting;\n //}\n \n if(uUseTexture > 0.0) {\n vec4 tColor = texture2D(uTexture, vTexCoords);\n gl_FragColor = vec4(tColor.rgb * lightWeighting, tColor.a);\n } else {\n gl_FragColor = vec4(vColor.rgb * lightWeighting, vColor.a);\n }\n }"})),this._planet.renderer.handler.programs.geo_object_picking||this._planet.renderer.handler.addProgram(new zi("geo_object_picking",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",eyePositionHigh:"vec3",eyePositionLow:"vec3",pickingScale:"float"},attributes:{aVertexPosition:"vec3",aPositionHigh:{type:"vec3",divisor:1},aPositionLow:{type:"vec3",divisor:1},aDirection:{type:"vec3",divisor:1},aPitchRoll:{type:"vec2",divisor:1},aPickingColor:{type:"vec3",divisor:1},aScale:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1}},vertexShader:"precision highp float;\n\n attribute vec3 aVertexPosition;\n attribute vec3 aPositionHigh;\n attribute vec3 aPositionLow; \n attribute vec3 aDirection;\n attribute vec3 aPickingColor;\n attribute vec2 aPitchRoll;\n attribute vec3 aScale;\n attribute float aDispose;\n \n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform float pickingScale;\n\n varying vec3 vColor;\n \n const float RADIANS = 3.141592653589793 / 180.0;\n\n void main(void) {\n\n if (aDispose == 0.0) {\n return;\n }\n \n vColor = aPickingColor;\n \n float cos_roll = cos(aPitchRoll.y);\n float sin_roll = sin(aPitchRoll.y);\n \n mat3 rotZ = mat3(\n vec3(cos_roll, sin_roll, 0.0),\n vec3(-sin_roll, cos_roll, 0.0), \n vec3(0.0, 0.0, 1.0) \n );\n\n float cos_pitch = cos(aPitchRoll.x);\n float sin_pitch = sin(aPitchRoll.x);\n\n mat3 rotX = mat3(\n vec3(1.0, 0.0, 0.0),\n vec3(0.0, cos_pitch, sin_pitch), \n vec3(0.0, -sin_pitch, cos_pitch) \n );\n \n vec3 position = aPositionHigh + aPositionLow;\n vec3 cameraPosition = eyePositionHigh + eyePositionLow;\n vec3 r = cross(normalize(-position), aDirection);\n mat3 modelMatrix = mat3(r, normalize(position), -aDirection) * rotX * rotZ;\n \n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n vec3 highDiff = aPositionHigh - eyePositionHigh;\n vec3 lowDiff = aPositionLow - eyePositionLow;\n \n vec3 look = cameraPosition - position;\n float lookLength = length(look);\n \n // if(lookLength > uScaleByDistance[1])\n // {\n // scd = uScaleByDistance[1] / uScaleByDistance[0];\n // }\n // else if(lookLength > uScaleByDistance[0])\n // {\n // scd = lookLength / uScaleByDistance[0];\n // }\n // ... is the same math above\n // @hack\n // pickingScale replace to this line, because when it s\n // tays in the vert above it affects on Mac Safari jitter\n float scd = pickingScale * uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];\n\n vec3 vert = modelMatrix * (aVertexPosition * aScale) * scd;\n \n vert += lowDiff;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + vert, 1.0);\n }",fragmentShader:"precision highp float;\n varying vec3 vColor;\n void main () {\n gl_FragColor = vec4(vColor, 1.0);\n }"})))}setRenderNode(e){this._planet=e,this.initProgram();for(let e=0;e<this._instanceDataMapValues.length;e++)this._loadDataTagTexture(this._instanceDataMapValues[e]);for(let e=0;e<this._geoObjects.length;e++)this._geoObjects[e].updateDirection();this.update()}setTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&(i._textureSrc=e,this._instanceDataMap.set(t,i),this._loadDataTagTexture(i))}setObjectSrc(e,t){const i=this._instanceDataMap.get(t);e&&i&&i._objectSrc!==e&&(i._objectSrc=e,gi.loadObj(e).then((e=>{this._updateInstanceData(e[0],t)})))}_updateInstanceData(e,t){const i=this._instanceDataMap.get(t);i&&(e.vertices.length!==i._vertexArr.length&&(i._vertexArr=e.vertices,i._changedBuffers[0]=!0,i._changedBuffers[5]=!0),e.normals.length!==i._normalsArr.length&&(i._normalsArr=e.normals,i._changedBuffers[3]=!0),e.indices.length!==i._indicesArr.length&&(i._indicesArr=e.indices,i._changedBuffers[4]=!0),e.texCoords.length!==i._texCoordArr.length&&(i._texCoordArr=e.texCoords,i._changedBuffers[10]=!0),i._textureSrc=e.src,this._loadDataTagTexture(i),this._updateTag(i),this._instanceDataMapValues=Array.from(this._instanceDataMap.values()))}_addGeoObjectToArray(e){const t=e.tag;let i=this._instanceDataMap.get(t);i||(i=new Vi(this),this._instanceDataMap.set(t,i),this._instanceDataMapValues=Array.from(this._instanceDataMap.values()),i._vertexArr=e.vertices,i._normalsArr=e.normals,i._indicesArr=e.indices,i._texCoordArr=e.texCoords,i._textureSrc=e.object3d.src,this._loadDataTagTexture(i)),e._tagDataIndex=i.numInstances++,e._tagData=i,i.geoObjects.push(e);let n=3;i._visibleArr=He(i._visibleArr,Oi([],0,1,1,e.getVisibility()?1:0));let r,s=e._positionHigh.x,a=e._positionHigh.y,o=e._positionHigh.z;i._positionHighArr=He(i._positionHighArr,Oi([],0,n,n,s,a,o)),s=e._positionLow.x,a=e._positionLow.y,o=e._positionLow.z,i._positionLowArr=He(i._positionLowArr,Oi([],0,n,n,s,a,o)),s=e._entity._pickingColor.x/255,a=e._entity._pickingColor.y/255,o=e._entity._pickingColor.z/255,i._pickingColorArr=He(i._pickingColorArr,Oi([],0,n,n,s,a,o)),s=e._direction.x,a=e._direction.y,o=e._direction.z,i._directionArr=He(i._directionArr,Oi([],0,n,n,s,a,o)),n=4,s=e._color.x,a=e._color.y,o=e._color.z,r=e._color.w,i._rgbaArr=He(i._rgbaArr,Oi([],0,n,n,s,a,o,r)),n=2,s=e.getPitch(),a=e.getRoll(),i._pitchRollArr=He(i._pitchRollArr,Oi([],0,n,n,s,a)),n=3;let l=e.getScale();s=l.x,a=l.y,o=l.z,i._sizeArr=He(i._sizeArr,Oi([],0,n,n,s,a,o))}_displayPASS(){let e=this._planet.renderer,t=e.handler.programs.geo_object,i=t._program,n=i.uniforms,r=i.attributes,s=e.handler.gl,a=this._entityCollection;t.activate(),s.uniform3fv(n.uScaleByDistance,a.scaleByDistance),s.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),s.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniform3fv(n.lightsPositions,this._planet._lightsPositions),s.uniform3fv(n.lightsParamsv,this._planet._lightsParamsv),s.uniform1fv(n.lightsParamsf,this._planet._lightsParamsf);for(let t=0;t<this._instanceDataMapValues.length;t++){let a=this._instanceDataMapValues[t];s.bindBuffer(s.ARRAY_BUFFER,a._directionBuffer),s.vertexAttribPointer(r.aDirection,a._directionBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._sizeBuffer),s.vertexAttribPointer(r.aScale,a._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._pitchRollBuffer),s.vertexAttribPointer(r.aPitchRoll,a._pitchRollBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._rgbaBuffer),s.vertexAttribPointer(r.aColor,a._rgbaBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._visibleBuffer),s.vertexAttribPointer(r.aDispose,a._visibleBuffer.itemSize,s.FLOAT,!1,0,0),s.uniform1f(n.uUseTexture,a._texture?1:0),s.bindBuffer(s.ARRAY_BUFFER,a._positionHighBuffer),s.vertexAttribPointer(r.aPositionHigh,a._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._positionLowBuffer),s.vertexAttribPointer(r.aPositionLow,a._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._normalsBuffer),s.vertexAttribPointer(r.aVertexNormal,a._normalsBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._vertexBuffer),s.vertexAttribPointer(r.aVertexPosition,a._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,a._texture||e.handler.defaultTexture),s.uniform1i(n.uTexture,0),s.bindBuffer(s.ARRAY_BUFFER,a._texCoordBuffer),s.vertexAttribPointer(r.aTexCoord,a._texCoordBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,a._indicesBuffer),i.drawElementsInstanced(s.TRIANGLES,a._indicesBuffer.numItems,s.UNSIGNED_INT,0,a.numInstances)}}drawPicking(){this._geoObjects.length&&this.pickingEnabled&&(this.update(),this._pickingPASS())}_pickingPASS(){let e=this._planet.renderer,t=e.handler.programs.geo_object_picking,i=t._program,n=i.uniforms,r=i.attributes,s=e.handler.gl,a=this._entityCollection;t.activate(),s.uniform3fv(n.uScaleByDistance,a.scaleByDistance),s.uniform1f(n.pickingScale,a.pickingScale),s.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),s.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix());for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e];s.bindBuffer(s.ARRAY_BUFFER,t._directionBuffer),s.vertexAttribPointer(r.aDirection,t._directionBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._sizeBuffer),s.vertexAttribPointer(r.aScale,t._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._pitchRollBuffer),s.vertexAttribPointer(r.aPitchRoll,t._pitchRollBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._pickingColorBuffer),s.vertexAttribPointer(r.aPickingColor,t._pickingColorBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._positionHighBuffer),s.vertexAttribPointer(r.aPositionHigh,t._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._positionLowBuffer),s.vertexAttribPointer(r.aPositionLow,t._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._visibleBuffer),s.vertexAttribPointer(r.aDispose,t._visibleBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._vertexBuffer),s.vertexAttribPointer(r.aVertexPosition,t._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,t._indicesBuffer),i.drawElementsInstanced(s.TRIANGLES,t._indicesBuffer.numItems,s.UNSIGNED_INT,0,t.numInstances)}}async _loadDataTagTexture(e){if(this._planet&&e._textureSrc){const t=await Xe(e._textureSrc);e.createTexture(t)}}setDirectionArr(e,t,i){Oi(e._directionArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[5]=!0,this._updateTag(e)}setVisibility(e,t,i){Oi(e._visibleArr,t,1,1,i?1:0),e._changedBuffers[9]=!0,this._updateTag(e)}setPositionArr(e,t,i,n){Oi(e._positionHighArr,t,3,3,i.x,i.y,i.z),Oi(e._positionLowArr,t,3,3,n.x,n.y,n.z),e._changedBuffers[1]=!0,this._updateTag(e)}setRgbaArr(e,t,i){Oi(e._rgbaArr,t,4,4,i.x,i.y,i.z,i.w),e._changedBuffers[2]=!0,this._updateTag(e)}setPickingColorArr(e,t,i){Oi(e._pickingColorArr,t,3,3,i.x/255,i.y/255,i.z/255),e._changedBuffers[8]=!0,this._updateTag(e)}setPitchRollArr(e,t,i,n){Oi(e._pitchRollArr,t,2,2,i,n),e._changedBuffers[6]=!0,this._updateTag(e)}setScaleArr(e,t,i){Oi(e._sizeArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[7]=!0,this._updateTag(e)}_updateTag(e){e.isFree&&(e.isFree=!1,this._dataTagUpdateQueue.push(e))}update(){for(let e=0,t=this._dataTagUpdateQueue.length;e<t;e++)this._dataTagUpdateQueue[e].update();this._dataTagUpdateQueue=[]}_removeAll(){let e=this._geoObjects.length;for(;e--;){const t=this._geoObjects[e];t._tagDataIndex=-1,t._tagData=null,t._handlerIndex=-1,t._handler=null}this._geoObjects.length=0,this._geoObjects=[];for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].clear();this._instanceDataMap.clear(),this._instanceDataMapValues=[]}clear(){this._removeAll()}draw(){this._geoObjects.length&&(this.update(),this._displayPASS())}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._geoObjects.length,this._geoObjects.push(e),this._addGeoObjectToArray(e),e.updateDirection(),e._tagData.refresh(),this._updateTag(e._tagData),e.setObjectSrc(e._objectSrc))}remove(e){e._handler&&this.__id==e._handler.__id&&this._removeGeoObject(e)}_clearDataTagQueue(){this._dataTagUpdateQueue=[]}_removeGeoObject(e){let t=e._tagData,i=e.tag;t.numInstances--;let n=!1;0===t.numInstances&&(t.clear(),this._instanceDataMap.delete(i),this._instanceDataMapValues=[],this._clearDataTagQueue(),n=!0),this._geoObjects.splice(e._handlerIndex,1);for(let t=e._handlerIndex,i=this._geoObjects.length;t<i;t++){let e=this._geoObjects[t];e._handlerIndex=e._handlerIndex-1}let r=e._tagDataIndex;t.geoObjects.splice(r,1);for(let i=e._tagDataIndex,n=t.geoObjects.length;i<n;i++){let e=t.geoObjects[i];e._tagDataIndex=e._tagDataIndex-1}t._rgbaArr=Ue(t._rgbaArr,4*r,4),t._positionHighArr=Ue(t._positionHighArr,3*r,3),t._positionLowArr=Ue(t._positionLowArr,3*r,3),t._directionArr=Ue(t._directionArr,3*r,3),t._pickingColorArr=Ue(t._pickingColorArr,3*r,3),t._sizeArr=Ue(t._sizeArr,3*r,3),t._pitchRollArr=Ue(t._pitchRollArr,2*r,2),t._visibleArr=Ue(t._visibleArr,r,1),e._handlerIndex=-1,e._handler=null,e._tagDataIndex=-1,e._tagData=null,n||(t.refresh(),this._updateTag(t))}}Ui.__counter__=0;const Gi="\n#define EMPTY -1.0\n#define RTL 1.0",Wi="vec2 project(vec4 p) {\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }",ji="mat2 rotate2d(float angle) {\n return mat2(cos(angle), -sin(angle),\n sin(angle), cos(angle));\n }";const Yi=-1;class qi extends Ni{constructor(e,t=21){super(e),this._billboards=[],this._gliphParamBuffer=null,this._fontIndexBuffer=null,this._outlineBuffer=null,this._outlineColorBuffer=null,this._gliphParamArr=new Float32Array([]),this._fontIndexArr=new Float32Array([]),this._outlineArr=new Float32Array([]),this._outlineColorArr=new Float32Array([]),this._buffersUpdateCallbacks[8]=this.createFontIndexBuffer,this._buffersUpdateCallbacks[9]=this.createOutlineBuffer,this._buffersUpdateCallbacks[10]=this.createOutlineColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length),this._maxLetters=t}initProgram(){this._renderer&&this._renderer.handler&&this._renderer.handler.gl&&(this._renderer.handler.programs.label||("webgl2"===this._renderer.handler.gl.type?this._renderer.handler.addProgram(new zi("label",{uniforms:{viewport:"vec2",fontTextureArr:"sampler2darray",sdfParamsArr:"vec4",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",isOutlinePass:"int",depthOffset:"float"},attributes:{a_outline:"float",a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4",a_offset:"vec3",a_fontIndex:"float"},vertexShader:`#version 300 es\n \n ${Gi}\n \n in float a_outline;\n in vec4 a_gliphParam;\n in vec2 a_vertices;\n in vec4 a_texCoord;\n in vec3 a_positionsHigh;\n in vec3 a_positionsLow;\n in vec3 a_offset;\n in float a_size;\n in float a_rotation;\n in vec4 a_rgba;\n in float a_fontIndex;\n\n out vec2 v_uv;\n out vec4 v_rgba;\n flat out int v_fontIndex; \n out vec4 v_outlineColor;\n flat out float v_outline;\n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n \n ${Wi}\n\n ${ji}\n\n void main() {\n\n if(a_texCoord.w == EMPTY) {\n gl_Position = vec4(0.0);\n v_fontIndex = -1;\n return;\n }\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_outline = a_outline;\n\n v_fontIndex = int(a_fontIndex);\n v_uv = a_texCoord.xy;\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgba = a_rgba;\n \n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"#version 300 es\n\n uniform int isOutlinePass;\n \n precision highp float;\n\n const int MAX_SIZE = 11;\n\n // x - ATLAS_WIDTH = 512.0;\n // y - ATLAS_HEIGHT = 512.0;\n // z - ATLAS_GLYPH_SIZE = 32.0;\n // w - ATLAS_FIELD_RANGE = 8.0;\n\n uniform sampler2D fontTextureArr[MAX_SIZE];\n uniform vec4 sdfParamsArr[MAX_SIZE];\n\n flat in int v_fontIndex;\n in vec2 v_uv;\n in vec4 v_rgba; \n\n flat in float v_outline;\n\n in vec3 v_pickingColor;\n\n layout(location = 0) out vec4 outScreen;\n\n float median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n }\n\n float getDistance() {\n vec3 msdf;\n if(v_fontIndex == 0) {\n msdf = texture(fontTextureArr[0], v_uv).rgb;\n } else if(v_fontIndex == 1){\n msdf = texture(fontTextureArr[1], v_uv).rgb;\n } else if(v_fontIndex == 2){\n msdf = texture(fontTextureArr[2], v_uv).rgb;\n } else if(v_fontIndex == 3){\n msdf = texture(fontTextureArr[3], v_uv).rgb;\n } else if(v_fontIndex == 4){\n msdf = texture(fontTextureArr[4], v_uv).rgb;\n } else if(v_fontIndex == 5){\n msdf = texture(fontTextureArr[5], v_uv).rgb;\n } else if(v_fontIndex == 6){\n msdf = texture(fontTextureArr[6], v_uv).rgb;\n } else if(v_fontIndex == 7){\n msdf = texture(fontTextureArr[7], v_uv).rgb;\n } else if(v_fontIndex == 8){\n msdf = texture(fontTextureArr[8], v_uv).rgb;\n } else if(v_fontIndex == 9){\n msdf = texture(fontTextureArr[9], v_uv).rgb;\n } else if(v_fontIndex == 10){\n msdf = texture(fontTextureArr[10], v_uv).rgb;\n }\n return median(msdf.r, msdf.g, msdf.b);\n }\n \n void main () {\n \n if(v_fontIndex == -1) {\n return;\n }\n \n vec4 sdfParams = sdfParamsArr[v_fontIndex];\n float sd = getDistance(); \n vec2 dxdy = fwidth(v_uv) * sdfParams.xy;\n\n if(isOutlinePass == 0){ \n float dist = sd + min(0.001, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);\n if(opacity <= 0.1){\n discard;\n }\n outScreen = vec4(v_rgba.rgb, opacity * v_rgba.a);\n } else { \n float dist = sd + min(v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0); \n if(opacity <= 0.1){\n discard;\n }\n outScreen = vec4(v_rgba.rgb, opacity * v_rgba.a);\n //outScreen = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;\n } \n }"})):this._renderer.handler.addProgram(new zi("label",{uniforms:{viewport:"vec2",fontTextureArr:"sampler2darray",sdfParamsArr:"vec4",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",isOutlinePass:"int",depthOffset:"float"},attributes:{a_outline:"float",a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4",a_offset:"vec3",a_fontIndex:"float"},vertexShader:` \n ${Gi}\n \n attribute float a_outline;\n attribute vec4 a_gliphParam;\n attribute vec2 a_vertices;\n attribute vec4 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute float a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n attribute float a_fontIndex;\n\n varying float v_outline;\n varying vec2 v_uv;\n varying vec4 v_rgba;\n varying float v_fontIndex; \n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Wi}\n\n ${ji}\n\n void main() {\n\n if(a_texCoord.w == EMPTY) {\n gl_Position = vec4(0.0);\n v_fontIndex = -1.0;\n return;\n }\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_outline = a_outline;\n v_uv = vec2(a_texCoord.xy);\n v_rgba = a_rgba;\n v_fontIndex = a_fontIndex;\n \n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n \n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n \n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"#extension GL_OES_standard_derivatives : enable\n\n precision highp float;\n precision highp int;\n\n const int MAX_SIZE = 11;\n\n // x - ATLAS_WIDTH = 512.0;\n // y - ATLAS_HEIGHT = 512.0;\n // z - ATLAS_GLYPH_SIZE = 32.0;\n // w - ATLAS_FIELD_RANGE = 8.0;\n\n uniform sampler2D fontTextureArr[MAX_SIZE];\n uniform vec4 sdfParamsArr[MAX_SIZE];\n uniform int isOutlinePass;\n \n varying float v_outline;\n varying vec2 v_uv;\n varying vec4 v_rgba; \n varying float v_fontIndex;\n \n float fontIndex;\n\n float median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n }\n\n float getDistance() {\n vec3 msdf;\n if(fontIndex >= 0.0 && fontIndex < 1.0) {\n msdf = texture2D(fontTextureArr[0], v_uv).rgb;\n } else if(fontIndex >= 1.0 && fontIndex < 2.0){\n msdf = texture2D(fontTextureArr[1], v_uv).rgb;\n } else if(fontIndex >= 2.0 && fontIndex < 3.0){\n msdf = texture2D(fontTextureArr[2], v_uv).rgb;\n } else if(fontIndex >= 3.0 && fontIndex < 4.0){\n msdf = texture2D(fontTextureArr[3], v_uv).rgb;\n } else if(fontIndex >= 4.0 && fontIndex < 5.0){\n msdf = texture2D(fontTextureArr[4], v_uv).rgb;\n } else if(fontIndex >= 5.0 && fontIndex < 6.0){\n msdf = texture2D(fontTextureArr[5], v_uv).rgb;\n } else if(fontIndex >= 6.0 && fontIndex < 7.0){\n msdf = texture2D(fontTextureArr[6], v_uv).rgb;\n } else if(fontIndex >= 7.0 && fontIndex < 8.0){\n msdf = texture2D(fontTextureArr[7], v_uv).rgb;\n } else if(fontIndex >= 8.0 && fontIndex < 9.0){\n msdf = texture2D(fontTextureArr[8], v_uv).rgb;\n } else if(fontIndex >= 9.0 && fontIndex < 10.0){\n msdf = texture2D(fontTextureArr[9], v_uv).rgb;\n } else if(fontIndex >= 10.0 && fontIndex < 11.0){\n msdf = texture2D(fontTextureArr[10], v_uv).rgb;\n }\n return median(msdf.r, msdf.g, msdf.b);\n }\n\n\n vec4 getSDFParams() {\n if(fontIndex >= 0.0 && fontIndex < 1.0) {\n return sdfParamsArr[0];\n } else if(fontIndex >= 1.0 && fontIndex < 2.0){\n return sdfParamsArr[1];\n } else if(fontIndex >= 2.0 && fontIndex < 3.0){\n return sdfParamsArr[2];\n } else if(fontIndex >= 3.0 && fontIndex < 4.0){\n return sdfParamsArr[3];\n } else if(fontIndex >= 4.0 && fontIndex < 5.0){\n return sdfParamsArr[4];\n } else if(fontIndex >= 5.0 && fontIndex < 6.0){\n return sdfParamsArr[5];\n } else if(fontIndex >= 6.0 && fontIndex < 7.0){\n return sdfParamsArr[6];\n } else if(fontIndex >= 7.0 && fontIndex < 8.0){\n return sdfParamsArr[7];\n } else if(fontIndex >= 8.0 && fontIndex < 9.0){\n return sdfParamsArr[8];\n } else if(fontIndex >= 9.0 && fontIndex < 10.0){\n return sdfParamsArr[9];\n } else if(fontIndex >= 10.0 && fontIndex < 11.0){\n return sdfParamsArr[10];\n }\n }\n \n void main () {\n\n fontIndex = v_fontIndex + 0.1;\n \n if(v_fontIndex < 0.0){\n return;\n }\n \n vec4 sdfParams = getSDFParams();\n float sd = getDistance(); \n vec2 dxdy = fwidth(v_uv) * sdfParams.xy;\n float dist = sd + min(0.001, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);\n\n if(isOutlinePass == 0){ \n //gl_FragColor = vec4(v_rgba.rgb, opacity * v_rgba.a);\n } else { \n float strokeDist = sd + min(v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float strokeAlpha = v_rgba.a * clamp(strokeDist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0); \n if(strokeAlpha < 0.1){\n discard;\n }\n //gl_FragColor = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;\n }\n }"}))),this._renderer.handler.programs.labelPicking||this._renderer.handler.addProgram(new zi("labelPicking",{uniforms:{viewport:"vec2",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4"},vertexShader:`\n \n ${Gi}\n \n attribute vec4 a_gliphParam;\n attribute vec2 a_vertices;\n attribute vec4 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute float a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec4 v_rgba;\n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Wi}\n\n ${ji}\n\n void main() {\n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n v_rgba = a_rgba;\n \n if(a_texCoord.w == EMPTY) {\n v_rgba.a = 0.0;\n gl_Position = vec4(0.0);\n return;\n }\n\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n \n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n\n varying vec4 v_rgba;\n\n varying vec3 v_pickingColor;\n\n void main () {\n\n vec4 color = v_rgba;\n if (color.a < 0.05) {\n return;\n }\n\n gl_FragColor = vec4(v_rgba.rgb, v_rgba.a);\n }"})))}get labels(){return this._billboards}add(e){e._handler||(e._handler=this,this.assignFontAtlas(e),this.refresh())}updateFonts(){let e=[...this._billboards];this._billboards=[];for(let t=0;t<e.length;t++)this.assignFontAtlas(e[t])}_addLabelToArrays(e){this._renderer&&this._renderer.labelWorker.make({handler:this,label:e})}assignFontAtlas(e){this._entityCollection&&this._renderer?(e.assignFontAtlas(this._renderer.fontAtlas),this._addLabelToArrays(e)):this._billboards.push(e)}workerCallback(e,t){t._lockId!==ti&&t._handler&&this.isEqual(t._handler)&&(t._isReady=!0,t._lockId=ti,t._handlerIndex=this._billboards.length,this._billboards.push(t),this._vertexArr=Ne(this._vertexArr,e.vertexArr),this._texCoordArr=Ne(this._texCoordArr,e.texCoordArr),this._gliphParamArr=Ne(this._gliphParamArr,e.gliphParamArr),this._positionHighArr=Ne(this._positionHighArr,e.positionHighArr),this._positionLowArr=Ne(this._positionLowArr,e.positionLowArr),this._sizeArr=Ne(this._sizeArr,e.sizeArr),this._offsetArr=Ne(this._offsetArr,e.offsetArr),this._rgbaArr=Ne(this._rgbaArr,e.rgbaArr),this._rotationArr=Ne(this._rotationArr,e.rotationArr),this._fontIndexArr=Ne(this._fontIndexArr,e.fontIndexArr),this._outlineArr=Ne(this._outlineArr,e.outlineArr),this._outlineColorArr=Ne(this._outlineColorArr,e.outlineColorArr),this._pickingColorArr=Ne(this._pickingColorArr,e.pickingColorArr),t.update(),this.refresh())}clear(){this._texCoordArr=null,this._gliphParamArr=null,this._vertexArr=null,this._positionHighArr=null,this._positionLowArr=null,this._sizeArr=null,this._offsetArr=null,this._rgbaArr=null,this._rotationArr=null,this._fontIndexArr=null,this._outlineArr=null,this._outlineColorArr=null,this._texCoordArr=new Float32Array([]),this._gliphParamArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._fontIndexArr=new Float32Array([]),this._outlineArr=new Float32Array([]),this._outlineColorArr=new Float32Array([]),this._removeBillboards(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e.deleteBuffer(this._gliphParamBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._fontIndexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._outlineBuffer),e.deleteBuffer(this._outlineColorBuffer),e.deleteBuffer(this._positionHighBuffer),e.deleteBuffer(this._positionLowBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._offsetBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._rotationBuffer),e.deleteBuffer(this._vertexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._pickingColorBuffer),this._gliphParamBuffer=null,this._sizeBuffer=null,this._fontIndexBuffer=null,this._texCoordBuffer=null,this._outlineBuffer=null,this._outlineColorBuffer=null,this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._vertexBuffer=null,this._texCoordBuffer=null,this._pickingColorBuffer=null}}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.label.activate();let i=t.programs.label._program,n=i.attributes,r=i.uniforms,s=t.gl,a=this._entityCollection;s.disable(s.CULL_FACE),s.uniform1iv(r.fontTextureArr,e.fontAtlas.samplerArr),s.uniform4fv(r.sdfParamsArr,e.fontAtlas.sdfParamsArr),s.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),s.uniform3fv(r.scaleByDistance,a.scaleByDistance),s.uniform1f(r.opacity,a._fadingOpacity),s.uniform1f(r.planetRadius,a.renderNode._planetRadius2||0),s.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),s.bindBuffer(s.ARRAY_BUFFER,this._texCoordBuffer),s.vertexAttribPointer(n.a_texCoord,this._texCoordBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._gliphParamBuffer),s.vertexAttribPointer(n.a_gliphParam,this._gliphParamBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._vertexBuffer),s.vertexAttribPointer(n.a_vertices,this._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionHighBuffer),s.vertexAttribPointer(n.a_positionsHigh,this._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionLowBuffer),s.vertexAttribPointer(n.a_positionsLow,this._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._sizeBuffer),s.vertexAttribPointer(n.a_size,this._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._rotationBuffer),s.vertexAttribPointer(n.a_rotation,this._rotationBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._offsetBuffer),s.vertexAttribPointer(n.a_offset,this._offsetBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._fontIndexBuffer),s.vertexAttribPointer(n.a_fontIndex,this._fontIndexBuffer.itemSize,s.FLOAT,!1,0,0),s.uniform1i(r.isOutlinePass,1),s.uniform1f(r.depthOffset,a.polygonOffsetUnits),s.bindBuffer(s.ARRAY_BUFFER,this._outlineColorBuffer),s.vertexAttribPointer(n.a_rgba,this._outlineColorBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._outlineBuffer),s.vertexAttribPointer(n.a_outline,this._outlineBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.depthFunc(s.EQUAL),s.uniform1i(r.isOutlinePass,0),s.uniform1f(r.depthOffset,a.polygonOffsetUnits),s.bindBuffer(s.ARRAY_BUFFER,this._rgbaBuffer),s.vertexAttribPointer(n.a_rgba,this._rgbaBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.depthFunc(s.LESS),s.enable(s.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.labelPicking.activate();let i=t.programs.labelPicking._program,n=i.attributes,r=i.uniforms,s=t.gl,a=this._entityCollection,o=a.renderNode;s.disable(s.CULL_FACE),s.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),s.uniform3fv(r.scaleByDistance,a.scaleByDistance),s.uniform1f(r.opacity,a._fadingOpacity),s.uniform1f(r.planetRadius,o._planetRadius2||0),s.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),s.bindBuffer(s.ARRAY_BUFFER,this._texCoordBuffer),s.vertexAttribPointer(n.a_texCoord,this._texCoordBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._gliphParamBuffer),s.vertexAttribPointer(n.a_gliphParam,this._gliphParamBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._vertexBuffer),s.vertexAttribPointer(n.a_vertices,this._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionHighBuffer),s.vertexAttribPointer(n.a_positionsHigh,this._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionLowBuffer),s.vertexAttribPointer(n.a_positionsLow,this._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._sizeBuffer),s.vertexAttribPointer(n.a_size,this._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._rotationBuffer),s.vertexAttribPointer(n.a_rotation,this._rotationBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._offsetBuffer),s.vertexAttribPointer(n.a_offset,this._offsetBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._pickingColorBuffer),s.vertexAttribPointer(n.a_rgba,this._pickingColorBuffer.itemSize,s.FLOAT,!1,0,0),s.uniform1f(r.depthOffset,a.polygonOffsetUnits),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.enable(s.CULL_FACE)}_removeBillboard(e){let t=e._handlerIndex;this._billboards.splice(t,1);let i=24*this._maxLetters,n=t*i;this._rgbaArr=Ge(this._rgbaArr,n,i),this._outlineColorArr=Ge(this._outlineColorArr,n,i),this._texCoordArr=Ge(this._texCoordArr,n,i),this._gliphParamArr=Ge(this._gliphParamArr,n,i),i=18*this._maxLetters,n=t*i,this._positionHighArr=Ge(this._positionHighArr,n,i),this._positionLowArr=Ge(this._positionLowArr,n,i),this._offsetArr=Ge(this._offsetArr,n,i),this._pickingColorArr=Ge(this._pickingColorArr,n,i),i=12*this._maxLetters,n=t*i,this._vertexArr=Ge(this._vertexArr,n,i),i=6*this._maxLetters,n=t*i,this._sizeArr=Ge(this._sizeArr,n,i),this._rotationArr=Ge(this._rotationArr,n,i),this._fontIndexArr=Ge(this._fontIndexArr,n,i),this._outlineArr=Ge(this._outlineArr,n,i),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1}setText(e,t,i,n,r=!1){t=t.normalize("NFKC");let s=this._renderer.fontAtlas.atlasesArr[i];if(!s)return;let a=24*e*this._maxLetters,o=this._texCoordArr,l=this._gliphParamArr,h=0,c=Math.min(this._maxLetters,t.length),d=0;r&&(d=1);let _=0,u=s.kernings;for(h=0;h<c;h++){let e=a+24*h,i=t[h],n=s.get(i.charCodeAt(0))||s.get(" ".charCodeAt(0));if(!n)continue;let r=n.texCoords,c=n.metrics;o[e]=r[0],o[e+1]=r[1],o[e+2]=_,o[e+3]=d,o[e+4]=r[2],o[e+5]=r[3],o[e+6]=_,o[e+7]=d,o[e+8]=r[4],o[e+9]=r[5],o[e+10]=_,o[e+11]=d,o[e+12]=r[6],o[e+13]=r[7],o[e+14]=_,o[e+15]=d,o[e+16]=r[8],o[e+17]=r[9],o[e+18]=_,o[e+19]=d,o[e+20]=r[10],o[e+21]=r[11],o[e+22]=_,o[e+23]=d,l[e]=c.nWidth,l[e+1]=c.nHeight,l[e+2]=c.nXOffset,l[e+3]=c.nYOffset,l[e+4]=c.nWidth,l[e+5]=c.nHeight,l[e+6]=c.nXOffset,l[e+7]=c.nYOffset,l[e+8]=c.nWidth,l[e+9]=c.nHeight,l[e+10]=c.nXOffset,l[e+11]=c.nYOffset,l[e+12]=c.nWidth,l[e+13]=c.nHeight,l[e+14]=c.nXOffset,l[e+15]=c.nYOffset,l[e+16]=c.nWidth,l[e+17]=c.nHeight,l[e+18]=c.nXOffset,l[e+19]=c.nYOffset,l[e+20]=c.nWidth,l[e+21]=c.nHeight,l[e+22]=c.nXOffset,l[e+23]=c.nYOffset;let f=u[i.charCodeAt(0)];if(f&&t[h+1]){let e=f[t[h+1].charCodeAt(0)];_+=e?c.nAdvance+e:c.nAdvance}else _+=c.nAdvance}if(n===mi.CENTER)for(_*=-.5,h=0;h<c;h++){let e=a+24*h;o[e+2]+=_,o[e+6]+=_,o[e+10]+=_,o[e+14]+=_,o[e+18]+=_,o[e+22]+=_}for(;h<this._maxLetters;h++){let e=a+24*h;o[e+3]=Yi,o[e+7]=Yi,o[e+11]=Yi,o[e+15]=Yi,o[e+19]=Yi,o[e+23]=Yi}this._changedBuffers[6]=!0}setPositionArr(e,t,i){let n=18*e*this._maxLetters,r=this._positionHighArr,s=t.x,a=t.y,o=t.z,l=this._positionLowArr,h=i.x,c=i.y,d=i.z;for(let e=0;e<this._maxLetters;e++){let t=n+18*e;r[t]=s,r[t+1]=a,r[t+2]=o,r[t+3]=s,r[t+4]=a,r[t+5]=o,r[t+6]=s,r[t+7]=a,r[t+8]=o,r[t+9]=s,r[t+10]=a,r[t+11]=o,r[t+12]=s,r[t+13]=a,r[t+14]=o,r[t+15]=s,r[t+16]=a,r[t+17]=o,l[t]=h,l[t+1]=c,l[t+2]=d,l[t+3]=h,l[t+4]=c,l[t+5]=d,l[t+6]=h,l[t+7]=c,l[t+8]=d,l[t+9]=h,l[t+10]=c,l[t+11]=d,l[t+12]=h,l[t+13]=c,l[t+14]=d,l[t+15]=h,l[t+16]=c,l[t+17]=d}this._changedBuffers[1]=!0}setPickingColorArr(e,t){let i=18*e*this._maxLetters,n=this._pickingColorArr,r=t.x/255,s=t.y/255,a=t.z/255;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;n[t]=r,n[t+1]=s,n[t+2]=a,n[t+3]=r,n[t+4]=s,n[t+5]=a,n[t+6]=r,n[t+7]=s,n[t+8]=a,n[t+9]=r,n[t+10]=s,n[t+11]=a,n[t+12]=r,n[t+13]=s,n[t+14]=a,n[t+15]=r,n[t+16]=s,n[t+17]=a}this._changedBuffers[0]=!0}setSizeArr(e,t){let i=6*e*this._maxLetters,n=this._sizeArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;n[r]=t,n[r+1]=t,n[r+2]=t,n[r+3]=t,n[r+4]=t,n[r+5]=t}this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e*this._maxLetters,n=this._offsetArr,r=t.x,s=t.y,a=t.z;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;n[t]=r,n[t+1]=s,n[t+2]=a,n[t+3]=r,n[t+4]=s,n[t+5]=a,n[t+6]=r,n[t+7]=s,n[t+8]=a,n[t+9]=r,n[t+10]=s,n[t+11]=a,n[t+12]=r,n[t+13]=s,n[t+14]=a,n[t+15]=r,n[t+16]=s,n[t+17]=a}this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e*this._maxLetters,n=this._rgbaArr,r=t.x,s=t.y,a=t.z,o=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;n[t]=r,n[t+1]=s,n[t+2]=a,n[t+3]=o,n[t+4]=r,n[t+5]=s,n[t+6]=a,n[t+7]=o,n[t+8]=r,n[t+9]=s,n[t+10]=a,n[t+11]=o,n[t+12]=r,n[t+13]=s,n[t+14]=a,n[t+15]=o,n[t+16]=r,n[t+17]=s,n[t+18]=a,n[t+19]=o,n[t+20]=r,n[t+21]=s,n[t+22]=a,n[t+23]=o}this._changedBuffers[4]=!0}setOutlineColorArr(e,t){let i=24*e*this._maxLetters,n=this._outlineColorArr,r=t.x,s=t.y,a=t.z,o=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;n[t]=r,n[t+1]=s,n[t+2]=a,n[t+3]=o,n[t+4]=r,n[t+5]=s,n[t+6]=a,n[t+7]=o,n[t+8]=r,n[t+9]=s,n[t+10]=a,n[t+11]=o,n[t+12]=r,n[t+13]=s,n[t+14]=a,n[t+15]=o,n[t+16]=r,n[t+17]=s,n[t+18]=a,n[t+19]=o,n[t+20]=r,n[t+21]=s,n[t+22]=a,n[t+23]=o}this._changedBuffers[10]=!0}setOutlineArr(e,t){let i=6*e*this._maxLetters,n=this._outlineArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;n[r]=t,n[r+1]=t,n[r+2]=t,n[r+3]=t,n[r+4]=t,n[r+5]=t}this._changedBuffers[9]=!0}setRotationArr(e,t){let i=6*e*this._maxLetters,n=this._rotationArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;n[r]=t,n[r+1]=t,n[r+2]=t,n[r+3]=t,n[r+4]=t,n[r+5]=t}this._changedBuffers[5]=!0}setVisibility(e,t){let i;i=t?[0,0,0,-1,1,-1,1,-1,1,0,0,0]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e*this._maxLetters,n=this._vertexArr;for(let e=0;e<this._maxLetters;e++){let r=i+12*e;n[r]=t[0],n[r+1]=t[1],n[r+2]=t[2],n[r+3]=t[3],n[r+4]=t[4],n[r+5]=t[5],n[r+6]=t[6],n[r+7]=t[7],n[r+8]=t[8],n[r+9]=t[9],n[r+10]=t[10],n[r+11]=t[11]}this._changedBuffers[7]=!0}setFontIndexArr(e,t){let i=6*e*this._maxLetters,n=this._fontIndexArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;n[r]=t,n[r+1]=t,n[r+2]=t,n[r+3]=t,n[r+4]=t,n[r+5]=t}this._changedBuffers[8]=!0}createSizeBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createArrayBuffer(this._sizeArr,1,this._sizeArr.length)}createFontIndexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._fontIndexBuffer),this._fontIndexBuffer=e.createArrayBuffer(this._fontIndexArr,1,this._fontIndexArr.length)}createTexCoordBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,4,this._texCoordArr.length/4),e.gl.deleteBuffer(this._gliphParamBuffer),this._gliphParamBuffer=e.createArrayBuffer(this._gliphParamArr,4,this._gliphParamArr.length/4)}createOutlineBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._outlineBuffer),this._outlineBuffer=e.createArrayBuffer(this._outlineArr,1,this._outlineArr.length)}createOutlineColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._outlineColorBuffer),this._outlineColorBuffer=e.createArrayBuffer(this._outlineColorArr,4,this._outlineColorArr.length/4)}setMaxLetters(e){this._maxLetters=e}}class Xi{constructor(e){this.pickingEnabled=!0,this.__id=Xi.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._pointClouds=[]}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.pointCloud||this._renderer.handler.addProgram(new zi("pointCloud",{uniforms:{projectionViewMatrix:"mat4",opacity:"float",pointSize:"float"},attributes:{coordinates:"vec3",colors:"vec3"},vertexShader:"attribute vec3 coordinates;\n attribute vec4 colors;\n uniform mat4 projectionViewMatrix;\n uniform float opacity;\n uniform float pointSize;\n varying vec4 color;\n void main() {\n color = colors;\n color.a *= opacity;\n gl_Position = projectionViewMatrix * vec4(coordinates, 1.0);\n gl_PointSize = pointSize;\n }",fragmentShader:"precision highp float;\n varying vec4 color;\n void main(void) {\n gl_FragColor = color;\n }"})))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._pointClouds.length;t++)this._pointClouds[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._pointClouds.length,this._pointClouds.push(e),this._entityCollection&&this._entityCollection.renderNode&&e.setRenderNode(this._entityCollection.renderNode))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._pointClouds.splice(t,1),this._reindexPointCloudArray(t))}_reindexPointCloudArray(e){let t=this._pointClouds;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e].drawPicking()}}clear(){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e]._deleteBuffers(),this._pointClouds[e]._handler=null,this._pointClouds[e]._handlerIndex=-1;this._pointClouds.length=0,this._pointClouds=[]}}Xi.__counter__=0;class Zi{constructor(e){this.__id=Zi.__counter__++,this._entityCollection=e,this._renderer=null,this._polylines=[],this.pickingEnabled=!0}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.polyline_screen||this._renderer.handler.addProgram(new zi("polyline_screen",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",uFloatParams:"vec2",thickness:"float",opacity:"float",depthOffset:"float"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float",color:"vec4"},vertexShader:"precision highp float;\n\n attribute vec3 prevHigh;\n attribute vec3 currentHigh;\n attribute vec3 nextHigh;\n\n attribute vec3 prevLow;\n attribute vec3 currentLow;\n attribute vec3 nextLow;\n\n attribute float order;\n\n attribute vec4 color;\n\n uniform float thickness;\n uniform mat4 proj;\n uniform mat4 view;\n uniform vec2 viewport;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float opacity;\n uniform float depthOffset;\n\n varying vec4 vColor;\n varying vec3 vPos;\n varying vec3 uCamPos;\n\n const float NEAR = -1.0;\n\n vec2 getIntersection(vec2 start1, vec2 end1, vec2 start2, vec2 end2){\n vec2 dir = end2 - start2;\n vec2 perp = vec2(-dir.y, dir.x);\n float d2 = dot(perp, start2);\n float seg = dot(perp, start1) - d2;\n float prl = seg - dot(perp, end1) + d2;\n if(prl > -1.0 && prl < 1.0){\n return start1;\n }\n float u = seg / prl;\n return start1 + u * (end1 - start1);\n }\n\n vec2 project(vec4 p){\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }\n\n void main(){\n\n uCamPos = eyePositionHigh + eyePositionLow;\n\n vColor = vec4(color.rgb, color.a * opacity);\n\n vec3 current = currentHigh + currentLow;\n\n vPos = current;\n\n mat4 viewMatrixRTE = view;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff, lowDiff;\n\n highDiff = currentHigh - eyePositionHigh;\n lowDiff = currentLow - eyePositionLow;\n vec4 vCurrent = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = prevHigh - eyePositionHigh;\n lowDiff = prevLow - eyePositionLow;\n vec4 vPrev = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = nextHigh - eyePositionHigh;\n lowDiff = nextLow - eyePositionLow;\n vec4 vNext = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n /*Clip near plane, the point behind view plane*/\n if(vCurrent.z > NEAR) {\n if(vPrev.z < NEAR && abs(order) == 1.0){\n vCurrent = vPrev + (vCurrent - vPrev) * (NEAR - vPrev.z) / (vCurrent.z - vPrev.z);\n } else if(vNext.z < NEAR && abs(order) == 2.0){\n vCurrent = vNext + (vCurrent - vNext) * (NEAR - vNext.z) / (vCurrent.z - vNext.z);\n }\n }\n\n vec4 dCurrent = proj * vCurrent;\n vec2 _next = project(proj * vNext);\n vec2 _prev = project(proj * vPrev);\n vec2 _current = project(dCurrent);\n\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n\n vec2 sNext = _next,\n sCurrent = _current,\n sPrev = _prev;\n\n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n\n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n\n float d = thickness * sign(order);\n\n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n m = getIntersection( sCurrent + normalPrev * d, sPrev + normalPrev * d,\n sCurrent + normalNext * d, sNext + normalNext * d );\n\n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n\n gl_Position = vec4((2.0 * m / viewport - 1.0) * dCurrent.w, dCurrent.z + depthOffset, dCurrent.w);\n }",fragmentShader:"precision highp float;\n uniform vec2 uFloatParams;\n varying vec3 uCamPos;\n varying vec4 vColor;\n varying vec3 vPos;\n void main() {\n vec3 look = vPos - uCamPos;\n float lookLength = length(look);\n float a = vColor.a * step(lookLength, sqrt(dot(uCamPos,uCamPos) - uFloatParams[0]) + sqrt(dot(vPos,vPos) - uFloatParams[0]));\n gl_FragColor = vec4(vColor.rgb, a);\n }"})),this._renderer.handler.programs.polyline_picking||this._renderer.handler.addProgram(new zi("polyline_picking",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",uFloatParams:"vec2",color:"vec4",thickness:"float",depthOffset:"float"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float"},vertexShader:"precision highp float;\n \n attribute vec3 prevHigh;\n attribute vec3 currentHigh;\n attribute vec3 nextHigh;\n \n attribute vec3 prevLow;\n attribute vec3 currentLow;\n attribute vec3 nextLow;\n\n attribute float order;\n\n uniform float thickness;\n uniform vec4 color;\n uniform mat4 proj;\n uniform mat4 view;\n uniform vec2 viewport;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float depthOffset;\n\n varying vec4 vColor;\n varying vec3 vPos;\n varying vec3 uCamPos;\n \n \n const float NEAR = -1.0;\n \n vec2 getIntersection(vec2 start1, vec2 end1, vec2 start2, vec2 end2){\n vec2 dir = end2 - start2;\n vec2 perp = vec2(-dir.y, dir.x);\n float d2 = dot(perp, start2);\n float seg = dot(perp, start1) - d2;\n float prl = seg - dot(perp, end1) + d2;\n if(prl > -1.0 && prl < 1.0){\n return start1;\n }\n float u = seg / prl;\n return start1 + u * (end1 - start1);\n }\n \n vec2 project(vec4 p){\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }\n \n void main(){\n\n uCamPos = eyePositionHigh + eyePositionLow;\n\n vColor = color;\n\n vec3 current = currentHigh + currentLow;\n\n vPos = current; \n\n vec3 highDiff, lowDiff;\n\n mat4 viewMatrixRTE = view;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n highDiff = currentHigh - eyePositionHigh;\n lowDiff = currentLow - eyePositionLow;\n vec4 vCurrent = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = prevHigh - eyePositionHigh;\n lowDiff = prevLow - eyePositionLow; \n vec4 vPrev = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = nextHigh - eyePositionHigh;\n lowDiff = nextLow - eyePositionLow; \n vec4 vNext = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n /*Clip near plane*/\n if(vCurrent.z > NEAR) {\n if(vPrev.z < NEAR && abs(order) == 1.0){\n vCurrent = vPrev + (vCurrent - vPrev) * (NEAR - vPrev.z) / (vCurrent.z - vPrev.z);\n } else if(vNext.z < NEAR && abs(order) == 2.0){\n vCurrent = vNext + (vCurrent - vNext) * (NEAR - vNext.z) / (vCurrent.z - vNext.z);\n }\n }\n \n vec4 dCurrent = proj * vCurrent;\n vec2 _next = project(proj * vNext);\n vec2 _prev = project(proj * vPrev);\n vec2 _current = project(dCurrent);\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n \n vec2 sNext = _next,\n sCurrent = _current,\n sPrev = _prev;\n\n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n \n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n \n float d = thickness * sign(order);\n \n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n m = getIntersection( sCurrent + normalPrev * d, sPrev + normalPrev * d,\n sCurrent + normalNext * d, sNext + normalNext * d );\n \n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }\n else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n gl_Position = vec4((2.0 * m / viewport - 1.0) * dCurrent.w, dCurrent.z + depthOffset, dCurrent.w);\n }",fragmentShader:"precision highp float;\n uniform vec2 uFloatParams;\n varying vec3 uCamPos;\n varying vec4 vColor;\n varying vec3 vPos;\n void main() {\n vec3 look = vPos - uCamPos;\n float lookLength = length(look);\n float a = vColor.a * step(lookLength, sqrt(dot(uCamPos,uCamPos) - uFloatParams[0]) + sqrt(dot(vPos,vPos) - uFloatParams[0])); \n gl_FragColor = vec4(vColor.rgb, a);\n }"})))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._polylines.length;t++)this._polylines[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._polylines.length,this._polylines.push(e),this._entityCollection&&this._entityCollection.renderNode&&e.setRenderNode(this._entityCollection.renderNode))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._polylines.splice(t,1),this.reindexPolylineArray(t))}reindexPolylineArray(e){let t=this._polylines;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){let e=this._polylines.length;for(;e--;)this._polylines[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._polylines.length;for(;e--;)this._polylines[e].drawPicking()}}clear(){let e=this._polylines.length;for(;e--;)this._polylines[e]._deleteBuffers(),this._polylines[e]._handler=null,this._polylines[e]._handlerIndex=-1;this._polylines.length=0,this._polylines=[]}}Zi.__counter__=0;class $i{constructor(e){this.__id=$i.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._rays=[],this._vertexBuffer=null,this._startPositionHighBuffer=null,this._startPositionLowBuffer=null,this._endPositionHighBuffer=null,this._endPositionLowBuffer=null,this._thicknessBuffer=null,this._rgbaBuffer=null,this._pickingColorBuffer=null,this._vertexArr=[],this._startPositionHighArr=[],this._startPositionLowArr=[],this._endPositionHighArr=[],this._endPositionLowArr=[],this._thicknessArr=[],this._rgbaArr=[],this._pickingColorArr=[],this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[5]=this.createVertexBuffer,this._buffersUpdateCallbacks[1]=this.createStartPositionBuffer,this._buffersUpdateCallbacks[2]=this.createEndPositionBuffer,this._buffersUpdateCallbacks[4]=this.createThicknessBuffer,this._buffersUpdateCallbacks[3]=this.createRgbaBuffer,this._buffersUpdateCallbacks[0]=this.createPickingColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}static concArr(e,t){for(let i=0;i<t.length;i++)e.push(t[i])}initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.rayScreen||this._renderer.handler.addProgram(new zi("rayScreen",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",resolution:"float",uOpacity:"float"},attributes:{a_vertices:"vec2",a_startPosHigh:"vec3",a_startPosLow:"vec3",a_endPosHigh:"vec3",a_endPosLow:"vec3",a_thickness:"float",a_rgba:"vec4"},vertexShader:"precision highp float;\n\n attribute vec4 a_rgba;\n attribute vec3 a_startPosHigh;\n attribute vec3 a_startPosLow;\n attribute vec3 a_endPosHigh;\n attribute vec3 a_endPosLow;\n attribute vec2 a_vertices;\n attribute float a_thickness;\n\n varying vec4 v_rgba;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float resolution;\n uniform float uOpacity;\n\n void main() {\n\n v_rgba = vec4(a_rgba.rgb, a_rgba.a * uOpacity);\n\n vec3 v = (a_endPosHigh - a_startPosHigh) + (a_endPosLow - a_startPosLow);\n\n vec3 look = (a_startPosHigh - eyePositionHigh) + (a_startPosLow - eyePositionLow) + v * a_vertices.y;\n vec3 up = normalize(normalize(v));\n vec3 right = normalize(cross(look,up));\n \n float dist = dot(look, vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]));\n float focalSize = 2.0 * dist * resolution;\n vec3 vert = right * a_thickness * focalSize * a_vertices.x;\n\n vec3 highDiff;\n if(a_vertices.y == 0.0){\n highDiff = a_startPosHigh - eyePositionHigh;\n vert += a_startPosLow - eyePositionLow;\n }else{\n highDiff = a_endPosHigh - eyePositionHigh;\n vert += a_endPosLow - eyePositionLow;\n }\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n // Hack for iMac M1, looks like it doesnt \n // work correctly with zeroes in highDiff\n // if(length(highDiff) < 1.0){\n // highDiff = vec3(0.0);\n // }\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + vert, 1.0);\n }",fragmentShader:"precision highp float;\n varying vec4 v_rgba;\n void main () {\n gl_FragColor = v_rgba;\n }"})))}setRenderer(e){this._renderer=e,this.initProgram()}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_removeRays(){let e=this._rays.length;for(;e--;){let t=this._rays[e];t._handlerIndex=-1,t._handler=null}this._rays.length=0,this._rays=[]}clear(){this._vertexArr=null,this._startPositionHighArr=null,this._startPositionLowArr=null,this._endPositionHighArr=null,this._endPositionLowArr=null,this._thicknessArr=null,this._rgbaArr=null,this._vertexArr=new Float32Array([]),this._startPositionHighArr=new Float32Array([]),this._startPositionLowArr=new Float32Array([]),this._endPositionHighArr=new Float32Array([]),this._endPositionLowArr=new Float32Array([]),this._thicknessArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._removeRays(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e&&(e.deleteBuffer(this._startPositionHighBuffer),e.deleteBuffer(this._startPositionLowBuffer),e.deleteBuffer(this._endPositionHighBuffer),e.deleteBuffer(this._endPositionLowBuffer),e.deleteBuffer(this._thicknessBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._vertexBuffer)),this._startPositionHighBuffer=null,this._startPositionLowBuffer=null,this._endPositionHighBuffer=null,this._endPositionLowBuffer=null,this._thicknessBuffer=null,this._rgbaBuffer=null,this._vertexBuffer=null}}update(){if(this._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}add(e){-1==e._handlerIndex&&(e._handler=this,e._handlerIndex=this._rays.length,this._rays.push(e),this._addRayToArrays(e),this.refresh())}_addRayToArrays(e){e.getVisibility()?this._vertexArr=He(this._vertexArr,[-.5,1,-.5,0,.5,0,.5,0,.5,1,-.5,1]):this._vertexArr=He(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t=e._startPositionHigh.x,i=e._startPositionHigh.y,n=e._startPositionHigh.z;this._startPositionHighArr=He(this._startPositionHighArr,[t,i,n,t,i,n,t,i,n,t,i,n,t,i,n,t,i,n]),t=e._startPositionLow.x,i=e._startPositionLow.y,n=e._startPositionLow.z,this._startPositionLowArr=He(this._startPositionLowArr,[t,i,n,t,i,n,t,i,n,t,i,n,t,i,n,t,i,n]),t=e._endPositionHigh.x,i=e._endPositionHigh.y,n=e._endPositionHigh.z,this._endPositionHighArr=He(this._endPositionHighArr,[t,i,n,t,i,n,t,i,n,t,i,n,t,i,n,t,i,n]),t=e._endPositionLow.x,i=e._endPositionLow.y,n=e._endPositionLow.z,this._endPositionLowArr=He(this._endPositionLowArr,[t,i,n,t,i,n,t,i,n,t,i,n,t,i,n,t,i,n]),t=e._thickness,this._thicknessArr=He(this._thicknessArr,[t,t,t,t,t,t]);let r=e._startColor.x,s=e._startColor.y,a=e._startColor.z,o=e._startColor.w,l=e._endColor.x,h=e._endColor.y,c=e._endColor.z,d=e._endColor.w;this._rgbaArr=He(this._rgbaArr,[l,h,c,d,r,s,a,o,r,s,a,o,r,s,a,o,l,h,c,d,l,h,c,d]),t=e._entity._pickingColor.x/255,i=e._entity._pickingColor.y/255,n=e._entity._pickingColor.z/255,this._pickingColorArr=He(this._pickingColorArr,[t,i,n,t,i,n,t,i,n,t,i,n,t,i,n,t,i,n])}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.rayScreen.activate();let i=t.programs.rayScreen._program,n=i.attributes,r=i.uniforms,s=t.gl,a=this._entityCollection;s.disable(s.CULL_FACE),s.uniform1f(r.uOpacity,a._fadingOpacity),s.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),s.uniform1f(r.resolution,e.activeCamera._tanViewAngle_hradOneByHeight),s.bindBuffer(s.ARRAY_BUFFER,this._startPositionHighBuffer),s.vertexAttribPointer(n.a_startPosHigh,this._startPositionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._startPositionLowBuffer),s.vertexAttribPointer(n.a_startPosLow,this._startPositionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._endPositionHighBuffer),s.vertexAttribPointer(n.a_endPosHigh,this._endPositionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._endPositionLowBuffer),s.vertexAttribPointer(n.a_endPosLow,this._endPositionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._rgbaBuffer),s.vertexAttribPointer(n.a_rgba,this._rgbaBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._thicknessBuffer),s.vertexAttribPointer(n.a_thickness,this._thicknessBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._vertexBuffer),s.vertexAttribPointer(n.a_vertices,this._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.enable(s.CULL_FACE)}_pickingPASS(){}draw(){this._rays.length&&(this.update(),this._displayPASS())}drawPicking(){this._rays.length&&this.pickingEnabled&&this._pickingPASS()}reindexRaysArray(e){let t=this._rays;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}_removeRay(e){let t=e._handlerIndex;this._rays.splice(t,1);let i=24*t;this._rgbaArr=Ue(this._rgbaArr,i,24),i=18*t,this._startPositionHighArr=Ue(this._startPositionHighArr,i,18),this._startPositionLowArr=Ue(this._startPositionLowArr,i,18),this._endPositionHighArr=Ue(this._endPositionHighArr,i,18),this._endPositionLowArr=Ue(this._endPositionLowArr,i,18),this._pickingColorArr=Ue(this._pickingColorArr,i,18),i=12*t,this._vertexArr=Ue(this._vertexArr,i,12),i=6*t,this._thicknessArr=Ue(this._thicknessArr,i,6),this.reindexRaysArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null}remove(e){e._handler&&this.__id===e._handler.__id&&this._removeRay(e)}setStartPositionArr(e,t,i){let n=18*e,r=this._startPositionHighArr,s=t.x,a=t.y,o=t.z;r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,r=this._startPositionLowArr,s=i.x,a=i.y,o=i.z,r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,this._changedBuffers[1]=!0}setEndPositionArr(e,t,i){let n=18*e,r=this._endPositionHighArr,s=t.x,a=t.y,o=t.z;r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,r=this._endPositionLowArr,s=i.x,a=i.y,o=i.z,r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,this._changedBuffers[2]=!0}setPickingColorArr(e,t){let i=18*e,n=this._pickingColorArr,r=t.x/255,s=t.y/255,a=t.z/255;n[i]=r,n[i+1]=s,n[i+2]=a,n[i+3]=r,n[i+4]=s,n[i+5]=a,n[i+6]=r,n[i+7]=s,n[i+8]=a,n[i+9]=r,n[i+10]=s,n[i+11]=a,n[i+12]=r,n[i+13]=s,n[i+14]=a,n[i+15]=r,n[i+16]=s,n[i+17]=a,this._changedBuffers[0]=!0}setRgbaArr(e,t,i){let n=24*e,r=this._rgbaArr,s=t.x,a=t.y,o=t.z,l=t.w,h=i.x,c=i.y,d=i.z,_=i.w;r[n]=h,r[n+1]=c,r[n+2]=d,r[n+3]=_,r[n+4]=s,r[n+5]=a,r[n+6]=o,r[n+7]=l,r[n+8]=s,r[n+9]=a,r[n+10]=o,r[n+11]=l,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=l,r[n+16]=h,r[n+17]=c,r[n+18]=d,r[n+19]=_,r[n+20]=h,r[n+21]=c,r[n+22]=d,r[n+23]=_,this._changedBuffers[3]=!0}setThicknessArr(e,t){let i=6*e,n=this._thicknessArr;n[i]=t,n[i+1]=t,n[i+2]=t,n[i+3]=t,n[i+4]=t,n[i+5]=t,this._changedBuffers[4]=!0}setVisibility(e,t){let i;i=t?[-.5,1,-.5,0,.5,0,.5,0,.5,1,-.5,1]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e,n=this._vertexArr;n[i]=t[0],n[i+1]=t[1],n[i+2]=t[2],n[i+3]=t[3],n[i+4]=t[4],n[i+5]=t[5],n[i+6]=t[6],n[i+7]=t[7],n[i+8]=t[8],n[i+9]=t[9],n[i+10]=t[10],n[i+11]=t[11],this._changedBuffers[5]=!0}createStartPositionBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._startPositionHighBuffer),this._startPositionHighArr=Oe(this._startPositionHighArr),this._startPositionHighBuffer=e.createArrayBuffer(this._startPositionHighArr,3,this._startPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._startPositionLowBuffer),this._startPositionLowArr=Oe(this._startPositionLowArr),this._startPositionLowBuffer=e.createArrayBuffer(this._startPositionLowArr,3,this._startPositionLowArr.length/3,e.gl.DYNAMIC_DRAW)}createEndPositionBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._endPositionHighBuffer),this._endPositionHighArr=Oe(this._endPositionHighArr),this._endPositionHighBuffer=e.createArrayBuffer(this._endPositionHighArr,3,this._endPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._endPositionLowBuffer),this._endPositionLowArr=Oe(this._endPositionLowArr),this._endPositionLowBuffer=e.createArrayBuffer(this._endPositionLowArr,3,this._endPositionLowArr.length/3,e.gl.DYNAMIC_DRAW)}createRgbaBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaArr=Oe(this._rgbaArr),this._rgbaBuffer=e.createArrayBuffer(this._rgbaArr,4,this._rgbaArr.length/4)}createThicknessBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._thicknessBuffer),this._thicknessArr=Oe(this._thicknessArr),this._thicknessBuffer=e.createArrayBuffer(this._thicknessArr,1,this._thicknessArr.length,e.gl.DYNAMIC_DRAW)}createVertexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexArr=Oe(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,2,this._vertexArr.length/2,e.gl.DYNAMIC_DRAW)}createPickingColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=Oe(this._pickingColorArr),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}}$i.__counter__=0;class Ki{constructor(e){this.__id=Ki.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._strips=[]}_initProgram(){this._renderer&&this._renderer.handler&&!this._renderer.handler.programs.strip&&this._renderer.handler.addProgram(new zi("strip",{uniforms:{projectionMatrix:{type:"mat4"},viewMatrix:{type:"mat4"},eyePositionHigh:"vec3",eyePositionLow:"vec3",uColor:{type:"vec4"},uOpacity:{type:"float"}},attributes:{aVertexPositionHigh:{type:"vec3"},aVertexPositionLow:{type:"vec3"}},vertexShader:"attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n void main(void) {\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:"precision highp float;\n uniform vec4 uColor;\n uniform float uOpacity;\n void main(void) {\n gl_FragColor = vec4(uColor.rgb, uColor.a * uOpacity);\n }"}))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._strips.length;t++)this._strips[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._strips.length,this._strips.push(e),this._entityCollection&&this._entityCollection.renderNode&&e.setRenderNode(this._entityCollection.renderNode))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._strips.splice(t,1),this.reindexStripArray(t))}reindexStripArray(e){let t=this._strips;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){let e=this._strips.length;for(;e--;)this._strips[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._strips.length;for(;e--;)this._strips[e].drawPicking()}}clear(){let e=this._strips.length;for(;e--;)this._strips[e]._deleteBuffers(),this._strips[e]._handler=null,this._strips[e]._handlerIndex=-1;this._strips.length=0,this._strips=[]}}Ki.__counter__=0;class Qi{constructor(e={}){this.__id=Qi.__counter__++,this._renderNodeIndex=-1,this.renderNode=null,this._visibility=null==e.visibility||e.visibility,this.polygonOffsetUnits=null!=e.polygonOffsetUnits?e.polygonOffsetUnits:0,this.billboardHandler=new Hi(this),this.labelHandler=new qi(this,e.labelMaxLetters),this.polylineHandler=new Zi(this),this.rayHandler=new $i(this),this.pointCloudHandler=new Xi(this),this.stripHandler=new Ki(this),this.geoObjectHandler=new Ui(this),null!=e.pickingEnabled&&this.setPickingEnabled(e.pickingEnabled),this._entities=[],this.scaleByDistance=e.scaleByDistance||[r,r,r],this.pickingScale=e.pickingScale||1,this._opacity=null==e.opacity?1:e.opacity,this._fadingOpacity=this._opacity,this.events=this.rendererEvents=Pt(Ji,this),e.entities&&this.addEntities(e.entities)}get id(){return this.__id}isEqual(e){return this.__id===e.__id}setVisibility(e){this._visibility=e,this._fadingOpacity=this._opacity*(e?1:0),this.events.dispatch(this.events.visibilitychange,this)}getVisibility(){return this._visibility}setOpacity(e){this._opacity=e}setPickingEnabled(e){this.billboardHandler.pickingEnabled=e,this.labelHandler.pickingEnabled=e,this.polylineHandler.pickingEnabled=e,this.rayHandler.pickingEnabled=e,this.pointCloudHandler.pickingEnabled=e,this.stripHandler.pickingEnabled=e,this.geoObjectHandler.pickingEnabled=e}getOpacity(){return this._opacity}setScaleByDistance(e,t,i){this.scaleByDistance[0]=e,this.scaleByDistance[1]=t,this.scaleByDistance[2]=i||r}appendChildEntity(e){this._addRecursively(e)}_addRecursively(e){e.billboard&&this.billboardHandler.add(e.billboard),e.label&&this.labelHandler.add(e.label),e.polyline&&this.polylineHandler.add(e.polyline),e.ray&&this.rayHandler.add(e.ray),e.pointCloud&&this.pointCloudHandler.add(e.pointCloud),e.strip&&this.stripHandler.add(e.strip),e.geoObject&&this.geoObjectHandler.add(e.geoObject),this.events.dispatch(this.events.entityadd,e);for(let t=0;t<e.childrenNodes.length;t++)e.childrenNodes[t]._entityCollection=this,e.childrenNodes[t]._entityCollectionIndex=e._entityCollectionIndex,e.childrenNodes[t]._pickingColor=e._pickingColor,this._addRecursively(e.childrenNodes[t])}add(e){if(!e._entityCollection){e._entityCollection=this,e._entityCollectionIndex=this._entities.length,this._entities.push(e);let t=this.renderNode;t&&(t.renderer&&t.renderer.assignPickingColor(e),t.ellipsoid&&e._cartesian.isZero()&&e.setCartesian3v(t.ellipsoid.lonLatToCartesian(e._lonLat))),this._addRecursively(e),e.setPickingColor()}return this}addEntities(e){for(let t=0,i=e.length;t<i;t++)this.add(e[t]);return this}belongs(e){return e._entityCollection&&this._renderNodeIndex===e._entityCollection._renderNodeIndex}_removeRecursively(e){e._entityCollection=null,e._entityCollectionIndex=-1,e.billboard&&this.billboardHandler.remove(e.billboard),e.label&&this.labelHandler.remove(e.label),e.polyline&&this.polylineHandler.remove(e.polyline),e.ray&&this.rayHandler.remove(e.ray),e.pointCloud&&this.pointCloudHandler.remove(e.pointCloud),e.strip&&this.stripHandler.remove(e.strip),e.geoObject&&this.geoObjectHandler.remove(e.geoObject);for(let t=0;t<e.childrenNodes.length;t++)this._removeRecursively(e.childrenNodes[t])}removeEntity(e){this._entities.splice(e._entityCollectionIndex,1),this.reindexEntitiesArray(e._entityCollectionIndex),this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(e),e._pickingColor.clear()),this.belongs(e)&&this._removeRecursively(e),this.events.dispatch(this.events.entityremove,e)}_removeEntitySilent(e){this._entities.splice(e._entityCollectionIndex,1),this.reindexEntitiesArray(e._entityCollectionIndex),this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(e),e._pickingColor.clear()),this.belongs(e)&&this._removeRecursively(e)}createPickingColors(){if(!this.renderNode||!this.renderNode.renderer)return;let e=this._entities;for(let t=0;t<e.length;t++)e[t].parent||(this.renderNode.renderer.assignPickingColor(e[t]),e[t].setPickingColor())}reindexEntitiesArray(e){let t=this._entities;for(let i=e;i<t.length;i++)t[i]._entityCollectionIndex=i}addTo(e,t=!1){return this.renderNode||(this.renderNode=e,t||(this._renderNodeIndex=e.entityCollections.length,e.entityCollections.push(this)),e.ellipsoid&&this._updateGeodeticCoordinates(e.ellipsoid),this.bindRenderNode(e),this.events.dispatch(this.events.add,this)),this}bindRenderNode(e){e.renderer&&e.renderer.isInitialized()&&(this.billboardHandler.setRenderer(e.renderer),this.labelHandler.setRenderer(e.renderer),this.rayHandler.setRenderer(e.renderer),this.geoObjectHandler.setRenderNode(e),this.polylineHandler.setRenderNode(e),this.pointCloudHandler.setRenderNode(e),this.stripHandler.setRenderNode(e),this.updateBillboardsTextureAtlas(),this.updateLabelsFontAtlas(),this.createPickingColors())}_updateGeodeticCoordinates(e){let t=this._entities,i=t.length;for(;i--;){let n=t[i];n._lonLat&&n.setCartesian3v(e.lonLatToCartesian(n._lonLat))}}updateBillboardsTextureAtlas(){let e=this.billboardHandler.billboards;for(let t=0;t<e.length;t++)e[t].setSrc(e[t].getSrc())}updateLabelsFontAtlas(){this.renderNode&&this.labelHandler.updateFonts()}remove(){if(this.renderNode){if(-1!==this._renderNodeIndex){this.renderNode.entityCollections.splice(this._renderNodeIndex,1);for(let e=this._renderNodeIndex;e<this.renderNode.entityCollections.length;e++)this.renderNode.entityCollections[e]._renderNodeIndex=e}this.renderNode=null,this._renderNodeIndex=-1,this.events.dispatch(this.events.remove,this)}}getEntities(){return[].concat(this._entities)}each(e){let t=this._entities.length;for(;t--;){let i=this._entities[t];i&&e(i)}}clear(){this.billboardHandler.clear(),this.labelHandler.clear(),this.polylineHandler.clear(),this.rayHandler.clear(),this.pointCloudHandler.clear(),this.stripHandler.clear(),this.geoObjectHandler.clear();let e=this._entities.length;for(;e--;){let t=this._entities[e];this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(t),t._pickingColor.clear()),this._clearEntity(t)}this._entities.length=0,this._entities=[]}_clearEntity(e){e._entityCollection=null,e._entityCollectionIndex=-1;for(let t=0;t<e.childrenNodes.length;t++)this._clearEntity(e.childrenNodes[t])}}Qi.__counter__=0;const Ji=["draw","drawend","add","remove","entityadd","entityremove","visibilitychange","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];class en{constructor(e,t,i,n,r,s){this.layer=e,this.parentNode=i,this.childrenNodes=[],this.partId=t,this.nodeId=t+(i?4*i.nodeId+1:0),this.state=null,this.extent=n,this.count=0,this.deferredEntities=[],this.entityCollection=null,this.zoom=s,this._inTheQueue=!1,this.bsphere=new At,r&&this._setExtentBounds()}insertEntity(e,t=!1){this.buildTree([e],t)}_addEntitiesToCollection(e,t=!1){if(e.length){const i=this.layer,n=i._planet;let r=this.entityCollection;r||(r=new Qi({pickingEnabled:i._pickingEnabled,labelMaxLetters:i.labelMaxLetters}),r._layer=this.layer,r.addTo(n,!0),r._quadNode=this,i._bindEventsDefault(r),this.entityCollection=r),t||!i.async?this.entityCollection.addEntities(e):this.deferredEntities.push.apply(this.deferredEntities,e)}}_setExtentBounds(){this.nodeId?this.bsphere.setFromExtent(this.layer._planet.ellipsoid,this.extent.inverseMercator()):(this.bsphere.radius=this.layer._planet.ellipsoid.equatorialSize,this.bsphere.center=new oe)}__setLonLat__(e){return e._lonLat.isZero()&&!e._cartesian.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),Math.abs(e._lonLat.lat)<J?e._lonLatMerc=e._lonLat.forwardMercator():e._lonLatMerc=new z,e._lonLatMerc}buildTree(e,t=!1){if(this.count+=e.length,e.length>this.layer._nodeCapacity){const i=this.childrenNodes;i.length||this.createChildrenNodes();let n=[],r=[],s=[],a=[],o=e.length;for(;o--;){const t=e[o];i[0].isInside(t)?(t._nodePtr=i[0],n.push(t)):i[1].isInside(t)?(t._nodePtr=i[1],r.push(t)):i[2].isInside(t)?(t._nodePtr=i[2],s.push(t)):i[3].isInside(t)&&(t._nodePtr=i[3],a.push(t))}n.length&&i[0].buildTree(n,t),r.length&&i[1].buildTree(r,t),s.length&&i[2].buildTree(s,t),a.length&&i[3].buildTree(a,t)}else this._addEntitiesToCollection(e,t)}isInside(e){return!!e._lonLatMerc&&this.extent.isInside(e._lonLatMerc)}createChildrenNodes(){const e=this.layer,t=this.extent,i=.5*t.getWidth(),n=.5*t.getHeight(),r=t.northEast,s=t.southWest,a=new z(s.lon+i,s.lat+n),o=this.childrenNodes,l=this.layer._planet,h=this.zoom+1;o[0]=new en(e,0,this,new ie(new z(s.lon,s.lat+n),new z(s.lon+i,r.lat)),l,h),o[1]=new en(e,1,this,new ie(a,new z(r.lon,r.lat)),l,h),o[2]=new en(e,2,this,new ie(new z(s.lon,s.lat),a),l,h),o[3]=new en(e,3,this,new ie(new z(s.lon+i,s.lat),new z(r.lon,s.lat+n)),l,h)}collectRenderCollectionsPASS1(e,t){const i=e[this.nodeId];if(i){const n=this.childrenNodes;this.entityCollection?this.renderCollection(t,e):n.length&&(1===i.state?this.layer._secondPASS.push(this):(n[0].collectRenderCollectionsPASS1(e,t),n[1].collectRenderCollectionsPASS1(e,t),n[2].collectRenderCollectionsPASS1(e,t),n[3].collectRenderCollectionsPASS1(e,t)))}}collectRenderCollectionsPASS2(e,t,i){const n=this.layer._planet.camera,r=n.eye.distance(this.bsphere.center)-this.bsphere.radius<3570*Math.sqrt(n._lonLat.height)||n._lonLat.height>1e4;if(this.count>0&&r&&n.frustum.containsSphere(this.bsphere)){const n=this.childrenNodes;this.entityCollection?this.renderCollection(t,e,i):n.length&&(n[0].collectRenderCollectionsPASS2(e,t,i),n[1].collectRenderCollectionsPASS2(e,t,i),n[2].collectRenderCollectionsPASS2(e,t,i),n[3].collectRenderCollectionsPASS2(e,t,i))}}applyCollection(){this.entityCollection.addEntities(this.deferredEntities),this.deferredEntities.length=0,this.deferredEntities=[],this._inTheQueue=!1}traverseTree(e){const t=this.childrenNodes;this.entityCollection?e(this):t.length&&(t[0].traverseTree(e),t[1].traverseTree(e),t[2].traverseTree(e),t[3].traverseTree(e))}renderCollection(e,t,i){const n=this.layer;n._renderingNodes[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(n.async?n._queueDeferredNode(this):this.applyCollection());const r=this.entityCollection;if(r._fadingOpacity=n._fadingOpacity,r.scaleByDistance=n.scaleByDistance,r.pickingScale=n.pickingScale,r.polygonOffsetUnits=n.polygonOffsetUnits,e.push(r),n.clampToGround||n.relativeToGround){const e=r._entities;let s=e.length;if(t[this.nodeId]&&1===t[this.nodeId].state)for(;s--;){let i=e[s];this.alignEntityToTheGround(i,t[this.nodeId].segment)}else if(i)for(;s--;){let n=e[s];this.alignEntityToTheGround(n,t[i].segment)}else{const t=n._planet._renderedNodes;for(;s--;){let i=e[s],n=t.length;for(;n--;)if(t[n].segment.isEntityInside(i)){this.alignEntityToTheGround(i,t[n].segment);break}}}}}alignEntityToTheGround(e,t){let i=new oe;t.getEntityTerrainPoint(e,i);let n=Number(this.layer.relativeToGround)&&e._altitude||0;if(n){let t=this.layer._planet.ellipsoid.getSurfaceNormal3v(i);e._setCartesian3vSilent(i.addA(t.scale(n)))}else e._setCartesian3vSilent(i)}isVisible(){return!!this.layer._renderingNodes[this.nodeId]}}class tn extends en{constructor(e,t,i,n,r,s){super(e,t,i,n,r,s),this.isNorth=!1}createChildrenNodes(){const e=this.layer,t=this.extent,i=.5*t.getWidth(),n=.5*t.getHeight(),r=t.northEast,s=t.southWest,a=new z(s.lon+i,s.lat+n),o=this.childrenNodes,l=this.layer._planet,h=this.zoom+1;o[0]=new tn(e,0,this,new ie(new z(s.lon,s.lat+n),new z(s.lon+i,r.lat)),l,h),o[1]=new tn(e,1,this,new ie(a,new z(r.lon,r.lat)),l,h),o[2]=new tn(e,2,this,new ie(new z(s.lon,s.lat),a),l,h),o[3]=new tn(e,3,this,new ie(new z(s.lon+i,s.lat),new z(r.lon,s.lat+n)),l,h)}_setExtentBounds(){this.extent.northEast.lat>0&&(this.isNorth=!0),this.bsphere.setFromExtent(this.layer._planet.ellipsoid,this.extent)}__setLonLat__(e){return e._lonLat.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),e._lonLat}isVisible(){return!(!this.isNorth||!this.layer._renderingNodesNorth[this.nodeId])||!!this.layer._renderingNodesSouth[this.nodeId]}isInside(e){return this.extent.isInside(e._lonLat)}renderCollection(e,t,i){this.isNorth?this.layer._renderingNodesNorth[this.nodeId]=!0:this.layer._renderingNodesSouth[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?this.layer._queueDeferredNode(this):this.applyCollection());const n=this.entityCollection;n._fadingOpacity=this.layer._fadingOpacity,n.scaleByDistance=this.layer.scaleByDistance,n.pickingScale=this.layer.pickingScale,e.push(n)}}function nn(e,t){if(e>=0){let i=65536*Math.floor(e/65536);t[0]=Math.fround(i),t[1]=Math.fround(e-i)}else{let i=65536*Math.floor(-e/65536);t[0]=Math.fround(-i),t[1]=Math.fround(e+i)}return t}function rn(e,t){if(e>=0){let i=65536*Math.floor(e/65536);t.x=Math.fround(i),t.y=Math.fround(e-i)}else{let i=65536*Math.floor(-e/65536);t.x=Math.fround(-i),t.y=Math.fround(e+i)}return t}function sn(e,t,i){i=i||2;var n,r,s,a,o,l,h,c=t&&t.length,d=c?t[0]*i:e.length,_=an(e,0,d,i,!0),u=[];if(!_)return u;if(c&&(_=function(e,t,i,n){var r,s,a,o=[];for(r=0,s=t.length;r<s;r++)(a=an(e,t[r]*n,r<s-1?t[r+1]*n:e.length,n,!1))===a.next&&(a.steiner=!0),o.push(pn(a));for(o.sort(un),r=0;r<o.length;r++)fn(o[r],i),i=on(i,i.next);return i}(e,t,_,i)),e.length>80*i){n=s=e[0],r=a=e[1];for(let t=i;t<d;t+=i)(o=e[t])<n&&(n=o),(l=e[t+1])<r&&(r=l),o>s&&(s=o),l>a&&(a=l);h=Math.max(s-n,a-r)}return ln(_,u,i,n,r,h),u}function an(e,t,i,n,r){var s,a;if(r===function(e,t,i,n){var r=0;for(let s=t,a=i-n;s<i;s+=n)r+=(e[a]-e[s])*(e[s+1]+e[a+1]),a=s;return r}(e,t,i,n)>0)for(s=t;s<i;s+=n)a=Cn(s,e[s],e[s+1],a);else for(s=i-n;s>=t;s-=n)a=Cn(s,e[s],e[s+1],a);return a&&xn(a,a.next)&&(Ln(a),a=a.next),a}function on(e,t){if(!e)return e;t||(t=e);var i,n=e;do{if(i=!1,n.steiner||!xn(n,n.next)&&0!==yn(n.prev,n,n.next))n=n.next;else{if(Ln(n),(n=t=n.prev)===n.next)return null;i=!0}}while(i||n!==t);return t}function ln(e,t,i,n,r,s,a){if(e){!a&&s&&function(e,t,i,n){var r=e;do{null===r.z&&(r.z=gn(r.x,r.y,t,i,n)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==e);r.prevZ.nextZ=null,r.prevZ=null,function(e){var t,i,n,r,s,a,o,l,h=1;do{for(i=e,e=null,s=null,a=0;i;){for(a++,n=i,o=0,t=0;t<h&&(o++,n=n.nextZ);t++);for(l=h;o>0||l>0&&n;)0!==o&&(0===l||!n||i.z<=n.z)?(r=i,i=i.nextZ,o--):(r=n,n=n.nextZ,l--),s?s.nextZ=r:e=r,r.prevZ=s,s=r;i=n}s.nextZ=null,h*=2}while(a>1)}(r)}(e,n,r,s);for(var o,l,h=e;e.prev!==e.next;)if(o=e.prev,l=e.next,s?cn(e,n,r,s):hn(e))t.push(o.i/i),t.push(e.i/i),t.push(l.i/i),Ln(e),e=l.next,h=l.next;else if((e=l)===h){a?1===a?ln(e=dn(e,t,i),t,i,n,r,s,2):2===a&&_n(e,t,i,n,r,s):ln(on(e),t,i,n,r,s,1);break}}}function hn(e){var t=e.prev,i=e,n=e.next;if(yn(t,i,n)>=0)return!1;for(var r=e.next.next;r!==e.prev;){if(mn(t.x,t.y,i.x,i.y,n.x,n.y,r.x,r.y)&&yn(r.prev,r,r.next)>=0)return!1;r=r.next}return!0}function cn(e,t,i,n){var r=e.prev,s=e,a=e.next;if(yn(r,s,a)>=0)return!1;for(var o=r.x<s.x?r.x<a.x?r.x:a.x:s.x<a.x?s.x:a.x,l=r.y<s.y?r.y<a.y?r.y:a.y:s.y<a.y?s.y:a.y,h=r.x>s.x?r.x>a.x?r.x:a.x:s.x>a.x?s.x:a.x,c=r.y>s.y?r.y>a.y?r.y:a.y:s.y>a.y?s.y:a.y,d=gn(o,l,t,i,n),_=gn(h,c,t,i,n),u=e.nextZ;u&&u.z<=_;){if(u!==e.prev&&u!==e.next&&mn(r.x,r.y,s.x,s.y,a.x,a.y,u.x,u.y)&&yn(u.prev,u,u.next)>=0)return!1;u=u.nextZ}for(u=e.prevZ;u&&u.z>=d;){if(u!==e.prev&&u!==e.next&&mn(r.x,r.y,s.x,s.y,a.x,a.y,u.x,u.y)&&yn(u.prev,u,u.next)>=0)return!1;u=u.prevZ}return!0}function dn(e,t,i){var n=e;do{var r=n.prev,s=n.next.next;!xn(r,s)&&bn(r,n,n.next,s)&&wn(r,s)&&wn(s,r)&&(t.push(r.i/i),t.push(n.i/i),t.push(s.i/i),Ln(n),Ln(n.next),n=e=s),n=n.next}while(n!==e);return n}function _n(e,t,i,n,r,s){var a=e;do{for(var o=a.next.next;o!==a.prev;){if(a.i!==o.i&&vn(a,o)){var l=Tn(a,o);return a=on(a,a.next),l=on(l,l.next),ln(a,t,i,n,r,s),void ln(l,t,i,n,r,s)}o=o.next}a=a.next}while(a!==e)}function un(e,t){return e.x-t.x}function fn(e,t){if(t=function(e,t){var i,n=t,r=e.x,s=e.y,a=-1/0;do{if(s<=n.y&&s>=n.next.y&&n.next.y!==n.y){var o=n.x+(s-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(o<=r&&o>a){if(a=o,o===r){if(s===n.y)return n;if(s===n.next.y)return n.next}i=n.x<n.next.x?n:n.next}}n=n.next}while(n!==t);if(!i)return null;if(r===a)return i.prev;var l,h=i,c=i.x,d=i.y,_=1/0;n=i.next;for(;n!==h;)r>=n.x&&n.x>=c&&r!==n.x&&mn(s<d?r:a,s,c,d,s<d?a:r,s,n.x,n.y)&&((l=Math.abs(s-n.y)/(r-n.x))<_||l===_&&n.x>i.x)&&wn(n,e)&&(i=n,_=l),n=n.next;return i}(e,t),t){var i=Tn(t,e);on(i,i.next)}}function gn(e,t,i,n,r){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-i)/r)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-n)/r)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function pn(e){var t=e,i=e;do{t.x<i.x&&(i=t),t=t.next}while(t!==e);return i}function mn(e,t,i,n,r,s,a,o){return(r-a)*(t-o)-(e-a)*(s-o)>=0&&(e-a)*(n-o)-(i-a)*(t-o)>=0&&(i-a)*(s-o)-(r-a)*(n-o)>=0}function vn(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&bn(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&wn(e,t)&&wn(t,e)&&function(e,t){var i=e,n=!1,r=(e.x+t.x)/2,s=(e.y+t.y)/2;do{i.y>s!=i.next.y>s&&i.next.y!==i.y&&r<(i.next.x-i.x)*(s-i.y)/(i.next.y-i.y)+i.x&&(n=!n),i=i.next}while(i!==e);return n}(e,t)}function yn(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function xn(e,t){return e.x===t.x&&e.y===t.y}function bn(e,t,i,n){return!!(xn(e,t)&&xn(i,n)||xn(e,n)&&xn(i,t))||yn(e,t,i)>0!=yn(e,t,n)>0&&yn(i,n,e)>0!=yn(i,n,t)>0}function wn(e,t){return yn(e.prev,e,e.next)<0?yn(e,t,e.next)>=0&&yn(e,e.prev,t)>=0:yn(e,t,e.prev)<0||yn(e,e.next,t)<0}function Tn(e,t){var i=new An(e.i,e.x,e.y),n=new An(t.i,t.x,t.y),r=e.next,s=t.prev;return e.next=t,t.prev=e,i.next=r,r.prev=i,n.next=i,i.prev=n,s.next=n,n.prev=s,n}function Cn(e,t,i,n){var r=new An(e,t,i);return n?(r.next=n.next,r.prev=n,n.next.prev=r,n.next=r):(r.prev=r,r.next=r),r}function Ln(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function An(e,t,i){this.i=e,this.x=t,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function En(e){var t=e[0][0].length,i={vertices:[],holes:[],dimensions:t},n=0;for(let r=0;r<e.length;r++){for(let n=0;n<e[r].length;n++)for(let s=0;s<t;s++)i.vertices.push(e[r][n][s]);r>0&&(n+=e[r-1].length,i.holes.push(n))}return i}function Pn(e,t,i){let n=e[0],r=e[1];if(n>=0){let e=65536*Math.floor(n/65536);t.x=Math.fround(e),i.x=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t.x=Math.fround(-e),i.x=Math.fround(n+e)}if(r>=0){let e=65536*Math.floor(r/65536);t.y=Math.fround(e),i.y=Math.fround(r-e)}else{let e=65536*Math.floor(-r/65536);t.y=Math.fround(-e),i.y=Math.fround(r+e)}}let Mn=new le,Sn=new le,Bn=new le;class kn{constructor(e){this.__id=kn.__counter__++,this._layer=e,this._handler=null,this._geometries=[],this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr=[],this._removeGeometryExtents={},this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyColors=[],this._polyPickingColors=[],this._polyIndexes=[],this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineOrders=[],this._lineIndexes=[],this._lineColors=[],this._linePickingColors=[],this._lineThickness=[],this._lineStrokes=[],this._lineStrokeColors=[],this._polyVerticesHighBufferMerc=null,this._polyVerticesLowBufferMerc=null,this._polyColorsBuffer=null,this._polyPickingColorsBuffer=null,this._polyIndexesBuffer=null,this._lineVerticesHighBufferMerc=null,this._lineVerticesLowBufferMerc=null,this._lineColorsBuffer=null,this._linePickingColorsBuffer=null,this._lineThicknessBuffer=null,this._lineStrokesBuffer=null,this._lineStrokeColorsBuffer=null,this._lineOrdersBuffer=null,this._lineIndexesBuffer=null,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this.createPolyVerticesBuffer,this._buffersUpdateCallbacks[1]=this.createPolyIndexesBuffer,this._buffersUpdateCallbacks[2]=this.createPolyColorsBuffer,this._buffersUpdateCallbacks[3]=this.createLineVerticesBuffer,this._buffersUpdateCallbacks[4]=this.createLineIndexesBuffer,this._buffersUpdateCallbacks[5]=this.createLineOrdersBuffer,this._buffersUpdateCallbacks[6]=this.createLineColorsBuffer,this._buffersUpdateCallbacks[7]=this.createLineThicknessBuffer,this._buffersUpdateCallbacks[8]=this.createLineStrokesBuffer,this._buffersUpdateCallbacks[9]=this.createLineStrokeColorsBuffer,this._buffersUpdateCallbacks[10]=this.createPolyPickingColorsBuffer,this._buffersUpdateCallbacks[11]=this.createLinePickingColorsBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}static appendLineData(e,t,i,n,r,s,a,o,l,h,c,d,_,u,f,g,p,m){var v=0;c.length>0?(v=c[c.length-5]+9,c.push(v,v)):c.push(0,0);var y=r,x=[i.x,i.y,i.z,i.w],b=a,w=[s.x,s.y,s.z,s.w],T=[n.x,n.y,n.z,1];for(let i=0;i<e.length;i++){var C=e[i];if(0===C.length)continue;let n,r,s=v;if(t)n=C[C.length-1];else{let e=C[0],t=C[1];t||(t=e),n=[e[0]+e[0]-t[0],e[1]+e[1]-t[1]]}Pn(n,Mn,Sn),o.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),l.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),p.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),m.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),h.push(1,-1,2,-2),u.push(y,y,y,y),g.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),f.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(T[0],T[1],T[2],T[3],T[0],T[1],T[2],T[3],T[0],T[1],T[2],T[3],T[0],T[1],T[2],T[3]);for(let e=0;e<C.length;e++){Pn(C[e],Mn,Sn),o.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),l.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),p.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),m.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),h.push(1,-1,2,-2),u.push(y,y,y,y),g.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),f.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(T[0],T[1],T[2],T[3],T[0],T[1],T[2],T[3],T[0],T[1],T[2],T[3],T[0],T[1],T[2],T[3]),c.push(v++,v++,v++,v++)}if(t)r=C[0],c.push(s,s+1,s+1,s+1);else{let e=C[C.length-1],t=C[C.length-2];t||(t=e),r=[e[0]+e[0]-t[0],e[1]+e[1]-t[1]],c.push(v-1,v-1,v-1,v-1)}Pn(r,Mn,Sn),o.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),l.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),p.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),m.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),h.push(1,-1,2,-2),u.push(y,y,y,y),g.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),f.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(T[0],T[1],T[2],T[3],T[0],T[1],T[2],T[3],T[0],T[1],T[2],T[3],T[0],T[1],T[2],T[3]),i<e.length-1&&(v+=8,c.push(v,v))}}assignHandler(e){this._handler=e,this.refresh(),e.isInitialized()&&this.update()}add(e){if(-1===e._handlerIndex){e._handler=this,e._handlerIndex=this._geometries.length,this._geometries.push(e);let t=e._entity._pickingColor.scaleTo(1/255);if(e._polyVerticesHighMerc=[],e._polyVerticesLowMerc=[],e._lineVerticesHighMerc=[],e._lineVerticesLowMerc=[],e._coordinates[0].length)if(e.type===ai.POLYGON){let i=e._coordinates,n=[];for(let e=0;e<i.length;e++){n[e]=[];for(let t=0;t<i[e].length;t++)n[e][t]=[Z(i[e][t][0]),$(i[e][t][1])]}let r=En(n),s=sn(r.vertices,r.holes,2);e._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,e._polyIndexesHandlerIndex=this._polyIndexes.length;for(let t=0;t<s.length;t++)this._polyIndexes.push(s[t]+.5*e._polyVerticesHandlerIndex);let a=e._style.fillColor,o=[],l=[];for(let e=0;e<.5*r.vertices.length;e++)this._polyColors.push(a.x,a.y,a.z,a.w),this._polyPickingColors.push(t.x,t.y,t.z,1);for(let e=0;e<r.vertices.length;e++)rn(r.vertices[e],Bn),o[e]=Bn.x,l[e]=Bn.y;e._polyVerticesHighMerc=o,e._polyVerticesLowMerc=l,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,o),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,l),e._polyVerticesLength=r.vertices.length,e._polyIndexesLength=s.length,e._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,e._lineOrdersHandlerIndex=this._lineOrders.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._lineColorsHandlerIndex=this._lineColors.length,e._lineThicknessHandlerIndex=this._lineThickness.length,kn.appendLineData(n,!0,e._style.lineColor,t,e._style.lineWidth,e._style.strokeColor,e._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,e._lineVerticesHighMerc,e._lineVerticesLowMerc),e._lineVerticesLength=this._lineVerticesHighMerc.length-e._lineVerticesHandlerIndex,e._lineOrdersLength=this._lineOrders.length-e._lineOrdersHandlerIndex,e._lineIndexesLength=this._lineIndexes.length-e._lineIndexesHandlerIndex,e._lineColorsLength=this._lineColors.length-e._lineColorsHandlerIndex,e._lineThicknessLength=this._lineThickness.length-e._lineThicknessHandlerIndex}else if(e.type===ai.MULTIPOLYGON){let i=e._coordinates,n=[],r=[];e._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,e._lineOrdersHandlerIndex=this._lineOrders.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._lineColorsHandlerIndex=this._lineColors.length,e._lineThicknessHandlerIndex=this._lineThickness.length;for(let s=0;s<i.length;s++){let a=i[s],o=[];for(let e=0;e<a.length;e++){o[e]=[];for(let t=0;t<i[s][e].length;t++)o[e][t]=[Z(a[e][t][0]),$(a[e][t][1])]}let l=En(o),h=sn(l.vertices,l.holes,2);for(let e=0;e<h.length;e++)r.push(h[e]+.5*n.length);n.push.apply(n,l.vertices),kn.appendLineData(o,!0,e._style.lineColor,t,e._style.lineWidth,e._style.strokeColor,e._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,e._lineVerticesHighMerc,e._lineVerticesLowMerc)}e._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,e._polyIndexesHandlerIndex=this._polyIndexes.length;for(let t=0;t<r.length;t++)this._polyIndexes.push(r[t]+.5*e._polyVerticesHandlerIndex);let s=e._style.fillColor,a=[],o=[];for(let e=0;e<.5*n.length;e++)this._polyColors.push(s.x,s.y,s.z,s.w),this._polyPickingColors.push(t.x,t.y,t.z,1);for(let e=0;e<n.length;e++)rn(n[e],Bn),a[e]=Bn.x,o[e]=Bn.y;e._polyVerticesHighMerc=a,e._polyVerticesLowMerc=o,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,a),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,o),e._polyVerticesLength=n.length,e._polyIndexesLength=r.length,e._lineVerticesLength=this._lineVerticesHighMerc.length-e._lineVerticesHandlerIndex,e._lineOrdersLength=this._lineOrders.length-e._lineOrdersHandlerIndex,e._lineIndexesLength=this._lineIndexes.length-e._lineIndexesHandlerIndex,e._lineColorsLength=this._lineColors.length-e._lineColorsHandlerIndex,e._lineThicknessLength=this._lineThickness.length-e._lineThicknessHandlerIndex}else if(e.type===ai.LINESTRING){let i=e._coordinates,n=new Array(i.length);for(let e=0;e<i.length;e++)n[e]=[Z(i[e][0]),$(i[e][1])];e._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,e._lineOrdersHandlerIndex=this._lineOrders.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._lineColorsHandlerIndex=this._lineColors.length,e._lineThicknessHandlerIndex=this._lineThickness.length,kn.appendLineData([n],!1,e._style.lineColor,t,e._style.lineWidth,e._style.strokeColor,e._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,e._lineVerticesHighMerc,e._lineVerticesLowMerc),e._lineVerticesLength=this._lineVerticesHighMerc.length-e._lineVerticesHandlerIndex,e._lineOrdersLength=this._lineOrders.length-e._lineOrdersHandlerIndex,e._lineIndexesLength=this._lineIndexes.length-e._lineIndexesHandlerIndex,e._lineColorsLength=this._lineColors.length-e._lineColorsHandlerIndex,e._lineThicknessLength=this._lineThickness.length-e._lineThicknessHandlerIndex}else if(e.type===ai.MULTILINESTRING){let i=e._coordinates,n=[];for(let e=0;e<i.length;e++){n[e]=[];for(let t=0;t<i[e].length;t++)n[e][t]=[Z(i[e][t][0]),$(i[e][t][1])]}e._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,e._lineOrdersHandlerIndex=this._lineOrders.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._lineColorsHandlerIndex=this._lineColors.length,e._lineThicknessHandlerIndex=this._lineThickness.length,kn.appendLineData(n,!1,e._style.lineColor,t,e._style.lineWidth,e._style.strokeColor,e._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,e._lineVerticesHighMerc,e._lineVerticesLowMerc),e._lineVerticesLength=this._lineVerticesHighMerc.length-e._lineVerticesHandlerIndex,e._lineOrdersLength=this._lineOrders.length-e._lineOrdersHandlerIndex,e._lineIndexesLength=this._lineIndexes.length-e._lineIndexesHandlerIndex,e._lineColorsLength=this._lineColors.length-e._lineColorsHandlerIndex,e._lineThicknessLength=this._lineThickness.length-e._lineThicknessHandlerIndex}this.setGeometryVisibility(e),!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0,this.refresh()}}remove(e){const t=e._handlerIndex;if(-1!==t){this._geometries.splice(t,1),this._polyVerticesHighMerc.splice(e._polyVerticesHandlerIndex,e._polyVerticesLength),this._polyVerticesLowMerc.splice(e._polyVerticesHandlerIndex,e._polyVerticesLength),this._polyColors.splice(2*e._polyVerticesHandlerIndex,2*e._polyVerticesLength),this._polyPickingColors.splice(2*e._polyVerticesHandlerIndex,2*e._polyVerticesLength),this._polyIndexes.splice(e._polyIndexesHandlerIndex,e._polyIndexesLength);let i=.5*e._polyVerticesLength;for(let t=e._polyIndexesHandlerIndex;t<this._polyIndexes.length;t++)this._polyIndexes[t]-=i;this._lineVerticesHighMerc.splice(e._lineVerticesHandlerIndex,e._lineVerticesLength),this._lineVerticesLowMerc.splice(e._lineVerticesHandlerIndex,e._lineVerticesLength),this._lineOrders.splice(e._lineOrdersHandlerIndex,e._lineOrdersLength),this._lineColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._linePickingColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._lineStrokeColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._lineThickness.splice(e._lineThicknessHandlerIndex,e._lineThicknessLength),this._lineStrokes.splice(e._lineThicknessHandlerIndex,e._lineThicknessLength),this._lineIndexes.splice(e._lineIndexesHandlerIndex,e._lineIndexesLength),i=.5*e._lineVerticesLength;for(let t=e._lineIndexesHandlerIndex;t<this._lineIndexes.length;t++)this._lineIndexes[t]-=i;let n=this._geometries;for(let i=t;i<n.length;i++){let t=n[i];t._handlerIndex=i,t._polyVerticesHandlerIndex-=e._polyVerticesLength,t._polyIndexesHandlerIndex-=e._polyIndexesLength,t._lineVerticesHandlerIndex-=e._lineVerticesLength,t._lineOrdersHandlerIndex-=e._lineOrdersLength,t._lineColorsHandlerIndex-=e._lineColorsLength,t._lineThicknessHandlerIndex-=e._lineThicknessLength,t._lineIndexesHandlerIndex-=e._lineIndexesLength}e._pickingReady=!1,e._handler=null,e._handlerIndex=-1,e._polyVerticesHighMerc=[],e._polyVerticesLowMerc=[],e._polyVerticesLength=-1,e._polyIndexesLength=-1,e._polyVerticesHandlerIndex=-1,e._polyIndexesHandlerIndex=-1,e._lineVerticesHighMerc=[],e._lineVerticesLowMerc=[],e._lineVerticesLength=-1,e._lineOrdersLength=-1,e._lineIndexesLength=-1,e._lineColorsLength=-1,e._lineThicknessLength=-1,e._lineVerticesHandlerIndex=-1,e._lineOrdersHandlerIndex=-1,e._lineIndexesHandlerIndex=-1,e._lineThicknessHandlerIndex=-1,e._lineColorsHandlerIndex=-1,!this._removeGeometryExtents[e.__id]&&this._removeGeometryExtentArr.push(e.getExtent()),this._removeGeometryExtents[e.__id]=!0,this.refresh()}}_refreshRecursevely(e,t){if(t.ready){let i=this._layer._id;for(let n=0;n<t.nodes.length;n++){let r=t.nodes[n];if(e.overlaps(r.segment.getExtentLonLat())){this._refreshRecursevely(e,r);let t=r.segment.materials[i];t&&t.isReady&&(1!==t.segment.node.getState()?t.layer.clearMaterial(t):(t.pickingReady=t.pickingReady&&e._pickingReady,t.isReady=!1,t._updateTexture=t.texture,t._updatePickingMask=t.pickingMask),e._pickingReady=!0)}}}}_refreshRecursevelyExt(e,t){if(t.ready){let i=this._layer.__id;for(let n=0;n<t.nodes.length;n++){let r=t.nodes[n];if(e.overlaps(r.segment.getExtentLonLat())){this._refreshRecursevelyExt(e,r);let t=r.segment.materials[i];t&&t.isReady&&t.layer.clearMaterial(t)}}}}_refreshPlanetNode(e){let t,i=this._removeGeometryExtentArr;for(t=0;t<i.length;t++)this._refreshRecursevelyExt(i[t],e);let n=this._updatedGeometryArr;for(t=0;t<n.length;t++)this._refreshRecursevely(n[t],e)}_updatePlanet(){let e=this._layer._planet;if(e){let t=e.quadTreeStrategy.quadTreeList;for(let e=0;e<t.length;e++)this._refreshPlanetNode(t[e])}this._updatedGeometryArr.length=0,this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr.length=0,this._removeGeometryExtentArr=[],this._removeGeometryExtents={}}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}update(){if(this._handler){let e=!1,t=this._changedBuffers.length;for(;t--;)this._changedBuffers[t]&&(e=!0,this._buffersUpdateCallbacks[t].call(this),this._changedBuffers[t]=!1);e&&this._updatePlanet()}}setGeometryVisibility(e){let t=e.getVisibility()?1:0,i=this._polyVerticesHighMerc,n=this._polyVerticesLowMerc,r=e._polyVerticesLength,s=e._polyVerticesHandlerIndex;for(let a=0;a<r;a++)i[s+a]=e._polyVerticesHighMerc[a]*t,n[s+a]=e._polyVerticesLowMerc[a]*t;i=this._lineVerticesHighMerc,n=this._lineVerticesLowMerc,r=e._lineVerticesLength,s=e._lineVerticesHandlerIndex;for(let a=0;a<r;a++)i[s+a]=e._lineVerticesHighMerc[a]*t,n[s+a]=e._lineVerticesLowMerc[a]*t;this._changedBuffers[0]=!0,this._changedBuffers[3]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setPolyColorArr(e,t){let i=2*e._polyVerticesHandlerIndex,n=i+2*e._polyVerticesLength,r=this._polyColors;for(let e=i;e<n;e+=4)r[e]=t.x,r[e+1]=t.y,r[e+2]=t.z,r[e+3]=t.w;this._changedBuffers[2]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineStrokeColorArr(e,t){let i=e._lineColorsHandlerIndex,n=i+e._lineColorsLength,r=this._lineStrokeColors;for(let e=i;e<n;e+=4)r[e]=t.x,r[e+1]=t.y,r[e+2]=t.z,r[e+3]=t.w;this._changedBuffers[9]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineColorArr(e,t){let i=e._lineColorsHandlerIndex,n=i+e._lineColorsLength,r=this._lineColors;for(let e=i;e<n;e+=4)r[e]=t.x,r[e+1]=t.y,r[e+2]=t.z,r[e+3]=t.w;this._changedBuffers[6]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineStrokeArr(e,t){}setLineThicknessArr(e,t){let i=e._lineThicknessHandlerIndex,n=i+e._lineThicknessLength,r=this._lineThickness;for(let e=i;e<n;e++)r[e]=t;this._changedBuffers[7]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}bringToFront(e){let t=this._polyIndexes.splice(e._polyIndexesHandlerIndex,e._polyIndexesLength),i=this._lineIndexes.splice(e._lineIndexesHandlerIndex,e._lineIndexesLength);this._geometries.splice(e._handlerIndex,1);let n=this._geometries;for(let t=e._handlerIndex;t<n.length;t++){let i=n[t];i._handlerIndex=t,i._polyIndexesHandlerIndex-=e._polyIndexesLength,i._lineIndexesHandlerIndex-=e._lineIndexesLength}e._polyIndexesHandlerIndex=this._polyIndexes.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._handlerIndex=this._geometries.length,this._geometries.push(e),this._polyIndexes.push.apply(this._polyIndexes,t),this._lineIndexes.push.apply(this._lineIndexes,i),this._changedBuffers[1]=!0,this._changedBuffers[4]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}createPolyVerticesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyVerticesHighBufferMerc),this._polyVerticesHighBufferMerc=e.createArrayBuffer(new Float32Array(this._polyVerticesHighMerc),2,this._polyVerticesHighMerc.length/2),e.gl.deleteBuffer(this._polyVerticesLowBufferMerc),this._polyVerticesLowBufferMerc=e.createArrayBuffer(new Float32Array(this._polyVerticesLowMerc),2,this._polyVerticesLowMerc.length/2)}createPolyIndexesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyIndexesBuffer),this._polyIndexesBuffer=e.createElementArrayBuffer(new Uint32Array(this._polyIndexes),1,this._polyIndexes.length)}createPolyColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyColorsBuffer),this._polyColorsBuffer=e.createArrayBuffer(new Float32Array(this._polyColors),4,this._polyColors.length/4)}createPolyPickingColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyPickingColorsBuffer),this._polyPickingColorsBuffer=e.createArrayBuffer(new Float32Array(this._polyPickingColors),4,this._polyPickingColors.length/4)}createLineVerticesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineVerticesHighBufferMerc),this._lineVerticesHighBufferMerc=e.createArrayBuffer(new Float32Array(this._lineVerticesHighMerc),2,this._lineVerticesHighMerc.length/2),e.gl.deleteBuffer(this._lineVerticesLowBufferMerc),this._lineVerticesLowBufferMerc=e.createArrayBuffer(new Float32Array(this._lineVerticesLowMerc),2,this._lineVerticesLowMerc.length/2)}createLineIndexesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineIndexesBuffer),this._lineIndexesBuffer=e.createElementArrayBuffer(new Uint32Array(this._lineIndexes),1,this._lineIndexes.length)}createLineOrdersBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineOrdersBuffer),this._lineOrdersBuffer=e.createArrayBuffer(new Float32Array(this._lineOrders),1,this._lineOrders.length/2)}createLineColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineColorsBuffer),this._lineColorsBuffer=e.createArrayBuffer(new Float32Array(this._lineColors),4,this._lineColors.length/4)}createLinePickingColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._linePickingColorsBuffer),this._linePickingColorsBuffer=e.createArrayBuffer(new Float32Array(this._linePickingColors),4,this._linePickingColors.length/4)}createLineThicknessBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineThicknessBuffer),this._lineThicknessBuffer=e.createArrayBuffer(new Float32Array(this._lineThickness),1,this._lineThickness.length)}createLineStrokesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineStrokesBuffer),this._lineStrokesBuffer=e.createArrayBuffer(new Float32Array(this._lineStrokes),1,this._lineStrokes.length)}createLineStrokeColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineStrokeColorsBuffer),this._lineStrokeColorsBuffer=e.createArrayBuffer(new Float32Array(this._lineStrokeColors),4,this._lineStrokeColors.length/4)}}kn.__counter__=0;class Rn{constructor(e=2048){this._size=e,this._array=new Array(this._size),this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}reset(){this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}clear(){this._array.length=0,this._array=new Array(this._size),this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}push(e){this.length++,this._array[this._popIndex++]=e}pop(){if(this.length){this.length--;let e=this._array[--this._popIndex];return this._array[this._popIndex]=null,this._array[this._popIndex-1]||(this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex),e}}unshift(e){this.length++,this._array[--this._shiftIndex]=e}shift(){if(this.length){this.length--;let e=this._array[this._shiftIndex];return this._array[this._shiftIndex++]=null,this._array[this._shiftIndex]||(this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex),e}}forEach(e){for(let t=this._shiftIndex;t<this._popIndex;t++)e(this._array[t])}}class In extends qt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(zn),this.isVector=!0,this._hasImageryTiles=!1,this.scaleByDistance=t.scaleByDistance||[r,r,r],this.pickingScale=t.pickingScale||1,this.async=void 0===t.async||t.async,this.clampToGround=t.clampToGround||!1,this.relativeToGround=t.relativeToGround||!1,this._nodeCapacity=t.nodeCapacity||30,this._entities=function(e){let t=[];for(let i=0;i<e.length;i++){let n=e[i];"Entity"===n.instanceName?t.push(n):t.push(new Ai(n))}return t}(t.entities||[]),this._labelMaxLetters=t.labelMaxLetters||24,this._stripEntityCollection=new Qi({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._stripEntityCollection),this._polylineEntityCollection=new Qi({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._polylineEntityCollection),this._geoObjectEntityCollection=new Qi({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._geoObjectEntityCollection),this._geometryHandler=new kn(this),this._entityCollectionsTree=null,this._entityCollectionsTreeNorth=null,this._entityCollectionsTreeSouth=null,this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={},this._counter=0,this._deferredEntitiesPendingQueue=new Rn,this._pendingsQueue=[],this.setEntities(this._entities),this.polygonOffsetUnits=null!=t.polygonOffsetUnits?t.polygonOffsetUnits:0,this.pickingEnabled=this._pickingEnabled,this._secondPASS=[]}get labelMaxLetters(){return this._labelMaxLetters}get instanceName(){return"Vector"}_bindPicking(){this._pickingColor.clear()}addTo(e){this._planet||(this._assignPlanet(e),this._geometryHandler.assignHandler(e.renderer.handler),this._polylineEntityCollection.addTo(e,!0),this._stripEntityCollection.addTo(e,!0),this._geoObjectEntityCollection.addTo(e,!0),this.setEntities(this._entities))}remove(){return super.remove(),this._polylineEntityCollection.remove(),this._stripEntityCollection.remove(),this._geoObjectEntityCollection.remove(),this}getEntities(){return[].concat(this._entities)}add(e,t=!1){return e._layer||e._entityCollection||(e._layer=this,e._layerIndex=this._entities.length,this._entities.push(e),this._proceedEntity(e,t)),this}insert(e,t,i=!1){if(!e._layer&&!e._entityCollection){e._layer=this,e._layerIndex=t,this._entities.splice(t,0,e);for(let e=t+1,i=this._entities.length;e<i;e++)this._entities[e]._layerIndex=e;this._proceedEntity(e,i)}return this}_proceedEntity(e,t=!1){let i=this._hasImageryTiles;e.strip&&this._stripEntityCollection.add(e),(e.polyline||e.ray)&&this._polylineEntityCollection.add(e),e.geoObject&&this._geoObjectEntityCollection.add(e),e.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(e),this._geometryHandler.add(e.geometry))),(e.billboard||e.label||e.geoObject)&&this._planet&&(e._cartesian.isZero()&&!e._lonLat.isZero()?e._setCartesian3vSilent(this._planet.ellipsoid.lonLatToCartesian(e._lonLat)):e._lonLat=this._planet.ellipsoid.cartesianToLonLat(e._cartesian),e._lonLat.lat>J?(this._entityCollectionsTreeNorth.__setLonLat__(e),this._entityCollectionsTreeNorth.insertEntity(e,t)):e._lonLat.lat<ee?(this._entityCollectionsTreeSouth.__setLonLat__(e),this._entityCollectionsTreeSouth.insertEntity(e,t)):(this._entityCollectionsTree.__setLonLat__(e),this._entityCollectionsTree.insertEntity(e,t))),this._planet&&this._hasImageryTiles!==i&&this._planet.updateVisibleLayers(),this.events.dispatch(this.events.entityadd,e)}addEntities(e,t=!1){let i=e.length;for(;i--;)this.add(e[i],t);return this}removeEntity(e){if(e._layer&&this.isEqual(e._layer)){if(this._entities.splice(e._layerIndex,1),this._reindexEntitiesArray(e._layerIndex),e._layer=null,e._layerIndex=-1,e._entityCollection){e._entityCollection._removeEntitySilent(e);let t=e._nodePtr;for(;t;)t.count--,t=t.parentNode;e._nodePtr&&0===e._nodePtr.count&&0===e._nodePtr.deferredEntities.length&&(e._nodePtr.entityCollection=null)}else if(e._nodePtr&&e._nodePtr.deferredEntities.length){let t=e._nodePtr.deferredEntities,i=t.length;for(;i--;)if(t[i].id===e.id){t.splice(i,1);let n=e._nodePtr;for(;n;)n.count--,n=n.parentNode;break}}e.geometry&&this._planet&&(this._geometryHandler.remove(e.geometry),this._planet.renderer.clearPickingColor(e)),e._nodePtr=void 0,this.events.dispatch(this.events.entityremove,e)}return this}set pickingEnabled(e){this._pickingEnabled=e,this._stripEntityCollection.setPickingEnabled(e),this._polylineEntityCollection.setPickingEnabled(e),this._geoObjectEntityCollection.setPickingEnabled(e),this._entityCollectionsTree&&this._entityCollectionsTree.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeNorth&&this._entityCollectionsTreeNorth.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeSouth&&this._entityCollectionsTreeSouth.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)}))}_reindexEntitiesArray(e){const t=this._entities;for(let i=e;i<t.length;i++)t[i]._layerIndex=i}removeEntities(e){let t=e.length;for(;t--;)this.removeEntity(e[t]);return this}clear(){let e=new Array(this._entities.length);for(let t=0;t<e.length;t++)e[t]=this._entities[t];let t=this._entities.length;for(;t--;)this._entities[t].remove();this._entities.length=0,this._entities=[];for(let t=0;t<e.length;t++)this._entities[t]=e[t];this._entityCollectionsTree=null,this._entityCollectionsTreeNorth=null,this._entityCollectionsTreeSouth=null}each(e){let t=this._entities,i=t.length;for(;i--;)e(t[i],i)}setEntities(e){let t=new Array(e.length);for(let i=0,n=e.length;i<n;i++)t[i]=e[i];this.clear(),this._entities=new Array(t.length);let i=[];for(let e=0;e<t.length;e++){let n=t[e];n._layer=this,n._layerIndex=e,n.strip?this._stripEntityCollection.add(n):n.polyline||n.ray?this._polylineEntityCollection.add(n):n.geoObject?this._geoObjectEntityCollection.add(n):(n.billboard||n.label)&&i.push(n),n.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(n),this._geometryHandler.add(n.geometry))),this._entities[e]=n}return this._createEntityCollectionsTree(i),this}_createEntityCollectionsTree(e){if(this._planet){this._entityCollectionsTree=new en(this,0,null,ie.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34]),this._planet,0),this._entityCollectionsTreeNorth=new tn(this,0,null,ie.createFromArray([-180,J,180,90]),this._planet,0),this._entityCollectionsTreeSouth=new tn(this,0,null,ie.createFromArray([-180,-90,180,ee]),this._planet,0);for(let t=0,i=e.length;t<i;t++){let i=e[t];i._lonLat.lat>J?this._entityCollectionsTreeNorth.__setLonLat__(i):i._lonLat.lat<ee?this._entityCollectionsTreeSouth.__setLonLat__(i):this._entityCollectionsTree.__setLonLat__(i)}this._entityCollectionsTree.buildTree(e),this._entityCollectionsTreeNorth.buildTree(e),this._entityCollectionsTreeSouth.buildTree(e)}}_bindEventsDefault(e){let t=this.events;e.events.on("mousemove",(e=>{t.dispatch(t.mousemove,e)})),e.events.on("mouseenter",(e=>{t.dispatch(t.mouseenter,e)})),e.events.on("mouseleave",(e=>{t.dispatch(t.mouseleave,e)})),e.events.on("lclick",(e=>{t.dispatch(t.lclick,e)})),e.events.on("rclick",(e=>{t.dispatch(t.rclick,e)})),e.events.on("mclick",(e=>{t.dispatch(t.mclick,e)})),e.events.on("ldblclick",(e=>{t.dispatch(t.ldblclick,e)})),e.events.on("rdblclick",(e=>{t.dispatch(t.rdblclick,e)})),e.events.on("mdblclick",(e=>{t.dispatch(t.mdblclick,e)})),e.events.on("lup",(e=>{t.dispatch(t.lup,e)})),e.events.on("rup",(e=>{t.dispatch(t.rup,e)})),e.events.on("mup",(e=>{t.dispatch(t.mup,e)})),e.events.on("ldown",(e=>{t.dispatch(t.ldown,e)})),e.events.on("rdown",(e=>{t.dispatch(t.rdown,e)})),e.events.on("mdown",(e=>{t.dispatch(t.mdown,e)})),e.events.on("lhold",(e=>{t.dispatch(t.lhold,e)})),e.events.on("rhold",(e=>{t.dispatch(t.rhold,e)})),e.events.on("mhold",(e=>{t.dispatch(t.mhold,e)})),e.events.on("mousewheel",(e=>{t.dispatch(t.mousewheel,e)})),e.events.on("touchmove",(e=>{t.dispatch(t.touchmove,e)})),e.events.on("touchstart",(e=>{t.dispatch(t.touchstart,e)})),e.events.on("touchend",(e=>{t.dispatch(t.touchend,e)})),e.events.on("doubletouch",(e=>{t.dispatch(t.doubletouch,e)})),e.events.on("touchleave",(e=>{t.dispatch(t.touchleave,e)})),e.events.on("touchenter",(e=>{t.dispatch(t.touchenter,e)}))}_collectStripCollectionPASS(e){let t=this._stripEntityCollection;t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t)}_collectPolylineCollectionPASS(e){let t=this._polylineEntityCollection;if(t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t),this.clampToGround||this.relativeToGround){let e=Number(this.relativeToGround);const i=this._planet._renderedNodes,n=this._planet.getViewExtent();let r=t._entities,s=r.length,a=new oe;for(;s--;){let t=r[s].polyline;if(t&&n.overlaps(t._extent)){let n=t._pathLonLatMerc,r=n.length;for(;r--;){let s=n[r].length;for(;s--;){let o=n[r][s],l=i.length;for(;l--;){let n=i[l].segment;if(n._extent.isInside(o)){let i=t._path3v[r][s];n.getTerrainPoint(i,o,a);let l=e&&t.altitude||0;if(l){let e=this._planet.ellipsoid.getSurfaceNormal3v(a);t.setPoint3v(a.addA(e.scale(l)),s,r,!0)}else t.setPoint3v(a,s,r,!0);break}}}}}}}}_collectGeoObjectCollectionPASS(e){let t=this._geoObjectEntityCollection;t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t)}collectVisibleCollections(e){let t=this._planet;if(this._fading&&this._fadingOpacity>0||this.minZoom<=t.maxCurrZoom&&this.maxZoom>=t.maxCurrZoom){this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={},this._collectStripCollectionPASS(e),this._collectPolylineCollectionPASS(e),this._collectGeoObjectCollectionPASS(e),this._secondPASS=[],this._entityCollectionsTree&&this._entityCollectionsTree.collectRenderCollectionsPASS1(t._visibleNodes,e);let i=this._secondPASS.length;for(;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodes,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeNorth&&this._entityCollectionsTreeNorth.collectRenderCollectionsPASS1(t._visibleNodesNorth,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesNorth,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeSouth&&this._entityCollectionsTreeSouth.collectRenderCollectionsPASS1(t._visibleNodesSouth,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesSouth,e,this._secondPASS[i].nodeId)}}_queueDeferredNode(e){this._visibility&&(e._inTheQueue=!0,this._counter>=1?this._deferredEntitiesPendingQueue.push(e):this._execDeferredNode(e))}_execDeferredNode(e){this._counter++,setTimeout((()=>{if(e.applyCollection(),this._counter--,this._deferredEntitiesPendingQueue.length&&this._counter<1)for(;this._deferredEntitiesPendingQueue.length;){let e=this._deferredEntitiesPendingQueue.pop();if(e._inTheQueue=!1,e.isVisible())return void this._execDeferredNode(e)}}),0)}loadMaterial(e){const t=e.segment;this._isBaseLayer?e.texture=t._isNorth?t.planet.solidTextureOne:t.planet.solidTextureTwo:e.texture=t.planet.transparentTexture,this._planet.layerLock.isFree()&&(e.isReady=!1,e.isLoading=!0,this._planet._vectorTileCreator.add(e))}abortMaterialLoading(e){e.isLoading=!1,e.isReady=!1}applyMaterial(e,t=!1){if(e.isReady)return[0,0,1,1];{!e.isLoading&&this.loadMaterial(e);const t=e.segment;let i=t.node,n=!1,r=this.__id,s=e;for(;i.parentNode;){if(s&&s.isReady){n=!0;break}i=i.parentNode,s=i.segment.materials[r]}if(n){e.appliedNodeId=i.nodeId,e.texture=s.texture,e.pickingMask=s.pickingMask;const n=1/(2<<t.tileZoom-i.segment.tileZoom-1);return[t.tileX*n-i.segment.tileX,t.tileY*n-i.segment.tileY,n,n]}return e.textureExists&&e._updateTexture?(e.texture=e._updateTexture,e.pickingMask=e._updatePickingMask):(e.texture=t.planet.transparentTexture,e.pickingMask=t.planet.transparentTexture),e.pickingReady=!0,[0,0,1,1]}}clearMaterial(e){if(e.isReady){const t=e.segment.handler.gl;e.isReady=!1,e.pickingReady=!1;let i=e.texture;e.texture=null,i&&!i.default&&t.deleteTexture(i),i=e.pickingMask,e.pickingMask=null,i&&!i.default&&t.deleteTexture(i),i=e._updateTexture,e._updateTexture=null,i&&!i.default&&t.deleteTexture(i),i=e._updatePickingMask,e._updatePickingMask=null,i&&!i.default&&t.deleteTexture(i)}this.abortMaterialLoading(e),e.isLoading=!1,e.textureExists=!1}update(){this._geometryHandler.update(),this.events.dispatch(this.events.draw,this)}}const zn=["draw","entityadd","entityremove"],Fn=["change","startpoint"],Dn=gi.createCylinder(1,1,2,20,1,!0,!1,0,-.5,0),Nn=200,Hn=.3,On={scale:.5,instanced:!0,tag:"corners",color:"rgb(350, 350, 0)",object3d:Dn},Vn={scale:.4,instanced:!0,tag:"centers",color:"rgb(0, 350, 50)",object3d:Dn},Un={thickness:3.5,color:"rgb(0, 350, 50)"};class Gn extends Pi{constructor(e){super(e.name),this._cornerDblClick=!1,this._onChange=e=>{if("POLYGON"===e.geometryType){let t=this.getCoordinates(),i=new Ai({geometry:{type:e.geometryType,coordinates:[t],style:{fillColor:"rgba(0,146,247,0.2)"}}});this._geometryLayer.clear(),this._geometryLayer.add(i)}},this._onCornerMouseEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer",this.hideGhostPointer()},this._onCornerMouseLeave=e=>{e.renderer.handler.canvas.style.cursor="default",this.showGhostPointer()},this._onCenterMouseEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer",this.hideGhostPointer()},this._onCenterMouseLeave=e=>{e.renderer.handler.canvas.style.cursor="default",this._pickedCenter||this._pickedCorner||this.showGhostPointer()},this._onLup=e=>{this._planet.renderer.controls.mouseNavigation.activate(),(this._pickedCorner||this._pickedCenter)&&(this.events.dispatch(this.events.change,this),this.setGhostPointerPosition(this._planet.getCartesianFromPixelTerrain(e)),this.showGhostPointer(),this._pickedCorner=null,this._pickedCenter=null)},this._onCornerLdown=e=>{this._pickedCorner=this._getLdown(e)},this._onCenterLdown=e=>{this._pickedCenter=this._getLdown(e)},this._onMouseMove=e=>{this._pickedCenter?this._moveCenterPoint():this._pickedCorner?this._moveCornerPoint(e.pos):this.setGhostPointerPosition(this._planet.getCartesianFromPixelTerrain(e.pos))},this._onCornerLdblclick=e=>{this._cornerDblClick=!0;let t=this.getCoordinates();t.splice(e.pickingObject.layerIndex,1),this.setCoordinates(t)},this._onMouseDblClick=e=>{if(this._cornerDblClick)return void(this._cornerDblClick=!1);if(!this._showGhostPointer)return;let t=this._planet.getCartesianFromPixelTerrain(e);t&&(this._addNew(t),!this._isStartPoint&&this._cornerLayer.getEntities().length>2&&(this._isStartPoint=!0,this.events.dispatch(this.events.startpoint,this)),this.events.dispatch(this.events.change,this))},this.events=Pt(Fn),this._planet=null,this._initCoordinates=e.coordinates||[],this._pickedCorner=null,this._pickedCenter=null,this._startPos=null,this._startClick=new le,this._geometryLayer=new In,this._cornerLayer=new In("corners",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._centerLayer=new In("centers",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._outlineLayer=new In("outline",{entities:[new Ai({polyline:{path3v:[],isClosed:!1,...Un}})],pickingEnabled:!1,polygonOffsetUnits:-5,relativeToGround:!0}),this._outlineLayer.getEntities()[0].polyline.altitude=Hn,this._ghostCorner=new Ai({geoObject:On}),this._ghostOutlineLayer=new In("ghost-pointer",{pickingEnabled:!1,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1],opacity:.5}),this._showGhostPointer=!1,this._isStartPoint=!1,this._insertCornerIndex=-1}get geometryType(){return"POLYGON"}getCoordinates(){let e=this._cornerLayer.getEntities();return e.length>0?e.map((e=>{let t=e.getLonLat();return[t.lon,t.lat,t.height]})):this._initCoordinates}bindPlanet(e){this._planet=e}init(){this._initEvents(),this._initGhostLayerPointer(),this._initCoordinates.length&&this.setCoordinates(this._initCoordinates),this._planet.addLayer(this._outlineLayer),this._planet.addLayer(this._cornerLayer),this._planet.addLayer(this._centerLayer),this.showGhostPointer(),this.startNewPoint(),this._planet.renderer.controls.mouseNavigation.deactivateDoubleClickZoom(),this._geometryLayer.addTo(this._planet),this.events.on("change",this._onChange,this)}onremove(){this._clearEvents(),this.hideGhostPointer(),this.stopNewPoint(),this.clear(),this._geometryLayer.remove()}clear(){this._geometryLayer.clear();let e=this._cornerLayer.getEntities(),t=e.length;for(;t--;)e[t].remove();let i=this._centerLayer.getEntities();for(t=i.length;t--;)i[t].remove();let n=this._outlineLayer.getEntities();for(t=n.length;t--;)n[t].polyline.clear(),t>0&&n[t].remove();this._clearGhostPointer()}setCoordinates(e){this.clear();for(let t=0;t<e.length;t++){let i=e[t],n=this._planet.ellipsoid.lonLatToCartesian(new z(i[0],i[1],i[2]));this._appendCart(n)}this.events.dispatch(this.events.change,this)}stopNewPoint(){this.renderer&&this.renderer.events.off("ldblclick",this._onMouseDblClick)}startNewPoint(){this.renderer.events.on("ldblclick",this._onMouseDblClick,this)}showGhostPointer(){this._showGhostPointer=!0,this._planet.addLayer(this._ghostOutlineLayer),this._insertCornerIndex=this._cornerLayer.getEntities().length}hideGhostPointer(){this._showGhostPointer=!1,this._ghostOutlineLayer.remove(),this._insertCornerIndex=-1}setGhostPointerPosition(e){e&&(this._ghostCorner.setCartesian3v(e),this._updateGhostOutlinePointer(e))}_getLdown(e){this._planet.renderer.controls.mouseNavigation.deactivate(),this._startClick.set(e.x,e.y);let t=e.pickingObject.getCartesian();return this._startPos=this._planet.getPixelFromCartesian(t),e.pickingObject}_initEvents(){this._cornerLayer.events.on("ldblclick",this._onCornerLdblclick,this),this._cornerLayer.events.on("ldown",this._onCornerLdown,this),this._centerLayer.events.on("ldown",this._onCenterLdown,this),this.renderer.events.on("lup",this._onLup,this),this.renderer.events.on("mousemove",this._onMouseMove,this),this._cornerLayer.events.on("mouseenter",this._onCornerMouseEnter,this),this._cornerLayer.events.on("mouseleave",this._onCornerMouseLeave,this),this._centerLayer.events.on("mouseenter",this._onCenterMouseEnter,this),this._centerLayer.events.on("mouseleave",this._onCenterMouseLeave,this)}_clearEvents(){this._cornerLayer.events.off("ldblclick",this._onCornerLdblclick),this._cornerLayer.events.off("ldown",this._onCornerLdown),this._centerLayer.events.off("ldown",this._onCenterLdown),this.renderer.events.off("lup",this._onLup),this.renderer.events.off("mousemove",this._onMouseMove),this._cornerLayer.events.off("mouseenter",this._onCornerMouseEnter),this._cornerLayer.events.off("mouseleave",this._onCornerMouseLeave),this._centerLayer.events.off("mouseenter",this._onCenterMouseEnter),this._centerLayer.events.off("mouseleave",this._onCenterMouseLeave)}_drawCorners(){let e=this._cornerLayer.getEntities();for(let t=0;t<e.length;t++){let i=e[t];this._checkTerrainCollision(i)}}_drawCenters(){let e=this._centerLayer.getEntities();for(let t=0;t<e.length;t++){let i=e[t];this._checkTerrainCollision(i)}}_drawGhostCorner(){this._showGhostPointer&&this._checkTerrainCollision(this._ghostCorner)}frame(){this._drawCorners(),this._drawCenters(),this._drawGhostCorner()}_checkTerrainCollision(e){let t=new oe,i=this._planet._renderedNodes;for(let n=0;n<i.length;n++){let r=i[n].segment;if(r&&r._extentLonLat.isInside(e.getLonLat())){r.getEntityTerrainPoint(e,t),e.setCartesian3v(t);break}}}_moveCenterPoint(){let e=this.getCoordinates(),t=this._pickedCenter.layerIndex+1,i=this._pickedCenter.getLonLat(),n=[i.lon,i.lat,i.height];e.splice(t,0,n),this.setCoordinates(e),this._pickedCenter=null,this._pickedCorner=this._cornerLayer.getEntities()[t]}_addNew(e){if(-1===this._insertCornerIndex||this._cornerLayer.getEntities().length<2)this._appendCart(e);else{let t=this.getCoordinates(),i=this._insertCornerIndex,n=this._planet.ellipsoid.cartesianToLonLat(e),r=[n.lon,n.lat,n.height];t.splice(i,0,r),this.clear(),this.setCoordinates(t)}}_appendCart(e){let t=this._cornerLayer.getEntities(),i=t[t.length-1],n=new Ai({geoObject:On});if(n.setCartesian3v(e),n.addTo(this._cornerLayer),this._checkTerrainCollision(n),i){let e=t[0].getCartesian(),r=i.getCartesian(),s=n.getCartesian().sub(r),a=n.getCartesian().sub(e),o=s.length(),l=a.length();s.normalize(),a.normalize();let h=[],c=[];for(let t=0;t<=Nn;t++){let i=s.scaleTo(t*o/Nn).addA(r);h.push(i);let n=a.scaleTo(t*l/Nn).addA(e);c.push(n)}this._outlineLayer.getEntities()[0].polyline.setPath3v([c]);let d=new Ai({polyline:{path3v:[h],isClosed:!1,...Un}});d.polyline.altitude=Hn,this._outlineLayer.add(d);let _=this._centerLayer.getEntities(),u=_[_.length-1],f=s.scaleTo(.5*o).addA(r),g=a.scaleTo(.5*l).addA(e),p=new Ai({geoObject:Vn});p.setCartesian3v(f),p.addTo(this._centerLayer),this._checkTerrainCollision(p),u.remove(),u.addTo(this._centerLayer),u.setCartesian3v(g)}else{new Ai({geoObject:Vn}).addTo(this._centerLayer)}}_clearGhostPointer(){const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.clear(),e.getEntities()[1].polyline.clear()}_moveCornerPoint(e){let t=new le(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),n=this._planet.getCartesianFromPixelTerrain(i);if(n){this._pickedCorner.setCartesian3v(n);let e=this._cornerLayer.getEntities();if(e.length){let t=this._pickedCorner.layerIndex,i=e.length,n=e[0===t?i-1:t-1].getCartesian(),r=e[(t+1)%i].getCartesian(),s=this._pickedCorner.getCartesian().sub(n),a=this._pickedCorner.getCartesian().sub(r),o=s.length(),l=a.length();s.normalize(),a.normalize();let h=[],c=[];for(let e=0;e<=Nn;e++){let t=s.scaleTo(e*o/Nn).addA(n);h.push(t);let i=a.scaleTo(e*l/Nn).addA(r);c.push(i)}let d=this._outlineLayer.getEntities(),_=d[t].polyline,u=d[(t+1)%i].polyline;_?.setPath3v([h]),u?.setPath3v([c]);let f=this._centerLayer.getEntities(),g=f[0===t?i-1:t-1],p=f[t],m=s.scaleTo(.5*o).addA(n),v=a.scaleTo(.5*l).addA(r);g.setCartesian3v(m),this._checkTerrainCollision(g),p.setCartesian3v(v),this._checkTerrainCollision(p)}}}_updateGhostOutlinePointer(e){let t=this._cornerLayer.getEntities(),i=t.length;if(i>0){let n=0,r=s;for(let s=0;s<i;s++){let i=t[s].getCartesian().distance(e);i<r&&(r=i,n=s)}let a=t[n].getCartesian(),o=t[(n+1)%i].getCartesian(),l=t[0===n?i-1:n-1].getCartesian().sub(a).normalize(),h=o.sub(a).normalize(),c=e.sub(a).normalize(),d=l.add(h).normalize(),_=c.cross(d),u=l.cross(h);_.dot(u)>0&&(n--,n<0&&(n=i-1));let f=new oe;for(let s=0;s<i;s++){if(new ci(t[s].getCartesian(),t[(s+1)%i].getCartesian()).getNearestDistancePoint(e,f)){let t=f.distance(e);t<r&&(r=t,n=s)}}this._insertCornerIndex=(n+1)%i;let g=t[n%i].getCartesian(),p=t[(n+1)%i].getCartesian(),m=this._ghostCorner.getCartesian().sub(g),v=this._ghostCorner.getCartesian().sub(p),y=m.length(),x=v.length();m.normalize(),v.normalize();let b=[],w=[];for(let e=0;e<=Nn;e++){let t=m.scaleTo(e*y/Nn).addA(g);b.push(t);let i=v.scaleTo(e*x/Nn).addA(p);w.push(i)}let T=this._ghostOutlineLayer.getEntities(),C=T[0].polyline,L=T[1].polyline;C?.setPath3v([b]),L?.setPath3v([w])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new Ai({polyline:{path3v:[],isClosed:!1,...Un}}),new Ai({polyline:{path3v:[],isClosed:!1,...Un}}),this._ghostCorner]);const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.altitude=e.getEntities()[1].polyline.altitude=Hn}}class Wn extends Gn{constructor(e){super(e)}get geometryType(){return"LineString"}_addNew(e){this._appendCart(e)}_appendCart(e){let t=this._cornerLayer.getEntities(),i=t[t.length-1],n=new Ai({geoObject:On});if(n.setCartesian3v(e),n.addTo(this._cornerLayer),this._checkTerrainCollision(n),i){let e=i.getCartesian(),t=n.getCartesian().sub(e),r=t.length();t.normalize();let s=[];for(let i=0;i<=Nn;i++){let n=t.scaleTo(i*r/Nn).addA(e);s.push(n)}let a=new Ai({polyline:{path3v:[s],isClosed:!1,...Un}});a.polyline.altitude=Hn,this._outlineLayer.add(a);let o=t.scaleTo(.5*r).addA(e),l=new Ai({geoObject:Vn});l.setCartesian3v(o),l.addTo(this._centerLayer),this._checkTerrainCollision(l)}}_clearGhostPointer(){this._ghostOutlineLayer.getEntities()[0].polyline.clear()}_moveCorner(e,t,i){let n=this._cornerLayer.getEntities();if(0==n.length)return;1==n.length&&(e=t=i=0);let r=n[e].getCartesian(),s=this._pickedCorner.getCartesian().sub(r),a=s.length();s.normalize();let o=[];for(let e=0;e<=Nn;e++){let t=s.scaleTo(e*a/Nn).addA(r);o.push(t)}let l=this._outlineLayer.getEntities()[t].polyline;l?.setPath3v([o]);let h=this._centerLayer.getEntities()[i];if(h){let e=s.scaleTo(.5*a).addA(r);h.setCartesian3v(e),this._checkTerrainCollision(h)}}_moveCornerPoint(e){let t=new le(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),n=this._planet.getCartesianFromPixelTerrain(i);if(n){this._pickedCorner.setCartesian3v(n);let e=this._cornerLayer.getEntities();if(e.length){let t=this._pickedCorner.layerIndex;0===t?this._moveCorner(t+1,t+1,t):(t===e.length-1||this._moveCorner(t+1,t+1,t),this._moveCorner(t-1,t,t-1))}}}_updateGhostOutlinePointer(e){let t=this._cornerLayer.getEntities(),i=t.length;if(i>0){let e=i-1;this._insertCornerIndex=e;let n=t[e].getCartesian(),r=this._ghostCorner.getCartesian().sub(n),s=r.length();r.normalize();let a=[];for(let e=0;e<=Nn;e++){let t=r.scaleTo(e*s/Nn).addA(n);a.push(t)}this._ghostOutlineLayer.getEntities()[0].polyline.setPath3v([a])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new Ai({polyline:{path3v:[],isClosed:!1,...Un}}),this._ghostCorner]),this._ghostOutlineLayer.getEntities()[0].polyline.altitude=Hn}}class jn extends It{constructor(e={}){super(e),this._drawingScene=new Wn({name:`drawingScene:${this.__id}`})}activatePolygonDrawing(){this.deactivate(),this._drawingScene=new Gn({name:`polygonDrawingScene:${this.__id}`}),this.activate()}activateLineStringDrawing(){this.deactivate(),this._drawingScene=new Wn({name:`linestringDrawingScene:${this.__id}`}),this.activate()}oninit(){}onactivate(){this.planet&&this._drawingScene.bindPlanet(this.planet),this.renderer&&this.renderer.addNode(this._drawingScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._drawingScene)}}const Yn={ell:0,msl:1,gnd:2},qn=.3048,Xn=1/qn,Zn=1/3.6,$n=.001*qn,Kn=1/$n,Qn=["m","km","ft","s","h","m/s","km/h","ft/s"],Jn=[0,2,0,0,0,0,0,0];let er=[];function tr(e,t,i){return er[e][t](i)}function ir(e,t,i,n,r){return e?tr(t,i,n).toFixed(r||Jn[i]):"--"}function nr(e){return Qn[e]}er[0]=[],er[0][0]=e=>e,er[0][1]=e=>.001*e,er[0][2]=e=>e*Xn,er[2]=[],er[2][0]=e=>e*qn,er[2][1]=e=>e*$n,er[2][2]=e=>e,er[1]=[],er[1][0]=e=>1e3*e,er[1][1]=e=>e,er[1][2]=e=>e*Kn,er[5]=[],er[5][5]=e=>e,er[5][6]=e=>3.6*e,er[5][7]=e=>3.28084*e,er[6]=[],er[6][5]=e=>e*Zn,er[6][6]=e=>e;var rr=Object.freeze({__proto__:null,ELL:0,GND:2,MSL:1,_tenth:Jn,convert:tr,convertExt:ir,ft:2,fts:7,h:4,heightMode:Yn,km:1,kmh:6,m:0,ms:5,s:3,toString:nr});const sr=['<div class="og-lat-side"></div><div class="og-lat-val"></div>\n <div class="og-lon-side"></div><div class="og-lon-val"></div>\n <div class="og-height"></div>\n <div class="og-units-height"></div>','<div class="og-lat-side"></div><div class="og-lat-val"></div>\n <div class="og-lon-side"></div><div class="og-lon-val"></div>\n <div class="og-height"></div>\n <div class="og-units-height"></div>'];class ar extends It{constructor(e={}){super(e),this._type=e.type||0,this._TYPE_FUNC=[this._SHOW_DECIMAL,this._SHOW_DEGREE],this._showFn=null,this._el=null,this._latSideEl=null,this._lonSideEl=null,this._latValEl=null,this._lonValEl=null,this._heightEl=null,this._altUnitVal=e.altitudeUnit||"m",this._heightModeVal=e.heightMode||"ell",this._altUnit=rr[this._altUnitVal],this._heightMode=Yn[this._heightModeVal],this._lonLat=null,this._centerMode=null==e.centerMode||e.centerMode}_SHOW_DECIMAL(e){if(e){let t=e.lat,i=e.lon;this._latSideEl.innerHTML=t>=0?"N":"S",this._lonSideEl.innerHTML=i>=0?"E":"W",this._latValEl.innerHTML=Math.abs(t).toFixed(7)+"°",this._lonValEl.innerHTML=Math.abs(i).toFixed(7)+"°"}}_SHOW_DEGREE(e){if(e){let t=e.lat,i=e.lon;this._latSideEl.innerHTML=t>=0?"N":"S",this._lonSideEl.innerHTML=i>=0?"E":"W";let n=0,r=t<0?Math.ceil(t):Math.floor(t),s=Math.floor(n=60*Math.abs(t-r)),a=Math.floor(6e3*(n-s))/100;this._latValEl.innerHTML=Math.abs(r)+"°"+s+"'"+a.toFixed(0)+'"',r=i<0?Math.ceil(i):Math.floor(i),s=Math.floor(n=60*Math.abs(i-r)),a=Math.floor(6e3*(n-s))/100,this._lonValEl.innerHTML=Math.abs(r)+"°"+s+"'"+a.toFixed(0)+'"'}}_createCenterEl(){let e=document.createElement("div");return e.className="og-center-icon",e.innerHTML='<svg width="12" height="12"><g><path stroke-width="1" stroke-opacity="1" d="M6 0L6 12M0 6L12 6" stroke="#337ab7"></path></g></svg>',e}_updateUnits(){this._heightMode=Yn[this._heightModeVal],this._altUnit=rr[this._altUnitVal],this._el.querySelector(".og-units-height").innerHTML=nr(this._altUnit),this._showHeight()}_refreshCoordinates(){this._type>=this._TYPE_FUNC.length&&(this._type=0);let e=this._el;e.innerHTML=sr[this._type],this._latSideEl=e.querySelector(".og-lat-side"),this._lonSideEl=e.querySelector(".og-lon-side"),this._latValEl=e.querySelector(".og-lat-val"),this._lonValEl=e.querySelector(".og-lon-val"),this._heightEl=e.querySelector(".og-height"),this._showFn=this._TYPE_FUNC[this._type],this._showFn(this._lonLat)}oninit(){this._el=document.createElement("div"),this._el.classList.add("og-coordinates"),this.renderer.div.appendChild(this._el),this._el.addEventListener("click",(()=>{this._type++,this._refreshCoordinates(),this._updateUnits(),this._showHeight()})),this._centerMode?(this.renderer.div.appendChild(this._createCenterEl()),this.planet.camera.events.on("moveend",this._grabCoordinates,this),this.planet.camera.events.on("moveend",De((()=>this._showHeight()),400,!0),this)):(this.renderer.events.on("mousemove",this._grabCoordinates,this),this.renderer.events.on("mousestop",De((()=>this._showHeight()),400,!0),this)),this._refreshCoordinates(),this._updateUnits()}_grabCoordinates(e){let t,i=e.pos,n=this.renderer;t=this._centerMode?n.handler.getCenter():i,this._lonLat=this.planet.getLonLatFromPixelTerrain(t)||null,this._showFn(this._lonLat)}async _showHeight(){if(this._lonLat&&this.planet){let e=0;this._heightEl.style.opacity="0.7",this._heightMode===Yn.ell?(e=await this.planet.getHeightAboveELL(this._lonLat),e=Number(ir(!0,0,this._altUnit,e))):this._heightMode===Yn.msl&&(e=await this.planet.getHeightDefault(this._lonLat),e=Number(ir(!0,0,this._altUnit,e))),this._heightEl.style.opacity="1.0",this._heightEl.innerHTML=e.toString()}}}let or=class{constructor(){this.x=0,this.y=0,this.prev_x=0,this.prev_y=0,this.grabbedPoint=new oe,this.grabbedSpheroid=new At}dX(){return this.x-this.prev_x}dY(){return this.y-this.prev_y}};class lr extends It{constructor(e={}){super(e),this.grabbedPoint=new oe,this.grabbedDir=new oe,this.inertia=.007,this.grabbedSpheroid=new At,this.planet=null,this._vRot=new ae,this._hRot=new ae,this._a=0,this.scaleRot=0,this.currState=0,this.positionState=[{h:17119745.303455353,max:.98,min:-.98},{h:6866011,max:.98,min:-.98},{h:3e6,max:.98,min:-.98},{h:1e6,max:.98,min:-.98},{h:5e5,max:.98,min:-.98}],this.touches=[new or,new or]}switchZoomState(e){this.stopRotation(),e>0?this.currState++:this.currState--,this.currState<=0&&(this.currState=0),this.currState>=this.positionState.length&&(this.currState=this.positionState.length-1),this.planet.stopFlying();const t=this.planet.camera._lonLat;this.planet.flyLonLat(new z(t.lon,t.lat,this.positionState[this.currState].h))}onMouseWheel(e){this.switchZoomState(e.wheelDelta)}oninit(){this.activate()}onactivate(){let e=this.renderer;e.events.on("mousewheel",this.onMouseWheel,this),e.events.on("lhold",this.onMouseLeftButtonDown,this),e.events.on("ldown",this.onMouseLeftButtonClick,this),e.events.on("lup",this.onMouseLeftButtonUp,this),e.events.on("touchstart",this.onTouchStart,this),e.events.on("touchend",this.onTouchEnd,this),e.events.on("touchmove",this.onTouchMove,this),e.events.on("draw",this.onDraw,this)}onTouchStart(e){if(1==e.sys.touches.length){const t=this.touches[0];t.x=e.sys.touches.item(0).pageX-e.sys.offsetLeft,t.y=e.sys.touches.item(0).pageY-e.sys.offsetTop,t.prev_x=e.sys.touches.item(0).pageX-e.sys.offsetLeft,t.prev_y=e.sys.touches.item(0).pageY-e.sys.offsetTop,t.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new le(t.x,t.y))||null,t.grabbedPoint&&(t.grabbedSpheroid.radius=t.grabbedPoint.length(),this.stopRotation())}}onTouchEnd(e){0==e.sys.touches.length&&(this.scaleRot=1,Math.abs(this.touches[0].x-this.touches[0].prev_x)<3&&Math.abs(this.touches[0].y-this.touches[0].prev_y)<3&&this.stopRotation())}onTouchMove(e){if(1==e.sys.touches.length){let t=this.planet.camera,i=this.touches[0];if(i.prev_x=i.x,i.prev_y=i.y,i.x=e.sys.touches.item(0).pageX-e.sys.offsetLeft,i.y=e.sys.touches.item(0).pageY-e.sys.offsetTop,!i.grabbedPoint)return;let n=t.unproject(i.x,i.y),r=new _i(t.eye,n).hitSphere(i.grabbedSpheroid);if(r){this._a=Math.acos(i.grabbedPoint.y/i.grabbedSpheroid.radius)-Math.acos(r.y/i.grabbedSpheroid.radius),this._vRot=ae.axisAngleToQuat(t._u,this._a),this._hRot=ae.getRotationBetweenVectors(new oe(r.x,0,r.z).normal(),new oe(i.grabbedPoint.x,0,i.grabbedPoint.z).normal());let e=this._hRot.mul(this._vRot),n=this.positionState[this.currState],s=e.mulVec3(t.eye).normal().dot(oe.NORTH);(s>n.max||s<n.min)&&(e=ae.yRotation(e.getYaw())),t.set(e.mulVec3(t.eye),oe.ZERO,oe.NORTH),t.update()}}}onMouseLeftButtonClick(e){this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this.grabbedPoint=this.planet.getCartesianFromMouseTerrain()||null,this.grabbedDir.copy(e.direction),this.grabbedPoint&&(this.grabbedSpheroid.radius=this.grabbedPoint.length(),this.stopRotation())}stopRotation(){this.scaleRot=0,this._a=0,this._vRot.clear(),this._hRot.clear()}onMouseLeftButtonUp(e){this.scaleRot=1,this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),Math.abs(e.x-e.prev_x)<3&&Math.abs(e.y-e.prev_y)<3&&this.stopRotation()}onMouseLeftButtonDown(e){let t=this.planet.camera;if(this.grabbedPoint&&!t.isFlying())if(this.renderer.events.mouseState.moving){let i=new _i(t.eye,e.direction).hitSphere(this.grabbedSpheroid);if(i){this._a=Math.acos(this.grabbedPoint.y/this.grabbedSpheroid.radius)-Math.acos(i.y/this.grabbedSpheroid.radius);let e=this._vRot=ae.axisAngleToQuat(t._u,this._a);t.set(e.mulVec3(t.eye),oe.ZERO,e.mulVec3(t.getUp())),this._hRot=ae.getRotationBetweenVectors(new oe(i.x,0,i.z).normal(),new oe(this.grabbedPoint.x,0,this.grabbedPoint.z).normal()),e=this._hRot,t.set(e.mulVec3(t.eye),oe.ZERO,e.mulVec3(t.getUp())),t.update()}}else this.scaleRot=0}onDraw(){let e=this.renderer,t=this.planet.camera;if(!e.events.mouseState.leftButtonDown&&this.scaleRot&&!t.isFlying())if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{this._vRot=ae.axisAngleToQuat(t._u,this._a);let i=this._vRot.mul(this._hRot),n=i.mulVec3(t.eye).normal().dot(oe.NORTH),r=this.positionState[this.currState];(n>r.max||n<r.min)&&(i=ae.yRotation(i.getYaw())),e.controlsBag.scaleRot=this.scaleRot,i=i.slerp(ae.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize(),i.x||i.y||i.z||(this.scaleRot=0),t.set(i.mulVec3(t.eye),oe.ZERO,oe.NORTH),t.update()}}}const hr=["loadend"];class cr extends qt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(hr),this._projType=0,this._frameWidth=256,this._frameHeight=256,this._sourceReady=!1,this._sourceTexture=null,this._materialTexture=null,this._gridBufferLow=null,this._gridBufferHigh=null,this._extentWgs84ParamsHigh=new Float32Array(4),this._extentWgs84ParamsLow=new Float32Array(4),this._extentMercParamsHigh=new Float32Array(4),this._extentMercParamsLow=new Float32Array(4),this._refreshFrame=!0,this._frameCreated=!1,this._sourceCreated=!1,this._animate=!1,this._ready=!1,this._creationProceeding=!1,this._isRendering=!1,this._extentWgs84=new ie,this._cornersWgs84=[],this._cornersMerc=[],this._isFullExtent=t.fullExtent?1:0,this.rendering=this._renderingProjType0.bind(this),this._onLoadend_=null,t.corners&&this.setCorners(t.corners)}get isIdle(){return super.isIdle&&this._ready}addTo(e){return this._onLoadend_=this._onLoadend.bind(this),this.events.on("loadend",this._onLoadend_,this),super.addTo(e)}_onLoadend(){this._planet&&this._planet.events.dispatch(this._planet.events.layerloadend,this)}remove(){return this.events.off("loadend",this._onLoadend_),this._onLoadend_=null,super.remove()}get instanceName(){return"BaseGeoImage"}getCornersLonLat(){let e=this._cornersWgs84;return[new z(e[0].lon,e[0].lat),new z(e[1].lon,e[1].lat),new z(e[2].lon,e[2].lat),new z(e[3].lon,e[3].lat)]}getCorners(){let e=this._cornersWgs84;return[[e[0].lon,e[0].lat],[e[1].lon,e[1].lat],[e[2].lon,e[2].lat],[e[3].lon,e[3].lat]]}setCorners(e){this.setCornersLonLat(z.join(e))}setCornersLonLat(e){this._refreshFrame=!0,this._cornersWgs84=[e[0].clone(),e[1].clone(),e[2].clone(),e[3].clone()];for(let e=0;e<this._cornersWgs84.length;e++)this._cornersWgs84[e].lat>=89.9&&(this._cornersWgs84[e].lat=89.9),this._cornersWgs84[e].lat<=-89.9&&(this._cornersWgs84[e].lat=-89.9);this._extent.setByCoordinates(this._cornersWgs84);let t=this._extent;t.southWest.lat>J||t.northEast.lat<ee?(this._projType=0,this.rendering=this._renderingProjType0):(this._projType=1,this.rendering=this._renderingProjType1),this._ready&&!this._creationProceeding&&this._planet._geoImageCreator.add(this)}_createFrame(){this._extentWgs84=this._extent.clone(),this._cornersMerc=[this._cornersWgs84[0].forwardMercatorEPS01(),this._cornersWgs84[1].forwardMercatorEPS01(),this._cornersWgs84[2].forwardMercatorEPS01(),this._cornersWgs84[3].forwardMercatorEPS01()],this._extentMerc=new ie(this._extentWgs84.southWest.forwardMercatorEPS01(),this._extentWgs84.northEast.forwardMercatorEPS01());let e=new Float32Array(2);if(0===this._projType?(nn(this._extentWgs84.southWest.lon,e),this._extentWgs84ParamsHigh[0]=e[0],this._extentWgs84ParamsLow[0]=e[1],nn(this._extentWgs84.southWest.lat,e),this._extentWgs84ParamsHigh[1]=e[0],this._extentWgs84ParamsLow[1]=e[1],this._extentWgs84ParamsHigh[2]=2/this._extentWgs84.getWidth(),this._extentWgs84ParamsHigh[3]=2/this._extentWgs84.getHeight()):(nn(this._extentMerc.southWest.lon,e),this._extentMercParamsHigh[0]=e[0],this._extentMercParamsLow[0]=e[1],nn(this._extentMerc.southWest.lat,e),this._extentMercParamsHigh[1]=e[0],this._extentMercParamsLow[1]=e[1],this._extentMercParamsHigh[2]=2/this._extentMerc.getWidth(),this._extentMercParamsHigh[3]=2/this._extentMerc.getHeight()),this._planet){let e=this._planet.renderer.handler;e.gl.deleteTexture(this._materialTexture),this._materialTexture=e.createEmptyTexture_l(this._frameWidth,this._frameHeight);let t=this._planet._geoImageCreator.createGridBuffer(this._cornersWgs84,1===this._projType);this._gridBufferHigh=t[0],this._gridBufferLow=t[1],this._refreshFrame=!1}}abortMaterialLoading(e){this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}clear(){let e=this._planet;if(e){let t=e.renderer.handler.gl;this._creationProceeding&&e._geoImageCreator.remove(this),e._clearLayerMaterial(this),t&&(t.deleteBuffer(this._gridBufferHigh),t.deleteBuffer(this._gridBufferLow),t.deleteTexture(this._sourceTexture),this._materialTexture&&!this._materialTexture.default&&t.deleteTexture(this._materialTexture))}this._sourceTexture=null,this._materialTexture=null,this._gridBufferHigh=null,this._gridBufferLow=null,this._refreshFrame=!0,this._sourceCreated=!1,this._ready=!1,this._creationProceeding=!1}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),this._planet&&this._sourceReady&&(e?this._planet._geoImageCreator.add(this):this._planet._geoImageCreator.remove(this)))}clearMaterial(e){e.texture=null,e.isLoading=!1,e.isReady=!1}applyMaterial(e){let t,i,n=e.segment;this._ready?e.applyTexture(this._materialTexture):(e.texture=this._planet.transparentTexture,!this._creationProceeding&&this.loadMaterial(e)),0===this._projType?(t=this._extentWgs84,i=n._extent):(t=this._extentMerc,i=n.getExtentMerc());let r=t.northEast.lon-t.southWest.lon,s=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/r,(t.northEast.lat-i.northEast.lat)/s,(i.northEast.lon-i.southWest.lon)/r,(i.northEast.lat-i.southWest.lat)/s]}get getFrameWidth(){return this._frameWidth}get getFrameHeight(){return this._frameHeight}_createSourceTexture(){}_renderingProjType1(){let e=this._planet,t=e.renderer.handler,i=t.gl,n=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let r=n._framebuffer;r.setSize(this._frameWidth,this._frameHeight),r.activate(),t.programs.geoImageTransform.activate();let s=t.programs.geoImageTransform._program,a=s.attributes,o=s.uniforms;i.disable(i.CULL_FACE),r.bindOutputTexture(this._materialTexture),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.uniform1i(o.isFullExtent,this._isFullExtent),i.bindBuffer(i.ARRAY_BUFFER,n._texCoordsBuffer),i.vertexAttribPointer(a.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(a.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(a.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(o.extentParamsHigh,this._extentMercParamsHigh),i.uniform4fv(o.extentParamsLow,this._extentMercParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(o.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,n._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,n._indexBuffer.numItems,i.UNSIGNED_INT,0),r.deactivate(),i.enable(i.CULL_FACE),this._ready=!0,this._creationProceeding=!1}_renderingProjType0(){let e=this._planet,t=e.renderer.handler,i=t.gl,n=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let r=n._framebuffer;r.setSize(this._frameWidth,this._frameHeight),r.activate(),t.programs.geoImageTransform.activate();let s=t.programs.geoImageTransform._program,a=s.attributes,o=s.uniforms;i.disable(i.CULL_FACE),r.bindOutputTexture(this._materialTexture),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.bindBuffer(i.ARRAY_BUFFER,n._texCoordsBuffer),i.vertexAttribPointer(a.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(a.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(a.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(o.extentParamsHigh,this._extentWgs84ParamsHigh),i.uniform4fv(o.extentParamsLow,this._extentWgs84ParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(o.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,n._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,n._indexBuffer.numItems,i.UNSIGNED_INT,0),r.deactivate(),i.enable(i.CULL_FACE),this._ready=!0,this._creationProceeding=!1}}const dr={MB_LEFT:0,MB_RIGHT:2,MB_MIDDLE:1,KEY_CTRL:17,KEY_ALT:18,KEY_SHIFT:16,KEY_SPACE:32,KEY_PGUP:33,KEY_PGDN:34,KEY_LEFT:37,KEY_UP:38,KEY_RIGHT:39,KEY_DOWN:40,KEY_PRINTSCREEN:44,KEY_EQUALS:61,KEY_A:65,KEY_C:67,KEY_D:68,KEY_E:69,KEY_F:70,KEY_H:72,KEY_I:73,KEY_K:75,KEY_L:76,KEY_N:78,KEY_O:79,KEY_P:80,KEY_Q:81,KEY_R:82,KEY_S:83,KEY_V:86,KEY_W:87,KEY_X:88,KEY_Z:90,KEY_PLUS:107,KEY_F1:112,KEY_MINUS:173,KEY_APOSTROPHE:192,KEY_BACK_SLASH:220,KEY_MORE:190,KEY_SLASH:191,KEY_LESS:188,KEY_LEFT_SQUARE_BRACKET:219,KEY_RIGHT_SQUARE_BRACKET:221,KEY_SINGLE_QUOTE:222};const _r=["change","idle","play","pause","stop"];class ur extends Bt{constructor(e){super({template:be('<button title={title} class="og-layerSwitcher__layerButton">{icon}<div class="og-layerSwitcher__name">{name}</div></button>',{title:e.model.name,name:e.model.name,icon:e.model.iconSrc?`<img src="${e.model.iconSrc}" />`:""}),...e}),this._onVisibilityChange=e=>{this.el&&(this.model.getVisibility()?this.el.classList.add("og-layerSwitcher__visible"):this.el.classList.remove("og-layerSwitcher__visible"))},this._onClick=()=>{this.model.isBaseLayer()?this.model.setVisibility(!0):this.model.setVisibility(!this.model.getVisibility())},this._onDblClick=()=>{this.model.flyExtent()}}render(e){return super.render(e),this.model.events.on("visibilitychange",this._onVisibilityChange),this._onVisibilityChange(this.model),this.el.addEventListener("click",this._onClick),this.el.addEventListener("dblclick",this._onDblClick),this}remove(){super.remove(),this.model.events.off("visibilitychange",this._onVisibilityChange)}}const fr=["change"];class gr extends Bt{constructor(e={}){super({template:be('<div class="og-slider">\n <div class="og-slider-label">{label}</div>\n <div class="og-slider-panel">\n <div class="og-slider-progress"></div> \n <div class="og-slider-pointer"></div>\n </div>\n <input type="number"/>\n </div>',{label:e.label||""})}),this._onResize=()=>{this._setOffset(this._value*this.$panel.clientWidth/(this._max-this._min))},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this.value=this._value+Math.sign(e.wheelDelta)*(this._max-this._min)/100},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onInput=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this.value=parseFloat(e.target.value)},this._onMouseDown=e=>{(e=e||window.event).preventDefault(),this._startPosX=e.clientX,this.value=this._min+(this._max-this._min)*(e.offsetX/this.$panel.clientWidth),document.addEventListener("mousemove",this._onMouseMove),document.addEventListener("mouseup",this._onMouseUp)},this._onMouseMove=e=>{(e=e||window.event).preventDefault(),e.stopPropagation();let t=this.$panel.getBoundingClientRect(),i=p(e.clientX,t.left,t.right),n=this._startPosX-i;this._startPosX=i,this.value=(this.$pointer.offsetLeft-n)*(this._max-this._min)/this.$panel.clientWidth},this._onMouseUp=()=>{document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove)},this.events=this.events.registerNames(fr),this._value=e.value||0,this._min=e.min||0,this._max=e.max||1,this._resizeObserver=new ResizeObserver(this._onResize),this._startPosX=0,this.$label=null,this.$pointer=null,this.$progress=null,this.$input=null,this.$panel=null}render(e){return super.render(e),this.$label=this.select(".og-slider-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$pointer=this.select(".og-slider-pointer"),this.$progress=this.select(".og-slider-progress"),this.$panel=this.select(".og-slider-panel"),this.$input=this.select("input"),this._resizeObserver.observe(this.el),this._initEvents(),this}set value(e){e!==this._value&&(this._value=p(e,this._min,this._max),this.$input.value=this._value.toString(),this._setOffset(this._value*this.$panel.clientWidth/(this._max-this._min)),this.events.dispatch(this.events.change,this._value,this))}get value(){return this._value}_initEvents(){this.$panel.addEventListener("mousedown",this._onMouseDown),this.$panel.addEventListener("mousewheel",this._onMouseWheel),this.$panel.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.$panel.removeEventListener("mousedown",this._onMouseDown),this.$panel.removeEventListener("mousewheel",this._onMouseWheel),this.$panel.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("input",this._onInput)}_setOffset(e){e>=0&&e<=this.$panel.clientWidth&&(this.$pointer.style.left=this.$progress.style.width=100*e/this.$panel.clientWidth+"%")}remove(){this._clearEvents(),super.remove()}}const pr=["input"];let mr=0;class vr extends Bt{constructor(e={}){super({template:be('<div class="og-color">\n <label for="{id}" class="og-color-label">{label}</label>\n <input type="color" name="{id}" value="{value}"/>\n </div>',{id:"color-"+mr++,label:e.label||""})}),this._onInput=e=>{this.value=e.target.value},this.events=this.events.registerNames(pr),this._value=e.value||"blue",this.$label=null,this.$input=null}render(e){return super.render(e),this.$label=this.select(".og-color-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$input=this.select("input"),this._initEvents(),this}set value(e){e!==this._value&&(this._value=e,this.$input.value=this._value,this.events.dispatch(this.events.input,this._value,this))}get value(){return this._value}_initEvents(){this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.$input.removeEventListener("input",this._onInput)}remove(){this._clearEvents(),super.remove()}}class yr{constructor(){this._lock=0}lock(e){this._lock|=1<<e.id}free(e){this._lock&=~(1<<e.id)}isFree(){return 0===this._lock}isLocked(){return 0!==this._lock}}class xr{constructor(){this.__id=xr.__counter__++}get id(){return this.__id}}xr.__counter__=0;class br extends It{constructor(e={}){super(e),this._deactivate=!1,this._shiftBusy=!1,this._name="mouseNavigation",this.grabbedPoint=new oe,this._eye0=new oe,this.pointOnEarth=new oe,this.earthUp=new oe,this.inertia=.007,this.grabbedSpheroid=new At,this.qRot=new ae,this.scaleRot=0,this.distDiff=.3,this.stepsCount=8,this.stepsForward=null,this.stepIndex=0,this._lmbDoubleClickActive=!0,this.minSlope=e.minSlope||.1,this._wheelDirection=1,this._keyLock=new xr}static getMovePointsFromPixelTerrain(e,t,i,n,r,s,a){const o=[];let l=e.eye.clone(),h=e._b.clone(),c=e._r.clone(),d=e._u.clone(),_=t.getCartesianFromPixelTerrain(r);if(_||(_=t.getCartesianFromPixelTerrain(t.renderer.handler.getCenter())),_){a||(a=oe.sub(_,e.eye).normalize());let t=n*e.eye.distance(_)/i;t*=s?-1.25:2;const r=h.scaleTo(t);if(a.dot(e.eye.normal().negate())>=.1){const t=new At;t.radius=_.length();let n=[],s=[],u=!1;for(let e=0;e<i;e++){l.addA(r);const i=new _i(l,a).hitSphere(t);if(s[e]=l.clone(),!i){u=!0;break}n[e]=(new se).rotateBetweenVectors(_.normal(),i.normal())}if(u){l=e.eye.clone();for(let e=0;e<i;e++)o[e]={eye:l.addA(r).clone(),v:d,u:c,n:h}}else for(let e=0;e<i;e++){let t=n[e];o[e]={eye:t.mulVec3(s[e]),v:t.mulVec3(d),u:t.mulVec3(c),n:t.mulVec3(h)}}}else for(let e=0;e<i;e++)o[e]={eye:l.addA(a.scaleTo(-t)).clone(),v:d,u:c,n:h};return o}}onactivate(){this.renderer&&(this.renderer.events.on("mousewheel",this.onMouseWheel,this),this.renderer.events.on("lhold",this.onMouseLeftButtonDown,this),this.renderer.events.on("rhold",this.onMouseRightButtonDown,this),this.renderer.events.on("ldown",this.onMouseLeftButtonClick,this),this.renderer.events.on("lup",this.onMouseLeftButtonUp,this),this.renderer.events.on("rdown",this.onMouseRightButtonClick,this),this.renderer.events.on("draw",this.onDraw,this,-1e3),this.renderer.events.on("mousemove",this.onMouseMove,this),this.renderer.events.on("mouseleave",this.onMouseLeave,this),this.renderer.events.on("mouseenter",this.onMouseEnter,this),this._lmbDoubleClickActive&&this.renderer.events.on("ldblclick",this.onMouseLeftButtonDoubleClick,this))}ondeactivate(){this.renderer&&(this.renderer.events.off("mousewheel",this.onMouseWheel),this.renderer.events.off("lhold",this.onMouseLeftButtonDown),this.renderer.events.off("rhold",this.onMouseRightButtonDown),this.renderer.events.off("ldown",this.onMouseLeftButtonClick),this.renderer.events.off("lup",this.onMouseLeftButtonUp),this.renderer.events.off("rdown",this.onMouseRightButtonClick),this.renderer.events.off("draw",this.onDraw),this.renderer.events.off("ldblclick",this.onMouseLeftButtonDoubleClick),this.renderer.events.off("mouseleave",this.onMouseLeave),this.renderer.events.off("mouseenter",this.onMouseEnter))}activateDoubleClickZoom(){this._lmbDoubleClickActive||(this._lmbDoubleClickActive=!0,this.renderer&&this.renderer.events.on("ldblclick",this.onMouseLeftButtonDoubleClick,this))}deactivateDoubleClickZoom(){this._lmbDoubleClickActive&&(this._lmbDoubleClickActive=!1,this.renderer&&this.renderer.events.off("ldblclick",this.onMouseLeftButtonDoubleClick))}onMouseEnter(e){const t=this.renderer.events;t.isKeyPressed(dr.KEY_ALT)&&t.releaseKeys(),t.updateButtonsStates(e.sys.buttons),t.mouseState.leftButtonDown?this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"):this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")}onMouseLeave(){this.renderer.events.mouseState.leftButtonDown&&(this.scaleRot=0),this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")}onMouseWheel(e){this.stepIndex||(this.planet.stopFlying(),this.stopRotation(),this._deactivate=!0,this.lockPlanet(!0),this.stepsForward=br.getMovePointsFromPixelTerrain(this.planet.camera,this.planet,this.stepsCount,this.distDiff,e.pos,e.wheelDelta>0,e.direction)||null,this._wheelDirection=e.wheelDelta,this.stepsForward&&(this.stepIndex=this.stepsCount))}oninit(){this.activate(),this.renderer&&(this.renderer.events.on("keyfree",dr.KEY_ALT,this.onShiftFree,this),this.renderer.events.on("keyfree",dr.KEY_PRINTSCREEN,this.onShiftFree,this))}onMouseLeftButtonDoubleClick(e){this.planet.stopFlying(),this.stopRotation();const t=this.planet.getCartesianFromPixelTerrain(e.pos);if(t){const e=this.planet.camera;let i=e.maxAltitude+this.planet.ellipsoid.polarSize,n=e.minAltitude+this.planet.ellipsoid.polarSize;const r=e.eye.length(),s=this.planet.ellipsoid.cartesianToLonLat(t);if(r>i||r<n)return void this.planet.flyLonLat(new z(s.lon,s.lat));this.renderer.events.isKeyPressed(dr.KEY_ALT)?this.planet.flyLonLat(new z(s.lon,s.lat,2*e.eye.distance(t))):this.planet.flyLonLat(new z(s.lon,s.lat,.57*e.eye.distance(t)))}}onMouseLeftButtonClick(){this._active&&(this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this.grabbedPoint=this.planet.getCartesianFromMouseTerrain(),this.grabbedPoint&&(this._eye0.copy(this.planet.camera.eye),this.grabbedSpheroid.radius=this.grabbedPoint.length(),this.stopRotation()))}stopRotation(){this.qRot.clear(),this.freePlanet()}onMouseLeftButtonUp(e){this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.x===e.prev_x&&e.y===e.prev_y&&(this.scaleRot=0)}onMouseLeftButtonDown(e){if(this._active){if(!this.grabbedPoint)return;if(this.planet.stopFlying(),e.moving){let t=this.planet.camera;if(t.slope>.2){const i=new _i(t.eye,e.direction).hitSphere(this.grabbedSpheroid);if(i){this.scaleRot=1,this.qRot=ae.getRotationBetweenVectors(i.normal(),this.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t._u=e.mulVec3(t._u),t._r=e.mulVec3(t._r),t._b=e.mulVec3(t._b)}}else{let i=this.grabbedPoint,n=oe.add(i,t._r),r=oe.add(i,i.normal()),s=new oe;new _i(t.eye,e.direction).hitPlane(i,n,r,s)===_i.INSIDE&&(t.eye=this._eye0.addA(s.subA(i).negate()))}}}}onMouseRightButtonClick(e){this.stopRotation(),this.planet.stopFlying(),this.pointOnEarth=this.planet.getCartesianFromPixelTerrain(e.pos),this.pointOnEarth&&(this.earthUp=this.pointOnEarth.normal())}onMouseRightButtonDown(e){const t=this.planet.camera;if(this.pointOnEarth&&e.moving){this.renderer.controlsBag.scaleRot=1;let i=.5/t.eye.distance(this.pointOnEarth)*t._lonLat.height*o;i>.007?i=.007:i<.003&&(i=.003),t.rotateHorizontal(i*(e.x-e.prev_x),!1,this.pointOnEarth,this.earthUp),t.rotateVertical(i*(e.y-e.prev_y),this.pointOnEarth,this.minSlope)}}onShiftFree(){this._shiftBusy=!1}onMouseMove(e){this._active&&this.renderer.events.isKeyPressed(dr.KEY_ALT)&&(this._shiftBusy||(this._shiftBusy=!0,this.onMouseRightButtonClick(e)),this.onMouseRightButtonDown(e))}onDraw(){if(this._active){const e=this.renderer,t=this.planet.camera;let i=t.eye.clone();if(this.stepIndex){e.controlsBag.scaleRot=1;const i=this.stepsForward[this.stepsCount-this.stepIndex--];t.eye=i.eye,t._u=i.v,t._r=i.u,t._b=i.n}else this._deactivate&&(this._deactivate=!1,this.freePlanet());if(e.events.mouseState.leftButtonDown||!this.scaleRot)return;if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{e.controlsBag.scaleRot=this.scaleRot;let i=this.qRot.slerp(ae.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize();i.x||i.y||i.z||(this.scaleRot=0),t.eye=i.mulVec3(t.eye),t._u=i.mulVec3(t._u),t._r=i.mulVec3(t._r),t._b=i.mulVec3(t._b)}t.eye.distance(i)/t.getAltitude()>.01?this.lockPlanet():this.freePlanet()}}lockPlanet(e){this.planet.layerLock.lock(this._keyLock),!e&&this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock)}freePlanet(){this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}}const wr=e=>e>1e3?`${(e/1e3).toFixed(1)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`;let Tr=gi.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);const Cr={text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,20,0]},Lr={scale:1,instanced:!0,tag:"ruler",color:"rgb(0,305,0)",object3d:Tr};class Ar extends Pi{constructor(e={}){super(e.name),this._onCornerLdown=e=>{if(!this._startLonLat){this.renderer?.controls.mouseNavigation?.deactivate(),this._startClick.set(e.x,e.y);let t=e.pickingObject.getCartesian();this._startPos=this._planet.getPixelFromCartesian(t),this._pickedCorner=e.pickingObject,"start"==e.pickingObject.properties.name?this._anchorLonLat=this._cornerEntity[1].getLonLat().clone():this._anchorLonLat=this._cornerEntity[0].getLonLat().clone()}},this._onLUp=()=>{this._pickedCorner&&(this.renderer.controls.mouseNavigation?.activate(),this._pickedCorner=null,this._anchorLonLat=null)},this._onCornerLup=()=>{this._onLUp()},this._onCornerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onCornerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onLdblclick=()=>{this._preventClick=!0},this._onLclick=e=>{let t=this._planet.getLonLatFromPixelTerrain(e.pos);t&&(this._timeout=setTimeout((()=>{this._preventClick||(this._startLonLat?this._startLonLat=null:(this.setVisibility(!0),this._stopDrawing=!1,this._startLonLat=t)),this._preventClick=!1,this._stopDrawing=!1,clearTimeout(this._timeout)}),200),this._startLonLat&&(this._stopDrawing=!0))},this._onMouseMove=e=>{if(this._startLonLat&&!this._stopDrawing){this._propsLabel.label.setVisibility(!0);let t=this._planet.getLonLatFromPixelTerrain(e.pos);if(!t)return;this._drawLine(this._startLonLat,t)}else if(this._pickedCorner){let t=this._planet.getLonLatFromPixelTerrain(e.pos);t&&("start"===this._pickedCorner.properties.name?this._drawLine(t,this._anchorLonLat):this._drawLine(this._anchorLonLat,t))}},this.events=Pt(Er),this._ignoreTerrain=null==e.ignoreTerrain||e.ignoreTerrain,this._planet=e.planet||null,this._startLonLat=null,this._preventClick=!1,this._stopDrawing=!1,this._pickedCorner=null,this._startPos=null,this._startClick=new le,this._anchorLonLat=null,this._heading=0,this._trackLayer=new In("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._labelLayer=new In("ruler-label",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-100,relativeToGround:!0,hideInLayerSwitcher:!0}),this._cornersLayer=new In("corners",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[100,4e6,1],pickingScale:2}),this._propsLabel=new Ai({name:"propsLabel",label:Cr}),this._trackEntity=new Ai({polyline:{path3v:[],thickness:4.8,color:"rgb(255,131,0)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01,this._cornerEntity=[new Ai({geoObject:Lr,properties:{name:"start"}}),new Ai({geoObject:Lr,properties:{name:"end"}})]}set ignoreTerrain(e){this._ignoreTerrain=e}bindPlanet(e){this._planet=e}_createCorners(){this._cornersLayer.addEntities(this._cornerEntity)}init(){this._createCorners(),this._trackLayer.addEntities([this._trackEntity]),this._labelLayer.addEntities([this._propsLabel]),this._planet.addLayer(this._labelLayer),this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._cornersLayer),this._activate()}onremove(){this._deactivate()}_activate(){this._propsLabel.label.setVisibility(!1),this.setVisibility(!1),this.renderer.events.on("lclick",this._onLclick,this),this.renderer.events.on("mousemove",this._onMouseMove,this),this.renderer.events.on("ldblclick",this._onLdblclick,this),this.renderer.events.on("lup",this._onLUp,this),this._cornersLayer.events.on("mouseenter",this._onCornerEnter,this),this._cornersLayer.events.on("mouseleave",this._onCornerLeave,this),this._cornersLayer.events.on("ldown",this._onCornerLdown,this),this._cornersLayer.events.on("lup",this._onCornerLup,this)}_deactivate(){this._startLonLat=null,this._preventClick=!1,this._stopDrawing=!1,this._pickedCorner=null,this.renderer.events.off("lclick",this._onLclick),this.renderer.events.off("mousemove",this._onMouseMove),this.renderer.events.off("lup",this._onLUp),this._cornersLayer.events.off("mouseenter",this._onCornerEnter),this._cornersLayer.events.off("mouseleave",this._onCornerLeave),this._cornersLayer.events.off("ldown",this._onCornerLdown),this._cornersLayer.events.off("lup",this._onCornerLup),this.clear()}setVisibility(e){this._cornersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._labelLayer.setVisibility(e)}_drawLine(e,t,i){i||(i=this._planet.ellipsoid.lonLatToCartesian(e));let n=this._planet.ellipsoid.lonLatToCartesian(t),r=this._planet.ellipsoid.inverse(e,t),s=r.distance;this._heading=r.initialAzimuth;let a=[],o=n.sub(i),l=o.length();o.normalize();for(let e=0;e<120;e++){let t=o.scaleTo(e*l/120).addA(i);a.push(t)}a.push(n),this._trackEntity.polyline.setPath3v([a]),this._ignoreTerrain&&(this._propsLabel.setCartesian3v(a[Math.floor(a.length/2)]),this._propsLabel.label.setText(`${wr(s)}, ${Math.round(this._heading)} deg`))}clear(){this._trackEntity.remove(),this._cornerEntity[0].remove(),this._cornerEntity[1].remove(),this._propsLabel.remove(),this._planet.removeLayer(this._trackLayer),this._planet.removeLayer(this._cornersLayer)}isCornersPositionChanged(){let e=this._trackEntity.polyline.getPath3v()[0];if(e){const t=e[0].clone(),i=e[e.length-1].clone();return this._cornerEntity[0].getCartesian().equal(t)&&this._cornerEntity[1].getCartesian().equal(i)}return!1}frame(){let e=this._trackEntity.polyline.getPath3v()[0];if(e){const t=e[0].clone(),i=e[e.length-1].clone();if(!this.isCornersPositionChanged()&&(this._cornerEntity[0].setCartesian3v(t),this._cornerEntity[1].setCartesian3v(i),!this._ignoreTerrain)){let t=0;for(let i=0,n=e.length-1;i<n;i++)t+=e[i+1].distance(e[i]);this._propsLabel.setCartesian3v(e[Math.floor(e.length/2)]),this._propsLabel.label.setText(`${wr(t)}, ${Math.round(this._heading)} deg`)}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Er=["add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];class Pr extends It{constructor(e={}){super(e),this._rulerScene=new Ar({name:`rulerScene:${this.__id}`,ignoreTerrain:e.ignoreTerrain})}set ignoreTerrain(e){this._rulerScene.ignoreTerrain=e}oninit(){this._rulerScene.bindPlanet(this.planet)}onactivate(){this.renderer&&this.renderer.addNode(this._rulerScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._rulerScene)}}let Mr=gi.createCylinder(1.1,0,2,6,1,!0,!0,0,0,0);const Sr={startColor:"rgb(255,131,0)",endColor:"rgb(255,131,0)",thickness:5},Br={text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,18,0]},kr={scale:1,instanced:!0,tag:"height-ruler",color:"rgb(255,131,0)",object3d:Mr};class Rr extends Ar{constructor(e={}){super(e),this._geoRulerLayer=new In("rayHeightRuler",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-2,relativeToGround:!1,hideInLayerSwitcher:!0}),this._rayV=new Ai({name:"verticalRay",ray:Sr}),this._rayH=new Ai({name:"heightRay",ray:Sr}),this._heightLabels=[new Ai({name:"startCornerLabel",label:{...Br}}),new Ai({name:"endCornerLabel",label:{...Br}}),new Ai({name:"deltaLabel",label:{...Br}})]}setVisibility(e){super.setVisibility(e),this._geoRulerLayer.setVisibility(e)}get deltaLabel(){return this._heightLabels[2]}get startLabel(){return this._heightLabels[0]}get endLabel(){return this._heightLabels[1]}get corners(){return this._cornerEntity}get startCorner(){return this.corners[0]}get endCorner(){return this.corners[1]}get startCornerLonLat(){return this.startCorner.getLonLat()}get startCornerHeight(){return this.startCornerLonLat.height}get endCornerLonLat(){return this.endCorner.getLonLat()}get endCornerHeight(){return this.endCornerLonLat.height}get maxHeightCornerLonLat(){return this.startCornerHeight<=this.endCornerHeight?this.endCornerLonLat:this.startCornerLonLat}get minHeightCornerLonLat(){return this.startCornerHeight>this.endCornerHeight?this.endCornerLonLat:this.startCornerLonLat}get deltaHeight(){return Math.abs(this.startCornerHeight-this.endCornerHeight)}_drawLine(e,t,i){super._drawLine(e,t,i),this._updateHeightRaysAndLabels()}async _updateHeightRaysAndLabels(){const e=this.minHeightCornerLonLat.clone();e.height=this.maxHeightCornerLonLat.height,this._rayH.ray.setStartPosition3v(this._planet.ellipsoid.lonLatToCartesian(this.maxHeightCornerLonLat)),this._rayH.ray.setEndPosition3v(this._planet.ellipsoid.lonLatToCartesian(e)),this._rayV.ray.setStartPosition3v(this._planet.ellipsoid.lonLatToCartesian(this.minHeightCornerLonLat)),this._rayV.ray.setEndPosition3v(this._planet.ellipsoid.lonLatToCartesian(e)),e.height=this.minHeightCornerLonLat.height+this.deltaHeight/2,this.deltaLabel.setLonLat(e),this.startLabel.setLonLat(this.startCornerLonLat),this.endLabel.setLonLat(this.endCornerLonLat);const t=await this._planet.getHeightDefault(this.startCornerLonLat),i=await this._planet.getHeightDefault(this.endCornerLonLat);this.deltaLabel.label.setText(`Δ ${Math.abs(t-i).toFixed(1)} m`),this.startLabel.label.setText(`P1 ${t.toFixed(1)} m`),this.endLabel.label.setText(`P2 ${i.toFixed(1)} m`)}clear(){this._rayH.remove(),this._rayV.remove(),this.startCorner.remove(),this.endCorner.remove(),this.startLabel.remove(),this.endLabel.remove(),this.deltaLabel.remove(),super.clear(),this._planet.removeLayer(this._geoRulerLayer)}_createCorners(){this._cornerEntity=[new Ai({geoObject:kr,properties:{name:"start"}}),new Ai({geoObject:kr,properties:{name:"end"}})],this._cornersLayer.setEntities(this._cornerEntity)}init(){super.init(),this._createCorners(),this._labelLayer.addEntities(this._heightLabels),this._geoRulerLayer.addEntities([this._rayH,this._rayV]),this._planet.addLayer(this._geoRulerLayer)}frame(){super.frame(),this._updateHeightRaysAndLabels()}}class Ir extends Pr{constructor(e={}){super(e),this._rulerScene=new Rr({name:`heightRulerScene:${this.__id}`,ignoreTerrain:!1})}}const zr=[1,2,3,5,10,20,30,50,100,200,300,500,1e3,2e3,3e3,5e3,1e4,2e4,3e4,5e4,1e5,2e5,3e5,5e5,1e6,2e6,3e6,5e6,1e7];class Fr extends It{constructor(e={}){e.name&&""!==e.name||(e.name="scaleControl"),super(e),this._template='<div class="og-scale-container">\n <div class="og-scale-label"></div>\n <div class="og-scale-ruler"></div>\n </div>',this._minWidth=100,this._maxWidth=150,this._isCenter=null==e.isCenter||e.isCenter,this._mPx=0,this.currWidth=0,this._metersInMinSize=0,this.el=null,this._scaleLabelEl=null}_renderTemplate(){return we(this._template)[0]}oninit(){this.el=this._renderTemplate(),this._scaleLabelEl=this.el.querySelector(".og-scale-label"),this.renderer.div.appendChild(this.el),this._isCenter?(this.planet.camera.events.on("moveend",(()=>{this._drawScreen(this.planet.renderer.handler.getCenter())})),!this.planet.terrain.isEmpty&&this.planet.terrain.events.on("loadend",(()=>{this._drawScreen(this.planet.renderer.handler.getCenter())}))):(this.renderer.events.on("mousemove",(e=>{e.leftButtonHold||e.rightButtonHold||this._drawScreen(e.pos)})),this.planet.camera.events.on("moveend",(()=>{let e=this.renderer.events.mouseState;e.leftButtonHold||e.rightButtonHold||this._drawScreen(e.pos)})))}_drawScreen(e){let t=this.planet.camera,i=e,n=this.planet.getDistanceFromPixel(i)||0;0===n&&(i=t.project(oe.ZERO),n=this.planet.getDistanceFromPixel(i)||0);let r=t.getForward().scaleTo(n).addA(t.eye),s=n*Math.tan(t.viewAngle*o),a=r.add(t.getRight().scaleTo(s)),l=t.project(a);this._mPx=s/l.distance(i);let h=this._mPx*this._minWidth,c=ke(zr,h,((e,t)=>e-t));c<0&&(c=~c);let d=zr[c],_=(d-h)/(zr[c+1]-d);this.currWidth=this._minWidth+_*(this._maxWidth-this._minWidth),this._scaleLabelEl.innerText=d>1e3?d/1e3+" km":`${d} m`,this._metersInMinSize=h,this.el.style.width=this.currWidth+"px"}}class Dr extends It{constructor(e={}){super({name:"SimpleSkyBackground",...e}),this._colorOne=new Float32Array([128/255,223/255,1]),this._colorTwo=new Float32Array([10/255,15/255,56/255])}get colorOne(){let e=this._colorOne;return me([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}get colorTwo(){let e=this._colorTwo;return me([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}set colorOne(e){let t=xe(e);this._colorOne[0]=t.x,this._colorOne[1]=t.y,this._colorOne[2]=t.z}set colorTwo(e){let t=xe(e);this._colorTwo[0]=t.x,this._colorTwo[1]=t.y,this._colorTwo[2]=t.z}oninit(){this.renderer.handler.addProgram(new zi("simpleSkyBackground",{uniforms:{iResolution:"vec2",fov:"float",camPos:"vec3",earthRadius:"float",viewMatrix:"mat4",colorOne:"vec3",colorTwo:"vec3"},attributes:{corners:"vec3"},vertexShader:"attribute vec2 corners;\n \n varying vec2 tc;\n \n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n \n #define MAX 10e10\n #define PI 3.14159265359\n #define rad(x) x * PI / 180.\n #define ZERO vec3(0.0) \n \n #define RED vec4(1.0, 0.0, 0.0, 1.0)\n #define GREEN vec4(0.0, 1.0, 0.0, 1.0) \n \n uniform vec3 camPos; \n uniform vec2 iResolution;\n uniform float fov;\n uniform float earthRadius;\n uniform mat4 viewMatrix;\n \n uniform vec3 colorOne;\n uniform vec3 colorTwo;\n \n varying vec2 tc;\n \n // compute the view ray in the camera coordinate\n vec3 computeView(vec2 uv){\n float w_h_ratio = iResolution.x / iResolution.y; \n float h = tan(rad(fov/2.));\n return normalize(vec3(-w_h_ratio * h, -h, -1.) + vec3(uv.x * 2. * h * w_h_ratio, uv.y*2.*h, 0.));\n }\n\n // sphere of size ra centered at point ce\n vec2 sphIntersect( in vec3 ro, in vec3 rd, in vec3 ce, float ra )\n {\n vec3 oc = ro - ce;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - ra * ra;\n float h = b * b - c;\n if( h < 0.0 ) return vec2(MAX); // no intersection\n h = sqrt( h );\n return vec2( -b-h, -b+h );\n }\n \n mat3 transpose(mat3 matrix) {\n vec3 row0 = matrix[0];\n vec3 row1 = matrix[1];\n vec3 row2 = matrix[2];\n mat3 result = mat3(\n vec3(row0.x, row1.x, row2.x),\n vec3(row0.y, row1.y, row2.y),\n vec3(row0.z, row1.z, row2.z)\n );\n return result;\n }\n \n float det(mat2 matrix) {\n return matrix[0].x * matrix[1].y - matrix[0].y * matrix[1].x;\n }\n \n mat3 inverse(mat3 matrix) {\n vec3 row0 = matrix[0];\n vec3 row1 = matrix[1];\n vec3 row2 = matrix[2];\n \n vec3 minors0 = vec3(\n det(mat2(row1.y, row1.z, row2.y, row2.z)),\n det(mat2(row1.z, row1.x, row2.z, row2.x)),\n det(mat2(row1.x, row1.y, row2.x, row2.y))\n );\n vec3 minors1 = vec3(\n det(mat2(row2.y, row2.z, row0.y, row0.z)),\n det(mat2(row2.z, row2.x, row0.z, row0.x)),\n det(mat2(row2.x, row2.y, row0.x, row0.y))\n );\n vec3 minors2 = vec3(\n det(mat2(row0.y, row0.z, row1.y, row1.z)),\n det(mat2(row0.z, row0.x, row1.z, row1.x)),\n det(mat2(row0.x, row0.y, row1.x, row1.y))\n );\n \n mat3 adj = transpose(mat3(minors0, minors1, minors2));\n \n return (1.0 / dot(row0, minors0)) * adj;\n }\n \n void main(void) {\n \n vec3 dir = computeView(tc);\n dir = inverse(mat3(viewMatrix)) * dir;\n \n vec2 ER = sphIntersect(camPos, dir, vec3(0.0), earthRadius);\n \n float bigRadius = earthRadius * 2.5;\n vec3 bigCenter = normalize(camPos) * bigRadius * 1.3; \n \n vec2 BIG = sphIntersect(camPos, dir, bigCenter, bigRadius);\n \n float Ix = distance(camPos + dir * BIG.y, ZERO); \n \n float maxI = sqrt(bigRadius * bigRadius + bigRadius * bigRadius);\n \n gl_FragColor = vec4(mix(colorOne, colorTwo, Ix / maxI), 1.0);\n }"})),this.activate()}onactivate(){super.onactivate(),this.planet.events.on("draw",this._drawBackground,this)}ondeactivate(){super.ondeactivate(),this.planet.events.off("draw",this._drawBackground)}_drawBackground(){let e=this.renderer.handler,t=e.programs.simpleSkyBackground,i=t._program,n=i.uniforms,r=e.gl,s=this.planet.camera;r.disable(r.DEPTH_TEST),t.activate(),r.bindBuffer(r.ARRAY_BUFFER,this.renderer.screenFramePositionBuffer),r.vertexAttribPointer(i.attributes.corners,2,r.FLOAT,!1,0,0),r.uniform3fv(n.camPos,[s.eye.x,s.eye.y,s.eye.z]),r.uniform2fv(n.iResolution,[e.getWidth(),e.getHeight()]),r.uniform1f(n.fov,s.getViewAngle()),r.uniform1f(n.earthRadius,this.planet.ellipsoid.getPolarSize()+1),r.uniform3fv(n.colorOne,this._colorOne),r.uniform3fv(n.colorTwo,this._colorTwo),r.uniformMatrix4fv(n.viewMatrix,!1,s.getViewMatrix()),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST)}}const Nr=14959787e4;function Hr(t){var i=t-ut,n=282.9404+470935e-10*i,r=.016709-1.151e-9*i,s=P(356.047+.9856002585*i),a=23.4392911-3.563e-7*i,h=s+l*r*Math.sin(s*o)*(1+r*Math.cos(s*o)),c=Math.cos(h*o)-r,d=Math.sin(h*o)*Math.sqrt(1-r*r),_=Math.sqrt(c*c+d*d),u=P(Math.atan2(d,c)*l+n),f=c=_*Math.cos(u*o),g=(d=_*Math.sin(u*o))*Math.cos(a*o),p=d*Math.sin(a*o),m=e*(24*i/23.9344694-259.853/360);return ae.zRotation(-m).mulVec3(new oe(-f*Nr,-g*Nr,p*Nr))}class Or{constructor(e,t){this._name=e||"light_"+Or.__counter__++,this._renderNode=null,this._position=t.position||new oe,this.directional=null==t.directional||t.directional,this._ambient=t.ambient||new oe,this._diffuse=t.diffuse||new oe(.8,.8,.8),this._specular=t.specular||new oe(.18,.18,.18),this._shininess=null!=t.shininess?t.shininess:3.3,this._active=!0,this._tempAmbient=this._ambient.clone(),this._tempDiffuse=this._diffuse.clone(),this._tempSpecular=this._specular.clone(),this._tempShininess=this._shininess}clone(){}setActive(e){if(e&&!this._active){const e=this._renderNode;if(e){let t=e._lightsNames.indexOf(this._name);this._shininess=e._lightsParamsf[t]=this._tempShininess,-1!=t&&(t*=9,this._ambient.x=e._lightsParamsv[t]=this._tempAmbient.x,this._ambient.y=e._lightsParamsv[t+1]=this._tempAmbient.y,this._ambient.z=e._lightsParamsv[t+2]=this._tempAmbient.z,this._diffuse.x=e._lightsParamsv[t+3]=this._tempDiffuse.x,this._diffuse.y=e._lightsParamsv[t+4]=this._tempDiffuse.y,this._diffuse.z=e._lightsParamsv[t+5]=this._tempDiffuse.z,this._specular.x=e._lightsParamsv[t+6]=this._tempSpecular.x,this._specular.y=e._lightsParamsv[t+7]=this._tempSpecular.y,this._specular.z=e._lightsParamsv[t+8]=this._tempSpecular.z)}this._active=!0}else!e&&this._active&&(this._tempAmbient=this._ambient.clone(),this._tempDiffuse=this._diffuse.clone(),this._tempSpecular=this._specular.clone(),this._tempShininess=this._shininess,this.setBlack(),this._active=!1)}isActive(){return this._active}setPosition3v(e){this._position.x=e.x,this._position.y=e.y,this._position.z=e.z}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i}getPosition(){return this._position.clone()}setAmbient3v(e){this.setAmbient(e.x,e.y,e.z)}setDiffuse3v(e){this.setDiffuse(e.x,e.y,e.z)}setSpecular3v(e){this.setSpecular(e.x,e.y,e.z)}setAmbient(e,t,i){this._ambient.set(e,t,i);const n=this._renderNode;if(n){let r=9*n._lightsNames.indexOf(this._name);-1!=r&&(n._lightsParamsv[r]=e,n._lightsParamsv[r+1]=t,n._lightsParamsv[r+2]=i)}}setDiffuse(e,t,i){this._diffuse.set(e,t,i);const n=this._renderNode;if(n){let r=9*n._lightsNames.indexOf(this._name);-1!=r&&(n._lightsParamsv[r+3]=e,n._lightsParamsv[r+4]=t,n._lightsParamsv[r+5]=i)}}setSpecular(e,t,i){this._specular.set(e,t,i);const n=this._renderNode;if(n){let r=9*n._lightsNames.indexOf(this._name);-1!=r&&(n._lightsParamsv[r+6]=e,n._lightsParamsv[r+7]=t,n._lightsParamsv[r+8]=i)}}setShininess(e){this._shininess=e;const t=this._renderNode;if(t){let i=t._lightsNames.indexOf(this._name);-1!=i&&(t._lightsParamsf[i]=e)}}setBlack(){this._ambient.clear(),this._diffuse.clear(),this._specular.clear(),this._shininess=0;const e=this._renderNode;if(e){let t=9*e._lightsNames.indexOf(this._name);-1!==t&&(e._lightsParamsv[t]=e._lightsParamsv[t+1]=e._lightsParamsv[t+2]=e._lightsParamsv[t+3]=e._lightsParamsv[t+4]=e._lightsParamsv[t+5]=e._lightsParamsv[t+6]=e._lightsParamsv[t+7]=e._lightsParamsv[t+8]=0)}}addTo(e){this._renderNode=e,e._lights.push(this),e._lightsNames.push(this._name),e._lightsParamsf.push(this._shininess),e._lightsParamsv.push.apply(e._lightsParamsv,this._ambient.toArray()),e._lightsParamsv.push.apply(e._lightsParamsv,this._diffuse.toArray()),e._lightsParamsv.push.apply(e._lightsParamsv,this._specular.toArray()),e.transformLights()}remove(){this._renderNode,this._renderNode=null}}Or.__counter__=0;class Vr extends It{constructor(e={}){super({autoActivate:!0,...e}),this._name="sun",this.activationHeight=e.activationHeight||12079e3,this.offsetVertical=e.offsetVertical||-5e6,this.offsetHorizontal=e.offsetHorizontal||5e6,this.sunlight=new Or("Sun",{ambient:new oe(.15,.15,.25),diffuse:new oe(.9,.9,.8),specular:new oe(.1,.1,.06),shininess:110}),this._currDate=0,this._prevDate=0,this._clockPtr=null,this._lightOn=!1,this._f=0,this._k=0,this._stopped=e.stopped||!1}oninit(){this.planet.lightEnabled=!0,this.sunlight.addTo(this.planet),this.renderer.events.on("draw",this._draw,this),this._clockPtr||(this._clockPtr=this.renderer.handler.defaultClock)}stop(){this._stopped=!0,this.deactivate()}start(){this._stopped=!1,this.activate()}onactivate(){super.onactivate(),this._stopped=!1}bindClock(e){this._clockPtr=e}_draw(){if(this._clockPtr)if(this._currDate=this._clockPtr.currentDate,this._stopped)this.sunlight.setPosition3v(Hr(this._currDate));else{let e=this.planet.camera;if(e.getHeight()<this.activationHeight||!this._active){this._lightOn=!0,this._f=1;let t=e.eye.normal(),i=e.getForward();i.scale(Math.sign(e._u.dot(t))),e.slope>.99&&(i=e._u);let n=oe.proj_b_to_plane(i,t,i).normalize().scale(this.offsetVertical),r=oe.proj_b_to_plane(e._r,t,e._r).normalize().scale(this.offsetHorizontal),s=n.add(r),a=e.eye.add(s);if(this._k>0){this._k-=.01;let e=ae.getRotationBetweenVectors(this.sunlight._position.normal(),a.normal()).slerp(ae.IDENTITY,this._k).normalize();this.sunlight.setPosition3v(e.mulVec3(this.sunlight._position))}else this.sunlight.setPosition3v(a)}else if(this._k=1,this._f>0){this._f-=.01;let e=ae.getRotationBetweenVectors(this.sunlight._position.normal(),Hr(this._currDate).normal()).slerp(ae.IDENTITY,this._f).normalize();this.sunlight.setPosition3v(e.mulVec3(this.sunlight._position))}else(Math.abs(this._currDate-this._prevDate)>34e-5&&this._active||this._lightOn)&&(this._lightOn=!1,this._prevDate=this._currDate,this.sunlight.setPosition3v(Hr(this._currDate)),this._f=0)}}}class Ur{constructor(){this.x=0,this.y=0,this.prev_x=0,this.prev_y=0,this.grabbedPoint=null,this.grabbedSpheroid=new At,this._vec=new le,this._vecPrev=new le}get dY(){return this.y-this.prev_y}get dX(){return this.x-this.prev_x}get vec(){return this._vec.set(this.x,this.y)}get vecPrev(){return this._vecPrev.set(this.prev_x,this.prev_y)}}class Gr extends It{constructor(e={}){super(e),this._name="touchNavigation",this.grabbedPoint=new oe,this.inertia=.007,this.grabbedSpheroid=new At,this.planet=null,this.qRot=new ae,this.scaleRot=0,this.rot=1,this._eye0=new oe,this.pointOnEarth=null,this.earthUp=null,this.touches=[new Ur,new Ur],this._keyLock=new xr,this._touching=!1}oninit(){this.renderer&&(this.renderer.events.on("touchstart",this.onTouchStart,this),this.renderer.events.on("touchend",this.onTouchEnd,this),this.renderer.events.on("doubletouch",this.onDoubleTouch,this),this.renderer.events.on("touchcancel",this.onTouchCancel,this),this.renderer.events.on("touchmove",this.onTouchMove,this),this.renderer.events.on("draw",this.onDraw,this))}onTouchStart(e){const t=this.renderer.handler;if(this._touching=!0,2===e.sys.touches.length){const i=this.touches[0],n=this.touches[1];i.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*t.pixelRatio,i.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*t.pixelRatio,i.prev_x=i.x,i.prev_y=i.y,i.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new le(i.x,i.y))||null,n.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*t.pixelRatio,n.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*t.pixelRatio,n.prev_x=n.x,n.prev_y=n.y,n.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new le(n.x,n.y))||null,this.pointOnEarth=this.planet.getCartesianFromPixelTerrain(this.renderer.handler.getCenter())||null,this.pointOnEarth&&(this.earthUp=this.pointOnEarth.normal()),i.grabbedPoint&&n.grabbedPoint&&(i.grabbedSpheroid.radius=i.grabbedPoint.length(),n.grabbedSpheroid.radius=n.grabbedPoint.length(),this.stopRotation())}else 1===e.sys.touches.length&&this._startTouchOne(e)}_startTouchOne(e){const t=this.touches[0],i=this.renderer.handler;t.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,t.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,t.prev_x=t.x,t.prev_y=t.y,t.grabbedPoint=this.planet.getCartesianFromPixelTerrain(e)||null,this._eye0.copy(this.planet.camera.eye),t.grabbedPoint&&(t.grabbedSpheroid.radius=t.grabbedPoint.length(),this.stopRotation())}stopRotation(){this.qRot.clear(),this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}onDoubleTouch(e){this.planet.stopFlying(),this.stopRotation();const t=this.planet.getCartesianFromPixelTerrain(e);if(t){const e=this.planet.ellipsoid.cartesianToLonLat(t);this.planet.flyLonLat(new z(e.lon,e.lat,.57*this.planet.camera.eye.distance(t)))}}onTouchEnd(e){0===e.sys.touches.length&&(this._touching=!1),1===e.sys.touches.length&&this._startTouchOne(e),Math.abs(this.touches[0].x-this.touches[0].prev_x)<3&&Math.abs(this.touches[0].y-this.touches[0].prev_y)<3&&(this.scaleRot=0)}onTouchCancel(e){}onTouchMove(e){let t=this.planet.camera;const i=this.renderer.handler;if(2===e.sys.touches.length){this.renderer.controlsBag.scaleRot=1;let r=this.touches[0],s=this.touches[1];if(!r.grabbedPoint||!s.grabbedPoint)return;this.planet.stopFlying(),r.prev_x=r.x,r.prev_y=r.y,r.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,r.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,s.prev_x=s.x,s.prev_y=s.y,s.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*i.pixelRatio,s.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*i.pixelRatio;const a=r.vec.add(s.vec).scale(.5),l=this.planet.getCartesianFromPixelTerrain(a);if(l){this.pointOnEarth=l;const e=Math.atan2(r.prev_y-s.prev_y,r.prev_x-s.prev_x),i=Math.atan2(r.y-s.y,r.x-s.x)-e,a=t.eye.distance(this.pointOnEarth),h=r.vec.sub(s.vec),c=r.vecPrev.sub(s.vecPrev);let d=a*-(1-h.length()/c.length());t.eye.addA(t.getForward().scale(d)),t.rotateAround(-i,!1,this.pointOnEarth,this.earthUp);const _=r.vec.add(s.vec).scale(.5),u=r.vecPrev.add(s.vecPrev).scale(.5),f=_.sub(u).scale(-1);var n=.5/a*t._lonLat.height*o;n>.003&&(n=.003),t.rotateHorizontal(n*-f.x,!1,this.pointOnEarth,this.earthUp),t.rotateVertical(n*-f.y,this.pointOnEarth),t.checkTerrainCollision(),t.update()}this.scaleRot=0}else if(1===e.sys.touches.length){let n=this.touches[0];if(n.prev_x=n.x,n.prev_y=n.y,n.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,n.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,!n.grabbedPoint)return;this.planet.stopFlying();let r=e.direction,s=new _i(t.eye,r).hitSphere(n.grabbedSpheroid);if(s)if(t.slope>.2){this.qRot=ae.getRotationBetweenVectors(s.normal(),n.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t._r=e.mulVec3(t._r),t._u=e.mulVec3(t._u),t._b=e.mulVec3(t._b),t.checkTerrainCollision(),t.update(),this.scaleRot=1}else{let e=n.grabbedPoint,i=oe.add(e,t._u),r=oe.add(e,e.normal()),s=t.unproject(n.x,n.y),a=new oe;new _i(t.eye,s).hitPlane(e,i,r,a)===_i.INSIDE&&(t.eye=this._eye0.addA(a.subA(e).negate()),t.checkTerrainCollision(),t.update(),this.scaleRot=0)}}}onDraw(){const e=this.renderer;if(e.controlsBag.scaleRot=this.scaleRot,this._touching)return;let t=this.planet.camera,i=t.eye.clone();if(!e.events.mouseState.leftButtonDown&&this.scaleRot){if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{e.controlsBag.scaleRot=this.scaleRot;let i=this.qRot.slerp(ae.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize();i.x||i.y||i.z||(this.scaleRot=0),t.eye=i.mulVec3(t.eye),t._r=i.mulVec3(t._r),t._u=i.mulVec3(t._u),t._b=i.mulVec3(t._b),t.checkTerrainCollision(),t.update()}t.eye.distance(i)/t.getAltitude()>.01?(this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock)):(this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock))}}}class Wr extends It{constructor(e={}){super(e),this._keyLock=new xr,this._move=0,this._targetPoint=null}oninit(){let e=new Rt({classList:["og-map-button","og-zoomin-button"],icon:'<?xml version="1.0"?><svg width=24 height=24 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M 11 5 L 11 11 L 5 11 L 5 13 L 11 13 L 11 19 L 13 19 L 13 13 L 19 13 L 19 11 L 13 11 L 13 5 L 11 5 z"/></svg>'});e.appendTo(this.renderer.div);let t=new Rt({classList:["og-map-button","og-zoomout-button"],icon:'<?xml version="1.0"?><svg width=24 height=24 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M 5 11 L 5 13 L 19 13 L 19 11 L 5 11 z"/></svg>'});t.appendTo(this.renderer.div),e.events.on("mousedown",(()=>this.zoomIn())),e.events.on("mouseup",(()=>this.stopZoom())),t.events.on("mousedown",(()=>this.zoomOut())),t.events.on("mouseup",(()=>this.stopZoom())),e.events.on("touchstart",(()=>this.zoomIn())),e.events.on("touchend",(()=>this.stopZoom())),e.events.on("touchcancel",(()=>this.stopZoom())),t.events.on("touchstart",(()=>this.zoomOut())),t.events.on("touchend",(()=>this.stopZoom())),t.events.on("touchcancel",(()=>this.stopZoom())),this.renderer.events.on("draw",this._draw,this)}zoomIn(){this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this._targetPoint=this.renderer.getCenter(),this._move=1}zoomOut(){this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this._targetPoint=this.renderer.getCenter(),this._move=-1}stopZoom(){this._move=0,this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}_draw(e){const t=this.planet.camera;if(0!==this._move){const i=this.planet.getCartesianFromPixelTerrain(e.getCenter());if(i){let e=.035*t.eye.distance(i);t.eye.addA(t.getForward().scale(this._move*e)),t.checkTerrainCollision(),t.update()}}}}class jr extends Pi{constructor(e={}){super(e.name),this._ignoreTerrain=!1,this.events=new Mt(Yr),this._ignoreTerrain=null==e.ignoreTerrain||e.ignoreTerrain,this._onSelect=e.onSelect||null,this._autoSelectionHide=e.autoSelectionHide||!1,this._planet=e.planet||null,this._startLonLat=null,this._heading=0,this._propsLabel=new Ai({name:"propsLabel",label:{text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,18]}}),this._propsLabel?.label?.setVisibility(!1),this._trackEntity=new Ai({polyline:{path3v:[],thickness:3.8,color:"rgb(455,455,455)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01;let t=gi.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);this._cornerEntity=[new Ai({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(0,305,0)",object3d:t},properties:{name:"start"}}),new Ai({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(455,0,0)",object3d:t},properties:{name:"end"}})],this._trackLayer=new In("track",{entities:[this._trackEntity,this._propsLabel],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!1}),this._cornersLayer=new In("corners",{entities:[this._cornerEntity[0],this._cornerEntity[1]],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,4e6,.01],pickingScale:2})}set ignoreTerrain(e){this._ignoreTerrain=e}bindPlanet(e){this._planet=e}init(){this._activate()}onremove(){this._deactivate()}_activate(){this._propsLabel?.label?.setVisibility(!1),this._onMouseMove_=this._onMouseMove.bind(this),this.renderer?.events.on("mousemove",this._onMouseMove_,this),this._onMouseLdown_=this._onMouseLdown.bind(this),this.renderer?.events.on("ldown",this._onMouseLdown_,this),this._onMouseLup_=this._onMouseLup.bind(this),this.renderer?.events.on("lup",this._onMouseLup_,this),this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._cornersLayer)}_deactivate(){this._startLonLat=null,this._trackLayer.remove(),this._cornersLayer.remove(),this.renderer?.events.off("mousemove",this._onMouseMove_),this.renderer?.events.off("ldown",this._onMouseLdown_),this.renderer?.events.off("lup",this._onMouseLup_),this.clear(),this._onMouseMove_=null,this._onMouseLdown_=null,this._onMouseLup_=null}_onMouseLdown(e){if(e.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.renderer.handler.canvas.style.cursor="pointer",!this._startLonLat){this._propsLabel.label?.setVisibility(!1),this._trackEntity.polyline?.setPath3v([]),this._cornerEntity[0].geoObject?.setVisibility(!0),this._cornerEntity[1].geoObject?.setVisibility(!0),this.renderer?.controls.mouseNavigation?.deactivate(),this._startLonLat=this._planet.getLonLatFromPixelTerrain(e);let t=this._planet.ellipsoid.lonLatToCartesian(this._startLonLat);this._cornerEntity[0].setCartesian3v(t),this._cornerEntity[1].setCartesian3v(t)}}_onMouseLup(e){if(this._startLonLat){if(this._pickedCorner=null,this._anchorLonLat=null,this._propsLabel.label?.setVisibility(!0),this._onSelect&&"function"==typeof this._onSelect){let e=this._cornerEntity[0].getLonLat(),t=this._cornerEntity[1].getLonLat(),i=[Math.min(e.lon,t.lon),Math.min(e.lat,t.lat),Math.max(e.lon,t.lon),Math.max(e.lat,t.lat)];this._onSelect(i)}this._autoSelectionHide&&this.clear(),this._startLonLat=null}e.renderer.handler.canvas.style.cursor="default",this.renderer?.controls.mouseNavigation?.activate()}_drawLine(e,t,i){i||(i=this._planet.ellipsoid.lonLatToCartesian(e));let n=this._planet.ellipsoid.lonLatToCartesian(t),r=this._planet.ellipsoid.direct(e,t);this._heading=r.initialAzimuth;let s=[];this._cornerEntity[0].setCartesian3v(i),this._cornerEntity[1].setCartesian3v(n);let a=[i,this._planet.ellipsoid.lonLatToCartesian(new z(t.lon,e.lat,e.height)),n,this._planet.ellipsoid.lonLatToCartesian(new z(e.lon,t.lat,e.height)),i];s.push(i);let o=(e,t)=>{let i=t.sub(e),n=i.length();i.normalize();for(let t=0;t<120;t++){let r=i.scaleTo(t*n/120).addA(e);s.push(r)}};for(let e=0;e<a.length-1;e++)o(a[e],a[e+1]);this._trackEntity.polyline?.setPath3v([s]),this._ignoreTerrain}_onMouseMove(e){if(this._startLonLat){this._propsLabel.label?.setVisibility(!0);let t=this._planet.getLonLatFromPixelTerrain(e);if(!t)return;this._drawLine(this._startLonLat,t)}}clear(){this._trackEntity.polyline?.clear(),this._cornerEntity[0].geoObject?.setVisibility(!1),this._cornerEntity[1].geoObject?.setVisibility(!1)}frame(){let e=this._trackEntity.polyline?.getPath3v()[0];if(e&&!this._ignoreTerrain){let i=0;for(let t=0,n=e.length-1;t<n;t++)i+=e[t+1].distance(e[t]);this._propsLabel.setCartesian3v(e[Math.floor(e.length/2)]),this._propsLabel.label?.setText(`${t=i,t>1e3?`${(t/1e3).toFixed(1)} km`:t>9?`${Math.round(t)} m`:`${t.toFixed(1)} m`}, ${Math.round(this._heading)} deg`)}var t}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Yr=["add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];function qr(e,t){return new Date(+e+1e3*t)}function Xr(e,t=!0,i=!1){let n=Qr[e.getMonth()],r=e.getUTCDate(),s=e.getUTCFullYear();if(t){let t=e.getUTCHours().toString().padStart(2,"0"),a=e.getUTCMinutes().toString().padStart(2,"0"),o=e.getUTCSeconds().toString().padStart(2,"0");if(i){return`${n} ${r} ${s} ${t}:${a}:${o}.${e.getUTCMilliseconds().toString().padStart(3,"0")}`}return`${n} ${r} ${s} ${t}:${a}:${o}`}return`${n} ${r} ${s}`}function Zr(e,t=0,i=10,n=2,r="white"){e.lineWidth=n,e.strokeStyle=r,e.beginPath(),e.moveTo(t,0),e.lineTo(t,i),e.stroke()}function $r(e,t,i,n,r="12px Arial",s="black",a="left",l="bottom",h=0){e.save(),e.translate(i,n),e.rotate(h*o),e.fillStyle=s,e.textBaseline=l,e.font=r,e.textAlign=a,e.fillText(t,0,0),e.restore()}const Kr=[[.001,10],[.002,10],[.005,10],[.01,10],[.02,10],[.05,10],[.1,10],[.25,10],[.5,5],[1,10],[2,10],[5,5],[10,10],[15,15],[30,6],[60,12],[120,12],[300,5],[600,10],[900,15],[1800,6],[3600,12],[7200,10],[14400,4],[21600,6],[43200,12],[86400,24],[172800,2],[345600,4],[604800,7],[1296e3,15],[2592e3,5],[5184e3,6],[7776e3,9],[15552e3,18],[31536e3,12],[63072e3,2],[126144e3,4],[15768e4,5],[31536e4,10],[63072e4,2],[126144e4,4],[15768e5,5],[31536e5,10],[63072e5,2],[126144e5,4],[15768e6,5],[31536e6,10]];const Qr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Jr=["change","current"];class es{constructor(e={}){this.events=Pt(Jr),this._current=e.current||new Date,this._rangeStart=e.rangeStart||new Date,this._rangeEnd=e.rangeEnd||qr(this._rangeStart,3600),this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this._minDate=e.minDate||null,this._maxDate=e.maxDate||null,this.multiplier=null!=e.multiplier?e.multiplier:1,this._requestAnimationFrameId=0,this._prevNow=0,this.dt=0}play(){this._requestAnimationFrameId||(this._prevNow=window.performance.now(),this._animationFrameCallback())}stop(){this._requestAnimationFrameId&&(window.cancelAnimationFrame(this._requestAnimationFrameId),this._requestAnimationFrameId=0)}stopped(){return 0==this._requestAnimationFrameId}_animationFrameCallback(){this._requestAnimationFrameId=window.requestAnimationFrame((()=>{this._frame(),this._animationFrameCallback()}))}_frame(){let e=window.performance.now();this.dt=e-this._prevNow,this._prevNow=e,this.current=new Date(this.currentTime+this.dt*this.multiplier)}get range(){return this._range}set(e,t){e===this._rangeStart&&t===this._rangeEnd||(this._rangeStart=e,this._rangeEnd=t,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e,t))}get current(){return this._current}get rangeStart(){return this._rangeStart}get rangeEnd(){return this._rangeEnd}get rangeStartTime(){return this._rangeStart.getTime()}get rangeEndTime(){return this._rangeEnd.getTime()}get currentTime(){return this._current.getTime()}set current(e){e!==this._current&&(this._maxDate&&e>this._maxDate?this._current=this._maxDate:this._minDate&&e<this._minDate?this._current=this._minDate:this._current=e,this.events.dispatch(this.events.current,this._current))}set rangeStart(e){e!==this._rangeStart&&(this._rangeStart=e,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e))}set rangeEnd(e){e!==this._rangeEnd&&(this._rangeEnd=e,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e))}}const ts=.001,is=["startdrag","stopdrag","startdragcurrent","stopdragcurrent","setcurrent","reset","play","playback","pause","visibility"],ns="#bfbfbf";class rs extends Bt{constructor(e={}){super({template:'<div class="og-timeline">\n\n <div class="og-timeline-top">\n </div>\n\n <div class="og-timeline-frame">\n <div class="og-timeline-current">\n <div class="og-timeline-current-spin">\n <div class="og-timeline-current-arrow"></div>\n </div>\n </div>\n <div class="og-timeline-scale"></div>\n </div>\n\n <div class="og-timeline-bottom">\n <div class="og-timeline-controls">\n </div>\n </div>\n\n</div>',model:new es({rangeStart:e.rangeStart,rangeEnd:e.rangeEnd,current:e.currentDate,minDate:e.minDate,maxDate:e.maxDate})}),this._onMouseWheel=e=>{if(this._isMouseOver){let t=this._canvasEl.getBoundingClientRect(),i=e.clientX-t.left,n=-(i-.5*this.clientWidth),r=this.model.rangeStartTime+this._millisecondsInPixel*i;this._zoom(r,n,Math.sign(e.wheelDelta))}else if(this._isCurrentMouseOver){let t=-((this.model.currentTime-this.model.rangeStartTime)/this._millisecondsInPixel-.5*this.clientWidth);this._zoom(this.model.currentTime,t,Math.sign(e.wheelDelta))}},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onMouseDown=e=>{this._isMouseOver?(this._isDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._clickTime=Date.now(),this._clickRangeStart=this.model.rangeStart,this._clickRangeEnd=this.model.rangeEnd,this.events.dispatch(this.events.startdrag,e)):this._isCurrentMouseOver&&(this._isCurrentDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._clickCurrentDate=this.model.current,this.events.dispatch(this.events.startdragcurrent,e))},this._onMouseUp=e=>{if(this._isDragging)if(this._isDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this._clickPosX===e.clientX&&Date.now()-this._clickTime<this._clickDelay){let t=this._canvasEl.getBoundingClientRect(),i=new Date(this.model.rangeStartTime+(e.clientX-t.left)*this._millisecondsInPixel);this.model.current=i,this.events.dispatch(this.events.stopdrag,i),this.events.dispatch(this.events.setcurrent,i)}else this.events.dispatch(this.events.stopdrag,this.model.current);else this._isCurrentDragging&&(this._isCurrentDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this.events.dispatch(this.events.stopdragcurrent,this.model.current))},this._onMouseEnter=()=>{this._isMouseOver=!0},this._onMouseOut=()=>{this._isMouseOver=!1},this._onCurrentMouseEnter=()=>{this._isCurrentMouseOver=!0},this._onCurrentMouseOut=()=>{this._isCurrentMouseOver=!1},this._onMouseMove=e=>{if(this._isDragging){let t=(this._clickPosX-e.clientX)*this._millisecondsInPixel*ts;this.model.set(qr(this._clickRangeStart,t),qr(this._clickRangeEnd,t))}else if(this._isCurrentDragging){let t=(this._clickPosX-e.clientX)*this._millisecondsInPixel*ts,i=qr(this._clickCurrentDate,-t);i>=this.model.rangeStart&&i<=this.model.rangeEnd&&(this.model.current=qr(this._clickCurrentDate,-t))}},this.events=this.events.registerNames(is),this.fillStyle=e.fillStyle||"rgba(64, 59, 59, 1.0)",this.$controls=null,this._frameEl=null,this._currentEl=null,this._canvasEl=document.createElement("canvas"),this._ctx=this._canvasEl.getContext("2d"),this._isMouseOver=!1,this._isDragging=!1,this._isCurrentDragging=!1,this._isCurrentMouseOver=!1,this._minWidth=330,this._canvasScale=2,this._millisecondsInPixel=0,this._clickPosX=0,this._clickRangeStart=new Date,this._clickRangeEnd=new Date,this._clickCurrentDate=new Date,this._clickTime=0,this._clickDelay=450,this._onResizeObserver_=this._onResizeObserver.bind(this),this._resizeObserver=new ResizeObserver(this._onResizeObserver_),this._pauseBtn=new Ot({classList:["og-timeline-control_button"],icon:'<?xml version="1.0" ?><!DOCTYPE svg PUBLIC \'-//W3C//DTD SVG 1.1//EN\' \'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\'><svg enable-background="new 0 0 512 512" height="512px" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="Layer_6"><rect fill="#252525" height="320" width="60" x="153" y="96"/><rect fill="#252525" height="320" width="60" x="299" y="96"/></g></svg>',name:"pause"}),this._playBtn=new Ot({classList:["og-timeline-control_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M8 5v14l11-7z" style="fill: black;"/></svg>',name:"play"}),this._buttons=new Qt({buttons:[this._pauseBtn,this._playBtn]}),this._visibility=!1}_onResizeObserver(){this.resize()}get canvasScale(){return this._canvasScale}set canvasScale(e){e!==this._canvasScale&&(this._canvasScale=e,this.resize())}resize(){this._resize(),this.draw()}afterRender(e){this.resize()}render(){return super.render(),this.$controls=this.select(".og-timeline-controls"),this._frameEl=this.select(".og-timeline-frame"),this._currentEl=this.select(".og-timeline-current"),this.select(".og-timeline-frame .og-timeline-scale").appendChild(this._canvasEl),this._resizeObserver.observe(this.el),this.model.events.on("change",(()=>{this.draw()})),this.model.events.on("current",(e=>{this._drawCurrent(),this.events.dispatch(this.events.setcurrent,e)})),this._canvasEl.addEventListener("mouseenter",this._onMouseEnter),this._canvasEl.addEventListener("mouseout",this._onMouseOut),this._currentEl.addEventListener("mouseenter",this._onCurrentMouseEnter),this._currentEl.addEventListener("mouseout",this._onCurrentMouseOut),document.body.addEventListener("mousemove",this._onMouseMove),document.body.addEventListener("mousedown",this._onMouseDown),document.body.addEventListener("mouseup",this._onMouseUp),document.body.addEventListener("wheel",this._onMouseWheelFF),this._playBtn.appendTo(this.$controls),this._pauseBtn.appendTo(this.$controls),this.model.stopped()?(this._pauseBtn.setActive(!0,!0),this._pauseBtn.preventClick=!0):(this._playBtn.setActive(!0,!0),this._playBtn.preventClick=!0),this._buttons.events.on("change",(e=>{switch(e.name){case"play":this.play();break;case"pause":this.pause()}})),this.setVisibility(!0),this}setVisibility(e){e!==this._visibility&&(this._visibility=e,this.el&&(this.el.style.display=e?"block":"none"),this.events.dispatch(this.events.visibility,e))}reset(){this.model.stop(),this.events.dispatch(this.events.reset,this.model)}play(){this.model.multiplier=Math.abs(this.model.multiplier),this.model.play(),this.events.dispatch(this.events.play,this.model)}pause(){this.model.stop(),this.events.dispatch(this.events.pause,this.model)}playBack(){this.model.multiplier=-1*Math.abs(this.model.multiplier),this.model.play(),this.events.dispatch(this.events.playback,this.model)}_zoom(e,t,i){let n=(e-(this.model.rangeStartTime+.5*this.model.range))*ts,r=qr(this.model.rangeStart,n),s=qr(this.model.rangeEnd,n),a=(s.getTime()-r.getTime())/20*ts,o=qr(r,a*i),l=qr(s,-a*i),h=(l.getTime()-o.getTime())/this.clientWidth;if(h<31536e6&&h>.1){let e=h*t*ts;this.model.set(qr(o,e),qr(l,e))}}get clientWidth(){return this._canvasEl?this._canvasEl.width/this._canvasScale:0}get clientHeight(){return this._canvasEl?this._canvasEl.height/this._canvasScale:0}_resize(){this._frameEl&&(this._canvasEl.width=this._frameEl.clientWidth*this._canvasScale,this._canvasEl.height=this._frameEl.clientHeight*this._canvasScale,this._canvasEl.style.width=`${this._frameEl.clientWidth}px`,this._canvasEl.style.height=`${this._frameEl.clientHeight}px`)}getOffsetByTime(e){return(e-this.model.rangeStartTime)/this._millisecondsInPixel}remove(){super.remove(),this.model.stop()}_clearCanvas(){this._ctx.fillStyle=this.fillStyle,this._ctx.fillRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}_drawCurrent(){let e=(this.model.currentTime-this.model.rangeStartTime)/this._millisecondsInPixel;this.model.current<this.model.rangeStart||this.model.current>this.model.rangeEnd?this._currentEl.style.display="none":(this._currentEl.style.display="block",this._currentEl.style.transform=`translateX(${e}px)`)}draw(){this._millisecondsInPixel=this.model.range/this.clientWidth;let e=function(e){for(let t=0,i=Kr.length;t<i;t++)if(Kr[t][0]>e)return Kr[t-1]}(this._minWidth*this._millisecondsInPixel*ts);if(e){this._clearCanvas();let i=1e3*e[0],n=i/this._millisecondsInPixel,r=e[1],s=(t=this.model.rangeStartTime)-t%i,a=e[0]<1,o=e[0]<86400;for(let e=s,t=this.model.rangeEndTime+i;e<t;e+=i){let t=this.getOffsetByTime(e);t>=0&&t<=this.clientWidth*this._canvasScale&&Zr(this._ctx,t*this._canvasScale,10*this._canvasScale,2*this._canvasScale,ns);for(let e=1;e<r;e++){let i=t+e*(n/r);i>=0&&i<=this.clientWidth*this._canvasScale&&Zr(this._ctx,i*this._canvasScale,5*this._canvasScale,1*this._canvasScale,ns)}$r(this._ctx,Xr(new Date(e),o,a),t*this._canvasScale,26*this._canvasScale,"24px monospace","#bfbfbf","center")}this._drawCurrent()}var t}}function ss(e,t){const i=new Date(e);return i.setHours(i.getHours()+t),i}class as{constructor(){this.resolve=()=>{},this.reject=()=>{},this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t})),Object.freeze(this)}}const os=["startcollecting","profilecollected","clear"];class ls{constructor(e={}){this.events=Pt(os),this.planet=e.planet||null,this._warningHeightLevel=5,this._pointsReady=!1,this._isWarning=!1,this._minX=0,this._planeDistance=this._maxX=1e3,this._minY=0,this._maxY=200,this._drawData=[[],[]],this._promiseArr=[],this._promiseCounter=0,this._pMaxY=0,this._pMinY=0,this._pDist=0,this._pTrackCoords=[],this._pGroundCoords=[],this._pIndex=0}bindPlanet(e){this.planet=e}setWarningHeightLevel(e=0){this._warningHeightLevel=e}setRange(e,t,i,n){this._minX=e,this._maxX=t,i&&(this._minY=i),n&&(this._maxY=n)}_getHeightAsync(e,t,i){let n=new as;if(this.planet){let r=this.planet.terrain.geoid.getHeightLonLat(e);this.planet.terrain.getHeightAsync(e,(s=>{this.planet&&i===this._promiseCounter?(s+=r,this._pGroundCoords[t][1]=s,this._pGroundCoords[t][2]=0,this._pGroundCoords[t][3]=e.height,s>this._pMaxY&&(this._pMaxY=s),s<this._pMinY&&(this._pMinY=s),this._updatePointType(t),n.resolve(s)):n.reject()}))}else n.reject();return n.promise}_collectCoordsBetweenTwoTrackPoints(e,t,i,n,r,s){if(this.planet)for(let a=1;a<=t;a++){this._pDist+=1,this._pIndex++;let t=a*i,o=n.add(r.scaleTo(t)),l=this.planet.ellipsoid.cartesianToLonLat(o);this._pGroundCoords[this._pIndex]=[this._pDist,0,0,0,e],((e,t)=>{this._promiseArr.push(this._getHeightAsync(e,t,s))})(l,this._pIndex)}}_collectAllPoints(e,t){if(!this.planet)return;if(t!==this._promiseCounter)return;let i=new oe,n=new oe;for(let r=1,s=e.length;r<s;r++){let s=e[r-1],a=e[r];this.planet.ellipsoid.lonLatToCartesianRes(s,i),this.planet.ellipsoid.lonLatToCartesianRes(a,n);let o=n.sub(i),l=o.length(),h=this.planet.ellipsoid.getSurfaceNormal3v(i),c=oe.proj_b_to_plane(o,h),d=c.length(),_=Math.floor(d/1),u=1*l/d;this._getGroundElevation(s,r-1,t),c.normalize(),o.normalize(),this._collectCoordsBetweenTwoTrackPoints(r-1,_,u,i,o,t),this._pDist+=d-1*_,this._pIndex++;let f=a.height;f>this._pMaxY&&(this._pMaxY=f),f<this._pMinY&&(this._pMinY=f),this._pTrackCoords[r]=[this._pDist,f,this._pIndex]}}_getGroundElevation(e,t,i){this._pGroundCoords[this._pIndex]=[this._pDist,0,0,0,t],this._promiseArr.push(this._getHeightAsync(e,this._pIndex,i))}_calcPointsAsync(e,t){return new Promise(((i,n)=>{this._pTrackCoords=[[0,e[0].height,0]],this._pMaxY=e[0].height,this._pMinY=this._pMaxY,this._pDist=0,this._pGroundCoords=[],this._pIndex=0,this._promiseArr=[],this._collectAllPoints(e,t),this._getGroundElevation(e[e.length-1],e.length-1,t),Promise.all(this._promiseArr).then((()=>{i({dist:this._pDist,minY:this._pMinY,maxY:this._pMaxY,trackCoords:this._pTrackCoords,groundCoords:this._pGroundCoords})}))}))}get minX(){return this._minX}get planeDistance(){return this._planeDistance}get maxX(){return this._maxX}get minY(){return this._minY}get maxY(){return this._maxY}get pointsReady(){return this._pointsReady}get isWarningOrCollision(){return this._isWarning}get drawData(){return this._drawData}collectProfile(e){let t=new as;return this.planet||t.reject(),this._pointsReady=!1,this._isWarning=!1,e&&e.length?(this.events.dispatch(this.events.startcollecting,this),this._promiseCounter++,(i=>{this._calcPointsAsync(e,i).then((e=>{i===this._promiseCounter&&(this._planeDistance=e.dist,this.setRange(0,e.dist,e.minY-.1*Math.abs(e.minY),e.maxY+.2*Math.abs(e.maxY)),this._pointsReady=!0,this._drawData=[e.trackCoords,e.groundCoords],this.events.dispatch(this.events.profilecollected,this._drawData,this),t.resolve(this._drawData))}))})(this._promiseCounter),t.promise):(t.reject(),t.promise)}_updatePointType(e){this._pGroundCoords[e][3]>=this._pGroundCoords[e][1]&&this._pGroundCoords[e][3]<this._pGroundCoords[e][1]+this._warningHeightLevel-.1&&(this._pGroundCoords[e][2]=1),this._pGroundCoords[e][3]<=this._pGroundCoords[e][1]+1&&(this._pGroundCoords[e][2]=2),1!==this._pGroundCoords[e][2]&&2!==this._pGroundCoords[e][2]||(this._isWarning=!0)}_setPointsType(){this._isWarning=!1,this._pTrackCoords=this._drawData[0],this._pGroundCoords=this._drawData[1];for(let e=0;e<this._pGroundCoords.length;e++)this._updatePointType(e);this._drawData[1]=this._pGroundCoords,this.events.dispatch(this.events.profilecollected,this._drawData,this)}clear(){this._promiseCounter=0,this._pointsReady=!1,this._isWarning=!1,this._drawData=[[],[]],this._pMaxY=0,this._pMinY=0,this._pDist=0,this._pTrackCoords=[],this._pGroundCoords=[],this._pIndex=0,this.events.dispatch(this.events.clear,this._drawData,this)}}const hs="rgb(198, 198, 198)",cs=[hs,"rgb(255, 255, 0)","rgb(255, 0, 0)"],ds=["startdrag","stopdrag","pointer","mouseenter","mouseleave","dblclick","tracklength","groundlength","warninglength","collisionlength"];class _s extends Bt{constructor(e={}){super({template:'<div class="og-elevationprofile">\n <div class="og-elevationprofile-loading" style="display: none;">\n <div class="loadingio-spinner-bars-r354qqyl5v">\n <div class="ldio-p0v5a1f6oz">\n <div></div>\n <div></div>\n <div></div>\n <div></div>\n </div>\n </div> \n </div> \n </div>',model:new ls}),this._onMouseDblClick=e=>{let t,i=this.$canvas.getBoundingClientRect(),n=e.clientX-i.left,r=this._leftDistance+(this._rightDistance-this._leftDistance)*n/this.clientWidth,s=this.model.drawData[1],a=this.model.drawData[0];r<0?(t=1,r=0,n=(0-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):r>this.model.planeDistance?(t=s.length-1,r=this.model.planeDistance,n=(r-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-ke(s,r,((e,t)=>e-t[0]));let o=s[t-1],l=s[t],h=(r-o[0])/(l[0]-o[0]),c=o[1]+h*(l[1]-o[1]),d=o[4],_=a[d],u=a[d+1];h=(r-_[0])/(u[0]-_[0]);let f=_[1]+h*(u[1]-_[1]);this.events.dispatch(this.events.dblclick,r,_,u,o,l,d,t-1,f-c)},this._onMouseEnter=e=>{this._isMouseOver=!0,this.events.dispatch(this.events.mouseenter,e)},this._onMouseOut=e=>{this._isMouseOver=!1,this.events.dispatch(this.events.mouseleave,e)},this._onMouseDown=e=>{this._isMouseOver&&(this._isDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX),this._clickLeftDistance=this._leftDistance,this._clickRightDistance=this._rightDistance,this.events.dispatch(this.events.startdrag,e))},this._onMouseUp=e=>{this._isDragging&&(this._isDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this.events.dispatch(this.events.stopdrag,e))},this._onCanvasMouseMove=e=>{if(this.model.pointsReady)if(this._isDragging)this.clearPointerCanvas();else{this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX);let t=this.$pointerCanvas.getBoundingClientRect(),i=e.clientX-t.left;this.redrawPointerCanvas(i)}},this._onMouseMove=e=>{if(this._isDragging&&this.model.pointsReady){let t=(this._clickPosX-e.clientX)*this._canvasScale/this._pixelsInMeter_x;this.setFrame(this._clickLeftDistance+t,this._clickRightDistance+t)}},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onMouseWheel=e=>{if(this._isMouseOver&&this.model.pointsReady){this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX),this._customFrame=!0;let t=Math.sign(e.wheelDelta)*(this._rightDistance-this._leftDistance)/20,i=this.$canvas.getBoundingClientRect(),n=e.clientX-i.left,r=n-.5*this.$canvas.clientWidth,s=r*this._canvasScale/this._pixelsInMeter_x,a=s+this._leftDistance+t,o=s+this._rightDistance-t;s=-r*(o-a)/this.clientWidth,this.setFrame(a+s,o+s),this.redrawPointerCanvas(n)}},this.events=this.events.registerNames(ds),this.fillStyle=e.fillStyle||"rgb(63, 63, 63)",this._customFrame=!1,this._leftDistance=0,this._rightDistance=0,this._pixelsInMeter_x=0,this._pixelsInMeter_y=0,this._canvasScale=2,this.$canvas=document.createElement("canvas"),this.$canvas.style.position="absolute",this._ctx=this.$canvas.getContext("2d"),this.$pointerCanvas=document.createElement("canvas"),this.$pointerCanvas.style.pointerEvents="none",this.$pointerCanvas.style.position="absolute",this._pointerCtx=this.$pointerCanvas.getContext("2d"),this.$loading=null,this._isMouseOver=!1,this._isDragging=!1,this._clickPosX=0,this._clickLeftDistance=0,this._clickRightDistance=0,this._timeStartHandler=0,this._onResizeObserver_=this._onResizeObserver.bind(this),this._resizeObserver=new ResizeObserver(this._onResizeObserver_)}_onResizeObserver(){this.resize()}get canvasScale(){return this._canvasScale}set canvasScale(e){e!==this._canvasScale&&(this._canvasScale=e,this.resize())}resize(){this._resize(),this.draw()}render(){return super.render(),this._resizeObserver.observe(this.el),this.el.appendChild(this.$canvas),this.el.appendChild(this.$pointerCanvas),this.model.events.on("profilecollected",(e=>{this._hideLoading(),this.clearPointerCanvas(),this.draw()})),this.model.events.on("startcollecting",(()=>{clearTimeout(this._timeStartHandler),this._timeStartHandler=setTimeout((()=>{this._showLoading()}),450)})),this.model.events.on("clear",(()=>{this._customFrame=!1,this._leftDistance=0,this.clearCanvas(),this.clearPointerCanvas()})),this.$loading=this.select(".og-elevationprofile-loading"),this.$canvas.addEventListener("mouseenter",this._onMouseEnter),this.$canvas.addEventListener("mouseout",this._onMouseOut),this.$canvas.addEventListener("dblclick",this._onMouseDblClick),this.$canvas.addEventListener("mousemove",this._onCanvasMouseMove),document.body.addEventListener("mousemove",this._onMouseMove),document.body.addEventListener("mousedown",this._onMouseDown),document.body.addEventListener("mouseup",this._onMouseUp),document.body.addEventListener("wheel",this._onMouseWheelFF),this}_hideLoading(){clearTimeout(this._timeStartHandler),this.$loading.style.display="none"}_showLoading(){this.$loading.style.display="flex"}redrawPointerCanvas(e){this.clearPointerCanvas();let t,i=this._leftDistance+(this._rightDistance-this._leftDistance)*e/this.clientWidth,n=this.model.drawData[1],r=this.model.drawData[0];i<0?(t=1,i=0,e=(0-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):i>this.model.planeDistance?(t=n.length-1,i=this.model.planeDistance,e=(i-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-ke(n,i,((e,t)=>e-t[0]));let s=n[t-1],a=n[t],o=(i-s[0])/(a[0]-s[0]),l=s[1]+o*(a[1]-s[1]),h=s[4],c=r[h],d=r[h+1];o=(i-c[0])/(d[0]-c[0]);let _=c[1]+o*(d[1]-c[1]),u=(this.model.maxY-_)*this._pixelsInMeter_y,f=(this.model.maxY-l)*this._pixelsInMeter_y;this.events.dispatch(this.events.pointer,i,c,d,s,a,h,t-1,_-l);let g=this._pointerCtx;g.lineWidth=3,g.strokeStyle="rgba(64,64,64,0.6)",g.beginPath(),g.moveTo(e*this._canvasScale,0),g.lineTo(e*this._canvasScale,this.clientHeight*this._canvasScale),g.stroke(),g.beginPath(),g.arc(e*this._canvasScale,f,4,0,2*Math.PI,!1),g.fillStyle="#FFB277",g.fill(),g.lineWidth=4,g.strokeStyle="#FFB277",g.stroke(),g.beginPath(),g.arc(e*this._canvasScale,u,4,0,2*Math.PI,!1),g.fillStyle="#FFB277",g.fill(),g.lineWidth=4,g.strokeStyle="#FFB277",g.stroke(),g.lineWidth=3,g.strokeStyle="#FFB277",g.beginPath(),g.moveTo(e*this._canvasScale,f),g.lineTo(e*this._canvasScale,u),g.stroke(),g.fillStyle="white",g.font=28/devicePixelRatio+"px Arial",g.textBaseline="middle",g.textAlign="left",g.fillText(`${Math.round(_-l).toString()} m`,(e+5)*this._canvasScale,f+.5*(u-f)),g.fillStyle="white",g.font=28/devicePixelRatio+"px Arial",g.textAlign="right";let p=$e(i);g.fillText(`${p[0]} ${p[1]}`,(e-5)*this._canvasScale,(this.clientHeight-7)*this._canvasScale)}get clientWidth(){return this.$canvas?this.$canvas.width/this._canvasScale:0}get clientHeight(){return this.$canvas?this.$canvas.height/this._canvasScale:0}_resize(){this.el&&(this.$canvas.width=this.el.clientWidth*this._canvasScale,this.$canvas.height=this.el.clientHeight*this._canvasScale,this.$canvas.style.width=`${this.el.clientWidth}px`,this.$canvas.style.height=`${this.el.clientHeight}px`,this.$pointerCanvas.width=this.el.clientWidth*this._canvasScale,this.$pointerCanvas.height=this.el.clientHeight*this._canvasScale,this.$pointerCanvas.style.width=`${this.el.clientWidth}px`,this.$pointerCanvas.style.height=`${this.el.clientHeight}px`,this._customFrame&&(this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this._rightDistance-this._leftDistance)))}clearPointerCanvas(){this._pointerCtx.fillStyle="rgba(0,0,0,0)",this._pointerCtx.clearRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}clearCanvas(){const e=this._ctx.createLinearGradient(0,0,0,this.clientHeight*this._canvasScale);e.addColorStop(0,"black"),e.addColorStop(1,this.fillStyle),this._ctx.fillStyle=e,this._ctx.fillRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}setFrame(e,t){this._leftDistance=e,this._rightDistance=t,this._customFrame=!0,this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this._rightDistance-this._leftDistance),this.model.setRange(e,t),this.draw()}_updateUnits(){this._customFrame||(this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this.model.maxX-this.model.minX)),this._pixelsInMeter_y=this._canvasScale*this.clientHeight/(this.model.maxY-this.model.minY)}clear(){this.model.clear(),this.clearCanvas()}draw(){let e=this.model.drawData[0];if(e.length>1){this._updateUnits(),this.clearCanvas();let t=this.model.drawData[1];this._drawTrack(e,t),this._drawTerrain(t),this._drawWarningAndCollision(t),this._drawLabels(e,t)}else this.clearCanvas()}_drawLabels(e,t){let i=this._ctx;if(i){let n=e[0];const r=this.model.maxY;let s=(-this._leftDistance+n[0])*this._pixelsInMeter_x,a=(r-n[1])*this._pixelsInMeter_y;t[n[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(s-4,a-4,8,8),i.stroke(),i.fillStyle="white",i.font=26/devicePixelRatio+"px Arial",i.textBaseline="bottom",i.textAlign="left",i.fillText(`${Math.round(n[1]-t[n[2]][1]).toString()} m`,s+1,a-10),i.stroke();for(let n=1,o=e.length;n<o;n++){let o=e[n];s=(-this._leftDistance+o[0])*this._pixelsInMeter_x,a=(r-o[1])*this._pixelsInMeter_y,t[o[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(s-4,a-4,8,8),i.stroke(),i.fillStyle="white",i.fillText(`${Math.round(o[1]-t[o[2]][1]).toString()} m`,s+1,a-10),i.stroke()}}}_drawTrack(e,t){let i=e[0],n=this._ctx;if(n){const r=this.model.maxY;n.lineWidth=5,n.strokeStyle="rgb(0, 255, 50)",n.beginPath(),n.moveTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(r-i[1])*this._pixelsInMeter_y);let s=0;for(let t=1,i=e.length;t<i;t++){let i=e[t];n.lineTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(r-i[1])*this._pixelsInMeter_y);let a=e[t-1],o=i[0]-a[0],l=i[1]-a[1],h=o*o,c=l*l;s+=Math.sqrt(h+c)}n.stroke(),n.lineWidth=2,n.strokeStyle="rgba(255,255,255,0.7)",n.beginPath();let a=(-this._leftDistance+i[0])*this._pixelsInMeter_x,o=(r-i[1])*this._pixelsInMeter_y,l=(r-t[i[2]][1])*this._pixelsInMeter_y;n.moveTo(a,o),n.lineTo(a,l);for(let i=1,s=e.length;i<s;i++){let s=e[i];a=(-this._leftDistance+s[0])*this._pixelsInMeter_x,o=(r-s[1])*this._pixelsInMeter_y,l=(r-t[s[2]][1])*this._pixelsInMeter_y,n.strokeStyle="rgba(255,255,255,0.7)",n.moveTo(a,o),n.lineTo(a,l)}n.stroke(),this.events.dispatch(this.events.tracklength,s)}}_drawTerrain(e){let t=e[0],i=this._ctx;if(i){const n=this.model.maxY;i.lineWidth=5,i.strokeStyle=hs,i.beginPath(),i.moveTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,this.$canvas.height),i.lineTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,(n-t[1])*this._pixelsInMeter_y);let r=0;for(let t=1,s=e.length;t<s;t++){let s=e[t];i.lineTo((-this._leftDistance+s[0])*this._pixelsInMeter_x,(n-s[1])*this._pixelsInMeter_y);let a=e[t-1],o=s[0]-a[0],l=s[1]-a[1],h=o*o,c=l*l;r+=Math.sqrt(h+c)}i.lineTo((-this._leftDistance+e[e.length-1][0])*this._pixelsInMeter_x,this.$canvas.height),i.closePath(),i.stroke(),i.save(),i.fillStyle="rgb(64, 68, 82)",i.globalAlpha=.5,i.fill(),i.restore(),i.globalAlpha=1,this.events.dispatch(this.events.groundlength,r)}}_drawWarningAndCollision(e){let t=this._ctx;if(t&&e.length>1){let i=this.model.maxY;t.lineWidth=5,t.beginPath();let n=0,r=0;for(let s=0,a=e.length-1;s<a;s++){let a=e[s],o=e[s+1];if(0!==a[2]&&0!==o[2]){let e=o[0]-a[0],s=o[1]-a[1],l=e*e,h=s*s;2===a[2]?(t.stroke(),t.beginPath(),t.strokeStyle=cs[2],r+=Math.sqrt(l+h)):1===a[2]&&(t.stroke(),t.beginPath(),t.strokeStyle=cs[1],n+=Math.sqrt(l+h)),t.moveTo((-this._leftDistance+a[0])*this._pixelsInMeter_x,(i-a[1])*this._pixelsInMeter_y),t.lineTo((-this._leftDistance+o[0])*this._pixelsInMeter_x,(i-o[1])*this._pixelsInMeter_y)}}t.stroke(),this.events.dispatch(this.events.warninglength,n),this.events.dispatch(this.events.collisionlength,r)}}}let us=gi.createCylinder(.33,0,1,20,1,!0,!1,0,0,0),fs=gi.createCylinder(.33,.33,1.1,20,1,!0,!0,0,-.55,0);const gs={startPosition:new oe,endPosition:new oe,startColor:"rgba(255,131,0,0.2)",endColor:"rgba(255,131,0,1.0)",thickness:2.7},ps={src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjEuNBNAaMQAAAiLSURBVHhe7Z0r0BxFEMcjIhAIRERERAQCgUAgEBEIBAIRiUAgIiIQiAgEIlUREQgEIgIREYFAIBCIiAgEIiIiAoGIoHimqPAKz5CP/t23/8vcbe89d/dmZ/pf9avLdZK72e6+ee3M7Imjo6Opc8o4b7xn3DIeGEOJz+Y7+C6+k+/2yjQZXOMEOGdcNe4anv4wvjV+m73bT3wGn8VneqIMlIUyeWXNGteYKTj4feNrI9W/xi/HfxxVfCffnYqyUcbJJINrzIjTxjvGV0aqn43fj/+YhSgLZUpFmd81uAbv2rLANWbAC8ZHxp+GxC8ufZ+rKGNaI1FLcC1ck3etB8U1HhCqzk8N6T/jENV7X6LsXIN008iqeXCNB+B54zND+tt4ePzHIsS1cE0SicA1e74YFdc4IgyjrhvqTP3TvJas9Bq59oP2EVzjCJw03jI0TCMBcurUDS1qBCU9PnjbwCeerwbFNQ4MVd9tQ5pyG7+v0mvHJ6N3FF3jgFwy1JPvmlipUfIFvmHY6/luEFzjANDO0fGRfm1eQ0+UzlriqzOG58tecY0985LxnYH+al5D3ZKP8Bm+83zaG66xRy4a6uzU3NZvK/nqkUEH0fNtL7jGHqBH+4EhTWEGL2ddMwYZJbjGPaGgHxuIDA7tJ/mQGdLek8A17sHTxucGiva+P6kGxbf42PP9TrjGHUmDH1V+/xokCVzjDkTwx1HvSeAat4R2SWP8CP7wko9ZmrZ3n8A1bok6fBH88SRf4/u9ksA1bgFr4ZDG+qHxpLuKLFD1YrMRrnFDLhjocfMaGl8aIjLh5sVoLa5xA140+lhxG+pHNAk7TRu7xjXQ+9TK3Jru4ecqxYB7B88YXsw6cY1rUKcv7ujlI907YLbQi1knrnEFavej05ef1ClkpZUXOxfX2AH3p6Pdz1/E6FnDi2EL19iBVu3Gbd18pdgwU+jFsIVrdHjDQHGDJ39pkojm2ovlAq5xCXqWWtETmo7uG2t3L7vGJTTbF73+6UhNARtVvZjOcY0JZ42Y45+uGK2t7BC6xoQbBoqO3/SkGpt5Gy+2M1xjw3MGGZRubgxNS5qv6dxw4hob9OuPsf90pWnizlrANRpM+sSvvwypFqBGb8W6ZWjgHjOKtn/6Ug3OMv1WrFsG4ykjqv3yxGiudbdw4U2DbvjEuL8cqSZv7TJaeNOg1b2h8nTHWIj3whuDSQOUHmcSKkPagr5wNE0afLhioOj8lSc16QvTw2nwYfk8vlB5YjnfPOZp8FX9x8kd5Uqju3kzkCYAPUQU1X+5UjPACaatBEiPcAmVrfmKIQU/Jn/qEpNCs82lSgCOL0U/Na+hcvVD8/qKMU8AjiZDsdGjfCnGl415AnyCJVSVZptIlAD3sISqEgt9ZwnAHSIU07/1SMv7T5EA7CpFPzavofKljuA5EkCbPmICqB4p1m+SAPQGQ3XqMgnAQwtCdeo6CRBTwPXqJgnAKpFQnbpDAsQcQL26RwLEzt96dZ8ECFWsSIDKFQlQuSIBKlckQOUiAThLJlSnZqOAmAeoV7N5gJgJrFd3SQCePBGqU7dIgLgbWK9mdwO1ITRUn66QADoQIlYE1SPF+gIJEGsC69PCmkDOk0WxKrgeaQf4aRIA9AiYUD2a7wuA2BlUn1gKOE8A9ouj2BtYvh42r4z+5gnATlEUHcHy9X3z+poxT4A4H6Aecfxv63wAiOXh9ah1QgioHxAnhJYr1fKz9h/SBOA0aRSnhJUrJQCP/m0lAMQ5geWr85xA0I2haAbKk4b4K08KVTMQ08LlSU37vPqHNPgiVgiVK5r4hXgvvGm4aKC4PVyOFMuNnhfABEFMCpWnjZ8YAjxfBkUiTF/q/LH0rxXrlqFBJ4friVOh6Uod+oUHRYiWIYFnzaG4QzhdqefPo/+9GK9MAJ42SQ0QtcB0pV//wtAvxTUmqBaIiaHpSff9Z0fCduEaE+gLxBNEpyliRuzctl+4xiU0Ioh5gelIsfrQ8GI6xzUuwdjxgRGalojZacOL6RzX6KDNI0wmhPKWev6tWT8P19jBFwaKDmG+0pD9tnHS8OK4gGvsgDuFUQPkr7UdvxTXuAI9Wk7nzYfykX6clwwvdi6ucQ3MKqEYFeQjxYKFvRtV/cI1roG9hDpdNNYPHl6KAWc9re31L+MaN4DHzMUUcT4iFi8bXqxW4ho3RP2Bx81raHw9al557J8Xo7W4xi24ZqAYHYwv+XztbN8qXOMW0OFQpzBuG48n+XrrTt8yrnFLWELGViMUSTC85GN8Ptvftw+ucQcYGTD7hCIJhpN8y8rtrXv8Hq5xR7hpdNdAkQT9Sz7Fx70EH1zjHlAl6Z5BdAz7k3xJLdta2bsPrnFP0j5BzBXsL/mwlzZ/GdfYA/RMbxgo5gl2l3yHL/fq7XfhGnskfSpp3DvYXKmvZs/5HwrX2DOcP6QVRVqoGOqWfMSmnFcNz6e94RoH4IyhziGLFeMmUlv4RItv8RU+83zZK65xIGjDOH9AnZoYKj6RfIFvrhqDtPcernFg2KTwpSHVvMQsvXa2bnNus+ezwXCNI6DaQOPbGoeLumZ8gC9G+9WnuMYRYeOJdh+hGiaP0mvkiF584PlmFFzjAWAxgzqJqMRESK+Ja91pAUffuMYDwvGlaSJQTU65j0DZ0+aNaztveNd+EFxjBjB3QPWYOm9Kh1WkZeUa2KDJNXnXelBcY0bQPnKs2fIj7nOsFZbLRJkp+0Hb+HW4xgzhMGuqTubEl2sC9igcYpqZ71zeH0HZKCNlpczetWSFa8wcJQO7lrtONiUQ3xh9TDbxGXxWVxNEGSjLZIKe4honxlnjdYMFqnSyhhxB8Nl8B9/Fd/LdXpkmg2ssANpdfpEsXacdZq6BJ6Tya+VZyWnnUsLG3/Fv+Lf8H/4vn8FnZd2W78bRif8BxMOwtJg5Ph4AAAAASUVORK5CYII=",color:"rgb(255,131,0)",size:[8,8]},ms={text:"",size:10.5,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"left",offset:[5,15,-5]},vs={text:"",size:10.5,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"right",offset:[-47,25,0]},ys={instanced:!0,tag:"ground-pointer",color:"rgb(0,305,0)",object3d:us},xs={instanced:!0,tag:"head-pointer",color:"rgb(305,305,0)",object3d:fs};class bs extends Pi{constructor(e={}){super("ElevationProfileScene"),this._onLClick=e=>{let t=this._planet.getCartesianFromPixelTerrain(e.pos);t&&this.addGroundPoint3vAsync(t)},this._onMouseMove=e=>{if(this._planet.getCartesianFromMouseTerrain(),this._pickedGroundEntity){let t=new le(e.x,e.y).sub(this._startClickPos),i=this._startEntityPos.add(t),n=this._planet.getCartesianFromPixelTerrain(i);n&&this.setGroundPointCartesian3v(this._pickedGroundEntity.properties.index,n)}else if(this._pickedHeadEntity){let t=this._planet.camera,i=this._pickedHeadEntity.properties.groundEntity.getCartesian(),n=this._planet.ellipsoid.getSurfaceNormal3v(i),r=i.add(n),s=i.add(t.getRight()),a=new oe;if(new _i(t.eye,e.direction).hitPlane(i,r,s,a)===_i.INSIDE){let e=oe.proj_b_to_a(a,i),t=e.sub(i).dot(i),r=i.add(n.scale(Math.sign(t)*e.distance(i)));this.setHeadPointCartesian3v(this._pickedHeadEntity.properties.index,r)}}},this._onLUp=e=>{},this._onGroundPointerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onGroundPointerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onGroundPointerLDown=e=>{this._clampToGround=!1,this.renderer.controls.mouseNavigation.deactivate(),this._pickedGroundEntity=e.pickingObject;const t=this._pickedGroundEntity.getCartesian();this._startClickPos.set(e.x,e.y),this._startEntityPos=this._planet.getPixelFromCartesian(t)},this._onGroundPointerLUp=e=>{this._clampToGround=!0,this.renderer.controls.mouseNavigation.activate(),this._pickedGroundEntity=null},this._onHeadPointerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onHeadPointerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onHeadPointerLDown=e=>{this.renderer.controls.mouseNavigation.deactivate(),this._pickedHeadEntity=e.pickingObject},this._onHeadPointerLUp=e=>{this.renderer.controls.mouseNavigation.activate(),this._pickedHeadEntity=null},this.events=Pt(ws),this._planet=e.planet||null,this._pickedGroundEntity=null,this._pickedHeadEntity=null,this._startClickPos=new le,this._startEntityPos=new le,this._clampToGround=!0,this._trackLayer=new In("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._groundPointersLayer=new In("ground-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,5e3,.02],pickingScale:1.5}),this._headPointersLayer=new In("head-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,1e4,.02],pickingScale:1}),this._columnPointersLayer=new In("column-pointers",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._trackEntity=new Ai({polyline:{path3v:[],thickness:3.8,color:"rgba(0,305,0,0.8)",isClosed:!1}}),this._trackLayer=new In("column-pointers",{entities:[this._trackEntity],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._heightsLayer=new In("heights-labels",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._pointerHeadEntity=new Ai({cartesian:new oe,billboard:ps}),this._pointerLabelEntity=new Ai({cartesian:new oe,label:ms}),this._pointerRayEntity=new Ai({cartesian:new oe,ray:gs}),this._pointerLayer=new In("pointer",{entities:[this._pointerHeadEntity,this._pointerLabelEntity,this._pointerRayEntity],pickingEnabled:!1,hideInLayerSwitcher:!0})}flyExtent(){let e=this._headPointersLayer.getEntities(),t=180,i=180,n=-180,r=-180,s=-1e6;if(e.length>1){for(let a=0;a<e.length;a++){let o=e[a].getLonLat();o.lon<t&&(t=o.lon),o.lat<i&&(i=o.lat),o.lon>n&&(n=o.lon),o.lat>r&&(r=o.lat),o.height>s&&(s=o.height)}this._planet.camera.flyExtent(new ie(new z(t,i),new z(n,r)),s,null,0)}}get planet(){return this._planet}_createGroundPointer(e,t=10){let i=this.ellipsoid.getSurfaceNormal3v(e),n=e.add(i.scale(t)),r=new Ai({ray:{startPosition:e,endPosition:n,startColor:"rgba(255,255,255,0.2)",endColor:"rgba(355,355,355,1.0)",thickness:3.2}}),s=new Ai({cartesian:e,geoObject:ys}),a=new Ai({cartesian:n,geoObject:xs,properties:{}}),o=new Ai({cartesian:n,label:vs});o.appendChild(new Ai({cartesian:n,label:{...vs,offset:[-47,45,0]}}));const l=this._groundPointersLayer.getEntities().length;return r.properties=s.properties=a.properties={index:l,altitude:t,lonLatEll:new z,headEntity:a,groundEntity:s,columnEntity:r,heightLabelEntity:o},{headEntity:a,groundEntity:s,columnEntity:r,heightLabelEntity:o}}setPointerCartesian3v(e,t){this._pointerLabelEntity.setCartesian3v(e),this._pointerLabelEntity.label.setText(`${Math.round(t).toString()} m`),this._pointerRayEntity.ray.setEndPosition3v(e);let i=this._planet.ellipsoid.getSurfaceNormal3v(e);this._pointerRayEntity.ray.setStartPosition3v(e.add(i.scale(-t))),this._pointerHeadEntity.setCartesian3v(e)}bindPlanet(e){this._planet=e}init(){this._activate()}onremove(){this._deactivate()}_activate(){this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._groundPointersLayer),this._planet.addLayer(this._columnPointersLayer),this._planet.addLayer(this._headPointersLayer),this._planet.addLayer(this._heightsLayer),this._planet.addLayer(this._pointerLayer),this.renderer.events.on("ldblclick",this._onLClick),this.renderer.events.on("mousemove",this._onMouseMove),this.renderer.events.on("lup",this._onLUp),this._groundPointersLayer.events.on("mouseenter",this._onGroundPointerEnter),this._groundPointersLayer.events.on("mouseleave",this._onGroundPointerLeave),this._groundPointersLayer.events.on("ldown",this._onGroundPointerLDown),this._groundPointersLayer.events.on("lup",this._onGroundPointerLUp),this._headPointersLayer.events.on("mouseenter",this._onHeadPointerEnter),this._headPointersLayer.events.on("mouseleave",this._onHeadPointerLeave),this._headPointersLayer.events.on("ldown",this._onHeadPointerLDown),this._headPointersLayer.events.on("lup",this._onHeadPointerLUp),this.setPointerVisibility(!1)}getPointLonLat(e){let t=this._headPointersLayer.getEntities()[e];if(t)return t.getLonLat()}getPointsLonLat(){let e=this._headPointersLayer.getEntities(),t=new Array(e.length);for(let i=0,n=t.length;i<n;i++){let n=e[i];t[i]=n.getLonLat()}return t}getHeightMSL(e){return this._planet&&this._planet.terrain.geoid?this._planet.terrain.geoid.getHeightLonLat(e):0}getHeightELLAsync(e){return new Promise(((t,i)=>{this._planet.terrain.getHeightAsync(e,(n=>{if(this._planet){let i=this.getHeightMSL(e);t(n+i)}else i()}))}))}addPointLonLatArrayAsync(e,t=!1){if(!this._planet)throw new Error("Planet is not defined");let i=this._planet.ellipsoid;for(let t=0,n=e.length-1;t<n;t++){let n=i.lonLatToCartesian(e[t]),r=i.lonLatToCartesian(e[t+1]);if(n.distance(r)>1e5)throw new Error("Track is too long! 100 km is maximum.")}let n=new Array(e.length);for(let t=0,i=e.length;t<i;t++)n[t]=this.addPointLonLatAsync(e[t],!0);return Promise.all(n).then((()=>{t||this.events.dispatch(this.events.change,this)})),n}addPointLonLatAsync(e,t=!1){let i=this._planet.ellipsoid.lonLatToCartesian(e),n=this._planet.ellipsoid.getSurfaceNormal3v(i),r=new z(e.lon,e.lat),s=this._planet.ellipsoid.lonLatToCartesian(r),{headEntity:a,groundEntity:o,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(s);return this._groundPointersLayer.add(o),this._columnPointersLayer.add(l),this._headPointersLayer.add(a),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(a.getCartesian()),o.properties.lonLatEll.lon=r.lon,o.properties.lonLatEll.lat=r.lat,o.properties.lonLatEll.height=r.height,new Promise((r=>{this.getHeightELLAsync(e).then((s=>{o.properties.lonLatEll.height=s;let l,c=10;0===e.height?(l=i.add(n.scaleTo(s)),i=l.add(n.scaleTo(c))):(c=e.height-s,l=i.sub(n.scaleTo(c))),o.setCartesian3v(l),h.setCartesian3v(i),h.label.setText(`${s.toFixed(1)} m`),h.childrenNodes[0].label.setText(`${c.toFixed(1)} m`),a.properties.altitude=c,a.setCartesian3v(i),a.properties.columnEntity.ray.setStartPosition3v(l),a.properties.columnEntity.ray.setEndPosition3v(i),this._trackEntity.polyline?.setPoint3v(i,a.properties.index),t||(this.events.dispatch(this.events.addpoint,a,this),this.events.dispatch(this.events.change,this)),r(a)}))}))}addGroundPointLonLatAsync(e,t=10,i=!1){let n=this._planet.ellipsoid.lonLatToCartesian(e);return this._addPoint(n,e,t,i)}addGroundPoint3vAsync(e,t=10,i=!1){let n=this._planet.ellipsoid.cartesianToLonLat(e);return this._addPoint(e,n,t,i)}_addPoint(e,t,i,n=!1){return new Promise(((r,s)=>{let{headEntity:a,groundEntity:o,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(e,i);this._groundPointersLayer.add(o),this._columnPointersLayer.add(l),this._headPointersLayer.add(a),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(a.getCartesian()),o.properties.lonLatEll.lon=t.lon,o.properties.lonLatEll.lat=t.lat,o.properties.lonLatEll.height=t.height,this.getHeightELLAsync(t).then((e=>{o.properties.lonLatEll.height=t.height=e;let s=this._planet.ellipsoid.lonLatToCartesian(t),l=this._planet.ellipsoid.getSurfaceNormal3v(s),c=s.add(l.scale(i));h.setCartesian3v(c),h.label.setText(`${e.toFixed(1)} m`),h.childrenNodes[0].label.setText(`${i.toFixed(1)} m`),a.setCartesian3v(c),a.properties.columnEntity.ray.setEndPosition3v(c),this._trackEntity.polyline?.setPoint3v(c,a.properties.index),n||(this.events.dispatch(this.events.addpoint,a,this),this.events.dispatch(this.events.change,this)),r(a)}))}))}setHeadPointCartesian3v(e,t){const i=this._headPointersLayer.getEntities()[e];if(i){let n=this._planet.ellipsoid.lonLatToCartesian(i.properties.lonLatEll),r=t.length()-n.length();r<=0&&(t=n,r=0),i.properties.altitude=r,i.setCartesian3v(t),i.properties.columnEntity.ray.setEndPosition3v(t),i.properties.heightLabelEntity.setCartesian3v(t),i.properties.heightLabelEntity.childrenNodes[0].label.setText(`${r.toFixed(1)} m`),this._trackEntity.polyline.setPoint3v(t,e),this.events.dispatch(this.events.change,this._pickedHeadEntity)}}setGroundPointCartesian3v(e,t){let i=this._groundPointersLayer.getEntities()[e];if(i){let e=this._planet.ellipsoid.cartesianToLonLat(t);i.properties.lonLatEll.lon=e.lon,i.properties.lonLatEll.lat=e.lat,i.properties.lonLatEll.height=e.height;let n=this._planet.ellipsoid.getSurfaceNormal3v(t),r=i.properties.headEntity,s=i.properties.heightLabelEntity,a=i.properties.altitude;i.setCartesian3v(t);let o=t.add(n.scale(a));r.setCartesian3v(o),r.properties.columnEntity.ray.setStartPosition3v(t),r.properties.columnEntity.ray.setEndPosition3v(o),this._trackEntity.polyline?.setPoint3v(o,r.properties.index),s.setCartesian3v(o),s.label.setText(`${e.height.toFixed(1)} m`),s.childrenNodes[0].label.setText(`${a.toFixed(1)} m`),this.events.dispatch(this.events.change,i.properties.headEntity)}}_deactivate(){this.renderer.events.off("ldblclick",this._onLClick),this.renderer.events.off("mousemove",this._onMouseMove),this.renderer.events.off("lup",this._onLUp),this._groundPointersLayer.events.off("mouseenter",this._onGroundPointerEnter),this._groundPointersLayer.events.off("mouseleave",this._onGroundPointerLeave),this._groundPointersLayer.events.off("ldown",this._onGroundPointerLDown),this._groundPointersLayer.events.off("lup",this._onGroundPointerLUp),this._headPointersLayer.events.off("mouseenter",this._onHeadPointerEnter),this._headPointersLayer.events.off("mouseleave",this._onHeadPointerLeave),this._headPointersLayer.events.off("ldown",this._onHeadPointerLDown),this._headPointersLayer.events.off("lup",this._onHeadPointerLUp),this._trackLayer.remove(),this._groundPointersLayer.remove(),this._headPointersLayer.remove(),this._columnPointersLayer.remove(),this._trackLayer.remove(),this._heightsLayer.remove(),this._pointerLayer.remove(),this.clear()}setPointerVisibility(e){this._pointerLayer.setVisibility(e)}setVisibility(e){this._groundPointersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._columnPointersLayer.setVisibility(e),this._headPointersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._heightsLayer.setVisibility(e),this._pointerLayer.setVisibility(e)}clear(){this._headPointersLayer.setEntities([]),this._groundPointersLayer.setEntities([]),this._columnPointersLayer.setEntities([]),this._heightsLayer.setEntities([]),this._trackEntity.polyline.setPath3v([])}frame(){if(this._clampToGround){let e=new oe;const t=this._planet._renderedNodes,i=this._groundPointersLayer.getEntities();for(let n=0;n<i.length;n++){let r=i[n];for(let i=0;i<t.length;i++){let n=t[i];if(n.segment.isEntityInside(r)){n.segment.getEntityTerrainPoint(r,e),r.setCartesian3v(e),r.properties.columnEntity.ray.setStartPosition3v(e);break}}}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const ws=["change","addpoint"],Ts=["reset","list","location"];class Cs extends Bt{constructor(e={}){super({...e,template:'<div class="og-elevationprofile-buttons"></div>'}),this.events=this.events.registerNames(Ts),this.pointListBtn=new Ot({classList:["og-elevationprofile-button"],icon:'<?xml version="1.0" encoding="utf-8"?><svg width="800px" height="800px" viewBox="0 0 32 32" id="icon" xmlns="http://www.w3.org/2000/svg"><defs><style>.cls-1{fill:none;}</style></defs><title>list</title><rect x="10" y="6" width="18" height="2"/><rect x="10" y="24" width="18" height="2"/><rect x="10" y="15" width="18" height="2"/><rect x="4" y="15" width="2" height="2"/><rect x="4" y="6" width="2" height="2"/><rect x="4" y="24" width="2" height="2"/></svg>',title:"Point List"}),this.pointListBtn.events.on("change",(e=>{this.events.dispatch(this.events.list,e)}))}render(e){super.render(e);let t=new Rt({classList:["og-elevationprofile-button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg width="30" height="30" viewBox="0 0 30 30" version="1.1">\n <g transform="translate(0,-289.0625)">\n <path d="M 15 6 C 10.041282 6 6 10.04128 6 15 C 6 19.95872 10.041282 24 15 24 C 16.586491 24 18.07668 23.58246 19.373047 22.857422 L 17.888672 21.375 C 17.00816 21.772814 16.032235 22 15 22 C 11.122162 22 8 18.87784 8 15 C 8 11.12216 11.122162 8 15 8 C 18.877838 8 22 11.12216 22 15 L 19 15 L 23 20 L 27 15 L 24 15 C 24 10.04128 19.958718 6 15 6 z " transform="translate(0,289.0625)" />\n </g>\n</svg>',title:"Reset"});t.appendTo(this.el),t.events.on("click",(()=>{this.model.clear(),this.events.dispatch(this.events.reset,this)})),this.pointListBtn.appendTo(this.el);let i=new Rt({classList:["og-elevationprofile-button","og-elevationprofile-button__location"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 256 256" enable-background="new 0 0 256 256" xml:space="preserve">\n<metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n<g><g><path fill="#000000" d="M127,169.4c23.7,0,42.8-18.3,42.8-41s-19.2-41-42.8-41c-23.7,0-42.8,18.4-42.8,41S103.4,169.4,127,169.4z"/><path fill="#000000" d="M221.7,120.2c-3.8-44-40.9-78.9-87-82V15h-16.3v23.6c-44.8,4-80.3,38.5-84.1,81.7H10v15.6h24.3c3.8,43.1,39.3,77.4,84.1,81.7V241h16.3v-23.2c46-3.1,83.2-37.9,87-82H246v-15.6H221.7L221.7,120.2L221.7,120.2z M128,201.6c-42.5,0-76.7-33-76.7-73.4c0-40.4,34.5-73.4,76.7-73.4c42.5,0,76.7,33,76.7,73.4C204.7,168.5,170.5,201.6,128,201.6L128,201.6z"/></g></g>\n</svg>',title:"View bounds"});return i.appendTo(this.el),i.events.on("click",(()=>{this.events.dispatch(this.events.location,this)})),this}}class Ls extends Nt{constructor(e){super({title:"Points List",visible:!1,resizable:!0,useHide:!0,top:150,left:200,width:400,height:300,minHeight:100,minWidth:100,...e}),this._onApplyClick=()=>{try{this.model.clear();let e=JSON.parse(this.$textarea.value),t=new Array(e.length);for(let i=0;i<e.length;i++){let n=e[i];t[i]=new z(n[0],n[1],n[2])}this.model.addPointLonLatArrayAsync(t)}catch(e){console.error(e)}},this.$textarea=null}render(e){super.render(e);let t=new Bt({template:'<div class="og-elevationprofile-list">\n <textarea placeholder="[[lon, lat, height], [lon, lat, height], ..., [lon, lat, height]]"></textarea>\n <div class="og-elevationprofile-list-buttons"></div>\n </div>'});t.appendTo(this.container);let i=new Rt({classList:["og-elevationprofile-list-apply"],icon:"Apply"});return i.appendTo(t.select(".og-elevationprofile-list-buttons")),i.events.on("click",this._onApplyClick),this.$textarea=t.select("textarea"),this}}class As extends Bt{constructor(e={}){super({...e,template:'<div class="og-elevationprofile-legend">\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__track">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__ground">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__warning"> \n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__collision">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n </div>'}),this.$groundValue=null,this.$trackValue=null,this.$warningValue=null,this.$collisionValue=null,this.$trackUnits=null,this.$groundUnits=null,this.$warningUnits=null,this.$collisionUnits=null}render(e){return super.render(e),this.$trackValue=this.select(".og-elevationprofile-legend__track .og-elevationprofile-value"),this.$groundValue=this.select(".og-elevationprofile-legend__ground .og-elevationprofile-value"),this.$warningValue=this.select(".og-elevationprofile-legend__warning .og-elevationprofile-value"),this.$collisionValue=this.select(".og-elevationprofile-legend__collision .og-elevationprofile-value"),this.$trackUnits=this.select(".og-elevationprofile-legend__track .og-elevationprofile-units"),this.$groundUnits=this.select(".og-elevationprofile-legend__ground .og-elevationprofile-units"),this.$warningUnits=this.select(".og-elevationprofile-legend__warning .og-elevationprofile-units"),this.$collisionUnits=this.select(".og-elevationprofile-legend__collision .og-elevationprofile-units"),this}clear(){this.$trackValue&&(this.$trackValue.innerText="0"),this.$trackUnits&&(this.$trackUnits.innerText="m"),this.$groundValue&&(this.$groundValue.innerText="0"),this.$groundUnits&&(this.$groundUnits.innerText="m"),this.$warningValue&&(this.$warningValue.innerText="0"),this.$warningUnits&&(this.$warningUnits.innerText="m"),this.$collisionValue&&(this.$collisionValue.innerText="0"),this.$collisionUnits&&(this.$collisionUnits.innerText="m")}setTrackLength(e){let t=$e(e);this.$trackValue.innerText=t[0],this.$trackUnits.innerText=t[1]}setGroundLength(e){let t=$e(e);this.$groundValue.innerText=t[0],this.$groundUnits.innerText=t[1]}setWarningLength(e){let t=$e(e);this.$warningValue.innerText=t[0],this.$warningUnits.innerText=t[1]}setCollisionLength(e){let t=$e(e);this.$collisionValue.innerText=t[0],this.$collisionUnits.innerText=t[1]}}var Es=Object.freeze({__proto__:null,CompassButton:zt,Control:It,DebugInfo:class extends It{constructor(e={}){e.name&&""!==e.name||(e.name="DebugInfo"),super(e),this.el=null,this._watch=e.watch||[],this._toggleBtn=new Ot({classList:["og-map-button","og-debuginfo_button"],icon:'<?xml version="1.0" encoding="iso-8859-1"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg fill="#000000" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \n\t width="800px" height="800px" viewBox="0 0 932.179 932.179"\n\t xml:space="preserve">\n<g>\n\t<path d="M61.2,341.538c4.9,16.8,11.7,33,20.3,48.2l-24.5,30.9c-8,10.1-7.1,24.5,1.9,33.6l42.2,42.2c9.1,9.1,23.5,9.899,33.6,1.899\n\t\tl30.7-24.3c15.8,9.101,32.6,16.2,50.1,21.2l4.6,39.5c1.5,12.8,12.3,22.4,25.1,22.4h59.7c12.8,0,23.6-9.601,25.1-22.4l4.4-38.1\n\t\tc18.8-4.9,36.8-12.2,53.7-21.7l29.7,23.5c10.1,8,24.5,7.1,33.6-1.9l42.2-42.2c9.1-9.1,9.9-23.5,1.9-33.6l-23.1-29.3\n\t\tc9.6-16.601,17.1-34.3,22.1-52.8l35.6-4.1c12.801-1.5,22.4-12.3,22.4-25.1v-59.7c0-12.8-9.6-23.6-22.4-25.1l-35.1-4.1\n\t\tc-4.801-18.3-12-35.8-21.199-52.2l21.6-27.3c8-10.1,7.1-24.5-1.9-33.6l-42.1-42.1c-9.1-9.1-23.5-9.9-33.6-1.9l-26.5,21\n\t\tc-17.2-10.1-35.601-17.8-54.9-23l-4-34.3c-1.5-12.8-12.3-22.4-25.1-22.4h-59.7c-12.8,0-23.6,9.6-25.1,22.4l-4,34.3\n\t\tc-19.8,5.3-38.7,13.3-56.3,23.8l-27.5-21.8c-10.1-8-24.5-7.1-33.6,1.9l-42.2,42.2c-9.1,9.1-9.9,23.5-1.9,33.6l23,29.1\n\t\tc-9.2,16.6-16.2,34.3-20.8,52.7l-36.8,4.2c-12.8,1.5-22.4,12.3-22.4,25.1v59.7c0,12.8,9.6,23.6,22.4,25.1L61.2,341.538z\n\t\t M277.5,180.038c54.4,0,98.7,44.3,98.7,98.7s-44.3,98.7-98.7,98.7c-54.399,0-98.7-44.3-98.7-98.7S223.1,180.038,277.5,180.038z"/>\n\t<path d="M867.699,356.238l-31.5-26.6c-9.699-8.2-24-7.8-33.199,0.9l-17.4,16.3c-14.699-7.1-30.299-12.1-46.4-15l-4.898-24\n\t\tc-2.5-12.4-14-21-26.602-20l-41.1,3.5c-12.6,1.1-22.5,11.4-22.9,24.1l-0.799,24.4c-15.801,5.7-30.701,13.5-44.301,23.3\n\t\tl-20.799-13.8c-10.602-7-24.701-5-32.9,4.7l-26.6,31.7c-8.201,9.7-7.801,24,0.898,33.2l18.201,19.399\n\t\tc-6.301,14.2-10.801,29.101-13.4,44.4l-26,5.3c-12.4,2.5-21,14-20,26.601l3.5,41.1c1.1,12.6,11.4,22.5,24.1,22.9l28.1,0.899\n\t\tc5.102,13.4,11.801,26.101,19.9,38l-15.699,23.7c-7,10.6-5,24.7,4.699,32.9l31.5,26.6c9.701,8.2,24,7.8,33.201-0.9l20.6-19.3\n\t\tc13.5,6.3,27.699,11,42.299,13.8l5.701,28.2c2.5,12.4,14,21,26.6,20l41.1-3.5c12.6-1.1,22.5-11.399,22.9-24.1l0.9-27.601\n\t\tc15-5.3,29.199-12.5,42.299-21.399l22.701,15c10.6,7,24.699,5,32.9-4.7l26.6-31.5c8.199-9.7,7.799-24-0.9-33.2l-18.301-19.399\n\t\tc6.701-14.2,11.602-29.2,14.4-44.601l25-5.1c12.4-2.5,21-14,20-26.601l-3.5-41.1c-1.1-12.6-11.4-22.5-24.1-22.9l-25.1-0.8\n\t\tc-5.201-14.6-12.201-28.399-20.9-41.2l13.699-20.6C879.4,378.638,877.4,364.438,867.699,356.238z M712.801,593.837\n\t\tc-44.4,3.801-83.602-29.3-87.301-73.699c-3.801-44.4,29.301-83.601,73.699-87.301c44.4-3.8,83.602,29.301,87.301,73.7\n\t\tC790.301,550.938,757.199,590.138,712.801,593.837z"/>\n\t<path d="M205,704.438c-12.6,1.3-22.3,11.899-22.4,24.6l-0.3,25.3c-0.2,12.7,9.2,23.5,21.8,25.101l18.6,2.399\n\t\tc3.1,11.301,7.5,22.101,13.2,32.301l-12,14.8c-8,9.899-7.4,24.1,1.5,33.2l17.7,18.1c8.9,9.1,23.1,10.1,33.2,2.3l14.899-11.5\n\t\tc10.5,6.2,21.601,11.101,33.2,14.5l2,19.2c1.3,12.6,11.9,22.3,24.6,22.4l25.301,0.3c12.699,0.2,23.5-9.2,25.1-21.8l2.3-18.2\n\t\tc12.601-3.101,24.601-7.8,36-14l14,11.3c9.9,8,24.101,7.4,33.201-1.5l18.1-17.7c9.1-8.899,10.1-23.1,2.301-33.2L496.6,818.438\n\t\tc6.6-11,11.701-22.7,15.201-35l16.6-1.7c12.6-1.3,22.299-11.9,22.4-24.6l0.299-25.301c0.201-12.699-9.199-23.5-21.799-25.1\n\t\tl-16.201-2.1c-3.1-12.2-7.699-24-13.699-35l10.1-12.4c8-9.9,7.4-24.1-1.5-33.2l-17.699-18.1c-8.9-9.101-23.102-10.101-33.201-2.3\n\t\tl-12.101,9.3c-11.399-6.9-23.6-12.2-36.399-15.8l-1.601-15.7c-1.3-12.601-11.899-22.3-24.6-22.4l-25.3-0.3\n\t\tc-12.7-0.2-23.5,9.2-25.101,21.8l-2,15.601c-13.199,3.399-25.899,8.6-37.699,15.399l-12.5-10.2c-9.9-8-24.101-7.399-33.201,1.5\n\t\tl-18.2,17.801c-9.1,8.899-10.1,23.1-2.3,33.199l10.7,13.801c-6.2,11-11.1,22.699-14.3,35L205,704.438z M368.3,675.837\n\t\tc36.3,0.4,65.399,30.301,65,66.601c-0.4,36.3-30.301,65.399-66.601,65c-36.3-0.4-65.399-30.3-65-66.601\n\t\tC302.1,704.538,332,675.438,368.3,675.837z"/>\n</g>\n</svg>'}),this._dialog=new Nt({title:"Debug Info",visible:!1,useHide:!0,top:120,left:60,width:480}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._canvasTiles=new $t("Tile grid",{visibility:!0,isBaseLayer:!1,hideInLayerSwitcher:!0,drawTile:function(e,t){let i,n=document.createElement("canvas"),r=n.getContext("2d");n.width=256,n.height=256,r.clearRect(0,0,n.width,n.height),r.beginPath(),r.rect(0,0,n.width,n.height),r.lineWidth=2,r.strokeStyle="black",r.stroke(),i=e.segment.tileZoom>14?"26":"32",r.fillStyle="black",r.font="normal "+i+"px Verdana",r.textAlign="center",r.fillText(e.segment.tileX+","+e.segment.tileY+","+e.segment.tileZoom,n.width/2,n.height/2),t(n)}})}addWatches(e){for(let t=0;t<e.length;t++)this.addWatch(e[t])}addWatch(e){this._watch.push(e);let t=document.createElement("div");t.classList.add("og-watch-line"),t.innerHTML=`<div class="og-watch-label">${e.label}</div><div class="og-watch-value"></div>`,e.valEl=t.querySelector(".og-watch-value"),this.el.appendChild(t)}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.renderer.div),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this.el=document.createElement("div"),this.el.className="og-debug-info";let e=document.createElement("div");e.classList.add("og-debuginfo_controls"),this.el.appendChild(e);let t=this._watch;this._watch=[];for(let e=0;e<t.length;e++)this.addWatch(t[e]);this._dialog.container?.appendChild(this.el),this.renderer.events.on("draw",this._frame,this);let i=this.planet;i&&this.addWatches([{label:"Nodes count",frame:()=>i._renderedNodes.length},{label:"Planet._fadingNodes",frame:()=>i._fadingNodes.size},{label:"createdNodes",frame:()=>i._createdNodesCount},{label:"indexesCache",frame:()=>i._indexesCacheToRemoveCounter},{label:"distBeforeMemClear",frame:()=>Math.round(i._distBeforeMemClear)},{label:"maxZoom/minZoom",frame:()=>i.maxCurrZoom+" / "+i?.minCurrZoom},{label:"viewExtent",frame:()=>i.getViewExtent().toString()},{label:"height/alt (km)",frame:()=>`<div style="width:190px">${(i.camera._lonLat.height/1e3).toFixed(2)+" / "+(i.camera.getAltitude()/1e3).toFixed(2)}</div>`},{label:"cam.slope",frame:()=>i.camera.slope.toFixed(3)},{label:"lodSize",frame:()=>Math.round(i.lodSize)},{label:"deltaTime/FPS",frame:()=>`<div style="width:70px"><div style="width:20px; float: left;">\n ${Math.round(i.renderer.handler.deltaTime)}\n </div> <div style="float: left">\n ${Math.round(1e3/i.renderer.handler.deltaTime)}\n </div></div>`},{label:"-------------------------"},{label:"_renderCompleted / renderCompletedActivated",frame:()=>`${i._renderCompleted} / ${i._renderCompletedActivated}`},{label:"_terrainCompleted / terrainCompletedActivated",frame:()=>`${i._terrainCompleted} / ${i._terrainCompletedActivated}`},{label:"PlainWorker",frame:()=>i._plainSegmentWorker.pendingQueue.length},{label:"TileLoader",frame:()=>`${i._tileLoader.loading} ${i._tileLoader.queue.length}`},{label:"TerrainLoader",frame:()=>i.terrain&&!i.terrain.isEmpty?`${i.terrain.loader.loading} ${i.terrain.loader.queue.length}`:""},{label:"TerrainWorker",frame:()=>i._terrainWorker.pendingQueue.length},{label:"NormalMapCreator",frame:()=>i._normalMapCreator.queueSize},{label:"VectorTileCreator",frame:()=>i._vectorTileCreator.queueSize}]);let n=new Ot({classList:["og-debuginfo_controls-button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg fill="#000000" width="800px" height="800px" viewBox="-7.5 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">\n<title>lock</title>\n<path d="M14.625 15.156h2.094c0.281 0 0.5 0.25 0.5 0.531v11c0 0.281-0.219 0.5-0.5 0.5h-16.219c-0.281 0-0.5-0.219-0.5-0.5v-11c0-0.281 0.219-0.531 0.5-0.531h2.031v-5.125c0-2.875 1.844-5.25 4.688-5.25h2.688c2.875 0 4.719 2.375 4.719 5.25v5.125zM5.188 15.156h6.813v-4.875c0-1.594-1.313-2.938-2.938-2.938h-0.969c-1.594 0-2.906 1.344-2.906 2.938v4.875zM7.156 24h2.906l-0.719-3.156c0.5-0.25 0.844-0.781 0.844-1.375 0-0.906-0.719-1.594-1.594-1.594s-1.563 0.688-1.563 1.594c0 0.594 0.344 1.125 0.844 1.375z"></path>\n</svg>',title:"Lock/Unlock quad tree"});n.appendTo(e),n.events.on("change",(e=>{e?i.lockQuadTree():i.unlockQuadTree()}));let r=new Ot({classList:["og-debuginfo_controls-button"],icon:'<?xml version="1.0"?>\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">\n <path d="M 4 4 L 4 8 L 8 8 L 8 4 L 4 4 z M 10 4 L 10 8 L 14 8 L 14 4 L 10 4 z M 16 4 L 16 8 L 20 8 L 20 4 L 16 4 z M 4 10 L 4 14 L 8 14 L 8 10 L 4 10 z M 10 10 L 10 14 L 14 14 L 14 10 L 10 10 z M 16 10 L 16 14 L 20 14 L 20 10 L 16 10 z M 4 16 L 4 20 L 8 20 L 8 16 L 4 16 z M 10 16 L 10 20 L 14 20 L 14 16 L 10 16 z M 16 16 L 16 20 L 20 20 L 20 16 L 16 16 z"/>\n</svg>',title:"Show/Hide grid"});r.appendTo(e),r.events.on("change",(e=>{e?this.planet.addLayer(this._canvasTiles):this._canvasTiles.remove()}))}_frame(){for(let e=0;e<this._watch.length;e++){let t=this._watch[e];t.valEl.innerHTML=t.frame?String(t.frame()):""}}},DrawingControl:jn,DrawingSwitcher:class extends It{constructor(e={}){super({name:"DrawingSwitcher",...e}),this.drawingControl=new jn}oninit(){this.planet.addControl(this.drawingControl),this._createMenu()}onactivate(){this.drawingControl.activate()}ondeactivate(){this.drawingControl.deactivate()}_createMenu(){let e=new Ot({classList:["og-map-button","og-drawing-default_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M4 0l16 12.279-6.951 1.17 4.325 8.817-3.596 1.734-4.35-8.879-5.428 4.702z"/></svg>',name:"default",isActive:!0}),t=new Ot({classList:["og-map-button","og-drawing-polygon_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Generator: Adobe Illustrator 24.1.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) --\x3e\n<svg version="1.1" id="Layer_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"\n\t viewBox="0 0 1024 1024" style="enable-background:new 0 0 1024 1024;" xml:space="preserve">\n<g>\n\t<path d="M926.03,321.16c-16.02,0-31.11,3.94-44.48,10.79l-263.43-191.4c2.69-8.94,4.18-18.4,4.18-28.2\n\t\tc0-54.02-43.95-97.97-97.97-97.97c-54.03,0-97.98,43.95-97.98,97.97c0,9.81,1.49,19.27,4.18,28.21L155.75,340.18\n\t\tc-16.22-11.91-36.16-19.03-57.78-19.03C43.95,321.16,0,365.11,0,419.13c0,52.58,41.67,95.5,93.71,97.75l102.63,315.86\n\t\tc-24.28,17.85-40.13,46.52-40.13,78.9c0,54.02,43.95,97.98,97.98,97.98c37.54,0,70.18-21.25,86.62-52.34h367.26\n\t\tc16.44,31.08,49.08,52.34,86.63,52.34c54.03,0,97.98-43.95,97.98-97.98c0-32.46-15.94-61.21-40.33-79.05l104.11-320.4\n\t\tc39.15-12.84,67.54-49.68,67.54-93.07C1024,365.11,980.05,321.16,926.03,321.16z M828.05,911.65c0,8.5-3.3,16.19-8.55,22.09\n\t\tc-6.11,6.85-14.9,11.26-24.79,11.26c-13.65,0-25.37-8.26-30.52-20.02c-1.79-4.09-2.82-8.58-2.82-13.33\n\t\tc0-18.39,14.95-33.35,33.34-33.35c2.93,0,5.72,0.5,8.43,1.21c13.27,3.49,23.21,14.91,24.59,28.9\n\t\tC827.83,909.5,828.05,910.54,828.05,911.65z M790.48,813.89c-45.63,1.96-83.27,35.16-91.87,78.77H350.28\n\t\tc-8.62-43.69-46.38-76.93-92.11-78.79L155.59,498.19c24.41-17.84,40.36-46.59,40.36-79.06c0-8.9-1.3-17.49-3.53-25.7L468.57,192.8\n\t\tc15.84,11.01,35.05,17.52,55.76,17.52c20.71,0,39.92-6.5,55.76-17.52l256.56,186.4c-5.48,12.21-8.59,25.7-8.59,39.93\n\t\tc0,41.02,25.36,76.17,61.21,90.75L790.48,813.89z M254.19,945c-10.11,0-19.07-4.62-25.19-11.75c-5.01-5.84-8.15-13.32-8.15-21.6\n\t\tc0-0.91,0.2-1.76,0.27-2.66c1.14-14.18,11.08-25.8,24.43-29.41c2.78-0.75,5.64-1.28,8.65-1.28c18.38,0,33.33,14.96,33.33,33.35\n\t\tc0,4.74-1.03,9.24-2.82,13.33C279.55,936.74,267.83,945,254.19,945z M64.88,421.49c-0.06-0.79-0.24-1.55-0.24-2.35\n\t\tc0-16.41,11.93-30.01,27.55-32.76c1.89-0.33,3.8-0.58,5.78-0.58c11.94,0,22.35,6.36,28.24,15.81c3.18,5.11,5.11,11.09,5.11,17.53\n\t\tc0,15.47-10.63,28.39-24.94,32.14c-2.7,0.71-5.48,1.2-8.4,1.2C80.4,452.47,66.11,438.76,64.88,421.49z M549.41,90.62\n\t\tc5.07,5.85,8.25,13.39,8.25,21.72c0,7.32-2.44,14.03-6.45,19.54c-6.07,8.33-15.82,13.81-26.88,13.81\n\t\tc-11.07,0-20.83-5.48-26.89-13.81c-4.01-5.51-6.45-12.22-6.45-19.54c0-8.33,3.17-15.86,8.24-21.71\n\t\tc6.12-7.07,15.04-11.64,25.1-11.64C534.38,79,543.29,83.57,549.41,90.62z M959.36,419.13c0,11.94-6.36,22.35-15.82,28.24\n\t\tc-5.1,3.18-11.07,5.1-17.52,5.1c-6.08,0-11.71-1.76-16.62-4.61c-9.71-5.64-16.33-15.94-16.64-27.89c-0.01-0.29-0.09-0.56-0.09-0.85\n\t\tc0-11.75,6.14-22.05,15.36-28c5.2-3.35,11.35-5.35,17.99-5.35C944.41,385.78,959.36,400.75,959.36,419.13z"/>\n</g>\n</svg>',name:"polygon"}),i=new Ot({classList:["og-map-button","og-drawing-linestring_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- License: MIT. Made by Esri: https://github.com/Esri/calcite-ui-icons --\x3e\n <svg width="800px" height="800px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M21 6h.046l-5.25 9h-.944L10 9.455V7H7v2.926L1.862 18H0v3h3v-2.926L8.138 10h1.01L14 15.545V18h3v-3h-.046l5.25-9H24V3h-3zM8 8h1v1H8zM2 20H1v-1h1zm14-3h-1v-1h1zm7-13v1h-1V4z"/></svg>',name:"linestring"});new Qt({buttons:[e,t,i]}).events.on("change",(e=>{switch(this.drawingControl.deactivate(),e.name){case"polygon":this.drawingControl.activatePolygonDrawing();break;case"linestring":this.drawingControl.activateLineStringDrawing()}})),e.appendTo(this.renderer.div),t.appendTo(this.renderer.div),i.appendTo(this.renderer.div)}},EarthCoordinates:ar,EarthNavigation:lr,ElevationProfileControl:class extends It{constructor(e={}){super({name:"ElevationProfileControl",...e}),this._onSceneChange=()=>{this._collectProfileThrottled()},this._onElevationProfilePointer=(e,t,i,n,r,s,a,o)=>{let l=this._elevationProfileScene.getPointLonLat(s),h=this._elevationProfileScene.getPointLonLat(s+1),c=this.planet.ellipsoid.lonLatToCartesian(l),d=this.planet.ellipsoid.lonLatToCartesian(h),_=(e-t[0])/(i[0]-t[0]),u=d.sub(c);this._elevationProfileScene.setPointerCartesian3v(c.add(u.scale(_)),o)},this._onElevationProfileDblClick=(e,t,i,n,r,s,a,o)=>{let l=this._elevationProfileScene.getPointLonLat(s),h=this._elevationProfileScene.getPointLonLat(s+1),c=this.planet.ellipsoid.lonLatToCartesian(l),d=this.planet.ellipsoid.lonLatToCartesian(h),_=(e-t[0])/(i[0]-t[0]),u=d.sub(c),f=c.add(u.scale(_));this.planet.camera.flyDistance(f,this.planet.camera.eye.distance(f))},this._onElevationProfileMouseEnter=()=>{this._elevationProfileView.model.pointsReady&&this._elevationProfileScene.setPointerVisibility(!0)},this._onElevationProfileMouseLeave=()=>{},this._elevationProfileScene=new bs,this._elevationProfileView=new _s,this._elevationProfileLegend=new As,this._elevationProfileButtonsView=new Cs({model:this._elevationProfileView.model}),this._elevationProfileView.events.on("pointer",this._onElevationProfilePointer),this._elevationProfileView.events.on("dblclick",this._onElevationProfileDblClick),this._elevationProfileView.events.on("mouseenter",this._onElevationProfileMouseEnter),this._elevationProfileView.events.on("mouseleave",this._onElevationProfileMouseLeave),this._dialog=new Nt({title:"Elevation Profile",visible:!1,resizable:!0,useHide:!0,top:175,left:65,width:400,height:200,minHeight:100,minWidth:100}),this._graphView=new Bt({template:'<div class="og-elevationprofile__container">\n <div class="og-elevationprofile__menu"></div>\n <div class="og-elevationprofile__graph"></div>\n </div>'}),this._poiListDialog=new Ls({model:this._elevationProfileScene}),this._toggleBtn=new Ot({classList:["og-map-button","og-elevationprofile_button"],icon:'<svg style="width: 2em; height: 2em;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M128 896v-158.293333l331.946667-191.573334 160.853333 93.866667L896 480V896H128M896 381.44l-275.2 159.146667-160.853333-92.586667L128 640v-94.293333l331.946667-191.573334 160.853333 93.866667L896 288v93.44z" fill="" /></svg>'}),this._collectProfileThrottled=De((()=>{let e=this._elevationProfileScene.getPointsLonLat();this._elevationProfileView.model.collectProfile(e)}),250)}oninit(){this._dialog.appendTo(this.planet.renderer.div),this._graphView.appendTo(this._dialog.container),this._toggleBtn.appendTo(this.renderer.div),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e),e?(this.activate(),this._elevationProfileView.resize()):this.deactivate()})),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this._elevationProfileView.appendTo(this._graphView.select(".og-elevationprofile__graph")),this._elevationProfileView.model.bindPlanet(this.planet),this._elevationProfileView.model.events.on("clear",(()=>{this._elevationProfileScene.clear(),this._elevationProfileLegend.clear()})),this._elevationProfileView.model.events.on("startcollecting",(()=>{this._elevationProfileScene.setPointerVisibility(!1)})),this._elevationProfileView.events.on("tracklength",(e=>{this._elevationProfileLegend.setTrackLength(e)})),this._elevationProfileView.events.on("groundlength",(e=>{this._elevationProfileLegend.setGroundLength(e)})),this._elevationProfileView.events.on("warninglength",(e=>{this._elevationProfileLegend.setWarningLength(e)})),this._elevationProfileView.events.on("collisionlength",(e=>{this._elevationProfileLegend.setCollisionLength(e)})),this._poiListDialog.appendTo(this.planet.renderer.div),this._poiListDialog.events.on("visibility",(e=>{this._elevationProfileButtonsView.pointListBtn.setActive(e,!0)})),this._elevationProfileLegend.appendTo(this._graphView.select(".og-elevationprofile__menu")),this._elevationProfileButtonsView.appendTo(this._graphView.select(".og-elevationprofile__menu")),this._elevationProfileButtonsView.events.on("list",(e=>{this._poiListDialog.setVisibility(e)})),this._elevationProfileButtonsView.events.on("location",(e=>{this._elevationProfileScene.flyExtent()})),this._elevationProfileButtonsView.events.on("reset",(e=>{this._elevationProfileScene.setPointerVisibility(!1)})),this._elevationProfileScene.events.on("change",this._onSceneChange)}onactivate(){this.renderer.controls.mouseNavigation.deactivateDoubleClickZoom(),this.planet&&this._elevationProfileScene.bindPlanet(this.planet),this.renderer&&this.renderer.addNode(this._elevationProfileScene)}ondeactivate(){this._poiListDialog.setVisibility(!1),this._elevationProfileView.model.clear(),this.renderer.controls.mouseNavigation.activateDoubleClickZoom(),this.renderer&&this.renderer.removeNode(this._elevationProfileScene),this._dialog.hide()}},GeoImageDragControl:class extends It{constructor(e={}){super(e),this._cornerIndex=-1,this._catchCorner=!1,this._toggleBtn=new Ot({classList:["og-map-button","og-geoimagegrag_button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M16 13l6.964 4.062-2.973.85 2.125 3.681-1.732 1-2.125-3.68-2.223 2.15L16 13zm-2-7h2v2h5a1 1 0 0 1 1 1v4h-2v-3H10v10h4v2H9a1 1 0 0 1-1-1v-5H6v-2h2V9a1 1 0 0 1 1-1h5V6zM4 14v2H2v-2h2zm0-4v2H2v-2h2zm0-4v2H2V6h2zm0-4v2H2V2h2zm4 0v2H6V2h2zm4 0v2h-2V2h2zm4 0v2h-2V2h2z" fill="#000"/></svg>'})}oninit(){this._toggleBtn.appendTo(this.renderer.div),this.planet.events.on("layeradd",(e=>{this.isActive()&&this._bindLayer(e)}),this),this._toggleBtn.events.on("change",(e=>{e?this.activate():this.deactivate()}))}onactivate(){super.onactivate();const e=this.planet;for(let t=0;t<e.layers.length;t++)this._bindLayer(e.layers[t])}ondeactivate(){super.ondeactivate();const e=this.planet;for(let t=0;t<e.layers.length;t++)this._unbindLayer(e.layers[t])}_bindLayer(e){e instanceof cr&&(e.events.on("mousemove",this._onMouseMove,this),e.events.on("mouseleave",this._onMouseLeave,this),e.events.on("ldown",this._onLDown,this),e.events.on("lup",this._onLUp,this))}_unbindLayer(e){e instanceof cr&&(e.events.off("mousemove",this._onMouseMove),e.events.off("mouseleave",this._onMouseLeave),e.events.off("ldown",this._onLDown),e.events.off("lup",this._onLUp))}_onLUp(e){this._catchCorner=!1,e.renderer.controls.mouseNavigation.activate()}_onLDown(e){-1!==this._cornerIndex&&(this._catchCorner=!0,e.renderer.controls.mouseNavigation.deactivate())}_onMouseLeave(){document.body.style.cursor="auto"}_onMouseMove(e){let t=e.pickingObject;const i=this.planet;if(this._catchCorner){let n=t.getCornersLonLat();n[this._cornerIndex]=i.getLonLatFromPixelTerrain(e),t.setCornersLonLat(n)}else{this._cornerIndex=-1;for(let n=0;n<t._cornersWgs84.length;n++){let r=i.getLonLatFromPixelTerrain(e);if(r&&i.ellipsoid.getGreatCircleDistance(t._cornersWgs84[n],r)/i.getDistanceFromPixel(e)<=.05){this._cornerIndex=n,document.body.style.cursor="move";break}document.body.style.cursor="auto"}}}},HeightRuler:Ir,KeyboardNavigation:class extends It{constructor(e={}){e=e||{},super({name:"KeyboardNavigation",...e}),this.step=e.step||250}onactivate(){let e=this.renderer;e.events.on("keypress",dr.KEY_PGUP,this.onCameraMoveForward,this),e.events.on("keypress",dr.KEY_PGDN,this.onCameraMoveBackward,this),e.events.on("keypress",dr.KEY_PLUS,this.onCameraMoveForward,this),e.events.on("keypress",dr.KEY_EQUALS,this.onCameraMoveForward,this),e.events.on("keypress",dr.KEY_MINUS,this.onCameraMoveBackward,this),e.events.on("keypress",dr.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",dr.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",dr.KEY_A,this.onCameraStrifeLeft,this),e.events.on("keypress",dr.KEY_D,this.onCameraStrifeRight,this),e.events.on("keypress",dr.KEY_UP,this.onCameraLookUp,this),e.events.on("keypress",dr.KEY_DOWN,this.onCameraLookDown,this),e.events.on("keypress",dr.KEY_LEFT,this.onCameraLookLeft,this),e.events.on("keypress",dr.KEY_RIGHT,this.onCameraLookRight,this),e.events.on("keypress",dr.KEY_Q,this.onCameraRollLeft,this),e.events.on("keypress",dr.KEY_E,this.onCameraRollRight,this),e.events.on("keypress",dr.KEY_N,this.onCameraRollNorth,this)}ondeactivate(){let e=this.renderer;e.events.off("keypress",dr.KEY_PGUP,this.onCameraMoveForward),e.events.off("keypress",dr.KEY_PGDN,this.onCameraMoveBackward),e.events.off("keypress",dr.KEY_PLUS,this.onCameraMoveForward),e.events.off("keypress",dr.KEY_EQUALS,this.onCameraMoveForward),e.events.off("keypress",dr.KEY_MINUS,this.onCameraMoveBackward),e.events.off("keypress",dr.KEY_W,this.onCameraMoveForward),e.events.off("keypress",dr.KEY_S,this.onCameraMoveBackward),e.events.off("keypress",dr.KEY_A,this.onCameraStrifeLeft),e.events.off("keypress",dr.KEY_D,this.onCameraStrifeRight),e.events.off("keypress",dr.KEY_UP,this.onCameraLookUp),e.events.off("keypress",dr.KEY_DOWN,this.onCameraLookDown),e.events.off("keypress",dr.KEY_LEFT,this.onCameraLookLeft),e.events.off("keypress",dr.KEY_RIGHT,this.onCameraLookRight),e.events.off("keypress",dr.KEY_Q,this.onCameraRollLeft),e.events.off("keypress",dr.KEY_E,this.onCameraRollRight),e.events.off("keypress",dr.KEY_N,this.onCameraRollNorth)}oninit(){this.activate()}onCameraMoveForward(){let e=this.planet.camera;e.slide(0,0,-e.getAltitude()/this.step)}onCameraMoveBackward(){let e=this.planet.camera;e.slide(0,0,e.getAltitude()/this.step)}onCameraStrifeLeft(){let e=this.planet.camera;e.slide(-e.getAltitude()/this.step,0,0)}onCameraStrifeRight(){let e=this.planet.camera;e.slide(e.getAltitude()/this.step,0,0)}onCameraLookUp(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.pitch(15/this.renderer.handler.deltaTime):e.rotateVertical(e.getAltitude()/3e6*o,oe.ZERO)}onCameraLookDown(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.pitch(-15/this.renderer.handler.deltaTime):e.rotateVertical(-e.getAltitude()/3e6*o,oe.ZERO)}onCameraLookLeft(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.roll(15/this.renderer.handler.deltaTime):e.rotateHorizontal(e.getAltitude()/3e6*o)}onCameraLookRight(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.roll(-15/this.renderer.handler.deltaTime):e.rotateHorizontal(-e.getAltitude()/3e6*o)}onCameraTurnLeft(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.yaw(15/this.renderer.handler.deltaTime):e.rotateHorizontal(e.getAltitude()/3e6*o)}onCameraTurnRight(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.yaw(-15/this.renderer.handler.deltaTime):e.rotateHorizontal(-e.getAltitude()/3e6*o,!1,oe.ZERO)}onCameraRollNorth(){let e=this.planet.getCartesianFromPixelTerrain(this.renderer.handler.getCenter());e?this.planet.flyCartesian(e.normal().scaleTo(e.length()+e.distance(this.planet.camera.eye)),null,null,0,null,null,(()=>{this.planet.camera.look})):this.planet.flyCartesian(this.planet.camera.eye)}onCameraRollLeft(){this.planet.camera.roll(-15/this.renderer.handler.deltaTime)}onCameraRollRight(){this.planet.camera.roll(15/this.renderer.handler.deltaTime)}},LayerAnimation:class extends It{constructor(e={}){super(e),this._currVisibleIndex=0,this._onViewchange=()=>{this._timeoutStart=performance.now()},this._onVisibilityChange=e=>{e||this.pause()},this._onLayerLoadend=e=>{let t=this._layersArr[this._currentIndex];if(t&&t.isEqual(e)){let e=this._getFrameIndex(this._currentIndex)*this._frameSize,i=this._currentIndex;for(let t=e;t<i;t++){let e=this._layersArr[t];e.opacity=0,e.setVisibility(!1)}t.opacity=1;let n=this._layersArr[this._currVisibleIndex];if(n){n.opacity=0,n.setVisibility(!1);let e=this._getFrameIndex(this._currVisibleIndex);this._getFrameIndex(this._currentIndex)!==e&&this._removeFrameFromPlanet(e)}this.events.dispatch(this.events.idle,t)}},this.events=Pt(_r),this._name=e.name||`layerAnimation-${this.__id}`,this._layersArr=e.layers?[].concat(e.layers):[],this._currentIndex=-1,this._playInterval=e.playInterval||120,this._playIntervalHandler=-1,this._playIndex=0,this._frameSize=e.frameSize||50,this.repeat=null==e.repeat||e.repeat,this.skipTimeout=e.skipTimeout||5e3,this._timeoutStart=0}_getFramesNum(){return Math.ceil(this._layersArr.length/this._frameSize)}_setFrame(e){for(let t=0,i=this._getFramesNum();t<i;t++)t!==e?this._removeFrameFromPlanet(t):this._appendFrameToPlanet(t)}_getFrameIndex(e){return Math.floor(e/this._frameSize)}_appendFrameToPlanet(e){if(this.planet){let t=e*this._frameSize,i=t+this._frameSize;for(let e=t,n=i>this._layersArr.length?this._layersArr.length:i;e<n;e++)this.planet.addLayer(this._layersArr[e])}}_removeFrameFromPlanet(e){if(this.planet){let t=e*this._frameSize,i=t+this._frameSize;for(let e=t,n=i>this._layersArr.length?this._layersArr.length:i;e<n;e++)this._layersArr[e].abortLoading(),this._layersArr[e].remove(),this._layersArr[e].setVisibility(!1)}}oninit(){super.oninit(),this.onactivate(),this._initLayers(),this.planet.events.on("layerloadend",this._onLayerLoadend),this._setCurrentIndexAsync(0,!1,!0)}onactivate(){super.onactivate(),this.planet.camera.events.on("viewchange",this._onViewchange),this.planet.renderer.handler.events.on("visibilitychange",this._onVisibilityChange)}ondeactivate(){super.ondeactivate(),this.planet.camera.events.off("viewchange",this._onViewchange);for(let e=0;e<this._layersArr.length;e++)this._layersArr[e].setVisibility(!1);this.planet.events.off("layerloadend",this._onLayerLoadend),this.planet.renderer.handler.events.off("visibilitychange",this._onVisibilityChange)}clear(){this.stop(),this._currentIndex=-1,this._currVisibleIndex=-1;let e=this._layersArr;this._layersArr=[];for(let t=0;t<e.length;t++)e[t].remove()}_initLayers(){if(this.planet){for(let e=0,t=this._layersArr.length;e<t;e++){let t=this._layersArr[e];t.setVisibility(!1),t.setBaseLayer(!1),t.opacity=0}this._appendFrameToPlanet(0)}}setLayers(e){this.clear(),this._layersArr=[].concat(e),this._initLayers()}appendLayer(e){this._layersArr.push(e),e.setVisibility(!1),e.setBaseLayer(!1),e.opacity=0,this.planet?.addLayer(e)}get isIdle(){let e=this._layersArr[this._currentIndex];return e&&e.isIdle||!e}get playInterval(){return this._playInterval}set playInterval(e){e!==this._playInterval&&(this._playInterval=e,this.isPlaying&&(this.pause(),this.play()))}get isPlaying(){return-1!==this._playIntervalHandler}get layers(){return this._layersArr}_checkEnd(){this._playIndex>this._layersArr.length&&(this.repeat?this._playIndex=0:this.pause())}play(){this.isPlaying||(this._currentIndex>=this._layersArr.length-1&&this.stop(),this._timeoutStart=performance.now(),this._playIntervalHandler=setInterval((()=>{this._checkEnd(),this._setCurrentIndexAsync(this._playIndex,!1,!1),requestAnimationFrame((()=>{(this.isIdle||performance.now()-this._timeoutStart>this.skipTimeout)&&(this._playIndex++,this._timeoutStart=performance.now())}))}),this._playInterval),this.events.dispatch(this.events.play))}stop(){this._playIndex>0&&(this._clearInterval(),this._playIndex=0,this.setCurrentIndex(0),this.events.dispatch(this.events.stop))}pause(){this.isPlaying&&(this._clearInterval(),this.events.dispatch(this.events.pause))}_clearInterval(){clearInterval(this._playIntervalHandler),this._playIntervalHandler=-1}setCurrentIndex(e,t=!1){this._setCurrentIndexAsync(e,!0,t)}_setCurrentIndexAsync(e,t=!1,i=!1){if(e!=this._currentIndex&&e>=0&&e<this._layersArr.length){let n=this._currentIndex;this._currentIndex=e,this._playIndex=e;let r=this._getFrameIndex(n),s=this._getFrameIndex(this._currentIndex),a=this._layersArr[n],o=this._layersArr[e],l=s!=r;l&&this._appendFrameToPlanet(s),a&&(a.isIdle?this._currVisibleIndex=n:(a.opacity=0,a.setVisibility(!1))),o&&(o.opacity=0,o.setVisibility(!0),requestAnimationFrame((()=>{if(o.isIdle||t){o.opacity=1,l&&this._removeFrameFromPlanet(r),a&&(a.opacity=0,a.setVisibility(!1));let e=this._layersArr[this._currVisibleIndex];e&&(e.opacity=0,e.setVisibility(!1))}})),i||this.events.dispatch(this.events.change,this._currentIndex,n))}}},LayerSwitcher:class extends It{constructor(e={}){super({name:"LayerSwitcher",...e}),this.addLayer=e=>{if(!e.hideInLayerSwitcher){let t=this._createLayerButton(e);this._layerViews.push(t),e.isBaseLayer()?t.appendTo(this.$baseLayers):t.appendTo(this.$overlays)}},this.removeLayer=e=>{for(let t=0;t<this._layerViews.length;t++){let i=this._layerViews[t];if(i.model.isEqual(e)){i.remove(),this._layerViews.splice(t,1);break}}},this._dialog=new Nt({title:"Layer Switcher",top:15,useHide:!0,visible:!1,width:300,maxHeight:500}),this._panel=new Bt({template:'<div class="og-layerSwitcher">\n <div class="og-layerSwitcher__title">Base Layers</div>\n <div class="og-layerSwitcher__list og-layerSwitcher__baseLayers"></div> \n \n <div class="og-layerSwitcher__title">Overlays</div>\n <div class="og-layerSwitcher__list og-layerSwitcher__overlays"></div>\n \n </div>'}),this._toggleBtn=new Ot({classList:["og-map-button","og-layerSwitcher_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">\n<metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n<g><path d="M500,573.5c-3.2,0-6.5-0.6-9.5-1.9L25,375.6c-9.1-3.8-15-12.7-15-22.6s5.9-18.8,15-22.6l465.5-196c6.1-2.5,12.9-2.5,19,0l465.5,196c9.1,3.8,15,12.7,15,22.6s-5.9,18.8-15,22.6l-465.5,196C506.5,572.9,503.2,573.5,500,573.5L500,573.5z M97.6,353L500,522.4L902.4,353L500,183.6L97.6,353L97.6,353z"/><path d="M500,720.5c-3.2,0-6.5-0.6-9.5-1.9L25,522.6c-12.4-5.2-18.3-19.6-13.1-32.1c5.2-12.5,19.6-18.3,32.1-13.1l456,192l456-192c12.4-5.2,26.9,0.6,32.1,13.1s-0.6,26.9-13.1,32.1l-465.5,196C506.5,719.9,503.2,720.5,500,720.5L500,720.5z"/><path d="M500,867.5c-3.2,0-6.5-0.6-9.5-1.9L25,669.6c-12.4-5.2-18.3-19.6-13.1-32.1c5.2-12.5,19.6-18.3,32.1-13.1l456,192l456-192c12.4-5.2,26.9,0.6,32.1,13.1c5.2,12.5-0.6,26.8-13.1,32.1l-465.5,196C506.5,866.9,503.2,867.5,500,867.5L500,867.5z"/></g>\n</svg>'}),this.$baseLayers=null,this.$overlays=null,this._layerViews=[]}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.planet.renderer.div),this._panel.appendTo(this._dialog.container),this.$baseLayers=this._panel.el.querySelector(".og-layerSwitcher__baseLayers"),this.$overlays=this._panel.el.querySelector(".og-layerSwitcher__overlays"),this._dialog.setPosition(this.planet.renderer.div.clientWidth-this._dialog.width-67),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this.planet.events.on("layeradd",this.addLayer,this),this.planet.events.on("layerremove",this.removeLayer,this),this._initLayers()}_initLayers(){let e=this.planet.layers;for(let t=0;t<e.length;t++)this.addLayer(e[t])}_createLayerButton(e){return new ur({model:e})}onactivate(){}ondeactivate(){this._dialog.hide()}},Lighting:class extends It{constructor(e={}){super(e),this._selectedLayer=null,this._toggleBtn=new Ot({classList:["og-map-button","og-lighting_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">\n\n<defs>\n</defs>\n<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; opacity: 1;" transform="translate(1.4065934065934016 1.4065934065934016) scale(2.81 2.81)" >\n\t<path d="M 45 68 c -12.682 0 -23 -10.317 -23 -23 c 0 -12.682 10.318 -23 23 -23 c 12.683 0 23 10.318 23 23 C 68 57.683 57.683 68 45 68 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 45 17.556 c -1.657 0 -3 -1.343 -3 -3 V 3 c 0 -1.657 1.343 -3 3 -3 c 1.657 0 3 1.343 3 3 v 11.556 C 48 16.212 46.657 17.556 45 17.556 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 45 90 c -1.657 0 -3 -1.343 -3 -3 V 75.444 c 0 -1.657 1.343 -3 3 -3 c 1.657 0 3 1.343 3 3 V 87 C 48 88.657 46.657 90 45 90 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 14.556 48 H 3 c -1.657 0 -3 -1.343 -3 -3 c 0 -1.657 1.343 -3 3 -3 h 11.556 c 1.657 0 3 1.343 3 3 C 17.556 46.657 16.212 48 14.556 48 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 87 48 H 75.444 c -1.657 0 -3 -1.343 -3 -3 c 0 -1.657 1.343 -3 3 -3 H 87 c 1.657 0 3 1.343 3 3 C 90 46.657 88.657 48 87 48 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 66.527 26.473 c -0.768 0 -1.535 -0.293 -2.121 -0.878 c -1.172 -1.172 -1.172 -3.071 0 -4.243 l 8.171 -8.171 c 1.172 -1.172 3.07 -1.171 4.242 0 c 1.172 1.172 1.172 3.071 0 4.243 l -8.171 8.171 C 68.063 26.18 67.295 26.473 66.527 26.473 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 15.302 77.698 c -0.768 0 -1.536 -0.293 -2.121 -0.879 c -1.172 -1.171 -1.172 -3.071 0 -4.242 l 8.171 -8.171 c 1.171 -1.172 3.071 -1.172 4.242 0 c 1.172 1.171 1.172 3.071 0 4.242 l -8.171 8.171 C 16.837 77.405 16.069 77.698 15.302 77.698 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 23.473 26.473 c -0.768 0 -1.536 -0.293 -2.121 -0.878 l -8.171 -8.171 c -1.172 -1.172 -1.172 -3.071 0 -4.243 c 1.172 -1.172 3.072 -1.171 4.243 0 l 8.171 8.171 c 1.172 1.172 1.172 3.071 0 4.243 C 25.008 26.18 24.24 26.473 23.473 26.473 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 74.698 77.698 c -0.768 0 -1.535 -0.293 -2.121 -0.879 l -8.171 -8.171 c -1.172 -1.171 -1.172 -3.071 0 -4.242 c 1.172 -1.172 3.07 -1.172 4.242 0 l 8.171 8.171 c 1.172 1.171 1.172 3.071 0 4.242 C 76.233 77.405 75.466 77.698 74.698 77.698 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n</g>\n</svg>'}),this._dialog=new Nt({title:"Lighting Parameters",visible:!1,useHide:!0,top:60,left:60,width:600}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._panel=new Bt({template:'<div class="og-lighing">\n\n <div class="og-option">\n <div class="og-suncontrol"></div>\n </div> \n \n <div class="og-option og-atmosphere-opacity">\n </div>\n \n <div class="og-option og-simpleskybackground">\n </div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option og-gamma"></div> \n <div class="og-option og-exposure"></div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option">\n <div class="og-layers">\n <div class="og-caption">Select layer:</div>\n <select id="layers"></select>\n </div>\n </div>\n\n <div class="og-option og-opacity">\n </div>\n \n <div class="og-option og-night">\n </div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option og-diffuse">\n </div>\n \n <div class="og-option og-ambient">\n </div>\n\n <div class="og-option og-specular">\n </div> \n\n </div>'}),this.$gamma=null,this.$exposure=null,this.$night=null,this.$opacity=null,this.$diffuse=null,this.$ambient=null,this.$specular=null,this.$atmosphereOpacity=null,this.$simpleSkyBackground=null,this._atmosphereMaxOpacity=new gr({label:"Max.opacity",max:5}),this._atmosphereMinOpacity=new gr({label:"Min.opacity",max:5}),this._simpleSkyBackgroundColorOne=new vr({label:"Color One"}),this._simpleSkyBackgroundColorTwo=new vr({label:"Color Two"}),this._gamma=new gr({label:"Gamma",max:5}),this._exposure=new gr({label:"Exposure",max:5}),this._night=new gr({label:"Nightlight",max:5}),this._opacity=new gr({label:"Opacity",max:1}),this._diffuse_r=new gr({label:"Diffuse R",max:5}),this._diffuse_g=new gr({label:"Diffuse G",max:5}),this._diffuse_b=new gr({label:"Diffuse B",max:5}),this._ambient_r=new gr({label:"Ambient R",max:5}),this._ambient_g=new gr({label:"Ambient G",max:5}),this._ambient_b=new gr({label:"Ambient B",max:5}),this._specular_r=new gr({label:"Specular R",max:.2}),this._specular_g=new gr({label:"Specular G",max:.2}),this._specular_b=new gr({label:"Specular B",max:.2}),this._shininess=new gr({label:"Shininess",max:100})}bindLayer(e){this._selectedLayer=e,this._opacity.value=e.opacity,this._update()}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.renderer.div),this._panel.appendTo(this._dialog.container),this._panel.el&&(this.$atmosphereOpacity=this._panel.el.querySelector(".og-atmosphere-opacity"),this.$simpleSkyBackground=this._panel.el.querySelector(".og-simpleskybackground"),this.$gamma=this._panel.el.querySelector(".og-option.og-gamma"),this.$exposure=this._panel.el.querySelector(".og-option.og-exposure"),this.$opacity=this._panel.el.querySelector(".og-option.og-opacity"),this.$diffuse=this._panel.el.querySelector(".og-option.og-diffuse"),this.$ambient=this._panel.el.querySelector(".og-option.og-ambient"),this.$specular=this._panel.el.querySelector(".og-option.og-specular"),this.$night=this._panel.el.querySelector(".og-option.og-night")),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)}));let e=this._dialog.select(".og-suncontrol"),t=new Ot({classList:["og-suncontrol-button"],isActive:!0,icon:'<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 122.88 70.41" style="enable-background:new 0 0 122.88 70.41" xml:space="preserve"><g><path d="M60.91,19.12c6.95,0,13.24,2.95,17.8,7.72c4.55,4.77,7.37,11.37,7.37,18.64c0,1.94-0.2,3.83-0.58,5.65h31.61 c2.1,0,2.62,1.16,2.62,2.59c0,1.43-0.52,2.59-2.62,2.59H7.09c-2.1,0-2.62-1.16-2.62-2.59c0-1.43,0.52-2.59,2.62-2.59h29.23 c-0.38-1.82-0.58-3.71-0.58-5.65c0-7.28,2.82-13.87,7.37-18.64C47.67,22.08,53.96,19.12,60.91,19.12L60.91,19.12L60.91,19.12z M63.4,70.41c-2.1,0-2.62-1.16-2.62-2.59s0.52-2.59,2.62-2.59h56.86c2.1,0,2.62,1.16,2.62,2.59s-0.52,2.59-2.62,2.59H63.4 L63.4,70.41z M2.62,70.41c-2.1,0-2.62-1.16-2.62-2.59s0.52-2.59,2.62-2.59h29.51c2.1,0,2.62,1.16,2.62,2.59s-0.52,2.59-2.62,2.59 H2.62L2.62,70.41z M38.39,9.46c-0.78-1.35-0.32-3.07,1.03-3.85c1.35-0.78,3.07-0.32,3.85,1.03l3.62,6.27 c0.78,1.35,0.32,3.07-1.03,3.85c-1.35,0.78-3.07,0.32-3.85-1.03L38.39,9.46L38.39,9.46L38.39,9.46z M58.67,2.83 c0-1.56,1.27-2.83,2.83-2.83c1.56,0,2.83,1.27,2.83,2.83v7.24c0,1.56-1.27,2.83-2.83,2.83c-1.56,0-2.83-1.26-2.83-2.83V2.83 L58.67,2.83L58.67,2.83z M79.56,7.23c0.77-1.35,2.49-1.81,3.84-1.04c1.35,0.77,1.81,2.49,1.04,3.84l-3.62,6.27 c-0.77,1.35-2.49,1.81-3.84,1.04c-1.35-0.77-1.81-2.49-1.04-3.84L79.56,7.23L79.56,7.23L79.56,7.23z M95.45,21.48 c1.35-0.78,3.07-0.32,3.85,1.03c0.78,1.35,0.32,3.07-1.03,3.85L92,29.98c-1.35,0.78-3.07,0.32-3.85-1.03 c-0.78-1.35-0.32-3.07,1.03-3.85L95.45,21.48L95.45,21.48L95.45,21.48z M102.08,41.76c1.56,0,2.83,1.27,2.83,2.83 c0,1.56-1.27,2.83-2.83,2.83h-7.24c-1.56,0-2.83-1.26-2.83-2.83s1.26-2.83,2.83-2.83H102.08L102.08,41.76L102.08,41.76z M19.74,46.25c-1.56,0-2.83-1.27-2.83-2.83c0-1.56,1.27-2.83,2.83-2.83h7.24c1.56,0,2.83,1.26,2.83,2.83s-1.27,2.83-2.83,2.83 H19.74L19.74,46.25L19.74,46.25z M24.14,25.35c-1.35-0.77-1.81-2.49-1.04-3.84c0.77-1.35,2.49-1.81,3.84-1.04l6.27,3.62 c1.35,0.77,1.81,2.49,1.04,3.84c-0.77,1.35-2.49,1.81-3.84,1.04L24.14,25.35L24.14,25.35L24.14,25.35z"/></g></svg>',title:"Star/stop the Sun from following the camera"});t.appendTo(e);let i=new Ot({classList:["og-suncontrol-button"],isActive:!0,icon:'<?xml version="1.0"?>\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">\n <path style="text-indent:0;text-align:start;line-height:normal;text-transform:none;block-progression:tb;-inkscape-font-specification:Sans" d="M 16 4 C 9.3844277 4 4 9.3844277 4 16 C 4 22.615572 9.3844277 28 16 28 C 22.615572 28 28 22.615572 28 16 C 28 9.3844277 22.615572 4 16 4 z M 16 6 C 16.389823 6 16.778223 6.0506339 17.15625 6.09375 C 18.631659 7.6568432 21 10.9245 21 16 C 21 21.0755 18.631659 24.343157 17.15625 25.90625 C 16.778223 25.949366 16.389823 26 16 26 C 10.465308 26 6 21.534692 6 16 C 6 10.465308 10.465308 6 16 6 z" overflow="visible" font-family="Sans"/>\n</svg>\n',title:"Activate/deactivate the Sun current time positioning"});i.appendTo(e),t.events.on("change",(e=>{const t=this.planet.renderer.controls.sun;e?t.start():t.stop()})),i.events.on("change",(e=>{const t=this.planet.renderer.controls.sun;e?t.activate():t.deactivate()}));let n=new Ot({classList:["og-suncontrol-button"],isActive:this.planet.lightEnabled,icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Generated by IcoMoon.io --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="512" height="512" viewBox="0 0 512 512">\n<g>\n</g>\n\t<path d="M257.894 156.948c-53.258 0-96.42 43.561-96.42 97.26 0 53.719 43.161 97.249 96.42 97.249 53.197 0 96.379-43.53 96.379-97.25 0-53.698-43.182-97.26-96.379-97.26zM257.894 309.873c-30.464 0-55.163-24.945-55.163-55.665s24.699-55.624 55.163-55.624c30.423 0 55.101 24.904 55.101 55.624s-24.688 55.665-55.101 55.665z" fill="#000000" />\n\t<path d="M241.808 43.499h32.144v79.575h-32.144v-79.575z" fill="#000000" />\n\t<path d="M417.209 115.897l-22.723-22.917-55.757 56.279 22.723 22.907z" fill="#000000" />\n\t<path d="M389.468 238.407h78.899v32.389h-78.899v-32.389z" fill="#000000" />\n\t<path d="M396.012 416.86l22.723-22.917-55.767-56.259-22.712 22.897z" fill="#000000" />\n\t<path d="M242.473 388.915h32.144v79.575h-32.144v-79.575z" fill="#000000" />\n\t<path d="M96.266 396.073l22.722 22.938 55.778-56.289-22.692-22.928z" fill="#000000" />\n\t<path d="M43.633 240.537h78.879v32.43h-78.879v-32.43z" fill="#000000" />\n\t<path d="M115.394 93.051l-22.681 22.907 55.757 56.258 22.702-22.917z" fill="#000000" />\n</svg>',title:"Enable/disable planet lighting"});n.appendTo(e),n.events.on("change",(e=>{this.planet.lightEnabled=e}));let r=new Ot({classList:["og-suncontrol-button"],isActive:this.planet.atmosphereEnabled,icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg width="800px" height="800px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path fill="#000000" d="M135.688 18.5c-6.798 74.842-23.842 85.39-107.907 59.656 84.85 52.022 73.57 64.954-6.843 96.938 87.743-10.27 103.29 4.89 70.75 87.594 17.805-27.56 32.5-44.498 46.282-54.47-11.813 28.26-18.345 59.274-18.345 91.813 0 84.184 43.71 157.96 109.656 200.376-41.624-43.834-67.686-102.7-67.686-167.875 0-134.923 109.45-244.405 244.375-244.405 30.92 0 60.76 5.762 88 16.25-38.584-26.87-85.517-42.625-136.064-42.625-55.257 0-106.14 18.802-146.562 50.375 4.627-18.783 17.39-38.073 41.03-60.906C190.18 90.942 153.53 95.634 135.69 18.5zm10.03 77.188c5.67.002 11.428 1.247 16.876 3.874 14.506 6.998 22.72 21.81 22 36.938-10.26 10.87-19.507 22.696-27.594 35.344-9.035 2.753-19.075 2.27-28.25-2.156-19.37-9.343-27.5-32.6-18.156-51.97 6.715-13.92 20.638-22.036 35.125-22.03z"/></svg>',title:"Enable/disable atmosphere scattering"});r.appendTo(e),this.planet.atmosphereEnabled?(this.$atmosphereOpacity.style.display="block",this.$simpleSkyBackground.style.display="none"):(this.$atmosphereOpacity.style.display="none",this.$simpleSkyBackground.style.display="flex"),r.events.on("change",(e=>{this.planet.atmosphereEnabled=e,this.planet.atmosphereEnabled?(this.$atmosphereOpacity.style.display="block",this.$simpleSkyBackground.style.display="none"):(this.$atmosphereOpacity.style.display="none",this.$simpleSkyBackground.style.display="flex")})),this._atmosphereMaxOpacity.appendTo(this.$atmosphereOpacity),this._atmosphereMinOpacity.appendTo(this.$atmosphereOpacity),this._simpleSkyBackgroundColorOne.appendTo(this.$simpleSkyBackground),this._simpleSkyBackgroundColorTwo.appendTo(this.$simpleSkyBackground),this._gamma.appendTo(this.$gamma),this._exposure.appendTo(this.$exposure),this._night.appendTo(this.$night),this._opacity.appendTo(this.$opacity),this._diffuse_r.appendTo(this.$diffuse),this._diffuse_g.appendTo(this.$diffuse),this._diffuse_b.appendTo(this.$diffuse),this._ambient_r.appendTo(this.$ambient),this._ambient_g.appendTo(this.$ambient),this._ambient_b.appendTo(this.$ambient),this._specular_r.appendTo(this.$specular),this._specular_g.appendTo(this.$specular),this._specular_b.appendTo(this.$specular),this._shininess.appendTo(this.$specular),this._gamma.value=this.planet.renderer.gamma,this._gamma.events.on("change",(e=>{this.planet.renderer.gamma=e})),this._exposure.value=this.planet.renderer.exposure,this._exposure.events.on("change",(e=>{this.planet.renderer.exposure=e})),this._atmosphereMinOpacity.value=this.planet.atmosphereMinOpacity,this._atmosphereMinOpacity.events.on("change",(e=>{this.planet.atmosphereMinOpacity=e})),this._atmosphereMaxOpacity.value=this.planet.atmosphereMaxOpacity,this._atmosphereMaxOpacity.events.on("change",(e=>{this.planet.atmosphereMaxOpacity=e,this.planet.renderer.controls.Atmosphere.opacity=e}));let s=this.planet.renderer.controls.SimpleSkyBackground;this._simpleSkyBackgroundColorOne.value=s.colorOne,this._simpleSkyBackgroundColorOne.events.on("input",(e=>{s.colorOne=e})),this._simpleSkyBackgroundColorTwo.value=s.colorTwo,this._simpleSkyBackgroundColorTwo.events.on("input",(e=>{s.colorTwo=e})),this._panel.el.querySelector("#layers").addEventListener("change",(e=>{const t=this.planet.getLayerByName(e.target.value);t&&this.bindLayer(t)})),this._night.events.on("change",(e=>{this._selectedLayer&&(this._selectedLayer.nightTextureCoefficient=e)})),this._opacity.events.on("change",(e=>{this._selectedLayer&&(this._selectedLayer.opacity=e)})),this._ambient_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[0]=e)})),this._ambient_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[1]=e)})),this._ambient_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[2]=e)})),this._diffuse_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[0]=e)})),this._diffuse_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[1]=e)})),this._diffuse_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[2]=e)})),this._specular_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[0]=e)})),this._specular_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[1]=e)})),this._specular_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[2]=e)})),this._shininess.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[3]=e)})),this.planet&&(this.planet.events.on("layeradd",this._onLayerAdd,this),this.planet.events.on("layerremove",this._onLayerRemove,this)),this._fetchLayers()}_update(){let e=this._selectedLayer;this._opacity.value=e&&e.opacity?e.opacity:0,this._night.value=e&&e.nightTextureCoefficient?e.nightTextureCoefficient:this.planet.nightTextureCoefficient;let t=e&&e._ambient?e._ambient:this.planet._ambient;this._ambient_r.value=t[0],this._ambient_g.value=t[1],this._ambient_b.value=t[2];let i=e&&e._diffuse?e._diffuse:this.planet._diffuse;this._diffuse_r.value=i[0],this._diffuse_g.value=i[1],this._diffuse_b.value=i[2];let n=e&&e._specular?e._specular:this.planet._specular;this._specular_r.value=n[0],this._specular_g.value=n[1],this._specular_b.value=n[2],this._shininess.value=n[3]}_fetchLayers(){if(this.planet)for(let e=0;e<this.planet.layers.length;e++)this._onLayerAdd(this.planet.layers[e])}_onLayerAdd(e){this.bindLayer(e);let t=document.createElement("option");t.value=e.name,t.innerText=e.name,this._panel.el.querySelector("#layers").appendChild(t),this._panel.el.querySelector("#layers").value=e.name}_onLayerRemove(e){}},MouseNavigation:br,MouseWheelZoomControl:class extends It{constructor(e={}){super(e),this._name="MouseWheelZoomControl",this.grabbedPoint=new oe,this._eye0=new oe,this.pointOnEarth=new oe,this.earthUp=new oe,this.inertia=.007,this.grabbedSpheroid=new At,this.planet=null,this.qRot=new ae,this.scaleRot=0,this.distDiff=.3,this.stepsCount=8,this.stepsForward=null,this.stepIndex=0,this._lmbDoubleClickActive=!0,this.minSlope=e.minSlope||.1,this._keyLock=new xr,this._deactivate=!1,this._move=0}oninit(){let e=document.createElement("div"),t=document.createElement("button"),i=document.createElement("button");e.className="ogZoomControl",t.className="ogZoomButton ogZoomIn",i.className="ogZoomButton ogZoomOut",e.appendChild(t),e.appendChild(i),this.renderer.div.appendChild(e),t.addEventListener("mousedown",(()=>this.zoomIn())),t.addEventListener("mouseup",(()=>this.stopZoom())),i.addEventListener("mousedown",(()=>this.zoomOut())),i.addEventListener("mouseup",(()=>this.stopZoom())),t.addEventListener("touchstart",(e=>{e.preventDefault(),this.zoomIn()})),t.addEventListener("touchend",(e=>{e.preventDefault(),this.stopZoom()})),t.addEventListener("touchcancel",(e=>{e.preventDefault(),this.stopZoom()})),i.addEventListener("touchstart",(e=>{e.preventDefault(),this.zoomOut()})),i.addEventListener("touchend",(e=>{e.preventDefault(),this.stopZoom()})),i.addEventListener("touchcancel",(e=>{e.preventDefault(),this.stopZoom()})),this.renderer.events.on("draw",this._draw,this)}zoomIn(){this.stepIndex||(this.planet.stopFlying(),this.stopRotation(),this._deactivate=!0,this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this.stepsForward=br.getMovePointsFromPixelTerrain(this.planet.camera,this.planet,this.stepsCount,this.distDiff,this.renderer.handler.getCenter(),!0,null)||null,this.stepsForward&&(this.stepIndex=this.stepsCount))}zoomOut(){this.stepIndex||(this.planet.stopFlying(),this.stopRotation(),this._deactivate=!0,this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this.stepsForward=br.getMovePointsFromPixelTerrain(this.planet.camera,this.planet,this.stepsCount,this.distDiff,this.renderer.handler.getCenter(),!1,null)||null,this.stepsForward&&(this.stepIndex=this.stepsCount))}stopRotation(){this.qRot.clear(),this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}stopZoom(){this._move=0,this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}_draw(){if(this._active){let e=this.renderer,t=this.planet.camera,i=t.eye.clone();if(this.stepIndex){e.controlsBag.scaleRot=1;let i=this.stepsForward[this.stepsCount-this.stepIndex--],n=t.maxAltitude+this.planet.ellipsoid.equatorialSize,r=t.minAltitude+this.planet.ellipsoid.equatorialSize;const s=i.eye.length();if(s>n||s<r)return;t.eye=i.eye,t._u=i.v,t._r=i.u,t._b=i.n,t.checkTerrainCollision(),t.update()}else this._deactivate&&(this._deactivate=!1,this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock));if(e.events.mouseState.leftButtonDown||!this.scaleRot)return;if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{e.controlsBag.scaleRot=this.scaleRot;let i=this.qRot.slerp(ae.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize();i.x||i.y||i.z||(this.scaleRot=0),t.eye=i.mulVec3(t.eye),t._u=i.mulVec3(t._u),t._r=i.mulVec3(t._r),t._b=i.mulVec3(t._b),t.checkTerrainCollision(),t.update()}t.eye.distance(i)/t.getAltitude()>.01?(this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock)):(this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock))}}},Ruler:Pr,RulerSwitcher:class extends It{constructor(e={}){super({name:"RulerSwitcher",...e}),this.ruler=new Ir({ignoreTerrain:e.ignoreTerrain})}oninit(){this.planet.addControl(this.ruler),this._createMenuBtn()}onactivate(){this.ruler.activate()}ondeactivate(){this.ruler.deactivate()}_createMenuBtn(){let e=new Ot({classList:["og-map-button","og-ruler_button"],icon:'<?xml version="1.0" encoding="iso-8859-1"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg fill="#000000" height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \n\t viewBox="0 0 512 512" xml:space="preserve">\n<g>\n\t<g>\n\t\t<path d="M369.151,0L0.001,369.15L142.85,512l369.149-369.15L369.151,0z M47.286,369.15l10.908-10.908l47.782,47.782l23.642-23.642\n\t\t\tL81.837,334.6l10.909-10.909l23.711,23.711L140.1,323.76l-23.711-23.711l10.909-10.909l23.711,23.711l23.642-23.642\n\t\t\tl-23.711-23.711l10.909-10.909l47.782,47.782l23.642-23.642l-47.782-47.782l10.908-10.908l23.71,23.71l23.642-23.642l-23.71-23.71\n\t\t\tl10.908-10.908l23.711,23.711l23.642-23.642l-23.711-23.711l10.909-10.909l47.782,47.782l23.642-23.642l-47.782-47.782\n\t\t\tl10.908-10.908l23.71,23.711l23.642-23.642l-23.711-23.71L334.6,81.837l23.711,23.71l23.642-23.642l-23.711-23.712l10.908-10.908\n\t\t\tl95.564,95.564L142.85,464.714L47.286,369.15z"/>\n\t</g>\n</g>\n</svg>'});e.appendTo(this.renderer.div),e.events.on("change",(e=>{e?this.onactivate():this.ondeactivate()}))}},ScaleControl:Fr,Selection:class extends It{constructor(e={}){super(e),this._selectorScene=new jr({name:`selectionScene:${this.__id}`,ignoreTerrain:e.ignoreTerrain,onSelect:e.onSelect,autoSelectionHide:e.autoSelectionHide}),this._toggleBtn=new Ot({classList:["og-map-button","og-selection_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg width="800px" height="800px" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--gis" preserveAspectRatio="xMidYMid meet"><path d="M2.1 0v1.914H0v6h3V3h5.1V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h1.8v1.2h3V0h-4.8zm1.8 7.2v6h3v-6h-3zM0 10.913v6h3v-6H0zM66.9 16.2v6h3v-6h-3zM0 19.914v6h3v-6H0zM66.9 25.2v6h3v-6h-3zM0 28.914v6h3v-6H0zM66.9 34.2v6h3v-6h-3zM0 37.914v6h3v-6H0zM66.9 43.2v6h3v-6h-3zM0 46.914v6h3v-6H0zM66.9 52.2v6h3v-6h-3zM0 55.914v5.191h3.809v-3H3v-2.19H0zm6.809 2.191v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9.648 1.899a2.076 2.076 0 0 0-2.19 2.324l3.137 33.676c.2 1.635 2.135 2.399 3.397 1.34l6.623-5.371l2.969 5.142c1.707 2.958 4.417 3.684 7.375 1.977c2.957-1.708 3.684-4.417 1.976-7.375l-2.959-5.125l7.848-3.008c1.548-.564 1.855-2.62.539-3.611L71.576 60.416a2.073 2.073 0 0 0-1.119-.412z" fill="#000000"></path></svg>'})}set ignoreTerrain(e){this._selectorScene.ignoreTerrain=e}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._toggleBtn.events.on("change",(e=>{e?this.activate():this.deactivate()})),this._selectorScene.bindPlanet(this.planet)}onactivate(){this.renderer.addNode(this._selectorScene)}ondeactivate(){this.renderer.removeNode(this._selectorScene)}},ShowFps:class extends It{constructor(e){super(e)}oninit(){let e=document.createElement("div");e.className="defaultText ",e.id="ogShowFpsControl",document.body.appendChild(e),this.renderer.events.on("draw",this._draw,this)}_draw(){Te("ogShowFpsControl",(1e3/this.renderer.handler.deltaTime).toFixed(1),this.renderer.handler.canvas.clientWidth-60,0)}},SimpleNavigation:class extends It{constructor(e={}){super({name:"SimpleNavigation",autoActivate:!0,...e}),this.speed=e.speed||1}oninit(){}onactivate(){super.onactivate();let e=this.renderer;e.events.on("keypress",dr.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",dr.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",dr.KEY_A,this.onCameraStrifeLeft,this),e.events.on("keypress",dr.KEY_D,this.onCameraStrifeRight,this),e.events.on("keypress",dr.KEY_UP,this.onCameraLookUp,this),e.events.on("keypress",dr.KEY_DOWN,this.onCameraLookDown,this),e.events.on("keypress",dr.KEY_LEFT,this.onCameraTurnLeft,this),e.events.on("keypress",dr.KEY_RIGHT,this.onCameraTurnRight,this),e.events.on("keypress",dr.KEY_Q,this.onCameraRollLeft,this),e.events.on("keypress",dr.KEY_E,this.onCameraRollRight,this)}ondeactivate(){super.ondeactivate();let e=this.renderer;e.events.off("keypress",dr.KEY_W,this.onCameraMoveForward),e.events.off("keypress",dr.KEY_S,this.onCameraMoveBackward),e.events.off("keypress",dr.KEY_A,this.onCameraStrifeLeft),e.events.off("keypress",dr.KEY_D,this.onCameraStrifeRight),e.events.off("keypress",dr.KEY_UP,this.onCameraLookUp),e.events.off("keypress",dr.KEY_DOWN,this.onCameraLookDown),e.events.off("keypress",dr.KEY_LEFT,this.onCameraTurnLeft),e.events.off("keypress",dr.KEY_RIGHT,this.onCameraTurnRight),e.events.off("keypress",dr.KEY_Q,this.onCameraRollLeft),e.events.off("keypress",dr.KEY_E,this.onCameraRollRight)}onCameraMoveForward(){if(this._active){let e=this.renderer.activeCamera;e.slide(0,0,-this.speed),e.update()}}onCameraMoveBackward(){let e=this.renderer.activeCamera;e.slide(0,0,this.speed),e.update()}onCameraStrifeLeft(){let e=this.renderer.activeCamera;e.slide(-this.speed,0,0),e.update()}onCameraStrifeRight(){let e=this.renderer.activeCamera;e.slide(this.speed,0,0),e.update()}onCameraLookUp(){let e=this.renderer.activeCamera;e.pitch(.5),e.update()}onCameraLookDown(){let e=this.renderer.activeCamera;e.pitch(-.5),e.update()}onCameraTurnLeft(){let e=this.renderer.activeCamera;e.yaw(.5),e.update()}onCameraTurnRight(){let e=this.renderer.activeCamera;e.yaw(-.5),e.update()}onCameraRollLeft(){let e=this.renderer.activeCamera;e.roll(-.5),e.update()}onCameraRollRight(){let e=this.renderer.activeCamera;e.roll(.5),e.update()}},SimpleSkyBackground:Dr,Sun:Vr,TimelineControl:class extends It{constructor(e={}){super({name:"timeline",...e});let t=e.current||new Date,i=e.rangeStart||ss(t,-12),n=e.rangeEnd||ss(t,12);this._timelineView=new rs({rangeStart:i,rangeEnd:n,currentDate:t}),this._toggleBtn=new Ot({classList:["og-map-button","og-timeline_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">\n <metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n <g><path d="M500,10C229.4,10,10,229.4,10,500s219.4,490,490,490s490-219.4,490-490S770.6,10,500,10z M800.3,800.3c-39,39-84.5,69.7-135,91C613,913.5,557.4,924.7,500,924.7s-112.9-11.2-165.3-33.3c-50.5-21.3-95.9-52-135-91c-39-39-69.7-84.5-91-135C86.5,612.9,75.3,557.4,75.3,500s11.2-112.9,33.3-165.3c21.3-50.5,52-95.9,91-135c39-39,84.5-69.7,135-91C387.1,86.5,442.6,75.3,500,75.3s112.9,11.2,165.3,33.3c50.5,21.3,95.9,52,135,91c39,39,69.7,84.5,91,135c22.1,52.3,33.3,107.9,33.3,165.3s-11.2,112.9-33.3,165.3C869.9,715.8,839.3,761.2,800.3,800.3z"/><path d="M761.3,532.7H532.7V304c0-18.1-14.6-32.7-32.7-32.7s-32.7,14.6-32.7,32.7v261.3l0,0c0,18.1,14.6,32.7,32.7,32.7h261.3c18.1,0,32.7-14.6,32.7-32.7l0,0C794,547.3,779.4,532.7,761.3,532.7z"/></g>\n</svg>'}),this._dialog=new Nt({title:"Timeline",visible:!1,resizable:!0,useHide:!0,top:10,left:60,width:600,height:115,minHeight:115,maxHeight:110}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)}))}oninit(){let e=this.renderer.div;this._toggleBtn.appendTo(e),this._dialog.appendTo(e),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e),e&&this._timelineView.resize()})),this._timelineView.appendTo(this._dialog.container),this._timelineView.events.on("setcurrent",(e=>{this.renderer&&this.renderer.handler.defaultClock.setDate(e)})),this._timelineView.events.on("startdrag",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.deactivate()})),this._timelineView.events.on("stopdrag",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.activate()})),this._timelineView.events.on("startdragcurrent",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.deactivate()})),this._timelineView.events.on("stopdragcurrent",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.activate()}))}},ToggleWireframe:class extends It{constructor(e={}){super(e),this._isActive=!1,this.toogleWireframe=()=>{this.renderer&&this.renderer.handler.gl&&(this.planet.drawMode===this.renderer.handler.gl.LINE_STRIP?this.planet.setDrawMode(this.renderer.handler.gl.TRIANGLE_STRIP):this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP))},this._isActive=e.isActive||!1}oninit(){this.renderer.events.on("charkeypress",dr.KEY_X,this.toogleWireframe,this),this._isActive&&this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP)}},TouchNavigation:Gr,ZoomControl:Wr});function Ps(e){return new Uint32Array(e)}function Ms(e){let t=[],i=0,n=0,r=0;for(let s=1;s<e-1-1;s++){for(let a=1;a<e-1;a++)i=s*e+a,r=(s+1)*e,n=r+a,t.push(i,n);t.push(n,r+1)}return t.push(t[t.length-1],e*e-e),Ps(t)}function Ss(e,t){let i=[];const n=(e-1)/t,r=e*e-e;let s=0;for(let t=0;t<e-2;t++){t%n==0&&(s=t);let a=r-e*t-e+1,o=r-e*s;i.push(o,a)}return t===e-1&&(i.push(e),i.push(0)),Ps(i)}function Bs(e,t){let i=[];const n=(e-1)/t;let r=0;for(let t=0;t<e-2;t++){t%n==0&&(r=t);let s=e+t+1,a=r;i.push(a,s)}return t===e-1&&(i.push(e-2),i.push(e-1)),Ps(i)}function ks(e,t){let i=[];const n=(e-1)/t;let r=0;for(let t=0;t<e-2;t++){t%n==0&&(r=t);let s=e*(t+1)+e-2,a=e+e*r-1;i.push(a,s)}return t===e-1&&(i.push(e*(e-1)-1),i.push(e*e-1)),Ps(i)}function Rs(e,t){let i=[];const n=(e-1)/t;let r=0;const s=e*(e-1)-2,a=e*e-1;for(let t=0;t<e-2;t++){t%n==0&&(r=t);let e=s-t,o=a-r;i.push(o,e)}return t===e-1&&i.push(e*e-e+1),i.push(e*e-e),Ps(i)}function Is(e){let t=[[],[],[],[]];for(let i=0;i<=e;i++){let n=Math.pow(2,i)+1;t[0][i]=[],t[3][i]=[],t[2][i]=[],t[1][i]=[];for(let r=0;r<=e;r++){let e=Math.pow(2,r);t[3][i][r]=Ss(n,e),t[0][i][r]=Bs(n,e),t[1][i][r]=ks(n,e),t[2][i][r]=Rs(n,e)}}return t}function zs(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=Ms(e+1)}return t}function Fs(e){let t=new Uint16Array((e+1)*(e+1)*2),i=0;for(let n=0;n<=e;n++)for(let r=0;r<=e;r++)t[i++]=r/e*65535,t[i++]=n/e*65535;return t}let Ds=new class{constructor(e=0){this._maxGridSize=e,this.centerIndexesTable=zs(this._maxGridSize),this.skirtsIndexesTable=Is(this._maxGridSize)}get maxGridSize(){return this._maxGridSize}init(){this.centerIndexesTable=zs(this._maxGridSize),this.skirtsIndexesTable=Is(this._maxGridSize)}setMaxGridSize(e){this._maxGridSize=e,this.init()}createSegmentIndexes(e,t){if(e){let i=this.centerIndexesTable[e],n=this.skirtsIndexesTable[3][e][t[3]],r=this.skirtsIndexesTable[0][e][t[0]],s=this.skirtsIndexesTable[1][e][t[1]],a=this.skirtsIndexesTable[2][e][t[2]],o=function(e){return new Uint32Array(e)}(i.length+n.length+r.length+s.length+a.length);return o.set(i,0),o.set(n,i.length),o.set(r,i.length+n.length),o.set(s,i.length+n.length+r.length),o.set(a,i.length+n.length+r.length+s.length),o}return Ps([0,2,1,3])}initTextureCoordsTable(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=Fs(e)}return t}};function Ns(){return Ds}const Hs="\n float getLerpValue(in float min, in float max, in float between)\n {\n return (clamp(between, min, max) - min) / (max - min);\n }\n \n vec3 aces(vec3 color) \n {\n float a = 2.51;\n float b = 0.03;\n float c = 2.43;\n float d = 0.59;\n float e = 0.14;\n return clamp((color * (a * color + b)) / (color * (c * color + d ) + e), 0.0, 1.0);\n }\n \n bool intersectSphere(vec3 rayOrigin, vec3 rayDirection, float radius, inout float t1, inout float t2) \n {\n float b = dot(rayDirection, rayOrigin);\n float c = dot(rayOrigin, rayOrigin) - radius * radius;\n float d = b * b - c;\n if (d < 0.0) {\n return false;\n }\n t1 = -b - sqrt(d);\n t2 = -b + sqrt(d);\n return true;\n }\n \n bool intersectSphere(vec3 rayOrigin, vec3 rayDirection, float radius, inout float t) \n {\n float b = dot(rayDirection, rayOrigin);\n float c = dot(rayOrigin, rayOrigin) - radius * radius;\n float d = b * b - c;\n if (d < 0.0) {\n return false;\n }\n t = -b - sqrt(d);\n return true;\n }\n \n bool intersectEllipsoid( in vec3 ro, in vec3 rd, in vec3 ra, inout float t )\n {\n vec3 ocn = ro/ra;\n vec3 rdn = rd/ra;\n float a = dot( rdn, rdn );\n float b = dot( ocn, rdn );\n float c = dot( ocn, ocn );\n float h = b*b - a*(c-1.0);\n \n if (h < 0.0) \n { \n return false; \n }\n \n t = (-b-sqrt(h))/a;\n \n return true;\n }\n \n bool intersectEllipsoid( in vec3 ro, in vec3 rd, in vec3 ra, inout float t1, inout float t2)\n {\n vec3 ocn = ro/ra;\n vec3 rdn = rd/ra;\n float a = dot( rdn, rdn );\n float b = dot( ocn, rdn );\n float c = dot( ocn, ocn );\n float h = b*b - a*(c-1.0);\n \n if (h < 0.0) \n { \n return false; \n }\n \n h = sqrt(h);\n t1 = (-b-h)/a;\n t2 = (-b+h)/a;\n \n return true;\n }\n \n vec3 normalEllipsoid( in vec3 pos, in vec3 ra )\n {\n return normalize( pos/(ra*ra) );\n }\n",Os=`\n \n ${Hs}\n \n #define PI 3.1415926538\n #define ATMOS_HEIGHT 100000.0\n #define RAYLEIGH_SCALE 0.08\n #define MIE_SCALE 0.012\n \n #define SAMPLE_COUNT 16\n #define SQRT_SAMPLE_COUNT 4\n \n const float GROUND_ALBEDO = 0.05 / PI;\n\n // Sphere\n const float BOTTOM_RADIUS = 6356752.3142451793;\n const float TOP_RADIUS = 6356752.3142451793 + ATMOS_HEIGHT;\n \n // Ellipsoid\n const vec3 bottomRadii = vec3(6378137.0, 6378137.0, 6356752.3142451793); \n const vec3 topRadii = bottomRadii + ATMOS_HEIGHT;\n \n const vec3 SPHERE_TO_ELLIPSOID_SCALE = vec3(BOTTOM_RADIUS) / bottomRadii; \n \n const vec2 rayleighMieHeights = vec2(RAYLEIGH_SCALE, MIE_SCALE) * ATMOS_HEIGHT;\n \n const vec3 rayleighScatteringCoefficient = vec3(5.802, 13.558, 33.100) * 1e-6;\n \n const float mieScatteringCoefficient = 3.996e-06;\n const float mieExtinctionCoefficient = 4.440e-06;\n const vec3 ozoneAbsorptionCoefficient = vec3(0.650, 1.881, 0.085) * 1e-6;\n \n const float SUN_ANGULAR_RADIUS = 0.004685;\n const float SUN_INTENSITY = 1.0; \n \n vec3 sunWithBloom(vec3 rayDir, vec3 sunDir) \n {\n float minSunCosTheta = cos(SUN_ANGULAR_RADIUS); \n float cosTheta = dot(rayDir, sunDir);\n if (cosTheta >= minSunCosTheta) return vec3(1.0); \n float offset = minSunCosTheta - cosTheta;\n float gaussianBloom = exp(-offset*15000.0)*0.7;\n float invBloom = 1.0/(0.09 + offset*200.0)*0.01;\n return vec3(gaussianBloom + invBloom);\n }\n \n float rayleighPhase(float angle) \n {\n return 3.0 / (16.0 * PI) * (1.0 + (angle * angle));\n }\n \n float miePhase(float angle) \n {\n float g = 0.8;\n return 3.0 / (8.0 * PI) * ((1.0 - g * g) * (1.0 + angle * angle)) / ((2.0 + g * g) * pow(1.0 + g * g - 2.0 * g * angle, 1.5));\n }\n \n vec3 opticalDepth(float height, float angle) \n {\n vec3 rayOrigin = vec3(0.0, BOTTOM_RADIUS + height, 0.0);\n vec3 rayDirection = vec3(sqrt(1.0 - angle * angle), angle, 0.0);\n float t1, t2;\n intersectSphere(rayOrigin, rayDirection, TOP_RADIUS, t1, t2);\n float segmentLength = t2 / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n vec3 opticalDepth = vec3(0.0);\n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n opticalDepth.xy += exp(-height / rayleighMieHeights) * segmentLength;\n \n // density of the ozone layer is modeled as a triangular \n // function that is 30 km wide and centered at 25 km altitude\n opticalDepth.z += (1.0 - min(abs(height - 25e3) / 15e3, 1.0)) * segmentLength; \n t += segmentLength;\n }\n \n return opticalDepth;\n }\n \n vec3 transmittance(float height, float angle) \n {\n vec3 opticalDepth = opticalDepth(height, angle);\n return exp(-(rayleighScatteringCoefficient * opticalDepth.x + mieExtinctionCoefficient * opticalDepth.y + ozoneAbsorptionCoefficient * opticalDepth.z));\n }`;const Vs="const vec3 nightStep = 10.0 * vec3(0.58, 0.48, 0.25);",Us="#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = texture( SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw ); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;",Gs="#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = texture2D( SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw ); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;";function Ws(){return new zi("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightsPositions:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"\n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec4 vTextureCoord;\n varying vec3 v_vertex;\n varying vec3 cameraPosition;\n varying vec2 vGlobalTextureCoord;\n varying float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n\n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`\n precision highp float;\n \n #define MAX_POINT_LIGHTS 1\n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient;\n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec3 lightsPositions[MAX_POINT_LIGHTS];\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient; \n uniform float camHeight;\n\n varying vec4 vTextureCoord;\n varying vec3 v_vertex;\n varying vec3 cameraPosition;\n varying vec2 vGlobalTextureCoord;\n varying float v_height;\n\n vec3 sunPos;\n\n ${Vs}\n\n ${Gs}\n \n ${Hs}\n \n void main(void) {\n \n sunPos = lightsPositions[0];\n \n vec3 texNormal = texture2D(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture2D( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0); \n vec4 nightImageColor = texture2D( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + diffuse * diffuseLightWeighting + night, 1.0);\n \n gl_FragColor = texture2D( defaultTexture, vTextureCoord.xy );\n if( samplerCount == 0 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n vec4 src;\n\n blend(gl_FragColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n }`})}class js{constructor(e,t={}){this.handler=e,this._fbo=null,this._width=t.width||e.canvas.width,this._height=t.height||e.canvas.height,this._depthComponent=null!=t.depthComponent?t.depthComponent:"DEPTH_COMPONENT16",this._useDepth=null==t.useDepth||t.useDepth,this._active=!1,this._size=t.size||1,this._depthRenderbuffer=null,this._filter=t.filter||"NEAREST"}get width(){return this._width}get height(){return this._height}setSize(e,t,i=!1){this._width=e,this._height=t,this._active&&this.handler.gl.viewport(0,0,this._width,this._height),(this._useDepth||i)&&(this.destroy(),this.init())}init(){}destroy(){}isComplete(){let e=this.handler.gl;return e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE}checkStatus(){let e=this.handler.gl;return e.checkFramebufferStatus(e.FRAMEBUFFER)}activate(){let e=this.handler.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo),e.viewport(0,0,this._width,this._height),this._active=!0;let t=this.handler.framebufferStack.current().data;return t&&(t._active=!1),this.handler.framebufferStack.push(this),this}deactivate(){let e=this.handler,t=e.gl;t.bindFramebuffer(t.FRAMEBUFFER,null),this._active=!1;let i=this.handler.framebufferStack.popPrev();i?(t.bindFramebuffer(t.FRAMEBUFFER,i._fbo),t.viewport(0,0,i._width,i._height)):t.viewport(0,0,e.canvas.width,e.canvas.height)}}class Ys{constructor(e=256,t=256){this._canvas=document.createElement("canvas"),this._canvas.width=e,this._canvas.height=t,this._context=this._canvas.getContext("2d",{willReadFrequently:!0})}getCanvas(){return this._canvas}getContext(){return this._context}fillEmpty(){let e=this._context.getImageData(0,0,this._canvas.width,this._canvas.height),t=e.data;for(let e=0,i=t.length;e<i;e+=4)t[e]=t[e+1]=t[e+2]=t[e+3]=0;this._context.putImageData(e,0,0)}fill(e){this._context.fillStyle=e,this._context.fill()}getData(){return this._context.getImageData(0,0,this._canvas.width,this._canvas.height).data}fillColor(e){this._context.fillStyle=e,this._context.fillRect(0,0,this._canvas.width,this._canvas.height)}setData(e){let t=this._context.createImageData(this._canvas.width,this._canvas.height);t.data.set(e),this._context.putImageData(t,0,0)}resize(e,t){this._canvas.width=e,this._canvas.height=t,this._context=this._canvas.getContext("2d")}drawImage(e,t,i,n,r){this._context.drawImage(e,t||0,i||0,n||e.width,r||e.height)}getImage(){let e=new Image;return e.width=this.getWidth(),e.height=this.getHeight(),e.src=this._canvas.toDataURL("image/png"),e}getTextWidth(e){let t=this._context.measureText(e);return Math.round(t.width)}drawText(e,t=0,i=14,n="normal 14px Verdana",r="black"){this._context.fillStyle=r,this._context.font=n,this._context.fillText(e,t,i)}getWidth(){return this._canvas.width}getHeight(){return this._canvas.height}load(e,t){let i=new Image,n=this;i.onload=function(){n.resize(i.width,i.height),n._context.drawImage(i,0,0,i.width,i.height),t&&t(i)},i.src=e}openImage(){let e=this.getImage(),t="<!DOCTYPE html>";t+="<html>",t+="<head><title>Print</title></head>",t+="<body>",t+='<img src="'+e.src+'">',t+="</body>",t+="</html>";let i=window.open("","","width="+e.width+"px ,height="+e.height+"px");i&&(i.document.open(),i.document.write(t),i.document.close(),i.focus())}destroy(){this._canvas.width=1,this._canvas.height=1,this._canvas=null,this._context=null}}class qs extends js{constructor(e,t={}){super(e,t),this._isBare=t.isBare||!1,this._internalFormatArr=t.internalFormat instanceof Array?t.internalFormat:[t.internalFormat||"RGBA"],this._formatArr=t.format instanceof Array?t.format:[t.format||"RGBA"],this._typeArr=t.type instanceof Array?t.type:[t.type||"UNSIGNED_BYTE"],t.attachment instanceof Array?this._attachmentArr=t.attachment.map(((e,t)=>{let i=e.toUpperCase();return"COLOR_ATTACHMENT"===i?`${i}${t.toString()}`:i})):this._attachmentArr=[t.attachment||"COLOR_ATTACHMENT0"],this._renderbufferTarget=null!=t.renderbufferTarget?t.renderbufferTarget:"DEPTH_ATTACHMENT",this.textures=t.textures||new Array(this._size)}destroy(){let e=this.handler.gl;if(e){for(let t=0;t<this.textures.length;t++)e.deleteTexture(this.textures[t]);this.textures=new Array(this._size),e.deleteFramebuffer(this._fbo),e.deleteRenderbuffer(this._depthRenderbuffer),this._depthRenderbuffer=null,this._fbo=null,this._active=!1}}init(){let e=this.handler.gl;if(e){if(this._fbo=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo),!this._isBare){let t=[];for(let i=0;i<this.textures.length;i++){let n=this.textures[i]||this.handler.createEmptyTexture2DExt(this._width,this._height,this._filter,this._internalFormatArr[i],this._formatArr[i],this._typeArr[i]),r=e[this._attachmentArr[i]];n&&(this.bindOutputTexture(n,r),this.textures[i]=n),"DEPTH_ATTACHMENT"!=this._attachmentArr[i]&&t.push(r)}e.drawBuffers&&e.drawBuffers(t)}this._useDepth&&(this._depthRenderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this._depthRenderbuffer),e.renderbufferStorage(e.RENDERBUFFER,e[this._depthComponent],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e[this._renderbufferTarget],e.RENDERBUFFER,this._depthRenderbuffer),e.bindRenderbuffer(e.RENDERBUFFER,null)),e.bindFramebuffer(e.FRAMEBUFFER,null)}}bindOutputTexture(e,t){let i=this.handler.gl;i.bindTexture(i.TEXTURE_2D,e),i.framebufferTexture2D(i.FRAMEBUFFER,t||i.COLOR_ATTACHMENT0,i.TEXTURE_2D,e,0),i.bindTexture(i.TEXTURE_2D,null)}readPixels(e,t,i,n=0,r=1,s=1){let a=this.handler.gl;a.bindFramebuffer(a.FRAMEBUFFER,this._fbo),a.readBuffer&&a.readBuffer(a.COLOR_ATTACHMENT0+n||0),a.readPixels(t*this._width,i*this._height,r,s,a.RGBA,a[this._typeArr[n]],e),a.bindFramebuffer(a.FRAMEBUFFER,null)}readAllPixels(e,t=0){let i=this.handler.gl;i.bindFramebuffer(i.FRAMEBUFFER,this._fbo),i.readBuffer&&i.readBuffer(i.COLOR_ATTACHMENT0+t),i.readPixels(0,0,this._width,this._height,i.RGBA,i[this._typeArr[t]],e),i.bindFramebuffer(i.FRAMEBUFFER,null)}getImage(){let e=new Uint8Array(4*this._width*this._height);this.readAllPixels(e);let t=new Ys(this._width,this._height);return t.setData(e),t.getImage()}}class Xs extends It{constructor(e={}){super({name:"Atmosphere",...e}),this._transmittanceBuffer=null,this._scatteringBuffer=null,this.opacity=1}oninit(){this.renderer&&(this.renderer.handler.addProgram(new zi("transmittance",{uniforms:{iResolution:"vec2"},attributes:{a_position:"vec2"},vertexShader:"\n attribute vec2 a_position;\n \n void main(void) \n {\n gl_Position = vec4(a_position, 0.0, 1.0);\n }",fragmentShader:`\n precision highp float;\n \n ${Os}\n \n uniform vec2 iResolution;\n \n void main(void) \n {\n vec2 uv = gl_FragCoord.xy / iResolution.xy;\n float height = uv.y * ATMOS_HEIGHT;\n float angle = uv.x * 2.0 - 1.0;\n gl_FragColor = vec4(transmittance(height, angle), 1.0);\n }`}),!0),this.renderer.handler.addProgram(new zi("scattering",{uniforms:{iResolution:"vec2",transmittanceTexture:"sampler2d"},attributes:{a_position:"vec2"},vertexShader:" \n attribute vec2 a_position; \n \n void main(void) \n {\n gl_Position = vec4(a_position, 0.0, 1.0);\n }",fragmentShader:` \n precision highp float;\n \n uniform sampler2D transmittanceTexture;\n uniform vec2 iResolution;\n \n ${Os}\n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(transmittanceTexture, vec2(u, v)).xyz;\n }\n \n void main(void) \n {\n vec2 uv = gl_FragCoord.xy / iResolution.xy;\n \n float height = uv.y * ATMOS_HEIGHT;\n float angle = uv.x * 2.0 - 1.0;\n \n vec3 rayOrigin = vec3(0.0, BOTTOM_RADIUS + height, 0.0);\n vec3 up = rayOrigin / length(rayOrigin);\n vec3 lightDirection = vec3(sqrt(1.0 - angle * angle), angle, 0.0);\n \n const float isotropicPhase = 1.0 / (4.0 * PI);\n \n vec3 light = vec3(0.0);\n vec3 lightTransferFactor = vec3(0.0);\n \n for (int i = 0; i < SQRT_SAMPLE_COUNT; i++)\n {\n for (int j = 0; j < SQRT_SAMPLE_COUNT; j++)\n {\n float u = ((0.5 + float(i)) / float(SQRT_SAMPLE_COUNT)) * 2.0 - 1.0;\n float v = (0.5 + float(j)) / float(SQRT_SAMPLE_COUNT);\n float r = sqrt(1.0 - u * u);\n float theta = 2.0 * PI * v;\n vec3 rayDirection = vec3(cos(theta) * r, sin(theta) * r, u);\n \n float rayAngle = dot(up, rayDirection);\n bool cameraBelow = rayAngle < 0.0;\n \n vec3 transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n intersectSphere(rayOrigin, rayDirection, TOP_RADIUS, offset, distanceToSpace);\n \n float distanceToGround = 0.0;\n bool hitGround = intersectSphere(rayOrigin, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0; \n float segmentLength = (hitGround ? distanceToGround : distanceToSpace) / float(SAMPLE_COUNT);\n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera;\n vec3 transmittanceLight;\n \n for (int k = 0; k < SAMPLE_COUNT; k++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDirection);\n \n float distanceToGround;\n float shadow = intersectSphere(position, lightDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround >= 0.0 ? 0.0 : 1.0;\n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n \n vec2 opticalDensity = exp(-height / rayleighMieHeights); \n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y) * isotropicPhase;\n \n light += shadow * transmittanceCamera * scatteredLight * segmentLength;\n lightTransferFactor += transmittanceCamera * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y) * segmentLength;\n \n t += segmentLength;\n }\n \n if (hitGround) \n {\n vec3 hitPoint = rayOrigin + rayDirection * distanceToGround;\n vec3 normal = normalize(hitPoint);\n float diffuseAngle = max(dot(normal, lightDirection), 0.0); \n float earthAlbedo = 0.05;\n light += transmittanceCamera * transmittanceLight * (earthAlbedo / PI) * diffuseAngle;\n }\n }\n }\n \n light /= float(SAMPLE_COUNT);\n lightTransferFactor /= float(SAMPLE_COUNT);\n vec3 color = light / (1.0 - lightTransferFactor); \n gl_FragColor = vec4(color, 1.0);\n }`}),!0),this.renderer.handler.addProgram(new zi("atmosphereBackground",{uniforms:{iResolution:"vec2",fov:"float",camPos:"vec3",viewMatrix:"mat4",transmittanceTexture:"sampler2D",scatteringTexture:"sampler2D",sunPos:"vec3",opacity:"float"},attributes:{corners:"vec3"},vertexShader:" \n attribute vec2 corners;\n \n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n }",fragmentShader:` \n precision lowp float;\n \n ${Os}\n \n uniform mat4 viewMatrix;\n uniform vec3 sunPos;\n uniform vec3 camPos; \n uniform vec2 iResolution;\n uniform float fov;\n uniform float opacity;\n \n uniform sampler2D transmittanceTexture;\n uniform sampler2D scatteringTexture;\n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(transmittanceTexture, vec2(u, v)).xyz;\n }\n \n vec3 multipleScatteringContributionFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(scatteringTexture, vec2(u, v)).xyz; \n }\n\n bool intersectEllipsoidToSphere(in vec3 ro, in vec3 rd, in vec3 ellRadii, in float sphereRadius, out float t1, out float t2) \n {\n float offset = 0.0,\n distanceToSpace = 0.0;\n \n if(intersectEllipsoid(ro, rd, ellRadii, offset, distanceToSpace)){\n vec3 hitEll = ro + rd * offset;\n vec3 nEll = normalEllipsoid(hitEll, ellRadii);\n float t = 0.0;\n bool intersectsSphere = intersectSphere(hitEll, nEll, sphereRadius, t);\n vec3 hitSphere = hitEll + nEll * t;\n t1 = length(hitSphere - ro);\n \n hitEll = ro + rd * distanceToSpace;\n nEll = normalEllipsoid(hitEll, ellRadii);\n t = 0.0;\n intersectsSphere = intersectSphere(hitEll, nEll, sphereRadius, t);\n hitSphere = hitEll + nEll * t;\n t2 = length(hitSphere - ro);\n \n return true; \n }\n return false; \n }\n \n mat4 transpose(in mat4 m) \n {\n vec4 i0 = m[0];\n vec4 i1 = m[1];\n vec4 i2 = m[2];\n vec4 i3 = m[3];\n \n mat4 outMatrix = mat4(\n vec4(i0.x, i1.x, i2.x, i3.x),\n vec4(i0.y, i1.y, i2.y, i3.y),\n vec4(i0.z, i1.z, i2.z, i3.z),\n vec4(i0.w, i1.w, i2.w, i3.w)\n );\n \n return outMatrix;\n }\n \n void mainImage(out vec4 fragColor) \n { \n vec3 cameraPosition = camPos;\n \n vec3 lightDirection = normalize(sunPos); \n \n vec2 uv = (2.0 * gl_FragCoord.xy - iResolution.xy) / iResolution.y;\n float fieldOfView = fov;\n float z = 1.0 / tan(fieldOfView * 0.5 * PI / 180.0);\n vec3 rayDirection = normalize(vec3(uv, -z));\n vec4 rd = transpose(viewMatrix) * vec4(rayDirection, 1.0);\n rayDirection = rd.xyz; \n \n vec3 light = vec3(0.0);\n vec3 transmittanceFromCameraToSpace = vec3(1.0);\n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n rayDirection = normalize(rayDirection * SPHERE_TO_ELLIPSOID_SCALE);\n cameraPosition *= SPHERE_TO_ELLIPSOID_SCALE;\n lightDirection = normalize(lightDirection * SPHERE_TO_ELLIPSOID_SCALE);\n \n if (intersectSphere(cameraPosition, rayDirection, TOP_RADIUS, offset, distanceToSpace)) \n { \n vec3 rayOrigin = cameraPosition;\n \n // above atmosphere \n if (offset > 0.0) {\n // intersection of camera ray with atmosphere\n rayOrigin = cameraPosition + rayDirection * offset;\n } \n \n float height = length(rayOrigin) - BOTTOM_RADIUS;\n float rayAngle = dot(rayOrigin, rayDirection) / length(rayOrigin);\n bool cameraBelow = rayAngle < 0.0;\n \n transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float phaseAngle = dot(lightDirection, rayDirection);\n float rayleighPhase = rayleighPhase(phaseAngle);\n float miePhase = miePhase(phaseAngle);\n \n float distanceToGround = 0.0;\n \n bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n \n if(intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS - 15000.0, distanceToGround) && hitGround)\n {\n discard;\n }\n \n float segmentLength = ((hitGround ? distanceToGround : distanceToSpace) - max(offset, 0.0)) / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera; \n vec3 transmittanceLight; \n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS; \n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDirection);\n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n vec2 opticalDensity = exp(-height / rayleighMieHeights);\n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x * rayleighPhase + mieScatteringCoefficient * opticalDensity.y * miePhase);\n scatteredLight += multipleScatteringContributionFromTexture(height, lightAngle) * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y); \n light += transmittanceCamera * scatteredLight * segmentLength;\n t += segmentLength;\n }\n \n light *= SUN_INTENSITY;\n \n if (hitGround) \n {\n vec3 hitPoint = cameraPosition + rayDirection * distanceToGround;\n vec3 up = hitPoint / length(hitPoint);\n float diffuseAngle = max(dot(up, lightDirection), 0.0);\n float lightAngle = dot(up, lightDirection);\n light += transmittanceCamera * GROUND_ALBEDO * multipleScatteringContributionFromTexture(height, lightAngle) * SUN_INTENSITY;\n light += transmittanceCamera * transmittanceLight * GROUND_ALBEDO * diffuseAngle * SUN_INTENSITY;\n }\n }\n \n // sun disk\n // float distanceToGround;\n // bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n // if (!hitGround) {\n // float angle = dot(rayDirection, lightDirection);\n // if (angle > cos(SUN_ANGULAR_RADIUS)) {\n // light = SUN_INTENSITY * transmittanceFromCameraToSpace;\n // }\n // }\n \n float distanceToGround = 0.0;\n bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n if(!hitGround)\n {\n vec3 sunLum = sunWithBloom(rayDirection, lightDirection) * vec3(1.0,1.0,0.8);\n // limit the bloom effect\n sunLum = smoothstep(0.002, 1.0, sunLum);\n light += sunLum * SUN_INTENSITY * transmittanceFromCameraToSpace;\n }\n \n fragColor = vec4(pow(light * 8.0, vec3(1.0 / 2.2)), clamp(opacity, 0.0, 1.0)); \n }\n \n void main(void) \n { \n mainImage(gl_FragColor); \n }`}),!0),this._drawAtmosphereTextures(),this.activate())}onactivate(){super.onactivate(),this.planet&&this.planet.events.on("draw",this._drawBackground,this)}ondeactivate(){super.ondeactivate(),this.planet&&this.planet.events.off("draw",this._drawBackground)}_drawAtmosphereTextures(){this._transmittanceBuffer=new qs(this.renderer.handler,{width:1024,height:1024,useDepth:!1,filter:"LINEAR",type:"FLOAT",internalFormat:"RGBA16F"}),this._transmittanceBuffer.init(),this._scatteringBuffer=new qs(this.renderer.handler,{width:1024,height:1024,useDepth:!1,filter:"LINEAR",type:"FLOAT",internalFormat:"RGBA16F"}),this._scatteringBuffer.init();let e=this.renderer.screenFramePositionBuffer,t=this.renderer.handler,i=t.gl;this._transmittanceBuffer.activate();let n=t.programs.transmittance,r=n._program.attributes,s=n._program.uniforms;n.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(s.iResolution,[this._transmittanceBuffer.width,this._transmittanceBuffer.height]),i.bindBuffer(i.ARRAY_BUFFER,e),i.vertexAttribPointer(r.a_position,e.itemSize,i.FLOAT,!1,0,0),i.drawArrays(i.TRIANGLE_STRIP,0,e.numItems),this._transmittanceBuffer.deactivate(),this._scatteringBuffer.activate(),n=t.programs.scattering,r=n._program.attributes,s=n._program.uniforms,n.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(s.iResolution,[this._scatteringBuffer.width,this._scatteringBuffer.height]),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._transmittanceBuffer.textures[0]),i.uniform1i(s.transmittanceTexture,0),i.bindBuffer(i.ARRAY_BUFFER,e),i.vertexAttribPointer(r.a_position,e.itemSize,i.FLOAT,!1,0,0),i.drawArrays(i.TRIANGLE_STRIP,0,e.numItems),this._scatteringBuffer.deactivate(),this._scatteringBuffer.isComplete()&&t.removeProgram("scattering"),this._transmittanceBuffer.isComplete()&&t.removeProgram("transmittance")}_drawBackground(){let e=this.renderer.handler,t=e.programs.atmosphereBackground,i=t._program,n=i.uniforms,r=e.gl,s=this.renderer,a=this.planet.camera;r.disable(r.DEPTH_TEST),t.activate(),r.bindBuffer(r.ARRAY_BUFFER,s.screenFramePositionBuffer),r.vertexAttribPointer(i.attributes.corners,2,r.FLOAT,!1,0,0),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this._transmittanceBuffer.textures[0]),r.uniform1i(n.transmittanceTexture,0),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,this._scatteringBuffer.textures[0]),r.uniform1i(n.scatteringTexture,1),r.uniformMatrix4fv(n.viewMatrix,!1,a.getViewMatrix());let o=this.planet.sunPos;r.uniform3fv(n.sunPos,[o.x,o.y,o.z]),r.uniform3fv(n.camPos,[a.eye.x,a.eye.y,a.eye.z]),r.uniform2fv(n.iResolution,[s.sceneFramebuffer.width,s.sceneFramebuffer.height]),r.uniform1f(n.fov,a.getViewAngle()),r.uniform1f(n.opacity,this.opacity),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST)}}const Zs="degrees",$s="m";let Ks=0;class Qs{constructor(e){this.id=Ks++,this.code=e.code,this.units=e.units}equal(e){return e.id===this.id}}const Js=new Qs({code:"epsg:3857",units:$s}),ea=new Qs({code:"epsg:4326",units:Zs});class ta{constructor(e){this.segment=e,this.layers=[],this.tileOffsetArr=new Float32Array(e.planet.SLICE_SIZE_4),this.layerOpacityArr=new Float32Array(e.planet.SLICE_SIZE)}clear(){this.layers=null,this.tileOffsetArr=null,this.layerOpacityArr=null}append(e,t){let i=this.layers.length;this.layers.push(e),this.layerOpacityArr[i]=e.screenOpacity;let n=4*i,r=e.applyMaterial(t);this.tileOffsetArr[n]=r[0],this.tileOffsetArr[n+1]=r[1],this.tileOffsetArr[n+2]=r[2],this.tileOffsetArr[n+3]=r[3]}}function ia(e,t,i){return Math.floor(Math.abs(i-e)/t)}function na(e,t,i,n){let r=1/(1<<i),s=n.getWidth()*r,a=n.getHeight()*r,o=n.southWest.lon+e*s,l=n.northEast.lat-t*a;return new ie(new z(o,l-a),new z(o+s,l))}const ra=20,sa=300;let aa=new oe,oa=new oe,la=new oe,ha=new oe,ca=new oe,da=new oe,_a=new _i,ua=new _i;const fa=new Array(4);fa[0]=0,fa[1]=1,fa[2]=1,fa[3]=0;const ga=new Array(4);ga[0]=!1,ga[1]=!0,ga[2]=!1,ga[3]=!0;class pa{constructor(e,t,i,n){this.isPole=!1,this._tileGroup=0,this._projection=Js,this.node=e,this.planet=t,this.handler=t.renderer.handler,this.bsphere=new At,this._plainRadius=0,this.bbox=new Lt,this._sw=new oe,this._nw=new oe,this._se=new oe,this._ne=new oe,this.centerNormal=new oe,this._extent=this._extentMerc=n,this._extentLonLat=new ie,this.gridSize=t.terrain.gridSizeByZoom[i],this.fileGridSize=0,this.tileZoom=i,this.powTileZoom=1<<i,this.tileX=0,this.tileXE=0,this.tileXW=0,this.tileYN=0,this.tileYS=0,this.tileY=0,this.tileIndex="",this.elevationData=null,this._assignTileIndexes(),this.materials=[],this.plainReady=!1,this.initialized=!1,this.normalMapReady=!1,this.terrainReady=!1,this.terrainIsLoading=!1,this.terrainExists=!1,this.passReady=!1,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapTexture=null,this.normalMapTextureBias=new Float32Array(3),this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null,this._globalTextureCoordinates=new Float32Array(4),this._inTheQueue=!1,this._appliedNeighborsZoom=[0,0,0,0],this._slices=[],this._indexBuffer=null,this.readyToEngage=!1,this.plainProcessing=!1,this.normalMapTexturePtr=null,this._transitionOpacity=1,this._transitionTimestamp=0}checkZoom(){return this.tileZoom<this.planet.terrain._maxNodeZoom}getEntityTerrainPoint(e,t){return this.getTerrainPoint(e._cartesian,this.getInsideLonLat(e),t)}getInsideLonLat(e){return e._lonLatMerc}isEntityInside(e){return this._extentLonLat.isInside(e._lonLat)}getTerrainPoint(e,t,i){let n=this.tempVertices;if(n&&n.length){let r=this.planet.ellipsoid.getSurfaceNormal3v(e);_a.set(e,r.negateTo());let s=this._extent.northEast,a=this._extent.southWest,o=Math.sqrt(n.length/3)-1,l=s.lon,h=s.lat,c=a.lon,d=a.lat,_=(l-c)/o,u=(h-d)/o,f=t.lon-c,g=t.lat-d,p=Math.floor(f/_),m=Math.floor(o-g/u),v=3*((o+1)*m+p),y=3*((o+1)*(m+1)+p);la.set(n[v],n[v+1],n[v+2]),ha.set(n[v+3],n[v+4],n[v+5]),ca.set(n[y],n[y+1],n[y+2]);let x=_a.hitTriangle(la,ha,ca,i);if(x===_i.INSIDE)return e.distance(i);if(x===_i.AWAY){if(ua.set(e,r),ua.hitTriangle(la,ha,ca,i)===_i.INSIDE)return-e.distance(i)}if(da.set(n[y+3],n[y+4],n[y+5]),x=_a.hitTriangle(ha,da,ca,i),x===_i.INSIDE)return e.distance(i);if(x===_i.AWAY){if(ua.set(e,r),ua.hitTriangle(ha,da,ca,i)===_i.INSIDE)return-e.distance(i)}return x===_i.AWAY?-e.distance(i):e.distance(i)}return e.distance(this.planet.ellipsoid.hitRay(_a.origin,_a.direction))}projectNative(e){return e.forwardMercator()}loadTerrain(e=!1){this.tileZoom<this.planet.terrain.minZoom||this.planet.terrain.isEmpty?(this.terrainIsLoading=!0,this.elevationsNotExists(),this._inTheQueue||this.planet._normalMapCreator.queue(this)):this.tileZoom>this.planet.terrain.maxZoom?this.elevationsNotExists():this.terrainIsLoading||this.terrainReady||this.planet.terrain.loadTerrain(this,e)}elevationsExists(e){if(this.plainReady&&this.terrainIsLoading){let t=new Float32Array(e.length);t.set(e),this.elevationData=new Float32Array(e.length),this.elevationData.set(e),this.planet._terrainWorker.make({segment:this,elevations:t}),this.plainVerticesHigh=null,this.plainVerticesLow=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.planet.terrain.equalizeVertices||(this.tempVerticesHigh=null,this.tempVerticesLow=null)}}elevationsNotExists(){if(this.planet&&this.tileZoom<=this.planet.terrain.maxNativeZoom){if(this.plainReady&&this.terrainIsLoading){this.terrainIsLoading=!1;let e=this.node;e.appliedTerrainNodeId=this.node.nodeId,e.equalizedSideWithNodeId[0]=e.equalizedSideWithNodeId[1]=e.equalizedSideWithNodeId[2]=e.equalizedSideWithNodeId[3]=e.appliedTerrainNodeId,this.planet.lightEnabled&&!this._inTheQueue&&this.planet._normalMapCreator.queue(this),this.readyToEngage=!0}this.terrainVertices=this.plainVertices,this.terrainVerticesHigh=this.plainVerticesHigh,this.terrainVerticesLow=this.plainVerticesLow,this.tempVertices=this.terrainVertices,this.tempVerticesHigh=this.terrainVerticesHigh,this.tempVerticesLow=this.terrainVerticesLow,this.noDataVertices=null,this.fileGridSize=Math.sqrt(this.terrainVertices.length/3)-1,this.gridSize=this.fileGridSize,this.terrainReady=!0,this.terrainExists=!1}else if(this.plainReady&&this.terrainIsLoading){this.terrainIsLoading=!1;let e=this.node;e.appliedTerrainNodeId=this.node.nodeId,e.equalizedSideWithNodeId[0]=e.equalizedSideWithNodeId[1]=e.equalizedSideWithNodeId[2]=e.equalizedSideWithNodeId[3]=e.appliedTerrainNodeId,this.readyToEngage=!0,this.terrainReady=!0,this.passReady=!0,this.terrainExists=!1}}_checkEqualization(e,t){return t&&t.segment&&this.tileZoom>=t.segment.tileZoom&&this.node.equalizedSideWithNodeId[e]!==t.equalizedSideWithNodeId[Vt[e]]}equalize(){if(this.tileZoom<2||this.gridSize<2)return;this.readyToEngage=!0;let e=this.node.neighbors,t=this.tempVertices,i=this.tempVerticesHigh,n=this.tempVerticesLow,r=this.gridSize,s=r+1,a=e[0][0];if(this._checkEqualization(0,a)){this.node.equalizedSideWithNodeId[0]=a.equalizedSideWithNodeId[2],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(a,0),o=a.segment.tempVertices,l=a.segment.tempVerticesHigh,h=a.segment.tempVerticesLow,c=a.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-a.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let r=0,a=e*c;r<s;r+=u,a+=f){const e=3*r,s=3*(d*c+a);t[e]=o[s],t[e+1]=o[s+1],t[e+2]=o[s+2],i[e]=l[s],i[e+1]=l[s+1],i[e+2]=l[s+2],n[e]=h[s],n[e+1]=h[s+1],n[e+2]=h[s+2]}}if(a=e[1][0],this._checkEqualization(1,a)){this.node.equalizedSideWithNodeId[1]=a.equalizedSideWithNodeId[3],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(a,1),o=a.segment.tempVertices,l=a.segment.tempVerticesHigh,h=a.segment.tempVerticesLow,c=a.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-a.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let a=0,_=e*c;a<s;a+=u,_+=f){const e=3*(s*a+r),c=d*_*3;t[e]=o[c],t[e+1]=o[c+1],t[e+2]=o[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],n[e]=h[c],n[e+1]=h[c+1],n[e+2]=h[c+2]}}if(a=e[2][0],this._checkEqualization(2,a)){this.node.equalizedSideWithNodeId[2]=a.equalizedSideWithNodeId[0],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(a,2),o=a.segment.tempVertices,l=a.segment.tempVerticesHigh,h=a.segment.tempVerticesLow,c=a.segment.gridSize,d=1/(1<<this.tileZoom-a.segment.tileZoom),_=Math.max(r/(c*d),1),u=Math.max(c*d/r,1);for(let a=0,d=e*c;a<s;a+=_,d+=u){const e=3*(s*r+a),c=3*d;t[e]=o[c],t[e+1]=o[c+1],t[e+2]=o[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],n[e]=h[c],n[e+1]=h[c+1],n[e+2]=h[c+2]}}if(a=e[3][0],this._checkEqualization(3,a)){this.node.equalizedSideWithNodeId[3]=a.equalizedSideWithNodeId[1],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(a,3),o=a.segment.tempVertices,l=a.segment.tempVerticesHigh,h=a.segment.tempVerticesLow,c=a.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-a.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let r=0,a=e*c;r<s;r+=u,a+=f){const e=s*r*3,_=3*(d*a+c);t[e]=o[_],t[e+1]=o[_+1],t[e+2]=o[_+2],i[e]=l[_],i[e+1]=l[_+1],i[e+2]=l[_+2],n[e]=h[_],n[e+1]=h[_+1],n[e+2]=h[_+2]}}}engage(){this.readyToEngage=!1,this.createCoordsBuffers(this.tempVerticesHigh,this.tempVerticesLow,this.gridSize)}_terrainWorkerCallback(e){if(this.plainReady){this.readyToEngage=!0,this.normalMapNormals=null,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapNormals=e.normalMapNormals,this.normalMapVertices=e.normalMapVertices,this.normalMapVerticesHigh=e.normalMapVerticesHigh,this.normalMapVerticesLow=e.normalMapVerticesLow,this.terrainVertices=e.terrainVertices,this.terrainVerticesHigh=e.terrainVerticesHigh,this.terrainVerticesLow=e.terrainVerticesLow,this.noDataVertices=e.noDataVertices,this.tempVertices=this.terrainVertices,this.tempVerticesHigh=this.terrainVerticesHigh,this.tempVerticesLow=this.terrainVerticesLow,this.setBoundingVolumeArr(e.bounds),this.gridSize=Math.sqrt(this.terrainVertices.length/3)-1;let t=this.node;if(t.appliedTerrainNodeId=t.nodeId,t.equalizedSideWithNodeId[0]=t.equalizedSideWithNodeId[1]=t.equalizedSideWithNodeId[2]=t.equalizedSideWithNodeId[3]=t.appliedTerrainNodeId,this.terrainReady=!0,this.terrainIsLoading=!1,this.terrainExists=!0,!this.normalMapTexturePtr){const e=this.planet._normalMapCreator;this.normalMapTexturePtr=this.planet.renderer.handler.createEmptyTexture_l(e.width,e.height)}this.planet.lightEnabled&&this.planet._normalMapCreator.queue(this)}}_normalMapEdgeEqualize(e){let t=this.node.neighbors,i=t[e],n=i&&i[0],r=this.planet.terrain.maxZoom;this.tileZoom===r&&i&&!(t[0].length||t[1].length||t[2].length||t[3].length)&&(n=this.node.getEqualNeighbor(e));let s=n&&n.segment,a=this;if(n&&s&&s.terrainReady&&s.terrainExists&&s.tileZoom<=r&&a._appliedNeighborsZoom[e]!==s.tileZoom){a._appliedNeighborsZoom[e]=s.tileZoom;let t=a.normalMapNormals,i=s.normalMapNormals;if(!t||!i)return;let n=a.normalMapNormals,r=s.normalMapNormals,o=Math.sqrt(t.length/3),l=o-1;const h=l*fa[e];let c,d,_,u;if(a.tileZoom===s.tileZoom){const f=l-h;if(ga[e])for(let e=0;e<o;e++){let s=3*(e*o+h),a=3*(e*o+f);c=n[s]+r[a],d=n[s+1]+r[a+1],_=n[s+2]+r[a+2],u=1/Math.sqrt(c*c+d*d+_*_),i[a]=t[s]=c*u,i[a+1]=t[s+1]=d*u,i[a+2]=t[s+2]=_*u}else for(let e=0;e<o;e++){let s=3*(h*o+e),a=3*(f*o+e);c=n[s]+r[a],d=n[s+1]+r[a+1],_=n[s+2]+r[a+2],u=1/Math.sqrt(c*c+d*d+_*_),i[a]=t[s]=c*u,i[a+1]=t[s+1]=d*u,i[a+2]=t[s+2]=_*u}s._inTheQueue||s._appliedNeighborsZoom[Vt[e]]===a.tileZoom||(s._appliedNeighborsZoom[Vt[e]]=a.tileZoom,a.planet._normalMapCreator.queue(s))}}}applyTerrain(e){e?this.elevationsExists(e):this.elevationsNotExists()}deleteBuffers(){const e=this.handler.gl;e.deleteBuffer(this.vertexNormalBuffer),e.deleteBuffer(this.vertexPositionBuffer),e.deleteBuffer(this.vertexPositionBufferHigh),e.deleteBuffer(this.vertexPositionBufferLow),this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null}deleteMaterials(){let e=this.materials;for(let t=0;t<e.length;t++){let i=e[t];i&&i.clear()}this.materials.length=0}deleteElevations(){this.terrainExists=!1,this.terrainReady=!1,this.terrainIsLoading=!1,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.normalMapReady&&(this.handler.gl.deleteTexture(this.normalMapTexture),this.normalMapReady=!1),this._appliedNeighborsZoom=[0,0,0,0],this.normalMapTextureBias[0]=0,this.normalMapTextureBias[1]=0,this.normalMapTextureBias[2]=1,this._inTheQueue=!1}clearSegment(){this.plainReady=!1,this.initialized=!1,this.deleteBuffers(),this.deleteMaterials(),this.deleteElevations()}childrenInitialized(){let e=this.node.nodes;return 4===e.length&&e[0].segment.initialized&&e[1].segment.initialized&&e[2].segment.initialized&&e[3].segment.initialized}destroySegment(){this.clearSegment();let e=this._slices.length;for(;e--;)this._slices[e].clear();this._slices=null,this.node=null,this.planet=null,this.handler=null,this.bbox=null,this.bsphere=null,this._extent=null,this.materials=null,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapTextureBias=null,this.normalMapTexture=null,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null,this._projection=null,this._appliedNeighborsZoom=null,this._globalTextureCoordinates=null}_setExtentLonLat(){this._extentLonLat=this._extent.inverseMercator()}_createExtentNormals(){const e=this.planet.ellipsoid,t=this._extentLonLat,i=e.geodeticToCartesian(t.southWest.lon,t.southWest.lat),n=e.geodeticToCartesian(t.northEast.lon,t.northEast.lat),r=e.geodeticToCartesian(t.southWest.lon,t.northEast.lat),s=e.geodeticToCartesian(t.northEast.lon,t.southWest.lat);this._sw.copy(i),this._nw.copy(r),this._ne.copy(n),this._se.copy(s)}createBoundsByExtent(){this._createExtentNormals(),this.setBoundingVolume3v(this._sw,this._ne)}createBoundsByParent(){let e=this.node;for(;e.parentNode&&!e.segment.terrainReady;)e=e.parentNode;let t=1<<this.tileZoom-e.segment.tileZoom,i=this.tileX-e.segment.tileX*t,n=this.tileY-e.segment.tileY*t;if(e.segment.terrainReady&&e.segment.tileZoom>=this.planet.terrain.minZoom){let r=e.segment.gridSize/t;if(r>=1){this.bsphere.center.x=e.segment.bsphere.center.x,this.bsphere.center.y=e.segment.bsphere.center.y,this.bsphere.center.z=e.segment.bsphere.center.z,this.bsphere.radius=e.segment.bsphere.radius;let t=r*n,s=r*i,a=e.segment.gridSize+1,o=3*((t+r)*a+s),l=3*(t*a+s),h=3*(t*a+s+r),c=3*((t+r)*a+s+r),d=e.segment.tempVertices,_=new oe(d[o],d[o+1],d[o+2]),u=new oe(d[h],d[h+1],d[h+2]),f=new oe(d[l],d[l+1],d[l+2]),g=new oe(d[c],d[c+1],d[c+2]);this._sw.copy(_),this._nw.copy(f),this._ne.copy(u),this._se.copy(g)}else{let t,s=e.segment,a=Math.floor(r*n),o=Math.floor(r*i),l=1/r,h=n-l*a,c=i-l*o;t=1===s.gridSize?s.tempVertices:We(s.tempVertices,s.gridSize,a,o,1);let d,_,u=new oe(t[0],t[1],t[2]),f=new oe(t[9],t[10],t[11]),g=new oe(t[3]-t[0],t[4]-t[1],t[5]-t[2]),p=new oe(t[6]-t[0],t[7]-t[1],t[8]-t[2]),m=new oe(t[3]-t[9],t[4]-t[10],t[5]-t[11]),v=new oe(t[6]-t[9],t[7]-t[10],t[8]-t[11]),y=h,x=c;d=y+x<l?oe.add(g.scaleTo(x/l),p.scaleTo(y/l)).addA(u):oe.add(v.scaleTo(1-x/l),m.scaleTo(1-y/l)).addA(f),y=h+1,x=c+1,_=y+x<l?oe.add(g.scaleTo(x/l),p.scaleTo(y/l)).addA(u):oe.add(v.scaleTo(1-x/l),m.scaleTo(1-y/l)).addA(f),this._createExtentNormals(),this.setBoundingVolume3v(d,_)}}else this.createBoundsByExtent()}setBoundingSphere(e,t,i,n){this.bsphere.center.x=e,this.bsphere.center.y=t,this.bsphere.center.z=i,this.bsphere.radius=this.bsphere.center.distance(n)}setBoundingVolume(e,t,i,n,r,s){this.bbox.setFromBoundsArr([e,t,i,n,r,s]);let a=e+.5*(n-e),o=t+.5*(r-t),l=i+.5*(s-i);this.bsphere.center.set(a,o,l),this.bsphere.radius=this.bsphere.center.distance(new oe(e,t,i))}setBoundingVolume3v(e,t){this.bbox.setFromBoundsArr([e.x,e.y,e.z,t.x,t.y,t.z]);let i=e.x+.5*(t.x-e.x),n=e.y+.5*(t.y-e.y),r=e.z+.5*(t.z-e.z);this.bsphere.center.set(i,n,r),this.bsphere.radius=this.bsphere.center.distance(new oe(e.x,e.y,e.z))}setBoundingVolumeArr(e){this.bbox.setFromBoundsArr(e);let t=e[0]+.5*(e[3]-e[0]),i=e[1]+.5*(e[4]-e[1]),n=e[2]+.5*(e[5]-e[2]);this.bsphere.center.set(t,i,n),this.bsphere.radius=this.bsphere.center.distance(new oe(e[0],e[1],e[2]))}createCoordsBuffers(e,t,i){const n=(i+1)*(i+1),r=this.handler;this.vertexPositionBufferHigh&&this.vertexPositionBufferHigh.numItems===n?(r.setStreamArrayBuffer(this.vertexPositionBufferHigh,e),r.setStreamArrayBuffer(this.vertexPositionBufferLow,t)):(r.gl.deleteBuffer(this.vertexPositionBufferHigh),r.gl.deleteBuffer(this.vertexPositionBufferLow),this.vertexTextureCoordBuffer=this.planet._textureCoordsBufferCache[Math.log2(i)],this.vertexPositionBufferHigh=r.createArrayBuffer(e,3,n),this.vertexPositionBufferLow=r.createArrayBuffer(t,3,n))}_addViewExtent(){const e=this._extentLonLat;let t=this.planet._viewExtent;e.southWest.lon<t.southWest.lon&&(t.southWest.lon=e.southWest.lon),e.northEast.lon>t.northEast.lon&&(t.northEast.lon=e.northEast.lon),e.southWest.lat<t.southWest.lat&&(t.southWest.lat=e.southWest.lat),e.northEast.lat>t.northEast.lat&&(t.northEast.lat=e.northEast.lat)}_assignTileIndexes(){this._tileGroup=0;const e=this.tileZoom,t=this._extent,i=F;this.tileX=ia(t.getCenter().lon,t.getWidth(),-i),this.tileY=ia(t.getCenter().lat,t.getHeight(),i);const n=this.powTileZoom;this.tileXE=(this.tileX+1)%n,this.tileXW=(n+this.tileX-1)%n,this.tileYN=this.tileY-1,this.tileYS=this.tileY+1,this.tileIndex=qt.getTileIndex(this.tileX,this.tileY,e,this._tileGroup)}initialize(){const e=this.planet,t=this.node;if(this.gridSize=e.terrain.gridSizeByZoom[this.tileZoom]||e.terrain.plainGridSize,t.sideSizeLog2[0]=t.sideSizeLog2[1]=t.sideSizeLog2[2]=t.sideSizeLog2[3]=Math.log2(this.gridSize),this.tileZoom<=e.terrain.maxZoom){const t=this.planet._normalMapCreator;this.normalMapTexturePtr=e.renderer.handler.createEmptyTexture_l(t.width,t.height)}this.normalMapTexture=this.planet.transparentTexture,this._assignGlobalTextureCoordinates(),this.initialized=!0}_assignGlobalTextureCoordinates(){const e=this._extent;this._globalTextureCoordinates[0]=(e.southWest.lon+F)*q,this._globalTextureCoordinates[1]=(F-e.northEast.lat)*q,this._globalTextureCoordinates[2]=(e.northEast.lon+F)*q,this._globalTextureCoordinates[3]=(F-e.southWest.lat)*q}createPlainSegmentAsync(){let e=this.planet,t=e.terrain;t.isReady()&&!this.plainReady&&this.tileZoom<=t.maxZoom&&(this.plainProcessing=!0,e._plainSegmentWorker.make(this))}_plainSegmentWorkerCallback(e){this.plainProcessing=!1,this.initialized&&!this.terrainReady&&(this.plainReady=!0,this.plainVertices=e.plainVertices,this.plainVerticesHigh=e.plainVerticesHigh,this.plainVerticesLow=e.plainVerticesLow,this.plainNormals=e.plainNormals,this._plainRadius=e.plainRadius,this.normalMapNormals=e.normalMapNormals,this.normalMapVertices=e.normalMapVertices,this.normalMapVerticesHigh=e.normalMapVerticesHigh,this.normalMapVerticesLow=e.normalMapVerticesLow,this.fileGridSize=Math.sqrt(e.normalMapVertices.length/3)-1)}createPlainSegment(){this.initialize(),this._createPlainVertices(),this.readyToEngage=!0}_projToDeg(e,t){return z.inverseMercator(e,t)}_createPlainVertices(){const e=this.planet.terrain.gridSizeByZoom[this.tileZoom],t=this.planet.terrain.plainGridSize,i=Math.max(t,e),n=this._extent,r=n.getWidth()/i,s=n.getHeight()/i,a=n.southWest.lon,o=n.northEast.lat,l=Math.max(t/e,1),h=i+1,c=this.planet.ellipsoid._invRadii2,d=h*h,_=(e+1)*(e+1)*3;let u=0,f=0;this.plainNormals=new Float32Array(_),this.plainVertices=new Float64Array(_),this.plainVerticesHigh=new Float32Array(_),this.plainVerticesLow=new Float32Array(_),this.normalMapNormals=new Float32Array(3*d),this.normalMapVertices=new Float64Array(3*d),this.normalMapVerticesHigh=new Float32Array(3*d),this.normalMapVerticesLow=new Float32Array(3*d);let g=this.plainVertices,p=this.plainVerticesHigh,m=this.plainVerticesLow,v=this.plainNormals,y=this.normalMapVertices,x=this.normalMapVerticesHigh,b=this.normalMapVerticesLow,w=this.normalMapNormals;for(let e=0;e<d;e++){let t=e%h,i=~~(e/h),n=this.planet.ellipsoid.lonLatToCartesian(this._projToDeg(a+t*r,o-i*s)),d=n.x*c.x,_=n.y*c.y,T=n.z*c.z,C=1/Math.sqrt(d*d+_*_+T*T),L=d*C,A=_*C,E=T*C;oe.doubleToTwoFloats(n,aa,oa),y[f]=n.x,x[f]=aa.x,b[f]=oa.x,w[f++]=L,y[f]=n.y,x[f]=aa.y,b[f]=oa.y,w[f++]=A,y[f]=n.z,x[f]=aa.z,b[f]=oa.z,w[f++]=E,i%l==0&&t%l==0&&(g[u]=n.x,p[u]=aa.x,m[u]=oa.x,v[u++]=L,g[u]=n.y,p[u]=aa.y,m[u]=oa.y,v[u++]=A,g[u]=n.z,p[u]=aa.z,m[u]=oa.z,v[u++]=E)}this.terrainVertices=g,this.terrainVerticesHigh=p,this.terrainVerticesLow=m,this.plainReady=!0}getMaterialByLayer(e){return this.materials[e.__id]}_getLayerExtentOffset(e){const t=e._extentMerc,i=this._extent,n=t.northEast.lon-t.southWest.lon,r=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/n,(t.northEast.lat-i.northEast.lat)/r,(i.northEast.lon-i.southWest.lon)/n,(i.northEast.lat-i.southWest.lat)/r]}initSlice(e){let t=this._slices[e];return t?t.layers=[]:t=this._slices[e]=new ta(this),t}screenRendering(e,t,i,n,r=!1,s){const a=this.handler.gl,o=e.attributes,l=e.uniforms,h=this.materials,c=this.planet;let d,_;t&&t.length?(_=t[0],d=_._height):d=0,a.activeTexture(a.TEXTURE0+c.SLICE_SIZE+2),a.bindTexture(a.TEXTURE_2D,n||this.getDefaultTexture()),a.uniform1i(l.defaultTexture,c.SLICE_SIZE+2);let u=0,f=0,g=!1,p=this.initSlice(i);for(this._indexBuffer=this._getIndexBuffer();_;){if(this.layerOverlap(_)&&(_._fading&&_._fadingOpacity>0||(_.minZoom>=c.minCurrZoom||_.maxZoom>=c.minCurrZoom)&&(_.minZoom<=c.maxCurrZoom||_.maxZoom<=c.maxCurrZoom))){g=!0;let e=h[_.__id];e||(e=h[_.__id]=_.createMaterial(this)),e.isReady||(this.planet._renderCompleted=!1),p.append(_,e),c._samplerArr[u]=u,a.activeTexture(a.TEXTURE0+u),a.bindTexture(a.TEXTURE_2D,e.texture||c.transparentTexture),u++}f++,_=t[f]}!g&&r||(a.uniform1f(l.transitionOpacity,s||this._transitionOpacity>1?1:this._transitionOpacity),a.uniform1i(l.samplerCount,u),a.uniform1f(l.height,d),a.uniform1iv(l.samplerArr,c._samplerArr),a.uniform4fv(l.tileOffsetArr,p.tileOffsetArr),a.uniform1fv(l.layerOpacityArr,p.layerOpacityArr),c.lightEnabled&&(a.activeTexture(a.TEXTURE0+c.SLICE_SIZE+3),a.bindTexture(a.TEXTURE_2D,this.normalMapTexture||c.transparentTexture),a.uniform1i(l.uNormalMap,c.SLICE_SIZE+3),a.uniform3fv(l.uNormalMapBias,this.normalMapTextureBias),a.uniform4fv(l.uGlobalTextureCoord,this._globalTextureCoordinates)),a.bindBuffer(a.ARRAY_BUFFER,this.vertexPositionBufferHigh),a.vertexAttribPointer(o.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,this.vertexPositionBufferLow),a.vertexAttribPointer(o.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,this.vertexTextureCoordBuffer),a.vertexAttribPointer(o.aTextureCoord,2,a.UNSIGNED_SHORT,!0,0,0),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBuffer),a.drawElements(c.drawMode,this._indexBuffer.numItems,a.UNSIGNED_INT,0))}heightPickingRendering(e,t){const i=this.handler.gl,n=e.attributes,r=e.uniforms;let s;s=t&&t.length?t[0]._height:0,i.uniform1f(r.height,s),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferHigh),i.vertexAttribPointer(n.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferLow),i.vertexAttribPointer(n.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,this._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,this._indexBuffer.numItems,i.UNSIGNED_INT,0)}increaseTransitionOpacity(){this._transitionOpacity+=(window.performance.now()-this._transitionTimestamp)/this.planet.transitionTime,this._transitionTimestamp=window.performance.now(),this._transitionOpacity>2&&(this._transitionOpacity=2);let e=this.node._fadingNodes.length;for(;e--;){let t=this.node._fadingNodes[e];if(!t.segment){this._transitionOpacity=1;break}t.segment._transitionOpacity>0&&!this.planet._fadingNodes.has(t.__id)&&(this.planet._fadingNodes.set(t.__id,t),t.segment._transitionOpacity=2-this._transitionOpacity,0===t.segment._transitionOpacity&&this.node._fadingNodes.splice(e,1))}}fadingTransitionOpacity(){this._transitionOpacity-=.01,this._transitionTimestamp=window.performance.now(),this._transitionOpacity<0&&(this._transitionOpacity=0)}colorPickingRendering(e,t,i,n,r=!1){const s=this.handler.gl,a=e.attributes,o=e.uniforms;let l,h=this.materials,c=this.planet;l=t&&t.length?t[0]._height:0;let d=!1,_=this._slices[i],u=_.layers.length;for(let e=0;e<u;e++){d=!0;let t=_.layers[e],i=4*e;c._pickingColorArr[i]=t._pickingColor.x/255,c._pickingColorArr[i+1]=t._pickingColor.y/255,c._pickingColorArr[i+2]=t._pickingColor.z/255,c._pickingColorArr[i+3]=Number(t._pickingEnabled),c._samplerArr[e]=e,s.activeTexture(s.TEXTURE0+e),s.bindTexture(s.TEXTURE_2D,h[t.__id].texture||this.planet.transparentTexture),c._pickingMaskArr[e]=e+c.SLICE_SIZE,s.activeTexture(s.TEXTURE0+e+c.SLICE_SIZE),s.bindTexture(s.TEXTURE_2D,h[t.__id].pickingMask||this.planet.transparentTexture)}!d&&r||(s.uniform1i(o.samplerCount,u),s.uniform1f(o.height,l),s.uniform1iv(o.samplerArr,c._samplerArr),s.uniform1iv(o.pickingMaskArr,c._pickingMaskArr),s.uniform4fv(o.pickingColorArr,c._pickingColorArr),s.uniform4fv(o.tileOffsetArr,_.tileOffsetArr),s.uniform1fv(o.layerOpacityArr,_.layerOpacityArr),s.bindBuffer(s.ARRAY_BUFFER,this.vertexPositionBufferHigh),s.vertexAttribPointer(a.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this.vertexPositionBufferLow),s.vertexAttribPointer(a.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this.vertexTextureCoordBuffer),s.vertexAttribPointer(a.aTextureCoord,2,s.UNSIGNED_SHORT,!0,0,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,this._indexBuffer),s.drawElements(s.TRIANGLE_STRIP,this._indexBuffer.numItems,s.UNSIGNED_INT,0))}depthRendering(e,t){const i=this.handler.gl,n=e.attributes,r=e.uniforms;var s;s=t&&t.length?t[0]._height:0,i.uniform1f(r.height,s),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferHigh),i.vertexAttribPointer(n.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferLow),i.vertexAttribPointer(n.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,this._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,this._indexBuffer.numItems,i.UNSIGNED_INT,0)}_getIndexBuffer(){const e=this.node.sideSizeLog2;let t=this.planet._indexesCache[Math.log2(this.gridSize)][e[0]][e[1]][e[2]][e[3]];if(!t.buffer){let i=Ns().createSegmentIndexes(Math.log2(this.gridSize),[e[0],e[1],e[2],e[3]]);t.buffer=this.planet.renderer.handler.createElementArrayBuffer(i,1),this.planet._indexesCacheToRemoveCounter++}return t.buffer}_collectVisibleNodes(){this.planet._visibleNodes[this.node.nodeId]=this.node}layerOverlap(e){return this._extent.overlaps(e._extentMerc)}getDefaultTexture(){return this.planet.solidTextureOne}getExtentLonLat(){return this._extentLonLat}getExtentMerc(){return this._extentMerc}getExtent(){return this._extent}getNeighborSide(e){if(this.tileY===e.tileY){if(this.tileX===e.tileXE)return 3;if(this.tileX===e.tileXW)return 1}else if(this.tileX===e.tileX){if(this.tileY===e.tileYS)return 0;if(this.tileY===e.tileYN)return 2}return-1}}let ma=new oe,va=new oe;const ya=[new le(0,0),new le(1,0),new le(0,1),new le(1,1)],xa=Math.sqrt(ya.length)-1;let ba={xmin:0,ymin:0,zmin:0,xmax:0,ymax:0,zmax:0},wa=0,Ta=class e{constructor(e,t,i,n,r,s){t._createdNodesCount++,this.__id=wa++,this.SegmentPrototype=e,this.planet=t,this.parentNode=n,this.partId=i,this.nodeId=i+(n?4*n.nodeId+1:0),this.state=null,this.prevState=null,this.appliedTerrainNodeId=-1,this.sideSizeLog2=[0,0,0,0],this.ready=!1,this.neighbors=[[],[],[],[]],this.equalizedSideWithNodeId=[this.nodeId,this.nodeId,this.nodeId,this.nodeId],this.nodes=[],this.segment=new e(this,t,r,s),this._cameraInside=!1,this.inFrustum=0,this._fadingNodes=[],this.createBounds()}createChildrenNodes(){this.ready=!0;const t=this.planet,i=this.segment,n=i._extent,r=i.tileZoom+1,s=.5*n.getWidth(),a=.5*n.getHeight(),o=n.northEast,l=n.southWest,h=new z(l.lon+s,l.lat+a),c=this.nodes;c[0]=new e(this.SegmentPrototype,t,0,this,r,new ie(new z(l.lon,l.lat+a),new z(l.lon+s,o.lat))),c[1]=new e(this.SegmentPrototype,t,1,this,r,new ie(h,new z(o.lon,o.lat))),c[2]=new e(this.SegmentPrototype,t,2,this,r,new ie(new z(l.lon,l.lat),h)),c[3]=new e(this.SegmentPrototype,t,3,this,r,new ie(new z(l.lon+s,l.lat),new z(o.lon,l.lat+a)))}createBounds(){let e=this.segment;e._setExtentLonLat(),0===e.tileZoom?e.setBoundingSphere(0,0,0,new oe(0,0,e.planet.ellipsoid.equatorialSize)):e.tileZoom<e.planet.terrain.minZoom?e.createBoundsByExtent():e.createBoundsByParent();let t=e.bsphere.center.x,i=e.bsphere.center.y,n=e.bsphere.center.z,r=1/Math.sqrt(t*t+i*i+n*n);e.centerNormal.x=t*r,e.centerNormal.y=i*r,e.centerNormal.z=n*r}getState(){if(-1===this.state)return this.state;let e=this.parentNode;for(;e;){if(2!==e.state)return 0;e=e.parentNode}return this.state}getEqualNeighbor(e){let t=this,i=Ut[e][t.partId];if(-1!==i)return t.parentNode.nodes[i];{let n=[];for(;t.parentNode;)if(n.push(t.partId),i=Ut[e][t.partId],t=t.parentNode,-1!==i){let r=n.length;for(e=Vt[e];t&&r--;)i=Gt[e][n[r]],t=t.nodes[i];return t}}}traverseNodes(e,t,i,n,r){this.ready||this.createChildrenNodes();let s=this.nodes;s[0].renderTree(e,t,i,n,r),s[1].renderTree(e,t,i,n,r),s[2].renderTree(e,t,i,n,r),s[3].renderTree(e,t,i,n,r)}renderTree(e,t,i,n,r){if(this.planet._renderedNodes.length>=1e3)return;(!t||r&&this.segment.tileZoom>r.segment.tileZoom)&&(this.prevState=this.state),this.state=2,this.clearNeighbors();let s=this.segment,a=this.planet;if(this._cameraInside=!1,!this.parentNode||this.parentNode._cameraInside){let t;Math.abs(e._lonLat.lat)<=J&&s._projection.id===Js.id?t=s._extent.isInside(e._lonLatMerc):s._projection.id===ea.id&&(t=s._extent.isInside(e._lonLat)),t&&(e._insideSegment=s,this._cameraInside=!0)}this.inFrustum=0;let o=e.frustums,l=o.length;if(s.tileZoom<6)for(let e=0;e<l;e++)o[e].containsSphere(s.bsphere)&&(this.inFrustum|=1<<e);else{let e=1<<l-1-1;for(let t=0;e&&t<l;t++)s.terrainReady?o[t].containsBox(s.bbox)&&(e>>=1,this.inFrustum|=1<<t):o[t].containsSphere(s.bsphere)&&(e>>=1,this.inFrustum|=1<<t)}if(this.inFrustum||this._cameraInside||s.tileZoom<3){let o=Math.abs(e._lonLat.height),l=e.eye.length2()-this.planet.ellipsoid.polarSizeSqr;l=l<106876472875.63281*a._heightFactor?106876472875.63281*a._heightFactor:l;let h=s.tileZoom<2||s.tileZoom>19||s.tileZoom<6&&!s.terrainReady;h=h||e.eye.distance2(s._sw)<l||e.eye.distance2(s._nw)<l||e.eye.distance2(s._ne)<l||e.eye.distance2(s._se)<l,(this.inFrustum&&(h||o>1e4)||this._cameraInside)&&s._collectVisibleNodes(),s.tileZoom<2?this.traverseNodes(e,t,i,n,r):s.terrainReady&&(!t&&e.projectedSize(s.bsphere.center,s._plainRadius)<a.lodSize||t&&(s.tileZoom===t||!h))?h?(s.passReady=!0,this.renderNode(this.inFrustum,!this.inFrustum,i,n)):this.state=0:s.terrainReady&&s.checkZoom()&&(!t||e.projectedSize(s.bsphere.center,s.bsphere.radius)>this.planet._maxLodSize)?this.traverseNodes(e,t,s,n,r):h?(s.passReady=!!t&&s.terrainReady,this.renderNode(this.inFrustum,!this.inFrustum,i,n)):this.state=0}else this.state=0}renderNode(e,t,i,n){let r=this.segment;r.terrainReady||(r.initialized||r.initialize(),this.whileTerrainLoading(i),r.plainProcessing||r.createPlainSegmentAsync(),r.plainReady&&!n&&r.loadTerrain()),r.planet.lightEnabled&&!r.normalMapReady&&this.whileNormalMapCreating(),t?this.state=-1:(!this._cameraInside&&r.tileZoom>this.planet.maxCurrZoom&&(this.planet.maxCurrZoom=r.tileZoom),r.tileZoom<this.planet.minCurrZoom&&(this.planet.minCurrZoom=r.tileZoom),r._addViewExtent(),this.addToRender(e))}childrenPrevStateEquals(e){let t=this.nodes;return 4===t.length&&t[0].prevState===e&&t[1].prevState===e&&t[2].prevState===e&&t[3].prevState===e}isFading(){let e=this.nodes;return 2===this.state&&this.segment._transitionOpacity>0&&4===e.length&&1===e[0].state&&1===e[1].state&&1===e[2].state&&1===e[3].state}_collectFadingNodes(){if(this.segment.tileZoom<3)this.segment._transitionOpacity=1;else if(1!==this.prevState){this.segment._transitionOpacity=0,this._fadingNodes=[];let e=window.performance.now();if(this.segment._transitionTimestamp=e,this.parentNode)if(1===this.parentNode.prevState){let t=this.parentNode.parentNode;for(;t;){if(t.isFading()){for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment._transitionOpacity=1,t.nodes[e]._fadingNodes=[];t.segment._transitionOpacity=0;break}t=t.parentNode}this.parentNode.whileTerrainLoading(),this._fadingNodes.push(this.parentNode),this.parentNode.segment._transitionOpacity=2,this.parentNode.segment._transitionTimestamp=e}else if(this.segment.childrenInitialized()&&this.childrenPrevStateEquals(1))for(let t=0;t<this.nodes.length;t++){let i=this.nodes[t];i.whileTerrainLoading(),this._fadingNodes.push(i),i.segment._transitionOpacity=2,i.segment._transitionTimestamp=e,i.prevState=i.state,i.state=0}}}clearNeighbors(){this.neighbors&&(this.neighbors[0]=this.neighbors[1]=this.neighbors[2]=this.neighbors[3]=null,this.neighbors[0]=[],this.neighbors[1]=[],this.neighbors[2]=[],this.neighbors[3]=[])}_refreshTransitionOpacity(){if(0===this._fadingNodes.length)this.segment._transitionOpacity=1;else if(4!==this._fadingNodes.length||this.childrenPrevStateEquals(1)){for(let e=0;e<this._fadingNodes.length;e++)this.segment._transitionOpacity<1&&0===this._fadingNodes[e].segment._transitionOpacity&&(this._fadingNodes[e].segment._transitionOpacity=0,this.segment._transitionOpacity=1);this.segment.increaseTransitionOpacity()}else this.segment._transitionOpacity=1,this._fadingNodes=[]}addToRender(e){this.state=1;let t=this.planet._renderedNodes;this.planet._transitionOpacityEnabled?Re(t,this,((e,t)=>e.segment.tileZoom-t.segment.tileZoom)):(this.getRenderedNodesNeighbors(t),t.push(this)),this.segment.terrainReady||(this.planet._renderCompleted=!1,this.planet._terrainCompleted=!1);let i=0,n=this.planet._renderedNodesInFrustum;for(;e;)1&e&&n[i].push(this),i++,e>>=1}applyNeighbor(e,t){const i=Vt[t];if(0===this.neighbors[t].length||0===e.neighbors[i].length){const n=this.segment,r=e.segment,s=n.gridSize/(r.gridSize*Math.pow(2,r.tileZoom-n.tileZoom));let a=n.gridSize,o=r.gridSize;s>1?(a=Math.ceil(n.gridSize/s),o=r.gridSize):s<1&&(a=n.gridSize,o=Math.ceil(r.gridSize*s)),this.sideSizeLog2[t]=Math.log2(a),e.sideSizeLog2[i]=Math.log2(o)}this.neighbors[t].push(e),e.neighbors[i].push(this)}getRenderedNodesNeighbors(e){for(let t=e.length-1;t>=0;--t){let i=e[t],n=this.getCommonSide(i);-1!==n&&this.applyNeighbor(i,n)}}getCommonSide(e){const t=this.segment,i=e.segment;if(t.tileZoom===i.tileZoom&&t._tileGroup===i._tileGroup)return t.getNeighborSide(i);{const e=t._extentLonLat,n=i._extentLonLat;let r=e.northEast,s=e.southWest,a=n.northEast,o=n.southWest,l=r.lon,h=r.lat,c=s.lon,d=s.lat,_=a.lon,u=a.lat,f=o.lon,g=o.lat;if(t._tileGroup===i._tileGroup){if(l===f&&(h<=u&&d>=g||h>=u&&d<=g))return 1;if(c===_&&(h<=u&&d>=g||h>=u&&d<=g))return 3;if(h===g&&(c>=f&&l<=_||c<=f&&l>=_))return 0;if(d===u&&(c>=f&&l<=_||c<=f&&l>=_))return 2;if(0===i.tileX&&f===-l&&(h<=u&&d>=g||h>=u&&d<=g))return 1;if(0===t.tileX&&c===-_&&(h<=u&&d>=g||h>=u&&d<=g))return 3}if(0===t._tileGroup&&i._tileGroup===ra&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=f&&l<=_||c<=f&&l>=_))return 0;if(0===t._tileGroup&&i._tileGroup===sa&&t.tileY===t.powTileZoom-1&&0===i.tileY&&(c>=f&&l<=_||c<=f&&l>=_))return 2;if(t._tileGroup===sa&&0===i._tileGroup&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=f&&l<=_||c<=f&&l>=_))return 0;if(t._tileGroup===ra&&0===i._tileGroup&&t.tileY===t.powTileZoom-1&&0===i.tileY&&(c>=f&&l<=_||c<=f&&l>=_))return 2}return-1}whileNormalMapCreating(){const e=this.segment;e.terrainIsLoading||!e.terrainExists||e._inTheQueue||e.planet._normalMapCreator.queue(e);let t=this;for(;t.parentNode&&!t.segment.normalMapReady;)t=t.parentNode;const i=2<<e.tileZoom-t.segment.tileZoom-1;e.normalMapTexture=t.segment.normalMapTexture,e.normalMapTextureBias[0]=e.tileX-t.segment.tileX*i,e.normalMapTextureBias[1]=e.tileY-t.segment.tileY*i,e.normalMapTextureBias[2]=1/i}whileTerrainLoading(e){const t=this.segment;let i=this;if(e&&e.terrainReady)i=e.node;else for(;i.parentNode&&!i.segment.terrainReady;)i=i.parentNode;if(i.segment.terrainReady&&this.appliedTerrainNodeId!==i.nodeId){let e=2<<t.tileZoom-i.segment.tileZoom-1,n=t.tileX-i.segment.tileX*e,r=t.tileY-i.segment.tileY*e;const o=i.segment;let l,h,c,d;this.appliedTerrainNodeId=i.nodeId,this.equalizedSideWithNodeId[0]=this.equalizedSideWithNodeId[1]=this.equalizedSideWithNodeId[2]=this.equalizedSideWithNodeId[3]=this.appliedTerrainNodeId;let _=i.segment.gridSize/e,u=i.segment.fileGridSize/e;if(ba.xmin=s,ba.xmax=a,ba.ymin=s,ba.ymax=a,ba.zmin=s,ba.zmax=a,_>=1){t.gridSize=_;let e=(_+1)*(_+1)*3;l=new Float64Array(e),h=new Float32Array(e),c=new Float32Array(e),o.noDataVertices&&(d=new Uint8Array(e/3)),Ye(o.terrainVertices,o.terrainVerticesHigh,o.terrainVerticesLow,o.noDataVertices,o.gridSize,_*r,_*n,_,l,h,c,ba,d)}else if(u>=1&&i.segment.terrainExists){t.gridSize=u;let e=(u+1)*(u+1)*3;l=new Float64Array(e),h=new Float32Array(e),c=new Float32Array(e),o.noDataVertices&&(d=new Uint8Array(e/3)),Ye(o.normalMapVertices,o.normalMapVerticesHigh,o.normalMapVerticesLow,o.noDataVertices,i.segment.fileGridSize,u*r,u*n,u,l,h,c,ba,d)}else{t.gridSize=xa;let e,i=Math.floor(_*r),s=Math.floor(_*n);e=1===o.gridSize?o.terrainVertices:We(o.terrainVertices,o.gridSize,i,s,1);let a=1/_,d=r-a*i,u=n-a*s,f=new oe(e[0],e[1],e[2]),g=new oe(e[9],e[10],e[11]),p=new oe(e[3]-e[0],e[4]-e[1],e[5]-e[2]),m=new oe(e[6]-e[0],e[7]-e[1],e[8]-e[2]),v=new oe(e[3]-e[9],e[4]-e[10],e[5]-e[11]),y=new oe(e[6]-e[9],e[7]-e[10],e[8]-e[11]),x=new oe;l=new Float64Array(3*ya.length),h=new Float32Array(3*ya.length),c=new Float32Array(3*ya.length);for(let e=0;e<ya.length;e++){let t=ya[e].y+d,i=ya[e].x+u,n=i*_,r=t*_;x=t+i<a?p.scaleTo(n).addA(m.scaleTo(r)).addA(f):y.scaleTo(1-n).addA(v.scaleTo(1-r)).addA(g),oe.doubleToTwoFloats(x,ma,va);let s=3*e;l[s]=x.x,l[s+1]=x.y,l[s+2]=x.z,h[s]=ma.x,h[s+1]=ma.y,h[s+2]=ma.z,c[s]=va.x,c[s+1]=va.y,c[s+2]=va.z,x.x<ba.xmin&&(ba.xmin=x.x),x.x>ba.xmax&&(ba.xmax=x.x),x.y<ba.ymin&&(ba.ymin=x.y),x.y>ba.ymax&&(ba.ymax=x.y),x.z<ba.zmin&&(ba.zmin=x.z),x.z>ba.zmax&&(ba.zmax=x.z)}}if(t.readyToEngage=!0,t.terrainVertices=l,t.terrainVerticesHigh=h,t.terrainVerticesLow=c,t.tempVertices=l,t.tempVerticesHigh=h,t.tempVerticesLow=c,t.noDataVertices=d,t.setBoundingVolume(ba.xmin,ba.ymin,ba.zmin,ba.xmax,ba.ymax,ba.zmax),t.tileZoom>t.planet.terrain.maxZoom&&i.segment.tileZoom>=t.planet.terrain.maxZoom&&(t._plainRadius=i.segment._plainRadius/e,t.terrainReady=!0,t.terrainIsLoading=!1,t.terrainVertices=l,t.terrainVerticesHigh=h,t.terrainVerticesLow=c,t.passReady=!0,this.appliedTerrainNodeId=this.nodeId,this.equalizedSideWithNodeId[0]=this.equalizedSideWithNodeId[1]=this.equalizedSideWithNodeId[2]=this.equalizedSideWithNodeId[3]=this.appliedTerrainNodeId,i.segment.terrainExists)){t.normalMapVertices=l,t.fileGridSize=Math.sqrt(l.length/3)-1;let i=Math.sqrt(o.normalMapNormals.length/3)-1,s=i/e;t.normalMapNormals=i>1?je(o.normalMapNormals,i,s*r,s*n,s):o.normalMapNormals}}}destroy(){this.prevState=this.state=0,this.segment.destroySegment();let e=this.neighbors;for(let t=0,i=e.length;t<i;t++){let i=e[t];if(i)for(let e=0;e<i.length;e++){let t=i[e];t&&t.neighbors&&t.clearNeighbors()}}this.neighbors=null,this.parentNode=null,this.sideSizeLog2=null,this.segment=null}clearTree(){const e=this.getState();if(0===e||1===e)this.destroyBranches();else for(let e=0;e<this.nodes.length;e++)this.nodes[e]&&this.nodes[e].clearTree()}clearBranches(){for(let e=0;e<this.nodes.length;e++)this.nodes[e].clearBranches(),this.nodes[e].segment.deleteMaterials()}destroyBranches(){if(this.ready){let e,t=[];for(e=0;e<this.nodes.length;e++)t[e]=this.nodes[e];for(this.ready=!1,this.nodes=[],e=0;e<t.length;e++)t[e].destroyBranches(),t[e].destroy(),t[e]=null;t.length=0,t=null}}traverseTree(e){if(e(this),this.ready)for(let t=0;t<this.nodes.length;t++)this.nodes[t].traverseTree(e)}getOffsetOppositeNeighbourSide(e,t){let i=this,n=e.segment.tileZoom,r=0;for(;i.segment.tileZoom>n;)r+=Wt[i.partId][t]/(1<<i.segment.tileZoom-n),i=i.parentNode;return r}};class Ca{constructor(e,t="",i=Js){this.name=t,this.projection=i,this._planet=e,this._quadTreeList=[]}destroyBranches(){for(let e=0,t=this._quadTreeList.length;e<t;e++)this._quadTreeList[e].destroyBranches()}clearLayerMaterial(e){let t=e.__id;for(let e=0,i=this._quadTreeList.length;e<i;e++)this._quadTreeList[e].traverseTree((function(e){let i=e.segment.materials;i[t]&&(i[t].clear(),i[t]=null)}))}get planet(){return this._planet}init(){}preRender(){for(let e=0;e<this._quadTreeList.length;e++){let t=this._quadTreeList[e];t.createChildrenNodes(),t.segment.createPlainSegment();for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment.createPlainSegment()}}preLoad(){for(let e=0;e<this._quadTreeList.length;e++){let t=this._quadTreeList[e];t.segment.passReady=!0,t.renderNode(1),this._planet.normalMapCreator.drawSingle(t.segment);for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment.passReady=!0,t.nodes[e].renderNode(1),this._planet._normalMapCreator.drawSingle(t.nodes[e].segment)}}collectRenderNodes(){for(let e=0;e<this._quadTreeList.length;e++)this._quadTreeList[e].renderTree(this._planet.camera,0,null)}clear(){for(let e=0;e<this._quadTreeList.length;e++)this._quadTreeList[e].clearTree()}get quadTreeList(){return this._quadTreeList}getTileXY(e,t){let i=t,n=-1,r=-1,s=1<<i;return n=ia(e.lon,360/s,-180),r=ia(e.lat,180/s,90),[n,r,i,0]}getLonLatTileOffset(e,t,i,n,r){let s=e,a=new ie;a=na(t,i,n,ie.createFromArray([-180,-90,180,90]));let o=a.getWidth()/(r-1),l=a.getHeight()/(r-1);return[r-Math.ceil((s.lat-a.southWest.lat)/l)-1,Math.floor((s.lon-a.southWest.lon)/o)]}}const La=(90-J)/Math.pow(2,7);class Aa extends pa{constructor(e,t,i,n){super(e,t,i,n),this._projection=ea,this._extentLonLat=this._extent,this._extentMerc=new ie(n.southWest.forwardMercatorEPS01(),n.northEast.forwardMercatorEPS01()),this._isNorth=this._extent.northEast.lat>0,this.isPole=!0}_setExtentLonLat(){this._extentLonLat=this._extent}projectNative(e){return e}getInsideLonLat(e){return e._lonLat}_getMaxZoom(){let e=0;if(this._isNorth){let t=Math.floor((90-this._extent.northEast.lat)/La);e=Math.floor(t/16)+7}else{let t=Math.floor((ee-this._extent.northEast.lat)/La);e=12-Math.floor(t/16)}return e}checkZoom(){return super.checkZoom()&&this.tileZoom<=this._getMaxZoom()}_assignTileIndexes(){this._assignTileXIndexes(this._extent),this._assignTileYIndexes(this._extent),this.tileIndex=qt.getTileIndex(this.tileX,this.tileY,this.tileZoom,this._tileGroup)}_assignTileXIndexes(e){this.tileX=ia(e.getCenter().lon,e.getWidth(),-180);let t=1<<this.tileZoom;this.tileXE=(this.tileX+1)%t,this.tileXW=(t+this.tileX-1)%t}_assignTileYIndexes(e){const t=e.getCenter().lat;t>0?(this._tileGroup=ra,this.tileY=ia(t,e.getHeight(),90)):(this._tileGroup=sa,this.tileY=ia(t,e.getHeight(),ee)),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_projToDeg(e,t){return new z(e,t)}_assignGlobalTextureCoordinates(){const e=this._extent;this._globalTextureCoordinates[0]=(e.southWest.lon+180)/360,this._globalTextureCoordinates[1]=(90-e.northEast.lat)/180,this._globalTextureCoordinates[2]=(e.northEast.lon+180)/360,this._globalTextureCoordinates[3]=(90-e.southWest.lat)/180}_collectVisibleNodes(){this._isNorth?this.planet._visibleNodesNorth[this.node.nodeId]=this.node:this.planet._visibleNodesSouth[this.node.nodeId]=this.node}_getLayerExtentOffset(e){const t=e._extent,i=this._extent,n=t.northEast.lon-t.southWest.lon,r=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/n,(t.northEast.lat-i.northEast.lat)/r,(i.northEast.lon-i.southWest.lon)/n,(i.northEast.lat-i.southWest.lat)/r]}layerOverlap(e){return this._extent.overlaps(e._extent)}getDefaultTexture(){return this._isNorth?this.planet.solidTextureOne:this.planet.solidTextureTwo}getExtentLonLat(){return this._extent}}class Ea extends Ca{constructor(e){super(e,"Earth")}init(){this._quadTreeList=[new Ta(pa,this.planet,0,null,0,ie.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34])),new Ta(Aa,this.planet,0,null,0,ie.createFromArray([-180,J,180,90])),new Ta(Aa,this.planet,0,null,0,ie.createFromArray([-180,-90,180,ee]))]}getTileXY(e,t){let i=function(e,t=J){return e>t?ra:e<-t?sa:0}(e.lat,J),n=t,r=-1,s=-1,a=1<<n;if(i===ra)r=ia(e.lon,360/a,-180),s=ia(e.lat,(90-J)/a,90);else if(i===sa)r=ia(e.lon,360/a,-180),s=ia(e.lat,(90-J)/a,ee);else{let t=X(e);r=ia(t.lon,D/a,-F),s=ia(t.lat,D/a,F)}return[r,s,n,i]}getLonLatTileOffset(e,t,i,n,r){let s=e,a=new ie;if(e.lat>J){a=na(t,i,n,ie.createFromArray([-180,J,180,90]))}else if(e.lat<ee){a=na(t,i,n,ie.createFromArray([-180,-90,180,ee]))}else s=X(e),a=Q(t,i,n);let o=a.getWidth()/(r-1),l=a.getHeight()/(r-1);return[r-Math.ceil((s.lat-a.southWest.lat)/l)-1,Math.floor((s.lon-a.southWest.lon)/o)]}}class Pa{constructor(e={}){this.model=e.model||null,this.src=e.src||null,this._cached_ix=0,this._cached_iy=0,this._v00=0,this._v01=0,this._v10=0,this._v11=0,this._t=0}static loadModel(e){return e?fetch(e,{}).then((e=>{if(!e.ok)throw Error("Geoid model file: HTTP error "+e.status);return e.arrayBuffer()})).then((t=>{if(t)return new Uint8Array(t);throw Error("Geoid model file: no data from "+e)})).then((function(e){if(80!==e[0]||53!==e[1]||(13!==e[2]||10!==e[3])&&10!==e[2])throw new Error("Geoid model file: no PGM header");var t,i,n=13===e[2]?4:3,r=null,s=null;function a(){let t=n;for(var i=n;;i++){if(i>=e.length)throw new Error("Geoid model file: missing newline in header");if(10===e[i]){n=i+1;break}}return i>t&&13===e[i-1]&&i--,String.fromCharCode.apply(null,e.slice(t,i))}for(;"#"===(i=a())[0];)if(t=i.match(/^# Offset (.*)$/)){if(r=parseInt(t[1],10),!isFinite(r))throw new Error("Geoid model file: bad offset "+t[1])}else if((t=i.match(/^# Scale (.*)$/))&&(s=parseFloat(t[1]),!isFinite(s)))throw new Error("Geoid model file: bad scale "+t[1]);let o=0,l=0;if((t=i.match(/^\s*(\d+)\s+(\d+)\s*$/))&&(o=parseInt(t[1],10),l=parseInt(t[2],10)),!(t&&o>=0&&l>=0))throw new Error("Geoid model file: bad PGM width&height line");if(65535!=parseInt(a()))throw new Error("Geoid model file: PGM file must have 65535 gray levels");if(null===r)throw new Error("Geoid model file: PGM file does not contain offset");if(null===s)throw new Error("Geoid model file: PGM file does not contain scale");if(o<2||l<2)throw new Error("Geoid model file: Raster size too small");if(e.length-n!==o*l*2)throw new Error("Geoid model file: File has the wrong length");return{scale:s,offset:r,width:o,height:l,rlonres:o/360,rlatres:(l-1)/180,i:n,rawfile:e}})):new Promise((e=>{e(null)}))}setModel(e){this.model=e}_rawval(e,t){let i=this.model;t<0?(t=-t,e+=i.width/2):t>=i.height&&(t=2*(i.height-1)-t,e+=i.width/2),e<0?e+=i.width:e>=i.width&&(e-=i.width);let n=2*(t*i.width+e)+i.i;return i.rawfile[n]<<8|i.rawfile[n+1]}getHeightLonLat(e){return this.getHeight(e.lon,e.lat)}getHeight(e,t){if(!this.model)return 0;let i=this.model;e<0&&(e+=360);let n=(90-t)*i.rlatres,r=e*i.rlonres,s=Math.floor(n),a=Math.floor(r);r-=a,n-=s,s===i.height-1&&s--,this._cached_ix===a&&this._cached_iy===s||(this._cached_ix=a,this._cached_iy=s,this._v00=this._rawval(a,s),this._v01=this._rawval(a+1,s),this._v10=this._rawval(a,s+1),this._v11=this._rawval(a+1,s+1));let o=(1-n)*((1-r)*this._v00+r*this._v01)+n*((1-r)*this._v10+r*this._v11);return i.offset+i.scale*o}}class Ma{constructor(e,t=5){this.MAX_FRAMES=t,this._gridSize=64,this._planet=e,this._framebuffer=null,this._framebufferMercProj=null,this._texCoordsBuffer=null,this._indexBuffer=null,this._currentFrame=0,this._queue=[],this._animate=[],this._quadTexCoordsBuffer=null,this._quadVertexBuffer=null}init(){this._initShaders(),this._initBuffers()}createGridBuffer(e,t=!1){let i=this._gridSize,n=new z((e[3].lon-e[0].lon)/i,(e[3].lat-e[0].lat)/i),r=new z((e[2].lon-e[1].lon)/i,(e[2].lat-e[1].lat)/i),s=new z((e[1].lon-e[0].lon)/i,(e[1].lat-e[0].lat)/i),a=new z((e[2].lon-e[3].lon)/i,(e[2].lat-e[3].lat)/i);const o=(i+1)*(i+1)*2,l=o/2;let h=new Float32Array(o),c=new Float32Array(o),d=new Array(l),_=0,u=0,f=0,g=new Float32Array(2);for(let t=0;t<=i;t++){let o=new z(e[0].lon+t*n.lon,e[0].lat+t*n.lat),l=new z(e[1].lon+t*r.lon,e[1].lat+t*r.lat);for(let t=0;t<=i;t++){let i=Ie(o,l,new z(e[0].lon+t*s.lon,e[0].lat+t*s.lat),new z(e[3].lon+t*a.lon,e[3].lat+t*a.lat));nn(i.lon,g),h[_++]=g[0],c[u++]=g[1],nn(i.lat,g),h[_++]=g[0],c[u++]=g[1],d[f++]=i}}if(t)for(let e=0;e<l;e++){let t=d[e].forwardMercator();nn(t.lon,g),h[2*e]=g[0],c[2*e]=g[1],nn(t.lat,g),h[2*e+1]=g[0],c[2*e+1]=g[1]}return[this._planet.renderer.handler.createArrayBuffer(h,2,l),this._planet.renderer.handler.createArrayBuffer(c,2,l)]}frame(){let e=this.MAX_FRAMES;for(;e--&&this._queue.length;){const e=this._queue.shift();e._isRendering=!1,e.rendering(),e.events.dispatch(e.events.loadend)}for(e=this._animate.length;e--;)this._animate[e].rendering()}add(e){e._isRendering||(e._isRendering=!0,e._animate?this._animate.push(e):this._queue.push(e))}remove(e){if(e._isRendering){let t;e._creationProceeding=!1,e._isRendering=!1,t=e._animate?this._animate:this._queue;for(let i=0;i<t.length;i++)if(t[i].isEqual(e))return void t.splice(i,1)}}_initBuffers(){let e=this._planet.renderer.handler;this._framebuffer=new qs(e,{width:2,height:2,useDepth:!1}),this._framebuffer.init(),this._framebufferMercProj=new qs(e,{width:2,height:2,useDepth:!1}),this._framebufferMercProj.init();let t=Math.log2(this._gridSize);this._texCoordsBuffer=this._planet._textureCoordsBufferCache[t],this._indexBuffer=this._planet._indexesCache[t][t][t][t][t].buffer,this._quadTexCoordsBuffer=e.createArrayBuffer(new Float32Array([0,1,1,1,0,0,1,0]),2,4),this._quadVertexBuffer=e.createArrayBuffer(new Float32Array([-1,1,1,1,-1,-1,1,-1]),2,4)}_initShaders(){this._planet.renderer.handler.addProgram(new zi("geoImageTransform",{uniforms:{sourceTexture:"sampler2d",extentParamsHigh:"vec4",extentParamsLow:"vec4",isFullExtent:"bool"},attributes:{cornersHigh:"vec2",cornersLow:"vec2",texCoords:"vec2"},vertexShader:"attribute vec2 cornersHigh; \n attribute vec2 cornersLow;\n attribute vec2 texCoords; \n uniform vec4 extentParamsHigh; \n uniform vec4 extentParamsLow; \n varying vec2 v_texCoords;\n void main() { \n v_texCoords = texCoords; \n vec2 highDiff = cornersHigh - extentParamsHigh.xy;\n vec2 lowDiff = cornersLow - extentParamsLow.xy; \n gl_Position = vec4((-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0), 0.0, 1.0); \n }",fragmentShader:"precision highp float;\n uniform sampler2D sourceTexture;\n uniform bool isFullExtent;\n varying vec2 v_texCoords;\n void main () {\n if(!isFullExtent && (v_texCoords.x <= 0.001 || v_texCoords.x >= 0.999 ||\n v_texCoords.y <= 0.001 || v_texCoords.y >= 0.999)) {\n discard;\n }\n gl_FragColor = texture2D(sourceTexture, v_texCoords);\n }"}))}}const Sa=["loadend","layerloadend"];class Ba{constructor(e=24){this.MAX_REQUESTS=e,this.events=Pt(Sa),this._loading=0,this._queue=[],this._senderRequestCounter=[],this._promises={json:e=>e.json(),blob:e=>e.blob(),arrayBuffer:e=>e.arrayBuffer(),imageBitmap:e=>e.blob().then((e=>createImageBitmap(e,{premultiplyAlpha:"premultiply"}))),text:e=>e.text()}}load(e,t){e.sender&&(this._senderRequestCounter[e.sender.__id]||(this._senderRequestCounter[e.sender.__id]={sender:e.sender,counter:0,__requestCounterFrame__:0}),this._senderRequestCounter[e.sender.__id].counter++),this._queue.push({params:e,callback:t}),this._exec()}fetch(e){return fetch(e.src,e.options||{}).then((t=>{if(!t.ok)throw Error(`Unable to load '${e.src}'`);return this._promises[e.type||"blob"](t)})).then((e=>({status:"ready",data:e}))).catch((e=>({status:"error",msg:e.toString()})))}getRequestCounter(e){if(e){let t=this._senderRequestCounter[e.__id];if(t)return t.counter}return 0}isIdle(e){return e.isIdle}_checkLoadend(e,t){0!==e.counter||t._planet&&!t._planet._terrainCompletedActivated?e.__requestCounterFrame__=requestAnimationFrame((()=>{this._checkLoadend(e,t)})):(t.events.dispatch(t.events.loadend,t),this.events.dispatch(this.events.layerloadend,t),e.__requestCounterFrame__=0)}_handleResponse(e,t){e.callback(t);let i=e.params.sender;if(i&&(i.events.loadend.handlers.length||this.events.layerloadend.handlers.length)){let e=this._senderRequestCounter[i.__id];e&&e.counter>0&&(e.counter--,cancelAnimationFrame(e.__requestCounterFrame__),e.__requestCounterFrame__=requestAnimationFrame((()=>{this._checkLoadend(e,i)})))}this._exec()}_exec(){if(this._queue.length>0&&this._loading<this.MAX_REQUESTS){let e=this._queue.pop();if(!e)return;let t=e.params;if(!t.filter||t.filter(t))return this._loading++,fetch(t.src,t.options||{}).then((e=>{if(!e.ok)throw Error(`Unable to load '${t.src}'`);return this._promises[t.type||"blob"](e)})).then((t=>{this._loading--,this._handleResponse(e,{status:"ready",data:t})})).catch((t=>{this._loading--,this._handleResponse(e,{status:"error",msg:t.toString()})}));this._handleResponse(e,{status:"abort"})}else 0===this._loading&&this.events.dispatch(this.events.loadend)}abort(e){this._senderRequestCounter[e.__id]&&(this._senderRequestCounter[e.__id].counter=0,cancelAnimationFrame(this._senderRequestCounter[e.__id].__requestCounterFrame__),this._senderRequestCounter[e.__id].__requestCounterFrame__=0);for(let t=0,i=this._queue.length;t<i;t++){let i=this._queue[t];i&&i.params.sender&&e.isEqual(i.params.sender)&&(i.callback({status:"abort"}),this._queue[t]=null)}}abortAll(){for(let e=0,t=this._queue.length;e<t;e++){let t=this._queue[e];if(t){let i=t.params.sender;i&&this._senderRequestCounter[i.__id]&&(this._senderRequestCounter[i.__id].counter=0,cancelAnimationFrame(this._senderRequestCounter[i.__id].__requestCounterFrame__),this._senderRequestCounter[i.__id].__requestCounterFrame__=0),t.callback({status:"abort"}),this._queue[e]=null}}this._queue=[]}get loading(){return this._loading}get queue(){return this._queue}}class ka{constructor(e,t={}){this._minTabelSize=t.minTableSize||1,this._maxTableSize=t.maxTableSize||8,this._planet=e,this._handler=null,this._verticesBufferArray=[],this._indexBufferArray=[],this._positionBuffer=null,this._framebuffer=null,this._normalMapVerticesTexture=null,this._width=t.width||128,this._height=t.height||128,this._queue=new Rn(1024),this._lock=new yr}get width(){return this._width}get height(){return this._height}init(){this._maxTableSize=this._planet.maxGridSize||8,this._handler=this._planet.renderer.handler;const e=new zi("normalMapBlur",{attributes:{a_position:"vec2"},uniforms:{s_texture:"sampler2d"},vertexShader:`attribute vec2 a_position;\n attribute vec2 a_texCoord;\n\n varying vec2 blurCoordinates[5];\n\n void main() {\n vec2 vt = a_position * 0.5 + 0.5; \n \n gl_Position = vec4(a_position, 0.0, 1.0);\n blurCoordinates[0] = vt;\n blurCoordinates[1] = vt + ${1/this._width*1.407333};\n blurCoordinates[2] = vt - ${1/this._height*1.407333};\n blurCoordinates[3] = vt + ${1/this._width*3.294215};\n blurCoordinates[4] = vt - ${1/this._height*3.294215};\n }`,fragmentShader:"precision lowp float;\n uniform sampler2D s_texture; \n varying vec2 blurCoordinates[5]; \n\n void main() {\n lowp vec4 sum = vec4(0.0);\n //if(blurCoordinates[0].x <= 0.01 || blurCoordinates[0].x >= 0.99 ||\n // blurCoordinates[0].y <= 0.01 || blurCoordinates[0].y >= 0.99){\n // sum = texture2D(s_texture, blurCoordinates[0]);\n //} else {\n sum += texture2D(s_texture, blurCoordinates[0]) * 0.204164;\n sum += texture2D(s_texture, blurCoordinates[1]) * 0.304005;\n sum += texture2D(s_texture, blurCoordinates[2]) * 0.304005;\n sum += texture2D(s_texture, blurCoordinates[3]) * 0.093913;\n sum += texture2D(s_texture, blurCoordinates[4]) * 0.093913;\n //}\n gl_FragColor = sum;\n }"}),t=new zi("normalMap",{attributes:{a_position:"vec2",a_normal:"vec3"},uniforms:{},vertexShader:"attribute vec2 a_position;\n attribute vec3 a_normal;\n \n varying vec3 v_color;\n \n void main() {\n gl_Position = vec4(a_position, 0, 1);\n v_color = normalize(a_normal) * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n \n varying vec3 v_color;\n \n void main () {\n gl_FragColor = vec4(v_color, 1.0);\n }"});this._handler.addProgram(e),this._handler.addProgram(t),this._framebuffer=new qs(this._handler,{width:this._width,height:this._height,useDepth:!1}),this._framebuffer.init(),this._normalMapVerticesTexture=this._handler.createEmptyTexture_l(this._width,this._height);for(let e=this._minTabelSize;e<=this._maxTableSize;e++){const t=1<<e,i=t/2;let n=new Float32Array((t+1)*(t+1)*2);for(let e=0;e<=t;e++)for(let r=0;r<=t;r++){let s=2*(e*(t+1)+r);n[s]=r/i-1,n[s+1]=e/i-1}this._verticesBufferArray[t]=this._handler.createArrayBuffer(n,2,n.length/2),this._indexBufferArray[t]=this._planet._indexesCache[Math.log2(t)][Math.log2(t)][Math.log2(t)][Math.log2(t)][Math.log2(t)].buffer}const i=new Float32Array([-1,-1,1,-1,-1,1,1,1]);this._positionBuffer=this._handler.createArrayBuffer(i,2,i.length/2)}_drawNormalMapBlur(e){let t=e.normalMapNormals;if(e.node&&0!==e.node.getState()&&t&&t.length){const i=t.length/3,n=Math.sqrt(i)-1;let r=this._verticesBufferArray[n];if(r){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let s=e.normalMapTexturePtr;const a=this._handler,o=a.gl;let l=a.createArrayBuffer(t,3,i,o.DYNAMIC_DRAW);const h=this._framebuffer;let c=a.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(this._normalMapVerticesTexture),c.activate(),o.bindBuffer(o.ARRAY_BUFFER,r),o.vertexAttribPointer(d.a_position,r.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,l),o.vertexAttribPointer(d.a_normal,l.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[n]),o.drawElements(o.TRIANGLE_STRIP,this._indexBufferArray[n].numItems,o.UNSIGNED_INT,0),o.deleteBuffer(l),h.bindOutputTexture(s),c=a.programs.normalMapBlur,c.activate(),o.bindBuffer(o.ARRAY_BUFFER,this._positionBuffer),o.vertexAttribPointer(c._program.attributes.a_position,this._positionBuffer.itemSize,o.FLOAT,!1,0,0),o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,this._normalMapVerticesTexture),o.uniform1i(c._program.uniforms.s_texture,0),o.drawArrays(o.TRIANGLE_STRIP,0,this._positionBuffer.numItems),!0}return!0}return!1}_drawNormalMapNoBlur(e){let t=e.normalMapNormals;if(e.node&&0!==e.node.getState()&&t&&t.length){const i=t.length/3,n=Math.sqrt(i)-1;let r=this._verticesBufferArray[n];if(r){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let s=e.normalMapTexturePtr;const a=this._handler,o=a.gl;let l=a.createArrayBuffer(t,3,i,o.DYNAMIC_DRAW);const h=this._framebuffer,c=a.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(s),c.activate(),o.bindBuffer(o.ARRAY_BUFFER,r),o.vertexAttribPointer(d.a_position,r.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,l),o.vertexAttribPointer(d.a_normal,l.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[n]),o.drawElements(o.TRIANGLE_STRIP,this._indexBufferArray[n].numItems,o.UNSIGNED_INT,0),o.deleteBuffer(l),!0}return!0}return!1}_drawNormalMap(e){return e.planet.terrain.isBlur(e)?this._drawNormalMapBlur(e):this._drawNormalMapNoBlur(e)}drawSingle(e){const t=this._handler.gl;this._framebuffer.activate(),t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),e.terrainReady&&this._drawNormalMap(e)&&(e.normalMapReady=!0,e.normalMapTexture=e.normalMapTexturePtr,e.normalMapTextureBias[0]=0,e.normalMapTextureBias[1]=0,e.normalMapTextureBias[2]=1),e._inTheQueue=!1,t.enable(t.DEPTH_TEST),t.enable(t.CULL_FACE),t.enable(t.BLEND),this._framebuffer.deactivate()}frame(){if(this._queue.length){const e=this._handler.gl;this._framebuffer.activate(),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.BLEND);let t=0,i=window.performance.now();for(;this._lock.isFree()&&this._queue.length&&t<.25;){const e=this._queue.shift();e.terrainReady&&this._drawNormalMap(e)&&(e.normalMapReady=!0,e.normalMapTexture=e.normalMapTexturePtr,e.normalMapTextureBias[0]=0,e.normalMapTextureBias[1]=0,e.normalMapTextureBias[2]=1),e._inTheQueue=!1,t=window.performance.now()-i}e.enable(e.BLEND),e.enable(e.DEPTH_TEST),e.enable(e.CULL_FACE),this._framebuffer.deactivate()}}get queueSize(){return this._queue.length}queue(e){e._inTheQueue=!0,this._queue.push(e)}unshift(e){e._inTheQueue=!0,this._queue.unshift(e)}remove(e){}clear(){for(;this._queue.length;){this._queue.pop()._inTheQueue=!1}}lock(e){this._lock.lock(e)}free(e){this._lock.free(e)}}class Ra extends Jt{constructor(e=2){super(e,Ia)}_onMessage(e){this._source.get(e.data.id)._plainSegmentWorkerCallback(e.data),e.data.plainVertices=null,e.data.plainVerticesHigh=null,e.data.plainVerticesLow=null,e.data.plainNormals=null,e.data.normalMapNormals=null,e.data.normalMapVertices=null,e.data.normalMapVerticesHigh=null,e.data.normalMapVerticesLow=null,this._source.delete(e.data.id)}setGeoid(e){if(e.model){let t=e.model,i={scale:t.scale,offset:t.offset,width:t.width,height:t.height,rlonres:t.rlonres,rlatres:t.rlatres,i:t.i};this._workerQueue.forEach((e=>{let n=new Uint8Array(t.rawfile.length);n.set(t.rawfile),e.postMessage({model:i,rawfile:n},[n.buffer])}))}else this._workerQueue.forEach((e=>{e.postMessage({model:null})}))}make(e){if(e.initialized)if(this._workerQueue.length){let t=this._workerQueue.pop();this._source.set(this._sourceId,e);let i=new Float64Array([this._sourceId,e._projection.id===ea.id?1:0,e.planet.terrain.gridSizeByZoom[e.tileZoom],e.planet.terrain.plainGridSize,e._extent.southWest.lon,e._extent.southWest.lat,e._extent.northEast.lon,e._extent.northEast.lat,e.planet.ellipsoid._e2,e.planet.ellipsoid.equatorialSize,e.planet.ellipsoid._invRadii2.x,e.planet.ellipsoid._invRadii2.y,e.planet.ellipsoid._invRadii2.z,e.planet._heightFactor]);this._sourceId++,t.postMessage({params:i},[i.buffer])}else this._pendingQueue.push(e);else this.check()}}const Ia="\n 'use strict';\n \n let model = null;\n\n let cached_ix = null;\n let cached_iy = null;\n let v00 = null;\n let v01 = null;\n let v10 = null;\n let v11 = null;\n let t = null;\n\n function rawval(ix, iy) {\n\n if (iy < 0) {\n iy = -iy;\n ix += model.width / 2;\n } else if (iy >= model.height) {\n iy = 2 * (model.height - 1) - iy;\n ix += model.width / 2;\n }\n\n if (ix < 0) {\n ix += model.width;\n } else if (ix >= model.width) {\n ix -= model.width;\n }\n\n var k = (iy * model.width + ix) * 2 + model.i;\n\n return (model.rawfile[k] << 8) | model.rawfile[k + 1];\n };\n\n function getHeightMSL(lon, lat) {\n\n if (!model) return 0;\n\n if (lon < 0) lon += 360.0;\n\n var fy = (90 - lat) * model.rlatres;\n var fx = lon * model.rlonres;\n var iy = Math.floor(fy);\n var ix = Math.floor(fx);\n\n fx -= ix;\n fy -= iy;\n\n if (iy === (model.height - 1)) {\n iy--;\n }\n\n if ((cached_ix !== ix) || (cached_iy !== iy)) {\n\n cached_ix = ix;\n cached_iy = iy;\n\n v00 = rawval(ix, iy);\n v01 = rawval(ix + 1, iy);\n v10 = rawval(ix, iy + 1);\n v11 = rawval(ix + 1, iy + 1);\n }\n\n let h = null;\n\n var a = (1 - fx) * v00 + fx * v01;\n var b = (1 - fx) * v10 + fx * v11;\n\n h = (1 - fy) * a + fy * b;\n\n return model.offset + model.scale * h;\n };\n\n const HALF_PI = Math.PI * 0.5;\n const POLE = 20037508.34;\n const PI_BY_POLE = Math.PI / POLE;\n const INV_POLE_BY_180 = 180.0 / POLE;\n const INV_PI_BY_180 = 180.0 / Math.PI;\n const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;\n const RADIANS = Math.PI / 180.0;\n const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;\n\n let E2 = 0.0,\n A = 0.0;\n\n let _projFunc = null;\n\n const Vec3 = function (x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n };\n\n var geodeticToCartesian = function (lon, lat, heightFactor, res) {\n\n let h = getHeightMSL(lon, lat) * heightFactor;\n\n let latrad = RADIANS * lat,\n lonrad = RADIANS * lon;\n\n let slt = Math.sin(latrad);\n\n let N = A / Math.sqrt(1.0 - E2 * slt * slt);\n let nc = (N + h) * Math.cos(latrad); \n \n res.x = nc * Math.cos(lonrad);\n res.y = nc * Math.sin(lonrad);\n res.z = (N * (1 - E2) + h) * slt;\n };\n\n var geodeticToCartesianInverse = function (lon, lat, heightFactor, res){\n geodeticToCartesian(\n lon * INV_POLE_BY_180,\n INV_PI_BY_360 * Math.atan(Math.exp(lat * PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,\n heightFactor,\n res);\n };\n\n var v = new Vec3(0.0, 0.0, 0.0);\n var _tempHigh = new Vec3(0.0, 0.0, 0.0);\n var _tempLow = new Vec3(0.0, 0.0, 0.0);\n\n var doubleToTwoFloats = function(v, high, low) {\n\n let x = v.x, y = v.y, z = v.z;\n \n if (x >= 0.0) {\n var doubleHigh = Math.floor(x / 65536.0) * 65536.0;\n high.x = Math.fround(doubleHigh);\n low.x = Math.fround(x - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-x / 65536.0) * 65536.0;\n high.x = Math.fround(-doubleHigh);\n low.x = Math.fround(x + doubleHigh);\n }\n\n if (y >= 0.0) {\n var doubleHigh = Math.floor(y / 65536.0) * 65536.0;\n high.y = Math.fround(doubleHigh);\n low.y = Math.fround(y - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-y / 65536.0) * 65536.0;\n high.y = Math.fround(-doubleHigh);\n low.y = Math.fround(y + doubleHigh);\n }\n\n if (z >= 0.0) {\n var doubleHigh = Math.floor(z / 65536.0) * 65536.0;\n high.z = Math.fround(doubleHigh);\n low.z = Math.fround(z - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-z / 65536.0) * 65536.0;\n high.z = Math.fround(-doubleHigh);\n low.z = Math.fround(z + doubleHigh);\n }\n };\n\n self.onmessage = function (msg) {\n if(msg.data.model) {\n model = msg.data.model;\n model.rawfile = msg.data.rawfile;\n } else if(msg.data.params) {\n\n let xmin = 549755748352.0, xmax = -549755748352.0, \n ymin = 549755748352.0, ymax = -549755748352.0, \n zmin = 549755748352.0, zmax = -549755748352.0;\n\n E2 = msg.data.params[8];\n A = msg.data.params[9];\n\n let gridSize = msg.data.params[2],\n fgs = msg.data.params[3],\n r2_x = msg.data.params[10],\n r2_y = msg.data.params[11],\n r2_z = msg.data.params[12];\n\n let heightFactor = msg.data.params[13];\n \n if(msg.data.params[1] === 0.0){\n _projFunc = geodeticToCartesianInverse;\n }else{\n _projFunc = geodeticToCartesian;\n }\n\n let maxFgs = Math.max(fgs, gridSize);\n let llStep = (msg.data.params[6] - msg.data.params[4]) / maxFgs;\n let ltStep = (msg.data.params[7] - msg.data.params[5]) / maxFgs;\n\n let esw_lon = msg.data.params[4],\n ene_lat = msg.data.params[7];\n\n let dg = Math.max(fgs / gridSize, 1.0),\n gs = maxFgs + 1;\n \n const gsgs = gs * gs;\n\n const gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;\n\n let plainNormals = new Float32Array(gridSize3);\n\n let plainVertices = new Float64Array(gridSize3);\n let plainVerticesHigh = new Float32Array(gridSize3);\n let plainVerticesLow = new Float32Array(gridSize3);\n\n let normalMapNormals = new Float32Array(gsgs * 3);\n\n let normalMapVertices = new Float64Array(gsgs * 3);\n let normalMapVerticesHigh = new Float32Array(gsgs * 3);\n let normalMapVerticesLow = new Float32Array(gsgs * 3);\n\n let ind = 0,\n nmInd = 0;\n\n for (let k = 0; k < gsgs; k++) {\n\n let j = k % gs,\n i = ~~(k / gs);\n\n _projFunc(esw_lon + j * llStep, ene_lat - i * ltStep, heightFactor, v);\n\n let nx = v.x * r2_x, ny = v.y * r2_y, nz = v.z * r2_z;\n let l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz); \n let nxl = nx * l,\n nyl = ny * l,\n nzl = nz * l;\n\n doubleToTwoFloats(v, _tempHigh, _tempLow);\n\n normalMapVertices[nmInd] = v.x;\n normalMapVerticesHigh[nmInd] = _tempHigh.x;\n normalMapVerticesLow[nmInd] = _tempLow.x;\n normalMapNormals[nmInd++] = nxl;\n\n normalMapVertices[nmInd] = v.y;\n normalMapVerticesHigh[nmInd] = _tempHigh.y;\n normalMapVerticesLow[nmInd] = _tempLow.y;\n normalMapNormals[nmInd++] = nyl;\n\n normalMapVertices[nmInd] = v.z;\n normalMapVerticesHigh[nmInd] = _tempHigh.z;\n normalMapVerticesLow[nmInd] = _tempLow.z;\n normalMapNormals[nmInd++] = nzl;\n\n if (i % dg === 0 && j % dg === 0) {\n plainVertices[ind] = v.x;\n plainVerticesHigh[ind] = _tempHigh.x;\n plainVerticesLow[ind] = _tempLow.x;\n plainNormals[ind++] = nxl;\n\n plainVertices[ind] = v.y;\n plainVerticesHigh[ind] = _tempHigh.y;\n plainVerticesLow[ind] = _tempLow.y;\n plainNormals[ind++] = nyl;\n\n plainVertices[ind] = v.z;\n plainVerticesHigh[ind] = _tempHigh.z;\n plainVerticesLow[ind] = _tempLow.z;\n plainNormals[ind++] = nzl;\n\n if (v.x < xmin) xmin = v.x; if (v.x > xmax) xmax = v.x;\n if (v.y < ymin) ymin = v.y; if (v.y > ymax) ymax = v.y;\n if (v.z < zmin) zmin = v.z; if (v.z > zmax) zmax = v.z;\n }\n }\n\n let x = (xmax - xmin) * 0.5,\n y = (ymax - ymin) * 0.5,\n z = (zmax - zmin) * 0.5;\n\n let plainRadius = Math.sqrt(x * x + y * y + z * z);\n\n self.postMessage({\n id: msg.data.params[0],\n plainVertices: plainVertices,\n plainVerticesHigh: plainVerticesHigh,\n plainVerticesLow: plainVerticesLow,\n plainNormals: plainNormals,\n normalMapNormals: normalMapNormals,\n normalMapVertices: normalMapVertices,\n normalMapVerticesHigh: normalMapVerticesHigh,\n normalMapVerticesLow: normalMapVerticesLow,\n plainRadius: plainRadius\n }, [\n plainVertices.buffer,\n plainVerticesHigh.buffer,\n plainVerticesLow.buffer,\n plainNormals.buffer,\n normalMapNormals.buffer,\n normalMapVertices.buffer,\n normalMapVerticesHigh.buffer,\n normalMapVerticesLow.buffer\n ]);\n }\n }";function za(e){let t=1/Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]*=t,e[1]*=t,e[2]*=t,e[3]*=t}class Fa{constructor(e={}){this._pickingColorU=new Float32Array([0,0,0]),this._f=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],this.projectionMatrix=new se,this.inverseProjectionMatrix=new se,this.projectionViewMatrix=new se,this.inverseProjectionViewMatrix=new se,this.left=0,this.right=0,this.bottom=0,this.top=0,this.near=0,this.far=0,this.cameraFrustumIndex=null!=e.cameraFrustumIndex?e.cameraFrustumIndex:-1,this.setProjectionMatrix(e.fov||30,e.aspect||1,e.near||1,e.far||1e3)}getRightPlane(){return this._f[0]}getLeftPlane(){return this._f[1]}getBottomPlane(){return this._f[2]}getTopPlane(){return this._f[3]}getBackwardPlane(){return this._f[4]}getForwardPlane(){return this._f[5]}getProjectionViewMatrix(){return this.projectionViewMatrix._m}getProjectionMatrix(){return this.projectionMatrix._m}getInverseProjectionMatrix(){return this.inverseProjectionMatrix._m}setProjectionMatrix(e,t,i,n){this.top=i*Math.tan(e*c),this.bottom=-this.top,this.right=this.top*t,this.left=-this.right,this.near=i,this.far=n,this.projectionMatrix.setPerspective(this.left,this.right,this.bottom,this.top,i,n),this.projectionMatrix.inverseTo(this.inverseProjectionMatrix)}setViewMatrix(e){this.projectionViewMatrix=this.projectionMatrix.mul(e),this.projectionViewMatrix.inverseTo(this.inverseProjectionViewMatrix);let t=this.projectionViewMatrix._m;this._f[0][0]=t[3]-t[0],this._f[0][1]=t[7]-t[4],this._f[0][2]=t[11]-t[8],this._f[0][3]=t[15]-t[12],za(this._f[0]),this._f[1][0]=t[3]+t[0],this._f[1][1]=t[7]+t[4],this._f[1][2]=t[11]+t[8],this._f[1][3]=t[15]+t[12],za(this._f[1]),this._f[2][0]=t[3]+t[1],this._f[2][1]=t[7]+t[5],this._f[2][2]=t[11]+t[9],this._f[2][3]=t[15]+t[13],za(this._f[2]),this._f[3][0]=t[3]-t[1],this._f[3][1]=t[7]-t[5],this._f[3][2]=t[11]-t[9],this._f[3][3]=t[15]-t[13],za(this._f[3]),this._f[4][0]=t[3]-t[2],this._f[4][1]=t[7]-t[6],this._f[4][2]=t[11]-t[10],this._f[4][3]=t[15]-t[14],za(this._f[4]),this._f[5][0]=t[3]+t[2],this._f[5][1]=t[7]+t[6],this._f[5][2]=t[11]+t[10],this._f[5][3]=t[15]+t[14],za(this._f[5])}containsPoint(e){for(let t=0;t<6;t++){if(e.dotArr(this._f[t])+this._f[t][3]<=0)return!1}return!0}containsSphereBottomExc(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[0])+i[0][3]<=t)&&(!(e.center.dotArr(i[1])+i[1][3]<=t)&&(!(e.center.dotArr(i[3])+i[3][3]<=t)&&(!(e.center.dotArr(i[4])+i[4][3]<=t)&&!(e.center.dotArr(i[5])+i[5][3]<=t))))}containsSphereButtom(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[2])+i[2][3]<=t)}containsSphere(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[0])+i[0][3]<=t)&&(!(e.center.dotArr(i[1])+i[1][3]<=t)&&(!(e.center.dotArr(i[2])+i[2][3]<=t)&&(!(e.center.dotArr(i[3])+i[3][3]<=t)&&(!(e.center.dotArr(i[4])+i[4][3]<=t)&&!(e.center.dotArr(i[5])+i[5][3]<=t)))))}containsSphere2(e,t){let i=-t;return!(e.dotArr(this._f[0])+this._f[0][3]<=i)&&(!(e.dotArr(this._f[1])+this._f[1][3]<=i)&&(!(e.dotArr(this._f[2])+this._f[2][3]<=i)&&(!(e.dotArr(this._f[3])+this._f[3][3]<=i)&&(!(e.dotArr(this._f[4])+this._f[4][3]<=i)&&!(e.dotArr(this._f[5])+this._f[5][3]<=i)))))}containsBox(e){let t,i,n=!0;for(let r=0;r<6;r++){t=0,i=0;for(let n=0;n<8&&(0===i||0===t);n++){e.vertices[n].dotArr(this._f[r])+this._f[r][3]<0?t++:i++}if(0===i)return!1;t>0&&(n=!0)}return n}}const Da=["viewchange","moveend"];class Na{constructor(e,t={}){if(this.renderer=e,this.events=Pt(Da,this),this.eye=t.eye||new oe,this.eyeHigh=new Float32Array(3),this.eyeLow=new Float32Array(3),this._aspect=t.aspect||1,this._viewAngle=t.viewAngle||47,this._viewMatrix=new se,this._normalMatrix=new ne,this._r=new oe(1,0,0),this._u=new oe(0,1,0),this._b=new oe(0,0,1),this._pr=this._r.clone(),this._pu=this._u.clone(),this._pb=this._b.clone(),this._peye=this.eye.clone(),this.isMoving=!1,this._tanViewAngle_hrad=0,this._tanViewAngle_hradOneByHeight=0,this.frustums=[],this.frustumColors=[],t.frustums)for(let e=0,i=t.frustums.length;e<i;e++){let i=t.frustums[e],n=new Fa({fov:this._viewAngle,aspect:this._aspect,near:i[0],far:i[1]});n.cameraFrustumIndex=this.frustums.length,this.frustums.push(n),this.frustumColors.push(n._pickingColorU[0],n._pickingColorU[1],n._pickingColorU[2])}else{let e=1,t=1e4,i=new Fa({fov:this._viewAngle,aspect:this._aspect,near:e,far:t});i.cameraFrustumIndex=this.frustums.length,this.frustums.push(i),this.frustumColors.push(i._pickingColorU[0],i._pickingColorU[1],i._pickingColorU[2])}this.FARTHEST_FRUSTUM_INDEX=this.frustums.length-1,this.currentFrustumIndex=0,this.isFirstPass=!1,this._projSizeConst=0,this.set(t.eye||new oe(0,0,1),t.look||new oe,t.up||new oe(0,1,0))}checkMoveEnd(){let e=this._r,t=this._u,i=this._b,n=this.eye;this._peye.equal(n)&&this._pr.equal(e)&&this._pu.equal(t)&&this._pb.equal(i)?(this.isMoving&&this.events.dispatch(this.events.moveend,this),this.isMoving=!1):this.isMoving=!0,this._pr.copy(e),this._pu.copy(t),this._pb.copy(i),this._peye.copy(n)}bindRenderer(e){this.renderer=e;for(let e=0;e<this.frustums.length;e++)this.renderer.assignPickingColor(this.frustums[e]);this._aspect=this.renderer.handler.getClientAspect(),this._setProj(this._viewAngle,this._aspect)}_init(e){this._setProj(this._viewAngle,this._aspect),this.set(e.eye||new oe(0,0,1),e.look||new oe,e.up||new oe(0,1,0))}getUp(){return this._u.clone()}getDown(){return this._u.negateTo()}getRight(){return this._r.clone()}getLeft(){return this._r.negateTo()}getForward(){return this._b.negateTo()}getBackward(){return this._b.clone()}update(){let e=this._r,t=this._u,i=this._b,n=this.eye;oe.doubleToTwoFloat32Array(n,this.eyeHigh,this.eyeLow),this._viewMatrix.set([e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,-n.dot(e),-n.dot(t),-n.dot(i),1]);for(let e=0,t=this.frustums.length;e<t;e++)this.frustums[e].setViewMatrix(this._viewMatrix);this.events.dispatch(this.events.viewchange,this)}refresh(){this._setProj(this._viewAngle,this._aspect),this.update()}setAspectRatio(e){this._aspect=e,this.refresh()}getAspectRatio(){return this._aspect}_setProj(e,t){this._viewAngle=e,this._aspect=t,this._tanViewAngle_hrad=Math.tan(e*c),this._tanViewAngle_hradOneByHeight=this._tanViewAngle_hrad*this.renderer.handler._oneByHeight;let i=this.renderer.handler.canvas;this._projSizeConst=Math.min(i.clientWidth<512?512:i.clientWidth,i.clientHeight<512?512:i.clientHeight)/(e*o);for(let i=0,n=this.frustums.length;i<n;i++)this.frustums[i].setProjectionMatrix(e,t,this.frustums[i].near,this.frustums[i].far)}setViewAngle(e){this._viewAngle=e,this.refresh()}getViewAngle(){return this._viewAngle}get viewAngle(){return this._viewAngle}set(e,t,i){return this.eye.x=e.x,this.eye.y=e.y,this.eye.z=e.z,t=t||this._b,i=i||this._u,this._b.x=e.x-t.x,this._b.y=e.y-t.y,this._b.z=e.z-t.z,this._r.copy(i.cross(this._b)),this._b.normalize(),this._r.normalize(),this._u.copy(this._b.cross(this._r)),this}look(e,t){this._b.set(this.eye.x-e.x,this.eye.y-e.y,this.eye.z-e.z),this._r.copy((t||this._u).cross(this._b)),this._b.normalize(),this._r.normalize(),this._u.copy(this._b.cross(this._r))}slide(e,t,i){this.eye.x+=e*this._r.x+t*this._u.x+i*this._b.x,this.eye.y+=e*this._r.y+t*this._u.y+i*this._b.y,this.eye.z+=e*this._r.z+t*this._u.z+i*this._b.z}roll(e){let t=Math.cos(o*e),i=Math.sin(o*e),n=this._r.clone();this._r.set(t*n.x-i*this._u.x,t*n.y-i*this._u.y,t*n.z-i*this._u.z),this._u.set(i*n.x+t*this._u.x,i*n.y+t*this._u.y,i*n.z+t*this._u.z)}pitch(e){let t=Math.cos(o*e),i=Math.sin(o*e),n=this._b.clone();this._b.set(t*n.x-i*this._u.x,t*n.y-i*this._u.y,t*n.z-i*this._u.z),this._u.set(i*n.x+t*this._u.x,i*n.y+t*this._u.y,i*n.z+t*this._u.z)}yaw(e){let t=Math.cos(o*e),i=Math.sin(o*e),n=this._r.clone();this._r.set(t*n.x-i*this._b.x,t*n.y-i*this._b.y,t*n.z-i*this._b.z),this._b.set(i*n.x+t*this._b.x,i*n.y+t*this._b.y,i*n.z+t*this._b.z)}unproject(e,t){let i=this.renderer.handler.canvas,n=.5*i.width,r=.5*i.height,s=(e-n)/n,a=-(t-r)/r,o=this.frustums[0].inverseProjectionViewMatrix.mulVec4(new re(s,a,-1,1)).affinity();return this.frustums[0].inverseProjectionViewMatrix.mulVec4(new re(s,a,0,1)).affinity().subA(o).toVec3().normalize()}project(e){let t=this.frustums[0].projectionViewMatrix.mulVec4(e.toVec4()),i=this.renderer.handler.canvas;return new le((1+t.x/t.w)*i.width*.5,(1-t.y/t.w)*i.height*.5)}rotateAround(e,t,i,n){i=i||oe.ZERO,n=n||oe.UP;let r=(new se).setRotation(t?this._u:n,e),s=(new se).setIdentity().translate(i),a=(new se).setIdentity().translate(i.negateTo()),o=s.mul(r).mul(a);this.eye=o.mulVec3(this.eye),this._u=r.mulVec3(this._u).normalize(),this._r=r.mulVec3(this._r).normalize(),this._b=r.mulVec3(this._b).normalize()}rotateHorizontal(e,t,i,n){this.rotateAround(e,t,i,n)}rotateVertical(e,t){this.rotateAround(e,!1,t,this._r)}projectedSize(e,t){return Math.atan(t/this.eye.distance(e))*this._projSizeConst}getViewMatrix(){return this._viewMatrix._m}getNormalMatrix(){return this._normalMatrix._m}setCurrentFrustum(e){this.currentFrustumIndex=e,this.isFirstPass=e===this.FARTHEST_FRUSTUM_INDEX}getCurrentFrustum(){return this.currentFrustumIndex}get frustum(){return this.frustums[this.currentFrustumIndex]}getProjectionMatrix(){return this.frustum.projectionMatrix._m}getProjectionViewMatrix(){return this.frustum.projectionViewMatrix._m}getInverseProjectionViewMatrix(){return this.frustum.inverseProjectionViewMatrix._m}getInverseProjectionMatrix(){return this.frustum.inverseProjectionMatrix._m}}class Ha extends Na{constructor(e,t={}){super(e.renderer,{...t,frustums:t.frustums||[[1,100.075],[100,1000.075],[1e3,101e4],[1e6,1e9]]}),this.planet=e,this.minAltitude=t.minAltitude||1,this.maxAltitude=t.maxAltitude||2e7,this._lonLat=this.planet.ellipsoid.cartesianToLonLat(this.eye),this._lonLatMerc=this._lonLat.forwardMercator(),this._terrainAltitude=this._lonLat.height,this._terrainPoint=new oe,this._insideSegment=null,this.slope=0,this._keyLock=new xr,this._framesArr=[],this._framesCounter=0,this._numFrames=50,this._completeCallback=null,this._frameCallback=null,this._flying=!1,this._checkTerrainCollision=!0,this.eyeNorm=this.eye.getNormal()}setTerrainCollisionActivity(e){this._checkTerrainCollision=e}update(){this.events.stopPropagation();let e=this.maxAltitude+this.planet.ellipsoid.getEquatorialSize();this.eye.length()>e&&this.eye.copy(this.eye.getNormal().scale(e)),super.update(),this.updateGeodeticPosition(),this.eyeNorm=this.eye.getNormal(),this.slope=this._b.dot(this.eyeNorm),this.events.dispatch(this.events.viewchange,this)}updateGeodeticPosition(){this.planet.ellipsoid.cartesianToLonLatRes(this.eye,this._lonLat),Math.abs(this._lonLat.lat)<=J&&z.forwardMercatorRes(this._lonLat,this._lonLatMerc)}setAltitude(e){let t=this._terrainPoint,i=this.planet.ellipsoid.getSurfaceNormal3v(this.eye);this.eye.x=i.x*e+t.x,this.eye.y=i.y*e+t.y,this.eye.z=i.z*e+t.z,this._terrainAltitude=e}getAltitude(){return this._terrainAltitude}setLonLat(e,t,i){this.stopFlying(),this._lonLat.set(e.lon,e.lat,e.height||this._lonLat.height);let n=this.planet.ellipsoid,r=n.lonLatToCartesian(this._lonLat),s=t?n.lonLatToCartesian(t):oe.ZERO;this.set(r,s,i||oe.NORTH),this.update()}getLonLat(){return this._lonLat}getHeight(){return this._lonLat.height}getExtentPosition(e,t){t=t||0;let i=e.getNorth(),n=e.getSouth(),r=e.getEast(),s=e.getWest();s>r&&(r+=360);let a=this.planet.ellipsoid,l=new z(r,i),h=a.lonLatToCartesian(l);l.lat=n;let c=a.lonLatToCartesian(l);l.lon=s;let d=a.lonLatToCartesian(l);l.lat=i;let _=a.lonLatToCartesian(l),u=oe.sub(h,d).scale(.5).addA(d),f=u.length();f<1e-6&&(l.lon=.5*(r+s),l.lat=.5*(i+n),u=a.lonLatToCartesian(l)),_.subA(u),c.subA(u),h.subA(u),d.subA(u);let g=u.getNormal(),p=g.cross(oe.NORTH).normalize(),m=p.cross(g).normalize(),v=Math.max(Math.abs(m.dot(_)),Math.abs(m.dot(c)),Math.abs(m.dot(h)),Math.abs(m.dot(d))),y=Math.max(Math.abs(p.dot(_)),Math.abs(p.dot(c)),Math.abs(p.dot(h)),Math.abs(p.dot(d))),x=Math.tan(this._viewAngle*o*.5),b=this._aspect*x,w=Math.max(y/b,v/x);return u.normalize(),u.scale(f+w+t),u}viewExtent(e,t){this.stopFlying(),this.set(this.getExtentPosition(e,t),oe.ZERO,oe.NORTH),this.update()}flyExtent(e,t,i,n,r,s,a){this.flyCartesian(this.getExtentPosition(e,t),oe.ZERO,i,null==n?1:n,r,s,a)}viewDistance(e,t=1e4){let i=this.eye.add(this.getForward().scaleTo(t)),n=ae.getRotationBetweenVectors(i.getNormal(),e.getNormal());if(n.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let i=e.add(n.mulVec3(this.getBackward()).scale(t)),r=n.mulVec3(this.getUp());this.set(i,e,r)}this.update()}flyDistance(e,t=1e4,i=0,n,r,s){let a=this.eye.add(this.getForward().scaleTo(t)),o=ae.getRotationBetweenVectors(a.getNormal(),e.getNormal());if(o.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let a=e.add(o.mulVec3(this.getBackward()).scale(t)),l=o.mulVec3(this.getUp());this.flyCartesian(a,e,l,i,n,r,s)}}flyCartesian(e,t=oe.ZERO,i=oe.NORTH,n=1,r=(()=>{}),s=(()=>{}),a=(()=>{})){this.stopFlying(),t=t||oe.ZERO,i=i||oe.NORTH,this._completeCallback=r,this._frameCallback=a,s&&s.call(this),t instanceof z&&(t=this.planet.ellipsoid.lonLatToCartesian(t));let o=this.planet.ellipsoid.lonLatToCartesian(new z(this._lonLat.lon,this._lonLat.lat)),l=this._u,h=this._b,c=this.planet.ellipsoid.cartesianToLonLat(e),_=i,u=this.planet.ellipsoid.lonLatToCartesian(new z(c.lon,c.lat,0)),f=oe.sub(e,t),g=_.cross(f);f.normalize(),g.normalize();let p=f.cross(g),m=o.getNormal(),v=u.getNormal(),y=1-m.dot(v),x=n*d*Math.sqrt(y>0?y:0),b=6639613,w=Math.max(this._lonLat.height,c.height);w>b&&(b=w);let T=w+2.5*x*(b-w),C=oe.ZERO;for(let e=0;e<=this._numFrames;e++){let t=1-e/this._numFrames;t=t*t*(3-2*t),t*=t;let i=o.smerp(u,t).normalize(),n=this.planet.getRayIntersectionEllipsoid(new _i(C,i)),r=1-t,s=this._lonLat.height*t*t*t+3*T*t*t*r+3*T*t*r*r+c.height*r*r*r,a=n.addA(i.scale(s)),d=l.smerp(p,t),_=oe.add(a,h.smerp(f,t).negateTo()),g=new oe(a.x-_.x,a.y-_.y,a.z-_.z),m=d.cross(g);g.normalize(),m.normalize();let v=g.cross(m);this._framesArr[e]={eye:a,n:g,u:m,v:v}}this._framesCounter=this._numFrames,this._flying=!0}flyLonLat(e,t,i,n,r,s,a){let o=new z(e.lon,e.lat,e.height||this._lonLat.height);this.flyCartesian(this.planet.ellipsoid.lonLatToCartesian(o),t,i,n,r,s,a)}stopFlying(){this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet.normalMapCreator.free(this._keyLock),this._flying=!1,this._framesArr.length=0,this._framesArr=[],this._framesCounter=-1,this._frameCallback=null}isFlying(){return this._flying}rotateLeft(e,t){this.rotateHorizontal(e*o,!0!==t,oe.ZERO),this.update()}rotateRight(e,t){this.rotateHorizontal(-e*o,!0!==t,oe.ZERO),this.update()}rotateUp(e){this.rotateVertical(e*o,oe.ZERO),this.update()}rotateDown(e){this.rotateVertical(-e*o,oe.ZERO),this.update()}rotateVertical(e,t,i=0){let n=(new se).setRotation(this._r,e),r=(new se).setIdentity().translate(t),s=(new se).setIdentity().translate(t.negateTo()),a=r.mul(n).mul(s).mulVec3(this.eye),o=n.mulVec3(this._u).normalize(),l=n.mulVec3(this._r).normalize(),h=n.mulVec3(this._b).normalize(),c=a.getNormal(),d=h.dot(c);if(i){let e=d-this.slope;if(d<i&&e<0)return;(d>.1&&o.dot(c)>0||this.slope<=.1||this._u.dot(this.eye.getNormal())<=0)&&(this.eye=a,this._u=o,this._r=l,this._b=h)}else this.eye=a,this._u=o,this._r=l,this._b=h}checkFly(){if(this._flying){let e=this._numFrames-this._framesCounter;this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet.normalMapCreator.lock(this._keyLock),this.eye=this._framesArr[e].eye,this._r=this._framesArr[e].u,this._u=this._framesArr[e].v,this._b=this._framesArr[e].n,this._frameCallback&&this._frameCallback(),this.update(),this._framesCounter--,this._framesCounter<0&&(this.stopFlying(),this._completeCallback&&(this._completeCallback(),this._completeCallback=null))}}checkTerrainCollision(){if(this._terrainAltitude=this._lonLat.height,this._insideSegment&&this._insideSegment.planet)return this._terrainAltitude=this._insideSegment.getTerrainPoint(this.eye,this._insideSegment.getInsideLonLat(this),this._terrainPoint),this._terrainAltitude<this.minAltitude&&this._checkTerrainCollision&&this.setAltitude(this.minAltitude),this._terrainPoint}getSurfaceVisibleDistance(e){let t=this.planet.ellipsoid.equatorialSize;return t*Math.acos(t/(t+this._lonLat.height+e))}getHeading(){let e=this.eye.getNormal(),t=oe.proj_b_to_plane(this.slope>=.97?this.getUp():this.getForward(),e).normalize(),i=oe.proj_b_to_plane(oe.NORTH,e).normalize(),n=Math.sign(e.dot(t.cross(i)))*Math.acos(t.dot(i))*l;return n<0?360+n:n}isVisible(e){let t=this.eye.length();return this.eye.distance(e)<Math.sqrt(t*t-this.planet.ellipsoid.equatorialSizeSqr)}}class Oa extends Jt{constructor(e=2){super(e,Va)}_onMessage(e){this._source.get(e.data.id).segment._terrainWorkerCallback(e.data),this._source.delete(e.data.id),e.data.normalMapNormals=null,e.data.normalMapVertices=null,e.data.normalMapVerticesHigh=null,e.data.normalMapVerticesLow=null,e.data.terrainVertices=null,e.data.terrainVerticesHigh=null,e.data.terrainVerticesLow=null}make(e){if(e.segment.plainReady&&e.segment.terrainIsLoading)if(this._workerQueue.length){const t=this._workerQueue.pop();this._source.set(this._sourceId,e);let i=e.segment;t.postMessage({elevations:e.elevations,this_plainVertices:i.plainVertices,this_plainNormals:i.plainNormals,this_normalMapVertices:i.normalMapVertices,this_normalMapNormals:i.normalMapNormals,heightFactor:i.planet._heightFactor,gridSize:i.planet.terrain.gridSizeByZoom[i.tileZoom],noDataValues:i.planet.terrain.noDataValues,id:this._sourceId},[e.elevations.buffer,i.plainVertices.buffer,i.plainNormals.buffer,i.normalMapVertices.buffer,i.normalMapNormals.buffer]),this._sourceId++}else this._pendingQueue.push(e);else this.check()}}const Va="'use strict';\n //\n //Terrain worker\n //\n\n function binarySearchFast(arr, x) {\n let start = 0,\n end = arr.length - 1;\n while (start <= end) {\n let k = Math.floor((start + end) * 0.5); \n if (Math.abs(arr[k] - x) < 1e-3)\n return k;\n else if (arr[k] < x)\n start = k + 1;\n else\n end = k - 1;\n }\n return -1;\n };\n\n function checkNoDataValue(noDataValues, value) {\n return binarySearchFast(noDataValues, value) !== -1;\n };\n\n\n var Vec3 = function(x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n };\n\n var doubleToTwoFloats = function(v, high, low) {\n\n let x = v.x, y = v.y, z = v.z;\n \n if (x >= 0.0) {\n var doubleHigh = Math.floor(x / 65536.0) * 65536.0;\n high.x = Math.fround(doubleHigh);\n low.x = Math.fround(x - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-x / 65536.0) * 65536.0;\n high.x = Math.fround(-doubleHigh);\n low.x = Math.fround(x + doubleHigh);\n }\n\n if (y >= 0.0) {\n var doubleHigh = Math.floor(y / 65536.0) * 65536.0;\n high.y = Math.fround(doubleHigh);\n low.y = Math.fround(y - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-y / 65536.0) * 65536.0;\n high.y = Math.fround(-doubleHigh);\n low.y = Math.fround(y + doubleHigh);\n }\n\n if (z >= 0.0) {\n var doubleHigh = Math.floor(z / 65536.0) * 65536.0;\n high.z = Math.fround(doubleHigh);\n low.z = Math.fround(z - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-z / 65536.0) * 65536.0;\n high.z = Math.fround(-doubleHigh);\n low.z = Math.fround(z + doubleHigh);\n }\n };\n\n Vec3.prototype.sub = function(v) {\n return new Vec3(this.x - v.x, this.y - v.y, this.z - v.z);\n };\n\n Vec3.prototype.add = function(v) {\n return new Vec3(this.x + v.x, this.y + v.y, this.z + v.z);\n };\n\n Vec3.prototype.cross = function(v) {\n return new Vec3(\n this.y * v.z - this.z * v.y,\n this.z * v.x - this.x * v.z,\n this.x * v.y - this.y * v.x\n );\n };\n\n Vec3.prototype.normalize = function(v) {\n var x = this.x, y = this.y, z = this.z;\n var length = 1.0 / Math.sqrt(x * x + y * y + z * z);\n this.x = x * length;\n this.y = y * length;\n this.z = z * length;\n return this;\n };\n\n Vec3.prototype.distance = function(v) {\n return this.sub(v).length();\n };\n\n Vec3.prototype.length = function () {\n return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);\n };\n\n var blerp = function(x, y, fQ11, fQ21, fQ12, fQ22) {\n return (fQ11 * (1.0 - x) * (1.0 - y) + fQ21 * x * (1.0 - y) + fQ12 * (1.0 - x) * y + fQ22 * x * y);\n };\n \n var slice = function (t, h1, h0) {\n return t * (h1 - h0);\n };\n\n var _tempVec = new Vec3(0.0, 0.0, 0.0);\n\n var _tempHigh = new Vec3(0.0, 0.0, 0.0),\n _tempLow = new Vec3(0.0, 0.0, 0.0);\n\n self.onmessage = function (e) {\n var elevations = e.data.elevations,\n this_plainVertices = e.data.this_plainVertices,\n this_plainNormals = e.data.this_plainNormals,\n this_normalMapVertices = e.data.this_normalMapVertices,\n this_normalMapNormals = e.data.this_normalMapNormals,\n heightFactor = e.data.heightFactor,\n gridSize = e.data.gridSize,\n noDataValues = e.data.noDataValues,\n id = e.data.id;\n \n var xmin = 549755748352.0, xmax = -549755748352.0, \n ymin = 549755748352.0, ymax = -549755748352.0, \n zmin = 549755748352.0, zmax = -549755748352.0;\n\n const fileGridSize = Math.sqrt(elevations.length) - 1;\n\n const fileGridSize_one = fileGridSize + 1;\n const fileGridSize_one_x2 = fileGridSize_one * fileGridSize_one;\n const tgs = gridSize;\n const dg = fileGridSize / tgs;\n const gs = tgs + 1;\n const hf = heightFactor;\n\n var nmvInd = 0,\n vInd = 0,\n noDataInd = 0;\n\n var gsgs3 = gs * gs * 3;\n\n var terrainVertices = new Float64Array(gsgs3),\n terrainVerticesHigh = new Float32Array(gsgs3),\n terrainVerticesLow = new Float32Array(gsgs3),\n noDataVertices = new Uint8Array(gs * gs);\n\n var normalMapNormals,\n normalMapVertices,\n normalMapVerticesHigh,\n normalMapVerticesLow;\n\n var nv = this_normalMapVertices,\n nn = this_normalMapNormals;\n\n if (fileGridSize >= tgs) {\n\n normalMapNormals = new Float32Array(fileGridSize_one_x2 * 3);\n normalMapVertices = new Float64Array(fileGridSize_one_x2 * 3);\n normalMapVerticesHigh = new Float32Array(fileGridSize_one_x2 * 3);\n normalMapVerticesLow = new Float32Array(fileGridSize_one_x2 * 3);\n\n for (let k = 0; k < fileGridSize_one_x2; k++) {\n\n var j = k % fileGridSize_one,\n i = ~~(k / fileGridSize_one);\n\n //\n // V0\n //\n var hInd0 = k;\n var vInd0 = hInd0 * 3;\n var currElv = elevations[hInd0];\n if(checkNoDataValue(noDataValues, currElv)) {\n currElv = 0.0;\n }\n var h0 = hf * currElv;\n var v0 = new Vec3(nv[vInd0] + h0 * nn[vInd0], nv[vInd0 + 1] + h0 * nn[vInd0 + 1], nv[vInd0 + 2] + h0 * nn[vInd0 + 2]);\n \n doubleToTwoFloats(v0, _tempHigh, _tempLow);\n\n normalMapVertices[vInd0] = v0.x;\n normalMapVertices[vInd0 + 1] = v0.y;\n normalMapVertices[vInd0 + 2] = v0.z;\n\n normalMapVerticesHigh[vInd0] = _tempHigh.x;\n normalMapVerticesHigh[vInd0 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd0 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd0] = _tempLow.x;\n normalMapVerticesLow[vInd0 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd0 + 2] = _tempLow.z;\n\n //\n // The vertex goes into screen buffer\n if (i % dg === 0 && j % dg === 0) {\n\n let currVert = new Vec3(nv[vInd0], nv[vInd0 + 1], nv[vInd0 + 2]);\n let nextVert = new Vec3(nv[vInd0 + 3], nv[vInd0 + 4], nv[vInd0 + 5]);\n\n let nextElv = elevations[hInd0 + 1];\n if(checkNoDataValue(noDataValues, nextElv)) {\n nextElv = 0.0;\n }\n \n let eps = false;\n if(noDataValues.length === 0){\n let step = currVert.distance(nextVert);\n let deltaElv = Math.abs(currElv - nextElv);\n eps = ((deltaElv / step) > 10.0) || (currElv < -5000);\n }\n\n if(eps){\n noDataVertices[noDataInd] = 1;\n } else {\n noDataVertices[noDataInd] = 0;\n if (v0.x < xmin) xmin = v0.x; if (v0.x > xmax) xmax = v0.x;\n if (v0.y < ymin) ymin = v0.y; if (v0.y > ymax) ymax = v0.y;\n if (v0.z < zmin) zmin = v0.z; if (v0.z > zmax) zmax = v0.z;\n }\n\n terrainVerticesHigh[vInd] = _tempHigh.x;\n terrainVerticesLow[vInd] = _tempLow.x;\n terrainVertices[vInd++] = v0.x;\n\n terrainVerticesHigh[vInd] = _tempHigh.y;\n terrainVerticesLow[vInd] = _tempLow.y;\n terrainVertices[vInd++] = v0.y;\n\n terrainVerticesHigh[vInd] = _tempHigh.z;\n terrainVerticesLow[vInd] = _tempLow.z;\n terrainVertices[vInd++] = v0.z;\n\n noDataInd++;\n }\n\n if (i !== fileGridSize && j !== fileGridSize) {\n\n //\n // V1\n //\n var hInd1 = k + 1;\n var vInd1 = hInd1 * 3;\n var elv = elevations[hInd1];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h1 = hf * elv;\n var v1 = new Vec3(nv[vInd1] + h1 * nn[vInd1], nv[vInd1 + 1] + h1 * nn[vInd1 + 1], nv[vInd1 + 2] + h1 * nn[vInd1 + 2]);\n\n doubleToTwoFloats(v1, _tempHigh, _tempLow);\n\n normalMapVertices[vInd1] = v1.x;\n normalMapVertices[vInd1 + 1] = v1.y;\n normalMapVertices[vInd1 + 2] = v1.z;\n\n normalMapVerticesHigh[vInd1] = _tempHigh.x;\n normalMapVerticesHigh[vInd1 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd1 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd1] = _tempLow.x;\n normalMapVerticesLow[vInd1 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd1 + 2] = _tempLow.z;\n\n //\n // V2\n //\n var hInd2 = k + fileGridSize_one;\n var vInd2 = hInd2 * 3;\n var elv = elevations[hInd2];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h2 = hf * elv;\n var v2 = new Vec3(nv[vInd2] + h2 * nn[vInd2], nv[vInd2 + 1] + h2 * nn[vInd2 + 1], nv[vInd2 + 2] + h2 * nn[vInd2 + 2]);\n\n doubleToTwoFloats(v2, _tempHigh, _tempLow);\n\n normalMapVertices[vInd2] = v2.x;\n normalMapVertices[vInd2 + 1] = v2.y;\n normalMapVertices[vInd2 + 2] = v2.z;\n\n normalMapVerticesHigh[vInd2] = _tempHigh.x;\n normalMapVerticesHigh[vInd2 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd2 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd2] = _tempLow.x;\n normalMapVerticesLow[vInd2 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd2 + 2] = _tempLow.z;\n\n //\n // V3\n //\n var hInd3 = k + fileGridSize_one + 1;\n var vInd3 = hInd3 * 3;\n var elv = elevations[hInd3];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h3 = hf * elv;\n var v3 = new Vec3(nv[vInd3] + h3 * nn[vInd3], nv[vInd3 + 1] + h3 * nn[vInd3 + 1], nv[vInd3 + 2] + h3 * nn[vInd3 + 2]);\n\n doubleToTwoFloats(v3, _tempHigh, _tempLow);\n\n normalMapVertices[vInd3] = v3.x;\n normalMapVertices[vInd3 + 1] = v3.y;\n normalMapVertices[vInd3 + 2] = v3.z;\n\n normalMapVerticesHigh[vInd3] = _tempHigh.x;\n normalMapVerticesHigh[vInd3 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd3 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd3] = _tempLow.x;\n normalMapVerticesLow[vInd3 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd3 + 2] = _tempLow.z;\n\n //\n // Normal\n //\n var e10 = v1.sub(v0),\n e20 = v2.sub(v0),\n e30 = v3.sub(v0);\n var sw = e20.cross(e30).normalize();\n var ne = e30.cross(e10).normalize();\n var n0 = ne.add(sw).normalize();\n\n normalMapNormals[vInd0] += n0.x;\n normalMapNormals[vInd0 + 1] += n0.y;\n normalMapNormals[vInd0 + 2] += n0.z;\n\n normalMapNormals[vInd1] += ne.x;\n normalMapNormals[vInd1 + 1] += ne.y;\n normalMapNormals[vInd1 + 2] += ne.z;\n\n normalMapNormals[vInd2] += sw.x;\n normalMapNormals[vInd2 + 1] += sw.y;\n normalMapNormals[vInd2 + 2] += sw.z;\n\n normalMapNormals[vInd3] += n0.x;\n normalMapNormals[vInd3 + 1] += n0.y;\n normalMapNormals[vInd3 + 2] += n0.z;\n }\n }\n\n } else {\n\n normalMapNormals = new Float32Array(gsgs3);\n normalMapVertices = new Float64Array(gsgs3);\n normalMapVerticesHigh = new Float32Array(gsgs3);\n normalMapVerticesLow = new Float32Array(gsgs3);\n normalMapNormals = new Float32Array(gsgs3);\n\n var oneSize = tgs / fileGridSize;\n var h, inside_i, inside_j, v_i, v_j;\n var gsgs = gsgs3 / 3;\n var fgsOne = fileGridSize + 1;\n\n for(let i = 0; i < gsgs; i++) {\n let ii = Math.floor(i / gs),\n ij = i % gs;\n \n let qii = ii % oneSize,\n qij = ij % oneSize;\n\n let hlt_ind = Math.floor(ii / oneSize) * fgsOne + Math.floor(ij / oneSize);\n\n if (ij === tgs) {\n hlt_ind -= 1;\n qij = oneSize;\n }\n\n if (ii === tgs) {\n hlt_ind -= fgsOne;\n qii = oneSize;\n }\n\n let hrt_ind = hlt_ind + 1,\n hlb_ind = hlt_ind + fgsOne,\n hrb_ind = hlb_ind + 1;\n\n let h_lt = elevations[hlt_ind],\n h_rt = elevations[hrt_ind],\n h_lb = elevations[hlb_ind],\n h_rb = elevations[hrb_ind];\n\n if(checkNoDataValue(noDataValues, h_lt)) {\n h_lt = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_rt)) {\n h_rt = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_lb)) {\n h_lb = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_rb)) {\n h_rb = 0.0;\n }\n\n let hi = blerp(qij / oneSize, qii / oneSize, h_lt, h_rt, h_lb, h_rb);\n\n let i3 = i * 3;\n\n _tempVec.x = this_plainVertices[i3] + hi * this_plainNormals[i3],\n _tempVec.y = this_plainVertices[i3 + 1] + hi * this_plainNormals[i3 + 1],\n _tempVec.z = this_plainVertices[i3 + 2] + hi * this_plainNormals[i3 + 2];\n\n doubleToTwoFloats(_tempVec, _tempHigh, _tempLow);\n\n terrainVertices[i3] = _tempVec.x;\n terrainVertices[i3 + 1] = _tempVec.y;\n terrainVertices[i3 + 2] = _tempVec.z;\n\n terrainVerticesHigh[i3] = _tempHigh.x;\n terrainVerticesHigh[i3 + 1] = _tempHigh.y;\n terrainVerticesHigh[i3 + 2] = _tempHigh.z;\n\n terrainVerticesLow[i3] = _tempLow.x;\n terrainVerticesLow[i3 + 1] = _tempLow.y;\n terrainVerticesLow[i3 + 2] = _tempLow.z;\n\n if (_tempVec.x < xmin) xmin = _tempVec.x; if (_tempVec.x > xmax) xmax = _tempVec.x;\n if (_tempVec.y < ymin) ymin = _tempVec.y; if (_tempVec.y > ymax) ymax = _tempVec.y;\n if (_tempVec.z < zmin) zmin = _tempVec.z; if (_tempVec.z > zmax) zmax = _tempVec.z;\n }\n\n normalMapVertices.set(terrainVertices);\n normalMapVerticesHigh.set(terrainVerticesHigh);\n normalMapVerticesLow.set(terrainVerticesLow);\n\n for (let k = 0; k < gsgs; k++) {\n\n var j = k % gs,\n i = ~~(k / gs);\n\n if (i !== tgs && j !== tgs) {\n var v0ind = k * 3,\n v1ind = v0ind + 3,\n v2ind = v0ind + gs * 3,\n v3ind = v2ind + 3;\n\n\n var v0 = new Vec3(terrainVertices[v0ind], terrainVertices[v0ind + 1], terrainVertices[v0ind + 2]),\n v1 = new Vec3(terrainVertices[v1ind], terrainVertices[v1ind + 1], terrainVertices[v1ind + 2]),\n v2 = new Vec3(terrainVertices[v2ind], terrainVertices[v2ind + 1], terrainVertices[v2ind + 2]),\n v3 = new Vec3(terrainVertices[v3ind], terrainVertices[v3ind + 1], terrainVertices[v3ind + 2]);\n\n var e10 = v1.sub(v0).normalize(),\n e20 = v2.sub(v0).normalize(),\n e30 = v3.sub(v0).normalize();\n\n var sw = e20.cross(e30).normalize();\n var ne = e30.cross(e10).normalize();\n var n0 = ne.add(sw).normalize();\n\n normalMapNormals[v0ind] += n0.x;\n normalMapNormals[v0ind + 1] += n0.y;\n normalMapNormals[v0ind + 2] += n0.z;\n\n normalMapNormals[v1ind] += ne.x;\n normalMapNormals[v1ind + 1] += ne.y;\n normalMapNormals[v1ind + 2] += ne.z;\n\n normalMapNormals[v2ind] += sw.x;\n normalMapNormals[v2ind + 1] += sw.y;\n normalMapNormals[v2ind + 2] += sw.z;\n\n normalMapNormals[v3ind] += n0.x;\n normalMapNormals[v3ind + 1] += n0.y;\n normalMapNormals[v3ind + 2] += n0.z;\n }\n }\n }\n\n self.postMessage({\n id: id,\n normalMapNormals: normalMapNormals,\n normalMapVertices: normalMapVertices,\n normalMapVerticesHigh: normalMapVerticesHigh,\n normalMapVerticesLow: normalMapVerticesLow,\n terrainVertices: terrainVertices,\n terrainVerticesHigh: terrainVerticesHigh,\n terrainVerticesLow: terrainVerticesLow,\n noDataVertices: noDataVertices,\n //bounds: [xmin, xmax, ymin, ymax, zmin, zmax]\n bounds: [xmin, ymin, zmin, xmax, ymax, zmax]\n }, [\n normalMapNormals.buffer, \n normalMapVertices.buffer, \n normalMapVerticesHigh.buffer, \n normalMapVerticesLow.buffer, \n terrainVertices.buffer,\n terrainVerticesHigh.buffer,\n terrainVerticesLow.buffer,\n noDataVertices.buffer\n ]);\n }";let Ua=new Float32Array(2);class Ga{constructor(e,t=512,i=512){this._width=t,this._height=i,this._planet=e,this._framebuffer=null,this._queue=[],this._handler=null}init(){this._handler=this._planet.renderer.handler,this._handler.programs.vectorTileLineRasterization||this._handler.addProgram(new zi("vectorTileLineRasterization",{uniforms:{viewport:"vec2",thicknessOutline:"float",alpha:"float",extentParamsHigh:"vec4",extentParamsLow:"vec4"},attributes:{prevHigh:"vec2",currentHigh:"vec2",nextHigh:"vec2",prevLow:"vec2",currentLow:"vec2",nextLow:"vec2",order:"float",color:"vec4",thickness:"float"},vertexShader:"attribute vec2 prevHigh;\n attribute vec2 currentHigh;\n attribute vec2 nextHigh;\n\n attribute vec2 prevLow;\n attribute vec2 currentLow;\n attribute vec2 nextLow;\n\n attribute float order;\n attribute float thickness;\n attribute vec4 color;\n uniform float thicknessOutline;\n uniform vec2 viewport;\n uniform vec4 extentParamsHigh;\n uniform vec4 extentParamsLow;\n varying vec4 vColor;\n \n vec2 proj(vec2 coordHigh, vec2 coordLow) {\n vec2 highDiff = coordHigh - extentParamsHigh.xy;\n vec2 lowDiff = coordLow - extentParamsLow.xy; \n return vec2(-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0);\n }\n \n void main(){\n vColor = color;\n\n vec2 vNext = proj(nextHigh, nextLow),\n vCurrent = proj(currentHigh, currentLow),\n vPrev = proj(prevHigh, prevLow);\n\n vec2 _next = vNext;\n vec2 _prev = vPrev;\n vec2 _current = vCurrent;\n\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n\n vec2 sNext = _next;\n vec2 sCurrent = _current;\n vec2 sPrev = _prev;\n \n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n \n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n vec2 d = (thickness + thicknessOutline) * 0.5 * sign(order) / viewport;\n \n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n vec2 dir = normalPrev + normalNext;\n m = sCurrent + dir * d / (dirNext.x * dir.y - dirNext.y * dir.x);\n \n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n gl_Position = vec4(m.x, m.y, 0.0, 1.0);\n }",fragmentShader:"precision highp float;\n uniform float alpha;\n varying vec4 vColor;\n void main() {\n gl_FragColor = vec4(vColor.rgb, alpha * vColor.a);\n }"})),this._handler.programs.vectorTilePolygonRasterization||this._handler.addProgram(new zi("vectorTilePolygonRasterization",{uniforms:{extentParamsHigh:"vec4",extentParamsLow:"vec4"},attributes:{coordinatesHigh:"vec2",coordinatesLow:"vec2",colors:"vec4"},vertexShader:"attribute vec2 coordinatesHigh;\n attribute vec2 coordinatesLow; \n attribute vec4 colors; \n uniform vec4 extentParamsHigh; \n uniform vec4 extentParamsLow; \n varying vec4 color;\n\n vec2 proj(vec2 coordHigh, vec2 coordLow) {\n vec2 highDiff = coordHigh - extentParamsHigh.xy;\n vec2 lowDiff = coordLow - extentParamsLow.xy;\n return vec2(-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0);\n }\n\n void main() { \n color = colors;\n gl_Position = vec4(proj(coordinatesHigh, coordinatesLow), 0.0, 1.0); \n }",fragmentShader:"precision highp float;\n varying vec4 color;\n void main () { \n gl_FragColor = color; \n }"})),this._framebuffer=new qs(this._handler,{width:this._width,height:this._height,useDepth:!1}),this._framebuffer.init()}frame(){if(this._planet.layerLock.isFree()&&this._queue.length){let e=this._handler,t=e.gl;t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST);let i=e.programs.vectorTileLineRasterization,n=e.programs.vectorTilePolygonRasterization,r=this._width,s=this._height,a=r,o=s,l=a<<1,h=o<<1,c=new Float32Array(4),d=new Float32Array(4),_=this._framebuffer.activate(),u=0,f=window.performance.now();for(;this._queue.length&&u<25;){let g=this._queue.shift();if(g.isLoading&&1===g.segment.node.getState()){let u=g.layer._pickingEnabled;g.segment.tileZoom<4?(a=l,o=h):(a=r,o=s);let f=g._updateTexture||e.createEmptyTexture_l(a,o),p=u?g._updatePickingMask||e.createEmptyTexture_n(a,o):null;g.applyTexture(f,p),_.setSize(a,o),_.bindOutputTexture(f),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);let m=g.segment.getExtentMerc();nn(m.southWest.lon,Ua),c[0]=Ua[0],d[0]=Ua[1],nn(m.southWest.lat,Ua),c[1]=Ua[0],d[1]=Ua[1],c[2]=2/m.getWidth(),c[3]=2/m.getHeight(),n.activate();let v=n._program,y=v.attributes,x=v.uniforms,b=g.layer._geometryHandler;t.uniform4fv(x.extentParamsHigh,c),t.uniform4fv(x.extentParamsLow,d),t.bindBuffer(t.ARRAY_BUFFER,b._polyVerticesHighBufferMerc),t.vertexAttribPointer(y.coordinatesHigh,b._polyVerticesHighBufferMerc.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._polyVerticesLowBufferMerc),t.vertexAttribPointer(y.coordinatesLow,b._polyVerticesLowBufferMerc.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._polyColorsBuffer),t.vertexAttribPointer(y.colors,b._polyColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,b._polyIndexesBuffer),t.drawElements(t.TRIANGLES,b._polyIndexesBuffer.numItems,t.UNSIGNED_INT,0),u&&(_.bindOutputTexture(p),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindBuffer(t.ARRAY_BUFFER,b._polyPickingColorsBuffer),t.vertexAttribPointer(y.colors,b._polyPickingColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.drawElements(t.TRIANGLES,b._polyIndexesBuffer.numItems,t.UNSIGNED_INT,0)),_.bindOutputTexture(f),i.activate(),v=i._program,y=v.attributes,x=v.uniforms,t.uniform2fv(x.viewport,[a,o]),t.uniform4fv(x.extentParamsHigh,c),t.uniform4fv(x.extentParamsLow,d);let w=b._lineVerticesHighBufferMerc;t.bindBuffer(t.ARRAY_BUFFER,w),t.vertexAttribPointer(y.prevHigh,w.itemSize,t.FLOAT,!1,8,0),t.vertexAttribPointer(y.currentHigh,w.itemSize,t.FLOAT,!1,8,32),t.vertexAttribPointer(y.nextHigh,w.itemSize,t.FLOAT,!1,8,64),w=b._lineVerticesLowBufferMerc,t.bindBuffer(t.ARRAY_BUFFER,w),t.vertexAttribPointer(y.prevLow,w.itemSize,t.FLOAT,!1,8,0),t.vertexAttribPointer(y.currentLow,w.itemSize,t.FLOAT,!1,8,32),t.vertexAttribPointer(y.nextLow,w.itemSize,t.FLOAT,!1,8,64),t.bindBuffer(t.ARRAY_BUFFER,b._lineOrdersBuffer),t.vertexAttribPointer(y.order,b._lineOrdersBuffer.itemSize,t.FLOAT,!1,4,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,b._lineIndexesBuffer),t.bindBuffer(t.ARRAY_BUFFER,b._lineStrokesBuffer),t.vertexAttribPointer(y.thickness,b._lineStrokesBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineStrokeColorsBuffer),t.vertexAttribPointer(y.color,b._lineStrokeColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(x.thicknessOutline,2),t.uniform1f(x.alpha,.54),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.uniform1f(x.thicknessOutline,1),t.uniform1f(x.alpha,1),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineThicknessBuffer),t.vertexAttribPointer(y.thickness,b._lineThicknessBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineColorsBuffer),t.vertexAttribPointer(y.color,b._lineColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(x.thicknessOutline,2),t.uniform1f(x.alpha,.54),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.uniform1f(x.thicknessOutline,1),t.uniform1f(x.alpha,1),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),u&&(_.bindOutputTexture(p),t.uniform1f(x.thicknessOutline,8),t.bindBuffer(t.ARRAY_BUFFER,b._linePickingColorsBuffer),t.vertexAttribPointer(y.color,b._linePickingColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0))}else g.isLoading=!1;u=window.performance.now()-f}t.enable(t.DEPTH_TEST),t.enable(t.CULL_FACE),_.deactivate()}}add(e){this._queue.push(e)}remove(e){}get queueSize(){return this._queue.length}}class Wa{constructor(e=1,t=1){this._a=e,this._b=t,this._flattening=(e-t)/e,this._f=1/this._flattening,this._a2=e*e,this._b2=t*t;const i=Math.sqrt(this._a2-this._b2);this._e=i/e,this._e2=this._e*this._e,this._e22=this._e2*this._e2,this._k=i/t,this._k2=this._k*this._k,this._radii=new oe(e,e,t),this._radii2=new oe(this._a2,this._a2,this._b2),this._invRadii=new oe(1/e,1/e,1/t),this._invRadii2=new oe(1/this._a2,1/this._a2,1/this._b2)}rhumbDistanceTo(e,t){const i=e.lat*o,n=t.lat*o,r=n-i;let s=Math.abs(t.lon-e.lon)*o;Math.abs(s)>Math.PI&&(s=s>0?-(2*Math.PI-s):2*Math.PI+s);const a=Math.log(Math.tan(n/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),l=Math.abs(a)>1e-11?r/a:Math.cos(i);return Math.sqrt(r*r+l*l*s*s)*this._a}getIntermediatePointOnGreatCircle(e,t,i){if(0==i)return e.clone();if(1==i)return t.clone();const n=this.inverse(e,t),r=n.distance,s=n.initialAzimuth;return isNaN(s)?e:this.getGreatCircleDestination(e,s,r*i)}static getBearing(e,t){let i=e.lat*o,n=e.lon*o,r=t.lat*o,s=t.lon*o,a=Math.sin(s-n)*Math.cos(r),h=Math.cos(i)*Math.sin(r)-Math.sin(i)*Math.cos(r)*Math.cos(s-n);return Math.atan2(a,h)*l}getFlattening(){return this._flattening}getEquatorialSize(){return this._a}get equatorialSize(){return this._a}get equatorialSizeSqr(){return this._a2}getPolarSize(){return this._b}get polarSize(){return this._b}get polarSizeSqr(){return this._b2}lonLatToCartesian(e){return this.geodeticToCartesian(e.lon,e.lat,e.height)}lonLatToCartesianRes(e,t){return this.geodeticToCartesian(e.lon,e.lat,e.height,t)}geodeticToCartesian(e,t,i=0,n=new oe){let r=o*t,s=o*e,a=Math.sin(r),l=this._a/Math.sqrt(1-this._e2*a*a),h=(l+i)*Math.cos(r);return n.x=h*Math.cos(s),n.y=h*Math.sin(s),n.z=(l*(1-this._e2)+i)*a,n}projToSurface(e){let t=e.x||0,i=e.y||0,n=e.z||0,r=Math.sqrt(t*t+i*i+n*n);if(0===r)return this.lonLatToCartesian(new z);let s=this._invRadii2.x,a=this._invRadii2.y,o=this._invRadii2.z,l=t*t*s,h=i*i*a,c=n*n*o,d=l+h+c,_=Math.sqrt(1/d),u=e.scaleTo(_);if(d<.1)return Number.isFinite(_)?u:new oe;let g=(1-_)*r/u.mulA(this._invRadii2).length(),p=0,m=0,v=0;for(;;){p=1/(1+g*s),m=1/(1+g*a),v=1/(1+g*o);let e=p*p,t=m*m,i=v*v,n=l*e+h*t+c*i-1;if(Math.abs(n)<f)break;g+=.5*n/(l*(e*p)*s+h*(t*m)*a+c*(i*v)*o)}return new oe(t*p,i*m,n*v)}cartesianToLonLat(e){return this.cartesianToLonLatRes(e)}cartesianToLonLatRes(e,t=new z){let i=this.projToSurface(e),n=this.getSurfaceNormal3v(i),r=e.sub(i);return t.lon=Math.atan2(n.y,n.x)*l,t.lat=Math.asin(n.z)*l,t.height=Math.sign(r.dot(e))*r.length(),t}getSurfaceNormal3v(e){let t=this._invRadii2,i=e.x*t.x,n=e.y*t.y,r=e.z*t.z,s=1/Math.sqrt(i*i+n*n+r*r);return new oe(i*s,n*s,r*s)}getGreatCircleDistance(e,t){return this.inverse(e,t).distance}getGreatCircleDestination(e,t,i){return this.direct(e,t,i).destination}inverse(e,t){let i=this._a,n=this._b,r=this._flattening;const s=e.lat*o,a=e.lon*o,h=t.lat*o,c=t.lon*o-a,d=(1-r)*Math.tan(s),_=1/Math.sqrt(1+d*d),u=d*_,g=(1-r)*Math.tan(h),p=1/Math.sqrt(1+g*g),m=g*p,v=Math.abs(c)>Math.PI/2||Math.abs(h-s)>Math.PI/2;let y=c,x=null,w=null,T=v?Math.PI:0,C=0,L=v?-1:1,A=null,E=1,P=1,M=null,S=0;do{if(x=Math.sin(y),w=Math.cos(y),A=(p*x)**2+(_*m-u*p*w)**2,Math.abs(A)<1e-24)break;C=Math.sqrt(A),L=u*m+_*p*w,T=Math.atan2(C,L);const e=_*p*x/C;P=1-e*e,E=0!=P?L-2*u*m/P:0;const t=r/16*P*(4+r*(4-3*P));M=y,y=c+(1-t)*r*e*(T+t*C*(E+t*L*(2*E*E-1)))}while(Math.abs(y-M)>f&&++S<1e3);const B=P*(i*i-n*n)/(n*n),k=B/1024*(256+B*(B*(74-47*B)-128)),R=n*(1+B/16384*(4096+B*(B*(320-175*B)-768)))*(T-k*C*(E+k/4*(L*(2*E*E-1)-k/6*E*(4*C*C-3)*(4*E*E-3)))),I=Math.abs(A)<Number.EPSILON?0:Math.atan2(p*x,_*m-u*p*w),z=Math.abs(A)<Number.EPSILON?Math.PI:Math.atan2(_*x,-u*p+_*m*w);return{distance:R,initialAzimuth:Math.abs(R)<Number.EPSILON?NaN:b(I)*l,finalAzimuth:Math.abs(R)<Number.EPSILON?NaN:b(z)*l}}direct(e,t,i){let n=e.lon,r=e.lat,s=this._a,a=this._b,h=this._flattening,c=i,d=t*o,_=Math.sin(d),u=Math.cos(d),f=(1-h)*Math.tan(r*o),g=1/Math.sqrt(1+f*f),p=f*g,m=Math.atan2(f,u),v=g*_,y=1-v*v,x=y*(s*s-a*a)/(a*a),b=1+x/16384*(4096+x*(x*(320-175*x)-768)),w=x/1024*(256+x*(x*(74-47*x)-128)),T=c/(a*b),C=2*Math.PI,L=0,A=0,E=0,P=0;for(;Math.abs(T-C)>1e-12;)L=Math.cos(2*m+T),A=Math.sin(T),E=Math.cos(T),P=w*A*(L+w/4*(E*(2*L*L-1)-w/6*L*(4*A*A-3)*(4*L*L-3))),C=T,T=c/(a*b)+P;let M=p*A-g*E*u,S=Math.atan2(p*E+g*A*u,(1-h)*Math.sqrt(v*v+M*M)),B=h/16*y*(4+h*(4-3*y)),k=Math.atan2(A*_,g*E-p*A*u)-(1-B)*h*v*(T+B*A*(L+B*E*(2*L*L-1))),R=Math.atan2(v,-M);return{destination:new z(n+k*l,S*l),finalAzimuth:R*l}}hitRay(e,t){let i,n,r,s,a,o=this._invRadii.mul(e),l=this._invRadii.mul(t),h=o.dot(o),c=o.dot(l);if(h>1){if(c>=0)return;var d=c*c;if(i=h-1,n=l.dot(l),r=n*i,Math.abs(d-r)>1e-15&&d<r)return;if(d>r){s=c*c-r,a=-c+Math.sqrt(s);var _=a/n,u=i/a;return _<u?e.add(t.scaleTo(_)):e.add(t.scaleTo(u))}var f=Math.sqrt(i/n);return e.add(t.scaleTo(f))}return h<1?(i=h-1,n=l.dot(l),r=n*i,s=c*c-r,a=-c+Math.sqrt(s),e.add(t.scaleTo(a/n))):c<0?(n=l.dot(l),e.add(t.scaleTo(-c/n))):void 0}getNorthFrameRotation(e){let t=this.getSurfaceNormal3v(e),i=oe.proj_b_to_plane(oe.NORTH,t);return ae.getLookRotation(i,t)}getBearingDestination(e,t=0,i=0){t*=o;var n=(e.lon+540)%360-180,r=e.lat*o,s=n*o,a=i/this._a,h=Math.asin(Math.sin(r)*Math.cos(a)+Math.cos(r)*Math.sin(a)*Math.cos(t));return new z((s+Math.atan2(Math.sin(t)*Math.sin(a)*Math.cos(r),Math.cos(a)-Math.sin(r)*Math.sin(h)))*l,h*l)}static getIntermediatePointOnGreatCircle(e,t,i){var n=e.lat*o,r=e.lon*o,s=t.lat*o,a=t.lon*o,h=Math.sin(n),c=Math.cos(n),d=Math.sin(r),_=Math.cos(r),u=Math.sin(s),f=Math.cos(s),g=Math.sin(a),p=Math.cos(a),m=s-n,v=a-r,y=Math.sin(m/2)*Math.sin(m/2)+Math.cos(n)*Math.cos(s)*Math.sin(v/2)*Math.sin(v/2),x=2*Math.atan2(Math.sqrt(y),Math.sqrt(1-y)),b=Math.sin((1-i)*x)/Math.sin(x),w=Math.sin(i*x)/Math.sin(x),T=b*c*_+w*f*p,C=b*c*d+w*f*g,L=b*h+w*u,A=Math.atan2(L,Math.sqrt(T*T+C*C)),E=Math.atan2(C,T);return new z((E*l+540)%360-180,A*l)}static getRhumbBearing(e,t){var i=(t.lon-e.lon)*o,n=Math.log(Math.tan(t.lat*o/2+Math.PI/4)/Math.tan(e.lat*o/2+Math.PI/4));return Math.abs(i)>Math.PI&&(i=i>0?-1*(2*Math.PI-i):2*Math.PI+i),(Math.atan2(i,n)*l+360)%360}}const ja=new Wa(6378137,6356752.314245179);let Ya=new Uint8Array(4),qa=new Uint8Array(4);class Xa extends Pi{constructor(e={}){super(e.name),this._renderingFadingNodes=(e,t,i,n,r,s)=>{let a=0===r,o=this.terrain.equalizeVertices;for(let l=0,h=i._fadingNodes.length;l<h;l++){let h=i._fadingNodes[l].segment;this._fadingNodes.has(i._fadingNodes[0].__id)&&!e.has(h.node.__id)&&(e.set(h.node.__id,!0),h._transitionOpacity<1?s.push(h):a?(o&&h.equalize(),h.readyToEngage&&h.engage(),h.screenRendering(t,n,r)):h.screenRendering(t,n,r,this.transparentTexture,!0))}},this._renderingFadingNodesNoDepth=(e,t,i,n,r)=>{let s=0===r,a=this.terrain.equalizeVertices,o=t.gl;o.disable(o.DEPTH_TEST);for(let o=0,l=i._fadingNodes.length;o<l;o++){let l=i._fadingNodes[o].segment;this._fadingNodes.has(i._fadingNodes[0].__id)&&!e.has(l.node.__id)&&(e.set(l.node.__id,!0),s?(a&&l.equalize(),l.readyToEngage&&l.engage(),l.screenRendering(t,n,r)):l.screenRendering(t,n,r,this.transparentTexture,!0))}o.enable(o.DEPTH_TEST)},this._prevNodes=new Map,this._currNodes=new Map,this.transitionTime=580,this.ellipsoid=e.ellipsoid||ja,this.lightEnabled=!0,this._planetRadius2=this.ellipsoid.getPolarSize()*this.ellipsoid.getPolarSize(),this._layers=[],this._updateLayer=!1,this.visibleTileLayers=[],this.visibleVectorLayers=[],this._visibleTileLayerSlices=[],this._frustumEntityCollections=[],this.baseLayer=null,this.terrain=null,this.camera=new Ha(this,{frustums:e.frustums,eye:new oe(25e6,0,0),look:oe.ZERO,up:oe.NORTH,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude}),this.maxEqualZoomAltitude=e.maxEqualZoomAltitude||15e6,this.minEqualZoomAltitude=e.minEqualZoomAltitude||1e4,this.minEqualZoomCameraSlope=e.minEqualZoomCameraSlope||.8,this.mousePositionOnEarth=new oe,this.emptyTexture=null,this.transparentTexture=null,this.defaultTexture=null,this.minCurrZoom=s,this.maxCurrZoom=a,this._viewExtent=new ie(new z(180,180),new z(-180,-180)),this._skipPreRender=!1,this._initialViewExtent=null,this._createdNodesCount=0,this._renderedNodes=[],this._renderedNodesInFrustum=[],this._fadingNodes=new Map,this._fadingNodesInFrustum=[],this._visibleNodes={},this._visibleNodesNorth={},this._visibleNodesSouth={},this.layerLock=new yr,this.terrainLock=new yr,this._heightFactor=1,this._indexesCache=[],this._indexesCacheToRemove=[],this._indexesCacheToRemoveCounter=0,this._textureCoordsBufferCache=[],this.quadTreeStrategy=e.quadTreeStrategyPrototype?new e.quadTreeStrategyPrototype(this):new Ea(this),this._nightTexture=null,this._specularTexture=null;let t=Pe(e.ambient,new oe(.2,.2,.3)),i=Pe(e.diffuse,new oe(1,1,1)),n=Pe(e.specular,new oe(63e-5,55e-5,32e-5)),r=e.shininess||18;this._ambient=new Float32Array([t.x,t.y,t.z]),this._diffuse=new Float32Array([i.x,i.y,i.z]),this._specular=new Float32Array([n.x,n.y,n.z,r]),this._maxGridSize=Math.log2(e.maxGridSize||256),this.SLICE_SIZE=4,this.SLICE_SIZE_4=4*this.SLICE_SIZE,this.SLICE_SIZE_3=3*this.SLICE_SIZE,this._lodSize=250,this._curLodSize=250,this._minLodSize=312,this._maxLodSize=190,this._pickingColorArr=new Float32Array(this.SLICE_SIZE_4),this._samplerArr=new Int32Array(this.SLICE_SIZE),this._pickingMaskArr=new Int32Array(this.SLICE_SIZE),this._geoImageCreator=new Ma(this),this._vectorTileCreator=new Ga(this),this._normalMapCreator=new ka(this),this._terrainWorker=new Oa(3),this._plainSegmentWorker=new Ra(3),this._tileLoader=new Ba(e.maxLoadingRequests||12),this._memKey=new xr,this.events=Pt(Za),this._distBeforeMemClear=0,this._prevCamEye=new oe,this._initialized=!1,this.always=[],this._renderCompleted=!1,this._renderCompletedActivated=!1,this._terrainCompleted=!1,this._terrainCompletedActivated=!1,this._collectRenderNodesIsActive=!0,this.nightTextureCoefficient=2,this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this._atmosphereEnabled=e.atmosphereEnabled||!1,this._atmosphereMaxMinOpacity=new Float32Array([1,.41]),this.solidTextureOne=null,this.solidTextureTwo=null,this._nightTextureSrc=e.nightTextureSrc||null,this._specularTextureSrc=e.specularTextureSrc||null,this._transitionOpacityEnabled=null==e.transitionOpacityEnabled||e.transitionOpacityEnabled}get terrainReady(){return this._terrainCompleted&&this._terrainCompletedActivated}get maxGridSize(){return this._maxGridSize}getNorthFrameRotation(e){return this.ellipsoid.getNorthFrameRotation(e)}set atmosphereMaxOpacity(e){this._atmosphereMaxMinOpacity[0]=e}get atmosphereMaxOpacity(){return this._atmosphereMaxMinOpacity[0]}set atmosphereMinOpacity(e){this._atmosphereMaxMinOpacity[1]=e}get atmosphereMinOpacity(){return this._atmosphereMaxMinOpacity[1]}set atmosphereEnabled(e){e!=this._atmosphereEnabled&&(this._atmosphereEnabled=e,this._initializeAtmosphere())}get atmosphereEnabled(){return this._atmosphereEnabled}set diffuse(e){let t=Pe(e);this._diffuse=new Float32Array(t.toArray())}set ambient(e){let t=Pe(e);this._ambient=new Float32Array(t.toArray())}set specular(e){let t=Pe(e);this._specular=new Float32Array([t.x,t.y,t.y,this._specular[3]])}set shininess(e){this._specular[3]=e}get normalMapCreator(){return this._normalMapCreator}get layers(){return[...this._layers]}getLayers(){return this.layers}get sunPos(){return this.renderer.controls.sun.sunlight.getPosition()}addControl(e){e.planet=this,e.addTo(this.renderer)}get lodSize(){return this._lodSize}setLodSize(e,t,i){this._maxLodSize=i||this._maxLodSize,this._minLodSize=t||this._minLodSize,this._curLodSize=e,this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1}addControls(e){for(let t=0;t<e.length;t++)this.addControl(e[t])}getLayerByName(e){for(let t=0,i=this._layers.length;t<i;t++)if(e===this._layers[t].name)return this._layers[t]}addLayer(e){e.addTo(this)}_onLayerVisibilityChanged(e){this.events.dispatch(this.events.layervisibilitychange,e)}addLayers(e){for(let t=0,i=e.length;t<i;t++)this.addLayer(e[t])}removeLayer(e){e.remove()}_clearLayerMaterial(e){this.quadTreeStrategy.clearLayerMaterial(e)}setBaseLayer(e){this.baseLayer?this.baseLayer.isEqual(e)||(this.baseLayer.setVisibility(!1),this.baseLayer=e,e.setVisibility(!0),this.events.dispatch(this.events.baselayerchange,e)):(this.baseLayer=e,this.baseLayer.setVisibility(!0),this.events.dispatch(this.events.baselayerchange,e))}setHeightFactor(e){this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1,this._heightFactor!==e&&(this._heightFactor=e,this.quadTreeStrategy.destroyBranches(),this._clearRenderedNodeList(),this._clearRenderNodesInFrustum())}getHeightFactor(){return this._heightFactor}setTerrain(e){this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1,this._initialized&&this.memClear(),this.terrain&&(this.terrain.abortLoading(),this.terrain.clearCache(),this.terrain._planet=null),this.terrain=e,this.terrain._planet=this,this.quadTreeStrategy.destroyBranches(),e._geoid.model?(this._plainSegmentWorker.setGeoid(e.getGeoid()),e._isReady=!0):Pa.loadModel(e.geoid.src).then((t=>{e.geoid.setModel(t),this._plainSegmentWorker.setGeoid(e.getGeoid()),e._isReady=!0})).catch((e=>{console.warn(e)}))}_initializeAtmosphere(){let e=this.renderer.handler;e.removeProgram("drawnode_screen_wl"),this._atmosphereEnabled?(this._renderScreenNodesPASS=this._renderScreenNodesPASSAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSAtmos,e.isWebGl2()?e.addProgram(new zi("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightsPositions:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",transmittanceTexture:"sampler2D",scatteringTexture:"sampler2D",camHeight:"float",nightTextureCoefficient:"float",maxMinOpacity:"vec2",transitionOpacity:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"#version 300 es\n\n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in vec3 aVertexPositionLow;\n in vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n out vec4 vTextureCoord;\n out vec3 v_vertex;\n out vec3 cameraPosition;\n out vec2 vGlobalTextureCoord;\n out float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n\n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`#version 300 es\n\n precision highp float;\n \n #define MAX_POINT_LIGHTS 1\n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient;\n\n uniform vec3 lightsPositions[MAX_POINT_LIGHTS];\n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D transmittanceTexture;\n uniform sampler2D scatteringTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient;\n \n uniform vec2 maxMinOpacity; \n uniform float camHeight;\n \n uniform float transitionOpacity;\n\n in vec4 vTextureCoord;\n in vec3 v_vertex;\n in vec3 cameraPosition;\n in vec2 vGlobalTextureCoord;\n in float v_height;\n\n vec3 sunPos;\n\n layout(location = 0) out vec4 diffuseColor;\n\n ${Vs}\n\n ${Us}\n \n ${Os} \n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture(transmittanceTexture, vec2(u, v)).xyz;\n }\n\n vec3 multipleScatteringContributionFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture(scatteringTexture, vec2(u, v)).xyz;\n }\n \n void getSunIlluminance(in vec3 point, in vec3 lightDir, out vec3 sunIlluminance)\n {\n // float r = length(point);\n // float mu_s = dot(point, sun_direction) / r;\n // float height = r - BOTTOM_RADIUS;\n \n float mu_s = dot(normalize(point), lightDir);\n float height = length(point) - BOTTOM_RADIUS;\n sunIlluminance = SUN_INTENSITY * transmittanceFromTexture(height, mu_s);\n }\n \n void atmosGroundColor(out vec4 fragColor, in vec3 normal)\n { \n vec3 rayDirection = normalize(v_vertex - cameraPosition);\n vec3 lightDir = normalize(sunPos);\n \n rayDirection = normalize(rayDirection * SPHERE_TO_ELLIPSOID_SCALE);\n vec3 camPos = cameraPosition * SPHERE_TO_ELLIPSOID_SCALE;\n lightDir = normalize(lightDir * SPHERE_TO_ELLIPSOID_SCALE);\n \n vec3 light = vec3(0.0);\n vec3 transmittanceFromCameraToSpace = vec3(1.0);\n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n intersectSphere(camPos, rayDirection, TOP_RADIUS, offset, distanceToSpace);\n \n vec3 rayOrigin = camPos;\n \n // above atmosphere\n if (offset > 0.0) \n {\n // intersection of camera ray with atmosphere\n rayOrigin += rayDirection * offset;\n }\n \n float height = length(rayOrigin) - BOTTOM_RADIUS;\n float rayAngle = dot(rayOrigin, rayDirection) / length(rayOrigin);\n bool cameraBelow = rayAngle < 0.0;\n \n transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float phaseAngle = dot(lightDir, rayDirection);\n float rayleighPhase = rayleighPhase(phaseAngle);\n float miePhase = miePhase(phaseAngle);\n \n float distanceToGround = 0.0;\n \n bool hitGround = intersectSphere(camPos, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0; \n \n // Fix black dots on the edge of atmosphere \n // if(camHeight < 700000.0 || !hitGround)\n // { \n // distanceToGround = distance(camPos, v_vertex * SPHERE_TO_ELLIPSOID_SCALE);\n // }\n \n if(length(v_vertex * SPHERE_TO_ELLIPSOID_SCALE) > BOTTOM_RADIUS){\n distanceToGround = distance(camPos, v_vertex * SPHERE_TO_ELLIPSOID_SCALE);\n }\n \n float segmentLength = (distanceToGround - max(offset, 0.0)) / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera; \n vec3 transmittanceLight; \n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDir); \n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n vec2 opticalDensity = exp(-height / rayleighMieHeights);\n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x * rayleighPhase + mieScatteringCoefficient * opticalDensity.y * miePhase);\n scatteredLight += multipleScatteringContributionFromTexture(height, lightAngle) * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y); \n light += transmittanceCamera * scatteredLight * segmentLength;\n t += segmentLength;\n }\n \n light *= SUN_INTENSITY;\n \n vec3 hitPoint = camPos + rayDirection * distanceToGround;\n vec3 up = normalize(hitPoint);\n float diffuseAngle = max(dot(up, lightDir), 0.0); \n \n float lightAngle = dot(normal, lightDir);\n vec3 tA = transmittanceCamera * GROUND_ALBEDO * SUN_INTENSITY; \n vec3 scatteringLight = multipleScatteringContributionFromTexture(height, lightAngle);\n vec3 diffuseTransmittanceLight = transmittanceLight * diffuseAngle; \n light += tA * (scatteringLight + diffuseTransmittanceLight);\n \n fragColor = vec4(pow(light * 8.0, vec3(1.0 / 2.2)), 1.0);\n }\n\n void getAtmosFadingOpacity(out float opacity)\n { \n float c = length(cameraPosition);\n float maxDist = sqrt(c * c - BOTTOM_RADIUS * BOTTOM_RADIUS);\n float minDist = c - BOTTOM_RADIUS;\n float vertDist = distance(cameraPosition, v_vertex); \n opacity = clamp(maxMinOpacity.y + ( maxMinOpacity.x - maxMinOpacity.y) * getLerpValue(minDist, maxDist, vertDist), 0.0, 1.0);\n }\n\n void main(void) {\n \n sunPos = lightsPositions[0];\n \n vec3 texNormal = texture(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n vec4 atmosColor;\n atmosGroundColor(atmosColor, normal);\n \n vec3 sunIlluminance; \n getSunIlluminance(v_vertex * SPHERE_TO_ELLIPSOID_SCALE, lightDir * SPHERE_TO_ELLIPSOID_SCALE, sunIlluminance);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = sunIlluminance * specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0);\n \n vec4 nightImageColor = texture( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + sunIlluminance * diffuse * diffuseLightWeighting + night, 1.0);\n \n float fadingOpacity;\n getAtmosFadingOpacity(fadingOpacity);\n \n getSunIlluminance(cameraPosition, viewDir * SPHERE_TO_ELLIPSOID_SCALE, sunIlluminance);\n \n spec *= sunIlluminance;\n\n diffuseColor = texture( defaultTexture, vTextureCoord.xy );\n if( samplerCount == 0 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n vec4 src;\n\n blend(diffuseColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n }`}),!0):e.addProgram(Ws(),!0),this.renderer.controls.Atmosphere?this.renderer.controls.Atmosphere.activate():this.addControl(new Xs),this.renderer.controls.SimpleSkyBackground&&this.renderer.controls.SimpleSkyBackground.deactivate()):(this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this.renderer.controls.Atmosphere&&this.renderer.controls.Atmosphere.deactivate(),this.renderer.controls.SimpleSkyBackground?this.renderer.controls.SimpleSkyBackground.activate():this.addControl(new Dr),e.isWebGl2()?e.addProgram(new zi("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightsPositions:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float",transitionOpacity:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"#version 300 es\n\n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in vec3 aVertexPositionLow;\n in vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n out vec4 vTextureCoord;\n out vec3 v_vertex;\n out vec3 cameraPosition;\n out vec2 vGlobalTextureCoord;\n out float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n \n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`#version 300 es\n\n precision highp float;\n \n #define MAX_POINT_LIGHTS 1\n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient; \n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec3 lightsPositions[MAX_POINT_LIGHTS];\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient;\n \n uniform float transitionOpacity;\n \n uniform float camHeight;\n\n in vec4 vTextureCoord;\n in vec3 v_vertex;\n in vec3 cameraPosition;\n in vec2 vGlobalTextureCoord;\n in float v_height;\n\n vec3 sunPos;\n\n layout(location = 0) out vec4 diffuseColor;\n\n ${Vs}\n\n ${Us}\n \n ${Hs}\n \n void main(void) {\n \n sunPos = lightsPositions[0];\n \n vec3 texNormal = texture(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0); \n vec4 nightImageColor = texture( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + diffuse * diffuseLightWeighting + night, 1.0);\n \n diffuseColor = texture( defaultTexture, vTextureCoord.xy );\n \n if( samplerCount == 0 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n vec4 src;\n\n blend(diffuseColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n }`}),!0):e.addProgram(Ws(),!0))}_initializeShaders(){let e=this.renderer.handler;e.addProgram(new zi("drawnode_screen_nl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",height:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"precision highp float;\n \n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec2 vTextureCoord;\n\n void main(void) {\n\n vTextureCoord = aTextureCoord;\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n mat4 m = projectionMatrix * viewMatrixRTE;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n // This is works for Mac Chrome, prevent some weird optimization I suppose\n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`precision highp float;\n #define SLICE_SIZE 5\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform float layerOpacityArr[SLICE_SIZE];\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n uniform int samplerCount;\n varying vec2 vTextureCoord;\n\n ${Gs}\n\n void main(void) {\n gl_FragColor = texture2D( defaultTexture, vTextureCoord );\n if( samplerCount == 0 ) return;\n\n vec4 src;\n\n blend(gl_FragColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) return;\n\n blend(gl_FragColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) return;\n\n blend(gl_FragColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) return;\n\n blend(gl_FragColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) return;\n\n blend(gl_FragColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n }`}),!0),e.addProgram(new zi("drawnode_colorPicking",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",samplerCount:"int",tileOffsetArr:"vec4",samplerArr:"sampler2darray",pickingMaskArr:"sampler2darray",pickingColorArr:"vec4",height:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"precision highp float;\n \n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec2 vTextureCoord;\n\n void main(void) {\n\n vTextureCoord = aTextureCoord;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n mat4 m = projectionMatrix * viewMatrixRTE;\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:"precision highp float;\n #define SLICE_SIZE 5\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec4 pickingColorArr[SLICE_SIZE];\n uniform sampler2D samplerArr[SLICE_SIZE];\n uniform sampler2D pickingMaskArr[SLICE_SIZE];\n uniform int samplerCount;\n varying vec2 vTextureCoord;\n\n #define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = texture2D(SAMPLER, tc); p = texture2D(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0 : 1.0) * COLOR.a);\n\n void main(void) {\n gl_FragColor = vec4(0.0);\n if( samplerCount == 0 ) return;\n\n vec2 tc;\n vec4 t;\n vec4 p;\n\n blendPicking(gl_FragColor, tileOffsetArr[0], samplerArr[0], pickingMaskArr[0], pickingColorArr[0], 1.0);\n if( samplerCount == 1 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[1], samplerArr[1], pickingMaskArr[1], pickingColorArr[1], 1.0);\n if( samplerCount == 2 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[2], samplerArr[2], pickingMaskArr[2], pickingColorArr[2], 1.0);\n if( samplerCount == 3 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[3], samplerArr[3], pickingMaskArr[3], pickingColorArr[3], 1.0);\n if( samplerCount == 4 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[4], samplerArr[4], pickingMaskArr[4], pickingColorArr[4], 1.0);\n }"}),!0),e.addProgram(new zi("drawnode_depth",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3",frustumPickingColor:"vec3"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"precision highp float;\n\n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n void main(void) {\n\n // @hack\n // This code is works for Mac Chrome and Safari\n // any other code probably will produce jittering\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n mat4 m = projectionMatrix * viewMatrixRTE;\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n vec3 eyePosition = eyePositionHigh + eyePositionLow;\n vec3 vertexPosition = aVertexPositionHigh + aVertexPositionLow;\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0); \n }",fragmentShader:"precision highp float;\n uniform vec3 frustumPickingColor;\n\n void main(void) {\n gl_FragColor = vec4(frustumPickingColor, 1.0);\n } "}),!0),e.addProgram(new zi("drawnode_heightPicking",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"precision highp float;\n\n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec3 eyePosition;\n varying vec3 vertexPosition;\n\n void main(void) {\n\n // This code is works for Mac Chrome and Safari\n // any other code probably will produce jittering\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n mat4 m = projectionMatrix * viewMatrixRTE;\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n eyePosition = eyePositionHigh + eyePositionLow;\n vertexPosition = aVertexPositionHigh + aVertexPositionLow;\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0); \n }",fragmentShader:"precision highp float;\n\n varying vec3 eyePosition;\n varying vec3 vertexPosition;\n\n vec3 encode24(highp float f) {\n float F = abs(f);\n float s = step( 0.0, -f );\n float e = floor( log2(F) );\n float m = exp2(- e) * F;\n e = floor( log2(F) + 127.0 ) + floor( log2(m) );\n return vec3(\n ( 128.0 * s + floor( e * exp2(-1.0) ) ) / 255.0,\n ( 128.0 * mod( e, 2.0 ) + mod( floor( m * 128.0 ), 128.0 ) ) / 255.0,\n floor( mod( floor( m * exp2( 23.0 - 8.0) ), exp2(8.0) ) ) / 255.0);\n }\n\n void main(void) {\n float range = distance(eyePosition, vertexPosition);\n gl_FragColor = vec4(encode24(range), 1.0);\n }"}),!0),this.renderer.addPickingCallback(this,this._renderColorPickingFramebufferPASS),this.renderer.addDepthCallback(this,this._renderDepthFramebufferPASS),this.renderer.addDistanceCallback(this,this._renderDistanceFramebufferPASS)}_onLayerLoadend(e){this.events.dispatch(this.events.layerloadend,e)}init(){this._tileLoader.events.on("layerloadend",this._onLayerLoadend,this),Ns().setMaxGridSize(this._maxGridSize);const e=this._maxGridSize;let t=0;for(let i=0;i<=e;i++){!this._indexesCache[i]&&(this._indexesCache[i]=new Array(e));for(let n=0;n<=e;n++){!this._indexesCache[i][n]&&(this._indexesCache[i][n]=new Array(e));for(let r=0;r<=e;r++){!this._indexesCache[i][n][r]&&(this._indexesCache[i][n][r]=new Array(e));for(let s=0;s<=e;s++){!this._indexesCache[i][n][r][s]&&(this._indexesCache[i][n][r][s]=new Array(e));for(let a=0;a<=e;a++){let e={buffer:null};if(i>=1&&i===n&&i===r&&i===s&&i===a){let t=Ns().createSegmentIndexes(i,[n,r,s,a]);e.buffer=this.renderer.handler.createElementArrayBuffer(t,1)}else this._indexesCacheToRemove[t++]=e;this._indexesCache[i][n][r][s][a]=e}}}}}this.renderer.events.on("resize",(()=>{this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1})),this.renderer.events.on("drawtransparent",(()=>{this._renderScreenNodesWithHeightPASS()})),this._textureCoordsBufferCache=[];let i=Ns().initTextureCoordsTable(e+1);for(let t=0;t<=e;t++)this._textureCoordsBufferCache[t]=this.renderer.handler.createArrayBuffer(i[t],2,(1+(1<<t))*(1+(1<<t)));this.renderer.handler.createDefaultTexture(null,(e=>{this.solidTextureOne=e,this.solidTextureTwo=e})),this.transparentTexture=this.renderer.handler.transparentTexture,this._renderedNodesInFrustum=new Array(this.camera.frustums.length);for(let e=0,t=this._renderedNodesInFrustum.length;e<t;e++)this._renderedNodesInFrustum[e]=[];if(this.quadTreeStrategy.init(),this.drawMode=this.renderer.handler.gl.TRIANGLE_STRIP,this._initializeShaders(),this._initializeAtmosphere(),this._updateVisibleLayers(),this.renderer.addPickingCallback(this,this._frustumEntityCollectionPickingCallback),this._nightTextureSrc){let e=new Image;e.crossOrigin="Anonymous",e.onload=()=>{this._nightTexture=this.renderer.handler.createTextureDefault(e),this._nightTexture.default=!0},e.src=this._nightTextureSrc}if(this._specularTextureSrc){let e=new Image;e.crossOrigin="Anonymous",e.onload=()=>{this._specularTexture=this.renderer.handler.createTextureDefault(e),this._specularTexture.default=!0},e.src=this._specularTextureSrc}this._geoImageCreator.init(),this._vectorTileCreator.init(),this._normalMapCreator.init(),this.renderer.events.on("draw",this._globalPreDraw,this,-100),this._preRender(),this.renderer.events.on("postdraw",(()=>{this._checkRendercompleted()})),this.initLayers(),this._initialized=!0,this._initialViewExtent&&this.viewExtent(this._initialViewExtent),this.renderer.activeCamera=this.camera,this.camera.bindRenderer(this.renderer),this.camera.update()}initLayers(){let e=[...this._layers];for(let t=0;t<e.length;t++)this.removeLayer(e[t]),this.addLayer(e[t])}_clearIndexesCache(){this._indexesCacheToRemoveCounter=0;let e=this._indexesCacheToRemove,t=this.renderer.handler.gl;for(let i=0,n=e.length;i<n;i++){let n=e[i];t.deleteBuffer(n.buffer),n.buffer=null}}_preRender(){this.quadTreeStrategy.preRender(),this._preLoad()}_preLoad(){this._clearRenderedNodeList(),this._skipPreRender=!1,this.quadTreeStrategy.preLoad()}createDefaultTextures(e,t){this.renderer.handler.gl.deleteTexture(this.solidTextureOne),this.renderer.handler.gl.deleteTexture(this.solidTextureTwo),this.renderer.handler.createDefaultTexture(e,(e=>{this.solidTextureOne=e})),this.renderer.handler.createDefaultTexture(t,(e=>{this.solidTextureTwo=e}))}_getLayerAttributionHTML(e){return`<div class="og-attribution__layer">${e.getAttribution()}</div>`}updateAttributionsList(){let e="";for(let t=0,i=this._layers.length;t<i;t++){let i=this._layers[t];i.getVisibility()&&i.getAttribution().length&&(e+=this._getLayerAttributionHTML(i))}this._applyAttribution(e)}updateVisibleLayers(){this._updateLayer=!0}_updateVisibleLayers(){this.visibleTileLayers=[],this.visibleTileLayers.length=0,this.visibleVectorLayers=[],this.visibleVectorLayers.length=0;let e="";for(let t=0,i=this._layers.length;t<i;t++){let i=this._layers[t];i.getVisibility()?(i.isBaseLayer()&&(this.createDefaultTextures(i._defaultTextures[0],i._defaultTextures[1]),this.baseLayer=i),i.hasImageryTiles()&&this.visibleTileLayers.push(i),i.isVector&&this.visibleVectorLayers.push(i),i.getAttribution().length&&(e+=this._getLayerAttributionHTML(i))):i._fading&&i._fadingOpacity>0&&(i.hasImageryTiles()&&this.visibleTileLayers.push(i),i.isVector&&this.visibleVectorLayers.push(i))}this._applyAttribution(e),this._sortLayers()}_applyAttribution(e){this.renderer&&this.renderer.div&&(e.length?this.renderer.div.attributions.innerHTML!==e&&(this.renderer.div.attributions.innerHTML=e):this.renderer.div.attributions.innerHTML="")}_sortLayers(){if(this.visibleVectorLayers.sort(((e,t)=>e.getZIndex()-t.getZIndex()||e.getHeight()-t.getHeight())),this._visibleTileLayerSlices=[],this._visibleTileLayerSlices.length=0,this.visibleTileLayers.length){this.visibleTileLayers.sort(((e,t)=>e.getHeight()-t.getHeight()||e.getZIndex()-t.getZIndex()));let e=-1,t=this.visibleTileLayers[0].getHeight();for(let i=0,n=this.visibleTileLayers.length;i<n;i++)i%this.SLICE_SIZE!=0&&this.visibleTileLayers[i].getHeight()===t||(e++,this._visibleTileLayerSlices[e]=[],t=this.visibleTileLayers[i].getHeight()),this._visibleTileLayerSlices[e].push(this.visibleTileLayers[i])}}_clearRenderedNodeList(){this._renderedNodes.length=0,this._renderedNodes=[]}_clearRenderNodesInFrustum(){for(let e=0,t=this._renderedNodesInFrustum.length;e<t;e++)this._renderedNodesInFrustum[e].length=0,this._renderedNodesInFrustum[e]=[]}_collectRenderedNodesMaxZoom(e){if(e.slope>this.minEqualZoomCameraSlope&&e._lonLat.height<this.maxEqualZoomAltitude&&e._lonLat.height>this.minEqualZoomAltitude){this.minCurrZoom=this.maxCurrZoom;let t=this._renderedNodes,i=this._renderedNodesInFrustum,n=[];this._clearRenderNodesInFrustum(),this._renderedNodes=[];for(let r=0,s=t.length;r<s;r++){let s=t[r],a=s.segment.centerNormal.dot(e._b);if(s.segment.tileZoom===this.maxCurrZoom||a<.81){this._renderedNodes.push(s);let e=0,t=s.inFrustum;for(;t;)1&t&&i[e].push(s),e++,t>>=1}else n.push(s)}for(let t=0,i=n.length;t<i;t++)n[t].renderTree(e,this.maxCurrZoom,null,!1,n[t])}}set transitionOpacityEnabled(e){this._transitionOpacityEnabled=e}get transitionOpacityEnabled(){return this._transitionOpacityEnabled}_collectRenderNodes(e){if(this._lodSize=L(e.slope<0?0:e.slope,this._curLodSize,this._minLodSize),e._insideSegment=null,this._clearRenderedNodeList(),this._clearRenderNodesInFrustum(),this._viewExtent.southWest.set(180,180),this._viewExtent.northEast.set(-180,-180),this._visibleNodes={},this._visibleNodesNorth={},this._visibleNodesSouth={},this.minCurrZoom=s,this.maxCurrZoom=a,this.quadTreeStrategy.collectRenderNodes(),this._collectRenderedNodesMaxZoom(e),this._fadingNodes.clear(),this._transitionOpacityEnabled){let e=[];for(let t=0;t<this._renderedNodes.length;t++){let i=this._renderedNodes[t];if(i._collectFadingNodes(),i._refreshTransitionOpacity(),i.segment._transitionOpacity>=1)i.clearNeighbors(),i.getRenderedNodesNeighbors(e),e.push(i);else for(let t=0;t<i._fadingNodes.length;t++){let n=i._fadingNodes[t];n.segment&&n.segment._transitionOpacity>=1&&(n.clearNeighbors(),n.getRenderedNodesNeighbors(e),e.push(n))}}}}_renderScreenNodesPASSNoAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodes(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesPASSAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsAtmos(e);this._renderingScreenNodes(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSNoAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodesWithHeight(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsAtmos(e);this._renderingScreenNodesWithHeight(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_globalPreDraw(){let e=this.camera;this.renderer.__useDistanceFramebuffer__=!this.terrain.isEmpty,this._distBeforeMemClear+=this._prevCamEye.distance(e.eye),this._prevCamEye.copy(e.eye),e.checkFly(),this._createdNodesCount>200&&this._distBeforeMemClear>1e3&&(this.terrain.clearCache(),this.memClear()),this._indexesCacheToRemoveCounter>600&&this._clearIndexesCache()}preFrame(){this._updateLayer&&(this._updateLayer=!1,this._updateVisibleLayers()),this.camera.isFirstPass&&(this.camera.update(),this._skipPreRender&&this._collectRenderNodesIsActive&&this._collectRenderNodes(this.camera),this._skipPreRender=!0,this.transformLights(),this._normalMapCreator.frame(),this._geoImageCreator.frame(),this._vectorTileCreator.frame(),this.camera.checkTerrainCollision(),this.camera.update(),this.events.dispatch(this.events.draw,this),this._collectVectorLayerCollections()),this.drawEntityCollections(this._frustumEntityCollections)}frame(){this._renderScreenNodesPASS()}_checkRendercompleted(){this._renderCompleted?this._renderCompletedActivated||(this._renderCompletedActivated=!0,this.events.dispatch(this.events.rendercompleted,!0)):this._renderCompletedActivated=!1,this._renderCompleted=!0,this._terrainCompleted?this._terrainCompletedActivated||(this._terrainCompletedActivated=!0,this.events.dispatch(this.events.terraincompleted,!0)):this._terrainCompletedActivated=!1,this._terrainCompleted=!0}lockQuadTree(){this._collectRenderNodesIsActive=!1,this.camera.setTerrainCollisionActivity(!1)}unlockQuadTree(){this._collectRenderNodesIsActive=!0,this.camera.setTerrainCollisionActivity(!0)}_setUniformsNoAtmos(e){let t,i,n=this.renderer,r=n.handler,s=r.gl;return s.enable(s.CULL_FACE),n.enableBlendOneSrcAlpha(),this.lightEnabled?(r.programs.drawnode_screen_wl.activate(),t=r.programs.drawnode_screen_wl._program,i=t.uniforms,s.uniform3fv(i.lightsPositions,this._lightsPositions),s.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),s.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(s.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),s.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),s.uniform4fv(i.specular,this.baseLayer._specular||this._specular),s.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(s.uniform3fv(i.diffuse,this._diffuse),s.uniform3fv(i.ambient,this._ambient),s.uniform4fv(i.specular,this._specular),s.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE),s.bindTexture(s.TEXTURE_2D,this._nightTexture||this.transparentTexture),s.uniform1i(i.nightTexture,this.SLICE_SIZE),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE+1),s.bindTexture(s.TEXTURE_2D,this._specularTexture||this.transparentTexture),s.uniform1i(i.specularTexture,this.SLICE_SIZE+1),s.uniform1f(i.camHeight,e.getHeight())):(r.programs.drawnode_screen_nl.activate(),t=r.programs.drawnode_screen_nl._program,i=t.uniforms,s.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),s.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),s.uniform3fv(i.eyePositionHigh,e.eyeHigh),s.uniform3fv(i.eyePositionLow,e.eyeLow),t}_setUniformsAtmos(e){let t,i,n=this.renderer,r=n.handler,s=r.gl;return s.enable(s.CULL_FACE),n.enableBlendOneSrcAlpha(),this.lightEnabled?(r.programs.drawnode_screen_wl.activate(),t=r.programs.drawnode_screen_wl._program,i=t.uniforms,s.uniform3fv(i.lightsPositions,this._lightsPositions),s.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),s.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(s.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),s.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),s.uniform4fv(i.specular,this.baseLayer._specular||this._specular),s.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(s.uniform3fv(i.diffuse,this._diffuse),s.uniform3fv(i.ambient,this._ambient),s.uniform4fv(i.specular,this._specular),s.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),s.uniform2fv(i.maxMinOpacity,this._atmosphereMaxMinOpacity),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE),s.bindTexture(s.TEXTURE_2D,this._nightTexture||this.transparentTexture),s.uniform1i(i.nightTexture,this.SLICE_SIZE),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE+1),s.bindTexture(s.TEXTURE_2D,this._specularTexture||this.transparentTexture),s.uniform1i(i.specularTexture,this.SLICE_SIZE+1),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE+4),s.bindTexture(s.TEXTURE_2D,n.controls.Atmosphere._transmittanceBuffer.textures[0]),s.uniform1i(i.transmittanceTexture,this.SLICE_SIZE+4),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE+5),s.bindTexture(s.TEXTURE_2D,n.controls.Atmosphere._scatteringBuffer.textures[0]),s.uniform1i(i.scatteringTexture,this.SLICE_SIZE+5),s.uniform1f(i.camHeight,e.getHeight())):(r.programs.drawnode_screen_nl.activate(),t=r.programs.drawnode_screen_nl._program,i=t.uniforms,s.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),s.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),s.uniform3fv(i.eyePositionHigh,e.eyeHigh),s.uniform3fv(i.eyePositionLow,e.eyeLow),t}_renderingScreenNodes(e,t,i){let n=t.isFirstPass,r=this._visibleTileLayerSlices;if(r.length){let e=r[0];for(let t=e.length-1;t>=0;--t){let i=e[t];i._fading&&n&&i._refreshFadingOpacity()&&e.splice(t,1)}}let s=new Map,a=[],o=this.terrain.equalizeVertices,l=i.length;if(t.slope>.8)for(;l--;){let t=i[l],n=t.segment;this._renderingFadingNodesNoDepth(s,e,t,r[0],0),o&&n.equalize(),n.readyToEngage&&n.engage(),n.screenRendering(e,r[0],0)}else{for(;l--;){let t=i[l],n=t.segment;this._renderingFadingNodes(s,e,t,r[0],0,a),n._transitionOpacity<1?a.push(n):(o&&n.equalize(),n.readyToEngage&&n.engage(),n.screenRendering(e,r[0],0))}for(let t=0;t<a.length;t++){let i=a[t];o&&i.equalize(),i.readyToEngage&&i.engage(),i.screenRendering(e,r[0],0)}}}_renderingScreenNodesWithHeight(e,t,i){let n=this.renderer.handler.gl,r=t.isFirstPass,s=this._visibleTileLayerSlices;n.enable(n.POLYGON_OFFSET_FILL),n.disable(n.CULL_FACE);let a=new Map,o=[];for(let t=1,l=s.length;t<l;t++){let l=s[t];for(let e=l.length-1;e>=0;--e){let t=l[e];t._fading&&r&&t._refreshFadingOpacity()&&l.splice(e,1)}n.polygonOffset(0,-t);let h=i.length;for(;h--;){let n=i[h];this._renderingFadingNodes(a,e,n,s[t],t,o),n.segment._transitionOpacity<1?n.segment.initSlice(t):n.segment.screenRendering(e,s[t],t,this.transparentTexture,!0)}}n.disable(n.POLYGON_OFFSET_FILL),n.enable(n.CULL_FACE)}_renderDistanceFramebufferPASS(){if(!this.terrain.isEmpty){let e,t=this.renderer,i=t.handler,n=i.gl,r=t.activeCamera;i.programs.drawnode_heightPicking.activate(),e=i.programs.drawnode_heightPicking._program;let s=e.uniforms;n.uniformMatrix4fv(s.viewMatrix,!1,r.getViewMatrix()),n.uniformMatrix4fv(s.projectionMatrix,!1,r.getProjectionMatrix()),n.uniform3fv(s.eyePositionHigh,r.eyeHigh),n.uniform3fv(s.eyePositionLow,r.eyeLow);let a=this._renderedNodesInFrustum[r.currentFrustumIndex],o=this._visibleTileLayerSlices,l=a.length;for(;l--;)a[l].segment.heightPickingRendering(e,o[0])}}_renderColorPickingFramebufferPASS(){let e,t=this.renderer,i=t.handler,n=i.gl;i.programs.drawnode_colorPicking.activate(),e=i.programs.drawnode_colorPicking._program;let r=e.uniforms,s=t.activeCamera;n.enable(n.CULL_FACE),n.uniformMatrix4fv(r.viewMatrix,!1,s.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,s.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,s.eyeHigh),n.uniform3fv(r.eyePositionLow,s.eyeLow);let a=this._renderedNodesInFrustum[s.getCurrentFrustum()],o=this._visibleTileLayerSlices,l=a.length;for(;l--;)a[l].segment.colorPickingRendering(e,o[0],0);t.enableBlendDefault(),n.enable(n.POLYGON_OFFSET_FILL);for(let t=1,i=o.length;t<i;t++)for(l=a.length,n.polygonOffset(0,-t);l--;)a[l].segment.colorPickingRendering(e,o[t],t,this.transparentTexture,!0);n.disable(n.POLYGON_OFFSET_FILL)}_renderDepthFramebufferPASS(){let e,t=this.renderer,i=t.handler,n=i.gl;i.programs.drawnode_depth.activate(),e=i.programs.drawnode_depth._program;let r=e.uniforms,s=t.activeCamera;n.disable(n.BLEND),n.disable(n.POLYGON_OFFSET_FILL),n.uniformMatrix4fv(r.viewMatrix,!1,s.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,s.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,s.eyeHigh),n.uniform3fv(r.eyePositionLow,s.eyeLow),n.uniform3fv(r.frustumPickingColor,s.frustum._pickingColorU);let a=this._renderedNodesInFrustum[s.getCurrentFrustum()],o=this._visibleTileLayerSlices,l=a.length;for(;l--;)a[l].segment.depthRendering(e,o[0]);n.enable(n.BLEND)}_collectVectorLayerCollections(){this._frustumEntityCollections.length=0,this._frustumEntityCollections=[];let e=this.visibleVectorLayers.length;for(;e--;){let t=this.visibleVectorLayers[e];t._fading&&t._refreshFadingOpacity()&&this.visibleVectorLayers.splice(e,1),t.collectVisibleCollections(this._frustumEntityCollections),t.update()}}_frustumEntityCollectionPickingCallback(){this.drawPickingEntityCollections(this._frustumEntityCollections)}memClear(){this._distBeforeMemClear=0,this.camera._insideSegment=null,this.layerLock.lock(this._memKey),this.terrainLock.lock(this._memKey),this._normalMapCreator.lock(this._memKey),this._normalMapCreator.clear(),this.terrain.abortLoading(),this._tileLoader.abortAll(),this.quadTreeStrategy.clear(),this.layerLock.free(this._memKey),this.terrainLock.free(this._memKey),this._normalMapCreator.free(this._memKey),this._createdNodesCount=0}getRayIntersectionEllipsoid(e){return this.ellipsoid.hitRay(e.origin,e.direction)}getCartesianFromPixelEllipsoid(e){let t=this.renderer.activeCamera;return this.ellipsoid.hitRay(t.eye,t.unproject(e.x,e.y))}getLonLatFromPixelEllipsoid(e){let t=this.getCartesianFromPixelEllipsoid(e);if(t)return this.ellipsoid.cartesianToLonLat(t)}getCartesianFromMouseTerrain(){let e=this.renderer.events.mouseState,t=this.getDistanceFromPixel(e);if(t)return e.direction.scaleTo(t).addA(this.renderer.activeCamera.eye)}getCartesianFromPixelTerrain(e){let t=this.getDistanceFromPixel(e);if(t){return(e.direction||this.renderer.activeCamera.unproject(e.x,e.y)).scaleTo(t).addA(this.renderer.activeCamera.eye)}}getLonLatFromPixelTerrain(e){let t=this.getCartesianFromPixelTerrain(e);if(t)return this.ellipsoid.cartesianToLonLat(t)}getPixelFromCartesian(e){return this.renderer.activeCamera.project(e)}getPixelFromLonLat(e){let t=this.ellipsoid.lonLatToCartesian(e);if(t)return this.renderer.activeCamera.project(t)}getDistanceFromPixelEllipsoid(e){let t=this.getCartesianFromPixelEllipsoid(e);if(t)return t.distance(this.renderer.activeCamera.eye)}getDistanceFromPixel(e){if(this.terrain.isEmpty)return this.getDistanceFromPixelEllipsoid(e)||0;{let t=this.renderer,i=t.handler.canvas,n=e.x/i.width,r=(i.height-e.y)/i.height;Ya[0]=Ya[1]=Ya[2]=0;let s=0;if(t.readDistanceColor(n,r,Ya),s=function(e,t=!1){let i=1-2*w(128,e[0]),n=2*x(e[0],128)+w(128,e[1])-127,r=65536*x(e[1],128)+256*e[2]+(t&&e[3]||0)+8388608;return i*C(n)*(1.1920928955078125e-7*r)}(Ya),Ya[0]||Ya[1]||Ya[2]){if(s<11){t.screenDepthFramebuffer.activate(),t.screenDepthFramebuffer.readPixels(qa,n,r);let i=new re(2*n-1,2*r-1,qa[0]/255*2-1,1),a=this.camera.frustums[0].inverseProjectionMatrix.mulVec4(i),o=e.direction||t.activeCamera.unproject(e.x,e.y);s=-a.z/a.w/o.dot(t.activeCamera.getForward()),t.screenDepthFramebuffer.deactivate()}}else s=this.getDistanceFromPixelEllipsoid(e)||0;return s}}viewExtent(e){this.camera?this.camera.viewExtent(e):this._initialViewExtent=e}viewExtentArr(e){this.viewExtent(new ie(new z(e[0],e[1]),new z(e[2],e[3])))}getViewExtent(){return this._viewExtent}viewLonLat(e,t,i){this.camera.setLonLat(e,t,i)}flyExtent(e,t,i,n,r,s){this.camera.flyExtent(e,t,i,n,r,s)}flyCartesian(e,t,i,n,r,s,a){this.camera.flyCartesian(e,t,i,n,r,s,a)}flyLonLat(e,t,i,n,r,s,a){this.camera.flyLonLat(e,t,i,n,r,s,a)}stopFlying(){this.camera.stopFlying()}updateBillboardsTexCoords(){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].billboardHandler.refreshTexCoordsArr();let e={};for(let t=0;t<this._layers.length;t++){let i=this._layers[t];i instanceof In&&i.each((function(t){t._entityCollection&&!e[t._entityCollection.id]&&(t._entityCollection.billboardHandler.refreshTexCoordsArr(),e[t._entityCollection.id]=!0)}))}}getEntityTerrainPoint(e,t){let i=this._renderedNodes,n=i.length;for(;n--;)if(i[n].segment.isEntityInside(e))return i[n].segment.getEntityTerrainPoint(e,t)}async getHeightDefault(e){return new Promise((t=>{this.terrain?this.terrain.getHeightAsync(e.clone(),(e=>{t(e)})):t(0)}))}async getHeightAboveELL(e){return new Promise((t=>{this.terrain?this.terrain.getHeightAsync(e.clone(),(i=>{t(i+this.terrain.geoid.getHeightLonLat(e))})):t(0)}))}onremove(){this.memClear(),this.quadTreeStrategy.destroyBranches(),this._renderedNodes=[]}}const Za=["draw","layeradd","baselayerchange","layerremove","layervisibilitychange","rendercompleted","terraincompleted","layerloadend"];class $a extends Pi{constructor(e){super("skybox"),this.params=e,this.vertexPositionBuffer=null,this.texture=null}static createDefault(e){return new $a({nx:e+"skybox/gal/_nx.jpg",px:e+"skybox/gal/_px.jpg",py:e+"skybox/gal/_py.jpg",ny:e+"skybox/gal/_ny.jpg",pz:e+"skybox/gal/_pz.jpg",nz:e+"skybox/gal/_nz.jpg"})}init(){this.renderer.handler.addProgram(new zi("skybox",{uniforms:{projectionViewMatrix:{type:Bi.MAT4},uSampler:{type:Bi.SAMPLERCUBE},pos:{type:Bi.VEC3}},attributes:{aVertexPosition:{type:Bi.VEC3,enableArray:!0}},vertexShader:"attribute vec3 aVertexPosition;\n uniform mat4 projectionViewMatrix;\n uniform vec3 pos;\n varying vec3 vTextureCoord;\n void main(void) {\n vTextureCoord = aVertexPosition;\n gl_Position = projectionViewMatrix * vec4(aVertexPosition + pos, 1.0);\n }",fragmentShader:"precision lowp float;\n varying vec3 vTextureCoord;\n uniform samplerCube uSampler;\n void main(void) {\n gl_FragColor = textureCube(uSampler, vTextureCoord);\n }"}),!0),this.texture=this.renderer.handler.loadCubeMapTexture(this.params),this._createBuffers(),this.drawMode=this.renderer.handler.gl.TRIANGLES}frame(){let e=this.renderer.handler,t=e.gl,i=this.renderer.activeCamera;t.disable(t.DEPTH_TEST),e.programs.skybox.activate();let n=e.programs.skybox._program,r=n.uniforms;t.uniformMatrix4fv(r.projectionViewMatrix,!1,i.getProjectionViewMatrix()),t.uniform3fv(r.pos,i.eye.toArray()),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_CUBE_MAP,this.texture),t.uniform1i(r.uSampler,0);let s=this.vertexPositionBuffer;t.bindBuffer(t.ARRAY_BUFFER,s),t.vertexAttribPointer(n.attributes.aVertexPosition,s.itemSize,t.FLOAT,!1,0,0),t.drawArrays(this.drawMode,0,s.numItems),t.enable(t.DEPTH_TEST)}_createBuffers(){const e=new Float32Array([-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,1e8,-1e8,1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,1e8,-1e8,1e8]);this.vertexPositionBuffer=this.renderer.handler.createArrayBuffer(e,3,e.length/3)}}var Ka=Object.freeze({__proto__:null,Axes:class extends Pi{constructor(e=100){super("Axes"),this.size=e,this.axesBuffer=null,this.axesColorBuffer=null}init(){this.createAxesBuffer(this.size),this.drawMode=this.renderer.handler.gl.LINES,this.renderer.handler.addProgram(new zi("axesShader",{uniforms:{projectionViewMatrix:"mat4"},attributes:{aVertexPosition:"vec3",aVertexColor:"vec4"},vertexShader:"attribute vec3 aVertexPosition;\n attribute vec4 aVertexColor;\n uniform mat4 projectionViewMatrix;\n varying vec4 vColor;\n void main(void) {\n gl_Position = projectionViewMatrix * vec4(aVertexPosition, 1.0);\n vColor = aVertexColor;\n }",fragmentShader:"precision highp float;\n varying vec4 vColor;\n void main(void) {\n gl_FragColor = vColor;\n }"}))}frame(){this.renderer.handler.programs.axesShader.activate().set({projectionViewMatrix:this.renderer.activeCamera.getProjectionViewMatrix(),aVertexPosition:this.axesBuffer,aVertexColor:this.axesColorBuffer}),this.renderer.handler.programs.axesShader.drawArrays(this.drawMode,this.axesBuffer.numItems)}createAxesBuffer(e){const t=[0,0,0,e-1,0,0,0,0,0,0,e-1,0,0,0,0,0,0,e-1];this.axesBuffer=this.renderer.handler.createArrayBuffer(new Float32Array(t),3,6),this.axesColorBuffer=this.renderer.handler.createArrayBuffer(new Float32Array([1,0,0,1,1,0,0,1,0,0,1,1,0,0,1,1,0,1,0,1,0,1,0,1]),4,6)}},Planet:Xa,RenderNode:Pi,SkyBox:$a});class Qa{constructor(e={}){this.__id=Qa.__counter__++,this.equalizeVertices=e.equalizeVertices||!1,this.equalizeNormals=!1,this.isEmpty=!0,this.name=e.name||"empty",this.minZoom=e.minZoom||2,this.maxZoom=e.maxZoom||19,this.maxNativeZoom=e.maxNativeZoom||this.maxZoom,this.gridSizeByZoom=e.gridSizeByZoom||[64,32,16,8,4,4,4,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],this._maxNodeZoom=this.gridSizeByZoom.length-1,this.plainGridSize=2,this.noDataValues=[],this._planet=null,this._geoid=e.geoid||new Pa({src:e.geoidSrc||null}),this._isReady=!1}setUrlRewriteCallback(e){}get isIdle(){return!0}isEqual(e){return e.__id===this.__id}static checkNoDataValue(e,t){return-1!==Be(e,t)}isBlur(e){return!1}set maxNodeZoom(e){e>this.gridSizeByZoom.length-1&&(e=this.gridSizeByZoom.length-1),this._maxNodeZoom=e}get maxNodeZoom(){return this._maxNodeZoom}set geoid(e){this._geoid=e}get geoid(){return this._geoid}getGeoid(){return this._geoid}handleSegmentTerrain(e){e.terrainIsLoading=!1,e.terrainReady=!0,e.terrainExists=!0}isReady(){return this._isReady}abortLoading(){}clearCache(){}getHeightAsync(e,t){return t(0),!0}loadTerrain(e,t=!1){}}Qa.__counter__=0;class Ja extends Qa{constructor(e="",t={}){super({geoidSrc:"https://openglobus.org/geoid/egm84-30.pgm",maxNativeZoom:t.maxNativeZoom||14,...t}),this._s=t.subdomains||["a","b","c"],this.events=Pt(eo,this),this._requestCount=0,this._requestsPeerSubdomain=4,this.isEmpty=!1,this.equalizeNormals=!0,this.name=e||"openglobus",this.url=t.url||"https://{s}.srtm3.openglobus.org/{z}/{y}/{x}.ddm",this.gridSizeByZoom=t.gridSizeByZoom||[64,32,32,16,16,8,8,8,16,16,16,32,32,32,32,16,8,4,2,2,2,2,2,2],this._heightFactor=null!=t.heightFactor?t.heightFactor:1,this.noDataValues=t.noDataValues||[];for(let e=0;e<this.noDataValues.length;e++)this.noDataValues[e]*=this._heightFactor;this.plainGridSize=t.plainGridSize||32,this._extent=Me(t.extent,new ie(new z(-180,-90),new z(180,90))),this._dataType="arrayBuffer",this._maxNodeZoom=this.gridSizeByZoom.length-1,this._elevationCache={},this._fetchCache={},this._loader=new Ba,this._urlRewriteCallback=t.urlRewrite||null}get loader(){return this._loader}clearCache(){for(let e in this._elevationCache)this._elevationCache[e].heights=null,this._elevationCache[e].extent=null,delete this._elevationCache[e];this._elevationCache=null,this._elevationCache={};for(let e in this._fetchCache)this._fetchCache[e]=null,delete this._fetchCache[e];this._fetchCache=null,this._fetchCache={}}isBlur(e){return e.tileZoom>=6}setElevationCache(e,t){this._elevationCache[e]=t}getElevationCache(e){return this._elevationCache[e]}getHeightAsync(e,t,i,n){if(!e||e.lat>J||e.lat<ee)return t(0),!0;n=null==n||n;const[r,s,a,o]=this._planet.quadTreeStrategy.getTileXY(e,i||this.maxZoom);let l=qt.getTileIndex(r,s,a,o),h=this.getElevationCache(l),c=X(e);if(h)return h.heights?t(this._getGroundHeightMerc(c,h)):t(0),!0;{let i=this._fetchCache[l];i||(i=this._loader.fetch({src:this.buildURL(r,s,a,o),type:this._dataType}),this._fetchCache[l]=i),i.then((i=>{let h=Q(r,s,a);if("ready"===i.status){let e={heights:this._createHeights(i.data,null,o,r,s,a,h),extent:h};this.setElevationCache(l,e),t(this._getGroundHeightMerc(c,e))}else if("error"===i.status){if(n&&a>this.maxNativeZoom)return n=!1,void this.getHeightAsync(e,t,this.maxNativeZoom,!1);this.setElevationCache(l,{heights:null,extent:h}),t(0)}else this._fetchCache[l]=null,delete this._fetchCache[l]}))}return!1}_getGroundHeightMerc(e,t){if(!t.extent||!t.heights)return 0;let i=t.extent.getWidth(),n=Math.sqrt(t.heights.length),r=i/(n-1),s=n-Math.ceil((e.lat-t.extent.southWest.lat)/r)-1,a=Math.floor((e.lon-t.extent.southWest.lon)/r),o=(s+1)*n+a,l=o+1,h=s*n+a,c=h+1,d=t.heights[o],_=t.heights[l],u=t.heights[h],f=t.heights[c],g=new oe(t.extent.southWest.lon+r*a,d,t.extent.northEast.lat-r*s-r),p=new oe(g.x+r,_,g.z),m=new oe(g.x,u,g.z+r),v=new oe(g.x+r,f,g.z+r),y=new oe(e.lon,1e5,e.lat),x=new _i(y,new oe(0,-1,0)),b=new oe,w=x.hitTriangle(g,p,m,b);return w===_i.INSIDE?b.y:(w=x.hitTriangle(p,v,m,b),w===_i.INSIDE?b.y:0)}abortLoading(){this._loader.abortAll()}setUrl(e){this.url=e}setName(e){this.name=e}isReadyToLoad(e){return 0===e._tileGroup&&this._extent.overlaps(e.getExtentLonLat())}loadTerrain(e,t=!1){if(this._planet.terrainLock.isFree())if(e.terrainReady=!1,e.terrainIsLoading=!0,this.isReadyToLoad(e)){let i=this.getElevationCache(e.tileIndex);i?this._applyElevationsData(e,i.heights):this._loader.load({sender:this,src:this._getHTTPRequestString(e),segment:e,type:this._dataType,filter:()=>e.plainReady&&0!==e.node.getState()||t},(t=>{if("ready"===t.status){let i=this._createHeights(t.data,e,e._tileGroup,e.tileX,e.tileY,e.tileZoom,e.getExtent(),e.tileZoom===this.maxZoom);this.setElevationCache(e.tileIndex,{heights:i,extent:e.getExtent()}),this._applyElevationsData(e,i)}else"abort"===t.status?e.terrainIsLoading=!1:"error"===t.status?this._applyElevationsData(e,null):e.terrainIsLoading=!1}))}else e.elevationsNotExists();else e.terrainIsLoading=!1}_getSubdomain(){return this._requestCount++,this._s[Math.floor(this._requestCount%(this._requestsPeerSubdomain*this._s.length)/this._requestsPeerSubdomain)]}buildURL(e,t,i,n){return be(this.url,{s:this._getSubdomain(),x:e.toString(),y:t.toString(),z:i.toString()})}_createUrl(e){return this.buildURL(e.tileX,e.tileY,e.tileZoom,e._tileGroup)}_getHTTPRequestString(e){return this._urlRewriteCallback&&this._urlRewriteCallback(e.tileX,e.tileY,e.tileZoom,e._tileGroup)||this._createUrl(e)}setUrlRewriteCallback(e){this._urlRewriteCallback=e}_createHeights(e,t,i,n,r,s,a,o){if(1!==this._heightFactor){let t=new Float32Array(e);for(let e=0,i=t.length;e<i;e++)t[e]=t[e]*this._heightFactor;return t}return new Float32Array(e)}_applyElevationsData(e,t){if(e){let i=this.events.load;i.handlers.length&&this.events.dispatch(i,{elevations:t,segment:e}),e.applyTerrain(t)}}}const eo=["load","loadend"];class to extends qt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(io),this.url=t.url||"",this._s=t.subdomains||["a","b","c"],this.minNativeZoom=t.minNativeZoom||0,this.maxNativeZoom=t.maxNativeZoom||19,this._urlRewriteCallback=t.urlRewrite||null,this._requestsPeerSubdomains=4,this._requestCount=0}get isIdle(){return super.isIdle&&0===this._planet._tileLoader.getRequestCounter(this)}get instanceName(){return"XYZ"}abortLoading(){this._planet&&this._planet._tileLoader.abort(this)}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),e||this.abortLoading())}remove(){return this.abortLoading(),super.remove(),this}setUrl(e){this.url=e}_checkSegment(e){return e._projection.id===this._planet.quadTreeStrategy.projection.id}loadMaterial(e,t=!1){let i=e.segment;this._isBaseLayer?e.texture=i.getDefaultTexture():e.texture=i.planet.transparentTexture,(this._planet.layerLock.isFree()||e.segment.tileZoom<2)&&(e.isReady=!1,e.isLoading=!0,this._checkSegment(i)?(e.loadingAttempts++,this._planet._tileLoader.load({sender:this,src:this._getHTTPRequestString(e.segment),type:"imageBitmap",filter:()=>i.initialized&&1===i.node.getState()||t,options:{}},(t=>{if("ready"===t.status){if(e.isLoading){let i=this.events.load;i.handlers.length&&this.events.dispatch(i,e),e.applyImage(t.data),t.data=null}}else"abort"===t.status?e.isLoading=!1:"error"===t.status&&e.isLoading&&e.textureNotExists()}))):e.textureNotExists())}_createUrl(e){return be(this.url,{s:this._getSubdomain(),x:e.tileX.toString(),y:e.tileY.toString(),z:e.tileZoom.toString()})}_getSubdomain(){return this._requestCount++,this._s[Math.floor(this._requestCount%(this._requestsPeerSubdomains*this._s.length)/this._requestsPeerSubdomains)]}_getHTTPRequestString(e){return this._urlRewriteCallback?this._urlRewriteCallback(e,this.url):this._createUrl(e)}setUrlRewriteCallback(e){this._urlRewriteCallback=e}applyMaterial(e,t=!1){if(e.isReady)return e.texOffset;if(e.segment.tileZoom<this.minNativeZoom)e.textureNotExists();else{let i=e.segment,n=i.node,r=!1,s=this.__id,a=e;for(;n.parentNode;)if(n=n.parentNode,a=n.segment.materials[s],a&&a.textureExists){r=!0;break}if(i.passReady){let r=e.layer.maxNativeZoom;if(n.segment.tileZoom===r)e.textureNotExists();else if(e.segment.tileZoom<=r)!e.isLoading&&!e.isReady&&this.loadMaterial(e,t);else{let t=i.node;for(;t.segment.tileZoom>e.layer.maxNativeZoom;)t=t.parentNode;let n=t.segment.materials[e.layer.__id];n?!n.isLoading&&!n.isReady&&this.loadMaterial(n,!0):(n=t.segment.materials[e.layer.__id]=e.layer.createMaterial(t.segment),this.loadMaterial(n,!0))}}if(r){e.appliedNode=n,e.appliedNodeId=n.nodeId,e.texture=a.texture;let t=1/(2<<i.tileZoom-n.segment.tileZoom-1);e.texOffset[0]=i.tileX*t-n.segment.tileX,e.texOffset[1]=i.tileY*t-n.segment.tileY,e.texOffset[2]=t,e.texOffset[3]=t}else e.texture=i.planet.transparentTexture,e.texOffset[0]=0,e.texOffset[1]=0,e.texOffset[2]=1,e.texOffset[3]=1}return e.texOffset}clearMaterial(e){e.isReady&&e.textureExists&&(!e.texture.default&&e.segment.handler.gl.deleteTexture(e.texture),e.texture=null),e.isReady=!1,e.textureExists=!1,e.isLoading=!1}_correctFullExtent(){let e=this._extent,t=this._extentMerc,i=F+5e4,n=F+5e4;90===e.northEast.lat&&(t.northEast.lat=n),180===e.northEast.lon&&(t.northEast.lon=i),-90===e.southWest.lat&&(t.southWest.lat=-20087508.34),-180===e.southWest.lon&&(t.southWest.lon=-20087508.34),e.northEast.lat>=J&&(e.northEast.lat=J),e.northEast.lat<=ee&&(e.northEast.lat=ee)}}const io=["load","loadend"];class no extends to{constructor(e,t){super(e,t),this._extra=new URLSearchParams(t.extra).toString(),t.extent||this.setExtent(new ie(new z(-180,-90),new z(180,90))),this.layers=t.layers,this.imageWidth=t.imageWidth||256,this.imageHeight=t.imageHeight||256,this._getBbox=no.get_bbox_v1_1_1,this._version="",this.setVersion(t.version)}static createRequestUrl(e,t,i="image/png",n="1.1.1",r="GetMap",s,a,o=256,l=256,h){return`${e}/?LAYERS=${t}&FORMAT=${i}&SERVICE=WMS&VERSION=${n}&REQUEST=${r}&SRS=${s}&BBOX=${a}&WIDTH=${o}&HEIGHT=${l}`+(h?`&${h}`:"")}static get_bbox_v1_1_1(e){return`${e.getWest()},${e.getSouth()},${e.getEast()},${e.getNorth()}`}static get_bbox_v1_3_0(e){return`${e.getSouth()},${e.getWest()},${e.getNorth()},${e.getEast()}`}_checkSegment(e){return!0}get instanceName(){return"WMS"}_createUrl(e){return no.createRequestUrl(this.url,this.layers,"image/png",this._version,"GetMap",e._projection.code,this._getBbox(e.getExtent()),this.imageWidth,this.imageHeight,this._extra)}setVersion(e){this._version=e||"1.1.1","1.1.1"===this._version?this._getBbox=no.get_bbox_v1_1_1:"1.3.0"===e&&(this._getBbox=no.get_bbox_v1_3_0)}_correctFullExtent(){const e=this._extent,t=this._extentMerc,i=F+5e4,n=F+5e4;90===e.northEast.lat&&(t.northEast.lat=n),180===e.northEast.lon&&(t.northEast.lon=i),-90===e.southWest.lat&&(t.southWest.lat=-20087508.34),-180===e.southWest.lon&&(t.southWest.lon=-20087508.34)}}class ro extends Ja{constructor(e={}){super("BilTerrain",e),this.equalizeVertices=!0,this.equalizeNormals=!0,this.minZoom=e.minZoom||2,this.maxZoom=e.maxZoom||14,this.noDataValues=e.noDataValues||[-9999,32767],this.url=e.url||"",this._format="application/bil16",this._layers=e.layers||"",this._imageSize=e.imageSize||256,this.plainGridSize=null!=e.plainGridSize?e.plainGridSize:m(this._imageSize)?this._imageSize/2:v(this._imageSize)/2,this._dataType="arrayBuffer"}isBlur(e){return e.tileZoom>=18}_createUrl(e){return no.createRequestUrl(this.url,this._layers,this._format,"1.1.1","GetMap",e._projection.code,no.get_bbox_v1_1_1(e.getExtent()),this._imageSize,this._imageSize)}_createHeights(e,t,i,n,r,s,a,o){let l=new Int16Array(e);if(!m(this._imageSize)){let e=new Float32Array(l.length);return function(e,t){for(let i=0,n=t.length;i<n;i++)t[i]=e[i]}(l,e),e}let h=(this.plainGridSize+1)*(this.plainGridSize+1),c=new Array(4);for(let e=0;e<4;e++){c[e]=[];for(let t=0;t<4;t++)c[e][t]=new Float32Array(h)}let d=new Float32Array(h);!function(e,t,i,n){let r=Math.sqrt(i.length)-1,s=r+1,a=Math.sqrt(e.length),o=a/r,l=0,h=0;for(let c=0,d=0,_=e.length;c<_;c++){let _=e[c],u=ro.checkNoDataValue(t,_),f=!1,g=!1,p=Math.floor(c/a),m=c%a,v=Math.floor(m/r),y=Math.floor(p/r),x=n[y][v],b=p%r,w=m%r,T=(b+y)*s+w+v;if(x[T]=_,(p+y)%o==0&&(m+v)%o==0&&(i[d++]=_),(m+1)%r==0&&m!==a-1){l=e[c],f=ro.checkNoDataValue(t,l);let a=_;u||f||(a=.5*(_+l)),T=(b+y)*s+w+1,x[T]=a,(p+y)%o==0&&(i[d++]=a);let h=(b+y)*s+(w+1)%r;n[y][v+1][h]=a}if((p+1)%r==0&&p!==a-1){h=e[c+a],g=ro.checkNoDataValue(t,h);let l=_;u||g||(l=.5*(_+h)),T=(b+1)*s+w+v,x[T]=l,(m+v)%o==0&&(i[d++]=l);let f=(b+1)%r*s+w+v;n[y+1][v][f]=l}if((m+1)%r==0&&m!==a-1&&(p+1)%r==0&&p!==a-1){let o=e[c+a+1],p=ro.checkNoDataValue(t,o),m=_;u||f||g||p||(m=.25*(_+l+h+o)),T=(b+1)*s+(w+1),x[T]=m,i[d++]=m;let C=(b+1)*s;n[y][v+1][C]=m;let L=r;n[y+1][v][L]=m;let A=0;n[y+1][v+1][A]=m}}}(l,this.noDataValues,d,c);let _=qt.getTileIndex(n,r,s,i);this.setElevationCache(_,{heights:d,extent:a});let u=this._imageSize/this.plainGridSize;for(let e=0;e<u;e++)for(let t=0;t<u;t++){let a=2*n+t,o=2*r+e,l=s+1,h=qt.getTileIndex(a,o,l,i);this.setElevationCache(h,{heights:c[e][t],extent:Q(a,o,l)})}return d}}const so=(e,t,i)=>255===e?-1e4:.1*(256*e*256+256*t+i)-1e4;class ao extends Ja{constructor(e,t={}){super(e||"RgbTerrain",{equalizeVertices:null==t.equalizeVertices||t.equalizeVertices,maxZoom:t.maxZoom||17,noDataValues:t.noDataValues||[-65537,-1e4],plainGridSize:t.plainGridSize||128,url:null!=t.url?t.url:`//api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token=${t.key||"<key>"}`,gridSizeByZoom:t.gridSizeByZoom||[64,32,16,8,8,8,16,16,16,32,32,32,32,32,32,64,64,64,32,32,16,8],...t}),this.equalizeNormals=t.equalizeNormals||!1,this._dataType="imageBitmap",this._imageSize=t.imageSize||256,this._ctx=this._createTemporalCanvas(this._imageSize),this._imageDataCache={}}static checkNoDataValue(e,t){return t>5e4||-1!==Be(e,t)}isBlur(e){return e.tileZoom>=16}_createTemporalCanvas(e){let t=document.createElement("canvas");return t.width=e,t.height=e,t.getContext("2d",{willReadFrequently:!0})}_createHeights(e,t,i,n,r,s,a,o){this._ctx.clearRect(0,0,this._imageSize,this._imageSize),this._ctx.drawImage(e,0,0);let l=this._ctx.getImageData(0,0,this._imageSize,this._imageSize).data;const h=e.width;let c=0,d=0,_=0,u=null,f=!1;if(t&&t.tileZoom>this.maxNativeZoom){let e=t.node;for(;e&&!e.segment.terrainExists;)e=e.parentNode;e&&(c=e.segment.tileX,d=e.segment.tileY,_=e.segment.tileZoom,u=e.segment.elevationData,f=_<=8)}if(!m(this._imageSize)&&h===this._imageSize){let e=new Float32Array(h*h);return function(e,t,i=1){for(let n=0,r=t.length;n<r;n++){let r=4*n;t[n]=i*so(e[r],e[r+1],e[r+2])}}(l,e,this._heightFactor),e}if(this._imageSize===this.plainGridSize){let e=(this.plainGridSize+1)*(this.plainGridSize+1),i=new Float32Array(e),[n,r,s]=t?oo(t.tileX,t.tileY,t.tileZoom,c,d,_):[0,0,0];return function(e,t,i=null,n,r,s,a,o,l=1,h){for(let c=0,d=h*h;c<d;c++){let d=c%h,_=Math.floor(c/h),u=4*c,f=l*so(e[u],e[u+1],e[u+2]);(ao.checkNoDataValue(t,f)||0===f)&&i&&(f=lo(s,n,r,i,_,d,a)),o[_*(h+1)+d]=f}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(c*h+d),u=l*so(e[_],e[_+1],e[_+2]);(ao.checkNoDataValue(t,u)||0===u)&&i&&(u=lo(s,n,r,i,c,d,a)),o[c*(h+1)+h]=u}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(d*h+c),u=l*so(e[_],e[_+1],e[_+2]);(ao.checkNoDataValue(t,u)||0===u)&&i&&(u=lo(s,n,r,i,d,c,a)),o[h*(h+1)+c]=u}let c=l*so(e[e.length-4],e[e.length-3],e[e.length-2]);(ao.checkNoDataValue(t,c)||0===c)&&i&&(c=lo(s,n,r,i,h-1,h-1,a));o[o.length-1]=c}(l,this.noDataValues,u,n,r,s,f,i,this._heightFactor,this._imageSize),i}let g=(this.plainGridSize+1)*(this.plainGridSize+1),p=h/this.plainGridSize,v=new Float32Array(g),y=new Array(p);for(let e=0;e<p;e++){y[e]=[];for(let t=0;t<p;t++)y[e][t]=new Float32Array(g)}if(o)!function(e,t,i,n=null,r,s,a,o,l,h,c,d){let _=Math.sqrt(d.length)-1,u=_+1,f=Math.sqrt(e.length/4),g=f/_,p=0,m=0,v=0,[y,x,b]=oo(o,l,h,r,s,a);for(let r=0,s=0,a=e.length/4;r<a;r++){let a=4*r,o=t*so(e[a],e[a+1],e[a+2]),l=ao.checkNoDataValue(i,o),h=!1,w=!1,T=Math.floor(r/f),C=r%f;(l||0===o)&&n&&(o=lo(b,y,x,n,Math.floor(s/u),s%u,c));let L=Math.floor(C/_),A=Math.floor(T/_);if((T+A)%g==0&&(C+L)%g==0&&(d[s++]=o),(C+1)%_==0&&C!==f-1){p=t*so(e[a+4],e[a+5],e[a+6]),h=ao.checkNoDataValue(i,p),(h||0===p)&&n&&(p=lo(b,y,x,n,Math.floor(s/u),s%u,c));let r=o;l||h||(r=.5*(o+p)),(T+A)%g==0&&(d[s++]=r)}if((T+1)%_==0&&T!==f-1){v=4*f,m=t*so(e[a+v],e[a+v+1],e[a+v+2]),w=ao.checkNoDataValue(i,m),(w||0===m)&&n&&(m=lo(b,y,x,n,Math.floor(s/u),s%u,c));let r=.5*(o+m);l||w||(r=.5*(o+m)),(C+L)%g==0&&(d[s++]=r)}if((C+1)%_==0&&C!==f-1&&(T+1)%_==0&&T!==f-1){let r=t*so(e[a+v+4],e[a+v+5],e[a+v+6]),_=ao.checkNoDataValue(i,r);(_||0===r)&&n&&(r=lo(b,y,x,n,Math.floor(s/u),s%u,c));let f=o;l||h||w||_||(f=.25*(o+p+m+r)),d[s++]=f}}}(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,f,v);else{!function(e,t,i,n=null,r,s,a,o,l,h,c,d,_){let u=Math.sqrt(d.length)-1,f=u+1,g=Math.sqrt(e.length/4),p=g/u,m=0,v=0,y=0,[x,b,w]=oo(o,l,h,r,s,a);for(let r=0,s=0,a=e.length/4;r<a;r++){let a=4*r,o=t*so(e[a],e[a+1],e[a+2]),l=ao.checkNoDataValue(i,o),h=!1,T=!1,C=Math.floor(r/g),L=r%g;(l||0===o)&&n&&(o=lo(w,x,b,n,Math.floor(C/p),Math.floor(L/p),c));let A=Math.floor(L/u),E=Math.floor(C/u),P=_[E][A],M=C%u,S=L%u,B=(M+E)*f+S+A;if(P[B]=o,(C+E)%p==0&&(L+A)%p==0&&(d[s++]=o),(L+1)%u==0&&L!==g-1){m=t*so(e[a+4],e[a+5],e[a+6]),h=ao.checkNoDataValue(i,m),(h||0===m)&&n&&(m=lo(w,x,b,n,Math.floor(C/p),Math.floor((L+1)/p),c));let r=o;l||h||(r=.5*(o+m)),B=(M+E)*f+S+1,P[B]=r,(C+E)%p==0&&(d[s++]=r);let g=(M+E)*f+(S+1)%u;_[E][A+1][g]=r}if((C+1)%u==0&&C!==g-1){y=4*g,v=t*so(e[a+y],e[a+y+1],e[a+y+2]),T=ao.checkNoDataValue(i,v),(T||0===v)&&n&&(v=lo(w,x,b,n,Math.floor((C+1)/p),Math.floor(L/p),c));let r=.5*(o+v);l||T||(r=.5*(o+v)),B=(M+1)*f+S+A,P[B]=r,(L+A)%p==0&&(d[s++]=r);let h=(M+1)%u*f+S+A;_[E+1][A][h]=r}if((L+1)%u==0&&L!==g-1&&(C+1)%u==0&&C!==g-1){let r=t*so(e[a+y+4],e[a+y+5],e[a+y+6]),g=ao.checkNoDataValue(i,r);(g||0===r)&&n&&(r=lo(w,x,b,n,Math.floor((C+1)/p),Math.floor((L+1)/p),c));let k=o;l||h||T||g||(k=.25*(o+m+v+r)),B=(M+1)*f+(S+1),P[B]=k,d[s++]=k;let R=(M+1)*f;_[E][A+1][R]=k;let I=u;_[E+1][A][I]=k;let z=0;_[E+1][A+1][z]=k}}}(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,f,v,y);for(let e=0;e<p;e++)for(let t=0;t<p;t++){let[a,o,l]=[2*n+t,2*r+e,s+1],h=qt.getTileIndex(a,o,l,i);this.setElevationCache(h,{heights:y[e][t],extent:Q(a,o,l)})}}let x=qt.getTileIndex(n,r,s,i);return this.setElevationCache(x,{heights:v,extent:a}),v}getHeightAsync(e,t,i){if(0===(i=null!=i?i:this.maxZoom))return t(0),!0;const n=this._planet.quadTreeStrategy,[r,s,a,o]=n.getTileXY(e,i),[l,h]=n.getLonLatTileOffset(e,r,s,a,this._imageSize),c=4*(l*this._imageSize+h),d=qt.getTileIndex(r,s,a,o);if(this._imageDataCache[d]){let n=this._imageDataCache[d],r=this._heightFactor*so(n[c],n[c+1],n[c+2]);return ao.checkNoDataValue(this.noDataValues,r)?this.getHeightAsync(e,t,i-1):(t(this._heightFactor*so(n[c],n[c+1],n[c+2])),!0)}let _=this._fetchCache[d];return _||(_=this._loader.fetch({src:this._urlRewriteCallback&&this._urlRewriteCallback(r,s,a,o)||this.buildURL(r,s,a,o),type:this._dataType}),this._fetchCache[d]=_),_.then((n=>{if("ready"===n.status){this._ctx.clearRect(0,0,this._imageSize,this._imageSize),this._ctx.drawImage(n.data,0,0);let r=this._ctx.getImageData(0,0,256,256).data;this._imageDataCache[d]=r;let s=this._heightFactor*so(r[c],r[c+1],r[c+2]);if(ao.checkNoDataValue(this.noDataValues,s))return this.getHeightAsync(e,t,i-1);t(this._heightFactor*so(r[c],r[c+1],r[c+2]))}else{if("error"===n.status)return this.getHeightAsync(e,t,i-1);this._fetchCache[d]=null,delete this._fetchCache[d]}})),!1}}function oo(e,t,i,n,r,s){let a=2<<i-s-1;return[e-a*n,t-a*r,1/a]}function lo(e,t,i,n,r,s,a){let o=Math.sqrt(n.length),l=n[Math.floor(i*e*o+r*e)*o+Math.floor(t*e*o+s*e)];return a&&l>0?0:l}const ho={[ra]:"north",[sa]:"south"},co=(e,t,i,n)=>{let r=ho[n];if(r)return`https://terrain.openglobus.org/public/poles/${r}/${i}/${e}/${t}.png`};class _o extends ao{constructor(e,t){super(e||"GlobusEarthRgb",{maxNativeZoom:6,maxZoom:17,url:"https://{s}.terrain.openglobus.org/public/all/{z}/{x}/{y}.png",urlRewrite:co,...t})}isReadyToLoad(e){return this._extent.overlaps(e.getExtentLonLat())}}var uo=Object.freeze({__proto__:null,BilTerrain:ro,EmptyTerrain:Qa,GlobusRgbTerrain:_o,GlobusTerrain:Ja,RgbTerrain:ao});class fo extends cr{constructor(e,t={}){super(e,t),this._image=t.image||null,this._src=t.src||null,this._onLoad_=null}get instanceName(){return"GeoImage"}abortLoading(){this._image instanceof HTMLImageElement&&(this._image.src="")}setSrc(e){this._planet&&this._planet._geoImageCreator.remove(this),this._src=e,this._sourceReady=!1,this._sourceCreated=!1,this._image=new Image,this._image.crossOrigin="Anonymous",this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_),this._image.src=e}setImage(e){this._planet&&this._planet._geoImageCreator.remove(this),this._sourceCreated=!1,this._sourceReady=!1,this._image=e,this._image.crossOrigin="Anonymous",this._src=e.src,Ze(this._image)?this._applyImage(this._image):(this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_))}_createSourceTexture(){!this._sourceCreated&&this._image&&(this._sourceTexture=this._planet.renderer.handler.createTexture_l(this._image),this._sourceCreated=!0)}_onLoad(e){this._applyImage(this._image),this._image instanceof HTMLImageElement&&this._image.removeEventListener("load",this._onLoad_),this._onLoad_=null}_applyImage(e){e&&(this._frameWidth=v(2*e.width,4096),this._frameHeight=v(3*e.height,4096),this._sourceReady=!0,this._planet&&this._planet._geoImageCreator.add(this))}loadMaterial(e){e.isLoading=!0,this._creationProceeding=!0,!this._sourceReady&&this._src?this._image?this._image instanceof HTMLImageElement&&(Ze(this._image)?this._applyImage(this._image):(this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_))):(this._image=new Image,this._image.crossOrigin="Anonymous",this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_),this._image.src=this._src):this._planet&&this._planet._geoImageCreator.add(this)}abortMaterialLoading(e){this._image&&this._image instanceof HTMLImageElement&&(this._image.src=""),this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class go extends cr{constructor(e,t={}){super(e,t),this._sourceTexture=t.texture||null,t.texture&&(this._sourceReady=!0,this._sourceCreated=!0),this._frameWidth=null!=t.frameWidth?v(t.frameWidth):256,this._frameHeight=null!=t.frameHeight?v(t.frameHeight):256,this._animate=!0}get instanceName(){return"GeoTexture2d"}loadMaterial(e){this._planet._geoImageCreator.add(this)}bindTexture(e){this._sourceReady=!0,this._sourceCreated=!0,this._sourceTexture=e}setSize(e,t){this._frameWidth=e,this._frameHeight=t,this._frameCreated=!1}abortMaterialLoading(e){this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class po extends cr{constructor(e,t={}){super(e,t),this._animate=!0,this._video=t.videoElement||null,this._src=t.src||null}get instanceName(){return"GeoVideo"}setSrc(e){this._planet&&this._planet._geoImageCreator.remove(this),this._src=e,this._sourceReady=!1}setVideoElement(e){this._planet&&this._planet._geoImageCreator.remove(this),this._video=e,this._src=e.src,this._sourceReady=!1}setVisibility(e){e!=this._visibility&&(super.setVisibility(e),this._planet&&(e?(this._sourceReady&&this._planet._geoImageCreator.add(this),this._video&&this._video.play()):(this._sourceReady&&this._planet._geoImageCreator.remove(this),this._video&&this._video.pause())))}_createSourceTexture(){let e=this._planet.renderer.handler.gl;this._sourceCreated?(e.bindTexture(e.TEXTURE_2D,this._sourceTexture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this._video)):(this._sourceTexture=this._planet.renderer.handler.createTexture_n_webgl1(this._video),this._sourceCreated=!0)}_onCanPlay(e){this._frameWidth=e.videoWidth,this._frameHeight=e.videoHeight,e.width=e.videoWidth,e.height=e.videoHeight,e.play(),this._sourceReady=!0,this._planet._geoImageCreator.add(this)}_onError(e){let t="unknown error";switch(e.error.code){case 1:t="video loading aborted";break;case 2:t="network loading error";break;case 3:t="video decoding failed / corrupted data or unsupported codec";break;case 4:t="video not supported"}console.warn(`Error: ${t} error-code=${e.error.code})`)}loadMaterial(e){if(e.isLoading=!0,this._creationProceeding=!0,!this._sourceReady&&this._src){if(this._video){if(this._video.readyState===this._video.HAVE_ENOUGH_DATA)this._onCanPlay(this._video);else if(this._video.src){let e=this;this._video.addEventListener("canplay",(function(t){e._onCanPlay(this)}))}}else{this._video=document.createElement("video"),this._video.crossOrigin="Anonymous";let e=this;this._video.addEventListener("canplay",(function(){e._onCanPlay(this)})),this._video.addEventListener("error",(function(){e._onError(this)}))}this._video.autoplay=!0,this._video.loop=!0,this._video.src=this._src,this._video.muted=!0,this._video.setAttribute("playsinline","true"),this._video.setAttribute("webkit-playsinline","true")}else this._planet._geoImageCreator.add(this)}abortMaterialLoading(e){this._video&&(this._video.src=""),this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class mo extends In{constructor(e,t={}){super(e,t),this._billboard=t.billboard||{src:"https://openglobus.org/examples/billboards/carrot.png"},this._color=t.color||"#6689db"}get instanceName(){return"KML"}_extractCoordonatesFromKml(e){return Array.from(e.getElementsByTagName("coordinates")).map((e=>e.textContent.trim())).map((e=>e.replace(/\n/g," ").replace(/\t/g," ").replace(/ +/g," ").split(" ").map((e=>e.split(",").map(parseFloat)))))}_AGBRtoRGBA(e){if(!e||8!=e.length)return;const t=parseInt(e.slice(0,2),16)/255,i=parseInt(e.slice(2,4),16),n=parseInt(e.slice(4,6),16);return`rgba(${parseInt(e.slice(6,8),16)},${n},${i},${t})`}_parseKMLcoordinates(e){return e.innerHTML.trim().replace(/\n/g," ").replace(/\t/g," ").replace(/ +/g," ").split(" ").map((e=>e.split(",").map(parseFloat)))}_kmlPlacemarkToEntity(e,t){if(!e)return;const i=Array.from(e.getElementsByTagName("name")),n=i&&i.length>0?i[0].innerHTML.trim():"",{iconHeading:r,iconURL:s,iconColor:a,lineWidth:o,lineColor:l}=this._extractStyle(e),h=[];for(const i of e.getElementsByTagName("coordinates")){const e=this._parseKMLcoordinates(i)||[[0,0,0]];for(const i of e){const[e,n,r]=i;h.push(new z(e,n,r)),e<t.southWest.lon&&(t.southWest.lon=e),n<t.southWest.lat&&(t.southWest.lat=n),e>t.northEast.lon&&(t.northEast.lon=e),n>t.northEast.lat&&(t.northEast.lat=n)}}if(1===h.length){const e=.01745329*r;return new Ai({name:n,lonlat:h[0],billboard:{src:s,size:[24,24],color:a,rotation:e},properties:{color:a,heading:r}})}return new Ai({polyline:{pathLonLat:[h],thickness:o,color:l,isClosed:!1}})}_extractStyle(e){let t,i,n,r,s;const a=e.getElementsByTagName("Style")[0];if(a){let e=a.getElementsByTagName("IconStyle")[0];if(e){let r=e.getElementsByTagName("color")[0];r&&(t=this._AGBRtoRGBA(r.innerHTML.trim()));let s=e.getElementsByTagName("heading")[0];if(s){const e=parseFloat(s.innerHTML.trim());e>=0&&e<=360&&(i=e%360)}let a=e.getElementsByTagName("Icon")[0];if(a){let e=a.getElementsByTagName("href")[0];e&&(n=e.innerHTML.trim())}}let o=a.getElementsByTagName("LineStyle")[0];if(o){let e=o.getElementsByTagName("color")[0];e&&(r=this._AGBRtoRGBA(e.innerHTML.trim()));let t=o.getElementsByTagName("width")[0];void 0!==t&&(s=parseFloat(t.innerHTML.trim()))}}return t||(t="#FFFFFF"),i||(i=0),n||(n="https://openglobus.org/examples/billboards/carrot.png"),r||(r="#FFFFFF"),s||(s=1),{iconHeading:i,iconURL:n,iconColor:t,lineWidth:s,lineColor:r}}_parseKML(e,t,i){if(i||(i=[]),"kml"!==e.documentElement.nodeName)return i;for(const n of e.getElementsByTagName("Placemark")){const e=this._kmlPlacemarkToEntity(n,t);e&&i.push(e)}return i}_convertKMLintoEntities(e){const t=new ie(new z(180,90),new z(-180,-90));return{entities:this._parseKML(e,t),extent:t}}_convertCoordonatesIntoEntities(e,t,i){const n=new ie(new z(180,90),new z(-180,-90)),r=e=>{const t=e[0],i=e[1];t<n.southWest.lon&&(n.southWest.lon=t),i<n.southWest.lat&&(n.southWest.lat=i),t>n.northEast.lon&&(n.northEast.lon=t),i>n.northEast.lat&&(n.northEast.lat=i)},s=[];e.forEach((e=>e.forEach((e=>s.push(e)))));return{entities:s.map((e=>{if(1===e.length){const t=e[0],n=new Ai({lonlat:t,billboard:i});return r(t),n}if(e.length>1){const i=e.map((e=>(r(e),new z(e[0],e[1],e[2]))));return new Ai({polyline:{pathLonLat:[i],thickness:3,color:t,isClosed:!1}})}})),extent:n}}_getXmlContent(e){return new Promise((t=>{const i=new FileReader;i.onload=async e=>t((new DOMParser).parseFromString(e.target.result,"text/xml")),i.readAsText(e)}))}_expandExtents(e,t){return e?(t.southWest.lon<e.southWest.lon&&(e.southWest.lon=t.southWest.lon),t.southWest.lat<e.southWest.lat&&(e.southWest.lat=t.southWest.lat),t.northEast.lon>e.northEast.lon&&(e.northEast.lon=t.northEast.lon),t.northEast.lat>e.northEast.lat&&(e.northEast.lat=t.northEast.lat),e):t}async addKmlFromFiles(e,t,i){if(!Array.isArray(e))return null;const n=(await Promise.all(e.map(this._getXmlContent))).map(this._extractCoordonatesFromKml),{entities:r,extent:s}=this._convertCoordonatesIntoEntities(n,t||this._color,i||this._billboard);return this._extent=this._expandExtents(this._extent,s),r.forEach(this.add.bind(this)),{entities:r,extent:s}}setColor(e){this._color=e,this._billboard.color=e}_getKmlFromUrl(e){return new Promise(((t,i)=>{const n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="document",n.overrideMimeType("text/xml"),n.onload=()=>{n.readyState===n.DONE&&200===n.status?t(n.responseXML):i(new Error("no valid kml file"))},n.send()}))}async addKmlFromUrl(e,t,i){const n=await this._getKmlFromUrl(e),{entities:r,extent:s}=this._convertKMLintoEntities(n);return this._extent=this._expandExtents(this._extent,s),r.forEach(this.add.bind(this)),{entities:r,extent:s}}}class vo extends to{constructor(e,t={}){super(e||"OpenStreetMap",{iconSrc:"https://tile.openstreetmap.org/8/138/95.png",url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",attribution:"Data @ OpenStreetMap contributors, ODbL",isBaseLayer:!0,maxNativeZoom:19,defaultTextures:[{color:"#AAD3DF"},{color:"#F2EFE9"}],isSRGB:!1,shininess:18,specular:[63e-5,55e-5,32e-5],ambient:[.2,.2,.3],diffuse:[.9,.9,.7],...t})}}function yo(e,t,i){var n="";for(let a=i;a>0;a--){var r=0,s=1<<a-1;e&s&&r++,t&s&&(r+=2),n+=r.toString()}return n}class xo extends to{constructor(e,t={}){super(e||"Bing",{iconSrc:"https://ecn.t0.tiles.virtualearth.net/tiles/a120.jpeg?n=z&g=7146",subdomains:["t0","t1","t2","t3"],url:"https://ecn.{s}.tiles.virtualearth.net/tiles/a{quad}.jpeg?n=z&g=7146",isBaseLayer:!0,maxNativeZoom:17,defaultTextures:[{color:"#001522"},{color:"#E4E6F3"}],attribution:'<div style="transform: scale(0.8); margin-top:-2px;"><a href="https://www.bing.com" target="_blank"><img style="position: relative; top: 2px;" title="Bing Imagery" src="https://sandcastle.cesium.com/CesiumUnminified/Assets/Images/bing_maps_credit.png"></a> © 2021 Microsoft Corporation</div>',urlRewrite:(e,t)=>be(t,{s:this._getSubdomain(),quad:yo(e.tileX,e.tileY,e.tileZoom)}),specular:[63e-5,55e-5,32e-5],ambient:"rgb(90,90,90)",diffuse:"rgb(350,350,350)",shininess:20,nightTextureCoefficient:2.7,...t})}}var bo=Object.freeze({__proto__:null,Bing:xo,CanvasTiles:$t,GeoImage:fo,GeoTexture2d:go,GeoVideo:po,KML:mo,LAYER_EVENTS:Xt,Layer:qt,Material:jt,OpenStreetMap:vo,Vector:In,WMS:no,XYZ:to});const wo=["tick","end","start","stop"];class To{constructor(e={}){this.__handler=null,this.active=!0,this.__id=To.__counter__++,this.events=Pt(wo,this),this.name=e.name||"",this.startDate=e.startDate||0,this.endDate=e.endDate||0;let t=e.currentDate||gt(new Date);e.startDate&&t<e.startDate&&(t=e.startDate),e.endDate&&t>e.endDate&&(t=e.endDate),this.currentDate=t,this._multiplier=void 0!==e.multiplier?e.multiplier:1,this._running=1,this.deltaTicks=0,this.active=!0,this._intervalDelay=0,this._intervalStart=0,this._intervalCallback=null}clearInterval(){this._intervalDelay=0,this._intervalStart=0,this._intervalCallback=null}setInterval(e,t){this._intervalStart=this.currentDate,this._intervalDelay=e*dt,this._intervalCallback=t}setDate(e){let t=gt(e);this.startDate&&t<this.startDate&&(t=this.startDate),this.endDate&&t>this.endDate&&(t=this.endDate),this.currentDate=t}getDate(){return vt(this.currentDate)}reset(){this.startDate&&(this.currentDate=this.startDate)}tick(e){let t=this._multiplier*this._running;if(this.deltaTicks=e*t,this.active){let e=yt(this.currentDate,this.deltaTicks);t>0?this.endDate&&e>this.endDate?(this.currentDate=this.startDate,this.events.dispatch(this.events.end,this)):this.currentDate=e:this.startDate&&e<this.startDate?(this.currentDate=this.endDate,this.events.dispatch(this.events.end,this)):this.currentDate=e,this._intervalCallback&&this.currentDate-this._intervalStart>=this._intervalDelay&&(this._intervalStart=this.currentDate,this._intervalCallback(this)),this.events.dispatch(this.events.tick,this)}}isEqual(e){return this.__id===e.__id}start(){0===this._running&&(this._running=1,this.events.dispatch(this.events.start,this))}get multiplier(){return this._multiplier}set multiplier(e){this._multiplier=e}stop(){1===this._running&&(this._running=0,this.events.dispatch(this.events.stop,this))}}To.__counter__=0;class Co{constructor(e,t){this._program=t,this._handler=e,this._activated=!1}initialize(){this._handler.gl&&this._program.createProgram(this._handler.gl)}getProgram(){return this._program}activate(){if(!this._activated){this._handler.activeProgram.deactivate(),this._handler.activeProgram=this;let e=this._program;this._activated=!0,e.enableAttribArrays(),e.use()}return this}remove(){let e=this._handler.programs;e[this._program.name]&&(this._activated&&this.deactivate(),this._program.delete(),delete e[this._program.name])}deactivate(){this._program.disableAttribArrays(),this._activated=!1}isActive(){return this._activated}set(e){return this.activate(),this._program.set(e),this}drawIndexBuffer(e,t){return this._program.drawIndexBuffer(e,t),this}drawArrays(e,t){return this._program.drawArrays(e,t),this}}class Lo{constructor(){this.next=null,this.prev=null,this.data=null}}class Ao{constructor(e=256){this._current=new Lo,this._head=this._current;for(let t=0;t<e;t++){let e=new Lo;e.prev=this._current,this._current.next=e,this._current=e}this._current=this._head}current(){return this._current}push(e){this._current=this._current.next,this._current.data=e}pop(){let e=this._current.data;return this._current=this._current.prev,e}popPrev(){return this._current=this._current.prev,this._current.data}}const Eo=["","WEBKIT_","MOZ_"],Po=["webgl2","webgl"];class Mo{constructor(e,t={}){this.framebufferStack=new Ao,this._requestAnimationFrameId=0,this.events=Pt(["visibilitychange","resize"]),this.defaultClock=new To,this._clocks=[],this.deltaTime=0,this.canvas=null,this.gl=null,this.programs={},this.activeProgram=null,this._canvasSize=[0,0],this._params={anisotropy:t.anisotropy||4,width:t.width||256,height:t.height||256,pixelRatio:Ke("og_dpi")||t.pixelRatio||1,extensions:t.extensions||[],context:t.context||{}},this._oneByHeight=1/(this._params.height*this._params.pixelRatio),this.extensions={},this._canvasTarget=e,this._lastAnimationFrameTime=0,this._initialized=!1,this._frameCallback=function(){},this.transparentTexture=null,this.defaultTexture=null,this.framebufferStack=new Ao,this.createTexture_n=this.createTexture_n_webgl2.bind(this),this.createTexture_l=this.createTexture_l_webgl2.bind(this),this.createTexture_mm=this.createTexture_mm_webgl2.bind(this),this.createTexture_a=this.createTexture_a_webgl2.bind(this),this.createTexture={NEAREST:this.createTexture_n,LINEAR:this.createTexture_l,MIPMAP:this.createTexture_mm,ANISOTROPIC:this.createTexture_a},this.createTextureDefault=this.createTexture_n,this.ONCANVASRESIZE=null,this._createCanvas(),(t.autoActivate||de(t.autoActivate))&&this.initialize()}isInitialized(){return this._initialized}_createCanvas(){this._canvasTarget?this._canvasTarget instanceof HTMLElement?this.canvas=this._canvasTarget:this.canvas=document.getElementById(this._canvasTarget)||document.querySelector(this._canvasTarget):(this.canvas=document.createElement("canvas"),this.canvas.width=this._params.width,this.canvas.height=this._params.height)}static getExtension(e,t){if(!e)return;let i,n;for(i in Eo)if(n=e.getExtension(Eo[i]+t),n)return n}static getContext(e,t){let i=null;try{let n=new URLSearchParams(location.search).get("og_ver");if(n)i=e.getContext(n,t),i&&(i.type=n);else for(let n=0;n<Po.length;n++)if(i=e.getContext(Po[n],t),i){i.type=Po[n];break}}catch(e){Mi.logErr("exception during the GL context initialization")}return i||Mi.logErr("could not initialise WebGL"),i}setFrameCallback(e){e&&(this._frameCallback=e)}createEmptyTexture2DExt(e=1,t=1,i="NEAREST",n="RGBA",r="RGBA",s="UNSIGNED_BYTE",a=0){let o=this.gl,l=o.createTexture();return o.bindTexture(o.TEXTURE_2D,l),o.texImage2D(o.TEXTURE_2D,a,o[n.toUpperCase()],e,t,0,o[r.toUpperCase()],o[s.toUpperCase()],null),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o[i.toUpperCase()]),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o[i.toUpperCase()]),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.bindTexture(o.TEXTURE_2D,null),l}createEmptyTexture_n(e,t,i){let n=this.gl,r=n.createTexture();return n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,i||n.RGBA,e,t,0,n.RGBA,n.UNSIGNED_BYTE,null),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),r}createEmptyTexture_l(e,t,i){let n=this.gl,r=n.createTexture();return n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,i||n.RGBA,e,t,0,n.RGBA,n.UNSIGNED_BYTE,null),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),r}createTexture_n_webgl1(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_l_webgl1(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_mm_webgl1(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_a_webgl1(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameterf(n.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_n_webgl2(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texStorage2D(n.TEXTURE_2D,1,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_l_webgl2(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texStorage2D(n.TEXTURE_2D,1,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_mm_webgl2(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texStorage2D(n.TEXTURE_2D,2,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_a_webgl2(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texStorage2D(n.TEXTURE_2D,2,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameterf(n.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}loadCubeMapTexture(e){let t=this.gl,i=t.createTexture();t.bindTexture(t.TEXTURE_CUBE_MAP,i),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,t.LINEAR);let n=[[e.px,t.TEXTURE_CUBE_MAP_POSITIVE_X],[e.nx,t.TEXTURE_CUBE_MAP_NEGATIVE_X],[e.py,t.TEXTURE_CUBE_MAP_POSITIVE_Y],[e.ny,t.TEXTURE_CUBE_MAP_NEGATIVE_Y],[e.pz,t.TEXTURE_CUBE_MAP_POSITIVE_Z],[e.nz,t.TEXTURE_CUBE_MAP_NEGATIVE_Z]],r=new Ys;r.fillEmpty();let s=r.getImage();for(let e=0;e<n.length;e++){let r=n[e][1];t.bindTexture(t.TEXTURE_CUBE_MAP,i),t.texImage2D(r,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,s)}for(let e=0;e<n.length;e++){let r=n[e][1],s=new Image;s.crossOrigin="",s.onload=function(e,i,n){return function(){t&&e&&(t.bindTexture(t.TEXTURE_CUBE_MAP,e),t.texImage2D(i,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,n))}}(i,r,s),s.src=n[e][0]}return i}addProgram(e,t=!1){if(this.programs[e.name])console.warn(`Shader program: "${e.name}" already exists.`);else{let i=new Co(this,e);this.programs[e.name]=i,this._initProgramController(i),t&&(i._activated=!1)}return e}removeProgram(e){this.programs[e]&&this.programs[e].remove()}addPrograms(e){for(let t=0;t<e.length;t++)this.addProgram(e[t])}_initProgramController(e){this._initialized&&(e.initialize(),this.activeProgram?(e.deactivate(),this.activeProgram._program.enableAttribArrays(),this.activeProgram._program.use()):(this.activeProgram=e,e.activate()))}_initPrograms(){for(let e in this.programs)this._initProgramController(this.programs[e])}initializeExtension(e,t=!1){if(!this.extensions||!this.extensions[e]){let i=Mo.getExtension(this.gl,e);i?this.extensions[e]=i:t&&console.warn("og.webgl.Handler: extension '"+e+"' doesn't initialize.")}return this.extensions&&this.extensions[e]}initialize(){if(this._initialized)return;if(!this.canvas)return;if(this.gl=Mo.getContext(this.canvas,this._params.context),!this.gl)return;this._initialized=!0,this._params.extensions.push("EXT_texture_filter_anisotropic"),"webgl"===this.gl.type?(this._params.extensions.push("OES_standard_derivatives"),this._params.extensions.push("OES_element_index_uint"),this._params.extensions.push("WEBGL_depth_texture"),this._params.extensions.push("ANGLE_instanced_arrays")):(this._params.extensions.push("EXT_color_buffer_float"),this._params.extensions.push("OES_texture_float_linear"));let e=this._params.extensions.length;for(;e--;)this.initializeExtension(this._params.extensions[e],!0);"webgl"===this.gl.type?(this.createTexture_n=this.createTexture_n_webgl1.bind(this),this.createTexture_l=this.createTexture_l_webgl1.bind(this),this.createTexture_mm=this.createTexture_mm_webgl1.bind(this),this.createTexture_a=this.createTexture_a_webgl1.bind(this)):(this.createTexture_n=this.createTexture_n_webgl2.bind(this),this.createTexture_l=this.createTexture_l_webgl2.bind(this),this.createTexture_mm=this.createTexture_mm_webgl2.bind(this),this.createTexture_a=this.createTexture_a_webgl2.bind(this)),this.createTexture.NEAREST=this.createTexture_n,this.createTexture.LINEAR=this.createTexture_l,this.createTexture.MIPMAP=this.createTexture_mm,this.createTexture.ANISOTROPIC=this.createTexture_a,this.extensions.EXT_texture_filter_anisotropic?this.createTextureDefault=this.createTexture_a:this.createTextureDefault=this.createTexture_mm,this._initPrograms(),this._setDefaults(),this.intersectionObserver=new IntersectionObserver((e=>{this._toggleVisibilityChange(e[0].isIntersecting)}),{threshold:0}),this.intersectionObserver.observe(this.canvas),this.resizeObserver=new ResizeObserver((e=>{this._toggleVisibilityChange(0!==e[0].contentRect.width&&0!==e[0].contentRect.height)})),this.resizeObserver.observe(this.canvas),document.addEventListener("visibilitychange",(()=>{this._toggleVisibilityChange("visible"===document.visibilityState)}))}_toggleVisibilityChange(e){e?(this.start(),this.ONCANVASRESIZE&&this.ONCANVASRESIZE(),this.events.dispatch(this.events.visibilitychange,!0)):(this.events.dispatch(this.events.visibilitychange,!1),this.stop())}_setDefaults(){let e=this.gl;e&&this.canvas&&(e.depthFunc(e.LESS),e.enable(e.DEPTH_TEST),this.setSize(this.canvas.clientWidth||this._params.width,this.canvas.clientHeight||this._params.height),e.frontFace(e.CCW),e.cullFace(e.BACK),e.enable(e.CULL_FACE),e.disable(e.BLEND),this.createDefaultTexture({color:"rgba(0,0,0,0.0)"},(e=>{this.transparentTexture=e})),this.createDefaultTexture({color:"rgba(255, 255, 255, 1.0)"},(e=>{this.defaultTexture=e})))}getCanvasSize(){return this._canvasSize}createStreamArrayBuffer(e,t,i,n=4){let r=this.gl,s=r.createBuffer();return r.bindBuffer(r.ARRAY_BUFFER,s),r.bufferData(r.ARRAY_BUFFER,t*e*n,i||r.STREAM_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),s.itemSize=e,s.numItems=t,s}setStreamArrayBuffer(e,t,i=0){let n=this.gl;return n.bindBuffer(n.ARRAY_BUFFER,e),n.bufferSubData(n.ARRAY_BUFFER,i,t),n.bindBuffer(n.ARRAY_BUFFER,null),e}createArrayBuffer(e,t,i,n){let r=this.gl,s=r.createBuffer();return r.bindBuffer(r.ARRAY_BUFFER,s),r.bufferData(r.ARRAY_BUFFER,e,n||r.STATIC_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),s.itemSize=t,s.numItems=i,s}createArrayBufferLength(e,t){let i=this.gl,n=i.createBuffer();return i.bindBuffer(i.ARRAY_BUFFER,n),i.bufferData(i.ARRAY_BUFFER,e,t||i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),n.itemSize=1,n.numItems=e,n}createElementArrayBuffer(e,t,i,n){let r=this.gl,s=r.createBuffer();return r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,s),r.bufferData(r.ELEMENT_ARRAY_BUFFER,e,n||r.STATIC_DRAW),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,null),s.itemSize=t,s.numItems=i||e.length,s}setSize(e,t){this._params.width=e,this._params.height=t,this.canvas&&(this.canvas.width=e*this._params.pixelRatio,this.canvas.height=t*this._params.pixelRatio,this._canvasSize[0]=this.canvas.width,this._canvasSize[1]=this.canvas.height,this._oneByHeight=1/this.canvas.height,this.gl&&this.gl.viewport(0,0,e,t),this.ONCANVASRESIZE&&this.ONCANVASRESIZE(this.canvas),this.events.dispatch(this.events.resize,this))}get pixelRatio(){return this._params.pixelRatio}set pixelRatio(e){this._params.pixelRatio=e,this.setSize(this._params.width,this._params.height)}getWidth(){return this.canvas?this.canvas.width:0}getHeight(){return this.canvas?this.canvas.height:0}getClientAspect(){return this.canvas?this.canvas.clientWidth/this.canvas.clientHeight:0}getCenter(){let e=this.canvas;return e?new le(Math.round(.5*e.width),Math.round(.5*e.height)):new le}drawFrame(){let e=window.performance.now();this.deltaTime=e-this._lastAnimationFrameTime,this._lastAnimationFrameTime=e,this.defaultClock.tick(this.deltaTime);for(let e=0;e<this._clocks.length;e++)this._clocks[e].tick(this.deltaTime);let t=this.canvas;Math.floor(t.clientWidth*this._params.pixelRatio)===t.width&&Math.floor(t.clientHeight*this._params.pixelRatio)===t.height||(0===t.clientWidth||0===t.clientHeight?this.stop():document.hidden||(this.start(),this.setSize(t.clientWidth,t.clientHeight))),this._frameCallback()}clearFrame(){let e=this.gl;e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}start(){!this._requestAnimationFrameId&&this._initialized&&this._animationFrameCallback()}stop(){this._requestAnimationFrameId&&(window.cancelAnimationFrame(this._requestAnimationFrameId),this._requestAnimationFrameId=0)}isStopped(){return!this._requestAnimationFrameId}isWebGl2(){return!!this.gl&&"webgl2"===this.gl.type}_animationFrameCallback(){this._requestAnimationFrameId=window.requestAnimationFrame((()=>{this.drawFrame(),this._requestAnimationFrameId&&this._animationFrameCallback()}))}createDefaultTexture(e,t){let i,n;if(e&&e.color)i=new Ys(2,2),i.fillColor(e.color),n=this.createTexture_n(i.getCanvas()),n.default=!0,t(n);else if(e&&e.url){let i=new Image,r=this;i.onload=function(){n=r.createTextureDefault(i),n.default=!0,t(n)},i.src=e.url}else i=new Ys(2,2),i.fillColor("#C5C5C5"),n=this.createTexture_n(i.getCanvas()),n.default=!0,t(n)}deleteTexture(e){e&&!e.default&&this.gl.deleteTexture(e)}destroy(){this.resizeObserver?.disconnect(),this.intersectionObserver?.disconnect(),this.stop();for(let e in this.programs)this.removeProgram(e);let e=this.gl;if(e){e.deleteTexture(this.transparentTexture),this.transparentTexture=null,e.deleteTexture(this.defaultTexture),this.defaultTexture=null,this.framebufferStack=new Ao;let t=e.getParameter(e.MAX_VERTEX_ATTRIBS),i=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,i);for(let i=0;i<t;++i)e.disableVertexAttribArray(i),e.vertexAttribPointer(i,4,e.FLOAT,!1,0,0),e.vertexAttrib1f(i,0);e.deleteBuffer(i);let n=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS);for(let t=0;t<n;++t)e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_CUBE_MAP,null),e.bindTexture(e.TEXTURE_2D,null);e.activeTexture(e.TEXTURE0),e.useProgram(null),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindRenderbuffer(e.RENDERBUFFER,null),e.disable(e.BLEND),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.DITHER),e.disable(e.SCISSOR_TEST),e.blendColor(0,0,0,0),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ZERO),e.clearColor(0,0,0,0),e.clearDepth(1),e.clearStencil(-1)}this.canvas&&(this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.canvas.width=1,this.canvas.height=1,this.canvas=null),this.gl=null,this._initialized=!1}addClock(e){e.__handler||(e.__handler=this,this._clocks.push(e))}addClocks(e){for(let t=0;t<e.length;t++)this.addClock(e[t])}removeClock(e){if(e.__handler){let t=this._clocks,i=t.length;for(;i--;)if(t[i].isEqual(e)){e.__handler=null,t.splice(i,1);break}}}}class So extends js{constructor(e,t={}){super(e,t),this._internalFormat=t.internalFormat?t.internalFormat.toUpperCase():"RGBA8",this._msaa=null!=t.msaa?t.msaa:4,this._glFilter=0,this.renderbuffers=new Array(this._size)}destroy(){let e=this.handler.gl;if(e){for(let t=0;t<this.renderbuffers.length;t++)e.deleteRenderbuffer(this.renderbuffers[t]);this.renderbuffers=new Array(this._size),e.deleteFramebuffer(this._fbo),e.deleteRenderbuffer(this._depthRenderbuffer),this._depthRenderbuffer=null,this._fbo=null,this._active=!1}}init(){let e=this.handler.gl;if(!e)return;this._glFilter=e[this._filter],this._fbo=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo);let t=[];for(let i=0;i<this.renderbuffers.length;i++){let n=e.createRenderbuffer();e.bindRenderbuffer(e.RENDERBUFFER,n),this._msaa>0?e.renderbufferStorageMultisample(e.RENDERBUFFER,this._msaa,e[this._internalFormat],this._width,this._height):e.renderbufferStorage(e.RENDERBUFFER,e[this._internalFormat],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+i,e.RENDERBUFFER,n),t.push(e.COLOR_ATTACHMENT0+i),this.renderbuffers[i]=n,e.bindRenderbuffer(e.RENDERBUFFER,null)}e.drawBuffers(t),this._useDepth&&(this._depthRenderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this._depthRenderbuffer),e.renderbufferStorageMultisample(e.RENDERBUFFER,this._msaa,e[this._depthComponent],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,this._depthRenderbuffer),e.bindRenderbuffer(e.RENDERBUFFER,null)),e.bindFramebuffer(e.FRAMEBUFFER,null)}blitTo(e,t=0){let i=this.handler.gl;i.bindFramebuffer(i.READ_FRAMEBUFFER,this._fbo),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,e._fbo),i.readBuffer(i.COLOR_ATTACHMENT0+t),i.clearBufferfv(i.COLOR,0,[0,0,0,1]),i.blitFramebuffer(0,0,this._width,this._height,0,0,e._width,e._height,i.COLOR_BUFFER_BIT,this._glFilter),i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindFramebuffer(i.READ_FRAMEBUFFER,null),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,null)}}var Bo=Object.freeze({__proto__:null,Framebuffer:qs,Handler:Mo,Multisample:So,Program:zi,types:Bi});const ko=function(e,t){return Number(e.priority<t.priority)};class Ro{constructor(){this._currentlyPressedKeys={},this._pressedKeysCallbacks={},this._unpressedKeysCallbacks={},this._charkeysCallbacks={},this._anykeyCallback=null,this._event=null,this._active=!0,this._stampCache={},document.onkeydown=e=>{this._event=e,this._active&&this.handleKeyDown()},document.onkeyup=e=>{this._event=e,this._active&&this.handleKeyUp()}}getcurrentlyPressedKeys(){return this._currentlyPressedKeys}getPressedKeysCallbacks(){return this._pressedKeysCallbacks}getUnpressedKeysCallbacks(){return this._unpressedKeysCallbacks}getCharkeysCallbacks(){return this._charkeysCallbacks}removeEvent(e,t,i){let n=this._getStamp(e,t,i._openglobus_id);i._openglobus_id&&this._stampCache[n]&&(delete this._stampCache[n],"keypress"===e?this._removeCallback(this._pressedKeysCallbacks[t],i):"keyfree"===e?this._removeCallback(this._unpressedKeysCallbacks[t],i):"charkeypress"===e&&this._removeCallback(this._charkeysCallbacks[t],i))}_removeCallback(e,t){for(let i=0;i<e.length;i++)e[i].callback._openglobus_id===t._openglobus_id&&e.splice(i,1)}_getStamp(e,t,i){return`${e}_${t}_${i}`}_stamp(e,t,i){const n=fe(i),r=this._getStamp(e,t,n);return!this._stampCache[r]&&(this._stampCache[r]=n,!0)}setActivity(e){this._active=e}releaseKeys(){this._currentlyPressedKeys={}}addEvent(e,t,i,n,r){if(this._stamp(e,t,i))switch(void 0===r&&(r=1600),e){case"keyfree":this._unpressedKeysCallbacks[t]||(this._unpressedKeysCallbacks[t]=[]),this._unpressedKeysCallbacks[t].push({callback:i,sender:n,priority:r}),this._unpressedKeysCallbacks[t].sort(ko);break;case"keypress":null==t?this._anykeyCallback={callback:i,sender:n||this}:(this._pressedKeysCallbacks[t]||(this._pressedKeysCallbacks[t]=[]),this._pressedKeysCallbacks[t].push({callback:i,sender:n,priority:r}),this._pressedKeysCallbacks[t].sort(ko));break;case"charkeypress":this._charkeysCallbacks[t]||(this._charkeysCallbacks[t]=[]),this._charkeysCallbacks[t].push({callback:i,sender:n,priority:r}),this._charkeysCallbacks[t].sort(ko)}}isKeyPressed(e){return this._currentlyPressedKeys[e]}handleKeyDown(){this._anykeyCallback&&this._anykeyCallback.callback.call(this._anykeyCallback.sender,this._event),this._currentlyPressedKeys[this._event.keyCode]=!0;for(let e in this._charkeysCallbacks)if(String.fromCharCode(this._event.keyCode)===String.fromCharCode(Number(e))){let t=this._charkeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}this._event.keyCode!=dr.KEY_ALT&&this._event.keyCode!=dr.KEY_SHIFT||this._event.preventDefault()}handleKeyUp(){if(this._currentlyPressedKeys[this._event.keyCode]||this._event.keyCode===dr.KEY_PRINTSCREEN)for(let e in this._unpressedKeysCallbacks)if(this._currentlyPressedKeys[e]||this._event.keyCode===dr.KEY_PRINTSCREEN&&Number(e)===dr.KEY_PRINTSCREEN){let t=this._unpressedKeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}this._currentlyPressedKeys[this._event.keyCode]=!1}handleEvents(){for(let e in this._pressedKeysCallbacks)if(this._currentlyPressedKeys[e]){let t=this._pressedKeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}}}class Io{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"mousewheel":this._htmlObject.addEventListener("wheel",(function(e){let n=e.deltaY||e.detail||e.wheelDelta||0;null==e.wheelDelta&&(e.wheelDelta=-120*n),i.call(t,e),e.preventDefault()}),!1);break;case"mousedown":this._htmlObject.addEventListener("mousedown",(function(e){let n=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-n.left,clientY:e.clientY-n.top})})),this._htmlObject.addEventListener("contextmenu",(function(e){return e.preventDefault(),!1}));break;case"mouseup":this._htmlObject.addEventListener("mouseup",(function(e){let n=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-n.left,clientY:e.clientY-n.top})}));break;case"mousemove":this._htmlObject.addEventListener("mousemove",(function(e){let n=this.getBoundingClientRect();i.call(t,e,{clientX:e.clientX-n.left,clientY:e.clientY-n.top})}));break;case"mouseleave":this._htmlObject.addEventListener("mouseleave",(function(e){i.call(t,e)}));break;case"mouseout":this._htmlObject.addEventListener("mouseout",(function(e){i.call(t,e)}));break;case"mouseover":this._htmlObject.addEventListener("mouseover",(function(e){i.call(t,e)}));break;case"mouseenter":this._htmlObject.addEventListener("mouseenter",(function(e){i.call(t,e)}))}}}class zo{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"touchcancel":this._htmlObject.addEventListener("touchcancel",(function(e){e.preventDefault();const n=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:n.left,offsetTop:n.top});i.call(t,r)}));break;case"touchstart":this._htmlObject.addEventListener("touchstart",(function(e){e.preventDefault();const n=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:n.left,offsetTop:n.top});i.call(t,r)}));break;case"touchend":this._htmlObject.addEventListener("touchend",(function(e){e.preventDefault();const n=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:n.left,offsetTop:n.top});i.call(t,r)}));break;case"touchmove":this._htmlObject.addEventListener("touchmove",(function(e){e.preventDefault();const n=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:n.left,offsetTop:n.top});i.call(t,r)}))}}}let Fo=new Uint8Array(4),Do=new Uint8Array(4),No=new Uint8Array(4);class Ho extends Mt{constructor(e){super(Oo),this.renderer=e,this._touchHandler=new zo(e.handler.canvas),this._mouseHandler=new Io(e.handler.canvas),this._keyboardHandler=new Ro,this._active=!0,this.clickRadius=15,this.mouseState={clientX:0,clientY:0,pos:new le,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new oe,leftButtonUp:!1,rightButtonUp:!1,middleButtonUp:!1,leftButtonDown:!1,rightButtonDown:!1,middleButtonDown:!1,leftButtonHold:!1,rightButtonHold:!1,middleButtonHold:!1,leftButtonDoubleClick:!1,rightButtonDoubleClick:!1,middleButtonDoubleClick:!1,leftButtonClick:!1,rightButtonClick:!1,middleButtonClick:!1,moving:!1,justStopped:!1,doubleClickDelay:500,clickDelay:200,wheelDelta:0,sys:null,pickingObject:null,renderer:e},this.touchState={moving:!1,touchEnd:!1,touchStart:!1,touchCancel:!1,doubleTouch:!1,doubleTouchDelay:550,doubleTouchRadius:10,clientX:0,clientY:0,pos:new le,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new oe,sys:null,pickingObject:null,renderer:e},this._isMouseInside=!1,this._entityPickingEventsActive=!0,this._dblTchCoords=new le,this._oneTouchStart=!1,this._dblTchBegins=0,this._mousestopThread=null,this._ldblClkBegins=0,this._rdblClkBegins=0,this._mdblClkBegins=0,this._lClkBegins=0,this._rClkBegins=0,this._mClkBegins=0,this._lclickX=0,this._lclickY=0,this._rclickX=0,this._rclickY=0,this._mclickX=0,this._mclickY=0}pointerEvent(){let e=this.mouseState,t=this.touchState;return e.moving||e.justStopped||t.moving||t.touchStart||t.touchEnd||0!==e.wheelDelta}get active(){return this._active}set active(e){this._active=e,this._keyboardHandler.setActivity(e)}handleEvents(){this._active&&(this.mouseState.direction=this.renderer.activeCamera.unproject(this.mouseState.x,this.mouseState.y),this.touchState.direction=this.renderer.activeCamera.unproject(this.touchState.x,this.touchState.y),this._keyboardHandler.handleEvents(),this.handleMouseEvents(),this.handleTouchEvents(),this.entityPickingEvents())}on(e,t,i,n,r){"keypress"===e||"charkeypress"===e||"keyfree"===e?this._keyboardHandler.addEvent(e,t,i,n,r):super.on(e,t,i,n)}off(e,t,i){"keypress"===e||"charkeypress"===e||"keyfree"===e?this._keyboardHandler.removeEvent(e,t,i):super.off(e,t)}isKeyPressed(e){return this._keyboardHandler.isKeyPressed(e)}releaseKeys(){this._keyboardHandler.releaseKeys()}initialize(){this._mouseHandler.setEvent("mouseup",this,this.onMouseUp),this._mouseHandler.setEvent("mousemove",this,this.onMouseMove),this._mouseHandler.setEvent("mousedown",this,this.onMouseDown),this._mouseHandler.setEvent("mousewheel",this,this.onMouseWheel),this._mouseHandler.setEvent("mouseleave",this,this.onMouseLeave),this._mouseHandler.setEvent("mouseenter",this,this.onMouseEnter),this._touchHandler.setEvent("touchstart",this,this.onTouchStart),this._touchHandler.setEvent("touchend",this,this.onTouchEnd),this._touchHandler.setEvent("touchcancel",this,this.onTouchCancel),this._touchHandler.setEvent("touchmove",this,this.onTouchMove)}onMouseWheel(e){this.mouseState.sys=e,this.mouseState.wheelDelta=e.wheelDelta||0}updateButtonsStates(e){let t=this.mouseState;1&e&&t.leftButtonDown?t.leftButtonDown=!0:(t.leftButtonHold=!1,t.leftButtonDown=!1),2&e&&t.rightButtonDown?t.rightButtonDown=!0:(t.rightButtonHold=!1,t.rightButtonDown=!1),4&e&&t.middleButtonDown?t.middleButtonDown=!0:(t.middleButtonHold=!1,t.middleButtonDown=!1)}onMouseMove(e,t){let i=this.mouseState;this.updateButtonsStates(e.buttons),i.sys=e;let n=t.clientX,r=t.clientY,s=this.clickRadius;if(Math.abs(this._lclickX-n)>=s&&Math.abs(this._lclickY-r)>=s&&(this._ldblClkBegins=0,this._lClkBegins=0),Math.abs(this._rclickX-n)>=s&&Math.abs(this._rclickY-r)>=s&&(this._rdblClkBegins=0,this._rClkBegins=0),Math.abs(this._mclickX-n)>=s&&Math.abs(this._mclickY-r)>=s&&(this._mdblClkBegins=0,this._mClkBegins=0),i.clientX===t.clientX&&i.clientY===t.clientY)return;i.clientX=t.clientX,i.clientY=t.clientY;let a=this.renderer.handler;i.pos.x=i.x=t.clientX*a.pixelRatio,i.pos.y=i.y=t.clientY*a.pixelRatio,i.nx=i.x/a.canvas.width,i.ny=i.y/a.canvas.height,i.moving=!0,clearTimeout(this._mousestopThread),this._mousestopThread=setTimeout((function(){i.justStopped=!0}),100)}onMouseLeave(e){this._isMouseInside=!1,this.mouseState.sys=e,this.dispatch(this.mouseleave,this.mouseState)}onMouseEnter(e){this._isMouseInside=!0,this.mouseState.sys=e,this.dispatch(this.mouseenter,this.mouseState)}onMouseDown(e,t){t.button===dr.MB_LEFT?(this._lClkBegins=window.performance.now(),this._lclickX=t.clientX,this._lclickY=t.clientY,this.mouseState.sys=e,this.mouseState.leftButtonDown=!0):t.button===dr.MB_RIGHT?(this._rClkBegins=window.performance.now(),this._rclickX=t.clientX,this._rclickY=t.clientY,this.mouseState.sys=e,this.mouseState.rightButtonDown=!0):t.button===dr.MB_MIDDLE&&(this._mClkBegins=window.performance.now(),this._mclickX=t.clientX,this._mclickY=t.clientY,this.mouseState.sys=e,this.mouseState.middleButtonDown=!0)}onMouseUp(e,t){let i=this.mouseState;i.sys=e;let n=window.performance.now();if(t.button===dr.MB_LEFT){if(i.leftButtonDown=!1,i.leftButtonUp=!0,Math.abs(this._lclickX-t.clientX)<this.clickRadius&&Math.abs(this._lclickY-t.clientY)<this.clickRadius&&n-this._lClkBegins<=i.clickDelay){if(this._ldblClkBegins){window.performance.now()-this._ldblClkBegins<=i.doubleClickDelay&&(i.leftButtonDoubleClick=!0),this._ldblClkBegins=0}else this._ldblClkBegins=window.performance.now();i.leftButtonClick=!0,this._lClkBegins=0}}else if(t.button===dr.MB_RIGHT){if(i.rightButtonDown=!1,i.rightButtonUp=!0,Math.abs(this._rclickX-t.clientX)<this.clickRadius&&Math.abs(this._rclickY-t.clientY)<this.clickRadius&&n-this._rClkBegins<=i.clickDelay){if(this._rdblClkBegins){window.performance.now()-this._rdblClkBegins<=i.doubleClickDelay&&(i.rightButtonDoubleClick=!0),this._rdblClkBegins=0}else this._rdblClkBegins=window.performance.now();i.rightButtonClick=!0,this._rClkBegins=0}}else if(t.button===dr.MB_MIDDLE&&(i.middleButtonDown=!1,i.middleButtonUp=!0,Math.abs(this._mclickX-t.clientX)<this.clickRadius&&Math.abs(this._mclickY-t.clientY)<this.clickRadius&&n-this._mClkBegins<=i.clickDelay)){if(this._mdblClkBegins){window.performance.now()-this._mdblClkBegins<=i.doubleClickDelay&&(i.middleButtonDoubleClick=!0),this._mdblClkBegins=0}else this._mdblClkBegins=window.performance.now();i.middleButtonClick=!0,this._mClkBegins=0}}onTouchStart(e){let t=this.touchState;t.sys=e,t.clientX=e.touches.item(0).clientX-e.offsetLeft,t.clientY=e.touches.item(0).clientY-e.offsetTop;let i=this.renderer.handler;t.pos.x=t.x=t.clientX*i.pixelRatio,t.pos.y=t.y=t.clientY*i.pixelRatio,t.nx=t.x/i.canvas.width,t.ny=t.y/i.canvas.height,t.prev_x=t.x,t.prev_y=t.y,t.touchStart=!0,1===e.touches.length?(this._dblTchCoords.x=t.x,this._dblTchCoords.y=t.y,this._oneTouchStart=!0):this._oneTouchStart=!1}onTouchEnd(e){let t=this.touchState;if(t.sys=e,t.touchEnd=!0,0===e.touches.length&&(t.prev_x=t.x,t.prev_y=t.y,this._oneTouchStart)){if(this._dblTchBegins){window.performance.now()-this._dblTchBegins<=t.doubleTouchDelay&&(t.doubleTouch=!0),this._dblTchBegins=0}this._dblTchBegins=window.performance.now(),this._oneTouchStart=!1}}onTouchCancel(e){let t=this.touchState;t.sys=e,t.touchCancel=!0}onTouchMove(e){let t=this.touchState;t.clientX=e.touches.item(0).clientX-e.offsetLeft,t.clientY=e.touches.item(0).clientY-e.offsetTop;let i=this.renderer.handler;t.x=t.clientX*i.pixelRatio,t.y=t.clientY*i.pixelRatio,t.nx=t.x/i.canvas.width,t.ny=t.y/i.canvas.height,t.sys=e,t.moving=!0;let n=t.x-t.prev_x,r=t.y-t.prev_y;(Math.abs(n)>9||Math.abs(r)>9)&&(this._dblTchBegins=0,this._oneTouchStart=!1)}entityPickingEvents(){let e=this.touchState,t=this.mouseState;if(this._isMouseInside!==this._entityPickingEventsActive&&(this._entityPickingEventsActive=this._isMouseInside,!this._entityPickingEventsActive)){let i=this.renderer,n=Fo,r=i.getPickingObjectArr(n);if(r){let i=r.rendererEvents;t.pickingObject=r,i&&i.dispatch(i.mouseleave,t),e.pickingObject=r,i&&i.dispatch(i.touchleave,e)}Fo[0]=Fo[1]=Fo[2]=Fo[3]=No[0]=No[1]=No[2]=No[3]=Do[0]=Do[1]=Do[2]=Do[3]=0}if(this._isMouseInside&&!(t.leftButtonHold||t.rightButtonHold||t.middleButtonHold)){let i=this.renderer,n=Fo,r=No,s=Do;e.x||e.y?i.readPickingColor(e.nx,1-e.ny,s):i.readPickingColor(t.nx,1-t.ny,s),r[0]=n[0],r[1]=n[1],r[2]=n[2],n[0]=s[0],n[1]=s[1],n[2]=s[2],t.pickingObject=null,e.pickingObject=null;let a=i.getPickingObjectArr(n);if(t.pickingObject=a,e.pickingObject=a,n[0]!==r[0]||n[1]!==r[1]||n[2]!==r[2])if((e=>!(e[0]||e[1]||e[2]))(n)){let n=i.getPickingObjectArr(r);if(n){let i=n.rendererEvents;t.pickingObject=n,i&&i.dispatch(i.mouseleave,t),e.pickingObject=n,i&&i.dispatch(i.touchleave,e)}}else{if((e=>!!(e[0]||e[1]||e[2]))(r)){let n=i.getPickingObjectArr(r);if(n){let i=n.rendererEvents;t.pickingObject=n,i&&i.dispatch(i.mouseleave,t),e.pickingObject=n,i&&i.dispatch(i.touchleave,e)}}if(a){let i=a.rendererEvents;t.pickingObject=a,i&&i.dispatch(i.mouseenter,t),e.pickingObject=a,i&&i.dispatch(i.touchenter,e)}}}}handleMouseEvents(){let e=this,t=this.mouseState,i=t.pickingObject,n=null;t.leftButtonClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.lclick,t)),this.dispatch(e.lclick,t),t.leftButtonClick=!1),t.rightButtonClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.rclick,t)),this.dispatch(e.rclick,t),t.rightButtonClick=!1),t.middleButtonClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.mclick,t)),this.dispatch(e.mclick,t),t.middleButtonClick=!1),t.leftButtonDown&&(t.leftButtonHold?(i&&(n=i.rendererEvents,n&&n.dispatch(n.lhold,t)),this.dispatch(e.lhold,t)):(t.leftButtonHold=!0,i&&(n=i.rendererEvents,n&&n.dispatch(n.ldown,t)),this.dispatch(e.ldown,t))),t.rightButtonDown&&(t.rightButtonHold?(i&&(n=i.rendererEvents,n&&n.dispatch(n.rhold,t)),this.dispatch(e.rhold,t)):(t.rightButtonHold=!0,i&&(n=i.rendererEvents,n&&n.dispatch(n.rdown,t)),this.dispatch(e.rdown,t))),t.middleButtonDown&&(t.middleButtonHold?(i&&(n=i.rendererEvents,n&&n.dispatch(n.mhold,t)),this.dispatch(e.mhold,t)):(t.middleButtonHold=!0,i&&(n=i.rendererEvents,n&&n.dispatch(n.mdown,t)),this.dispatch(e.mdown,t))),t.leftButtonUp&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.lup,t)),this.dispatch(e.lup,t),t.leftButtonUp=!1,t.leftButtonHold=!1),t.rightButtonUp&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.rup,t)),this.dispatch(e.rup,t),t.rightButtonUp=!1,t.rightButtonHold=!1),t.middleButtonUp&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.mup,t)),this.dispatch(e.mup,t),t.middleButtonUp=!1,t.middleButtonHold=!1),t.leftButtonDoubleClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.ldblclick,t)),this.dispatch(e.ldblclick,t),t.leftButtonDoubleClick=!1),t.rightButtonDoubleClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.rdblclick,t)),this.dispatch(e.rdblclick,t),t.rightButtonDoubleClick=!1),t.middleButtonDoubleClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.mdblclick,t)),this.dispatch(e.mdblclick,t),t.middleButtonDoubleClick=!1),t.wheelDelta&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.mousewheel,t)),this.dispatch(e.mousewheel,t)),t.moving&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.mousemove,t)),this.dispatch(e.mousemove,t),t.prev_x=t.x,t.prev_y=t.y),t.justStopped&&this.dispatch(e.mousestop,t)}handleTouchEvents(){let e=this,t=this.touchState,i=t.pickingObject,n=null;if(t.touchCancel&&(this.dispatch(e.touchcancel,t),t.touchCancel=!1),t.touchStart){let r=this.renderer;r.pickingFramebuffer.activate(),r.pickingFramebuffer.readPixels(Fo,t.nx,1-t.ny,1),r.pickingFramebuffer.deactivate();let s=r.getPickingObjectArr(Fo);i=t.pickingObject=s,i&&(n=i.rendererEvents,n&&n.dispatch(n.touchstart,t)),this.dispatch(e.touchstart,t),t.touchStart=!1}t.doubleTouch&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.doubletouch,t)),this.dispatch(e.doubletouch,t),t.doubleTouch=!1),t.touchEnd&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.touchend,t)),this.dispatch(e.touchend,t),t.x=0,t.y=0,t.touchEnd=!1),t.moving&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.touchmove,t)),this.dispatch(e.touchmove,t),t.prev_x=t.x,t.prev_y=t.y)}}const Oo=["draw","drawtransparent","postdraw","resize","resizeend","mouseenter","mouseleave","mousemove","mousestop","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchstart","touchend","touchcancel","touchmove","doubletouch","touchleave","touchenter"];class Vo{constructor(e=0,t=0,i=0,n=0){this.left=e,this.right=i,this.top=t,this.bottom=n}set(e=0,t=0,i=0,n=0){this.left=e,this.right=i,this.top=t,this.bottom=n}clone(){return new Vo(this.left,this.top,this.right,this.bottom)}getWidth(){return Math.abs(this.right-this.left)}getHeight(){return Math.abs(this.bottom-this.top)}getSquare(){return this.getHeight()*this.getWidth()}getDiagonal(){let e=this.getWidth(),t=this.getHeight();return Math.sqrt(t*t+e*e)}fit(e,t){return this.getWidth()===e&&this.getHeight()===t}isInside(e,t){return e>=this.left&&e<=this.right&&t>=this.top&&t<=this.bottom}}class Uo{constructor(){this.imagesCache={},this._counter=0,this._pendingsQueue=new Rn,this._imageIndexCounter=0}load(e,t){if(this.imagesCache[e])t(this.imagesCache[e]);else{let i={src:e,success:t};this._counter>=1?this._pendingsQueue.unshift(i):this._exec(i)}}_exec(e){this._counter++;const t=this;let i=new Image;i.crossOrigin="",i.onload=function(){t.imagesCache[e.src]=i,i.__nodeIndex=t._imageIndexCounter++,e.success(i),t._dequeueRequest()},i.onerror=function(){t._dequeueRequest()},i.src=e.src}_dequeueRequest(){if(this._counter--,this._pendingsQueue.length&&this._counter<1)for(;this._pendingsQueue.length;){let e=this._pendingsQueue.pop();if(e){if(!this.imagesCache[e.src]){this._exec(e);break}this._counter<=0?this._counter=0:this._counter--,e.success(this.imagesCache[e.src])}}}}class Go{constructor(e=1024,t=1024){this.nodes=new Map,this.texture=null,this.canvas=new Ys(e,t),this.clearCanvas(),this._handler=null,this._images=[],this._btree=null,this._imagesCacheManager=new Uo,this.borderSize=4}getImage(){return this.canvas.getImage()}getCanvas(){return this.canvas.getCanvas()}clearCanvas(){this.canvas.fillEmpty()}assignHandler(e){this._handler=e,this.createTexture()}getDiagonal(e){let t=e.atlasWidth||e.width,i=e.atlasHeight||e.height;return Math.sqrt(t*t+i*i)}addImage(e,t=!1){if(e.width&&e.height)return this._images.push(e),this._makeAtlas(t),null!=e.__nodeIndex?this.get(e.__nodeIndex):void 0}_completeNode(e,t){if(t){let i=this.canvas.getWidth(),n=this.canvas.getHeight(),r=t.image,s=t.rect,a=Math.round(.5*this.borderSize);this.canvas.drawImage(r,s.left+a,s.top+a,r.atlasWidth||0,r.atlasHeight||0);let o=t.texCoords;o[0]=(s.left+a)/i,o[1]=(s.top+a)/n,o[2]=(s.left+a)/i,o[3]=(s.bottom-a)/n,o[4]=(s.right-a)/i,o[5]=(s.bottom-a)/n,o[6]=(s.right-a)/i,o[7]=(s.bottom-a)/n,o[8]=(s.right-a)/i,o[9]=(s.top+a)/n,o[10]=(s.left+a)/i,o[11]=(s.top+a)/n,e.set(r.__nodeIndex,t)}}_makeAtlas(e=!1){if(e&&this._btree){let e=this._images[this._images.length-1];this._completeNode(this.nodes,this._btree.insert(e))}else{let e=this._images.slice(0);e.sort((function(e,t){return(t.atlasWidth||t.width)-(e.atlasWidth||e.width)||(t.atlasHeight||t.height)-(e.atlasHeight||e.height)})),this._btree=new Wo(new Vo(0,0,this.canvas.getWidth(),this.canvas.getHeight())),this._btree.atlas=this,this.clearCanvas();let t=new Map;for(let i=0;i<e.length;i++)this._completeNode(t,this._btree.insert(e[i]));this.nodes=null,this.nodes=t}}get(e){return this.nodes.get(e)}set(e,t){this.nodes.set(e,t)}createTexture(e,t){this._handler&&(this._handler.gl.deleteTexture(this.texture),e&&(this.canvas.resize(e.width,e.height),this.canvas.drawImage(e,0,0,e.width,e.height)),this.texture=this._handler.createTexture_l(this.canvas.getCanvas(),t))}loadImage(e,t){this._imagesCacheManager.load(e,t)}getImageTexCoordinates(e){if(null!=e.__nodeIndex){let t=this.get(e.__nodeIndex);if(t)return t.texCoords}}}class Wo{constructor(e,t){this.childNodes=null,this.image=null,this.rect=e||new Vo,this.texCoords=t||[],this.atlas=null}insert(e){if(this.childNodes){let t=this.childNodes[0].insert(e);return t||this.childNodes[1].insert(e)}{if(null!=this.image)return;let t=this.rect;const i=(e.atlasWidth||e.width)+this.atlas.borderSize,n=(e.atlasHeight||e.height)+this.atlas.borderSize;if(i>t.getWidth()||n>t.getHeight())return;if(t.fit(i,n))return this.image=e,this;this.childNodes=new Array(2),this.childNodes[0]=new Wo,this.childNodes[0].atlas=this.atlas,this.childNodes[1]=new Wo,this.childNodes[1].atlas=this.atlas;return t.getWidth()-i>t.getHeight()-n?(this.childNodes[0].rect.set(t.left,t.top,t.left+i,t.bottom),this.childNodes[1].rect.set(t.left+i,t.top,t.right,t.bottom)):(this.childNodes[0].rect.set(t.left,t.top,t.right,t.top+n),this.childNodes[1].rect.set(t.left,t.top+n,t.right,t.bottom)),this.childNodes[0].insert(e)}}}class jo extends Go{constructor(e,t){super(e,t),this.width=0,this.height=0,this.gliphSize=0,this.distanceRange=0,this.nodes=new Map,this.kernings={}}get(e){return this.nodes.get(e)}}class Yo extends Wo{constructor(e,t){super(e,t),this.emptySize=1,this.metrics={id:0,char:"",width:0,height:0,x:0,y:0,chnl:0,index:0,page:0,xadvance:0,xoffset:0,yoffset:0,nChar:"",nCode:0,nWidth:0,nHeight:0,nAdvance:0,nXOffset:0,nYOffset:0}}}class qo{constructor(e){this.atlasesArr=[],this.atlasIndexes={},this.atlasIndexesDeferred={},this.tokenImageSize=64,this.samplerArr=new Uint32Array(11),this.sdfParamsArr=new Float32Array(44),this._handler=null,this.catalogSrc=e||"./"}assignHandler(e){this._handler=e}getFontIndex(e){let t=this.getFullIndex(e);return this.atlasIndexes[t]||this.loadFont(e,this.catalogSrc,`${e}.json`),this.atlasIndexesDeferred[t]||(this.atlasIndexesDeferred[t]=new as),this.atlasIndexesDeferred[t].promise}getFullIndex(e){return e.trim().toLowerCase()}_applyFontDataToAtlas(e,t,i=0){let n=t.chars;e.height=t.common.scaleH,e.width=t.common.scaleW,e.gliphSize=t.info.size,e.distanceRange=t.distanceField.distanceRange;let r=e.width,s=e.height,a=e.gliphSize;this.sdfParamsArr[4*i]=r,this.sdfParamsArr[4*i+1]=s,this.sdfParamsArr[4*i+2]=a,this.sdfParamsArr[4*i+3]=e.distanceRange;let o={};for(let t=0;t<n.length;t++){let i=n[t],l=i.char;o[i.id]=l;let h=new Vo(i.x,i.y,i.x+i.width,i.y+i.height),c=new Array(12);c[0]=h.left/r,c[1]=h.top/s,c[2]=h.left/r,c[3]=h.bottom/s,c[4]=h.right/r,c[5]=h.bottom/s,c[6]=h.right/r,c[7]=h.bottom/s,c[8]=h.right/r,c[9]=h.top/s,c[10]=h.left/r,c[11]=h.top/s;let d=new Yo(h,c),_=i.char.normalize("NFKC"),u=_.charCodeAt(0),f=d.metrics;f.id=i.id,f.char=i.char,f.width=i.width,f.height=i.height,f.x=i.x,f.y=i.y,f.chnl=i.chnl,f.index=i.index,f.page=i.page,f.xadvance=i.xadvance,f.xoffset=i.xoffset,f.yoffset=i.yoffset,f.nChar=_,f.nCode=u,f.nWidth=d.metrics.width/a,f.nHeight=d.metrics.height/a,f.nAdvance=d.metrics.xadvance/a,f.nXOffset=d.metrics.xoffset/a,f.nYOffset=1-d.metrics.yoffset/a,d.emptySize=1,e.nodes.set(_.charCodeAt(0),d)}e.kernings={};for(let i=0;i<t.kernings.length;i++){let n=t.kernings[i],r=n.first,s=n.second;e.kernings[r]||(e.kernings[r]={}),e.kernings[r][s]=n.amount/a}}initFont(e,t,i){let n=this.atlasesArr.length,r=this.getFullIndex(e);this.atlasIndexes[r]=n;let s=this.atlasIndexesDeferred[r];s||(s=this.atlasIndexesDeferred[r]=new as),this.samplerArr[this.atlasesArr.length]=n;let a=new jo;a.height=0,a.width=0,a.gliphSize=0,a.distanceRange=0,a.kernings={},a.assignHandler(this._handler),this.atlasesArr[n]=a,this._applyFontDataToAtlas(a,t,n);let o=new Image;o.onload=()=>{this._createTexture(a,o),s.resolve(n)},o.src=i}_createTexture(e,t){e.createTexture(t)}loadFont(e,t,i){let n=this.atlasesArr.length,r=this.getFullIndex(e);this.atlasIndexes[r]=n;let s=this.atlasIndexesDeferred[r];s||(s=this.atlasIndexesDeferred[r]=new as),this.samplerArr[this.atlasesArr.length]=n;let a=new jo;a.height=0,a.width=0,a.gliphSize=0,a.distanceRange=0,a.kernings={},a.assignHandler(this._handler),this.atlasesArr[n]=a,fetch(`${t}/${i}`).then((e=>{if(!e.ok)throw Error(`Unable to load "${t}/${i}"`);return e.json()})).then((e=>{this._applyFontDataToAtlas(a,e,n);let i=new Image;i.onload=()=>{this._createTexture(a,i),s.resolve(n)},i.src=`${t}/${e.pages[0]}`,i.crossOrigin="Anonymous"})).catch((e=>(s.reject(),{status:"error",msg:e.toString()})))}}let Xo=0,Zo=0,$o=0;function Ko(e,t,i){return new Promise(((n,r)=>{!function s(){const a=e.clientWaitSync(t,i,0);a==e.WAIT_FAILED?r():a==e.TIMEOUT_EXPIRED?requestAnimationFrame(s):n()}()}))}class Qo{constructor(e,t={}){if(this._readPickingBuffer_webgl1=()=>{this.pickingFramebuffer.activate(),this.pickingFramebuffer.readAllPixels(this._tempPickingPix_),this.pickingFramebuffer.deactivate()},this._readPickingBuffer_webgl2=()=>{const e=this.handler.gl,t=this._pickingPixelBuffer;if(!this._skipPickingFrame){this._skipPickingFrame=!0;let i=this._tempPickingPix_,n=this.pickingFramebuffer.width,r=this.pickingFramebuffer.height;this.pickingFramebuffer.activate(),e.bindBuffer(e.PIXEL_PACK_BUFFER,t),e.bufferData(e.PIXEL_PACK_BUFFER,i.byteLength,e.STREAM_READ),e.readPixels(0,0,n,r,e.RGBA,e.UNSIGNED_BYTE,0),e.bindBuffer(e.PIXEL_PACK_BUFFER,null),this.pickingFramebuffer.deactivate();const s=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);e.flush(),Ko(e,s,0).then((()=>{this._skipPickingFrame=!1,e.deleteSync(s),e.bindBuffer(e.PIXEL_PACK_BUFFER,t),e.getBufferSubData(e.PIXEL_PACK_BUFFER,0,i),e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}))}},this._readDistanceBuffer_webgl1=()=>{this.distanceFramebuffer.activate(),this.distanceFramebuffer.readAllPixels(this._tempDistancePix_),this.distanceFramebuffer.deactivate()},this._readDistanceBuffer_webgl2=()=>{const e=this.handler.gl,t=this._distancePixelBuffer;if(!this._skipDistanceFrame){this._skipDistanceFrame=!0;let i=this._tempDistancePix_,n=this.distanceFramebuffer.width,r=this.distanceFramebuffer.height;this.distanceFramebuffer.activate(),e.bindBuffer(e.PIXEL_PACK_BUFFER,t),e.bufferData(e.PIXEL_PACK_BUFFER,i.byteLength,e.STREAM_READ),e.readPixels(0,0,n,r,e.RGBA,e.UNSIGNED_BYTE,0),e.bindBuffer(e.PIXEL_PACK_BUFFER,null),this.distanceFramebuffer.deactivate();const s=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);e.flush(),Ko(e,s,0).then((()=>{this._skipDistanceFrame=!1,e.deleteSync(s),e.bindBuffer(e.PIXEL_PACK_BUFFER,t),e.getBufferSubData(e.PIXEL_PACK_BUFFER,0,i),e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}))}},this.div=null,this.handler=e,this.exposure=3.01,this.gamma=.47,this.whitepoint=1,this.brightThreshold=.9,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=null,this.events=new Ho(this),this.controls={},t.controls)for(let e in t.controls)this.controls[t.controls[e].name]=t.controls[e];this.controlsBag={},this.colorObjects=new Map,this._pickingCallbacks=[],this.pickingFramebuffer=null,this._tempPickingPix_=new Uint8Array([]),this.distanceFramebuffer=null,this._distanceCallbacks=[],this._tempDistancePix_=new Uint8Array([]),this._depthCallbacks=[],this.depthFramebuffer=null;let i=new URLSearchParams(location.search),n=i.get("og_msaa");this._msaa=n?Number(i.get("og_msaa")):null!=t.msaa?t.msaa:0,this._internalFormat="RGBA16F",this._format="RGBA",this._type="FLOAT",this.sceneFramebuffer=null,this.blitFramebuffer=null,this.toneMappingFramebuffer=null,this._initialized=!1,this.billboardsTextureAtlas=new Go,this.geoObjectsTextureAtlas=new Go,this.fontAtlas=new qo(t.fontsSrc),this._entityCollections=[],this._currentOutput="screen",this._fnScreenFrame=null,this.labelWorker=new ii(4),this.__useDistanceFramebuffer__=!0,this.screenDepthFramebuffer=null,this.screenFramePositionBuffer=null,this.screenTexture={},this.outputTexture=null,this._skipDistanceFrame=!1,this._distancePixelBuffer=null,this._skipPickingFrame=!1,this._pickingPixelBuffer=null,this._readDistanceBuffer=this._readDistanceBuffer_webgl2,this._readPickingBuffer=this._readPickingBuffer_webgl2,(t.autoActivate||de(t.autoActivate))&&this.start()}enableBlendOneSrcAlpha(){let e=this.handler.gl;e.enable(e.BLEND),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA)}enableBlendDefault(){let e=this.handler.gl;e.enable(e.BLEND),e.blendEquation(e.FUNC_ADD),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE)}setEventsActivity(e){this.events.active=e}addDepthCallback(e,t){let i=Zo++;return this._depthCallbacks.push({id:i,callback:t,sender:e}),i}removeDepthCallback(e){for(let t=0;t<this._depthCallbacks.length;t++)if(e===this._depthCallbacks[t].id){this._depthCallbacks.splice(t,1);break}}addDistanceCallback(e,t){let i=$o++;return this._distanceCallbacks.push({id:i,callback:t,sender:e}),i}removeDistanceCallback(e){for(let t=0;t<this._distanceCallbacks.length;t++)if(e===this._distanceCallbacks[t].id){this._distanceCallbacks.splice(t,1);break}}addPickingCallback(e,t){let i=Xo++;return this._pickingCallbacks.push({id:i,callback:t,sender:e}),i}removePickingCallback(e){for(let t=0;t<this._pickingCallbacks.length;t++)if(e===this._pickingCallbacks[t].id){this._pickingCallbacks.splice(t,1);break}}getPickingObject(e,t,i){return this.colorObjects.get(`${e}_${t}_${i}`)}getPickingObjectArr(e){return this.colorObjects.get(`${e[0]}_${e[1]}_${e[2]}`)}getPickingObject3v(e){return this.colorObjects.get(`${e.x}_${e.y}_${e.z}`)}assignPickingColor(e){if(!e._pickingColor||e._pickingColor.isZero()){let t=0,i=0,n=0,r="0_0_0";for(;!(t||i||n)||this.colorObjects.has(r);)t=y(1,255),i=y(1,255),n=y(1,255),r=`${t}_${i}_${n}`;e._pickingColor?e._pickingColor.set(t,i,n):e._pickingColor=new oe(t,i,n),e._pickingColorU=new Float32Array([t/255,i/255,n/255]),this.colorObjects.set(r,e)}}clearPickingColor(e){if(e._pickingColor&&!e._pickingColor.isZero()){let t=e._pickingColor;t.isZero()||(this.colorObjects.delete(`${t.x}_${t.y}_${t.z}`),t.x=t.y=t.z=0)}}getWidth(){return this.handler.canvas.clientWidth}getHeight(){return this.handler.canvas.clientHeight}getCenter(){let e=this.handler.canvas;return new le(Math.round(.5*e.width),Math.round(.5*e.height))}getClientCenter(){let e=this.handler.canvas;return new le(Math.round(.5*e.clientWidth),Math.round(.5*e.clientHeight))}addControl(e){e.addTo(this)}addControls(e){for(let t=0;t<e.length;t++)e[t].addTo(this)}removeControl(e){e.remove()}isInitialized(){return this._initialized}initialize(){if(!this._initialized){if(this._initialized=!0,this.handler.initialize(),this.billboardsTextureAtlas.assignHandler(this.handler),this.geoObjectsTextureAtlas.assignHandler(this.handler),this.fontAtlas.assignHandler(this.handler),this.handler.setFrameCallback((()=>{this.draw()})),this.activeCamera=new Na(this,{eye:new oe(0,0,0),look:new oe(0,0,-1),up:new oe(0,1,0)}),this.events.initialize(),this.events.on("charkeypress",dr.KEY_APOSTROPHE,(function(){Mi.setVisibility(!Mi.getVisibility())})),this.handler.addProgram(new zi("screenFrame",{uniforms:{texture:"sampler2d"},attributes:{corners:"vec3"},vertexShader:"attribute vec2 corners;\n \n varying vec2 tc;\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n uniform sampler2D texture;\n \n varying vec2 tc;\n \n void main(void) {\n gl_FragColor = texture2D( texture, tc );\n }"})),this.pickingFramebuffer=new qs(this.handler,{width:640,height:480}),this.pickingFramebuffer.init(),this._tempPickingPix_=new Uint8Array(this.pickingFramebuffer.width*this.pickingFramebuffer.height*4),this.distanceFramebuffer=new qs(this.handler,{width:320,height:240}),this.distanceFramebuffer.init(),this._tempDistancePix_=new Uint8Array(this.distanceFramebuffer.width*this.distanceFramebuffer.height*4),this.depthFramebuffer=new qs(this.handler,{size:2,internalFormat:["RGBA","DEPTH_COMPONENT24"],format:["RGBA","DEPTH_COMPONENT"],type:["UNSIGNED_BYTE","UNSIGNED_INT"],attachment:["COLOR_ATTACHMENT","DEPTH_ATTACHMENT"],useDepth:!1}),this.depthFramebuffer.init(),this.screenDepthFramebuffer=new qs(this.handler,{useDepth:!1}),this.screenDepthFramebuffer.init(),"webgl"===this.handler.gl.type)this._readDistanceBuffer=this._readDistanceBuffer_webgl1,this._readPickingBuffer=this._readPickingBuffer_webgl1,this.sceneFramebuffer=new qs(this.handler),this.sceneFramebuffer.init(),this._fnScreenFrame=this._screenFrameNoMSAA,this.screenTexture={screen:this.sceneFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],distance:this.distanceFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0]};else{let e=this.getMaxMSAA(this._internalFormat);this._msaa>e&&(this._msaa=e),this.handler.addPrograms([new zi("toneMapping",{uniforms:{hdrBuffer:"sampler2d",exposure:"float",gamma:"float",whitepoint:"float"},attributes:{corners:"vec3"},vertexShader:"#version 300 es\n \n in vec2 corners;\n \n out vec2 tc;\n\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"#version 300 es\n\n precision highp float;\n\n #ifndef saturate\n #define saturate(a) clamp(a, 0.0, 1.0)\n #endif\n\n uniform sampler2D hdrBuffer;\n\n uniform float whitepoint;\n uniform float exposure;\n uniform float gamma;\n\n vec3 LinearToneMapping(vec3 color) {\n return exposure * color;\n }\n\n vec3 ReinhardToneMapping2(vec3 color) {\n return vec3(1.0) - exp(-color * exposure);\n }\n\n vec3 ReinhardToneMapping(vec3 color) {\n color *= exposure;\n return saturate(color / (vec3(1.0) + color));\n }\n\n #define Uncharted2Helper(x) max(((x * (0.15 * x + 0.10 * 0.50) + 0.20 * 0.02) / (x * (0.15 * x + 0.50) + 0.20 * 0.30)) - 0.02 / 0.30, vec3(0.0))\n\n vec3 Uncharted2ToneMapping(vec3 color) {\n color *= exposure;\n return saturate(Uncharted2Helper(color) / Uncharted2Helper(vec3(whitepoint)));\n }\n\n vec3 OptimizedCineonToneMapping(vec3 color) {\n color *= exposure;\n color = max(vec3(0.0), color - 0.004);\n return pow((color * (6.2 * color + 0.5)) / (color * (6.2 * color + 1.7) + 0.06), vec3(2.2));\n }\n\n vec3 ACESFilmicToneMapping(vec3 color) {\n color *= exposure;\n return saturate((color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14));\n }\n\n in vec2 tc;\n\n layout(location = 0) out vec4 fragColor;\n \n void main(void) {\n vec4 hdrColor = texture(hdrBuffer, tc).rgba;\n \n float oneByGamma = gamma / gamma;\n float oneByWhitePoint = whitepoint / whitepoint;\n vec3 mapped = ReinhardToneMapping2(hdrColor.rgb) * oneByGamma * oneByWhitePoint;\n //vec3 mapped = ACESFilmicToneMapping(hdrColor.rgb) * oneByGamma * oneByWhitePoint;\n\n mapped = pow(mapped, vec3(1.0 / gamma));\n \n fragColor = vec4(mapped, hdrColor.a);\n }"})]),this.handler.addPrograms([new zi("depth",{uniforms:{depthTexture:"sampler2d"},attributes:{corners:"vec2"},vertexShader:"#version 300 es\n \n in vec2 corners;\n \n out vec2 tc;\n\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"#version 300 es\n\n precision highp float;\n\n #define MAX_FRUSTUMS 4\n\n uniform sampler2D depthTexture;\n \n in vec2 tc;\n\n layout(location = 0) out vec4 fragColor;\n\n float LinearizeDepth(in vec2 uv)\n {\n float depth = texture(depthTexture, tc).x;\n return depth;//(2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear));\n }\n \n void main(void) {\n float c = LinearizeDepth(tc);\n fragColor = vec4(c, c, c, 1.0);\n }"})]),this.sceneFramebuffer=new So(this.handler,{size:1,msaa:this._msaa,internalFormat:this._internalFormat,filter:"LINEAR"}),this.sceneFramebuffer.init(),this.blitFramebuffer=new qs(this.handler,{size:1,useDepth:!1,internalFormat:this._internalFormat,format:this._format,type:this._type,filter:"NEAREST"}),this.blitFramebuffer.init(),this.toneMappingFramebuffer=new qs(this.handler,{useDepth:!1}),this.toneMappingFramebuffer.init(),this._fnScreenFrame=this._screenFrameMSAA,this.screenTexture={screen:this.toneMappingFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],distance:this.distanceFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0],frustum:this.depthFramebuffer.textures[0]},this._initReadPixelsBuffers()}this.handler.ONCANVASRESIZE=()=>{this._resizeStart(),this.events.dispatch(this.events.resize,this.handler.canvas),this._resizeEnd(),this.events.dispatch(this.events.resizeend,this.handler.canvas)},this.screenFramePositionBuffer=this.handler.createArrayBuffer(new Float32Array([1,1,-1,1,1,-1,-1,-1]),2,4),this.outputTexture=this.screenTexture.screen,this._initializeRenderNodes(),this._initializeControls()}}_initReadPixelsBuffers(){let e=this.handler.gl;this._distancePixelBuffer=e.createBuffer(),e.bindBuffer(e.PIXEL_PACK_BUFFER,this._distancePixelBuffer),e.bufferData(e.PIXEL_PACK_BUFFER,this.distanceFramebuffer.width*this.distanceFramebuffer.height*4,e.STREAM_READ),e.bindBuffer(e.PIXEL_PACK_BUFFER,null),this._pickingPixelBuffer=e.createBuffer(),e.bindBuffer(e.PIXEL_PACK_BUFFER,this._pickingPixelBuffer),e.bufferData(e.PIXEL_PACK_BUFFER,this.pickingFramebuffer.width*this.pickingFramebuffer.height*4,e.STREAM_READ),e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}_initializeControls(){let e=this.controls;this.controls={};for(let t in e)this.addControl(e[t])}resize(){this._resizeEnd()}setCurrentScreen(e){this._currentOutput=e,this.screenTexture[e]&&(this.outputTexture=this.screenTexture[e])}_resizeStart(){let e=this.handler.canvas;this.activeCamera.setAspectRatio(e.width/e.height),this.sceneFramebuffer.setSize(.5*e.width,.5*e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(.5*e.width,.5*e.height,!0)}_resizeEnd(){let e=this.handler.canvas;this.activeCamera.setAspectRatio(e.width/e.height),this.sceneFramebuffer.setSize(e.width,e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(e.width,e.height,!0),this.toneMappingFramebuffer&&this.toneMappingFramebuffer.setSize(e.width,e.height,!0),this.depthFramebuffer&&this.depthFramebuffer.setSize(e.clientWidth,e.clientHeight,!0),this.screenDepthFramebuffer&&this.screenDepthFramebuffer.setSize(e.clientWidth,e.clientHeight,!0),"webgl"===this.handler.gl.type?(this.screenTexture.screen=this.sceneFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.distance=this.distanceFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]):(this.screenTexture.screen=this.toneMappingFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.distance=this.distanceFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]),this.setCurrentScreen(this._currentOutput)}removeNode(e){e.remove()}addNode(e){this.renderNodes[e.name]?Mi.logWrn(`Node name ${e.name} already exists.`):(e.assign(this),this._renderNodesArr.unshift(e),this.renderNodes[e.name]=e)}_initializeRenderNodes(){for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].initialize()}addNodeBefore(e,t){if(this.renderNodes[e.name])Mi.logWrn(`Node name ${e.name} already exists.`);else{e.assign(this),this.renderNodes[e.name]=e;for(let i=0;i<this._renderNodesArr.length;i++)if(this._renderNodesArr[i].isEqual(t)){this._renderNodesArr.splice(i,0,e);break}this._renderNodesArr.unshift(e)}}addNodes(e){for(let t=0;t<e.length;t++)this.addNode(e[t])}getMaxMSAA(e){let t=this.handler.gl;return t.getInternalformatParameter(t.RENDERBUFFER,t[e],t.SAMPLES)[0]}getMSAA(){return this._msaa}enqueueEntityCollectionsToDraw(e){this._entityCollections.push.apply(this._entityCollections,e)}_drawOpaqueEntityCollections(){let e=this._entityCollections;if(e.length){this.enableBlendDefault();let t=e.length;for(;t--;)e[t]._fadingOpacity&&e[t].pointCloudHandler.draw()}}_drawTransparentEntityCollections(){let e=this._entityCollections;if(e.length){let t=this.handler.gl;this.enableBlendDefault();let i=e.length;for(;i--;){let t=e[i];e[i]._fadingOpacity&&(t.events.dispatch(t.events.draw,t),e[i].geoObjectHandler.draw())}for(t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.billboardsTextureAtlas.texture),i=e.length;i--;){let t=e[i];t._fadingOpacity&&t.billboardHandler.draw()}let n=this.fontAtlas.atlasesArr;for(i=0;i<n.length;i++)t.activeTexture(t.TEXTURE0+i),t.bindTexture(t.TEXTURE_2D,n[i].texture);for(i=e.length;i--;)e[i]._fadingOpacity&&e[i].labelHandler.draw();for(i=e.length;i--;)e[i]._fadingOpacity&&e[i].rayHandler.draw();for(i=e.length;i--;)e[i]._fadingOpacity&&e[i].polylineHandler.draw();for(i=e.length;i--;)e[i]._fadingOpacity&&e[i].stripHandler.draw()}}_clearEntityCollectionQueue(){this._entityCollections.length=0,this._entityCollections=[]}draw(){this.activeCamera.checkMoveEnd();let e=this.events;e.handleEvents();let t=this.sceneFramebuffer;t.activate();let i=this.handler,n=i.gl;n.clearColor(0,0,0,1),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),this.enableBlendDefault(),e.dispatch(e.draw,this);let r=this.activeCamera.frustums,s=e.pointerEvent(),a=e.mouseState.leftButtonDown||e.mouseState.rightButtonDown,o=this._renderNodesArr,l=r.length;for(;l--;){this.activeCamera.setCurrentFrustum(l),n.clear(n.DEPTH_BUFFER_BIT);let t=o.length;for(;t--;)o[t].preDrawNode();for(this._drawOpaqueEntityCollections(),t=o.length;t--;)this.enableBlendDefault(),o[t].drawNode();this._drawTransparentEntityCollections(),this._clearEntityCollectionQueue(),e.dispatch(e.drawtransparent,this),s&&!a&&this._drawPickingBuffer(),this.__useDistanceFramebuffer__&&this._drawDistanceBuffer()}t.deactivate(),this.blitFramebuffer&&t.blitTo(this.blitFramebuffer,0),s&&(i.isWebGl2()&&this._drawDepthBuffer(),this._readPickingBuffer()),this.__useDistanceFramebuffer__&&this._readDistanceBuffer(),this._fnScreenFrame(),e.dispatch(e.postdraw,this),e.mouseState.wheelDelta=0,e.mouseState.justStopped=!1,e.mouseState.moving=!1,e.touchState.moving=!1}_screenFrameMSAA(){let e=this.handler,t=e.programs.toneMapping,i=t._program,n=e.gl;n.disable(n.DEPTH_TEST),n.bindBuffer(n.ARRAY_BUFFER,this.screenFramePositionBuffer),n.vertexAttribPointer(i.attributes.corners,2,n.FLOAT,!1,0,0),this.toneMappingFramebuffer.activate(),t.activate(),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this.blitFramebuffer.textures[0]),n.uniform1i(i.uniforms.hdrBuffer,0),n.uniform1f(i.uniforms.gamma,this.gamma),n.uniform1f(i.uniforms.exposure,this.exposure),n.uniform1f(i.uniforms.whitepoint,this.whitepoint),n.drawArrays(n.TRIANGLE_STRIP,0,4),this.toneMappingFramebuffer.deactivate(),t=e.programs.screenFrame,i=t._program,t.activate(),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this.outputTexture),n.uniform1i(i.uniforms.texture,0),n.drawArrays(n.TRIANGLE_STRIP,0,4),n.enable(n.DEPTH_TEST)}_screenFrameNoMSAA(){let e=this.handler,t=e.programs.screenFrame,i=t._program,n=e.gl;n.disable(n.DEPTH_TEST),t.activate(),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this.outputTexture),n.uniform1i(i.uniforms.texture,0),n.bindBuffer(n.ARRAY_BUFFER,this.screenFramePositionBuffer),n.vertexAttribPointer(i.attributes.corners,2,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLE_STRIP,0,4),n.enable(n.DEPTH_TEST)}_drawPickingBuffer(){this.pickingFramebuffer.activate();let e=this.handler.gl;this.activeCamera.isFirstPass?(e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)):e.clear(e.DEPTH_BUFFER_BIT);let t=this._pickingCallbacks;for(let i=0,n=t.length;i<n;i++)e.disable(e.BLEND),t[i].callback.call(t[i].sender),e.enable(e.BLEND);this.pickingFramebuffer.deactivate()}_drawDistanceBuffer(){this.distanceFramebuffer.activate();let e=this.handler.gl;this.activeCamera.isFirstPass?(e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)):e.clear(e.DEPTH_BUFFER_BIT),e.disable(e.BLEND);let t=this._distanceCallbacks,i=t.length;for(;i--;)t[i].callback.call(t[i].sender);e.enable(e.BLEND),this.distanceFramebuffer.deactivate()}_drawDepthBuffer(){this.depthFramebuffer.activate();let e=this.handler,t=e.gl;t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),t.enable(t.DEPTH_TEST);let i=this._depthCallbacks,n=i.length;for(;n--;)i[n].callback.call(i[n].sender);this.depthFramebuffer.deactivate(),this.screenDepthFramebuffer.activate();let r=e.programs.depth,s=r._program;t.bindBuffer(t.ARRAY_BUFFER,this.screenFramePositionBuffer),t.vertexAttribPointer(s.attributes.corners,2,t.FLOAT,!1,0,0),r.activate(),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.depthFramebuffer.textures[1]),t.uniform1i(s.uniforms.depthTexture,0),t.drawArrays(t.TRIANGLE_STRIP,0,4),this.screenDepthFramebuffer.deactivate()}readPickingColor(e,t,i){let n=this.pickingFramebuffer.width,r=this.pickingFramebuffer.height;e=Math.round(e*n);let s=4*((t=Math.round(t*r))*n+e);i[0]=this._tempPickingPix_[s],i[1]=this._tempPickingPix_[s+1],i[2]=this._tempPickingPix_[s+2]}readDistanceColor(e,t,i){let n=this.distanceFramebuffer.width,r=this.distanceFramebuffer.height;e=Math.round(e*n);let s=4*((t=Math.round(t*r))*n+e);i[0]=this._tempDistancePix_[s],i[1]=this._tempDistancePix_[s+1],i[2]=this._tempDistancePix_[s+2]}start(){this._initialized||this.initialize(),this.handler.start()}destroy(){for(let e in this.controls)this.controls[e].remove();for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].remove();this.div=null,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=null,this.controls={},this.controlsBag={},this.colorObjects.clear(),this.colorObjects=null,this._pickingCallbacks=[],this.pickingFramebuffer=null,this._tempPickingPix_=null,this.distanceFramebuffer=null,this._distanceCallbacks=[],this._tempDistancePix_=null,this._depthCallbacks=[],this.depthFramebuffer=null,this.sceneFramebuffer=null,this.blitFramebuffer=null,this.toneMappingFramebuffer=null,this._entityCollections=[],this.handler.ONCANVASRESIZE=null,this.handler.destroy(),this.handler=null,this._initialized=!1}}const Jo="/res";class el{constructor(e){this.$target=null,this._instanceID=`__globus${el.__counter__++?el.__counter__:""}__`,window[this._instanceID]=this,this._canvas=document.createElement("canvas"),this._canvas.id=`canvas${this._instanceID}`,this._canvas.style.width="100%",this._canvas.style.height="100%",this._canvas.style.display="block",this._canvas.style.opacity="0.0",this._canvas.style.transition="opacity 150ms",this.$inner=document.createElement("div"),this.$inner.classList.add("og-inner"),this.$inner.appendChild(this._canvas),this.$inner.attributions=document.createElement("div"),e.attributionContainer?e.attributionContainer.appendChild(this.$inner.attributions):(this.$inner.attributions.classList.add("og-attribution"),this.$inner.appendChild(this.$inner.attributions)),e.target&&this.attachTo(e.target);const t=e=>{e.preventDefault()};this._canvas.onmouseenter=function(){document.addEventListener("mousewheel",t,{capture:!1,passive:!1})},this._canvas.onmouseleave=function(){document.removeEventListener("mousewheel",t)},this.renderer=new Qo(new Mo(this._canvas,{autoActivate:!1,pixelRatio:e.dpi||window.devicePixelRatio+.15,context:{antialias:!1,premultipliedAlpha:!1}}),{autoActivate:!1,msaa:e.msaa,fontsSrc:e.fontsSrc}),this.renderer.div=this.$inner,e.skybox&&this.renderer.addNode(e.skybox),this._planetName=e.name?e.name:"globus_planet_"+el.__counter__,this.planet=new Xa({name:this._planetName,frustums:e.frustums,ellipsoid:e.ellipsoid,maxGridSize:e.maxGridSize,nightTextureSrc:null===e.nightTextureSrc?null:`${e.resourcesSrc||Jo}/night.png`,specularTextureSrc:null===e.specularTextureSrc?null:`${e.resourcesSrc||Jo}/spec.png`,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude||15e6,maxEqualZoomAltitude:e.maxEqualZoomAltitude,minEqualZoomAltitude:e.minEqualZoomAltitude,minEqualZoomCameraSlope:e.minEqualZoomCameraSlope,quadTreeStrategyPrototype:e.quadTreeStrategyPrototype,maxLoadingRequests:e.maxLoadingRequests,atmosphereEnabled:e.atmosphereEnabled,transitionOpacityEnabled:e.transitionOpacityEnabled}),e.terrain?Array.isArray(e.terrain)?this.planet.setTerrain(e.terrain[0]):this.planet.setTerrain(e.terrain):this.planet.setTerrain(new Qa),this.renderer.addNode(this.planet),e.controls?this.planet.addControls(e.controls):this.planet.addControls([new Wr,e.useEarthNavigation?new lr:new br({minSlope:e.minSlope}),new Gr,new ar,new Fr,new zt]);const i=this.renderer.controls;let n;for(let e in i)if(i[e]instanceof Vr){n=i[e];break}n?this.sun=n:(this.sun=new Vr,this.planet.addControl(this.sun)),e.sun&&(void 0===e.sun.active||e.sun.active||this.sun.deactivate(),!0===e.sun.stopped&&this.sun.stop()),e.layers&&this.planet.addLayers(e.layers);let r=e.viewExtent;r&&(r instanceof Array?this.planet.viewExtentArr(r):this.planet.viewExtent(r)),(e.autoActivate||de(e.autoActivate))&&this.start()}start(){this.renderer.start(),this.fadeIn()}fadeIn(){this._canvas.style.opacity="1.0"}fadeOut(){this._canvas.style.opacity="0"}attachTo(e){let t;this.detach(),t=e instanceof HTMLElement?e:document.getElementById(e)||document.querySelector(e),t&&(this.$target=t,t.appendChild(this.$inner))}detach(){this.$target&&this.$target.removeChild(this.$inner)}destroy(){this.detach(),this.planet.layers.forEach((e=>e.remove())),this.planet.destroy(),this.renderer.destroy(),window[this._instanceID]=null}}el.__counter__=0;const tl=`<div class="og-popup {className}">\n <div class="og-popup-content-wrapper">\n <div class="og-popup-content"></div>\n </div>\n <div class="og-popup-tip-container">\n <div class="og-popup-tip"></div>\n </div>\n <div class="og-popup-toolbar">\n <div class="og-popup-btn og-popup-close">${Ft}</div>\n </div>\n <div class="og-popup-title">{title}</div>\n </div>`,il=["open","close"];class nl extends Bt{constructor(e){super({template:be(tl,{title:e.title||""}),classList:e.className?[e.className]:[],...e}),this.events=this.events.registerNames(il),this._content=e.content||"",this.$content=null,this.$tip=null,this.$title=null,this._planet=e.planet,this._offset=e.offset||[0,0],this._lonLat=Se(e.lonLat),this._cartPos=new oe,this._visibility=e.visibility||!1,this.render()}_updatePosition(){this.setCartesian3v(this._cartPos)}setScreen(e){if(this._planet){let t=this._planet.renderer.handler.pixelRatio;this.el.style.transform=`translate(${e.x/t-.5*this.clientWidth}px, ${e.y/t-this._planet.renderer.handler.canvas.clientHeight-this.$tip.clientHeight}px)`}}get clientWidth(){return this.el?this.el.clientWidth:0}get clientHeight(){return this.el?this.el.clientHeight:0}setOffset(e=0,t=0){return this._offset[0]=e,this._offset[1]=t,this.el&&(this.el.style.left=`${e}px`,this.el.style.bottom=`${t}px`),this}render(e){return super.render(e),this.$content=this.select(".og-popup-content"),this.$title=this.select(".og-popup-title"),this.$tip=this.select(".og-popup-tip-container"),this.setOffset(this._offset[0],this._offset[1]),this.setContent(this._content),this.setLonLat(this._lonLat),this.setVisibility(this._visibility),this.select(".og-popup-close").addEventListener("click",(()=>{this.hide()})),this}setVisibility(e){return e?this.show():this.hide(),this}getContainer(){return this.$content}getToolbarContainer(){return this.select(".og-popup-toolbar")}show(){return this._visibility=!0,this._planet&&(this._planet.events.on("draw",this._updatePosition,this),this.appendTo(this._planet.renderer.div),this.events.dispatch(this.events.open,this)),this}hide(){return this._visibility=!1,this.el&&this.el.parentNode&&(this._planet.events.off("draw",this._updatePosition),this.el.parentNode.removeChild(this.el),this.events.dispatch(this.events.close,this)),this}setCartesian3v(e,t=0){if(this._cartPos=e,this._planet){let i=this._planet.camera,n=this._planet.ellipsoid.equatorialSize+t,r=i._lonLat.height,s=e.sub(i.eye);Math.sqrt((n+r)*(n+r)-n*n)>s.length()&&i.getForward().dot(s.normalize())>0?(this.el.style.display="block",this.setScreen(i.project(e))):this.el.style.display="none"}return this}setTitle(e){this.$title&&(this.$title.innerHTML=e)}setLonLat(e){this._lonLat=e,this._planet&&this.setCartesian3v(this._planet.ellipsoid.lonLatToCartesian(e),e.height)}setContent(e){e&&(this.clear(),this._content=e,this.$content&&("string"==typeof e?this.$content.innerHTML=e:this.$content.appendChild(e)))}clear(){this._content=null,this.$content&&(this.$content.innerHTML="")}}class rl extends Aa{constructor(e,t,i,n){super(e,t,i,n),this.isPole=!1,this._tileGroup=0}_getMaxZoom(){return 150}_assignTileYIndexes(e){const t=e.getCenter().lat;this.tileY=ia(t,e.getHeight(),90),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_assignTileXIndexes(e){let t=e.getCenter().lon;this.tileX=ia(t,e.getWidth(),-180);let i=2*(1<<this.tileZoom);this.tileXE=(this.tileX+1)%i,this.tileXW=(i+this.tileX-1)%i}}class sl extends Ca{constructor(e){super(e,"Mars",ea),this._westExtent=ie.createFromArray([-180,-90,0,90]),this._eastExtent=ie.createFromArray([0,-90,180,90])}init(){this._quadTreeList=[new Ta(rl,this.planet,0,null,0,this._westExtent),new Ta(rl,this.planet,0,null,0,this._eastExtent)]}getTileXY(e,t){let i=t,n=-1,r=-1,s=1<<i;return n=e.lon>0?ia(e.lon,180/s,0)+s:ia(e.lon,180/s,-180),r=ia(e.lat,180/s,90),[n,r,i,0]}getLonLatTileOffset(e,t,i,n,r){let s=e,a=new ie;a=e.lon>0?na(t-(1<<n),i,n,this._westExtent):na(t,i,n,this._eastExtent);let o=a.getWidth()/(r-1),l=a.getHeight()/(r-1);return[r-Math.ceil((s.lat-a.southWest.lat)/l)-1,Math.floor((s.lon-a.southWest.lon)/o)]}}class al extends Ca{constructor(e){super(e,"wgs84",ea)}init(){this._quadTreeList=[new Ta(rl,this.planet,0,null,0,ie.createFromArray([-180,-90,180,90]))]}}const ol={epsg4326:class extends Ca{constructor(e){super(e,"EPSG4326",ea)}init(){this._quadTreeList=[new Ta(rl,this.planet,0,null,0,ie.createFromArray([-180,-90,0,90])),new Ta(rl,this.planet,0,null,0,ie.createFromArray([0,-90,180,90]))]}},earth:Ea,mars:sl,wgs84:al};export{mi as ALIGN,ro as BilTerrain,si as Billboard,xo as Bing,Na as Camera,$t as CanvasTiles,To as Clock,It as Control,Ea as EarthQuadTreeStrategy,Wa as Ellipsoid,Qa as EmptyTerrain,Ai as Entity,Qi as EntityCollection,Mt as Events,ie as Extent,qs as Framebuffer,fo as GeoImage,pi as GeoObject,go as GeoTexture2d,po as GeoVideo,Pa as Geoid,li as Geometry,ai as GeometryTypeEnum,el as Globe,_o as GlobusRgbTerrain,Ja as GlobusTerrain,Mo as Handler,mo as KML,Xt as LAYER_EVENTS,yi as Label,qt as Layer,Or as LightSource,hi as Line2,ci as Line3,z as LonLat,sl as MarsQuadTreeStrategy,ne as Mat3,se as Mat4,jt as Material,So as Multisample,gi as Object3d,vo as OpenStreetMap,di as Plane,Xa as Planet,Ha as PlanetCamera,xi as PointCloud,bi as Polyline,nl as Popup,zi as Program,Ca as QuadTreeStrategy,ae as Quat,_i as Ray,Pi as RenderNode,Qo as Renderer,ao as RgbTerrain,Li as Strip,le as Vec2,oe as Vec3,re as Vec4,In as Vector,no as WMS,al as Wgs84QuadTreeStrategy,to as XYZ,Et as bv,Es as control,dr as input,Ct as jd,bo as layer,M as math,te as mercator,ol as quadTreeStrategyType,Ka as scene,uo as terrain,Qe as utils,Bo as webgl,ja as wgs84};
|
|
1
|
+
const e=2*Math.PI,t=Math.PI/2,i=Number.MAX_VALUE||17976931348623157e292,n=Math.log(2),r=2147483647,s=549755748352,a=-s,o=Math.PI/180,l=180/Math.PI,h=2*l,c=.5*o,d=Math.sqrt(.5),_=1e-5,u=1e-10,f=1e-12,g=1e-14;function p(e,t,i){return Math.max(t,Math.min(e,i))}function m(e){return!(e&e-1)}function v(e,t=4096){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1>t?t:e+1}function y(e=0,t=1){return Math.floor(Math.random()*(t-e))+e}function x(e,t){return(e%t+t)%t}function b(t){const i=x(t,e);return Math.abs(i)<g&&Math.abs(t)>g?e:i}function w(e,t){return t<e?0:1}function C(e){const t=Math.abs(e);return t-Math.floor(t)}function T(e){return Math.pow(2,e)}function L(e,t,i){return i+e*(t-i)}function A(e){return e*e*e}function E(e){return e*e}function P(e){return e-360*Math.floor(e/360)}var S=Object.freeze({__proto__:null,ARCSECONDS_TO_RADIANS:484813681109536e-20,DEG2RAD:function(e){return e*o},DEGREES:l,DEGREES_DOUBLE:h,DEGREES_TO_HOURS:1/15,EPS1:.1,EPS10:u,EPS11:1e-11,EPS12:f,EPS13:1e-13,EPS14:g,EPS15:1e-15,EPS16:1e-16,EPS17:1e-17,EPS18:1e-18,EPS19:1e-19,EPS2:.01,EPS20:1e-20,EPS3:.001,EPS4:1e-4,EPS5:_,EPS6:1e-6,EPS7:1e-7,EPS8:1e-8,EPS9:1e-9,HOURS_TO_DEGREES:15,HOURS_TO_RADIANS:.26179938779914946,LOG2:n,MAX:s,MAX32:r,MAX_FLOAT:i,MIN:a,PI_TWO:t,RAD2DEG:function(e){return e*l},RADIANS:o,RADIANS_HALF:c,RADIANS_TO_HOURS:3.819718634205488,SQRT_HALF:d,TWO_PI:e,W:3,X:0,Y:1,Z:2,bezier1v:function(e,t,i,n,r){return A(1-e)*t+3*E(1-e)*e*i+3*(1-e)*E(e)*n+A(e)*r},bezier3v:function(e,t,i,n,r){let s=1-e,a=e*e,o=s*s,l=o*s,h=a*e;return t.scaleTo(l).addA(i.scaleTo(3*o*e)).addA(n.scaleTo(3*s*a)).addA(r.scaleTo(h))},clamp:p,cube:A,degToDec:function(e,t,i,n){return n?e+t/60+i/3600:-e-t/60-i/3600},exp2:T,frac:C,getAngleBetweenAzimuths:function(e,t){return(((e=b(e))-(t=b(t)))%360+360+180)%360-180},isPowerOfTwo:m,lerp:L,log:function(e,t){return Math.log(e)/Math.log(t)},log2:function(e){return Math.log(e)/n},mod:x,negativePItoPI:function(e){return b(e+Math.PI)-Math.PI},nextHighestPowerOfTwo:v,norm_lon:function(e){return e>180?(e+180)%360-180:e<-180?(e-180)%360+180:e},pow2i:function(e){return 2<<e-1},random:function(e=0,t=1){return Math.random()*(t-e)+e},randomi:y,rev:P,slice:function(e,t,i){return e*(t-i)},solve_iteration:function(e,t,i,n=50){let r=0,s=t;for(let t=0;t<n;t++)if(r=s,s=e(r),Math.abs(s-r)<i)return s;return s},solve_iteration_fixed:function(e,t,i){let n=0,r=t;for(let t=0;t<i;t++)n=r,r=e(n);return r},square:E,step:w,zeroTwoPI:b});const M=.5*Math.PI,B=180/Math.PI,k=2*B,R=Math.PI/360,I=B*M;class z{constructor(e=0,t=0,i=0){this.lon=0,this.lat=0,this.height=0,this.lon=e,this.lat=t,this.height=i}isZero(){return 0===this.lon&&0===this.lat&&0===this.height}static join(e){let t=[];for(let i=0;i<e.length;i++){let n=e[i];t[i]=new z(n[0],n[1],n[2])}return t}static createFromArray(e){return new z(e[0],e[1],e[2])}static toArray(e){return[e.lon,e.lat,e.height]}toArray(){return z.toArray(this)}static forwardMercator(e,t,i){return new z(e*V,Math.log(Math.tan((90+t)*R))*H,i)}static forwardMercatorRes(e,t){return t.lon=e.lon*V,t.lat=Math.log(Math.tan((90+e.lat)*R))*H,t.height=e.height,t}static inverseMercator(e,t,i=0){return new z(e*U,k*Math.atan(Math.exp(t*N))-I,i)}set(e=0,t=0,i=0){return this.lon=e,this.lat=t,this.height=i,this}copy(e){return this.lon=e.lon,this.lat=e.lat,this.height=e.height,this}clone(){return new z(this.lon,this.lat,this.height)}forwardMercator(){return z.forwardMercator(this.lon,this.lat,this.height)}forwardMercatorEPS01(){let e=this.lat;return e>89.9?e=89.9:e<-89.9&&(e=-89.9),new z(this.lon*V,Math.log(Math.tan((90+e)*R))*H)}inverseMercator(){return z.inverseMercator(this.lon,this.lat,this.height)}equal(e){return e.height?this.lon===e.lon&&this.lat===e.lat&&this.height===e.height:this.lon===e.lon&&this.lat===e.lat}}const D=20037508.34,F=2*D,N=Math.PI/D,H=D/Math.PI,O=.5*Math.PI,V=D/180,U=180/D,G=Math.PI/360,W=Math.PI/180,j=180/Math.PI,Y=2*D,q=1/Y;function X(e){return new z(e.lon*D/180,Math.log(Math.tan((90+e.lat)*G))*H,e.height)}function $(e){return e*D/180}function Z(e){return Math.log(Math.tan((90+e)*G))*H}function K(e){return j*(2*Math.atan(Math.exp(e*N))-O)}function Q(e,t,i){let n=F/(1<<i),r=new z(e*n-D,D-t*n-n);return new ie(r,new z(r.lon+n,r.lat+n))}const J=K(D),ee=-J;var te=Object.freeze({__proto__:null,INV_POLE_BY_180:U,MAX_LAT:J,MIN_LAT:ee,ONE_BY_POLE_DOUBLE:q,PI_BY_POLE:N,POLE:D,POLE2:F,POLE_BY_180:V,POLE_BY_PI:H,POLE_DOUBLE:Y,forward:X,forwardArray:function(e){let t=[];for(let i=0;i<e.length;i++)t.push(e[i].forwardMercator());return t},forward_lat:Z,forward_lon:$,getTileExtent:Q,getTileX:function(e,t){return Math.floor((e+180)/360*Math.pow(2,t))},getTileY:function(e,t){return Math.floor(.5*(1-Math.log(Math.tan(e*W)+1/Math.cos(e*W))/Math.PI)*Math.pow(2,t))},inverse_lat:K,inverse_lon:function(e){return 180*e/D}});class ie{constructor(e=new z,t=new z){this.southWest=e,this.northEast=t}static createFromArray(e){return new ie(new z(e[0],e[1]),new z(e[2],e[3]))}static createByCoordinates(e){let t=s,i=a,n=s,r=a;for(let s=0;s<e.length;s++){const a=e[s];a.lon<t&&(t=a.lon),a.lon>i&&(i=a.lon),a.lat<n&&(n=a.lat),a.lat>r&&(r=a.lat)}return new ie(new z(t,n),new z(i,r))}static createByCoordinatesArr(e){let t=s,i=a,n=s,r=a;for(let s=0;s<e.length;s++){const a=e[s];a[0]<t&&(t=a[0]),a[0]>i&&(i=a[0]),a[1]<n&&(n=a[1]),a[1]>r&&(r=a[1])}return new ie(new z(t,n),new z(i,r))}static fromTile(e,t,i,n=40075016.68,r=40075016.68){const s=1<<i,a=n/s,o=r/s,l=.5*-n+e*a,h=.5*r-t*o,c=l+a;return new ie(new z(l,h-o),new z(c,h))}setByCoordinates(e){let t=s,i=a,n=s,r=a;for(let s=0;s<e.length;s++){const a=e[s];a.lon<t&&(t=a.lon),a.lon>i&&(i=a.lon),a.lat<n&&(n=a.lat),a.lat>r&&(r=a.lat)}return this.southWest.lon=t,this.southWest.lat=n,this.northEast.lon=i,this.northEast.lat=r,this}isInside(e){const t=this.southWest,i=this.northEast;return e.lon>=t.lon&&e.lon<=i.lon&&e.lat>=t.lat&&e.lat<=i.lat}overlaps(e){const t=this.southWest,i=this.northEast;return t.lon<=e.northEast.lon&&i.lon>=e.southWest.lon&&t.lat<=e.northEast.lat&&i.lat>=e.southWest.lat}getWidth(){return this.northEast.lon-this.southWest.lon}getHeight(){return this.northEast.lat-this.southWest.lat}clone(){return new ie(this.southWest.clone(),this.northEast.clone())}getCenter(){const e=this.southWest,t=this.northEast;return new z(e.lon+.5*(t.lon-e.lon),e.lat+.5*(t.lat-e.lat))}getNorthWest(){return new z(this.southWest.lon,this.northEast.lat)}getNorthEast(){return new z(this.northEast.lon,this.northEast.lat)}getSouthWest(){return new z(this.southWest.lon,this.southWest.lat)}getSouthEast(){return new z(this.northEast.lon,this.southWest.lat)}getNorth(){return this.northEast.lat}getEast(){return this.northEast.lon}getWest(){return this.southWest.lon}getSouth(){return this.southWest.lat}equals(e){return this.southWest.lon===e.southWest.lon&&this.southWest.lat===e.southWest.lat&&this.northEast.lon===e.northEast.lon&&this.northEast.lat===e.northEast.lat}forwardMercator(){return new ie(this.southWest.forwardMercator(),this.northEast.forwardMercator())}inverseMercator(){return new ie(this.southWest.inverseMercator(),this.northEast.inverseMercator())}getCartesianBounds(e){let t=s,i=a,n=s,r=a,o=s,l=a;const h=[new z(this.southWest.lon,this.southWest.lat),new z(this.southWest.lon,this.northEast.lat),new z(this.northEast.lon,this.northEast.lat),new z(this.northEast.lon,this.southWest.lat)];for(let s=0;s<h.length;s++){const a=e.lonLatToCartesian(h[s]),c=a.x,d=a.y,_=a.z;c<t&&(t=c),c>i&&(i=c),d<n&&(n=d),d>r&&(r=d),_<o&&(o=_),_>l&&(l=_)}return[t,n,o,i,r,l]}toString(){return`[${this.southWest.lon.toFixed(5)}, ${this.southWest.lat.toFixed(5)}, ${this.northEast.lon.toFixed(5)}, ${this.northEast.lat.toFixed(5)}]`}}class ne{constructor(){this._m=[0,0,0,0,0,0,0,0,0]}set(e){return this._m[0]=e[0],this._m[1]=e[1],this._m[2]=e[2],this._m[3]=e[3],this._m[4]=e[4],this._m[5]=e[5],this._m[6]=e[6],this._m[7]=e[7],this._m[8]=e[8],this}clone(){let e=new ne;return e.set(this._m),e}copy(e){return this.set(e._m)}transposeTo(){let e=new ne,t=this._m;return e._m[0]=t[0],e._m[1]=t[3],e._m[2]=t[6],e._m[3]=t[1],e._m[4]=t[4],e._m[5]=t[7],e._m[6]=t[2],e._m[7]=t[5],e._m[8]=t[8],e}setIdentity(){return this._m[0]=1,this._m[1]=0,this._m[2]=0,this._m[3]=0,this._m[4]=1,this._m[5]=0,this._m[6]=0,this._m[7]=0,this._m[8]=1,this}mulVec(e){let t=e.x,i=e.y,n=e.z,r=this._m;return new oe(r[0]*t+r[3]*i+r[6]*n,r[1]*t+r[4]*i+r[7]*n,r[2]*t+r[5]*i+r[8]*n)}toMatrix4(){let e=new se,t=e._m,i=this._m;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=0,t[4]=i[3],t[5]=i[4],t[6]=i[5],t[7]=0,t[8]=i[6],t[9]=i[7],t[10]=i[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,e}}class re{constructor(e=0,t=0,i=0,n=0){this.x=e,this.y=t,this.z=i,this.w=n}static get identity(){return new re(0,0,0,1)}static fromVec(e){return new re(e[0],e[1],e[2],e[3])}toVec3(){return new oe(this.x,this.y,this.z)}clone(){return new re(this.x,this.y,this.z,this.w)}equal(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}toArray(){return[this.x,this.y,this.z,this.w]}toArray3(){return[this.x,this.y,this.z]}set(e,t,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,this}addA(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}subA(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}scale(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}affinity(){let e=1/this.w;return this.x*=e,this.y*=e,this.z*=e,this.w=1,this}scaleTo(e){return new re(this.x*e,this.y*e,this.z*e,this.w*e)}getStep(e){return new re(this.x<e?0:1,this.y<e?0:1,this.z<e?0:1,this.w<e?0:1)}getFrac(e){return new re(C(e.x),C(e.y),C(e.z),C(e.w))}dot(e){return e.x*this.x+e.y*this.y+e.z*this.z+e.w*this.w}isZero(){return!(this.x||this.y||this.z||this.w)}}class se{constructor(){this._m=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}static identity(){let e=new se;return e._m[0]=1,e._m[1]=0,e._m[2]=0,e._m[3]=0,e._m[4]=0,e._m[5]=1,e._m[6]=0,e._m[7]=0,e._m[8]=0,e._m[9]=0,e._m[10]=1,e._m[11]=0,e._m[12]=0,e._m[13]=0,e._m[14]=0,e._m[15]=1,e}set(e){return this._m[0]=e[0],this._m[1]=e[1],this._m[2]=e[2],this._m[3]=e[3],this._m[4]=e[4],this._m[5]=e[5],this._m[6]=e[6],this._m[7]=e[7],this._m[8]=e[8],this._m[9]=e[9],this._m[10]=e[10],this._m[11]=e[11],this._m[12]=e[12],this._m[13]=e[13],this._m[14]=e[14],this._m[15]=e[15],this}clone(){let e=new se;return e.set(this._m),e}copy(e){return this.set(e._m)}toMatrix3(){let e=new ne,t=this._m,i=e._m;return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[4],i[4]=t[5],i[5]=t[6],i[6]=t[8],i[7]=t[9],i[8]=t[10],e}mulVec3(e){let t=e.x,i=e.y,n=e.z;return new oe(this._m[0]*t+this._m[4]*i+this._m[8]*n+this._m[12],this._m[1]*t+this._m[5]*i+this._m[9]*n+this._m[13],this._m[2]*t+this._m[6]*i+this._m[10]*n+this._m[14])}mulVec4(e){let t=e.x,i=e.y,n=e.z,r=e.w;return new re(this._m[0]*t+this._m[4]*i+this._m[8]*n+this._m[12]*r,this._m[1]*t+this._m[5]*i+this._m[9]*n+this._m[13]*r,this._m[2]*t+this._m[6]*i+this._m[10]*n+this._m[14]*r,this._m[3]*t+this._m[7]*i+this._m[11]*n+this._m[15]*r)}toInverseMatrix3(){let e=this._m,t=e[0],i=e[1],n=e[2],r=e[4],s=e[5],a=e[6],o=e[8],l=e[9],h=e[10],c=h*s-a*l,d=-h*r+a*o,_=l*r-s*o,u=t*c+i*d+n*_;if(!u)return;u=1/u;let f=new ne;return f._m[0]=c*u,f._m[1]=(-h*i+n*l)*u,f._m[2]=(a*i-n*s)*u,f._m[3]=d*u,f._m[4]=(h*t-n*o)*u,f._m[5]=(-a*t+n*r)*u,f._m[6]=_*u,f._m[7]=(-l*t+i*o)*u,f._m[8]=(s*t-i*r)*u,f}inverseTo(e=new se){let t=this._m[0],i=this._m[1],n=this._m[2],r=this._m[3],s=this._m[4],a=this._m[5],o=this._m[6],l=this._m[7],h=this._m[8],c=this._m[9],d=this._m[10],_=this._m[11],u=this._m[12],f=this._m[13],g=this._m[14],p=this._m[15],m=t*a-i*s,v=t*o-n*s,y=t*l-r*s,x=i*o-n*a,b=i*l-r*a,w=n*l-r*o,C=h*f-c*u,T=h*g-d*u,L=h*p-_*u,A=c*g-d*f,E=c*p-_*f,P=d*p-_*g,S=1/(m*P-v*E+y*A+x*L-b*T+w*C);return e._m[0]=(a*P-o*E+l*A)*S,e._m[1]=(-i*P+n*E-r*A)*S,e._m[2]=(f*w-g*b+p*x)*S,e._m[3]=(-c*w+d*b-_*x)*S,e._m[4]=(-s*P+o*L-l*T)*S,e._m[5]=(t*P-n*L+r*T)*S,e._m[6]=(-u*w+g*y-p*v)*S,e._m[7]=(h*w-d*y+_*v)*S,e._m[8]=(s*E-a*L+l*C)*S,e._m[9]=(-t*E+i*L-r*C)*S,e._m[10]=(u*b-f*y+p*m)*S,e._m[11]=(-h*b+c*y-_*m)*S,e._m[12]=(-s*A+a*T-o*C)*S,e._m[13]=(t*A-i*T+n*C)*S,e._m[14]=(-u*x+f*v-g*m)*S,e._m[15]=(h*x-c*v+d*m)*S,e}transposeTo(){let e=new se;return e._m[0]=this._m[0],e._m[1]=this._m[4],e._m[2]=this._m[8],e._m[3]=this._m[12],e._m[4]=this._m[1],e._m[5]=this._m[5],e._m[6]=this._m[9],e._m[7]=this._m[13],e._m[8]=this._m[2],e._m[9]=this._m[6],e._m[10]=this._m[10],e._m[11]=this._m[14],e._m[12]=this._m[3],e._m[13]=this._m[7],e._m[14]=this._m[11],e._m[15]=this._m[15],e}setIdentity(){return this._m[0]=1,this._m[1]=0,this._m[2]=0,this._m[3]=0,this._m[4]=0,this._m[5]=1,this._m[6]=0,this._m[7]=0,this._m[8]=0,this._m[9]=0,this._m[10]=1,this._m[11]=0,this._m[12]=0,this._m[13]=0,this._m[14]=0,this._m[15]=1,this}mul(e){let t=this._m[0],i=this._m[1],n=this._m[2],r=this._m[3],s=this._m[4],a=this._m[5],o=this._m[6],l=this._m[7],h=this._m[8],c=this._m[9],d=this._m[10],_=this._m[11],u=this._m[12],f=this._m[13],g=this._m[14],p=this._m[15],m=e._m[0],v=e._m[1],y=e._m[2],x=e._m[3],b=e._m[4],w=e._m[5],C=e._m[6],T=e._m[7],L=e._m[8],A=e._m[9],E=e._m[10],P=e._m[11],S=e._m[12],M=e._m[13],B=e._m[14],k=e._m[15],R=new se;return R._m[0]=m*t+v*s+y*h+x*u,R._m[1]=m*i+v*a+y*c+x*f,R._m[2]=m*n+v*o+y*d+x*g,R._m[3]=m*r+v*l+y*_+x*p,R._m[4]=b*t+w*s+C*h+T*u,R._m[5]=b*i+w*a+C*c+T*f,R._m[6]=b*n+w*o+C*d+T*g,R._m[7]=b*r+w*l+C*_+T*p,R._m[8]=L*t+A*s+E*h+P*u,R._m[9]=L*i+A*a+E*c+P*f,R._m[10]=L*n+A*o+E*d+P*g,R._m[11]=L*r+A*l+E*_+P*p,R._m[12]=S*t+M*s+B*h+k*u,R._m[13]=S*i+M*a+B*c+k*f,R._m[14]=S*n+M*o+B*d+k*g,R._m[15]=S*r+M*l+B*_+k*p,R}translate(e){let t=e.x,i=e.y,n=e.z,r=this._m;return r[12]=r[0]*t+r[4]*i+r[8]*n+r[12],r[13]=r[1]*t+r[5]*i+r[9]*n+r[13],r[14]=r[2]*t+r[6]*i+r[10]*n+r[14],r[15]=r[3]*t+r[7]*i+r[11]*n+r[15],this}translateToPosition(e){let t=this._m;return t[12]=e.x,t[13]=e.y,t[14]=e.z,this}rotate(e,t){let i=Math.cos(t),n=Math.sin(t),r=new se,s=r._m;return s[0]=i+(1-i)*e.x*e.x,s[1]=(1-i)*e.y*e.x-n*e.z,s[2]=(1-i)*e.z*e.x+n*e.y,s[3]=0,s[4]=(1-i)*e.x*e.y+n*e.z,s[5]=i+(1-i)*e.y*e.y,s[6]=(1-i)*e.z*e.y-n*e.x,s[7]=0,s[8]=(1-i)*e.x*e.z-n*e.y,s[9]=(1-i)*e.y*e.z+n*e.x,s[10]=i+(1-i)*e.z*e.z,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,this.mul(r)}setRotation(e,t){let i=Math.cos(t),n=Math.sin(t),r=this._m;return r[0]=i+(1-i)*e.x*e.x,r[1]=(1-i)*e.y*e.x-n*e.z,r[2]=(1-i)*e.z*e.x+n*e.y,r[3]=0,r[4]=(1-i)*e.x*e.y+n*e.z,r[5]=i+(1-i)*e.y*e.y,r[6]=(1-i)*e.z*e.y-n*e.x,r[7]=0,r[8]=(1-i)*e.x*e.z-n*e.y,r[9]=(1-i)*e.y*e.z+n*e.x,r[10]=i+(1-i)*e.z*e.z,r[11]=0,r[12]=0,r[13]=0,r[14]=0,r[15]=1,this}rotateBetweenVectors(e,t){return ae.getRotationBetweenVectors(e,t).getMat4()}scale(e){let t=this._m;return t[0]=t[0]*e.x,t[1]=t[1]*e.x,t[2]=t[2]*e.x,t[3]=t[3]*e.x,t[4]=t[4]*e.y,t[5]=t[5]*e.y,t[6]=t[6]*e.y,t[7]=t[7]*e.y,t[8]=t[8]*e.z,t[9]=t[9]*e.z,t[10]=t[10]*e.z,t[11]=t[11]*e.z,this}setPerspective(e,t,i,n,r,s){let a=t-e,o=n-i,l=r-s,h=2*r,c=this._m;return c[0]=h/a,c[1]=0,c[2]=0,c[3]=0,c[4]=0,c[5]=h/o,c[6]=0,c[7]=0,c[8]=(t+e)/a,c[9]=(n+i)/o,c[10]=(s+r)/l,c[11]=-1,c[12]=0,c[13]=0,c[14]=h*s/l,c[15]=0,this}setOrtho(e,t,i,n,r,s){let a=1/(e-t),o=1/(i-n),l=1/(r-s),h=this._m;return h[0]=-2*a,h[1]=0,h[2]=0,h[3]=0,h[4]=0,h[5]=-2*o,h[6]=0,h[7]=0,h[8]=0,h[9]=0,h[10]=2*l,h[11]=0,h[12]=(e+t)*a,h[13]=(n+i)*o,h[14]=(s+r)*l,h[15]=1,this}eulerToMatrix(e,t,i){let n=Math.cos(e),r=Math.sin(e),s=Math.cos(t),a=Math.sin(t),o=Math.cos(i),l=Math.sin(i),h=n*a,c=r*a,d=this._m;return d[0]=s*o,d[1]=-s*l,d[2]=-a,d[4]=-c*o+n*l,d[5]=c*l+n*o,d[6]=-r*s,d[8]=h*o+r*l,d[9]=-h*l+r*o,d[10]=n*s,d[3]=d[7]=d[11]=d[12]=d[13]=d[14]=0,d[15]=1,this}}class ae{constructor(e=0,t=0,i=0,n=0){this.x=e,this.y=t,this.z=i,this.w=n}static get IDENTITY(){return new ae(0,0,0,1)}static xRotation(e){return e*=.5,new ae(Math.sin(e),0,0,Math.cos(e))}static yRotation(e){return e*=.5,new ae(0,Math.sin(e),0,Math.cos(e))}static zRotation(e){return e*=.5,new ae(0,0,Math.sin(e),Math.cos(e))}static axisAngleToQuat(e,t=0){let i=e.getNormal(),n=.5*t,r=Math.sin(n);return new ae(i.x*r,i.y*r,i.z*r,Math.cos(n))}static getLookRotation(e,t){let i=e.getNormal().negate(),n=t.cross(i).normalize(),r=i.cross(n),s=1+n.x+r.y+i.z;if(s>1e-6){let e=1/(2*Math.sqrt(s));return new ae((i.y-r.z)*e,(n.z-i.x)*e,(r.x-n.y)*e,.25/e)}if(n.x>r.y&&n.x>i.z){let e=1/(2*Math.sqrt(1+n.x-r.y-i.z));return new ae(.25/e,(r.x+n.y)*e,(n.z+i.x)*e,(i.y-r.z)*e)}if(r.y>i.z){let e=1/(2*Math.sqrt(1+r.y-n.x-i.z));return new ae((r.x+n.y)*e,.25/e,(i.y+r.z)*e,(n.z-i.x)*e)}let a=1/(2*Math.sqrt(1+i.z-n.x-r.y));return new ae((n.z+i.x)*a,(i.y+r.z)*a,.25/a,(r.x-n.y)*a)}static getLookAtSourceDest(e,t){let i=t.subA(e).normalize(),n=oe.FORWARD.dot(i);if(Math.abs(n- -1)<1e-6)return ae.axisAngleToQuat(oe.UP,Math.PI);if(Math.abs(n-1)<1e-6)return new ae(0,0,0,1);let r=Math.acos(n),s=oe.FORWARD.cross(i).normalize();return ae.axisAngleToQuat(s,r)}static getRotationBetweenVectors(e,t){let i=e.cross(t);return new ae(i.x,i.y,i.z,1+e.dot(t)).normalize()}static getRotationBetweenVectorsRes(e,t,i){let n=e.cross(t);return i.set(n.x,n.y,n.z,1+e.dot(t)),i.normalize()}static getRotationBetweenVectorsUp(e,t,i){let n=e.dot(t);if(Math.abs(n+1)<1e-6)return ae.axisAngleToQuat(i,Math.PI);if(Math.abs(n-1)<1e-6)return new ae(0,0,0,1);let r=Math.acos(n),s=e.cross(t).normalize();return ae.axisAngleToQuat(s,r)}isZero(){return 0===this.x&&0===this.y&&0===this.z&&0===this.w}clear(){return this.x=this.y=this.z=this.w=0,this}set(e,t,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,this}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}setIdentity(){return this.x=0,this.y=0,this.z=0,this.w=1,this}clone(){return new ae(this.x,this.y,this.z,this.w)}add(e){return new ae(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)}sub(e){return new ae(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)}scaleTo(e){return new ae(this.x*e,this.y*e,this.z*e,this.w*e)}scale(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}toVec(){return[this.x,this.y,this.z,this.w]}setFromSphericalCoords(e,t,i){let n=Math.sin(i/2),r=Math.cos(i/2),s=Math.sin(e),a=Math.cos(e),o=Math.sin(t),l=Math.cos(t);return this.x=n*a*o,this.y=n*s,this.z=n*s*l,this.w=r,this}setLookRotation(e,t){let i=e.getNormal().negate(),n=t.cross(i).normalize(),r=i.cross(n),s=1+n.x+r.y+i.z;if(s>1e-6){let e=1/(2*Math.sqrt(s));this.x=(i.y-r.z)*e,this.y=(n.z-i.x)*e,this.z=(r.x-n.y)*e,this.w=.25/e}else if(n.x>r.y&&n.x>i.z){let e=1/(2*Math.sqrt(1+n.x-r.y-i.z));this.x=.25/e,this.y=(r.x+n.y)*e,this.z=(n.z+i.x)*e,this.w=(i.y-r.z)*e}else if(r.y>i.z){let e=1/(2*Math.sqrt(1+r.y-n.x-i.z));this.x=(r.x+n.y)*e,this.y=.25/e,this.z=(i.y+r.z)*e,this.w=(n.z-i.x)*e}else{let e=1/(2*Math.sqrt(1+i.z-n.x-r.y));this.x=(n.z+i.x)*e,this.y=(i.y+r.z)*e,this.z=.25/e,this.w=(r.x-n.y)*e}return this}toSphericalCoords(){let e=this.w,t=Math.sqrt(1-e*e);Math.abs(t)<5e-4&&(t=1);let i,n=this.x/t,r=this.y/t,s=this.z/t,a=-Math.asin(r);return i=n*n+s*s<5e-4?0:Math.atan2(n,s),i<0&&(i+=360),{lat:a,lon:i,alpha:Math.acos(e)}}setFromAxisAngle(e,t){let i=e.getNormal(),n=.5*t,r=Math.sin(n);return this.set(i.x*r,i.y*r,i.z*r,Math.cos(n)),this}getAxisAngle(){let e,t,i=this.x,n=this.y,r=this.z,s=this.w,a=Math.sqrt(i*i+n*n+r*r);if(a>1e-7){let o=1/a;e=new oe(i*o,n*o,r*o),t=s<0?2*Math.atan2(-a,-s):2*Math.atan2(a,s)}else e=new oe(0,0,0),t=0;return{axis:e,angle:t}}setFromEulerAngles(e,t,i){let n=e*c,r=t*c,s=i*c,a=Math.cos(n),o=Math.cos(r),l=Math.cos(s),h=Math.sin(n),d=Math.sin(r),_=Math.sin(s),u=o*l,f=d*_;return this.w=a*u+h*f,this.x=h*u-a*f,this.y=a*d*l+h*o*_,this.z=a*o*_-h*d*l,this.normalize()}getEulerAngles(){let e=this.x,t=this.y,i=this.z,n=this.w,r=t*t,s=n*t-i*e;return s<-1?s=-1:s>1&&(s=1),{roll:Math.atan2(2*(n*e+t*i),1-2*(e*e+r)),pitch:Math.asin(2*s),yaw:Math.atan2(2*(n*i+e*t),1-2*(r+i*i))}}setFromMatrix4(e){let t,i,n,r,s,a=[],o=e._m,l=[1,2,0];return t=o[0]+o[5]+o[10],t>0?(i=Math.sqrt(t+1),this.w=i/2,i=.5/i,this.x=(o[6]-o[9])*i,this.y=(o[8]-o[2])*i,this.z=(o[1]-o[4])*i):(n=0,o[5]>o[0]&&(n=1),o[10]>o[5*n]&&(n=2),r=l[n],s=l[r],i=Math.sqrt(o[5*n]-(o[5*r]+o[5*s])+1),a[n]=.5*i,0!==i&&(i=.5/i),a[3]=(o[4*r+s]-o[4*s+r])*i,a[r]=(o[4*n+r]+o[4*r+n])*i,a[s]=(o[4*n+s]+o[4*s+n])*i,this.x=a[0],this.y=a[1],this.z=a[2],this.w=a[3]),this}getMat4(e=new se){let t=this.x+this.x,i=this.y+this.y,n=this.z+this.z,r=this.w*t,s=this.w*i,a=this.w*n,o=this.x*t,l=this.x*i,h=this.x*n,c=this.y*i,d=this.y*n,_=this.z*n;return e.set([1-(c+_),l-a,h+s,0,l+a,1-(o+_),d-r,0,h-s,d+r,1-(o+c),0,0,0,0,1])}getMat3(){let e=new ne,t=e._m,i=this.x,n=this.y,r=this.z,s=this.w,a=i+i,o=n+n,l=r+r,h=i*a,c=i*o;i*=l;let d=n*o;return n*=l,r*=l,a*=s,o*=s,s*=l,t[0]=1-(d+r),t[1]=c-s,t[2]=i+o,t[3]=c+s,t[4]=1-(h+r),t[5]=n-a,t[6]=i-o,t[7]=n+a,t[8]=1-(h+d),e}mulVec3(e){let t=e.x,i=e.y,n=e.z,r=this.x,s=this.y,a=this.z,o=this.w,l=o*t+s*n-a*i,h=o*i+a*t-r*n,c=o*n+r*i-s*t;return t=-r*t-s*i-a*n,new oe(l*o+t*-r+h*-a-c*-s,h*o+t*-s+c*-r-l*-a,c*o+t*-a+l*-s-h*-r)}mul(e){let t=this.x,i=this.y,n=this.z,r=this.w,s=e.x,a=e.y,o=e.z,l=e.w;return new ae(t*l+r*s+i*o-n*a,i*l+r*a+n*s-t*o,n*l+r*o+t*a-i*s,r*l-t*s-i*a-n*o)}mulA(e){let t=this.x,i=this.y,n=this.z,r=this.w,s=e.x,a=e.y,o=e.z,l=e.w;return this.x=t*l+r*s+i*o-n*a,this.y=i*l+r*a+n*s-t*o,this.z=n*l+r*o+t*a-i*s,this.w=r*l-t*s-i*a-n*o,this}conjugate(){return new ae(-this.x,-this.y,-this.z,this.w)}inverse(){let e=1/this.magnitude2();return new ae(-this.x*e,-this.y*e,-this.z*e,this.w*e)}magnitude(){let e=this.x,t=this.y,i=this.z,n=this.w;return Math.sqrt(e*e+t*t+i*i+n*n)}magnitude2(){let e=this.x,t=this.y,i=this.z,n=this.w;return e*e+t*t+i*i+n*n}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}normalize(){let e=this.x,t=this.y,i=this.z,n=this.w,r=Math.sqrt(e*e+t*t+i*i+n*n);return 0===r?(this.x=0,this.y=0,this.z=0,this.w=0,this):(r=1/r,this.x=e*r,this.y=t*r,this.z=i*r,this.w=n*r,this)}isEqual(e){let t=this.dot(e);return Math.abs(t-1)<.001}slerp(e,t){let i,n,r,s,a,o=this.x,l=this.y,h=this.z,c=this.w,d=e.x,_=e.y,u=e.z,f=e.w;return n=o*d+l*_+h*u+c*f,n<0&&(n=-n,d=-d,_=-_,u=-u,f=-f),1-n>1e-6?(i=Math.acos(n),r=Math.sin(i),s=Math.sin((1-t)*i)/r,a=Math.sin(t*i)/r):(s=1-t,a=t),new ae(s*o+a*d,s*l+a*_,s*h+a*u,s*c+a*f)}getRoll(e=!1){let t=this.x,i=this.y,n=this.z,r=this.w;if(e){let e=2*i,s=2*n,a=s*r,o=e*t,l=e*i,h=s*n;return Math.atan2(o+a,1-(l+h))}return Math.atan2(2*(t*i+r*n),r*r+t*t-i*i-n*n)}getPitch(e=!1){let t=this.x,i=this.y,n=this.z,r=this.w;if(e){let e=2*t,s=2*n,a=e*r,o=e*t,l=s*i,h=s*n;return Math.atan2(l+a,1-(o+h))}return Math.atan2(2*(i*n+r*t),r*r-t*t-i*i+n*n)}getYaw(e=!1){let t=this.x,i=this.y,n=this.z,r=this.w;if(e){let e=2*i,s=e*r,a=2*t*t,o=2*n*t,l=e*i;return Math.atan2(o+s,1-(a+l))}return Math.asin(-2*(t*n-r*i))}}class oe{constructor(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}static get UP(){return new oe(0,1,0)}static get DOWN(){return new oe(0,-1,0)}static get RIGHT(){return new oe(1,0,0)}static get LEFT(){return new oe(-1,0,0)}static get FORWARD(){return new oe(0,0,-1)}static get BACKWARD(){return new oe(0,0,1)}static get ZERO(){return new oe}static get UNIT_X(){return new oe(1,0,0)}static get UNIT_Y(){return new oe(0,1,0)}static get UNIT_Z(){return new oe(0,0,1)}static get NORTH(){return oe.UNIT_Z}static doubleToTwoFloats(e,t,i){let n=e.x,r=e.y,s=e.z;if(n>=0){let e=65536*Math.floor(n/65536);t.x=Math.fround(e),i.x=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t.x=Math.fround(-e),i.x=Math.fround(n+e)}if(r>=0){let e=65536*Math.floor(r/65536);t.y=Math.fround(e),i.y=Math.fround(r-e)}else{let e=65536*Math.floor(-r/65536);t.y=Math.fround(-e),i.y=Math.fround(r+e)}if(s>=0){let e=65536*Math.floor(s/65536);t.z=Math.fround(e),i.z=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t.z=Math.fround(-e),i.z=Math.fround(s+e)}}static doubleToTwoFloat32Array(e,t,i){let n=e.x,r=e.y,s=e.z;if(n>=0){let e=65536*Math.floor(n/65536);t[0]=Math.fround(e),i[0]=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t[0]=Math.fround(-e),i[0]=Math.fround(n+e)}if(r>=0){let e=65536*Math.floor(r/65536);t[1]=Math.fround(e),i[1]=Math.fround(r-e)}else{let e=65536*Math.floor(-r/65536);t[1]=Math.fround(-e),i[1]=Math.fround(r+e)}if(s>=0){let e=65536*Math.floor(s/65536);t[2]=Math.fround(e),i[2]=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t[2]=Math.fround(-e),i[2]=Math.fround(s+e)}}static fromVec(e){return new oe(e[0],e[1],e[2])}static angle(e,t){return Math.acos(e.dot(t)/Math.sqrt(e.length2()*t.length2()))}static lerp(e,t,i){return new oe(e.x+(t.x-e.x)*i,e.y+(t.y-e.y)*i,e.z+(t.z-e.z)*i)}static add(e,t){let i=new oe(e.x,e.y,e.z);return i.addA(t),i}static sub(e,t){let i=new oe(e.x,e.y,e.z);return i.subA(t),i}static scale(e,t){return e.scaleTo(t)}static mul(e,t){let i=new oe(e.x,e.y,e.z);return i.mulA(t),i}static noncollinear(e,t){return Boolean(e.y*t.z-e.z*t.y||e.z*t.x-e.x*t.z||e.x*t.y-e.y*t.z)}static proj_b_to_plane(e,t,i){let n=e.sub(t.scaleTo(t.dot(e)/t.dot(t)));return i&&n.isZero()?new oe(i.x,i.y,i.z):n}static proj_b_to_a(e,t){return t.scaleTo(t.dot(e)/t.dot(t))}static orthoNormalize(e,t){return(e=e.getNormal()).scale(t.dot(e)),t.subA(e).normalize()}static div(e,t){let i=new oe(e.x,e.y,e.z);return i.divA(t),i}static length2(e){return e.length2()}static dot(e,t){return e.dot(t)}toVec4(){return new re(this.x,this.y,this.z,1)}clone(){return new oe(this.x,this.y,this.z)}toString(){return`(${this.x},${this.y},${this.z})`}isZero(){return!(this.x||this.y||this.z)}projToVec(e){return e.scaleTo(e.dot(this)/e.dot(e))}equal(e){return this.x===e.x&&this.y===e.y&&this.z===e.z}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}length2(){return this.x*this.x+this.y*this.y+this.z*this.z}getQuat(){return new ae(this.x,this.y,this.z)}addA(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}add(e){return new oe(this.x+e.x,this.y+e.y,this.z+e.z)}subA(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}sub(e){return new oe(this.x-e.x,this.y-e.y,this.z-e.z)}scale(e){return this.x*=e,this.y*=e,this.z*=e,this}scaleTo(e){return new oe(this.x*e,this.y*e,this.z*e)}mulA(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}mul(e){return new oe(this.x*e.x,this.y*e.y,this.z*e.z)}divA(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}div(e){return new oe(this.x/e.x,this.y/e.y,this.z/e.z)}dot(e){return e.x*this.x+e.y*this.y+e.z*this.z}dotArr(e){return e[0]*this.x+e[1]*this.y+e[2]*this.z}cross(e){return new oe(this.y*e.z-this.z*e.y,this.z*e.x-this.x*e.z,this.x*e.y-this.y*e.x)}clear(){return this.x=this.y=this.z=0,this}getNormal(){let e=new oe;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normal(){let e=new oe;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegate(){let e=new oe;e.copy(this);let t=-1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegateScale(e){let t=new oe;t.copy(this);let i=-e/t.length();return t.x*=i,t.y*=i,t.z*=i,t}normalScale(e){let t=new oe;t.copy(this);let i=e/t.length();return t.x*=i,t.y*=i,t.z*=i,t}normalize(){let e=1/this.length();return this.x*=e,this.y*=e,this.z*=e,this}toVec(){return[this.x,this.y,this.z]}toArray(){return[this.x,this.y,this.z]}distance(e){let t=this.x-e.x,i=this.y-e.y,n=this.z-e.z;return Math.sqrt(t*t+i*i+n*n)}distance2(e){let t=this.x-e.x,i=this.y-e.y,n=this.z-e.z;return t*t+i*i+n*n}set(e,t,i){return this.x=e,this.y=t,this.z=i,this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}negateTo(){return new oe(-this.x,-this.y,-this.z)}projToRay(e,t){let i=oe.proj_b_to_a(oe.sub(this,e),t);return i.addA(e),i}angle(e){return oe.angle(this,e)}lerp(e,t){return new oe(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t,this.z+(e.z-this.z)*t)}smerp(e,t){let i=1-t;return new oe(this.x*t+e.x*i,this.y*t+e.y*i,this.z*t+e.z*i)}static get LERP_DELTA(){return 1e-6}slerp(e,t){let i,n,r,s,a=new oe;if(t<=0)return a.copy(this),a;if(t>=1)return a.copy(e),a;let o=this.dot(e);return 1-o>oe.LERP_DELTA?(i=Math.acos(o),n=Math.sin(i),r=Math.sin((1-t)*i)/n,s=Math.sin(t*i)/n):(r=1-t,s=t),oe.add(this.scaleTo(r),e.scale(s))}getRotationTo(e,t){let i=this.clone(),n=e.clone();i.normalize(),n.normalize();let r=i.dot(n);if(r>=1)return ae.IDENTITY.clone();if(r<-.999999){if(t.equal(oe.ZERO)){let e=oe.UNIT_X.cross(i);return e.isZero()&&(e=oe.UNIT_Y.cross(i)),e.normalize(),ae.axisAngleToQuat(e,Math.PI)}return ae.axisAngleToQuat(t,Math.PI)}{let e=Math.sqrt(2*(1+r)),t=1/e,s=i.cross(n),a=new ae(s.x*t,s.y*t,s.z*t,.5*e);return a.normalize(),a}}}class le{constructor(e=0,t=0){this.x=e,this.y=t}static get UP(){return new le(0,1)}static get DOWN(){return new le(0,-1)}static get RIGHT(){return new le(1,0)}static get LEFT(){return new le(-1,0)}static get ZERO(){return new le}static add(e,t){const i=new le(e.x,e.y);return i.addA(t),i}static sub(e,t){var i=new le(e.x,e.y);return i.subA(t),i}static scale(e,t){let i=new le(e.x,e.y);return i.scale(t),i}static mul(e,t){let i=new le(e.x,e.y);return i.mulA(t),i}static div(e,t){let i=new le(e.x,e.y);return i.divA(t),i}static proj_b_to_a(e,t){return t.scaleTo(t.dot(e)/t.dot(t))}static angle(e,t){return Math.acos(e.dot(t)/Math.sqrt(e.length2()*t.length2()))}static orthoNormalize(e,t){return(e=e.normal()).scale(t.dot(e)),t.sub(e).normalize()}toVector3(){return new oe(this.x,this.y,0)}clone(){return new le(this.x,this.y)}equal(e){return this.x===e.x&&this.y===e.y}copy(e){return this.x=e.x,this.y=e.y,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}length2(){return this.x*this.x+this.y*this.y}addA(e){return this.x+=e.x,this.y+=e.y,this}add(e){return new le(this.x+e.x,this.y+e.y)}subA(e){return this.x-=e.x,this.y-=e.y,this}sub(e){return new le(this.x-e.x,this.y-e.y)}scale(e){return this.x*=e,this.y*=e,this}scaleTo(e){return new le(this.x*e,this.y*e)}mulA(e){return this.x*=e.x,this.y*=e.y,this}mul(e){return new le(this.x*e.x,this.y*e.y)}divA(e){return this.x/=e.x,this.y/=e.y,this}dot(e){return e.x*this.x+e.y*this.y}dotArr(e){return e[0]*this.x+e[1]*this.y}cross(e){return this.x*e.y-this.y*e.x}clear(){return this.x=this.y=0,this}normal(){let e=new le;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e}normalize(){let e=1/this.length();return this.x*=e,this.y*=e,this}toVec(){return[this.x,this.y]}distance(e){return le.sub(this,e).length()}set(e,t){return this.x=e,this.y=t,this}negate(){return this.x=-this.x,this.y=-this.y,this}negateTo(){return new le(-this.x,-this.y)}projToRay(e,t){let i=le.proj_b_to_a(le.sub(this,e),t);return i.add(e),i}angle(e){return le.angle(this,e)}lerp(e,t,i){let n=this.clone();return i<=0?n.copy(e):i>=1?n.copy(t):n=le.add(e,le.sub(t,e).scale(i)),n}static get LERP_DELTA(){return 1e-6}slerp(e,t){let i,n,r,s,a=new le;if(t<=0)return a.copy(this),a;if(t>=1)return a.copy(e),a;let o=this.dot(e);return 1-o>le.LERP_DELTA?(i=Math.acos(o),n=Math.sin(i),r=Math.sin((1-t)*i)/n,s=Math.sin(t*i)/n):(r=1-t,s=t),le.add(this.scale(r),e.scale(s))}}const he={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4","indianred ":"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};function ce(e,t){return null!=e?e:t}function de(e){return null==e}function _e(e){return void 0===e}let ue=0;function fe(e){let t=e._openglobus_id;return t||(t=e._openglobus_id=++ue),t}function ge(e){return"string"==typeof e||e instanceof String}function pe(e){return e.toString(16).padStart(2,"0")}function me(e){let t,i,n;return e instanceof Array?(t=pe(e[0]),i=pe(e[1]),n=pe(e[2])):(t=pe(e.x),i=pe(e.y),n=pe(e.z)),`#${t}${i}${n}`}function ve(e,t){let i=he[e];if(i&&(e=i),"#"===e[0]){let i=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,n=e.replace(i,(function(e,t,i,n){return t+t+i+i+n+n})),r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return r?new re(parseInt(r[1],16)/255,parseInt(r[2],16)/255,parseInt(r[3],16)/255,de(t)?1:t):new re}{de(t)&&(t=1);let i=e.split(",");return new re(parseInt(i[0].split("(")[1])/255,parseInt(i[1])/255,parseInt(i[2])/255,de(i[3])?t:parseFloat(i[3]))}}function ye(e,t){let i=ve(e,t);return new Float32Array([i.x,i.y,i.z,i.w])}function xe(e){let t=he[e];if(t&&(e=t),"#"===e[0]){let t=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,i=e.replace(t,(function(e,t,i,n){return t+t+i+i+n+n})),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i);return n?new oe(parseInt(n[1],16)/255,parseInt(n[2],16)/255,parseInt(n[3],16)/255):new oe}{let t=e.split(",");return new oe(parseInt(t[0].split("(")[1])/255,parseInt(t[1])/255,parseInt(t[2])/255)}}function be(e,t){return e.replace(/{[^{}]+}/g,(function(e){return t[e.replace(/[{}]+/g,"")]||""}))}function we(e){let t=document.createElement("div");t.innerHTML=e;let i=[];for(let e=0;e<t.childNodes.length;e++)i.push(t.childNodes[e]),t.removeChild(t.childNodes[e]);return i}function Ce(e,t,i,n){let r=document.getElementById(e);r||(r=document.createElement("div"),r.id=e,r.classList.add("defaultText"),document.body.appendChild(r)),r.innerHTML=t,r.style.left=`${i}px`,r.style.top=`${n}px`}function Te(e){return"number"==typeof e}function Le(e,t=""){return e?e.trim():t}function Ae(e,t){if(e){if(Te(e))return new oe(e,e,e);if(e instanceof oe)return e.clone();if(e instanceof Array)return oe.fromVec(e);if(e instanceof le)return new oe(e.x,e.y,0)}else if(t)return t;return new oe}function Ee(e,t){if(e){if(ge(e))return ve(e);if(e instanceof Array)return re.fromVec(e);if(e instanceof re)return e.clone()}else if(t)return t;return new re(1,1,1,1)}function Pe(e,t){if(e){if(ge(e))return xe(e);if(e instanceof Array)return oe.fromVec(e);if(e instanceof oe)return e.clone()}else if(t)return t;return new oe(1,1,1)}function Se(e,t){if(e){if(e instanceof Array)return new ie(Me(e[0]),Me(e[1]));if(e instanceof ie)return e.clone()}else if(t)return t;return new ie}function Me(e,t){if(e){if(e instanceof Array)return new z(e[0],e[1],e[2]);if(e instanceof z)return e.clone()}else if(t)return t;return new z}function Be(e,t){let i=0,n=e.length-1;for(;i<=n;){let r=Math.floor(.5*(i+n));if(Math.abs(e[r]-t)<.001)return r;e[r]<t?i=r+1:n=r-1}return-1}function ke(e,t,i){let n=0,r=e.length-1;for(;n<=r;){let s=r+n>>1,a=i(t,e[s],s);if(a>0)n=s+1;else{if(!(a<0))return s;r=s-1}}return-n-1}function Re(e,t,i){let n=ke(e,t,i);return n<0&&(n=~n),e.splice(n,0,t),n}function Ie(e,t,i,n,r=!1){let s=new z(t.lon-e.lon,t.lat-e.lat),a=new z(n.lon-i.lon,n.lat-i.lat),o=-s.lat,l=+s.lon,h=-(o*e.lon+l*e.lat),c=-a.lat,d=+a.lon,_=-(c*i.lon+d*i.lat),u=c*e.lon+d*e.lat+_,f=c*t.lon+d*t.lat+_,g=o*i.lon+l*i.lat+h,p=o*n.lon+l*n.lat+h;if(r&&(u*f>0||g*p>0))return;let m=u/(u-f);return new z(e.lon+m*s.lon,e.lat+m*s.lat)}const ze={string:function(e){return de(e)?e:e.toString()},date:function(e){return de(e)?e:new Date(1e3*e)},datetime:function(e){return de(e)?e:new Date(1e3*e)},time:function(e){return de(e)?e:parseInt(e)},integer:function(e){return de(e)?e:parseInt(e)},float:function(e){return de(e)?e:parseFloat(e)},boolean:function(e){if(null===e)return e;if("boolean"==typeof e)return!0===e;if("string"==typeof e){if(""===e)return!1;if("true"===(e=e.replace(/^\s+|\s+$/g,"")).toLowerCase()||"yes"===e.toLowerCase())return!0;e=(e=e.replace(/,/g,".")).replace(/^\s*\-\s*/g,"-")}return!isNaN(e)&&0!==parseFloat(e)}};function De(e,t=""){let i=1024,n=atob(e),r=n.length,s=Math.ceil(r/i),a=new Array(s);for(let e=0;e<s;++e){let t=e*i,s=Math.min(t+i,r),o=new Array(s-t);for(let e=t,i=0;e<s;++i,++e)o[i]=n[e].charCodeAt(0);a[e]=new Uint8Array(o)}return new Blob(a,{type:t})}function Fe(e,t,i=!1){let n,r=0;return function(){const s=arguments;r?(i&&clearTimeout(n),n=setTimeout((()=>{Date.now()-r>=t&&(e.apply(null,s),r=Date.now())}),t-(Date.now()-r))):(e.apply(null,s),r=Date.now())}}function Ne(e,t){let i=new e.constructor(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function He(e=[],t=[]){if(ArrayBuffer.isView(e))return Ne(e,t);for(let i=0;i<t.length;i++)e.push(t[i]);return e}function Oe(e,t=Float32Array){if(ArrayBuffer.isView(e))return e;{const i=new t(e.length);return i.set(e,0),i}}function Ve(e){return ArrayBuffer.isView(e)?Array.from(e):e}function Ue(e,t,i,n){if(ArrayBuffer.isView(e))return t<0&&(i=Math.abs(t),t+=e.length),Ge(e,t,i,n);{let r;return r=t<0?e.splice(t):e.splice(t,i),n&&(n.result=r),e}}function Ge(e,t,i,n){if(0===e.length)return e;const r=e.length-i,s=new e.constructor(r);return s.set(e.subarray(0,t)),s.set(e.subarray(t+i),t),n&&(n.result=e.subarray(t,t+i)),s}function We(e,t,i,n,r){const s=r+1,a=i+s,o=n+s;let l=new Float64Array(s*s*3),h=0;for(let r=i;r<a;r++)for(let i=n;i<o;i++){let n=3*(r*(t+1)+i);l[h++]=e[n],l[h++]=e[n+1],l[h++]=e[n+2]}return l}function je(e,t,i,n,r){const s=r+1,a=i+s,o=n+s;let l=new Float32Array(s*s*3),h=0;for(let r=i;r<a;r++)for(let i=n;i<o;i++){let n=3*(r*(t+1)+i);l[h++]=e[n],l[h++]=e[n+1],l[h++]=e[n+2]}return l}function Ye(e,t,i,n,r,s,a,o,l,h,c,d,_){const u=s+o+1,f=a+o+1;r+=1;let g=0,p=0;for(let o=s;o<u;o++)for(let s=a;s<f;s++){let a=o*r+s,u=3*a,f=e[u],m=e[u+1],v=e[u+2];n&&0!==n[a]?_[p]=1:(f<d.xmin&&(d.xmin=f),f>d.xmax&&(d.xmax=f),m<d.ymin&&(d.ymin=m),m>d.ymax&&(d.ymax=m),v<d.zmin&&(d.zmin=v),v>d.zmax&&(d.zmax=v)),p++,l[g]=f,c[g]=i[u],h[g++]=t[u],l[g]=m,c[g]=i[u+1],h[g++]=t[u+1],l[g]=v,c[g]=i[u+2],h[g++]=t[u+2]}}function qe(e){return e.map((e=>Array.isArray(e)?qe(e):e))}async function Xe(e){return new Promise((t=>{const i=new Image;return i.addEventListener("load",(()=>{t(i)})),i.src=e,i.crossOrigin="",i}))}function $e(e){return e.complete&&0!==e.naturalHeight}function Ze(e){if(e>1e3){return 0!==e-Math.floor(e)?[(e/1e3).toFixed(2),"km"]:[(e/1e3).toFixed(0),"km"]}return e>9?[Math.round(e).toString(),"m"]:e<=.01?["0","m"]:[e.toFixed(1),"m"]}function Ke(e){let t=new URLSearchParams(location.search).get(e);if(t)return Number(t)}var Qe=Object.freeze({__proto__:null,base64StringToBlog:function(e){let t=e.split(";"),i=t[0].split(":")[1];return De(t[1].split(",")[1],i)},base64toBlob:De,binaryInsert:Re,binarySearch:ke,binarySearchFast:Be,blerp:function(e,t,i,n,r,s,a=0,o=1,l=0,h=1){return(i*(o-e)*(h-t)+n*(e-a)*(h-t)+r*(o-e)*(t-l)+s*(e-a)*(t-l))/((o-a)*(h-l))},blerp2:function(e,t,i,n,r,s){return i*(1-e)*(1-t)+n*e*(1-t)+r*(1-e)*t+s*e*t},castType:ze,cloneArray:qe,concatArrays:He,concatTypedArrays:Ne,createColorRGB:Pe,createColorRGBA:Ee,createExtent:Se,createLonLat:Me,createVector3:Ae,createVector4:function(e,t){if(e){if(e instanceof re)return e.clone();if(e instanceof Array)return re.fromVec(e)}else if(t)return t;return new re},defaultString:Le,distanceFormat:function(e){return e>1e3?`${(e/1e3).toFixed(2)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`},distanceFormatExt:Ze,extractElevationTiles:function(e,t,i){let n=Math.sqrt(t.length)-1,r=n+1,s=Math.sqrt(e.length/4),a=s/n,o=0,l=0;for(let h=0,c=0,d=e.length/4;h<d;h++){let d=e[4*h],_=Math.floor(h/s),u=h%s,f=Math.floor(u/n),g=Math.floor(_/n),p=i[g][f],m=_%n,v=u%n,y=(m+g)*r+v+f;if(p[y]=d,(_+g)%a==0&&(u+f)%a==0&&(t[c++]=d),(u+1)%n==0&&u!==s-1){o=e[4*(h+1)];let s=.5*(d+o);y=(m+g)*r+v+1,p[y]=s,(_+g)%a==0&&(t[c++]=s);let l=(m+g)*r+(v+1)%n;i[g][f+1][l]=s}if((_+1)%n==0&&_!==s-1){l=e[4*(h+s)];let o=.5*(d+l);y=(m+1)*r+v+f,p[y]=o,(u+f)%a==0&&(t[c++]=o);let _=(m+1)%n*r+v+f;i[g+1][f][_]=o}if((u+1)%n==0&&u!==s-1&&(_+1)%n==0&&_!==s-1){let a=.25*(d+o+l+e[4*(h+s+1)]);y=(m+1)*r+(v+1),p[y]=a,t[c++]=a;let _=(m+1)*r;i[g][f+1][_]=a;let u=n;i[g+1][f][u]=a;let x=0;i[g+1][f+1][x]=a}}},getDefault:ce,getHTML:function(e,t){return be(e,t)},getLinesIntersection2v:function(e,t,i,n,r){let s=t.sub(e),a=n.sub(i),o=-s.y,l=+s.x,h=-(o*e.x+l*e.y),c=-a.y,d=+a.x,_=-(c*i.x+d*i.y),u=c*e.x+d*e.y+_,f=c*t.x+d*t.y+_,g=o*i.x+l*i.y+h,p=o*n.x+l*n.y+h;if(r&&(u*f>0||g*p>0))return;let m=u/(u-f);return new le(e.x+m*s.x,e.y+m*s.y)},getLinesIntersectionLonLat:Ie,getMatrixSubArray32:je,getMatrixSubArray64:We,getMatrixSubArrayBoundsExt:Ye,getUrlParam:Ke,htmlColorToFloat32Array:ye,htmlColorToRgb:xe,htmlColorToRgba:ve,isEmpty:de,isImageLoaded:$e,isNumber:Te,isString:ge,isUndef:_e,isUndefExt:function(e,t){return _e(e)?t:e},loadImage:Xe,makeArray:Ve,makeArrayTyped:Oe,parseHTML:we,print2d:Ce,rgbToStringHTML:me,spliceArray:Ue,spliceTypedArray:Ge,stamp:fe,stringTemplate:be,throttle:Fe,xmlToJson:function e(t){let i={};if(1===t.nodeType){if(t.attributes.length>0){i["@attributes"]={};for(let e=0;e<t.attributes.length;e++){let n=t.attributes.item(e);i["@attributes"][n.nodeName]=n.nodeValue}}}else 3===t.nodeType&&(i=t.nodeValue);if(t.hasChildNodes())for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes.item(n),s=r.nodeName;if(void 0===i[s])i[s]=e(r);else{if(void 0===i[s].push){let e=i[s];i[s]=[],i[s].push(e)}i[s].push(e(r))}}return i}});const Je=.001,et=1e3,tt=60,it=1/tt,nt=1/24,rt=3600,st=1/rt,at=12*rt,ot=1440,lt=1/ot,ht=86400,ct=864e5,dt=1.1574074074074074e-8,_t=1/ht,ut=2451545;function ft(e,t,i){let n=(t-14)/12|0,r=e+4800+n;return(1461*r/4|0)+(367*(t-2-12*n)/12|0)-(3*((r+100)/100|0)/4|0)+i-32075}function gt(e){let t=ft(e.getUTCFullYear(),e.getUTCMonth()+1,e.getUTCDate()),i=e.getUTCHours()-12;i<0&&(i+=24);let n=e.getUTCSeconds()+i*rt+e.getUTCMinutes()*tt+e.getUTCMilliseconds()*Je;n>=at&&t--;let r=n*_t|0;return t+=r,n-=ht*r,n<0&&(t--,n+=ht),t+n*_t}function pt(e){let t=wt,i=ke(t,e,(function(e,t){return e-t.jd}));i<0&&(i=~i),i>=t.length&&(i=t.length-1);let n=t[i].leapSeconds;return 0!==i&&(t[i].jd-e)*ht>n&&(n=t[i-1].leapSeconds),e+n*_t}function mt(e){let t=wt,i=ke(t,e,(function(e,t){return e-t.jd}));if(i<0&&(i=~i),i>=t.length)return e-t[i-1].leapSeconds*_t;if(0===i)return e-t[0].leapSeconds*_t;let n=(t[i].jd-e)*ht;return 0===n?e-t[i].leapSeconds*_t:n<=1?void 0:e-t[i-1].leapSeconds*_t}function vt(e){let t=0|e,i=(e-t)*ht;i>=at&&t++;let n=t+68569|0,r=4*n/146097|0;n=n-((146097*r+3)/4|0)|0;let s=4e3*(n+1)/1461001|0;n=n-(1461*s/4|0)+31|0;let a=80*n/2447|0,o=n-(2447*a/80|0)|0;n=a/11|0;let l=a+2-12*n|0,h=100*(r-49)+s+n|0,c=i*st|0,d=i-c*rt,_=d*it|0;d-=_*tt;let u=0|d,f=(d-u)*et|0;return c+=12,c>23&&(c-=24),new Date(Date.UTC(h,l-1,o,c,_,u,f))}function yt(e,t){return e+t*dt}function xt(e,t){return e+t*_t}function bt(e,t){return{jd:e,leapSeconds:t}}const wt=[bt(2441317.5,10),bt(2441499.5,11),bt(2441683.5,12),bt(2442048.5,13),bt(2442413.5,14),bt(2442778.5,15),bt(2443144.5,16),bt(2443509.5,17),bt(2443874.5,18),bt(2444239.5,19),bt(2444786.5,20),bt(2445151.5,21),bt(2445516.5,22),bt(2446247.5,23),bt(2447161.5,24),bt(2447892.5,25),bt(2448257.5,26),bt(2448804.5,27),bt(2449169.5,28),bt(2449534.5,29),bt(2450083.5,30),bt(2450630.5,31),bt(2451179.5,32),bt(2453736.5,33),bt(2454832.5,34),bt(2456109.5,35),bt(2457204.5,36)],Ct=pt(ut);var Tt=Object.freeze({__proto__:null,DAYS_PER_JULIAN_CENTURY:36525,DAYS_PER_JULIAN_YEAR:365.25,DateToTAI:function(e){return pt(gt(e))},DateToUTC:gt,HOURS_PER_DAY:24,J2000:ut,J2000TAI:Ct,MILLISECONDS_PER_DAY:ct,MILLISECONDS_PER_SECOND:et,MINUTES_PER_DAY:ot,MINUTES_PER_HOUR:60,MODIFIED_JULIAN_DATE_DIFFERENCE:2400000.5,ONE_BY_HOURS_PER_DAY:nt,ONE_BY_MILLISECONDS_PER_DAY:dt,ONE_BY_MINUTES_PER_DAY:lt,ONE_BY_SECONDS_PER_DAY:_t,ONE_BY_SECONDS_PER_HOUR:st,ONE_BY_SECONDS_PER_MINUTE:it,PICOSECOND:1e-9,SECONDS_PER_12_HOURS:at,SECONDS_PER_DAY:ht,SECONDS_PER_HOUR:rt,SECONDS_PER_MILLISECOND:Je,SECONDS_PER_MINUTE:tt,T:function(e){return(e-ut)/36525},TAItoDate:function(e){let t=mt(e);return t||(t=mt(xt(e,-1)),console.trace(`TAItoDate - can't convert ${e.toString()} to utc.`)),vt(t)},TAItoUTC:mt,UTCtoDate:vt,UTCtoTAI:pt,addDays:function(e,t){return e+t},addHours:function(e,t){return e+t*nt},addMilliseconds:yt,addMinutes:function(e,t){return e+t*ot},addSeconds:xt,daysToSeconds:function(e){return e*ht},getDayNumber:ft,getDays:function(e){return 0|e},getHours:function(e){let t=(e-(0|e))*ht,i=t*st|0,n=t-i*rt,r=n*it|0;n-=r*tt;let s=0|n;return i+=12+r/60+s/3600+((n-s)*et|0)/1e3,i>23&&(i-=24),i},getMilliseconds:function(e){let t=e-(0|e);return t*=ht,(t-(0|t))*et|0},getMinutes:function(e){return(e-(0|e))*ot|0},getSeconds:function(e){return(e-(0|e))*ht},secondsToDays:function(e){return e*_t}});class Lt{constructor(e){this.vertices=[new oe,new oe,new oe,new oe,new oe,new oe,new oe,new oe],e&&this.setFromBoundsArr(e)}copy(e){for(let t=0,i=this.vertices.length;t<i;t++)this.vertices[t].copy(e.vertices[t])}setFromBoundsArr(e){let t=e[0],i=e[3],n=e[1],r=e[4],s=e[2],a=e[5],o=this.vertices;o[0].set(t,n,s),o[1].set(i,n,s),o[2].set(i,n,a),o[3].set(t,n,a),o[4].set(t,r,s),o[5].set(i,r,s),o[6].set(i,r,a),o[7].set(t,r,a)}setFromExtent(e,t){this.setFromBoundsArr(t.getCartesianBounds(e))}}class At{constructor(e=0,t){this.radius=e,this.center=t?t.clone():new oe}setFromBounds(e){let t=new oe(e[0],e[1],e[2]);this.center.set(t.x+.5*(e[3]-t.x),t.y+.5*(e[3]-t.y),t.z+.5*(e[5]-t.z)),this.radius=this.center.distance(t)}setFromExtent(e,t){this.setFromBounds(t.getCartesianBounds(e))}}var Et=Object.freeze({__proto__:null,Box:Lt,Sphere:At});function Pt(e,t){return new St(e,t)}class St{constructor(e,t){this.__id=St.__counter__++,this._eventNames=[],e&&this.registerNames(e),this._sender=t||this,this._stopPropagation=!1,this._stampCache={}}bindSender(e){this._sender=e||this}registerNames(e){for(let t=0;t<e.length;t++)this[e[t]]={active:!0,handlers:[]},this._eventNames.push(e[t]);return this}_getStamp(e,t,i){return`${e}_${t}_${i}`}_stamp(e,t){let i=fe(t),n=this._getStamp(e,this.__id,i);return!this._stampCache[n]&&(this._stampCache[n]=i,!0)}on(e,t,i,n=0){if(this._stamp(e,t)&&this[e]){let r=t.bind(i||this._sender);r._openglobus_id=t._openglobus_id,r._openglobus_priority=n,Re(this[e].handlers,r,((e,t)=>(t._openglobus_priority||0)-(e._openglobus_priority||0)))}}off(e,t){if(t){let i=this._getStamp(e,this.__id,t._openglobus_id);if(t._openglobus_id&&this._stampCache[i]){let n=this[e].handlers,r=n.length,s=-1;for(;r--;){if(n[r]._openglobus_id===t._openglobus_id){s=r;break}}-1!==s&&(n.splice(s,1),this._stampCache[i]=void 0,delete this._stampCache[i])}}}dispatch(e,...t){let i=!0;if(e&&e.active&&!this._stopPropagation){let n=e.handlers.slice(0),r=n.length;for(;r--;)!1===n[r](...t)&&(i=!1)}return this._stopPropagation=!1,i}stopPropagation(){this._stopPropagation=!0}clear(){for(let e=0;e<this._eventNames.length;e++){let t=this[this._eventNames[e]];t.handlers.length=0,t.handlers=[]}this._eventNames.length=0,this._eventNames=[]}}St.__counter__=0;const Mt=["render"];class Bt{constructor(e={}){this.__id=Bt.__counter__++,this.events=Pt(Mt),this.model=e.model||null,this.template=e.template||"",this.parent=e.parent||null,this._classList=e.classList||[],this.el=null}static getHTML(e,t){return be(e,t)}static parseHTML(e){return we(e)}static insertAfter(e,t){Array.isArray(e)||(e=[e]);for(let i=0;i<e.length;i++)t.parentNode&&t.parentNode.insertBefore(e[i],t.nextSibling);return e}static insertBefore(e,t){Array.isArray(e)||(e=[e]);for(let i=0;i<e.length;i++)t.parentNode&&t.parentNode.insertBefore(e[i],t);return e}insertBefore(e){this.el||this.render(),this.el&&(e instanceof HTMLElement&&e.parentNode&&Bt.insertBefore(this.el,e),e instanceof Bt&&e.el&&e.el.parentNode&&Bt.insertBefore(this.el,e.el))}insertAfter(e){this.el||this.render(),this.el&&(e instanceof HTMLElement&&e.parentNode&&Bt.insertAfter(this.el,e),e instanceof Bt&&e.el&&e.el.parentNode&&Bt.insertAfter(this.el,e.el))}isEqual(e){return e.__id===this.__id}appendTo(e,t=!1,i=!1){return e&&(this.el||(this.beforeRender(e),this.render()),this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),t&&(e.innerHTML=""),this.el&&(i&&e.childNodes[0]?Bt.insertBefore(this.el,e.childNodes[0]):e.appendChild(this.el)),this.afterRender(e)),this}afterRender(e){}beforeRender(e){}stopPropagation(){this.events.stopPropagation()}renderTemplate(e){return Bt.parseHTML(Bt.getHTML(this.template,e||{}))[0]}render(e){this.el=this.renderTemplate(e);for(let e=0,t=this._classList.length;e<t;e++)this.el.classList.add(this._classList[e]);return this.events.dispatch(this.events.render,this),this}select(e){return this.el?this.el.querySelector(e):null}selectRemove(e){if(this.el){let t=this.select(e);if(t&&t.parentNode)return t.parentNode.removeChild(t),t}}selectAll(e,t){if(this.el){const i=this.el.querySelectorAll(e);if(t)for(let e=0,n=i.length;e<n;e++)t(i[e],e);return i}}remove(){this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el)}}Bt.__counter__=0;const kt=["click","mousedown","mouseup","touchstart","touchend","touchcancel"];class Rt extends Bt{constructor(e={}){super({template:be('<div class="og-button" title="{title}">\n <div class="og-button-icon">{icon}</div>\n <div class="og-button-text">{text}</div>\n </div>',{icon:e.icon||"",text:e.text||"",title:e.title||""}),...e}),this._onMouseDown=e=>{e.preventDefault(),this.events.dispatch(this.events.mousedown,this,e)},this._onMouseUp=e=>{e.preventDefault(),this.events.dispatch(this.events.mouseup,this,e)},this._onTouchStart=e=>{e.preventDefault(),this.events.dispatch(this.events.touchstart,this,e)},this._onTouchEnd=e=>{e.preventDefault(),this.events.dispatch(this.events.touchend,this,e)},this._onTouchCancel=e=>{e.preventDefault(),this.events.dispatch(this.events.touchcancel,this,e)},this._onMouseClick=e=>{this._mouseClickHandler(e)},this.events=this.events.registerNames(kt),this.el=null,this.name=e.name||"",this.$icon=null,this.$text=null}render(e){return super.render(e),this.$icon=this.select(".og-button-icon"),this.$text=this.select(".og-button-text"),this.el.__og_button__=this,this._initEvents(),this}_initEvents(){this.el&&(this.el.addEventListener("click",this._onMouseClick),this.el.addEventListener("mousedown",this._onMouseDown),this.el.addEventListener("mouseup",this._onMouseUp),this.el.addEventListener("touchstart",this._onTouchStart),this.el.addEventListener("touchend",this._onTouchEnd),this.el.addEventListener("touchcancel",this._onTouchCancel))}_mouseClickHandler(e){e.preventDefault(),this.events.dispatch(this.events.click,this,e)}remove(){this._clearEvents(),super.remove()}_clearEvents(){this.el&&this.el.removeEventListener("click",this._onMouseClick)}}class It{constructor(e={}){this.__id=It.__counter__++,this._name=e.name||`_control_${this.__id.toString()}`,this.planet=null,this._initialized=!1,this.renderer=null,this.autoActivate=e.autoActivate||!1,this._active=!1,this._deferredActive=!0}get name(){return this._name}oninit(){}onadd(){}onremove(){}onactivate(){}ondeactivate(){}addTo(e){e&&(this.renderer=e,e.controls[this.name]=this,this.onadd&&this.onadd(),e.isInitialized()&&(this._initialized=!0,this.oninit&&this.oninit(),this.autoActivate&&this.activate()))}remove(){this.deactivate(),this.onremove&&this.onremove();let e=this.renderer,t=this.name;if(!e)return;let i=e.controls[t];i&&this.isEqual(i)&&delete e.controls[t],this.renderer=null,this._active=!1,this._initialized=!1}activate(){this._active||(this._initialized||(this._initialized=!0,this.oninit&&this.oninit()),this._deferredActive?(this._active=!0,this.onactivate&&this.onactivate()):this._deferredActive=!0)}deactivate(){this._active?(this._active=!1,this.ondeactivate&&this.ondeactivate()):this._initialized||(this._deferredActive=!1)}isActive(){return this._active}isEqual(e){return e.__id===this.__id}}It.__counter__=0;class zt extends It{constructor(e={}){super(e),this._heading=0,this._svg=null}oninit(){let e=new Rt({classList:["og-map-button","og-compass-button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg\n xmlns:dc="http://purl.org/dc/elements/1.1/"\n xmlns:cc="http://creativecommons.org/ns#"\n xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n xmlns:svg="http://www.w3.org/2000/svg"\n xmlns="http://www.w3.org/2000/svg"\n xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"\n xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"\n viewBox="0 0 110.6 110.3"\n version="1.1"\n id="svg21"\n sodipodi:docname="aaa.svg"\n inkscape:version="0.92.3 (2405546, 2018-03-11)">\n <metadata\n id="metadata11">\n <rdf:RDF>\n <cc:Work\n rdf:about="">\n <dc:format>image/svg+xml</dc:format>\n <dc:type\n rdf:resource="http://purl.org/dc/dcmitype/StillImage" />\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs\n id="defs25" />\n <sodipodi:namedview\n pagecolor="#ffffff"\n bordercolor="#666666"\n borderopacity="1"\n objecttolerance="10"\n gridtolerance="10"\n guidetolerance="10"\n inkscape:pageopacity="0"\n inkscape:pageshadow="2"\n inkscape:window-width="1920"\n inkscape:window-height="1001"\n id="namedview23"\n showgrid="false"\n inkscape:zoom="9.4900968"\n inkscape:cx="28.376998"\n inkscape:cy="60.17054"\n inkscape:window-x="-9"\n inkscape:window-y="-9"\n inkscape:window-maximized="1"\n inkscape:current-layer="svg21" />\n <g\n id="Layer_2"\n data-name="Layer 2"\n transform="matrix(1,0,0,-1,0,110.3)">\n <g\n id="Слой_1"\n data-name="Слой 1">\n <g\n id="_Group_"\n data-name="<Group>">\n <g\n id="_Group_7"\n data-name="<Group>">\n <polygon\n id="_Path_7"\n data-name="<Path>"\n points="55.2,97.6 55.3,97.4 55.3,97.6 55.3,97.2 65.3,55.1 55.3,55.1 55.2,55.1 45.3,55.1 55.2,97.2 "\n style="fill:#ff2b45" />\n <polygon\n id="_Path_8"\n data-name="<Path>"\n points="55.3,12.7 55.3,12.9 55.2,12.7 55.2,13.1 45.3,55.1 55.2,55.1 55.3,55.1 65.3,55.1 55.3,13.1 "\n style="fill:#cecece;" />\n </g>\n </g>\n </g>\n </g>\n</svg>'});e.appendTo(this.renderer.div),e.events.on("click",this._onClick,this),this._svg=e.select("svg"),this.renderer.events.on("draw",this._draw,this)}_onClick(){const e=this.planet;let t=e.getCartesianFromPixelTerrain(this.renderer.handler.getCenter());t?e.flyCartesian(t.normal().scaleTo(t.length()+t.distance(e.camera.eye)),null,null,0,null,null,(()=>{e.camera.look(t)})):e.flyCartesian(e.camera.eye)}_draw(){this.setHeading(this.planet.camera.getHeading())}setHeading(e){this._heading!==e&&(this._heading=e,this._svg.style.transform=`rotateZ(${-e}deg)`)}}const Dt='<svg className="svg-icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor; overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">\n <path d="M777.856 280.192l-33.92-33.952-231.872 231.872-231.84-231.872-33.984 33.888 231.872 231.904-231.84 231.84 33.888 33.984 231.904-231.904 231.84 231.872 33.952-33.888-231.872-231.904z"/>\n</svg>',Ft=["resize","focus","visibility","dragstart","dragend"];class Nt extends Bt{constructor(e={}){super({template:be('<div class="og-ddialog" \n style="display:{display}; resize:{resize}; width: {width}px; {height}; top: {top}px; left: {left}px; min-height: {minHeight}; max-height: {maxHeight}; min-width: {minWidth}; max-width: {maxWidth};">\n <div class="og-ddialog-header">\n <div class="og-ddialog-header__title">{title}</div> \n <div class="og-ddialog-header__buttons"></div> \n </div>\n <div class="og-ddialog-container"></div>\n </div>>',{title:e.title||"",display:ce(e.visible,!0)?"flex":"none",resize:ce(e.resizable,!0)?"both":"none",width:e.width||300,height:e.height?`height: ${e.height||200}px`:"",left:e.left||0,top:e.top||0,minHeight:e.minHeight?`${e.minHeight}px`:"unset",maxHeight:e.maxHeight?`${e.maxHeight}px`:"unset",minWidth:e.minWidth?`${e.minWidth}px`:"unset",maxWidth:e.maxWidth?`${e.maxWidth}px`:"unset"}),...e}),this._onCloseBtnClick=()=>{this.close()},this._onMouseDownAll=()=>{this.bringToFront()},this._onMouseDown=e=>{e.preventDefault(),this._startDragging(),this._startPosX=e.clientX,this._startPosY=e.clientY,document.addEventListener("mousemove",this._onMouseMove),document.addEventListener("mouseup",this._onMouseUp)},this._onMouseMove=e=>{e.preventDefault();let t=this._startPosX-e.clientX,i=this._startPosY-e.clientY;this._startPosX=e.clientX,this._startPosY=e.clientY,this.setPosition(this.el.offsetLeft-t,this.el.offsetTop-i)},this._onMouseUp=()=>{this._clearDragging(),document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove)},this.events=this.events.registerNames(Ft),this._startPosX=0,this._startPosY=0,this.$header=null,this.$title=null,this.$container=null,this.$buttons=null,this._closeBtn=new Rt({icon:Dt,classList:["og-button-size__20"]}),this.useHide=e.useHide||!1,this._visibility=ce(e.visible,!0)}setContainer(e){this.$container.innerHTML=e}get container(){return this.$container}get width(){return this.el?parseFloat(this.el.style.width):0}get height(){return this.el?parseFloat(this.el.style.height):0}bringToFront(){this.el.style.zIndex=String(Nt.__zIndex__++)}render(e){return super.render(e),this.bringToFront(),this.$header=this.select(".og-ddialog-header"),this.$title=this.select(".og-ddialog-header__title"),this.$container=this.select(".og-ddialog-container"),this.$buttons=this.select(".og-ddialog-header__buttons"),this._initEvents(),this._initButtons(),this}show(){this._visibility||(this._visibility=!0,this.el.style.display="flex",this.bringToFront(),this.events.dispatch(this.events.visibility,!0,this))}hide(){this._visibility&&(this._visibility=!1,this.el.style.display="none",this.events.dispatch(this.events.visibility,!1,this))}close(){this.useHide?this.hide():this.remove()}setVisibility(e){e?this.show():this.hide()}_initButtons(){this._closeBtn.events.on("click",this._onCloseBtnClick),this._closeBtn.appendTo(this.$buttons)}_initEvents(){this.$header.addEventListener("mousedown",this._onMouseDown),this.el.addEventListener("mousedown",this._onMouseDownAll)}setPosition(e,t){null!=e&&(this.el.style.left=`${e}px`),null!=t&&(this.el.style.top=`${t}px`)}_startDragging(){this.el.classList.contains("dragging")||(this.el.classList.add("dragging"),this.events.dispatch(this.events.dragstart,this))}_clearDragging(){this.el.classList.contains("dragging")&&(this.events.dispatch(this.events.dragend,this),this.el.classList.remove("dragging"))}remove(){this._clearDragging(),this._clearEvents(),super.remove()}_clearEvents(){this._closeBtn.events.off("click",this._onCloseBtnClick),document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove),this.$header.removeEventListener("mousedown",this._onMouseDown),this.el.removeEventListener("mousedown",this._onMouseDownAll)}}Nt.__zIndex__=0;const Ht=["change"];class Ot extends Rt{constructor(e){super({...e}),this._onMouseClick=e=>{this.preventClick||(this._mouseClickHandler(e),this.setActive(!this.isActive))},this.events=this.events.registerNames(Ht),this._isActive=e.isActive||!1,this.preventClick=e.preventClick||!1}setActive(e,t=!1){e!==this._isActive&&(this._isActive=e,this._toggle(),t||this.events.dispatch(this.events.change,e,this))}_toggle(){this.el&&this.el.classList.toggle("og-button__active")}get isActive(){return this._isActive}render(e){return super.render(e),this._isActive&&this._toggle(),this}}const Vt=[2,3,0,1],Ut=[[-1,-1,0,1],[1,-1,3,-1],[2,3,-1,-1],[-1,0,-1,2]],Gt=[[2,3,0,1],[1,0,3,2],[2,3,0,1],[1,0,3,2]],Wt=[[0,1,0,0],[1,0,0,0],[0,1,0,1],[1,1,1,1]];class jt{constructor(e,t){this.segment=e,this.layer=t,this.isReady=!1,this.isLoading=!1,this.texture=null,this.pickingMask=null,this.textureExists=!1,this.appliedNodeId=0,this.appliedNode=null,this.texOffset=[0,0,1,1],this.loadingAttempts=0,this._updateTexture=null,this._updatePickingMask=null,this.pickingReady=!1}abortLoading(){this.layer.abortMaterialLoading(this)}_createTexture(e){return this.layer._planet&&this.layer.createTexture(e,this.layer._internalFormat,this.isReady?this.texture:null)}applyImage(e){this.segment.initialized&&(this._updateTexture=null,this.texture=this._createTexture(e),this.isReady=!0,this.pickingReady=!0,this.textureExists=!0,this.isLoading=!1,this.appliedNodeId=this.segment.node.nodeId,this.texOffset=[0,0,1,1])}applyTexture(e,t){this.segment.initialized&&(this.texture=e,this._updateTexture=null,this.pickingMask=t||null,this._updatePickingMask=null,this.isReady=!0,this.pickingReady=!0,this.textureExists=!0,this.isLoading=!1,this.appliedNodeId=this.segment.node.nodeId,this.texOffset=[0,0,1,1])}textureNotExists(){this.segment.initialized&&(this.pickingReady=!0,this.isLoading=!1,this.isReady=!0,this.textureExists=!1)}clear(){this.loadingAttempts=0,this.layer.clearMaterial(this)}}const Yt=15.8;class qt{constructor(e,t={}){if(this.isVector=!1,this.__id=qt.__counter__++,this._iconSrc=t.iconSrc||null,this.events=Pt(Xt,this),this.name=e||"noname",this.properties=t.properties||{},this.hideInLayerSwitcher=t.hideInLayerSwitcher||!1,this._hasImageryTiles=!0,this._opacity=null!=t.opacity?t.opacity:1,this.minZoom=t.minZoom||0,this.maxZoom=null!=t.maxZoom?t.maxZoom:50,this._planet=null,this.isVector=!1,this._attribution=t.attribution||"",this._zIndex=t.zIndex||0,this._isBaseLayer=t.isBaseLayer||!1,this._defaultTextures=t.defaultTextures||[null,null],this._visibility=void 0===t.visibility||t.visibility,this._fading=t.fading||!1,this._fadingFactor=this._opacity/Yt,this._fading?this._fadingOpacity=this._visibility?this._opacity:0:this._fadingOpacity=this._opacity,this._height=t.height||0,this._extent=new ie,this.createTexture=null,this._textureFilter=t.textureFilter?t.textureFilter.trim().toUpperCase():"MIPMAP",this._isSRGB=null!=t.isSRGB&&t.isSRGB,this._internalFormat=null,this._extentMerc=new ie,this.setExtent(Se(t.extent,new ie(new z(-180,-90),new z(180,90)))),this._pickingColor=new oe,this._pickingEnabled=void 0===t.pickingEnabled||t.pickingEnabled,this._isPreloadDone=!1,this._preLoadZoomLevels=t.preLoadZoomLevels||[0,1],this._ambient=null,this._diffuse=null,this._specular=null,t.ambient){let e=Pe(t.ambient,new oe(.2,.2,.2));this._ambient=new Float32Array([e.x,e.y,e.z])}if(t.diffuse){let e=Pe(t.diffuse,new oe(.8,.8,.8));this._diffuse=new Float32Array([e.x,e.y,e.z])}if(t.specular){let e=Pe(t.specular,new oe(3e-4,3e-4,3e-4)),i=t.shininess||20;this._specular=new Float32Array([e.x,e.y,e.z,i])}this.nightTextureCoefficient=t.nightTextureCoefficient||1}get iconSrc(){return this._iconSrc}set iconSrc(e){this._iconSrc=e}set diffuse(e){if(e){let t=Pe(e);this._diffuse=new Float32Array(t.toArray())}else this._diffuse=null}set ambient(e){if(e){let t=Pe(e);this._ambient=new Float32Array(t.toArray())}else this._ambient=null}set specular(e){if(e){let t=Pe(e);this._specular=new Float32Array([t.x,t.y,t.y,this._specular?this._specular[3]:0])}else this._specular=null}set shininess(e){this._specular&&(this._specular[3]=e)}static getTMS(e,t,i){return{x:e,y:(1<<i)-t-1,z:i}}static getTileIndex(e,t,i,n){return`${n}::${e}_${t}_${i}`}get instanceName(){return"Layer"}get rendererEvents(){return this.events}set opacity(e){e!==this._opacity&&(this._fading?(e>this._opacity||e<this._opacity)&&(this._fadingFactor=(e-this._opacity)/Yt):this._fadingOpacity=e,this._opacity=e)}set pickingEnabled(e){this._pickingEnabled=e}get pickingEnabled(){return this._pickingEnabled}hasImageryTiles(){return this._hasImageryTiles}getID(){return this.__id}get id(){return this.__id}get _id(){return this.__id}isEqual(e){return e.__id===this.__id}_assignPlanet(e){this._planet=e,e._layers.push(this),e.renderer&&e.renderer.isInitialized()&&(this._isSRGB?this._internalFormat=e.renderer.handler.gl.SRGB8_ALPHA8:this._internalFormat=e.renderer.handler.gl.RGBA8,this.createTexture=e.renderer.handler.createTexture[this._textureFilter],this.events.on("visibilitychange",e._onLayerVisibilityChanged,e),this._isBaseLayer&&this._visibility&&e.setBaseLayer(this),e.events.dispatch(e.events.layeradd,this),this.events.dispatch(this.events.add,e),e.updateVisibleLayers(),this._bindPicking(),this._visibility&&this.hasImageryTiles()&&this._preLoad())}get isIdle(){return this._planet&&this._planet._terrainCompletedActivated||!1}_bindPicking(){this._planet&&this._planet.renderer&&this._planet.renderer.assignPickingColor(this)}addTo(e){this._planet||this._assignPlanet(e)}remove(){let e=this._planet;if(e)for(let t=0;t<e._layers.length;t++)if(this.isEqual(e._layers[t]))return e.renderer&&e.renderer.clearPickingColor(this),e._layers.splice(t,1),e.updateVisibleLayers(),this.clear(),e.events.dispatch(e.events.layerremove,this),this.events.dispatch(this.events.remove,e),this._planet=null,this._internalFormat=null,this.createTexture=null,this;return this}clear(){this._planet&&this._planet._clearLayerMaterial(this)}get planet(){return this._planet}setAttribution(e){this._attribution!==e&&(this._attribution=e,this._planet&&this._planet.updateAttributionsList())}getAttribution(){return this._attribution}setHeight(e){this._height=e,this._planet&&this._planet.updateVisibleLayers()}getHeight(){return this._height}setZIndex(e){this._zIndex=e,this._planet&&this._planet.updateVisibleLayers()}getZIndex(){return this._zIndex}bringToFront(){if(this._planet){let e=this._planet.visibleTileLayers,t=e[e.length-1];t.isEqual(this)||this.setZIndex(t.getZIndex()+1)}}isBaseLayer(){return this._isBaseLayer}setBaseLayer(e){this._isBaseLayer=e,this._planet&&(!e&&this._planet.baseLayer&&this.isEqual(this._planet.baseLayer)&&(this._planet.baseLayer=null),this._planet.updateVisibleLayers())}setVisibility(e){e!==this._visibility&&(this._visibility=e,this._planet&&(this._isBaseLayer&&e&&this._planet.setBaseLayer(this),this._planet.updateVisibleLayers(),!e||this._isPreloadDone||this.isVector||(this._isPreloadDone=!0,this._preLoad())),this.events.dispatch(this.events.visibilitychange,this))}_forceMaterialApply(e){let t=e.materials,i=t[this.__id];i||(i=t[this.__id]=this.createMaterial(e)),i.isReady||(this._planet._renderCompleted=!1),this.applyMaterial(i,!0)}clearMaterial(e){}loadMaterial(e,t=!1){}applyMaterial(e,t=!1){return[0,0,1,1]}_preLoadRecursive(e,t){if(!(e.segment.tileZoom>t)){this._preLoadZoomLevels.includes(e.segment.tileZoom)&&this._forceMaterialApply(e.segment);for(let i=0,n=e.nodes.length;i<n;i++)e.nodes[i]&&this._preLoadRecursive(e.nodes[i],t)}}_preLoad(){if(this._planet&&this._preLoadZoomLevels.length){let e=this._planet,t=Math.max(...this._preLoadZoomLevels);for(let i=0,n=e.quadTreeStrategy.quadTreeList.length;i<n;i++)this._preLoadRecursive(e.quadTreeStrategy.quadTreeList[i],t)}}getVisibility(){return this._visibility}setExtent(e){let t=e.southWest.clone(),i=e.northEast.clone();t.lat<ee&&(t.lat=ee),i.lat>J&&(i.lat=J),this._extent=e.clone(),this._extentMerc=new ie(t.forwardMercator(),i.forwardMercator()),this._correctFullExtent()}getExtent(){return this._extent}getExtentMerc(){return this._extentMerc}flyExtent(){this._planet?.flyExtent(this.getExtent())}viewExtent(){this._planet?.viewExtent(this.getExtent())}_correctFullExtent(){}get opacity(){return this._opacity}get screenOpacity(){return this._fading?this._fadingOpacity:this._opacity}_refreshFadingOpacity(){let e=this._planet;return this._visibility&&e.getViewExtent().overlaps(this._extent)&&e.maxCurrZoom>=this.minZoom&&e.minCurrZoom<=this.maxZoom?(this._fadingOpacity+=this._fadingFactor,(this._fadingFactor>0&&this._fadingOpacity>this._opacity||this._fadingFactor<0&&this._fadingOpacity<this._opacity)&&(this._fadingOpacity=this._opacity),!1):(this._fadingOpacity=0,!this._visibility)}createMaterial(e){return new jt(e,this)}redraw(){this._planet&&this._planet.quadTreeStrategy.clearLayerMaterial(this)}abortMaterialLoading(e){}abortLoading(){}}qt.__counter__=0;const Xt=["visibilitychange","add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"],$t=["load","loadend"];class Zt extends qt{constructor(e,t){super(e,t),this.events=this.events.registerNames($t),this.animated=t.animated||!1,this.minNativeZoom=t.minNativeZoom||0,this.maxNativeZoom=t.maxNativeZoom||100,this._counter=0,this._pendingsQueue=[],this.drawTile=t.drawTile,this._onLoadend_=null}addTo(e){return this._onLoadend_=this._onLoadend.bind(this),this.events.on("loadend",this._onLoadend_,this),super.addTo(e)}remove(){return this.events.off("loadend",this._onLoadend_),this._onLoadend_=null,super.remove()}_onLoadend(){this._planet&&this._planet._terrainCompletedActivated&&this._planet.events.dispatch(this._planet.events.layerloadend,this)}get instanceName(){return"CanvasTiles"}get isIdle(){return super.isIdle&&0===this._counter}abortLoading(){this._pendingsQueue.forEach((e=>{this.abortMaterialLoading(e)})),this._pendingsQueue=[]}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),e||this.abortLoading())}loadMaterial(e){let t=e.segment;this._isBaseLayer?e.texture=t._isNorth?t.planet.solidTextureOne:t.planet.solidTextureTwo:e.texture=t.planet.transparentTexture,(this._planet.layerLock.isFree()||e.segment.tileZoom<2)&&(e.isReady=!1,e.isLoading=!0,Zt.__requestsCounter>=Zt.MAX_REQUESTS&&this._counter?this._pendingsQueue.push(e):this._exec(e))}_exec(e){Zt.__requestsCounter++,this._counter++;const t=this.events.load;t.handlers.length&&this.events.dispatch(t,e),requestAnimationFrame((()=>{this.drawTile(e,(t=>{this._counter--,Zt.__requestsCounter--,this._correctCounter(),e.isLoading&&e.applyImage(t),this._dequeueRequest()}))}))}_correctCounter(){this._counter<0&&(this._counter=0),Zt.__requestsCounter<0&&(Zt.__requestsCounter=0)}abortMaterialLoading(e){e.isLoading&&(this._counter--,Zt.__requestsCounter--,this._correctCounter(),this._dequeueRequest()),e.isLoading=!1,e.isReady=!1}_dequeueRequest(){if(this._pendingsQueue.length){if(Zt.__requestsCounter<Zt.MAX_REQUESTS){const e=this._whilePendings();e&&this._exec(e)}}else 0===this._counter&&this._planet&&this._planet._terrainCompletedActivated&&this.events.dispatch(this.events.loadend)}_whilePendings(){for(;this._pendingsQueue.length;){const e=this._pendingsQueue.pop();if(e&&e.segment&&e.segment.node){if(e.segment.initialized&&1===e.segment.node.getState())return e;e.isLoading=!1}}return null}applyMaterial(e){if(e.isReady)return e.layer.animated&&requestAnimationFrame((()=>{this.drawTile(e,(function(t){e.applyImage(t)}))})),e.texOffset;if(e.segment.tileZoom<this.minNativeZoom)e.textureNotExists();else{let t=e.segment,i=t.node,n=!1,r=e.layer.maxNativeZoom;t.passReady&&!e.isLoading&&t.tileZoom<=r&&this.loadMaterial(e);let s=this._id,a=e;for(;i.parentNode;)if(i=i.parentNode,a=i.segment.materials[s],a&&a.textureExists){n=!0;break}if(t.passReady)if(i.segment.tileZoom===r)t.tileZoom>r&&e.textureNotExists();else if(i.segment.tileZoom<r){let i=t.node;for(;i.segment.tileZoom>r;)i=i.parentNode;let n=i.segment.materials[s];n?!n.isLoading&&!n.isReady&&this.loadMaterial(n):(n=i.segment.materials[e.layer._id]=e.layer.createMaterial(i.segment),this.loadMaterial(n))}if(n){e.layer.animated&&requestAnimationFrame((()=>{this.drawTile(e,(function(t){e.applyImage(t)}))})),e.appliedNodeId=i.nodeId,e.texture=a.texture;let n=1/(2<<t.tileZoom-i.segment.tileZoom-1);e.texOffset[0]=t.tileX*n-i.segment.tileX,e.texOffset[1]=t.tileY*n-i.segment.tileY,e.texOffset[2]=n,e.texOffset[3]=n}else e.texture=t.planet.transparentTexture,e.texOffset[0]=0,e.texOffset[1]=0,e.texOffset[2]=1,e.texOffset[3]=1}return e.texOffset}clearMaterial(e){e.isReady&&(e.isReady=!1,e.textureExists&&e.texture&&!e.texture.default&&(e.segment.handler.gl.deleteTexture(e.texture),e.texture=null)),this.abortMaterialLoading(e),e.isLoading=!1,e.textureExists=!1,e.layer=null,e.segment=null}}Zt.MAX_REQUESTS=20,Zt.__requestsCounter=0;const Kt=["change"];class Qt{constructor(e={}){this._onChange=(e,t)=>{if(e){t.preventClick=!0;for(let e=0;e<this._buttons.length;e++){let i=this._buttons[e];i.isEqual(t)||(i.setActive(!1),i.preventClick=!1)}this.events.dispatch(this.events.change,t)}},this.events=Pt(Kt),this._buttons=e.buttons||[];for(let e=0;e<this._buttons.length;e++)this._bindButton(this._buttons[e])}_bindButton(e){e.events.on("change",this._onChange)}add(e){this._buttons.push(e),this._bindButton(e)}remove(e){for(let t=0;t<this._buttons.length;t++)if(this._buttons[t].isEqual(e))return this._buttons.splice(t),void e.events.off("change",this._onChange)}}class Jt{constructor(e=2,t){this._sourceId=0,this._source=new Map,this._pendingQueue=[],this._numWorkers=e,this._workerQueue=[],t&&this.setProgram(t)}check(){this._pendingQueue.length&&this.make(this._pendingQueue.pop())}setProgram(e){let t=new Blob([e],{type:"application/javascript"});for(let e=0;e<this._numWorkers;e++){let e=new Worker(URL.createObjectURL(t));e.onmessage=e=>{this._onMessage(e),this._workerQueue&&this._workerQueue.unshift(e.target),this.check()},this._workerQueue.push(e)}}make(e){}_onMessage(e){}destroy(){for(let e=0;e<this._workerQueue.length;e++){const t=this._workerQueue[e];t.onmessage=null,t.terminate()}this._pendingQueue=null,this._workerQueue=null}get pendingQueue(){return this._pendingQueue}}const ei=-2,ti=-1;class ii extends Jt{constructor(e=4){super(e,ni)}_onMessage(e){let t=this._source.get(e.data.id);t.label._lockId===ei?requestAnimationFrame((()=>{this.make({handler:t.handler,label:t.label})})):t.handler.workerCallback(e.data,t.label),this._source.delete(e.data.id)}make(e){let t=e.label;if(e.handler._entityCollection){let i=t.serializeWorkerData(this._sourceId);if(i)if(this._workerQueue.length){let n=this._workerQueue.pop();this._source.set(this._sourceId,e),t._lockId=this._sourceId,this._sourceId++,n.postMessage({labelData:i},[i.buffer])}else this._pendingQueue.push(e)}}}const ni="'use strict';\n\n function concatTypedArrays(dest, index, source) {\n let len = source.length,\n offset = index * len;\n for(let i = 0; i < len; i++) {\n dest[offset + i] = source[i];\n }\n }\n\n self.onmessage = function (e) {\n var labelData = e.data.labelData,\n id = labelData[0],\n maxLetters = labelData[1],\n isVisible = labelData[2],\n /*3, 4, 5*/_positionHigh_x = labelData[3], _positionHigh_y = labelData[4], _positionHigh_z = labelData[5],\n /*6, 7, 8*/_positionLow_x = labelData[6], _positionLow_y = labelData[7], _positionLow_z = labelData[8],\n /*9*/_size = labelData[9],\n /*10, 11, 12*/_offset_x = labelData[10], _offset_y = labelData[11], _offset_z = labelData[12],\n /*13, 14, 15, 16*/_color_x = labelData[13], _color_y = labelData[14], _color_z = labelData[15], _color_w = labelData[16],\n /*17*/_rotation = labelData[17],\n /*18, 19, 20*/_alignedAxis_x = labelData[18], _alignedAxis_y = labelData[19], _alignedAxis_z = labelData[20],\n /*21*/_fontIndex = labelData[21],\n /*22*/_outline = labelData[22],\n /*23, 24, 25, 26*/_outlineColor_x = labelData[23], _outlineColor_y = labelData[24], _outlineColor_z = labelData[25], _outlineColor_w = labelData[26],\n /*27, 28, 29*/_pickingColor_x = labelData[27], _pickingColor_y = labelData[28], _pickingColor_z = labelData[29]\n \n\n let _vertexArr = new Float32Array(maxLetters * 12),\n _texCoordArr = new Float32Array(maxLetters * 24),\n _gliphParamArr = new Float32Array(maxLetters * 24),\n _positionHighArr = new Float32Array(maxLetters * 18),\n _positionLowArr = new Float32Array(maxLetters * 18),\n _sizeArr = new Float32Array(maxLetters * 6),\n _offsetArr = new Float32Array(maxLetters * 18),\n _rgbaArr = new Float32Array(maxLetters * 24),\n _rotationArr = new Float32Array(maxLetters * 6),\n _alignedAxisArr = new Float32Array(maxLetters * 18),\n _fontIndexArr = new Float32Array(maxLetters * 6),\n _outlineArr = new Float32Array(maxLetters * 6),\n _outlineColorArr = new Float32Array(maxLetters * 24),\n _pickingColorArr = new Float32Array(maxLetters * 18);\n \n for (let i = 0; i < maxLetters; i++) {\n if (isVisible !== 0) {\n concatTypedArrays(_vertexArr, i, [0, 0, 0, -1, 1, -1, 1, -1, 1, 0, 0, 0]);\n } else {\n concatTypedArrays(_vertexArr, i, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);\n }\n\n concatTypedArrays(_texCoordArr, i, [0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0]);\n concatTypedArrays(_gliphParamArr, i, [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]);\n\n var x = _positionHigh_x, y = _positionHigh_y, z = _positionHigh_z, w;\n concatTypedArrays(_positionHighArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _positionLow_x; y = _positionLow_y; z = _positionLow_z;\n concatTypedArrays(_positionLowArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _size;\n concatTypedArrays(_sizeArr, i, [x, x, x, x, x, x]);\n\n x = _offset_x; y = _offset_y; z = _offset_z;\n concatTypedArrays(_offsetArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _color_x; y = _color_y; z = _color_z; w = _color_w;\n concatTypedArrays(_rgbaArr, i, [x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w]);\n\n x = _rotation;\n concatTypedArrays(_rotationArr, i, [x, x, x, x, x, x]);\n\n x = _alignedAxis_x; y = _alignedAxis_y; z = _alignedAxis_z;\n concatTypedArrays(_alignedAxisArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _fontIndex;\n concatTypedArrays(_fontIndexArr, i, [x, x, x, x, x, x]);\n\n x = _outline;\n concatTypedArrays(_outlineArr, i, [x, x, x, x, x, x]);\n\n x = _outlineColor_x; y = _outlineColor_y; z = _outlineColor_z; w = _outlineColor_w;\n concatTypedArrays(_outlineColorArr, i, [x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w]);\n\n x = _pickingColor_x / 255; y = _pickingColor_y / 255; z = _pickingColor_z / 255;\n concatTypedArrays(_pickingColorArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n }\n\n self.postMessage({\n id: id,\n vertexArr: _vertexArr,\n texCoordArr: _texCoordArr,\n gliphParamArr: _gliphParamArr,\n positionHighArr: _positionHighArr,\n positionLowArr: _positionLowArr,\n sizeArr: _sizeArr,\n offsetArr: _offsetArr,\n rgbaArr: _rgbaArr,\n rotationArr: _rotationArr,\n alignedAxisArr: _alignedAxisArr,\n fontIndexArr: _fontIndexArr,\n outlineArr: _outlineArr,\n outlineColorArr: _outlineColorArr,\n pickingColorArr: _pickingColorArr\n }, [\n _vertexArr.buffer,\n _texCoordArr.buffer,\n _gliphParamArr.buffer,\n _positionHighArr.buffer,\n _positionLowArr.buffer,\n _sizeArr.buffer,\n _offsetArr.buffer,\n _rgbaArr.buffer,\n _rotationArr.buffer,\n _alignedAxisArr.buffer,\n _fontIndexArr.buffer,\n _outlineArr.buffer,\n _outlineColorArr.buffer,\n _pickingColorArr.buffer\n ]);\n }";class ri{constructor(e={}){this.__id=ri.__counter__++,this._position=Ae(e.position),this._positionHigh=new oe,this._positionLow=new oe,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._rotation=e.rotation||0,this._color=Ee(e.color),this._alignedAxis=Ae(e.alignedAxis),this._offset=Ae(e.offset),this._visibility=null==e.visibility||e.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1,this._isReady=!1,this._lockId=ti}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):this._lockId!==ti&&(this._lockId=ei)}setPosition3v(e){this._position.x=e.x,this._position.y=e.y,this._position.z=e.z,oe.doubleToTwoFloats(e,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):this._lockId!==ti&&(this._lockId=ei)}getPosition(){return this._position}setOffset(e,t,i){this._offset.x=e,this._offset.y=t,null!=i&&(this._offset.z=i),this._isReady&&this._handler?this._handler.setOffsetArr(this._handlerIndex,this._offset):this._lockId!==ti&&(this._lockId=ei)}setOffset3v(e){this.setOffset(e.x,e.y,e.z)}getOffset(){return this._offset}setRotation(e){e!==this._rotation&&(this._rotation=e,this._isReady&&this._handler?this._handler.setRotationArr(this._handlerIndex,e):this._lockId!==ti&&(this._lockId=ei))}getRotation(){return this._rotation}setOpacity(e){e!==this._color.w&&(null!=e&&(this._color.w=e),this._isReady&&this._handler?this._handler.setRgbaArr(this._handlerIndex,this._color):this._lockId!==ti&&(this._lockId=ei))}setColor(e,t,i,n){n===this._color.w&&e===this._color.x&&t===this._color.y&&this._color.z===i||(this._color.x=e,this._color.y=t,this._color.z=i,null!=n&&(this._color.w=n),this._isReady&&this._handler?this._handler.setRgbaArr(this._handlerIndex,this._color):this._lockId!==ti&&(this._lockId=ei))}setColor4v(e){this.setColor(e.x,e.y,e.z,e.w)}setColorHTML(e){this.setColor4v(ve(e))}getColor(){return this._color}setVisibility(e){e!==this._visibility&&(this._visibility=e,this._isReady&&this._handler?this._handler.setVisibility(this._handlerIndex,e):this._lockId!==ti&&(this._lockId=ei))}getVisibility(){return this._visibility}setAlignedAxis(e,t,i){this._alignedAxis.x=e,this._alignedAxis.y=t,this._alignedAxis.z=i,this._isReady&&this._handler?this._handler.setAlignedAxisArr(this._handlerIndex,this._alignedAxis):this._lockId!==ti&&(this._lockId=ei)}setAlignedAxis3v(e){this.setAlignedAxis(e.x,e.y,e.z)}getAlignedAxis(){return this._alignedAxis}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._isReady&&this._handler?this._handler.setPickingColorArr(this._handlerIndex,e):this._lockId!==ti&&(this._lockId=ei)}serializeWorkerData(e){return this._handler?new Float32Array([]):null}}ri.__counter__=0;class si extends ri{constructor(e={}){super(e),this._handler=null,this._src=e.src||null,this._image=e.image||null,this._scale=1,this._width=e.width||(e.size?e.size[0]:30),this._height=e.height||(e.size?e.size[1]:30)}setSrc(e){this._src=e;let t=this._handler;if(t&&e&&e.length){let i=t._entityCollection.renderNode;if(i&&i.renderer){let n=i.renderer.billboardsTextureAtlas,r=this;n.loadImage(e,(function(e){null!=e.__nodeIndex&&n.get(e.__nodeIndex)?(r._image=e,t.setTexCoordArr(r._handlerIndex,n.get(r._image.__nodeIndex).texCoords)):(n.addImage(e),n.createTexture(),r._image=e,i.updateBillboardsTexCoords())}))}}}getSrc(){return this._src}setImage(e){this.setSrc(e.src)}getImage(){return this._image}setSize(e,t){this._width=e,this._height=t,this._handler&&this._handler.setSizeArr(this._handlerIndex,e*this._scale,t*this._scale)}getSize(){return{width:this._width,height:this._height}}setWidth(e){this.setSize(e,this._height)}getWidth(){return this._width}setHeight(e){this.setSize(this._width,e)}getHeight(){return this._height}}var ai;!function(e){e[e.POINT=1]="POINT",e[e.LINESTRING=2]="LINESTRING",e[e.POLYGON=3]="POLYGON",e[e.MULTIPOLYGON=4]="MULTIPOLYGON",e[e.MULTILINESTRING=5]="MULTILINESTRING"}(ai||(ai={}));const oi={POINT:1,LINESTRING:2,POLYGON:3,MULTIPOLYGON:4,MULTILINESTRING:5};class li{constructor(e={}){this.__id=li.__counter__++,this._entity=null,this._handler=null,this._handlerIndex=-1,this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyVerticesLength=-1,this._polyIndexesLength=-1,this._polyVerticesHandlerIndex=-1,this._polyIndexesHandlerIndex=-1,this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineVerticesLength=-1,this._lineOrdersLength=-1,this._lineIndexesLength=-1,this._lineColorsLength=-1,this._lineThicknessLength=-1,this._lineVerticesHandlerIndex=-1,this._lineOrdersHandlerIndex=-1,this._lineIndexesHandlerIndex=-1,this._lineThicknessHandlerIndex=-1,this._lineColorsHandlerIndex=-1,this._type=e.type&&li.getType(e.type)||ai.POINT,this._coordinates=e.coordinates||[],this._extent=li.getExtent({type:e.type||"POINT",coordinates:e.coordinates||[]},this._coordinates),e.style=e.style||{},this._style={fillColor:Ee(e.style.fillColor,new re(.19,.62,.85,.4)),lineColor:Ee(e.style.lineColor,new re(.19,.62,.85,1)),strokeColor:Ee(e.style.strokeColor,new re(1,1,1,.95)),lineWidth:e.style.lineWidth||3,strokeWidth:e.style.strokeWidth||0},this._visibility=e.visibility||!0,this._pickingReady=!1}get id(){return this.__id}get type(){return this._type}static getType(e){return oi[e.toUpperCase()]}static getExtent(e,t){let i=new ie(new z(180,90),new z(-180,-90)),n=li.getType(e.type);if(n===ai.POINT){let n=e.coordinates[0],r=e.coordinates[1];i.southWest.lon=n,i.southWest.lat=r,i.northEast.lon=n,i.northEast.lat=r,t&&(t[0]=n)&&(t[1]=r)}else if(n===ai.LINESTRING){let n=e.coordinates;for(let e=0;e<n.length;e++){let r=n[e][0],s=n[e][1];r<i.southWest.lon&&(i.southWest.lon=r),s<i.southWest.lat&&(i.southWest.lat=s),r>i.northEast.lon&&(i.northEast.lon=r),s>i.northEast.lat&&(i.northEast.lat=s),t&&(t[e]=[r,s])}}else if(n===ai.POLYGON){let n=e.coordinates;for(let e=0;e<n.length;e++){let r=n[e];t&&(t[e]=[]);for(let n=0;n<r.length;n++){let s=r[n],a=s[0],o=s[1];a<i.southWest.lon&&(i.southWest.lon=a),o<i.southWest.lat&&(i.southWest.lat=o),a>i.northEast.lon&&(i.northEast.lon=a),o>i.northEast.lat&&(i.northEast.lat=o),t&&(t[e][n]=[a,o])}}}else if(n===ai.MULTIPOLYGON){let n=e.coordinates;for(let e=0;e<n.length;e++){let r=n[e];t&&(t[e]=[]);for(let n=0;n<r.length;n++){let s=r[n];t&&(t[e][n]=[]);for(let r=0;r<s.length;r++){let a=s[r],o=a[0],l=a[1];o<i.southWest.lon&&(i.southWest.lon=o),l<i.southWest.lat&&(i.southWest.lat=l),o>i.northEast.lon&&(i.northEast.lon=o),l>i.northEast.lat&&(i.northEast.lat=l),t&&(t[e][n][r]=[o,l])}}}}else if(n===ai.MULTILINESTRING){let n=e.coordinates;for(let e=0;e<n.length;e++){let r=n[e];t&&(t[e]=[]);for(let n=0;n<r.length;n++){let s=r[n],a=s[0],o=s[1];a<i.southWest.lon&&(i.southWest.lon=a),o<i.southWest.lat&&(i.southWest.lat=o),a>i.northEast.lon&&(i.northEast.lon=a),o>i.northEast.lat&&(i.northEast.lat=o),t&&(t[e][n]=[a,o])}}}else i.southWest.lon=i.southWest.lat=i.northEast.lon=i.northEast.lat=0,t&&(t[0]=0)&&(t[1]=0);return i}setGeometry(e){let t=this._handler;return t&&(this.remove(),this._type=li.getType(e.type||"Point"),this._extent=li.getExtent(e,this._coordinates),t.add(this)),this}setFillColor(e,t,i,n=1){let r=this._style.fillColor;return(0===r.w&&0!==n||0!==r.w&&0===n)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=n,this._handler&&this._handler.setPolyColorArr(this,r),this}overlaps(e){return this._extent.overlaps(e)}setFillColor4v(e){return this.setFillColor(e.x,e.y,e.z,e.w)}setStrokeColor(e,t,i,n=1){let r=this._style.strokeColor;return(0===r.w&&0!==n||0!==r.w&&0===n)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=n,this._handler&&this._handler.setLineStrokeColorArr(this,r),this}setLineColor(e,t,i,n=1){let r=this._style.lineColor;return(0===r.w&&0!==n||0!==r.w&&0===n)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=n,this._handler&&this._handler.setLineColorArr(this,r),this}setStrokeColor4v(e){return this.setStrokeColor(e.x,e.y,e.z,e.w)}setLineColor4v(e){return this.setLineColor(e.x,e.y,e.z,e.w)}setStrokeOpacity(e){let t=this._style.strokeColor;return t.w=e,this.setStrokeColor(t.x,t.y,t.z,e)}setLineOpacity(e){let t=this._style.lineColor;return t.w=e,this.setLineColor(t.x,t.y,t.z,e)}setStrokeWidth(e){return this._style.strokeWidth=e,this._pickingReady=!1,this._handler&&this._handler.setLineStrokeArr(this,e),this}bringToFront(){return this._handler&&this._handler.bringToFront(this),this}setLineWidth(e){return this._style.lineWidth=e,this._pickingReady=!1,this._handler&&this._handler.setLineThicknessArr(this,e),this}setFillOpacity(e){let t=this._style.fillColor;return(0===t.w&&0!==e||0!==t.w&&0===e)&&(this._pickingReady=!1),t.w=e,this._handler&&this._handler.setPolyColorArr(this,t),this}setVisibility(e){return this._visibility=e,this._handler&&this._handler.setGeometryVisibility(this),this}getVisibility(){return this._visibility}remove(){this._handler&&this._handler.remove(this)}getExtent(){return this._extent.clone()}getType(){return this._type}}li.__counter__=0;class hi{constructor(e=0,t=0,i=0){this.a=e,this.b=t,this.c=i}static get(e,t){return new hi(t.y-e.y,e.x-t.x,t.x*e.y-e.x*t.y)}static getParallel(e,t){return new hi(e.a,e.b,-e.a*t.x-e.b*t.y)}static getIntersection(e,t){let i=(t.b*e.c-e.b*t.c)/(e.b*t.a-t.b*e.a);return new le(i,-(e.c+e.a*i)/e.b)}intersects(e){return hi.getIntersection(this,e)}}class ci{constructor(e,t){this.p0=e||new oe,this.p1=t||new oe}getMagnitude(){return this.p0.distance(this.p1)}getSphereIntersection(e){let t=this.p0,i=this.p1,n=e.center.x,r=e.center.y,s=e.center.z,a=t.x,o=t.y,l=t.z,h=i.x-a,c=i.y-o,d=i.z-l,_=h*h+c*c+d*d,u=2*(a*h+o*c+l*d-h*n-c*r-d*s),f=u*u-4*_*(a*a-2*a*n+n*n+o*o-2*o*r+r*r+l*l-2*l*s+s*s-e.radius*e.radius);if(f<0)return[];let g=(-u-Math.sqrt(f))/(2*_),p=new oe(t.x*(1-g)+g*i.x,t.y*(1-g)+g*i.y,t.z*(1-g)+g*i.z);if(0==f)return[p];let m=(-u+Math.sqrt(f))/(2*_),v=new oe(t.x*(1-m)+m*i.x,t.y*(1-m)+m*i.y,t.z*(1-m)+m*i.z);return Math.abs(g-.5)<Math.abs(m-.5)?[p,v]:[v,p]}intersects(e,t,i){let n=this.p0.sub(e.p0),r=e.p1.sub(e.p0);if(Math.abs(r.x)<u&&Math.abs(r.y)<u&&Math.abs(r.z)<u)return!1;let s=this.p1.sub(this.p0);if(Math.abs(s.x)<u&&Math.abs(s.y)<u&&Math.abs(s.z)<u)return!1;let a=n.x*r.x+n.y*r.y+n.z*r.z,o=r.x*s.x+r.y*s.y+r.z*s.z,l=n.x*s.x+n.y*s.y+n.z*s.z,h=r.x*r.x+r.y*r.y+r.z*r.z,c=(s.x*s.x+s.y*s.y+s.z*s.z)*h-o*o;if(Math.abs(c)<u)return!1;let d=(a*o-l*h)/c;if(t.x=this.p0.x+d*s.x,t.y=this.p0.y+d*s.y,t.z=this.p0.z+d*s.z,i){let t=(a+o*d)/h;i.x=e.p0.x+t*r.x,i.y=e.p0.y+t*r.y,i.z=e.p0.z+t*r.z}return!0}getNearestDistancePoint(e,t){let i=this.p0,n=this.p1,r=this.getMagnitude(),s=((e.x-i.x)*(n.x-i.x)+(e.y-i.y)*(n.y-i.y)+(e.z-i.z)*(n.z-i.z))/(r*r);return t.x=i.x+s*(n.x-i.x),t.y=i.y+s*(n.y-i.y),t.z=i.z+s*(n.z-i.z),!(s<0||s>1)}}class di{constructor(e,t){this.p=e?e.clone():new oe,this.n=t?t.clone():this.p.normal()}set(e,t){this.p.copy(e),this.n.copy(t)}getNormal(){return this.n.clone()}distance(e){let t=this.getProjection(e);return e.distance(t)}getProjection(e,t){return oe.proj_b_to_plane(e,this.n,t)}getProjectionPoint(e,t){let i=e.sub(this.p),n=this.n,r=i.dot(n);return t?t.copy(n.scale(r)):t=n.scale(r),e.sub(t)}getIntersection(e,t,i){let n,r=e.n.cross(t.n),s=r.x>=0?r.x:-r.x,a=r.y>=0?r.y:-r.y,o=r.z>=0?r.z:-r.z;if(s+a+o<_){let i=t.p.sub(e.p);return 0==e.n.dot(i)?1:0}n=s>a?s>o?1:3:a>o?2:3;let l,h,c=new oe;return l=-e.n.dot(e.p),h=-t.n.dot(t.p),1===n?(c.x=0,c.y=(h*e.n.z-l*t.n.z)/r.x,c.z=(l*t.n.y-h*e.n.y)/r.x):2===n?(c.x=(l*t.n.z-h*e.n.z)/r.y,c.y=0,c.z=(h*e.n.x-l*t.n.x)/r.y):3===n&&(c.x=(h*e.n.y-l*t.n.y)/r.z,c.y=(l*t.n.x-h*e.n.x)/r.z,c.z=0),i.p0.copy(c),i.p1.copy(c.add(r)),2}}let _i=class e{constructor(e=oe.ZERO,t=oe.ZERO){this.origin=e,this.direction=t}static get OUTSIDE(){return 0}static get INSIDE(){return 1}static get INPLANE(){return 2}static get AWAY(){return 3}set(e,t){return this.origin=e,this.direction=t,this}getPoint(e){return oe.add(this.origin,this.direction.scaleTo(e))}hitTriangle(t,i,n,r){let s=i.sub(t),a=n.sub(t),o=s.cross(a),l=this.origin.sub(t),h=-o.dot(l),c=o.dot(this.direction);if(Math.abs(c)<u)return 0===h?(r.copy(this.origin),e.INPLANE):e.OUTSIDE;let d=h/c;if(r.copy(this.origin.add(this.direction.scaleTo(d))),d<0)return e.AWAY;let _=s.dot(s),f=s.dot(a),g=a.dot(a),p=r.sub(t),m=p.dot(s),v=p.dot(a),y=f*f-_*g,x=(f*v-g*m)/y;if(x<0||x>1)return e.OUTSIDE;let b=(f*m-_*v)/y;return b<0||x+b>1?e.OUTSIDE:e.INSIDE}hitPlane(t,i,n,r){let s=oe.sub(i,t),a=oe.sub(n,t),o=s.cross(a),l=oe.sub(this.origin,t),h=-o.dot(l),c=o.dot(this.direction);if(Math.abs(c)<u&&0===h)return e.OUTSIDE;let d=h/c;if(d<0)return e.OUTSIDE;let _=this.direction.scaleTo(d);return r.x=this.origin.x+_.x,r.y=this.origin.y+_.y,r.z=this.origin.z+_.z,e.INSIDE}hitSphere(e){let t=e.radius,i=e.center,n=this.origin,r=this.direction,s=oe.sub(i,n);if(s.dot(r)<0){var a=s.length();if(a>t)return null;if(a===t)return n.clone();let e=i.projToRay(n,s);var o=oe.sub(e,i).length();let l=Math.sqrt(t*t-o*o)-oe.sub(e,n).length();return oe.add(n,r.scaleTo(l))}{let a=i.projToRay(n,r);var l=oe.sub(i,a).length();if(l>e.radius)return null;{let e,i=Math.sqrt(t*t-l*l);return a.subA(n),e=s.length()>t?a.length()-i:a.length()+i,oe.add(n,r.scaleTo(e))}}}hitBox(e){}};function ui(e){const t=[[0,0,0]],i=[[0,0]],n=[[0,0,0]],r=[t,i,n];let s=[[],[],[]];const a=[],o=[];let l,h=["default"],c="default",d="default";function _(){l&&l.data.vertices.length&&(l=null)}function u(e){e.split("/").forEach(((e,t)=>{if(!e)return;const i=parseInt(e),n=i+(i>=0?0:r[t].length);s[t].push(...r[t][n])}))}const f={v(e){t.push(e.map(parseFloat))},vn(e){n.push(e.map(parseFloat))},vt(e){i.push(e.map(parseFloat))},f(e){!function(){if(!l){const e=[],t=[],i=[];s=[e,t,i],l={object:d,groups:h,material:c,data:{vertices:e,textures:t,normals:i}},o.push(l)}}();const t=e.length-2;for(let i=0;i<t;++i)u(e[0]),u(e[i+1]),u(e[i+2])},s:()=>{},mtllib(e,t){a.push(t)},usemtl(e,t){c=t,_()},g(e){h=e,_()},o(e,t){d=t,_()}},g=/(\w*)(?: )*(.*)/,p=e.split("\n");for(let e=0;e<p.length;++e){const t=p[e].trim();if(""===t||t.startsWith("#"))continue;const i=g.exec(t);if(!i)continue;const[,n,r]=i,s=t.split(/\s+/).slice(1),a=f[n];a?a(s,r):console.warn("unhandled keyword:",n)}for(const e of o)e.data=Object.fromEntries(Object.entries(e.data).filter((([e,t])=>t.length>0)));return{geometries:o,materialLibs:a}}function fi(e){const t=e.geometries.map((e=>{const t=e.data.vertices,i=e.data.normals,n=e.data.textures;!function(e,t){const i=Math.cos(t),n=Math.sin(t),r=e.vertices,s=e.normals;for(let e=0;e<r.length;e+=3){const t=r[e],a=r[e+1],o=r[e+2];r[e]=t*i+o*n,r[e+1]=a,r[e+2]=-t*n+o*i;const l=s[e],h=s[e+1],c=s[e+2];s[e]=l*i+c*n,s[e+1]=h,s[e+2]=-l*n+c*i}}(e.data,0);let r=[],s=[],a=[];for(let e=0;e<t.length;e+=3){const i=t[e],n=t[e+1],s=t[e+2];r.push(i,n,s)}for(let e=0;e<i.length;e+=3){const t=i[e],n=i[e+1],r=i[e+2];s.push(t,n,-r)}for(let e=0;e<n.length;e+=2){const t=n[e],i=1-n[e+1];a.push(t,i)}return{object:e.object,groups:e.groups,material:e.material,data:{vertices:r,normals:s,textures:a}}}));return{geometries:t,materialLibs:e.materialLibs}}class gi{constructor(e={}){var t;if(this._name=e.name||"noname",this._vertices=e.vertices||[],this._numVertices=this._vertices.length/3,this._texCoords=e.texCoords||new Array(2*this._numVertices),e.center&&gi.centering(this._vertices),this._src=e.src||null,this.color=(t=e.color)instanceof Array?new Float32Array(t):"string"==typeof t?ye(t):new Float32Array([1,1,1,1]),e.scale&&gi.scale(this._vertices,e.scale),e.indices)this._indices=e.indices,this._normals=e.normals||[];else{this._normals=gi.getNormals(this._vertices),this._indices=new Array(this._vertices.length/3);for(let e=0,t=this._indices.length;e<t;e++)this._indices[e]=e}}static centering(e){let t=s,i=s,n=s,r=a,o=a,l=a;for(let s=0,a=e.length;s<a;s+=3){let a=e[s],h=e[s+1],c=e[s+2];a<t&&(t=a),h<i&&(i=h),c<n&&(n=c),a>r&&(r=a),h>o&&(o=h),c>l&&(l=c)}let h=t+.5*(r-t),c=i+.5*(o-i),d=n+.5*(l-n);for(let t=0,i=e.length;t<i;t+=3)e[t]-=h,e[t+1]-=c,e[t+2]-=d}get src(){return this._src}set src(e){this._src=e}get name(){return this._name}get vertices(){return this._vertices}get normals(){return this._normals}get indices(){return this._indices}get texCoords(){return this._texCoords}get numVertices(){return this._numVertices}static scale(e,t){for(let i=0;i<e.length;i++)e[i]*=t}static centroid(e){let t=1e3,i=1e3,n=1e3,r=-1e3,s=-1e3,a=-1e3;for(let o=0;o<e.length;o+=3){let l=e[o],h=e[o+1],c=e[o+2];l<t&&(t=l),h<i&&(i=h),c<n&&(n=c),l>r&&(r=l),h>s&&(s=h),c>a&&(a=c)}return[t+.5*(r-t),i+.5*(s-i),n+.5*(a-n)]}static translate(e,t){for(let i=0;i<e.length;i+=3)e[i]-=t[0],e[i+1]-=t[1],e[i+2]-=t[2]}static getNormals(e){let t=new Array(e.length);for(let i=0;i<e.length;i+=9){let n=i,r=i+3,s=i+6,a=e[n],o=e[n+1],l=e[n+2],h=e[r]-a,c=e[r+1]-o,d=e[r+2]-l,_=e[s]-a,u=e[s+1]-o,f=e[s+2]-l,g=c*f-d*u,p=d*_-h*f,m=h*u-c*_,v=Math.sqrt(g*g+p*p+m*m);g/=v,p/=v,m/=v,t[n]=g,t[n+1]=p,t[n+2]=m,t[r]=g,t[r+1]=p,t[r+2]=m,t[s]=g,t[s+1]=p,t[s+2]=m}return t}static createSphere(e=16,t=16,i=1,n=0,r=0,s=0){let a=[],o=[],l=[];for(let o=0;o<=t;o++){let h=o*Math.PI/t,c=Math.sin(h),d=Math.cos(h);for(let t=0;t<=e;t++){let o=2*t*Math.PI/e,h=Math.sin(o),_=Math.cos(o)*c+n,u=d+r,f=h*c+s;l.push(_),l.push(u),l.push(f),a.push(i*_),a.push(i*u),a.push(i*f)}}for(let i=0;i<t;i++)for(let t=0;t<e;t++){let n=i*(e+1)+t,r=n+e+1;o.push(n),o.push(n+1),o.push(r),o.push(r),o.push(n+1),o.push(r+1)}return new gi({vertices:a,normals:l,indices:o})}static createDisc(e=1,t=0,i=8,n=!0,r=0,s=0,a=0,o=0){let l=[],h=[],c=[],d=2*Math.PI,_=n?1:-1,u=r;for(let e=1;e<=i;e++)l.push(s,t*_+a,o),c.push(0,_,0),r++;let f=r;for(let n=0;n<=i;n++){let h=n/i*d+0,u=Math.cos(h),f=Math.sin(h);l.push(e*f+s,t*_+a,e*u+o),c.push(0,_,0),r++}for(let e=0;e<i;e++){let t=u+e,i=f+e;n?h.push(i,i+1,t):h.push(i+1,i,t)}return new gi({vertices:l,normals:c,indices:h})}static getFrustumScaleByCameraAngles(e,t,i){return new oe(2*e*Math.tan(c*t),2*e*Math.tan(c*i),e)}static getFrustumScaleByCameraAspectRatio(e,t,i){let n=h*Math.atan(Math.tan(c*t)/i);return gi.getFrustumScaleByCameraAngles(e,t,n)}static createFrustum(e=1,t=1,i=1,n=0,r=0,s=0){return new gi({vertices:[0+n,0+r,0+s,-1*(t*=.5)+n,1*(i*=.5)+r,-1*e+s,1*t+n,1*i+r,-1*e+s,0+n,0+r,0+s,1*t+n,-1*i+r,-1*e+s,-1*t+n,-1*i+r,-1*e+s,0+n,0+r,0+s,1*t+n,1*i+r,-1*e+s,1*t+n,-1*i+r,-1*e+s,0+n,0+r,0+s,-1*t+n,-1*i+r,-1*e+s,-1*t+n,1*i+r,-1*e+s,0+n,0+r,0+s,1*t+n,1*i+r,-1*e+s,-1*t+n,1*i+r,-1*e+s,0+n,0+r,0+s,-1*t+n,-1*i+r,-1*e+s,1*t+n,-1*i+r,-1*e+s,0+n,0+r,0+s,1*t+n,-1*i+r,-1*e+s,1*t+n,1*i+r,-1*e+s,0+n,0+r,0+s,-1*t+n,1*i+r,-1*e+s,-1*t+n,-1*i+r,-1*e+s]})}static createCylinder(e=1,t=1,i=1,n=32,r=1,s=!0,a=!0,o=0,l=0,h=0){let c=[],d=[],_=[],u=2*Math.PI,f=0,g=[],p=new oe,m=(t-e)/i;for(let s=0;s<=r;s++){let a=[],d=s/r,v=d*(t-e)+e;for(let e=0;e<=n;e++){let t=e/n*u+0,r=Math.sin(t),s=Math.cos(t);c.push(v*r+o,-d*i+i+l,v*s+h),p.set(r,m,s).normalize(),_.push(p.x,p.y,p.z),a.push(f++)}g.push(a)}for(let e=0;e<n;e++)for(let t=0;t<r;t++){let i=g[t][e],n=g[t+1][e],r=g[t+1][e+1],s=g[t][e+1];d.push(i,n,s),d.push(n,r,s)}if(0!==e&&s){let t=gi.createDisc(e,i,n,!0,f,o,l,h);c.push(...t.vertices),_.push(...t.normals),d.push(...t.indices)}if(0!==t&&a){let e=gi.createDisc(t,0,n,!1,f+(s?1+2*n:0),o,l,h);c.push(...e.vertices),_.push(...e.normals),d.push(...e.indices)}return new gi({vertices:c,normals:_,indices:d})}static createCube(e=1,t=1,i=1,n=0,r=0,s=0){let a=.5*e+n,o=.5*t+r,l=.5*i+s;return new gi({vertices:[-a,-o,l,a,-o,-l,a,-o,l,-a,-o,l,-a,-o,-l,a,-o,-l,-a,o,l,a,o,l,a,o,-l,-a,o,l,a,o,-l,-a,o,-l,-a,-o,l,a,-o,l,-a,o,l,-a,o,l,a,-o,l,a,o,l,-a,-o,-l,-a,o,-l,a,-o,-l,-a,o,-l,a,o,-l,a,-o,-l,a,-o,l,a,-o,-l,a,o,l,a,o,l,a,-o,-l,a,o,-l,-a,-o,l,-a,o,l,-a,-o,-l,-a,o,l,-a,o,-l,-a,-o,-l]})}static createArrow(e=0,t=2.1,i=-15){return new gi({vertices:[0,t,0,7,0,6,0,0,i,0,0,e,7,0,6,0,t,0,-7,0,6,0,0,e,0,t,0,-7,0,6,0,t,0,0,0,i,-7,0,6,0,0,i,0,0,e,0,0,e,0,0,i,7,0,6]})}static async loadObj(e){return(await fetch(e,{mode:"cors"}).then((e=>e.text())).then((e=>fi(ui(e)))).catch((()=>[]))).geometries.map((({data:{vertices:e,normals:t,textures:i}})=>new gi({vertices:e,normals:t,texCoords:i})))}}class pi{constructor(e){this._handlerIndex=-1,this._tag=e.tag||"none",this.instanced=!0,this._entity=null,this._position=Ae(e.position),this._positionHigh=new oe,this._positionLow=new oe,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._pitch=e.pitch||0,this._yaw=e.yaw||0,this._roll=e.roll||0,this._scale=Ae(e.scale,new oe(1,1,1)),this._color=Ee(e.color),this._direction=new oe(0,1,0),this._handler=null,this._handlerIndex=-1,this._tagData=null,this._tagDataIndex=-1;let t=e.object3d;e.object3d&&0!==e.object3d?.vertices.length||(t=new gi),e.objSrc&&(this.setObjectSrc(e.objSrc),this._objectSrc=e.objSrc),this._object3d=t,e.textureSrc&&this.setTextureSrc(e.textureSrc),this._visibility=null==e.visibility||e.visibility,this._qNorthFrame=new ae}get tag(){return this._tag}getPosition(){return this._position}getPitch(){return this._pitch}getYaw(){return this._yaw}getRoll(){return this._roll}getDirection(){return this._direction}get object3d(){return this._object3d}get vertices(){return this._object3d.vertices}get normals(){return this._object3d.normals}get texCoords(){return this._object3d.texCoords}get indices(){return this._object3d.indices}setOpacity(e){this._color.w=e,this.setColor(this._color.x,this._color.y,this._color.z,e)}setColor(e,t,i,n){this._color.x=e,this._color.y=t,this._color.z=i,null!=n&&(this._color.w=n),this._handler&&this._handler.setRgbaArr(this._tagData,this._tagDataIndex,this._color)}setColor4v(e){this._color.x=e.x,this._color.y=e.y,this._color.z=e.z,null!=e.w&&(this._color.w=e.w),this._handler&&this._handler.setRgbaArr(this._tagData,this._tagDataIndex,this._color)}setVisibility(e){this._visibility=e,this._handler&&this._handler.setVisibility(this._tagData,this._tagDataIndex,e)}getVisibility(){return this._visibility}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._handler&&this._handler.setPositionArr(this._tagData,this._tagDataIndex,this._positionHigh,this._positionLow),this.updateDirection()}setPosition3v(e){this._position.x=e.x,this._position.y=e.y,this._position.z=e.z,oe.doubleToTwoFloats(e,this._positionHigh,this._positionLow),this._handler&&this._handler.setPositionArr(this._tagData,this._tagDataIndex,this._positionHigh,this._positionLow),this.updateDirection()}setYaw(e){this._yaw=e,this.updateDirection()}setObject(e){this._object3d=e}setObjectSrc(e){this._objectSrc=e,this._handler&&this._handler.setObjectSrc(e,this.tag)}setTextureSrc(e){this._textureSrc=e,this._object3d&&(this._object3d.src=e),this._handler&&this._handler.setTextureTag(e,this.tag)}setColorHTML(e){this.setColor4v(ve(e))}setPitch(e){this._pitch=e,this._handler&&this._handler.setPitchRollArr(this._tagData,this._tagDataIndex,e,this._roll)}setRoll(e){this._roll=e,this._handler&&this._handler.setPitchRollArr(this._tagData,this._tagDataIndex,this._pitch,e)}setPitchYawRoll(e,t,i){this.setPitch(e),this.setYaw(t),this.setRoll(i)}setScale(e){this._scale.x=this._scale.y=this._scale.z=e,this._handler&&this._handler.setScaleArr(this._tagData,this._tagDataIndex,this._scale)}setScale3v(e){this._scale.copy(e),this._handler&&this._handler.setScaleArr(this._tagData,this._tagDataIndex,e)}getScale(){return this._scale}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._handler&&this._handler.setPickingColorArr(this._tagData,this._tagDataIndex,e)}updateDirection(){if(this._handler&&this._handler._planet){this._qNorthFrame=this._handler._planet.getNorthFrameRotation(this._position);let e=ae.yRotation(this._yaw).mul(this._qNorthFrame).conjugate();this._direction=e.mulVec3(new oe(0,0,-1)).normalize(),this._handler.setDirectionArr(this._tagData,this._tagDataIndex,this._direction)}}}const mi={RIGHT:0,LEFT:1,CENTER:2},vi={left:mi.LEFT,right:mi.RIGHT,center:mi.CENTER};class yi extends ri{constructor(e={}){super(e),this._handler=null,this._text=e.text||"",this._face=Le(e.face,"arial"),this._size=e.size||24,this._outline=null!=e.outline?e.outline:0,this._outlineColor=Ee(e.outlineColor,new re(0,0,0,1)),this._align=e.align&&vi[e.align.trim().toLowerCase()]||mi.RIGHT,this._fontIndex=0,this._fontAtlas=null,this._isRTL=e.isRTL||!1}setText(e){this._text=e.toString(),this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,e,this._fontIndex,this._align,this._isRTL)}setRtl(e){this._isRTL=e,this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._isRTL)}getText(){return this._text}setAlign(e){this._align=vi[e.trim().toLowerCase()],this._isReady&&this._handler?this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._isRTL):this._lockId!==ti&&(this._lockId=ei)}getAlign(){return this._align}setFace(e){this._face=e.trim(),this.update()}getFace(){return this._face}setSize(e){e!==this._size&&(this._size=e,this._isReady&&this._handler?this._handler.setSizeArr(this._handlerIndex,e):this._lockId!==ti&&(this._lockId=ei))}getSize(){return this._size}setOutline(e){this._outline=e,this._isReady&&this._handler?this._handler.setOutlineArr(this._handlerIndex,e):this._lockId!==ti&&(this._lockId=ei)}getOutline(){return this._outline}setOpacity(e){super.setOpacity(e),this.setOutlineOpacity(e)}setOutlineColor(e,t,i,n){n===this._outlineColor.w&&e===this._outlineColor.x&&t===this._outlineColor.y&&i===this._outlineColor.z||(this._outlineColor.x=e,this._outlineColor.y=t,this._outlineColor.z=i,this._outlineColor.w=n,this._isReady&&this._handler?this._handler.setOutlineColorArr(this._handlerIndex,this._outlineColor):this._lockId!==ti&&(this._lockId=ei))}setOutlineColor4v(e){this.setOutlineColor(e.x,e.y,e.z,e.w)}setOutlineColorHTML(e){this.setOutlineColor4v(ve(e))}getOutlineColor(){return this._outlineColor}setOutlineOpacity(e){e!==this._outlineColor.w&&(this._outlineColor.w=e,this._isReady&&this._handler?this._handler.setOutlineColorArr(this._handlerIndex,this._outlineColor):this._lockId!==ti&&(this._lockId=ei))}getOutlineOpacity(){return this._outlineColor.w}async update(){if(this._fontAtlas){const e=await this._fontAtlas.getFontIndex(this._face);this._applyFontIndex(e)}}_applyFontIndex(e){this._fontIndex=e,this._isReady&&this._handler?(this._handler.setFontIndexArr(this._handlerIndex,this._fontIndex),this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._isRTL)):this._lockId!==ti&&(this._lockId=ei)}assignFontAtlas(e){this._fontAtlas||(this._fontAtlas=e),this.update()}serializeWorkerData(e){return this._handler?new Float32Array([e,this._handler._maxLetters,this.getVisibility()?1:0,this._positionHigh.x,this._positionHigh.y,this._positionHigh.z,this._positionLow.x,this._positionLow.y,this._positionLow.z,this._size,this._offset.x,this._offset.y,this._offset.z,this._color.x,this._color.y,this._color.z,this._color.w,this._rotation,this._alignedAxis.x,this._alignedAxis.y,this._alignedAxis.z,this._fontIndex,this._outline,this._outlineColor.x,this._outlineColor.y,this._outlineColor.z,this._outlineColor.w,this._entity._pickingColor.x,this._entity._pickingColor.y,this._entity._pickingColor.z]):null}}class xi{constructor(e={}){this.__id=xi.__counter__++,this.visibility=null==e.visibility||e.visibility,this.pointSize=e.pointSize||3,this.pickingScale=e.pickingScale||0,this._renderNode=null,this._entity=null,this._points=[],this._coordinatesData=[],this._colorData=[],this._pickingColorData=[],this._coordinatesBuffer=null,this._colorBuffer=null,this._pickingColorBuffer=null,this._handler=null,this._handlerIndex=-1,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this._createCoordinatesBuffer,this._buffersUpdateCallbacks[1]=this._createColorBuffer,this._buffersUpdateCallbacks[2]=this._createPickingColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length),e.points&&this.setPoints(e.points)}clear(){this._points.length=0,this._points=[],this._coordinatesData.length=0,this._coordinatesData=[],this._colorData.length=0,this._colorData=[],this._pickingColorData.length=0,this._pickingColorData=[],this._deleteBuffers()}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){this._renderNode=e,this._setPickingColors()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPoints(e){this.clear();for(let t=0;t<e.length;t++){let i=e[t],n=new oe(i[0],i[1],i[2]),r=new re(i[3],i[4],i[5],null==i[6]?255:i[6]);this._coordinatesData.push(n.x,n.y,n.z),this._colorData.push(r.x/255,r.y/255,r.z/255,r.w/255);let s={_entity:this._entity,_pickingColor:new oe,_entityCollection:this._entity?this._entity._entityCollection:null,index:t,position:n,color:r,pointCloud:this,properties:i[7]||{}};this._points.push(s),this._renderNode&&this._renderNode.renderer&&(this._renderNode.renderer.assignPickingColor(s),this._pickingColorData.push(s._pickingColor.x/255,s._pickingColor.y/255,s._pickingColor.z/255,1))}this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}setPointPosition(e,t,i,n){this._changedBuffers[0]=!0}setPointColor(e,t,i,n,r){this._changedBuffers[1]=!0}addPoints(e){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}addPoint(e,t){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}getPoint(e){return this._points[e]}removePoint(e){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}insertPoint(e,t){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}draw(){if(this.visibility&&this._coordinatesData.length){this._update();let e=this._renderNode.renderer,t=e.handler.programs.pointCloud,i=t._program,n=e.handler.gl,r=i.attributes,s=i.uniforms;t.activate(),n.uniformMatrix4fv(s.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),n.uniform1f(s.opacity,this._handler._entityCollection._fadingOpacity),n.uniform1f(s.pointSize,this.pointSize),n.bindBuffer(n.ARRAY_BUFFER,this._coordinatesBuffer),n.vertexAttribPointer(r.coordinates,this._coordinatesBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._colorBuffer),n.vertexAttribPointer(r.colors,this._colorBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.POINTS,0,this._coordinatesBuffer.numItems)}}drawPicking(){if(this.visibility&&this._coordinatesData.length){let e=this._renderNode.renderer,t=e.handler.programs.pointCloud,i=t._program,n=e.handler.gl,r=i.attributes,s=i.uniforms;t.activate(),n.uniformMatrix4fv(s.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),n.uniform1f(s.opacity,this._handler._entityCollection._fadingOpacity),n.uniform1f(s.pointSize,this.pointSize+this.pickingScale),n.bindBuffer(n.ARRAY_BUFFER,this._coordinatesBuffer),n.vertexAttribPointer(r.coordinates,this._coordinatesBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._pickingColorBuffer),n.vertexAttribPointer(r.colors,this._pickingColorBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.POINTS,0,this._coordinatesBuffer.numItems)}}_update(){if(this._renderNode){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}_deleteBuffers(){if(this._renderNode){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._coordinatesBuffer),e.deleteBuffer(this._colorBuffer),e.deleteBuffer(this._pickingColorBuffer)}this._coordinatesBuffer=null,this._colorBuffer=null,this._pickingColorBuffer=null}_createCoordinatesBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._coordinatesBuffer),this._coordinatesBuffer=e.createArrayBuffer(new Float32Array(this._coordinatesData),3,this._coordinatesData.length/3)}_createColorBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._colorBuffer),this._colorBuffer=e.createArrayBuffer(new Float32Array(this._colorData),4,this._colorData.length/4)}_createPickingColorBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorBuffer=e.createArrayBuffer(new Float32Array(this._pickingColorData),4,this._pickingColorData.length/4)}_setPickingColors(){if(this._renderNode&&this._renderNode.renderer){for(let e=0;e<this._points.length;e++){let t=this._points[e];t._entity=this._entity,t._entityCollection=this._entity._entityCollection,this._renderNode.renderer.assignPickingColor(t),this._pickingColorData.push(t._pickingColor.x/255,t._pickingColor.y/255,t._pickingColor.z/255,1)}this._changedBuffers[2]=!0}}}xi.__counter__=0;class bi{constructor(e={}){this.__id=bi.__counter__++,this.altitude=e.altitude||0,this.thickness=e.thickness||1.5,this._opacity=null!=e.opacity?e.opacity:1,this._defaultColor=ye(e.color||"#0000FF",e.opacity),this.visibility=null==e.visibility||e.visibility,this._closedLine=e.isClosed||!1,this._path3v=[],this._pathLengths=[],this._pathLonLat=[],this._pathLonLatMerc=[],this._pathColors=e.pathColors?qe(e.pathColors):[],this._extent=new ie,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null,this._pickingColor=[0,0,0],this._renderNode=null,this._entity=null,this._handler=null,this._handlerIndex=-1,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this._createVerticesBuffer,this._buffersUpdateCallbacks[1]=this._createIndexBuffer,this._buffersUpdateCallbacks[2]=this._createColorsBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length),e.pathLonLat?this.setPathLonLat(e.pathLonLat):e.path3v&&this.setPath3v(e.path3v),this._refresh()}static appendLineData3v(e,t,i,n,r,s,a,o,l,h,c,d,_,u){var f=0,g=new oe,p=new oe;_&&(_.southWest.set(180,90),_.northEast.set(-180,-90)),o.length>0?(f=o[o.length-5]+9,o.push(f,f)):o.push(0,0);for(let A=0,E=e.length;A<E;A++){var m=e[A],v=t[A];if(h[A]=[],d[A]=[],c[A]=[],0===m.length)continue;var y,x=f;if(n)(y=m[m.length-1])instanceof Array&&(y=new oe(y[0],y[1],y[2]));else{var b=m[0],w=m[1]||b;b instanceof Array&&(b=new oe(b[0],b[1],b[2])),w instanceof Array&&(w=new oe(w[0],w[1],w[2])),y=new oe(b.x+b.x-w.x,b.y+b.y-w.y,b.z+b.z-w.z)}let E=i;v&&v[0]&&(E=v[0]),oe.doubleToTwoFloats(y,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z);let P=E[0],S=E[1],M=E[2],B=null!=E[3]?E[3]:1;A>0&&u.push(P,S,M,B,P,S,M,B,P,S,M,B,P,S,M,B),a.push(1,-1,2,-2);for(let e=0,t=m.length;e<t;e++){var C=m[e];if(C instanceof Array&&(C=new oe(C[0],C[1],C[2])),c[A].push(C),l){var T=l.cartesianToLonLat(C);h[A].push(T),d[A].push(T.forwardMercator()),T.lon<_.southWest.lon&&(_.southWest.lon=T.lon),T.lat<_.southWest.lat&&(_.southWest.lat=T.lat),T.lon>_.northEast.lon&&(_.northEast.lon=T.lon),T.lat>_.northEast.lat&&(_.northEast.lat=T.lat)}v&&v[e]&&(E=v[e]),P=E[0],S=E[1],M=E[2],B=null!=E[3]?E[3]:1,oe.doubleToTwoFloats(C,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(P,S,M,B,P,S,M,B,P,S,M,B,P,S,M,B),a.push(1,-1,2,-2),o.push(f++,f++,f++,f++)}var L;if(n)(L=m[0])instanceof Array&&(L=new oe(L[0],L[1],L[2])),o.push(x,x+1,x+1,x+1);else{let e=m[m.length-1],t=m[m.length-2]||e;e instanceof Array&&(e=new oe(e[0],e[1],e[2])),t instanceof Array&&(t=new oe(t[0],t[1],t[2])),L=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),o.push(f-1,f-1,f-1,f-1)}v&&v[m.length-1]&&(E=v[m.length-1]),P=E[0],S=E[1],M=E[2],B=null!=E[3]?E[3]:1,oe.doubleToTwoFloats(L,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(P,S,M,B,P,S,M,B,P,S,M,B,P,S,M,B),a.push(1,-1,2,-2),A<e.length-1&&0!==e[A+1].length&&(f+=8,o.push(f,f))}}static appendPoint3v(e,t,i,n,r,s,a,o,l,h,c,d,_,u){var f=new oe,g=new oe,p=h.length-4,m=h[p-1]+1;0===e.length?(e.push([]),i[0]||(i[0]=[])):i[e.length-1]||(i[e.length-1]=[]);var v=e[e.length-1],y=v.length;v.push(t);let x=n[0],b=n[1],w=n[2],C=null!=n[3]?n[3]:1,T=i[e.length-1];if(T[y]?(T[y][0]=x,T[y][1]=b,T[y][2]=w,T[y][3]=C):T.push(n),1===y){var L;if(r)(L=v[y-1])instanceof Array&&(L=new oe(L[0],L[1],L[2]));else{let e=v[0],t=v[1]||e;e instanceof Array&&(e=new oe(e[0],e[1],e[2])),t instanceof Array&&(t=new oe(t[0],t[1],t[2])),L=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}oe.doubleToTwoFloats(L,f,g);let e=s.length-36;s[e]=f.x,s[e+1]=f.y,s[e+2]=f.z,s[e+3]=f.x,s[e+4]=f.y,s[e+5]=f.z,s[e+6]=f.x,s[e+7]=f.y,s[e+8]=f.z,s[e+9]=f.x,s[e+10]=f.y,s[e+11]=f.z,a[e]=g.x,a[e+1]=g.y,a[e+2]=g.z,a[e+3]=g.x,a[e+4]=g.y,a[e+5]=g.z,a[e+6]=g.x,a[e+7]=g.y,a[e+8]=g.z,a[e+9]=g.x,a[e+10]=g.y,a[e+11]=g.z}var A=m;if(c){0===d.length&&d.push([]),0===_.length&&_.push([]);var E=d[d.length-1],P=_[_.length-1];let e=c.cartesianToLonLat(t);E.push(e),P.push(e.forwardMercator()),e.lon<u.southWest.lon&&(u.southWest.lon=e.lon),e.lat<u.southWest.lat&&(u.southWest.lat=e.lat),e.lon>u.northEast.lon&&(u.northEast.lon=e.lon),e.lat>u.northEast.lat&&(u.northEast.lat=e.lat)}oe.doubleToTwoFloats(t,f,g);let S=s.length-12;s[S]=f.x,s[S+1]=f.y,s[S+2]=f.z,s[S+3]=f.x,s[S+4]=f.y,s[S+5]=f.z,s[S+6]=f.x,s[S+7]=f.y,s[S+8]=f.z,s[S+9]=f.x,s[S+10]=f.y,s[S+11]=f.z,a[S]=g.x,a[S+1]=g.y,a[S+2]=g.z,a[S+3]=g.x,a[S+4]=g.y,a[S+5]=g.z,a[S+6]=g.x,a[S+7]=g.y,a[S+8]=g.z,a[S+9]=g.x,a[S+10]=g.y,a[S+11]=g.z;let M=o.length-16;var B;if(o[M]=x,o[M+1]=b,o[M+2]=w,o[M+3]=C,o[M+4]=x,o[M+5]=b,o[M+6]=w,o[M+7]=C,o[M+8]=x,o[M+9]=b,o[M+10]=w,o[M+11]=C,o[M+12]=x,o[M+13]=b,o[M+14]=w,o[M+15]=C,h[p]=m++,h[p+1]=m++,h[p+2]=m++,h[p+3]=m++,r)B=v[0],h.push(A,A+1,A+1,A+1);else{let e=v[v.length-1],t=v[v.length-2]||e;B=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),h.push(m-1,m-1,m-1,m-1)}oe.doubleToTwoFloats(B,f,g),s.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),a.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),o.push(x,b,w,C,x,b,w,C,x,b,w,C,x,b,w,C),l.push(1,-1,2,-2)}static setPathColors(e,t,i,n){for(let o=0,l=e.length;o<l;o++){var r=e[o],s=t[o];if(0===r.length)continue;let l=i;s&&s[0]&&(l=s[0]);let h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1;o>0&&n.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_);for(let e=0,t=r.length;e<t;e++){var a=r[e];a instanceof Array&&(a=new z(a[0],a[1],a[2])),s&&s[e]&&(l=s[e]),h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1,n.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_)}s&&s[r.length-1]&&(l=s[r.length-1]),h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1,n.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_)}}static appendLineDataLonLat(e,t,i,n,r,s,a,o,l,h,c,d,_,u){var f=0,g=new oe,p=new oe;_&&(_.southWest.set(180,90),_.northEast.set(-180,-90)),o.length>0?(f=o[o.length-5]+9,o.push(f)):o.push(0);for(let T=0,L=e.length;T<L;T++){var m=e[T],v=t[T];if(h[T]=[],d[T]=[],c[T]=[],0===m.length)continue;var y,x=f;if(n){let e=m[m.length-1];y=e instanceof Array?l.lonLatToCartesian(new z(e[0],e[1],e[2])):l.lonLatToCartesian(e)}else{let e,t,i=m[0];e=i instanceof Array?l.lonLatToCartesian(new z(i[0],i[1],i[2])):l.lonLatToCartesian(i),i=m[1],i||(i=m[0]),t=i instanceof Array?l.lonLatToCartesian(new z(i[0],i[1],i[2])):l.lonLatToCartesian(i),y=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}let L=i;v&&v[0]&&(L=v[0]),oe.doubleToTwoFloats(y,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z);let A=L[0],E=L[1],P=L[2],S=null!=L[3]?L[3]:1;T>0&&u.push(A,E,P,S,A,E,P,S,A,E,P,S,A,E,P,S),a.push(1,-1,2,-2);for(let e=0,t=m.length;e<t;e++){var b=m[e];b instanceof Array&&(b=new z(b[0],b[1],b[2])),v&&v[e]&&(L=v[e]),A=L[0],E=L[1],P=L[2],S=null!=L[3]?L[3]:1;var w=l.lonLatToCartesian(b);h[T].push(w),c[T].push(b),d[T].push(b.forwardMercator()),oe.doubleToTwoFloats(w,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(A,E,P,S,A,E,P,S,A,E,P,S,A,E,P,S),a.push(1,-1,2,-2),o.push(f++,f++,f++,f++),b.lon<_.southWest.lon&&(_.southWest.lon=b.lon),b.lat<_.southWest.lat&&(_.southWest.lat=b.lat),b.lon>_.northEast.lon&&(_.northEast.lon=b.lon),b.lat>_.northEast.lat&&(_.northEast.lat=b.lat)}var C;if(n){let e=m[0];C=e instanceof Array?l.lonLatToCartesian(new z(e[0],e[1],e[2])):l.lonLatToCartesian(e),o.push(x,x+1,x+1,x+1)}else{let e,t,i=m[m.length-1];e=i instanceof Array?l.lonLatToCartesian(new z(i[0],i[1],i[2])):l.lonLatToCartesian(i),i=m[m.length-2],i||(i=m[0]),t=i instanceof Array?l.lonLatToCartesian(new z(i[0],i[1],i[2])):l.lonLatToCartesian(i),C=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),o.push(f-1,f-1,f-1,f-1)}v&&v[m.length-1]&&(L=v[m.length-1]),A=L[0],E=L[1],P=L[2],S=null!=L[3]?L[3]:1,oe.doubleToTwoFloats(C,g,p),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),s.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(A,E,P,S,A,E,P,S,A,E,P,S,A,E,P,S),a.push(1,-1,2,-2),T<e.length-1&&0!==e[T+1].length&&(f+=8,o.push(f,f))}}_setEqualPath3v(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new oe,n=new oe,r=this._verticesHigh,s=this._verticesLow,a=this._pathLonLat,o=this._pathLonLatMerc,l=0,h=this._renderNode.ellipsoid;for(let m=0;m<e.length;m++){var c,d,_=e[m];c=this._closedLine?_[_.length-1]:new oe(_[0].x+_[0].x-_[1].x,_[0].y+_[0].y-_[1].y,_[0].z+_[0].z-_[1].z),oe.doubleToTwoFloats(c,i,n),r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z;for(let e=0;e<_.length;e++){var u=_[e],f=this._path3v[m][e];if(f.x=u.x,f.y=u.y,f.z=u.z,h){var g=h.cartesianToLonLat(u);this._pathLonLat[m][e]=g,a[m][e]=g,o[m][e]=g.forwardMercator(),g.lon<t.southWest.lon&&(t.southWest.lon=g.lon),g.lat<t.southWest.lat&&(t.southWest.lat=g.lat),g.lon>t.northEast.lon&&(t.northEast.lon=g.lon),g.lat>t.northEast.lat&&(t.northEast.lat=g.lat)}oe.doubleToTwoFloats(u,i,n),r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z}if(this._closedLine)d=_[0];else{var p=_.length-1;d=new oe(_[p].x+_[p].x-_[p-1].x,_[p].y+_[p].y-_[p-1].y,_[p].z+_[p].z-_[p-1].z)}oe.doubleToTwoFloats(d,i,n),r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z,r[l]=i.x,s[l++]=n.x,r[l]=i.y,s[l++]=n.y,r[l]=i.z,s[l++]=n.z}}_setEqualPathLonLat(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new oe,n=new oe,r=this._verticesHigh,s=this._verticesLow,a=this._pathLonLat,o=this._pathLonLatMerc,l=this._path3v,h=0,c=this._renderNode.ellipsoid;for(let p=0;p<e.length;p++){var d,_,u=e[p];if(this._closedLine)d=c.lonLatToCartesian(u[u.length-1]);else{let e=c.lonLatToCartesian(u[0]),t=c.lonLatToCartesian(u[1]);d=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}oe.doubleToTwoFloats(d,i,n),r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z;for(let e=0;e<u.length;e++){var f=u[e],g=c.lonLatToCartesian(f);l[p][e]=g,o[p][e]=f.forwardMercator(),a[p][e]=f,oe.doubleToTwoFloats(g,i,n),r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,f.lon<t.southWest.lon&&(t.southWest.lon=f.lon),f.lat<t.southWest.lat&&(t.southWest.lat=f.lat),f.lon>t.northEast.lon&&(t.northEast.lon=f.lon),f.lat>t.northEast.lat&&(t.northEast.lat=f.lat)}if(this._closedLine)_=c.lonLatToCartesian(u[0]);else{let e=c.lonLatToCartesian(u[u.length-1]),t=c.lonLatToCartesian(u[u.length-2]);_=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}oe.doubleToTwoFloats(_,i,n),r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z,r[h]=i.x,s[h++]=n.x,r[h]=i.y,s[h++]=n.y,r[h]=i.z,s[h++]=n.z}}setPointLonLat(e,t,i){if(this._renderNode&&this._renderNode.ellipsoid){let o=this._pathLonLat,l=this._pathLonLatMerc;o[i][t]=e,l[i][t]=e.forwardMercator();var n=this._extent;n.southWest.set(180,90),n.northEast.set(-180,-90);for(let e=0;e<o.length;e++){var r=o[e];for(let e=0;e<r.length;e++){var s=r[e].lon,a=r[e].lat;s>n.northEast.lon&&(n.northEast.lon=s),a>n.northEast.lat&&(n.northEast.lat=a),s<n.southWest.lon&&(n.southWest.lon=s),a<n.southWest.lat&&(n.southWest.lat=a)}}this.setPoint3v(this._renderNode.ellipsoid.lonLatToCartesian(e),t,i,!0)}else{let n=this._pathLonLat[i];n[t].lon=e.lon,n[t].lat=e.lat,n[t].height=e.height}}setPoint3v(e,t=0,i=0,n=!1){if(this._renderNode){var r,s=new oe,a=new oe,o=this._verticesHigh,l=this._verticesLow,h=this._pathLonLat,c=this._pathLonLatMerc,d=0;r=12*this._pathLengths[i]+24*i;let x=this._path3v[i];x[t].x=e.x,x[t].y=e.y,x[t].z=e.z;let b=this._closedLine||1===x.length;var _;if(0===t||1===t)_=b?x[x.length-1]:new oe(x[0].x+x[0].x-x[1].x,x[0].y+x[0].y-x[1].y,x[0].z+x[0].z-x[1].z),d=r,oe.doubleToTwoFloats(_,s,a),o[d]=s.x,o[d+1]=s.y,o[d+2]=s.z,o[d+3]=s.x,o[d+4]=s.y,o[d+5]=s.z,o[d+6]=s.x,o[d+7]=s.y,o[d+8]=s.z,o[d+9]=s.x,o[d+10]=s.y,o[d+11]=s.z,l[d]=a.x,l[d+1]=a.y,l[d+2]=a.z,l[d+3]=a.x,l[d+4]=a.y,l[d+5]=a.z,l[d+6]=a.x,l[d+7]=a.y,l[d+8]=a.z,l[d+9]=a.x,l[d+10]=a.y,l[d+11]=a.z;if(!n&&this._renderNode.ellipsoid){var u=this._renderNode.ellipsoid.cartesianToLonLat(e);h[i][t]=u,c[i][t]=u.forwardMercator();var f=this._extent;f.southWest.set(180,90),f.northEast.set(-180,-90);for(let e=0;e<h.length;e++){var g=h[e];for(let e=0;e<g.length;e++){var p=g[e].lon,m=g[e].lat;p>f.northEast.lon&&(f.northEast.lon=p),m>f.northEast.lat&&(f.northEast.lat=m),p<f.southWest.lon&&(f.southWest.lon=p),m<f.southWest.lat&&(f.southWest.lat=m)}}}if(d=r+12*t+12,oe.doubleToTwoFloats(e,s,a),o[d]=s.x,o[d+1]=s.y,o[d+2]=s.z,o[d+3]=s.x,o[d+4]=s.y,o[d+5]=s.z,o[d+6]=s.x,o[d+7]=s.y,o[d+8]=s.z,o[d+9]=s.x,o[d+10]=s.y,o[d+11]=s.z,l[d]=a.x,l[d+1]=a.y,l[d+2]=a.z,l[d+3]=a.x,l[d+4]=a.y,l[d+5]=a.z,l[d+6]=a.x,l[d+7]=a.y,l[d+8]=a.z,l[d+9]=a.x,l[d+10]=a.y,l[d+11]=a.z,t===x.length-1||t===x.length-2){var v;if(b)v=x[0];else{var y=x.length-1;v=new oe(x[y].x+x[y].x-x[y-1].x,x[y].y+x[y].y-x[y-1].y,x[y].z+x[y].z-x[y-1].z)}d=r+12*x.length+12,oe.doubleToTwoFloats(v,s,a),o[d]=s.x,o[d+1]=s.y,o[d+2]=s.z,o[d+3]=s.x,o[d+4]=s.y,o[d+5]=s.z,o[d+6]=s.x,o[d+7]=s.y,o[d+8]=s.z,o[d+9]=s.x,o[d+10]=s.y,o[d+11]=s.z,l[d]=a.x,l[d+1]=a.y,l[d+2]=a.z,l[d+3]=a.x,l[d+4]=a.y,l[d+5]=a.z,l[d+6]=a.x,l[d+7]=a.y,l[d+8]=a.z,l[d+9]=a.x,l[d+10]=a.y,l[d+11]=a.z}this._changedBuffers[0]=!0}else{let n=this._path3v[i];n[t].x=e.x,n[t].y=e.y,n[t].z=e.z}}_resizePathLengths(e=0){this._pathLengths[0]=0;for(let t=e+1,i=this._path3v.length;t<=i;t++)this._pathLengths[t]=this._pathLengths[t-1]+this._path3v[t-1].length}removeSegment(e){this._path3v.splice(e,1),this.setPath3v([].concat(this._path3v))}removePoint(e,t=0){this._path3v[t].splice(e,1),0===this._path3v[t].length&&this._path3v.splice(t,1),this.setPath3v([].concat(this._path3v))}insertPoint3v(e,t=0,i,n=0){let r=[].concat(this._path3v),s=r[n];if(s){let a=[].concat(this._pathColors);if(s.splice(t,0,e),i){let e=a[n];e||(e=new Array(s.length)),e.splice(t,0,i)}this.setPath3v(r,a)}else this.addPoint3v(e,n)}appendPoint3v(e,t,i){0!==this._path3v.length&&this._renderNode?(this._verticesHigh=Ve(this._verticesHigh),this._verticesLow=Ve(this._verticesLow),this._colors=Ve(this._colors),this._orders=Ve(this._orders),this._indexes=Ve(this._indexes),bi.appendPoint3v(this._path3v,e,this._pathColors,t||this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._colors,this._orders,this._indexes,i?null:this._renderNode.ellipsoid,this._pathLonLat,this._pathLonLatMerc,this._extent),this._pathLengths[this._path3v.length]+=1,this._changedBuffers[0]=!0,this._changedBuffers[2]=!0,this._changedBuffers[1]=!0):(this._pathColors.push([t||this._defaultColor]),this.addPoint3v(e))}addPoint3v(e,t=0){t>=this._path3v.length&&this._path3v.push([]),this._path3v[t].push(e),this.setPath3v([].concat(this._path3v))}addPointLonLat(e,t=0){t>=this._pathLonLat.length&&this._pathLonLat.push([]),this._pathLonLat[t].push(e),this.setPathLonLat([].concat(this._pathLonLat))}clear(){this._clearData()}setPointColor(e,t=0,i=0){if(this._renderNode&&t<this._path3v[i].length){let n=this._pathColors[i];if(!n){if(!(this._path3v[i]&&t<this._path3v[i].length))return;this._pathColors[i]=new Array(this._path3v[i].length)}n[t]?(n[t][0]=e[0],n[t][1]=e[1],n[t][2]=e[2],n[t][3]=e[3]||1):n[t]=[e[0],e[1],e[2],e[3]||1];let r=this._colors,s=16*t+16*this._pathLengths[i]+32*i;r[s]=r[s+4]=r[s+8]=r[s+12]=e[0],r[s+1]=r[s+5]=r[s+9]=r[s+13]=e[1],r[s+2]=r[s+6]=r[s+10]=r[s+14]=e[2],r[s+3]=r[s+7]=r[s+11]=r[s+15]=e[3]||1,this._changedBuffers[2]=!0}else{this._pathColors[i][t]=e}}setOpacity(e){this._opacity=e}setAltitude(e){this.altitude=e}setThickness(e){this.thickness=e}getThickness(){return this.thickness}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){e&&(this._renderNode=e,this._pathLonLat.length?this._createDataLonLat([].concat(this._pathLonLat)):this._createData3v([].concat(this._path3v)),this._refresh(),e.renderer&&e.renderer.isInitialized()&&this._update())}_clearData(){this._verticesHigh=null,this._verticesLow=null,this._orders=null,this._indexes=null,this._colors=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._path3v.length=0,this._pathLonLat.length=0,this._pathLonLatMerc.length=0,this._path3v=[],this._pathLonLat=[],this._pathLonLatMerc=[]}_createData3v(e){this._clearData(),bi.appendLineData3v(e,this._pathColors,this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._orders,this._indexes,this._renderNode.ellipsoid,this._pathLonLat,this._path3v,this._pathLonLatMerc,this._extent,this._colors),this._resizePathLengths(0)}_createDataLonLat(e){this._clearData(),bi.appendLineDataLonLat(e,this._pathColors,this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._orders,this._indexes,this._renderNode.ellipsoid,this._path3v,this._pathLonLat,this._pathLonLatMerc,this._extent,this._colors),this._resizePathLengths(0)}remove(){this._entity=null,this._pathColors.length=0,this._pathColors=[],this._verticesHigh=null,this._verticesLow=null,this._orders=null,this._indexes=null,this._colors=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._deleteBuffers(),this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._pickingColor[0]=e.x/255,this._pickingColor[1]=e.y/255,this._pickingColor[2]=e.z/255}getExtent(){return this._extent.clone()}getPath3v(){return this._path3v}getPathLonLat(){return this._pathLonLat}getPathColors(){return this._pathColors}setPathColors(e){e&&(this._colors=[],this._pathColors=[].concat(e),bi.setPathColors(this._pathLonLat,e,this._defaultColor,this._colors),this._changedBuffers[2]=!0)}setColorHTML(e){this._defaultColor=ye(e);let t=ve(e),i=this._pathColors;for(let e=0,n=i.length;e<n;e++){let n=i[e];for(let e=0,i=n.length;e<i;e++)n[e][0]=t.x,n[e][1]=t.y,n[e][2]=t.z,n[e][3]=t.w}let n=this._colors;for(let e=0,i=n.length;e<i;e+=4)n[e]=t.x,n[e+1]=t.y,n[e+2]=t.z,n[e+3]=t.w;this._changedBuffers[2]=!0}setPathLonLat(e,t=!1){this._renderNode&&this._renderNode.ellipsoid?t?(this._setEqualPathLonLat(e),this._changedBuffers[0]=!0,this._changedBuffers[2]=!0):(this._createDataLonLat(e),this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0):this._pathLonLat=[].concat(e)}setPath3v(e,t,i=!1){t&&(this._pathColors=[].concat(t)),this._renderNode?i?(this._setEqualPath3v(e),this._changedBuffers[0]=!0,this._changedBuffers[2]=!0):(this._createData3v(e),this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0):this._path3v=[].concat(e)}draw(){if(this.visibility&&this._path3v.length){this._update();let e=this._renderNode,t=e.renderer,i=t.handler.programs.polyline_screen,n=i._program,r=t.handler.gl,s=n.attributes,a=n.uniforms,o=this._handler._entityCollection;i.activate(),r.disable(r.CULL_FACE),r.uniform1f(a.depthOffset,o.polygonOffsetUnits),r.uniformMatrix4fv(a.proj,!1,t.activeCamera.getProjectionMatrix()),r.uniformMatrix4fv(a.view,!1,t.activeCamera.getViewMatrix()),r.uniform3fv(a.eyePositionHigh,t.activeCamera.eyeHigh),r.uniform3fv(a.eyePositionLow,t.activeCamera.eyeLow),r.uniform2fv(a.uFloatParams,[e._planetRadius2||0,t.activeCamera._tanViewAngle_hradOneByHeight]),r.uniform2fv(a.viewport,[t.handler.canvas.width,t.handler.canvas.height]),r.uniform1f(a.thickness,.5*this.thickness),r.uniform1f(a.opacity,this._opacity*o._fadingOpacity),r.bindBuffer(r.ARRAY_BUFFER,this._colorsBuffer),r.vertexAttribPointer(s.color,this._colorsBuffer.itemSize,r.FLOAT,!1,0,0);let l=this._verticesHighBuffer;r.bindBuffer(r.ARRAY_BUFFER,l),r.vertexAttribPointer(s.prevHigh,l.itemSize,r.FLOAT,!1,12,0),r.vertexAttribPointer(s.currentHigh,l.itemSize,r.FLOAT,!1,12,48),r.vertexAttribPointer(s.nextHigh,l.itemSize,r.FLOAT,!1,12,96),l=this._verticesLowBuffer,r.bindBuffer(r.ARRAY_BUFFER,l),r.vertexAttribPointer(s.prevLow,l.itemSize,r.FLOAT,!1,12,0),r.vertexAttribPointer(s.currentLow,l.itemSize,r.FLOAT,!1,12,48),r.vertexAttribPointer(s.nextLow,l.itemSize,r.FLOAT,!1,12,96),r.bindBuffer(r.ARRAY_BUFFER,this._ordersBuffer),r.vertexAttribPointer(s.order,this._ordersBuffer.itemSize,r.FLOAT,!1,4,0),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),r.drawElements(r.TRIANGLE_STRIP,this._indexesBuffer.numItems,r.UNSIGNED_INT,0),r.enable(r.CULL_FACE)}}drawPicking(){if(this.visibility&&this._path3v.length){let e=this._renderNode,t=e.renderer,i=t.handler.programs.polyline_picking,n=i._program,r=t.handler.gl,s=n.attributes,a=n.uniforms;i.activate(),r.disable(r.CULL_FACE),r.uniform1f(a.depthOffset,this._handler._entityCollection.polygonOffsetUnits),r.uniformMatrix4fv(a.proj,!1,t.activeCamera.getProjectionMatrix()),r.uniformMatrix4fv(a.view,!1,t.activeCamera.getViewMatrix()),r.uniform4fv(a.color,[this._pickingColor[0],this._pickingColor[1],this._pickingColor[2],1]),r.uniform3fv(a.eyePositionHigh,t.activeCamera.eyeHigh),r.uniform3fv(a.eyePositionLow,t.activeCamera.eyeLow),r.uniform2fv(a.uFloatParams,[e._planetRadius2||0,t.activeCamera._tanViewAngle_hradOneByHeight]),r.uniform2fv(a.viewport,[t.handler.canvas.width,t.handler.canvas.height]),r.uniform1f(a.thickness,.5*this.thickness);let o=this._verticesHighBuffer;r.bindBuffer(r.ARRAY_BUFFER,o),r.vertexAttribPointer(s.prevHigh,o.itemSize,r.FLOAT,!1,12,0),r.vertexAttribPointer(s.currentHigh,o.itemSize,r.FLOAT,!1,12,48),r.vertexAttribPointer(s.nextHigh,o.itemSize,r.FLOAT,!1,12,96),o=this._verticesLowBuffer,r.bindBuffer(r.ARRAY_BUFFER,o),r.vertexAttribPointer(s.prevLow,o.itemSize,r.FLOAT,!1,12,0),r.vertexAttribPointer(s.currentLow,o.itemSize,r.FLOAT,!1,12,48),r.vertexAttribPointer(s.nextLow,o.itemSize,r.FLOAT,!1,12,96),r.bindBuffer(r.ARRAY_BUFFER,this._ordersBuffer),r.vertexAttribPointer(s.order,this._ordersBuffer.itemSize,r.FLOAT,!1,4,0),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),r.drawElements(r.TRIANGLE_STRIP,this._indexesBuffer.numItems,r.UNSIGNED_INT,0),r.enable(r.CULL_FACE)}}_refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_update(){if(this._renderNode){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}_deleteBuffers(){if(this._renderNode){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer),e.deleteBuffer(this._ordersBuffer),e.deleteBuffer(this._indexesBuffer),e.deleteBuffer(this._colorsBuffer),this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null}}_createVerticesBuffer(){let e=this._renderNode.renderer.handler,t=this._verticesHigh.length/3;this._verticesHighBuffer&&this._verticesHighBuffer.numItems===t||(e.gl.deleteBuffer(this._verticesHighBuffer),e.gl.deleteBuffer(this._verticesLowBuffer),this._verticesHighBuffer=e.createStreamArrayBuffer(3,t),this._verticesLowBuffer=e.createStreamArrayBuffer(3,t)),this._verticesHigh=Oe(this._verticesHigh),this._verticesLow=Oe(this._verticesLow),e.setStreamArrayBuffer(this._verticesHighBuffer,this._verticesHigh),e.setStreamArrayBuffer(this._verticesLowBuffer,this._verticesLow)}_createIndexBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._ordersBuffer),e.gl.deleteBuffer(this._indexesBuffer),this._orders=Oe(this._orders),this._ordersBuffer=e.createArrayBuffer(this._orders,1,this._orders.length/2),this._indexes=Oe(this._indexes,Uint32Array),this._indexesBuffer=e.createElementArrayBuffer(this._indexes,1,this._indexes.length)}_createColorsBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._colorsBuffer),this._colors=Oe(this._colors),this._colorsBuffer=e.createArrayBuffer(new Float32Array(this._colors),4,this._colors.length/4)}}bi.__counter__=0;class wi{constructor(e={}){this.__id=wi.__counter__++,this._thickness=e.thickness||2,this._startPosition=Ae(e.startPosition),this._startPositionHigh=new oe,this._startPositionLow=new oe,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._endPosition=Ae(e.endPosition),this._endPositionHigh=new oe,this._endPositionLow=new oe,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._startColor=Ee(e.startColor),this._endColor=Ee(e.endColor),this._visibility=null==e.visibility||e.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1}setStartPosition(e,t,i){this._startPosition.x=e,this._startPosition.y=t,this._startPosition.z=i,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._handler&&this._handler.setStartPositionArr(this._handlerIndex,this._startPositionHigh,this._startPositionLow)}getLength(){return this._startPosition.distance(this._endPosition)}setStartPosition3v(e){this._startPosition.x=e.x,this._startPosition.y=e.y,this._startPosition.z=e.z,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._handler&&this._handler.setStartPositionArr(this._handlerIndex,this._startPositionHigh,this._startPositionLow)}setEndPosition(e,t,i){this._endPosition.x=e,this._endPosition.y=t,this._endPosition.z=i,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._handler&&this._handler.setEndPositionArr(this._handlerIndex,this._endPositionHigh,this._endPositionLow)}setEndPosition3v(e){this._endPosition.x=e.x,this._endPosition.y=e.y,this._endPosition.z=e.z,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._handler&&this._handler.setEndPositionArr(this._handlerIndex,this._endPositionHigh,this._endPositionLow)}setThickness(e){this._thickness=e,this._handler&&this._handler.setThicknessArr(this._handlerIndex,e)}setColors4v(e,t){e&&(this._startColor.x=e.x,this._startColor.y=e.y,this._startColor.z=e.z,this._startColor.w=e.w),t&&(this._endColor.x=t.x,this._endColor.y=t.y,this._endColor.z=t.z,this._endColor.w=t.w),this._handler&&this._handler.setRgbaArr(this._handlerIndex,this._startColor,this._endColor)}setColorsHTML(e,t){e&&(this._startColor=ve(e)),t&&(this._endColor=ve(t)),this._handler&&this._handler.setRgbaArr(this._handlerIndex,this._startColor,this._endColor)}getStartPosition(){return this._startPosition}getEndPosition(){return this._endPosition}setVisibility(e){this._visibility=e,this._handler&&this._handler.setVisibility(this._handlerIndex,e)}getVisibility(){return this._visibility}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._handler&&this._handler.setPickingColorArr(this._handlerIndex,e)}}wi.__counter__=0;let Ci=new oe,Ti=new oe;class Li{constructor(e={}){if(this.__id=Li.__counter__++,this.visibility=null==e.visibility||e.visibility,this.color=new Float32Array([1,1,1,.5]),e.color){let t=Ee(e.color);this.setColor(t.x,t.y,t.z,t.w)}e.opacity&&this.setOpacity(e.opacity),this._renderNode=null,this._entity=null,this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._indexBuffer=null,this._verticesHigh=[],this._verticesLow=[],this._indexes=[],this._path=[],this._pickingColor=new Float32Array(4),this._gridSize=1,this._handler=null,this._handlerIndex=-1,e.path&&this.setPath(e.path)}setPickingColor3v(e){this._pickingColor[0]=e.x/255,this._pickingColor[1]=e.y/255,this._pickingColor[2]=e.z/255,this._pickingColor[3]=1}clear(){this._path.length=0,this._path=[],this._verticesHigh.length=0,this._verticesHigh=[],this._verticesLow.length=0,this._verticesLow=[],this._indexes.length=0,this._indexes=[],this._deleteBuffers()}setColor4v(e){this.setColor(e.x,e.y,e.z,e.w)}setColorHTML(e){this.setColor4v(ve(e))}setColor(e,t,i,n){n=n||this.color[3],this.color[0]=e,this.color[1]=t,this.color[2]=i,this.color[3]=n}setOpacity(e){this.color[3]=e||0}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){this._renderNode=e,this._createBuffers()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}draw(){if(this.visibility&&this._verticesHigh.length){let e=this._renderNode.renderer,t=e.handler.gl,i=e.handler.programs.strip,n=i._program,r=n.attributes,s=n.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(s.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(s.eyePositionLow,e.activeCamera.eyeLow),t.uniform4fv(s.uColor,this.color),t.uniform1f(s.uOpacity,this._entity._entityCollection._fadingOpacity),t.bindBuffer(t.ARRAY_BUFFER,this._verticesHighBuffer),t.vertexAttribPointer(r.aVertexPositionHigh,this._verticesHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._verticesLowBuffer),t.vertexAttribPointer(r.aVertexPositionLow,this._verticesLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indexBuffer),t.drawElements(e.handler.gl.TRIANGLE_STRIP,this._indexBuffer.numItems,t.UNSIGNED_INT,0),t.enable(t.CULL_FACE)}}drawPicking(){if(this.visibility&&this._verticesHigh.length){let e=this._renderNode.renderer,t=e.handler.gl,i=e.handler.programs.strip,n=i._program,r=n.attributes,s=n.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(s.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(s.eyePositionLow,e.activeCamera.eyeLow),t.uniform1f(s.uOpacity,0!=this._entity._entityCollection._fadingOpacity?1:0),t.uniform4fv(s.uColor,this._pickingColor),t.bindBuffer(t.ARRAY_BUFFER,this._verticesHighBuffer),t.vertexAttribPointer(r.aVertexPositionHigh,this._verticesHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._verticesLowBuffer),t.vertexAttribPointer(r.aVertexPositionLow,this._verticesLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indexBuffer),t.drawElements(e.handler.gl.TRIANGLE_STRIP,this._indexBuffer.numItems,t.UNSIGNED_INT,0),t.enable(t.CULL_FACE)}}_deleteBuffers(){if(this._renderNode&&this._renderNode.renderer){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._indexBuffer),e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer)}this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._indexBuffer=null}_createBuffers(){if(this._renderNode&&this._renderNode.renderer&&this._renderNode.renderer.isInitialized()){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._indexBuffer),e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer),this._verticesHighBuffer=this._renderNode.renderer.handler.createArrayBuffer(new Float32Array(this._verticesHigh),3,this._verticesHigh.length/3),this._verticesLowBuffer=this._renderNode.renderer.handler.createArrayBuffer(new Float32Array(this._verticesLow),3,this._verticesLow.length/3),this._indexBuffer=this._renderNode.renderer.handler.createElementArrayBuffer(new Uint32Array(this._indexes),1,this._indexes.length)}}addEdge3v(e,t){let i=this._path.length;if(0===i)this._path.push([e.clone(),t.clone()]);else{let n=this._path[i-1][0],r=this._path[i-1][1];this._path.push([e.clone(),t.clone()]);let s=this._verticesHigh,a=this._verticesLow,o=this._gridSize,l=o+1,h=new oe,c=this._verticesHigh.length/3,d=c,_=Math.abs(n.sub(r).normal().dot(e.sub(n).normal()));for(let i=0;i<l;i++){let u=i/o,f=n.lerp(e,u),g=r.lerp(t,u);for(let u=0;u<l;u++){let p=u/o,m=n.lerp(r,p),v=e.lerp(t,p);1!==_?new ci(f,g).intersects(new ci(m,v),h):h=v,d=c+i*l+u,oe.doubleToTwoFloats(h,Ci,Ti);let y=3*d;s[y]=Ci.x,s[y+1]=Ci.y,s[y+2]=Ci.z,a[y]=Ti.x,a[y+1]=Ti.y,a[y+2]=Ti.z,i<o&&this._indexes.push(d,d+l)}i<o&&this._indexes.push(d+l,d+1)}this._createBuffers()}}setEdge3v(e,t,i){if(i!==this._path.length)if(this._path[i]){if(this._path[i][0]=e,this._path[i][1]=t,this._path.length>1){let n=this._gridSize,r=n+1,s=r*r,a=new oe,o=this._verticesHigh,l=this._verticesLow;if(i===this._path.length-1){let h=this._path[i-1][0],c=this._path[i-1][1],d=this._verticesHigh.length/3-s,_=d,u=Math.abs(h.sub(c).normal().dot(e.sub(h).normal()));for(let i=0;i<r;i++){let s=i/n,f=h.lerp(e,s),g=c.lerp(t,s);for(let s=0;s<r;s++){let p=s/n,m=h.lerp(c,p),v=e.lerp(t,p);1!==u?new ci(f,g).intersects(new ci(m,v),a):a=v,_=d+i*r+s,oe.doubleToTwoFloats(a,Ci,Ti);let y=3*_;o[y]=Ci.x,o[y+1]=Ci.y,o[y+2]=Ci.z,l[y]=Ti.x,l[y+1]=Ti.y,l[y+2]=Ti.z}}}else if(0===i){let i=0,s=e,h=t;e=this._path[1][0],t=this._path[1][1];for(let c=0;c<r;c++){let d=c/n,_=s.lerp(e,d),u=h.lerp(t,d);for(let d=0;d<r;d++){let f=d/n,g=s.lerp(h,f),p=e.lerp(t,f);new ci(_,u).intersects(new ci(g,p),a),i=c*r+d,oe.doubleToTwoFloats(a,Ci,Ti);let m=3*i;o[m]=Ci.x,o[m+1]=Ci.y,o[m+2]=Ci.z,l[m]=Ti.x,l[m+1]=Ti.y,l[m+2]=Ti.z}}}else if(i>0&&i<this._path.length){let h=this._path[i-1][0],c=this._path[i-1][1],d=this._path[i+1][0],_=this._path[i+1][1],u=i*s,f=(i-1)*s,g=f;for(let i=0;i<r;i++){let s=i/n,p=h.lerp(e,s),m=t.lerp(_,s),v=e.lerp(d,s),y=c.lerp(t,s);for(let s=0;s<r;s++){let x=s/n,b=h.lerp(c,x),w=e.lerp(t,x);new ci(p,y).intersects(new ci(b,w),a);let C=i*r+s;g=f+C,oe.doubleToTwoFloats(a,Ci,Ti);let T=3*g;o[T]=Ci.x,o[T+1]=Ci.y,o[T+2]=Ci.z,l[T]=Ti.x,l[T+1]=Ti.y,l[T+2]=Ti.z;let L=d.lerp(_,x);w=e.lerp(t,x),new ci(v,m).intersects(new ci(w,L),a),g=u+C,oe.doubleToTwoFloats(a,Ci,Ti),T=3*g,o[T]=Ci.x,o[T+1]=Ci.y,o[T+2]=Ci.z,l[T]=Ti.x,l[T+1]=Ti.y,l[T+2]=Ti.z}}}this._createBuffers()}}else console.warn(`strip index ${i} is out of range`);else this.addEdge3v(e,t)}removeEdge(e){this._path.splice(e,1),this.setPath([].concat(this._path))}setGridSize(e){this._gridSize=e,this.setPath([].concat(this._path))}getPath(){return this._path}setPath(e){this._verticesHigh=[],this._verticesLow=[],this._indexes=[],this._path=[];for(let t=0;t<e.length;t++){let i=e[t][0],n=e[t][1];i instanceof Array&&(i=new oe(i[0],i[1],i[2])),n instanceof Array&&(n=new oe(n[0],n[1],n[2])),this.addEdge3v(i,n)}}insertEdge3v(e,t,i){if(i<this._path.length){let n=[].concat(this._path);n.splice(i,0,[e,t]),this.setPath(n)}else i===this._path.length&&this.addEdge3v(e,t)}}Li.__counter__=0;class Ai{constructor(e={}){e.properties=e.properties||{},this.__id=Ai.__counter__++,this.properties=e.properties||{},this.properties.name=null!=this.properties.name?this.properties.name:"",this.childrenNodes=[],this.parent=null,this._cartesian=Ae(e.cartesian),this._lonLat=Me(e.lonlat),this._lonLatMerc=new z,this._altitude=e.altitude||0,this._visibility=null==e.visibility||e.visibility,this._entityCollection=null,this._entityCollectionIndex=-1,this._layer=null,this._layerIndex=-1,this._pickingColor=new oe(0,0,0),this._featureConstructorArray={billboard:[si,this.setBillboard],label:[yi,this.setLabel],polyline:[bi,this.setPolyline],pointCloud:[xi,this.setPointCloud],geometry:[li,this.setGeometry],geoObject:[pi,this.setGeoObject],strip:[Li,this.setStrip],ray:[wi,this.setRay]},this.billboard=this._createOptionFeature("billboard",e.billboard),this.label=this._createOptionFeature("label",e.label),this.polyline=this._createOptionFeature("polyline",e.polyline),this.ray=this._createOptionFeature("ray",e.ray),this.pointCloud=this._createOptionFeature("pointCloud",e.pointCloud),this.geometry=this._createOptionFeature("geometry",e.geometry),this.geoObject=this._createOptionFeature("geoObject",e.geoObject),this.strip=this._createOptionFeature("strip",e.strip)}get id(){return this.__id}isEqual(e){return this.__id===e.__id}get layerIndex(){return this._layerIndex}get instanceName(){return"Entity"}_createOptionFeature(e,t){if(t){let i=this._featureConstructorArray[e];return i[1].call(this,new i[0](t))}return null}getCollectionIndex(){return this._entityCollectionIndex}addTo(e,t=!1){return e.add(this,t),this}remove(){this._layer&&this._layer.removeEntity(this),this._entityCollection&&this._entityCollection.removeEntity(this)}setVisibility(e){this._visibility=e,this.billboard&&this.billboard.setVisibility(e),this.geoObject&&this.geoObject.setVisibility(e),this.label&&this.label.setVisibility(e),this.polyline&&this.polyline.setVisibility(e),this.ray&&this.ray.setVisibility(e),this.geometry&&this.geometry.setVisibility(e);for(let t=0;t<this.childrenNodes.length;t++)this.childrenNodes[t].setVisibility(e)}getVisibility(){return this._visibility}setCartesian3v(e){this.setCartesian(e.x,e.y,e.z)}setCartesian(e,t,i){let n=this._cartesian;n.x=e||0,n.y=t||0,n.z=i||0,this.billboard&&this.billboard.setPosition3v(n),this.geoObject&&this.geoObject.setPosition3v(n),this.label&&this.label.setPosition3v(n);for(let n=0;n<this.childrenNodes.length;n++)this.childrenNodes[n].setCartesian(e,t,i);let r=this._entityCollection;r&&r.renderNode&&r.renderNode.ellipsoid&&(this._lonLat=r.renderNode.ellipsoid.cartesianToLonLat(n),Math.abs(this._lonLat.lat)<J?this._lonLatMerc=this._lonLat.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=this._lonLatMerc.height=0)}_setCartesian3vSilent(e,t=!1){let i=this._cartesian;i.x=e.x||0,i.y=e.y||0,i.z=e.z||0,this.billboard&&this.billboard.setPosition3v(i),this.geoObject&&this.geoObject.setPosition3v(i),this.label&&this.label.setPosition3v(i);for(let e=0;e<this.childrenNodes.length;e++)this.childrenNodes[e].setCartesian(i.x,i.y,i.z);let n=this._entityCollection;!t&&n&&n.renderNode&&n.renderNode.ellipsoid&&(this._lonLat=n.renderNode.ellipsoid.cartesianToLonLat(i),Math.abs(this._lonLat.lat)<J&&(this._lonLatMerc=this._lonLat.forwardMercator()))}getLonLat(){return this._lonLat.clone()}setLonLat(e){let t=this._lonLat;t.lon=e.lon,t.lat=e.lat,t.height=e.height;let i=this._entityCollection;i&&i.renderNode&&i.renderNode.ellipsoid&&(Math.abs(t.lat)<J&&(this._lonLatMerc=t.forwardMercator()),i.renderNode.ellipsoid.lonLatToCartesianRes(t,this._cartesian),this.setCartesian3v(this._cartesian))}setLonLat2(e,t,i){let n=this._lonLat;n.lon=e,n.lat=t,n.height=null!=i?i:n.height;let r=this._entityCollection;r&&r.renderNode&&r.renderNode.ellipsoid&&(Math.abs(n.lat)<J?this._lonLatMerc=n.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=this._lonLatMerc.height=0,r.renderNode.ellipsoid.lonLatToCartesianRes(n,this._cartesian),this.setCartesian3v(this._cartesian))}setAltitude(e){this._altitude=e}getAltitude(){return this._altitude}getCartesian(){return this._cartesian.clone()}setBillboard(e){return this.billboard&&this.billboard.remove(),this.billboard=e,this.billboard._entity=this,this.billboard.setPosition3v(this._cartesian),this.billboard.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.billboardHandler.add(e),e}setLabel(e){return this.label&&this.label.remove(),this.label=e,this.label._entity=this,this.label.setPosition3v(this._cartesian),this.label.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.labelHandler.add(e),e}setRay(e){return this.ray&&this.ray.remove(),this.ray=e,this.ray._entity=this,this.ray.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.rayHandler.add(e),e}setPolyline(e){return this.polyline&&this.polyline.remove(),this.polyline=e,this.polyline._entity=this,this.polyline.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.polylineHandler.add(e),e}setPointCloud(e){return this.pointCloud&&this.pointCloud.remove(),this.pointCloud=e,this.pointCloud._entity=this,this.pointCloud.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.pointCloudHandler.add(e),e}setGeometry(e){this.geometry&&this.geometry.remove(),this.geometry=e,this.geometry._entity=this,this.geometry.setVisibility(this._visibility);let t=this._layer;return this._layer&&this._layer.removeEntity(this),t&&t.add(this),e}setGeoObject(e){return this.geoObject&&this.geoObject.remove(),this.geoObject=e,this.geoObject._entity=this,this.geoObject.setPosition3v(this._cartesian),this.geoObject.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.geoObjectHandler.add(e),e}setStrip(e){return this.strip&&this.strip.remove(),this.strip=e,this.strip._entity=this,this.strip.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.stripHandler.add(e),e}get layer(){return this._layer}get rendererEvents(){return this._layer?this._layer.events:this._entityCollection?this._entityCollection.events:null}appendChild(e){e._entityCollection=this._entityCollection,e._pickingColor=this._pickingColor,e.parent=this,this.childrenNodes.push(e),this._entityCollection&&this._entityCollection.appendChildEntity(e)}setPickingColor(){let e=this._pickingColor;this.billboard&&this.billboard.setPickingColor3v(e),this.label&&this.label.setPickingColor3v(e),this.polyline&&this.polyline.setPickingColor3v(e),this.ray&&this.ray.setPickingColor3v(e),this.strip&&this.strip.setPickingColor3v(e),this.geoObject&&this.geoObject.setPickingColor3v(e);for(let e=0;e<this.childrenNodes.length;e++)this.childrenNodes[e].setPickingColor()}getExtent(){let e,t=this._lonLat;e=this.billboard||this.label?new ie(new z(t.lon,t.lat),new z(t.lon,t.lat)):new ie(new z(180,90),new z(-180,-90));let i=e.southWest,n=e.northEast;if(this.polyline){let e=this.polyline.getExtent();e.southWest.lon<i.lon&&(i.lon=e.southWest.lon),e.southWest.lat<i.lat&&(i.lat=e.southWest.lat),e.northEast.lon>n.lon&&(n.lon=e.northEast.lon),e.northEast.lat>n.lat&&(n.lat=e.northEast.lat)}if(this.geometry){let e=this.geometry.getExtent();e.southWest.lon<i.lon&&(i.lon=e.southWest.lon),e.southWest.lat<i.lat&&(i.lat=e.southWest.lat),e.northEast.lon>n.lon&&(n.lon=e.northEast.lon),e.northEast.lat>n.lat&&(n.lat=e.northEast.lat)}for(let e=0;e<this.childrenNodes.length;e++){let t=this.childrenNodes[e].getExtent();t.southWest.lon<i.lon&&(i.lon=t.southWest.lon),t.southWest.lat<i.lat&&(i.lat=t.southWest.lat),t.northEast.lon>n.lon&&(n.lon=t.northEast.lon),t.northEast.lat>n.lat&&(n.lat=t.northEast.lat)}return e}}Ai.__counter__=0;class Ei{constructor(e){this.__id=Ei.__counter__++,this._name=e||`nonameNode:${this.__id}`,this.topNode=this,this._dictionary={},this._dictionary[this._name]=this,this.childNodes=[],this.parentNode=null}get name(){return this._name}addNode(e){null==this.parentNode?e.topNode=this:e.topNode=this.topNode,e.parentNode=this,e._dictionary=this.topNode._dictionary,this.childNodes.push(e),this.topNode._dictionary[e.name]=e}destroy(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e].destroy();this._clear()}getNodeByName(e){return this._dictionary[e]}_clear(){this.parentNode=null,this.topNode=this,this.childNodes.length=0}isEqual(e){return e.__id===this.__id}}Ei.__counter__=0;class Pi extends Ei{constructor(e){super(e),this.childNodes=[],this.renderer=null,this.drawMode=0,this.show=!0,this._isActive=!0,this.lightEnabled=!1,this._lights=[],this._lightsNames=[],this._lightsPositions=[],this._lightsParamsv=[],this._lightsParamsf=[],this.entityCollections=[],this._pickingId=-1}addNode(e){super.addNode(e),this.renderer&&e.assign(this.renderer)}assign(e){this.renderer=e,this._pickingId=e.addPickingCallback(this,this._entityCollectionPickingCallback),this.initialize()}initialize(){if(this.renderer&&this.renderer.isInitialized()){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].bindRenderNode(this);this.init()}}init(){}onremove(){}remove(){let e=this.renderer,t=this.name;if(e){e.renderNodes[t]&&e.renderNodes[t].isEqual(this)&&(e.renderNodes[t]=null,delete e.renderNodes[t]);for(let t=0;t<e._renderNodesArr.length;t++)if(e._renderNodesArr[t].isEqual(this)){e._renderNodesArr.splice(t,1);break}e.removePickingCallback(this._pickingId),this._pickingId=-1,this.onremove&&this.onremove()}}addEntityCollection(e,t){return e.addTo(this,t),this}removeEntityCollection(e){e.remove()}addLight(e){return e.addTo(this),this}getLightByName(e){let t=this._lightsNames.indexOf(e);return this._lights[t]}removeLight(e){e.remove()}preDrawNode(){this._isActive&&this._preDrawNodes()}drawNode(){this._isActive&&this._drawNodes()}isActive(){return this._isActive}setActive(e){this._isActive=e,this.renderer&&(this._isActive&&-1===this._pickingId?this._pickingId=this.renderer.addPickingCallback(this,this._entityCollectionPickingCallback):this._isActive||-1===this._pickingId||(this.renderer.removePickingCallback(this._pickingId),this._pickingId=-1));for(let t=0;t<this.childNodes.length;t++)this.childNodes[t].setActive(e)}setDrawMode(e){this.drawMode=e;for(let t=0;t<this.childNodes.length;t++)this.childNodes[t].setDrawMode(e)}transformLights(){for(let e=0;e<this._lights.length;e++){let t,i=3*e;t=this._lights[e]._position,this._lightsPositions[i]=t.x,this._lightsPositions[i+1]=t.y,this._lightsPositions[i+2]=t.z}}updateBillboardsTexCoords(){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].billboardHandler.refreshTexCoordsArr()}frame(){}preFrame(){}_preDrawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._preDrawNodes();this.show&&(this.preFrame(),this.drawEntityCollections(this.entityCollections))}_drawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._drawNodes();this.show&&this.frame()}drawEntityCollections(e){this.renderer.enqueueEntityCollectionsToDraw(e)}drawPickingEntityCollections(e){if(e.length){let t=e.length;for(;t--;)e[t]._fadingOpacity&&e[t].billboardHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].geoObjectHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].labelHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].rayHandler.drawPicking();for(t=e.length;t--;)e[t]._visibility&&e[t].polylineHandler.drawPicking();for(t=e.length;t--;)e[t]._visibility&&e[t].stripHandler.drawPicking()}}_entityCollectionPickingCallback(){this.drawPickingEntityCollections(this.entityCollections)}}const Si=new class{constructor(){this._container=document.createElement("div"),this._container.classList.add("ogConsole"),this._container.style.display="none",document.body&&document.body.appendChild(this._container),this._visibility=!1}getVisibility(){return this._visibility}setVisibility(e){this._visibility!=e&&(this._visibility=e,this._visibility?this.show():this.hide())}show(){this._container.parentNode||document.body&&document.body.appendChild(this._container),this._container.style.display="block",this._visibility=!0}hide(){this._container.style.display="none",this._visibility=!1}logErr(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.classList.add("ogConsole-error"),t.innerHTML="error: "+e,console.trace(t.innerHTML),this._container.appendChild(t),this.show()}logWrn(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.classList.add("ogConsole-warning"),t.innerHTML="warning: "+e,console.trace(t.innerHTML),this._container.appendChild(t),this.show()}log(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.innerHTML=e,console.trace(e),this._container.appendChild(t),this.show()}};let Mi=["FLOAT","DOUBLE","BOOL","INT","UINT","VEC2","VEC3","VEC4","DVEC2","DVEC3","DVEC4","BVEC2","BVEC3","BVEC4","IVEC2","IVEC3","IVEC4","UVEC2","UVEC3","UVEC4","MAT2","DMAT2","MAT3","DMAT3","MAT4","DMAT4","MAT2X3","MAT2X4","MAT3X2","MAT3X4","MAT4X2","MAT4X3","DMAT2X3","DMAT2X4","DMAT3X2","DMAT3X4","DMAT4X2","DMAT4X3","SAMPLER1D","SAMPLER2D","SAMPLER3D","SAMPLERCUBE","SAMPLER2DSHADOW","SAMPLER2DARRAY","INTXX","FLOATXX"];const Bi={};for(let e=0;e<Mi.length;e++)Bi[Mi[e]]=e;const ki={};for(let e=0;e<Mi.length;e++)ki[Mi[e].toLowerCase()]=Bi[Mi[e]];const Ri={u:[],a:[]};Ri.u[Bi.MAT4]=function(e,t){e.gl.uniformMatrix4fv(t._pName,!1,t.value)},Ri.u[Bi.MAT3]=function(e,t){e.gl.uniformMatrix3fv(t._pName,!1,t.value)},Ri.u[Bi.FLOAT]=function(e,t){e.gl.uniform1f(t._pName,t.value)},Ri.u[Bi.INT]=function(e,t){e.gl.uniform1i(t._pName,t.value)},Ri.u[Bi.VEC2]=function(e,t){e.gl.uniform2fv(t._pName,t.value)},Ri.u[Bi.VEC3]=function(e,t){e.gl.uniform3fv(t._pName,t.value)},Ri.u[Bi.VEC4]=function(e,t){e.gl.uniform4fv(t._pName,t.value)},Ri.u[Bi.SAMPLER2D]=function(e,t){let i=e.gl;i.activeTexture(i.TEXTURE0+e._textureID),i.bindTexture(i.TEXTURE_2D,t.value),i.uniform1i(t._pName,e._textureID),e._textureID++},Ri.u[Bi.SAMPLERCUBE]=function(e,t){let i=e.gl;i.activeTexture(i.TEXTURE0+e._textureID),i.bindTexture(i.TEXTURE_CUBE_MAP,t.value),i.uniform1i(t._pName,e._textureID),e._textureID++},Ri.u[Bi.SAMPLER2DARRAY]=function(e,t){let i=t.value,n=e.gl,r=i.length,s=new Int32Array(r);for(let t=0;t<r;t++)n.activeTexture(n.TEXTURE0+e._textureID+t),n.bindTexture(n.TEXTURE_2D,i[t]),s[t]=t;n.uniform1iv(t._pName,s)},Ri.u[Bi.INTXX]=function(e,t){e.gl.uniform1iv(t._pName,t.value)},Ri.u[Bi.FLOATXX]=function(e,t){e.gl.uniform1fv(t._pName,t.value)},Ri.a[Bi.FLOAT]=function(e,t){e.gl.vertexAttrib1f(t._pName,t.value)},Ri.a[Bi.VEC2]=function(e,t){e.gl.vertexAttrib2fv(t._pName,t.value)},Ri.a[Bi.VEC3]=function(e,t){e.gl.vertexAttrib3fv(t._pName,t.value)};const Ii=["BYTE","SHORT","UNSIGNED_BYTE","UNSIGNED_SHORT","FLOAT","HALF_FLOAT"];class zi{constructor(e,t){this.name=e,this._attributes={};for(let e in t.attributes)"string"==typeof t.attributes[e]||"number"==typeof t.attributes[e]?this._attributes[e]={type:t.attributes[e]}:this._attributes[e]=t.attributes[e];this._uniforms={};for(let e in t.uniforms)"string"==typeof t.uniforms[e]||"number"==typeof t.uniforms[e]?this._uniforms[e]={type:t.uniforms[e]}:this._uniforms[e]=t.uniforms[e];this.vertexShader=t.vertexShader,this.fragmentShader=t.fragmentShader,this.gl=null,this._variables={},this._p=null,this._textureID=0,this._attribArrays=[],this._attribDivisor=[],this.attributes={},this.uniforms={},this.vertexAttribDivisor=null,this.drawElementsInstanced=null}static bindBuffer(e,t){let i=e.gl;i&&(i.bindBuffer(i.ARRAY_BUFFER,t.value),i.vertexAttribPointer(t._pName,t.value.itemSize,t.itemType,t.normalized,0,0))}use(){this.gl&&this.gl.useProgram(this._p)}set(e){this._textureID=0;for(let t in e)this._variables[t].value=e[t],this._variables[t].func(this,this._variables[t])}apply(){this._textureID=0;let e=this._variables;for(let t in e)e[t].func(this,e[t])}drawIndexBuffer(e,t){let i=this.gl;i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,t),i.drawElements(e,t.numItems,i.UNSIGNED_SHORT,0)}drawArrays(e,t){this.gl.drawArrays(e,0,t)}_getShaderCompileStatus(e,t){return!!this.gl&&(this.gl.shaderSource(e,t),this.gl.compileShader(e),!!this.gl.getShaderParameter(e,this.gl.COMPILE_STATUS)||(Si.logErr(`Shader program "${this.name}":${this.gl.getShaderInfoLog(e)}.`),!1))}_createVertexShader(e){if(!this.gl)return;let t=this.gl.createShader(this.gl.VERTEX_SHADER);return t&&this._getShaderCompileStatus(t,e)?t:void 0}_createFragmentShader(e){if(!this.gl)return;let t=this.gl.createShader(this.gl.FRAGMENT_SHADER);return t&&this._getShaderCompileStatus(t,e)?t:void 0}disableAttribArrays(){let e=this.gl,t=this._attribArrays;for(let i=0,n=t.length;i<n;i++)e.disableVertexAttribArray(t[i]),this.vertexAttribDivisor(t[i],0)}enableAttribArrays(){let e=this.gl,t=this._attribArrays,i=this._attribDivisor;for(let n=0,r=t.length;n<r;n++)e.enableVertexAttribArray(t[n]),this.vertexAttribDivisor(t[n],i[n])}delete(){this.gl&&this.gl.deleteProgram(this._p)}createProgram(e){if(this.gl=e,this._p=this.gl.createProgram(),!this._p)return;let t=this._createFragmentShader(this.fragmentShader),i=this._createVertexShader(this.vertexShader);if(t&&i){if(e.attachShader(this._p,t),e.attachShader(this._p,i),e.linkProgram(this._p),!this.drawElementsInstanced)if(e.drawElementsInstanced)this.drawElementsInstanced=e.drawElementsInstanced.bind(e);else{let t=e.getExtension("ANGLE_instanced_arrays");t&&(this.drawElementsInstanced=t.drawElementsInstancedANGLE.bind(t))}if(!this.vertexAttribDivisor)if(e.vertexAttribDivisor)this.vertexAttribDivisor=e.vertexAttribDivisor.bind(e);else{let t=e.getExtension("ANGLE_instanced_arrays");t&&(this.vertexAttribDivisor=t.vertexAttribDivisorANGLE.bind(t))}if(!e.getProgramParameter(this._p,e.LINK_STATUS))return Si.logErr(`Shader program "${this.name}": initialization failed. ${e.getProgramInfoLog(this._p)}.`),void e.deleteProgram(this._p);this.use();for(let t in this._attributes){this._variables[t]=this._attributes[t],this._attributes[t].func=zi.bindBuffer;let i=this._attributes[t].itemType,n=i?i.trim().toUpperCase():"FLOAT";if(-1==Ii.indexOf(n)?(Si.logErr(`Shader program "${this.name}": attribute '${t}', item type '${this._attributes[t].itemType}' not exists.`),this._attributes[t].itemType=e.FLOAT):this._attributes[t].itemType=e[n],this._attributes[t].normalized=this._attributes[t].normalized||!1,this._attributes[t].divisor=this._attributes[t].divisor||0,this._p[t]=e.getAttribLocation(this._p,t),null==this._p[t])return Si.logErr(`Shader program "${this.name}": attribute '${t}' not exists.`),void e.deleteProgram(this._p);let r=this._attributes[t].type;"string"==typeof r&&(r=ki[r.trim().toLowerCase()]);let s=this._attributes[t].divisor;if(r===Bi.MAT4){let e=this._p[t];this._attribArrays.push(e,e+1,e+2,e+3),this._attribDivisor.push(s,s,s,s)}else this._attribArrays.push(this._p[t]),this._attribDivisor.push(s);e.enableVertexAttribArray(this._p[t]),this._attributes[t]._pName=this._p[t],this.attributes[t]=this._p[t]}for(let t in this._uniforms){if("string"==typeof this._uniforms[t].type){let e=this._uniforms[t].type;this._uniforms[t].func=Ri.u[ki[e.trim().toLowerCase()]]}else this._uniforms[t].func=Ri.u[this._uniforms[t].type];if(this._variables[t]=this._uniforms[t],this._p[t]=e.getUniformLocation(this._p,t),null==this._p[t])return Si.logErr(`Shader program "${this.name}": uniform '${t}' not exists.`),void e.deleteProgram(this._p);this._uniforms[t]._pName=this._p[t],this.uniforms[t]=this._p[t]}e.detachShader(this._p,t),e.detachShader(this._p,i),e.deleteShader(t),e.deleteShader(i)}}}const Di="vec2 project(vec4 p) {\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }",Fi="mat2 rotate2d(float angle) {\n return mat2(cos(angle), -sin(angle),\n sin(angle), cos(angle));\n }";class Ni{constructor(e){this.__id=Ni.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._billboards=[],this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._texCoordBuffer=null,this._vertexBuffer=null,this._pickingColorBuffer=null,this._texCoordArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._pickingColorArr=new Float32Array([]),this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this.createPickingColorBuffer,this._buffersUpdateCallbacks[1]=this.createPositionBuffer,this._buffersUpdateCallbacks[2]=this.createSizeBuffer,this._buffersUpdateCallbacks[3]=this.createOffsetBuffer,this._buffersUpdateCallbacks[4]=this.createRgbaBuffer,this._buffersUpdateCallbacks[5]=this.createRotationBuffer,this._buffersUpdateCallbacks[6]=this.createTexCoordBuffer,this._buffersUpdateCallbacks[7]=this.createVertexBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}isEqual(e){return e&&e.__id===this.__id}static concArr(e,t){for(let i=0;i<t.length;i++)e.push(t[i])}initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.billboard||this._renderer.handler.addProgram(new zi("billboard",{uniforms:{viewport:"vec2",u_texture:"sampler2d",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",uScaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_vertices:"vec2",a_texCoord:"vec2",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"vec2",a_rotation:"float",a_rgba:"vec4"},vertexShader:`precision highp float;\n attribute vec2 a_vertices;\n attribute vec2 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute vec2 a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec2 v_texCoords;\n varying vec4 v_rgba;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform float opacity;\n uniform float planetRadius;\n uniform vec2 viewport;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Di}\n\n ${Fi}\n\n void main() {\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_texCoords = a_texCoord;\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgba = a_rgba;\n\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n //vec3 up = vec3( viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1] );\n //vec3 right = vec3( viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0] );\n\n float scd = (1.0 - smoothstep(uScaleByDistance[0], uScaleByDistance[1], lookDist)) * (1.0 - step(uScaleByDistance[2], lookDist));\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02;\n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n\n vec2 v = screenPos + rotate2d(a_rotation) * (a_vertices * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n uniform sampler2D u_texture;\n varying vec2 v_texCoords;\n varying vec4 v_rgba;\n void main () {\n vec4 color = texture2D(u_texture, v_texCoords);\n if(color.a < 0.1)\n discard;\n gl_FragColor = color * v_rgba;\n }"})),this._renderer.handler.programs.billboardPicking||this._renderer.handler.addProgram(new zi("billboardPicking",{uniforms:{viewport:"vec2",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",uScaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_vertices:"vec2",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"vec2",a_rotation:"float",a_rgba:"vec4"},vertexShader:`precision highp float;\n attribute vec2 a_vertices;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute vec2 a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec3 v_rgb;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform float opacity;\n uniform float planetRadius;\n uniform vec2 viewport;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Di}\n\n ${Fi}\n\n void main() {\n\n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgb = a_rgba.rgb;\n\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n //vec3 up = vec3( viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1] );\n //vec3 right = vec3( viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0] );\n\n float scd = (1.0 - smoothstep(uScaleByDistance[0], uScaleByDistance[1], lookDist)) * (1.0 - step(uScaleByDistance[2], lookDist));\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02;\n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n\n vec2 v = screenPos + rotate2d(a_rotation) * (a_vertices * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n varying vec3 v_rgb;\n void main () {\n gl_FragColor = vec4(v_rgb, 1.0);\n }"})))}setRenderer(e){this._renderer=e,this.initProgram()}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_removeBillboards(){let e=this._billboards.length;for(;e--;){let t=this._billboards[e];t._handlerIndex=-1,t._handler=null,t._isReady=!1,t._lockId=ti}this._billboards.length=0,this._billboards=[]}clear(){this._texCoordArr=null,this._vertexArr=null,this._positionHighArr=null,this._positionLowArr=null,this._sizeArr=null,this._offsetArr=null,this._rgbaArr=null,this._rotationArr=null,this._pickingColorArr=null,this._texCoordArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._pickingColorArr=new Float32Array([]),this._removeBillboards(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e.deleteBuffer(this._positionHighBuffer),e.deleteBuffer(this._positionLowBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._offsetBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._rotationBuffer),e.deleteBuffer(this._vertexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._pickingColorBuffer)}this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._vertexBuffer=null,this._texCoordBuffer=null,this._pickingColorBuffer=null}update(){if(this._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}add(e){-1==e._handlerIndex&&(e._isReady=!0,e._handler=this,e._handlerIndex=this._billboards.length,this._billboards.push(e))}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.billboard.activate();let i=t.programs.billboard._program,n=i.attributes,r=i.uniforms,s=t.gl,a=this._entityCollection;s.disable(s.CULL_FACE),s.uniform1f(r.depthOffset,a.polygonOffsetUnits),s.uniform1i(r.u_texture,0),s.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),s.uniform3fv(r.uScaleByDistance,a.scaleByDistance),s.uniform1f(r.opacity,a._fadingOpacity),s.bindBuffer(s.ARRAY_BUFFER,this._texCoordBuffer),s.vertexAttribPointer(n.a_texCoord,this._texCoordBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._vertexBuffer),s.vertexAttribPointer(n.a_vertices,this._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionHighBuffer),s.vertexAttribPointer(n.a_positionsHigh,this._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionLowBuffer),s.vertexAttribPointer(n.a_positionsLow,this._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._rgbaBuffer),s.vertexAttribPointer(n.a_rgba,this._rgbaBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._sizeBuffer),s.vertexAttribPointer(n.a_size,this._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._offsetBuffer),s.vertexAttribPointer(n.a_offset,this._offsetBuffer.itemSize,s.FLOAT,!1,0,0),s.uniform1f(r.planetRadius,a.renderNode._planetRadius2||0),s.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),s.bindBuffer(s.ARRAY_BUFFER,this._rotationBuffer),s.vertexAttribPointer(n.a_rotation,this._rotationBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.enable(s.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.billboardPicking.activate();let i=t.programs.billboardPicking._program,n=i.attributes,r=i.uniforms,s=t.gl,a=this._entityCollection;s.disable(s.CULL_FACE),s.uniform1f(r.depthOffset,a.polygonOffsetUnits),s.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),s.uniform3fv(r.uScaleByDistance,a.scaleByDistance),s.uniform1f(r.opacity,a._fadingOpacity),s.bindBuffer(s.ARRAY_BUFFER,this._vertexBuffer),s.vertexAttribPointer(n.a_vertices,this._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionHighBuffer),s.vertexAttribPointer(n.a_positionsHigh,this._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionLowBuffer),s.vertexAttribPointer(n.a_positionsLow,this._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._pickingColorBuffer),s.vertexAttribPointer(n.a_rgba,this._pickingColorBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._sizeBuffer),s.vertexAttribPointer(n.a_size,this._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._offsetBuffer),s.vertexAttribPointer(n.a_offset,this._offsetBuffer.itemSize,s.FLOAT,!1,0,0),s.uniform1f(r.planetRadius,a.renderNode._planetRadius2||0),s.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),s.bindBuffer(s.ARRAY_BUFFER,this._rotationBuffer),s.vertexAttribPointer(n.a_rotation,this._rotationBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.enable(s.CULL_FACE)}draw(){this._billboards.length&&(this.update(),this._displayPASS())}drawPicking(){this._billboards.length&&this.pickingEnabled&&this._pickingPASS()}reindexBillboardsArray(e){let t=this._billboards;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}_removeBillboard(e){let t=e._handlerIndex;this._billboards.splice(t,1);let i=24*t;this._rgbaArr=Ge(this._rgbaArr,i,24),i=18*t,this._positionHighArr=Ge(this._positionHighArr,i,18),this._positionLowArr=Ge(this._positionLowArr,i,18),this._offsetArr=Ge(this._offsetArr,i,18),this._pickingColorArr=Ge(this._pickingColorArr,i,18),i=12*t,this._vertexArr=Ge(this._vertexArr,i,12),this._sizeArr=Ge(this._sizeArr,i,12),this._texCoordArr=Ge(this._texCoordArr,i,12),i=6*t,this._rotationArr=Ge(this._rotationArr,i,6),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1,e._lockId=ti}setAlignedAxisArr(e,t){}remove(e){e._handler&&(e._isReady&&this.__id===e._handler.__id?this._removeBillboard(e):e._handler=null)}setPositionArr(e,t,i){let n=18*e,r=this._positionHighArr,s=t.x,a=t.y,o=t.z;r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,r=this._positionLowArr,s=i.x,a=i.y,o=i.z,r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,this._changedBuffers[1]=!0}setPickingColorArr(e,t){let i=18*e,n=this._pickingColorArr,r=t.x/255,s=t.y/255,a=t.z/255;n[i]=r,n[i+1]=s,n[i+2]=a,n[i+3]=r,n[i+4]=s,n[i+5]=a,n[i+6]=r,n[i+7]=s,n[i+8]=a,n[i+9]=r,n[i+10]=s,n[i+11]=a,n[i+12]=r,n[i+13]=s,n[i+14]=a,n[i+15]=r,n[i+16]=s,n[i+17]=a,this._changedBuffers[0]=!0}setSizeArr(e,t,i){let n=12*e,r=this._sizeArr,s=t,a=i;r[n]=s,r[n+1]=a,r[n+2]=s,r[n+3]=a,r[n+4]=s,r[n+5]=a,r[n+6]=s,r[n+7]=a,r[n+8]=s,r[n+9]=a,r[n+10]=s,r[n+11]=a,this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e,n=this._offsetArr,r=t.x,s=t.y,a=t.z;n[i]=r,n[i+1]=s,n[i+2]=a,n[i+3]=r,n[i+4]=s,n[i+5]=a,n[i+6]=r,n[i+7]=s,n[i+8]=a,n[i+9]=r,n[i+10]=s,n[i+11]=a,n[i+12]=r,n[i+13]=s,n[i+14]=a,n[i+15]=r,n[i+16]=s,n[i+17]=a,this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e,n=this._rgbaArr,r=t.x,s=t.y,a=t.z,o=t.w;n[i]=r,n[i+1]=s,n[i+2]=a,n[i+3]=o,n[i+4]=r,n[i+5]=s,n[i+6]=a,n[i+7]=o,n[i+8]=r,n[i+9]=s,n[i+10]=a,n[i+11]=o,n[i+12]=r,n[i+13]=s,n[i+14]=a,n[i+15]=o,n[i+16]=r,n[i+17]=s,n[i+18]=a,n[i+19]=o,n[i+20]=r,n[i+21]=s,n[i+22]=a,n[i+23]=o,this._changedBuffers[4]=!0}setRotationArr(e,t){let i=6*e,n=this._rotationArr;n[i]=t,n[i+1]=t,n[i+2]=t,n[i+3]=t,n[i+4]=t,n[i+5]=t,this._changedBuffers[5]=!0}setTexCoordArr(e,t){let i=12*e,n=this._texCoordArr;n[i]=t[0],n[i+1]=t[1],n[i+2]=t[2],n[i+3]=t[3],n[i+4]=t[4],n[i+5]=t[5],n[i+6]=t[6],n[i+7]=t[7],n[i+8]=t[8],n[i+9]=t[9],n[i+10]=t[10],n[i+11]=t[11],this._changedBuffers[6]=!0}setVisibility(e,t){let i;i=t?[-.5,.5,-.5,-.5,.5,-.5,.5,-.5,.5,.5,-.5,.5]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e,n=this._vertexArr;n[i]=t[0],n[i+1]=t[1],n[i+2]=t[2],n[i+3]=t[3],n[i+4]=t[4],n[i+5]=t[5],n[i+6]=t[6],n[i+7]=t[7],n[i+8]=t[8],n[i+9]=t[9],n[i+10]=t[10],n[i+11]=t[11],this._changedBuffers[7]=!0}createPositionBuffer(){let e=this._renderer.handler,t=this._positionHighArr.length/3;this._positionHighBuffer&&this._positionHighBuffer.numItems===t||(e.gl.deleteBuffer(this._positionHighBuffer),e.gl.deleteBuffer(this._positionLowBuffer),this._positionHighBuffer=e.createStreamArrayBuffer(3,t),this._positionLowBuffer=e.createStreamArrayBuffer(3,t)),e.setStreamArrayBuffer(this._positionHighBuffer,this._positionHighArr),e.setStreamArrayBuffer(this._positionLowBuffer,this._positionLowArr)}createSizeBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createArrayBuffer(this._sizeArr,2,this._sizeArr.length/2)}createOffsetBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._offsetBuffer),this._offsetBuffer=e.createArrayBuffer(this._offsetArr,3,this._offsetArr.length/3)}createRgbaBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaBuffer=e.createArrayBuffer(this._rgbaArr,4,this._rgbaArr.length/4)}createRotationBuffer(){let e=this._renderer.handler;this._rotationBuffer&&this._rotationBuffer.numItems===this._rotationArr.length||(e.gl.deleteBuffer(this._rotationBuffer),this._rotationBuffer=e.createStreamArrayBuffer(1,this._rotationArr.length)),e.setStreamArrayBuffer(this._rotationBuffer,this._rotationArr)}createVertexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,2,this._vertexArr.length/2)}createTexCoordBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,2,this._texCoordArr.length/2)}createPickingColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}refreshTexCoordsArr(){}}Ni.__counter__=0;class Hi extends Ni{constructor(e){super(e),this._billboards=[]}add(e){if(-1==e._handlerIndex){super.add(e),this._addBillboardToArrays(e),this.refresh();let t=e.getSrc()||e.getImage()&&e.getImage().src;t&&e.setSrc(t)}}_addBillboardToArrays(e){e.getVisibility()?this._vertexArr=Ne(this._vertexArr,[-.5,.5,-.5,-.5,.5,-.5,.5,-.5,.5,.5,-.5,.5]):this._vertexArr=Ne(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]),this._texCoordArr=Ne(this._texCoordArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t,i=e._positionHigh.x,n=e._positionHigh.y,r=e._positionHigh.z;this._positionHighArr=Ne(this._positionHighArr,[i,n,r,i,n,r,i,n,r,i,n,r,i,n,r,i,n,r]),i=e._positionLow.x,n=e._positionLow.y,r=e._positionLow.z,this._positionLowArr=Ne(this._positionLowArr,[i,n,r,i,n,r,i,n,r,i,n,r,i,n,r,i,n,r]),i=e._width,n=e._height,this._sizeArr=Ne(this._sizeArr,[i,n,i,n,i,n,i,n,i,n,i,n]),i=e._offset.x,n=e._offset.y,r=e._offset.z,this._offsetArr=Ne(this._offsetArr,[i,n,r,i,n,r,i,n,r,i,n,r,i,n,r,i,n,r]),i=e._color.x,n=e._color.y,r=e._color.z,t=e._color.w,this._rgbaArr=Ne(this._rgbaArr,[i,n,r,t,i,n,r,t,i,n,r,t,i,n,r,t,i,n,r,t,i,n,r,t]),i=e._rotation,this._rotationArr=Ne(this._rotationArr,[i,i,i,i,i,i]),i=e._entity._pickingColor.x/255,n=e._entity._pickingColor.y/255,r=e._entity._pickingColor.z/255,this._pickingColorArr=Ne(this._pickingColorArr,[i,n,r,i,n,r,i,n,r,i,n,r,i,n,r,i,n,r])}get billboards(){return this._billboards}refreshTexCoordsArr(){if(this._entityCollection&&this._renderer){let e=this._renderer.billboardsTextureAtlas;for(let t=0;t<this._billboards.length;t++){let i=this._billboards[t],n=i.getImage();if(n){let t=e.get(n.__nodeIndex);t&&this.setTexCoordArr(i._handlerIndex,t.texCoords)}}}}}function Oi(e,t=0,i=0,n=1,...r){const s=t*i;for(let t=s,a=s+i;t<a;t++)e[t]=r[t%n];return e}class Vi{constructor(e){this.isFree=!0,this._geoObjectHandler=e,this.geoObjects=[],this.numInstances=0,this._texture=null,this._textureSrc=null,this._pitchRollArr=[],this._sizeArr=[],this._vertexArr=[],this._positionHighArr=[],this._positionLowArr=[],this._directionArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._pitchRollBuffer=null,this._sizeBuffer=null,this._vertexBuffer=null,this._positionHighBuffer=null,this._positionLowBuffer=null,this._directionBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[8]=this.createPickingColorBuffer,this._buffersUpdateCallbacks[1]=this.createPositionBuffer,this._buffersUpdateCallbacks[5]=this.createDirectionBuffer,this._buffersUpdateCallbacks[3]=this.createNormalsBuffer,this._buffersUpdateCallbacks[2]=this.createRgbaBuffer,this._buffersUpdateCallbacks[4]=this.createIndicesBuffer,this._buffersUpdateCallbacks[0]=this.createVertexBuffer,this._buffersUpdateCallbacks[7]=this.createSizeBuffer,this._buffersUpdateCallbacks[6]=this.createPitchRollBuffer,this._buffersUpdateCallbacks[9]=this.createVisibleBuffer,this._buffersUpdateCallbacks[10]=this.createTexCoordBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}createTexture(e){this._geoObjectHandler&&this._geoObjectHandler._planet&&(this._texture=this._geoObjectHandler._planet.renderer.handler.createTextureDefault(e))}clear(){this.numInstances=0,this.geoObjects=[],this._pitchRollArr=[],this._sizeArr=[],this._vertexArr=[],this._positionHighArr=[],this._positionLowArr=[],this._directionArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._deleteBuffers(),this.isFree=!1}_deleteBuffers(){if(this._geoObjectHandler&&this._geoObjectHandler._planet&&this._geoObjectHandler._planet.renderer){let e=this._geoObjectHandler._planet.renderer.handler,t=e.gl;e.deleteTexture(this._texture),this._texture=null,t.deleteBuffer(this._pitchRollBuffer),t.deleteBuffer(this._sizeBuffer),t.deleteBuffer(this._vertexBuffer),t.deleteBuffer(this._positionHighBuffer),t.deleteBuffer(this._positionLowBuffer),t.deleteBuffer(this._directionBuffer),t.deleteBuffer(this._rgbaBuffer),t.deleteBuffer(this._normalsBuffer),t.deleteBuffer(this._indicesBuffer),t.deleteBuffer(this._pickingColorBuffer),t.deleteBuffer(this._visibleBuffer),t.deleteBuffer(this._texCoordBuffer)}this._pitchRollBuffer=null,this._sizeBuffer=null,this._vertexBuffer=null,this._positionHighBuffer=null,this._positionLowBuffer=null,this._directionBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null}createVertexBuffer(){const e=this._geoObjectHandler._planet.renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexArr=Oe(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,3,this._vertexArr.length/3)}createPitchRollBuffer(){let e=this._geoObjectHandler._planet.renderer.handler,t=this._pitchRollArr.length/2;this._pitchRollBuffer&&this._pitchRollBuffer.numItems===t||(e.gl.deleteBuffer(this._pitchRollBuffer),this._pitchRollBuffer=e.createStreamArrayBuffer(2,t)),this._pitchRollArr=Oe(this._pitchRollArr),e.setStreamArrayBuffer(this._pitchRollBuffer,this._pitchRollArr)}createVisibleBuffer(){const e=this._geoObjectHandler._planet.renderer.handler,t=this._visibleArr.length;this._visibleBuffer&&this._visibleBuffer.numItems===t||(e.gl.deleteBuffer(this._visibleBuffer),this._visibleBuffer=e.createStreamArrayBuffer(1,t)),this._visibleArr=Oe(this._visibleArr),e.setStreamArrayBuffer(this._visibleBuffer,this._visibleArr)}createSizeBuffer(){let e=this._geoObjectHandler._planet.renderer.handler,t=this._sizeArr.length/3;this._sizeBuffer&&this._sizeBuffer.numItems===t||(e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createStreamArrayBuffer(3,t)),this._sizeArr=Oe(this._sizeArr),e.setStreamArrayBuffer(this._sizeBuffer,this._sizeArr)}createTexCoordBuffer(){const e=this._geoObjectHandler._planet.renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordArr=Oe(this._texCoordArr),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,2,this._texCoordArr.length/2)}createPositionBuffer(){let e=this._geoObjectHandler._planet.renderer.handler,t=this._positionHighArr.length/3;this._positionHighBuffer&&this._positionHighBuffer.numItems===t||(e.gl.deleteBuffer(this._positionHighBuffer),e.gl.deleteBuffer(this._positionLowBuffer),this._positionHighBuffer=e.createStreamArrayBuffer(3,t),this._positionLowBuffer=e.createStreamArrayBuffer(3,t)),this._positionHighArr=Oe(this._positionHighArr),this._positionLowArr=Oe(this._positionLowArr),e.setStreamArrayBuffer(this._positionHighBuffer,this._positionHighArr),e.setStreamArrayBuffer(this._positionLowBuffer,this._positionLowArr)}createRgbaBuffer(){let e=this._geoObjectHandler._planet.renderer.handler,t=this._rgbaArr.length/4;this._rgbaBuffer&&this._rgbaBuffer.numItems===t||(e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaBuffer=e.createStreamArrayBuffer(4,t)),this._rgbaArr=Oe(this._rgbaArr),e.setStreamArrayBuffer(this._rgbaBuffer,this._rgbaArr)}createDirectionBuffer(){let e=this._geoObjectHandler._planet.renderer.handler,t=this._directionArr.length/3;this._directionBuffer&&this._directionBuffer.numItems===t||(e.gl.deleteBuffer(this._directionBuffer),this._directionBuffer=e.createStreamArrayBuffer(3,t)),this._directionArr=Oe(this._directionArr),e.setStreamArrayBuffer(this._directionBuffer,this._directionArr)}createNormalsBuffer(){const e=this._geoObjectHandler._planet.renderer.handler;e.gl.deleteBuffer(this._normalsBuffer),this._normalsArr=Oe(this._normalsArr),this._normalsBuffer=e.createArrayBuffer(this._normalsArr,3,this._normalsArr.length/3)}createIndicesBuffer(){const e=this._geoObjectHandler._planet.renderer.handler;e.gl.deleteBuffer(this._indicesBuffer),this._indicesArr=Oe(this._indicesArr,Uint32Array),this._indicesBuffer=e.createElementArrayBuffer(this._indicesArr,1,this._indicesArr.length)}createPickingColorBuffer(){const e=this._geoObjectHandler._planet.renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=Oe(this._pickingColorArr),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}update(){if(this._geoObjectHandler._planet){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1);this.isFree=!0}}}class Ui{constructor(e){this.__id=Ui.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._planet=null,this._geoObjects=[],this._instanceDataMap=new Map,this._instanceDataMapValues=[],this._dataTagUpdateQueue=[]}initProgram(){this._planet&&this._planet.renderer&&(this._planet.renderer.handler.programs.geo_object||this._planet.renderer.handler.addProgram(new zi("geo_object",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",eyePositionHigh:"vec3",eyePositionLow:"vec3",lightsPositions:"vec3",lightsParamsv:"vec3",lightsParamsf:"float",uTexture:"sampler2d",uUseTexture:"float"},attributes:{aVertexPosition:"vec3",aVertexNormal:"vec3",aTexCoord:"vec2",aPositionHigh:{type:"vec3",divisor:1},aPositionLow:{type:"vec3",divisor:1},aDirection:{type:"vec3",divisor:1},aPitchRoll:{type:"vec2",divisor:1},aColor:{type:"vec4",divisor:1},aScale:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1}},vertexShader:"precision highp float;\n \n attribute vec3 aVertexPosition;\n attribute vec3 aVertexNormal; \n attribute vec3 aPositionHigh;\n attribute vec3 aPositionLow; \n attribute vec3 aDirection;\n attribute vec2 aPitchRoll;\n attribute vec4 aColor;\n attribute vec3 aScale;\n attribute float aDispose;\n attribute float aUseTexture;\n attribute vec2 aTexCoord;\n \n uniform vec3 uScaleByDistance;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n \n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n\n varying vec3 cameraPosition;\n varying vec3 vNormal;\n varying vec3 v_vertex; \n varying vec4 vColor;\n varying float vDispose;\n varying vec2 vTexCoords;\n //varying float useLighting;\n \n const float PI = 3.141592653589793;\n \n const float RADIANS = PI / 180.0;\n \n void main(void) {\n \n if (aDispose == 0.0) {\n return;\n }\n \n vec3 position = aPositionHigh + aPositionLow;\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 look = cameraPosition - position;\n float lookLength = length(look);\n\n // useLighting = 1.0; \n // if(lookLength > 2000000.0){\n // useLighting = 0.0;\n // }\n\n \n vColor = aColor;\n vTexCoords = aTexCoord;\n \n float cos_roll = cos(aPitchRoll.y);\n float sin_roll = sin(aPitchRoll.y);\n \n mat3 rotZ = mat3(\n vec3(cos_roll, sin_roll, 0.0),\n vec3(-sin_roll, cos_roll, 0.0), \n vec3(0.0, 0.0, 1.0) \n );\n\n float cos_pitch = cos(aPitchRoll.x);\n float sin_pitch = sin(aPitchRoll.x);\n\n mat3 rotX = mat3(\n vec3(1.0, 0.0, 0.0),\n vec3(0.0, cos_pitch, sin_pitch), \n vec3(0.0, -sin_pitch, cos_pitch) \n );\n\n vec3 r = cross(normalize(-position), aDirection);\n mat3 modelMatrix = mat3(r, normalize(position), -aDirection) * rotX * rotZ;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = aPositionHigh - eyePositionHigh;\n vec3 lowDiff = aPositionLow - eyePositionLow;\n \n vNormal = modelMatrix * aVertexNormal;\n \n // if(lookLength > uScaleByDistance[1])\n // {\n // scd = uScaleByDistance[1] / uScaleByDistance[0];\n // }\n // else if(lookLength > uScaleByDistance[0])\n // {\n // scd = lookLength / uScaleByDistance[0];\n // }\n // ... is the same math\n float scd = uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];\n \n vec3 vert = modelMatrix * (aVertexPosition * aScale) * scd;\n \n vert += lowDiff;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + vert, 1.0);\n \n v_vertex = position + vert;\n }",fragmentShader:"precision highp float;\n\n #define MAX_POINT_LIGHTS 1\n \n uniform vec3 lightsPositions[MAX_POINT_LIGHTS];\n uniform vec3 lightsParamsv[MAX_POINT_LIGHTS * 3];\n uniform float lightsParamsf[MAX_POINT_LIGHTS];\n uniform sampler2D uTexture;\n uniform float uUseTexture;\n \n varying vec3 cameraPosition;\n varying vec3 v_vertex; \n varying vec4 vColor;\n varying vec3 vNormal;\n varying vec2 vTexCoords;\n //varying float useLighting;\n \n void main(void) { \n \n vec3 lightWeighting = vec3(1.0);\n \n //if(useLighting != 0.0){\n vec3 normal = normalize(vNormal);\n vec3 lightDir = normalize(lightsPositions[0]);\n vec3 viewDir = normalize(cameraPosition - v_vertex); \n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n float specularLightWeighting = pow( reflection, lightsParamsf[0]); \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0);\n lightWeighting = lightsParamsv[0] + lightsParamsv[1] * diffuseLightWeighting + lightsParamsv[2] * specularLightWeighting;\n //}\n \n if(uUseTexture > 0.0) {\n vec4 tColor = texture2D(uTexture, vTexCoords);\n gl_FragColor = vec4(tColor.rgb * lightWeighting, tColor.a);\n } else {\n gl_FragColor = vec4(vColor.rgb * lightWeighting, vColor.a);\n }\n }"})),this._planet.renderer.handler.programs.geo_object_picking||this._planet.renderer.handler.addProgram(new zi("geo_object_picking",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",eyePositionHigh:"vec3",eyePositionLow:"vec3",pickingScale:"float"},attributes:{aVertexPosition:"vec3",aPositionHigh:{type:"vec3",divisor:1},aPositionLow:{type:"vec3",divisor:1},aDirection:{type:"vec3",divisor:1},aPitchRoll:{type:"vec2",divisor:1},aPickingColor:{type:"vec3",divisor:1},aScale:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1}},vertexShader:"precision highp float;\n\n attribute vec3 aVertexPosition;\n attribute vec3 aPositionHigh;\n attribute vec3 aPositionLow; \n attribute vec3 aDirection;\n attribute vec3 aPickingColor;\n attribute vec2 aPitchRoll;\n attribute vec3 aScale;\n attribute float aDispose;\n \n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform float pickingScale;\n\n varying vec3 vColor;\n \n const float RADIANS = 3.141592653589793 / 180.0;\n\n void main(void) {\n\n if (aDispose == 0.0) {\n return;\n }\n \n vColor = aPickingColor;\n \n float cos_roll = cos(aPitchRoll.y);\n float sin_roll = sin(aPitchRoll.y);\n \n mat3 rotZ = mat3(\n vec3(cos_roll, sin_roll, 0.0),\n vec3(-sin_roll, cos_roll, 0.0), \n vec3(0.0, 0.0, 1.0) \n );\n\n float cos_pitch = cos(aPitchRoll.x);\n float sin_pitch = sin(aPitchRoll.x);\n\n mat3 rotX = mat3(\n vec3(1.0, 0.0, 0.0),\n vec3(0.0, cos_pitch, sin_pitch), \n vec3(0.0, -sin_pitch, cos_pitch) \n );\n \n vec3 position = aPositionHigh + aPositionLow;\n vec3 cameraPosition = eyePositionHigh + eyePositionLow;\n vec3 r = cross(normalize(-position), aDirection);\n mat3 modelMatrix = mat3(r, normalize(position), -aDirection) * rotX * rotZ;\n \n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n vec3 highDiff = aPositionHigh - eyePositionHigh;\n vec3 lowDiff = aPositionLow - eyePositionLow;\n \n vec3 look = cameraPosition - position;\n float lookLength = length(look);\n \n // if(lookLength > uScaleByDistance[1])\n // {\n // scd = uScaleByDistance[1] / uScaleByDistance[0];\n // }\n // else if(lookLength > uScaleByDistance[0])\n // {\n // scd = lookLength / uScaleByDistance[0];\n // }\n // ... is the same math above\n // @hack\n // pickingScale replace to this line, because when it s\n // tays in the vert above it affects on Mac Safari jitter\n float scd = pickingScale * uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];\n\n vec3 vert = modelMatrix * (aVertexPosition * aScale) * scd;\n \n vert += lowDiff;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + vert, 1.0);\n }",fragmentShader:"precision highp float;\n varying vec3 vColor;\n void main () {\n gl_FragColor = vec4(vColor, 1.0);\n }"})))}setRenderNode(e){this._planet=e,this.initProgram();for(let e=0;e<this._instanceDataMapValues.length;e++)this._loadDataTagTexture(this._instanceDataMapValues[e]);for(let e=0;e<this._geoObjects.length;e++)this._geoObjects[e].updateDirection();this.update()}setTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&(i._textureSrc=e,this._instanceDataMap.set(t,i),this._loadDataTagTexture(i))}setObjectSrc(e,t){const i=this._instanceDataMap.get(t);e&&i&&i._objectSrc!==e&&(i._objectSrc=e,gi.loadObj(e).then((e=>{this._updateInstanceData(e[0],t)})))}_updateInstanceData(e,t){const i=this._instanceDataMap.get(t);i&&(e.vertices.length!==i._vertexArr.length&&(i._vertexArr=e.vertices,i._changedBuffers[0]=!0,i._changedBuffers[5]=!0),e.normals.length!==i._normalsArr.length&&(i._normalsArr=e.normals,i._changedBuffers[3]=!0),e.indices.length!==i._indicesArr.length&&(i._indicesArr=e.indices,i._changedBuffers[4]=!0),e.texCoords.length!==i._texCoordArr.length&&(i._texCoordArr=e.texCoords,i._changedBuffers[10]=!0),i._textureSrc=e.src,this._loadDataTagTexture(i),this._updateTag(i),this._instanceDataMapValues=Array.from(this._instanceDataMap.values()))}_addGeoObjectToArray(e){const t=e.tag;let i=this._instanceDataMap.get(t);i||(i=new Vi(this),this._instanceDataMap.set(t,i),this._instanceDataMapValues=Array.from(this._instanceDataMap.values()),i._vertexArr=e.vertices,i._normalsArr=e.normals,i._indicesArr=e.indices,i._texCoordArr=e.texCoords,i._textureSrc=e.object3d.src,this._loadDataTagTexture(i)),e._tagDataIndex=i.numInstances++,e._tagData=i,i.geoObjects.push(e);let n=3;i._visibleArr=He(i._visibleArr,Oi([],0,1,1,e.getVisibility()?1:0));let r,s=e._positionHigh.x,a=e._positionHigh.y,o=e._positionHigh.z;i._positionHighArr=He(i._positionHighArr,Oi([],0,n,n,s,a,o)),s=e._positionLow.x,a=e._positionLow.y,o=e._positionLow.z,i._positionLowArr=He(i._positionLowArr,Oi([],0,n,n,s,a,o)),s=e._entity._pickingColor.x/255,a=e._entity._pickingColor.y/255,o=e._entity._pickingColor.z/255,i._pickingColorArr=He(i._pickingColorArr,Oi([],0,n,n,s,a,o)),s=e._direction.x,a=e._direction.y,o=e._direction.z,i._directionArr=He(i._directionArr,Oi([],0,n,n,s,a,o)),n=4,s=e._color.x,a=e._color.y,o=e._color.z,r=e._color.w,i._rgbaArr=He(i._rgbaArr,Oi([],0,n,n,s,a,o,r)),n=2,s=e.getPitch(),a=e.getRoll(),i._pitchRollArr=He(i._pitchRollArr,Oi([],0,n,n,s,a)),n=3;let l=e.getScale();s=l.x,a=l.y,o=l.z,i._sizeArr=He(i._sizeArr,Oi([],0,n,n,s,a,o))}_displayPASS(){let e=this._planet.renderer,t=e.handler.programs.geo_object,i=t._program,n=i.uniforms,r=i.attributes,s=e.handler.gl,a=this._entityCollection;t.activate(),s.uniform3fv(n.uScaleByDistance,a.scaleByDistance),s.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),s.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniform3fv(n.lightsPositions,this._planet._lightsPositions),s.uniform3fv(n.lightsParamsv,this._planet._lightsParamsv),s.uniform1fv(n.lightsParamsf,this._planet._lightsParamsf);for(let t=0;t<this._instanceDataMapValues.length;t++){let a=this._instanceDataMapValues[t];s.bindBuffer(s.ARRAY_BUFFER,a._directionBuffer),s.vertexAttribPointer(r.aDirection,a._directionBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._sizeBuffer),s.vertexAttribPointer(r.aScale,a._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._pitchRollBuffer),s.vertexAttribPointer(r.aPitchRoll,a._pitchRollBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._rgbaBuffer),s.vertexAttribPointer(r.aColor,a._rgbaBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._visibleBuffer),s.vertexAttribPointer(r.aDispose,a._visibleBuffer.itemSize,s.FLOAT,!1,0,0),s.uniform1f(n.uUseTexture,a._texture?1:0),s.bindBuffer(s.ARRAY_BUFFER,a._positionHighBuffer),s.vertexAttribPointer(r.aPositionHigh,a._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._positionLowBuffer),s.vertexAttribPointer(r.aPositionLow,a._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._normalsBuffer),s.vertexAttribPointer(r.aVertexNormal,a._normalsBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,a._vertexBuffer),s.vertexAttribPointer(r.aVertexPosition,a._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,a._texture||e.handler.defaultTexture),s.uniform1i(n.uTexture,0),s.bindBuffer(s.ARRAY_BUFFER,a._texCoordBuffer),s.vertexAttribPointer(r.aTexCoord,a._texCoordBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,a._indicesBuffer),i.drawElementsInstanced(s.TRIANGLES,a._indicesBuffer.numItems,s.UNSIGNED_INT,0,a.numInstances)}}drawPicking(){this._geoObjects.length&&this.pickingEnabled&&(this.update(),this._pickingPASS())}_pickingPASS(){let e=this._planet.renderer,t=e.handler.programs.geo_object_picking,i=t._program,n=i.uniforms,r=i.attributes,s=e.handler.gl,a=this._entityCollection;t.activate(),s.uniform3fv(n.uScaleByDistance,a.scaleByDistance),s.uniform1f(n.pickingScale,a.pickingScale),s.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),s.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix());for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e];s.bindBuffer(s.ARRAY_BUFFER,t._directionBuffer),s.vertexAttribPointer(r.aDirection,t._directionBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._sizeBuffer),s.vertexAttribPointer(r.aScale,t._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._pitchRollBuffer),s.vertexAttribPointer(r.aPitchRoll,t._pitchRollBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._pickingColorBuffer),s.vertexAttribPointer(r.aPickingColor,t._pickingColorBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._positionHighBuffer),s.vertexAttribPointer(r.aPositionHigh,t._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._positionLowBuffer),s.vertexAttribPointer(r.aPositionLow,t._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._visibleBuffer),s.vertexAttribPointer(r.aDispose,t._visibleBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,t._vertexBuffer),s.vertexAttribPointer(r.aVertexPosition,t._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,t._indicesBuffer),i.drawElementsInstanced(s.TRIANGLES,t._indicesBuffer.numItems,s.UNSIGNED_INT,0,t.numInstances)}}async _loadDataTagTexture(e){if(this._planet&&e._textureSrc){const t=await Xe(e._textureSrc);e.createTexture(t)}}setDirectionArr(e,t,i){Oi(e._directionArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[5]=!0,this._updateTag(e)}setVisibility(e,t,i){Oi(e._visibleArr,t,1,1,i?1:0),e._changedBuffers[9]=!0,this._updateTag(e)}setPositionArr(e,t,i,n){Oi(e._positionHighArr,t,3,3,i.x,i.y,i.z),Oi(e._positionLowArr,t,3,3,n.x,n.y,n.z),e._changedBuffers[1]=!0,this._updateTag(e)}setRgbaArr(e,t,i){Oi(e._rgbaArr,t,4,4,i.x,i.y,i.z,i.w),e._changedBuffers[2]=!0,this._updateTag(e)}setPickingColorArr(e,t,i){Oi(e._pickingColorArr,t,3,3,i.x/255,i.y/255,i.z/255),e._changedBuffers[8]=!0,this._updateTag(e)}setPitchRollArr(e,t,i,n){Oi(e._pitchRollArr,t,2,2,i,n),e._changedBuffers[6]=!0,this._updateTag(e)}setScaleArr(e,t,i){Oi(e._sizeArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[7]=!0,this._updateTag(e)}_updateTag(e){e.isFree&&(e.isFree=!1,this._dataTagUpdateQueue.push(e))}update(){for(let e=0,t=this._dataTagUpdateQueue.length;e<t;e++)this._dataTagUpdateQueue[e].update();this._dataTagUpdateQueue=[]}_removeAll(){let e=this._geoObjects.length;for(;e--;){const t=this._geoObjects[e];t._tagDataIndex=-1,t._tagData=null,t._handlerIndex=-1,t._handler=null}this._geoObjects.length=0,this._geoObjects=[];for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].clear();this._instanceDataMap.clear(),this._instanceDataMapValues=[]}clear(){this._removeAll()}draw(){this._geoObjects.length&&(this.update(),this._displayPASS())}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._geoObjects.length,this._geoObjects.push(e),this._addGeoObjectToArray(e),e.updateDirection(),e._tagData.refresh(),this._updateTag(e._tagData),e.setObjectSrc(e._objectSrc))}remove(e){e._handler&&this.__id==e._handler.__id&&this._removeGeoObject(e)}_clearDataTagQueue(){this._dataTagUpdateQueue=[]}_removeGeoObject(e){let t=e._tagData,i=e.tag;t.numInstances--;let n=!1;0===t.numInstances&&(t.clear(),this._instanceDataMap.delete(i),this._instanceDataMapValues=[],this._clearDataTagQueue(),n=!0),this._geoObjects.splice(e._handlerIndex,1);for(let t=e._handlerIndex,i=this._geoObjects.length;t<i;t++){let e=this._geoObjects[t];e._handlerIndex=e._handlerIndex-1}let r=e._tagDataIndex;t.geoObjects.splice(r,1);for(let i=e._tagDataIndex,n=t.geoObjects.length;i<n;i++){let e=t.geoObjects[i];e._tagDataIndex=e._tagDataIndex-1}t._rgbaArr=Ue(t._rgbaArr,4*r,4),t._positionHighArr=Ue(t._positionHighArr,3*r,3),t._positionLowArr=Ue(t._positionLowArr,3*r,3),t._directionArr=Ue(t._directionArr,3*r,3),t._pickingColorArr=Ue(t._pickingColorArr,3*r,3),t._sizeArr=Ue(t._sizeArr,3*r,3),t._pitchRollArr=Ue(t._pitchRollArr,2*r,2),t._visibleArr=Ue(t._visibleArr,r,1),e._handlerIndex=-1,e._handler=null,e._tagDataIndex=-1,e._tagData=null,n||(t.refresh(),this._updateTag(t))}}Ui.__counter__=0;const Gi="\n#define EMPTY -1.0\n#define RTL 1.0",Wi="vec2 project(vec4 p) {\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }",ji="mat2 rotate2d(float angle) {\n return mat2(cos(angle), -sin(angle),\n sin(angle), cos(angle));\n }";const Yi=-1;class qi extends Ni{constructor(e,t=21){super(e),this._billboards=[],this._gliphParamBuffer=null,this._fontIndexBuffer=null,this._outlineBuffer=null,this._outlineColorBuffer=null,this._gliphParamArr=new Float32Array([]),this._fontIndexArr=new Float32Array([]),this._outlineArr=new Float32Array([]),this._outlineColorArr=new Float32Array([]),this._buffersUpdateCallbacks[8]=this.createFontIndexBuffer,this._buffersUpdateCallbacks[9]=this.createOutlineBuffer,this._buffersUpdateCallbacks[10]=this.createOutlineColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length),this._maxLetters=t}initProgram(){this._renderer&&this._renderer.handler&&this._renderer.handler.gl&&(this._renderer.handler.programs.label||("webgl2"===this._renderer.handler.gl.type?this._renderer.handler.addProgram(new zi("label",{uniforms:{viewport:"vec2",fontTextureArr:"sampler2darray",sdfParamsArr:"vec4",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",isOutlinePass:"int",depthOffset:"float"},attributes:{a_outline:"float",a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4",a_offset:"vec3",a_fontIndex:"float"},vertexShader:`#version 300 es\n \n ${Gi}\n \n in float a_outline;\n in vec4 a_gliphParam;\n in vec2 a_vertices;\n in vec4 a_texCoord;\n in vec3 a_positionsHigh;\n in vec3 a_positionsLow;\n in vec3 a_offset;\n in float a_size;\n in float a_rotation;\n in vec4 a_rgba;\n in float a_fontIndex;\n\n out vec2 v_uv;\n out vec4 v_rgba;\n flat out int v_fontIndex; \n out vec4 v_outlineColor;\n flat out float v_outline;\n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n \n ${Wi}\n\n ${ji}\n\n void main() {\n\n if(a_texCoord.w == EMPTY) {\n gl_Position = vec4(0.0);\n v_fontIndex = -1;\n return;\n }\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_outline = a_outline;\n\n v_fontIndex = int(a_fontIndex);\n v_uv = a_texCoord.xy;\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgba = a_rgba;\n \n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"#version 300 es\n\n uniform int isOutlinePass;\n \n precision highp float;\n\n const int MAX_SIZE = 11;\n\n // x - ATLAS_WIDTH = 512.0;\n // y - ATLAS_HEIGHT = 512.0;\n // z - ATLAS_GLYPH_SIZE = 32.0;\n // w - ATLAS_FIELD_RANGE = 8.0;\n\n uniform sampler2D fontTextureArr[MAX_SIZE];\n uniform vec4 sdfParamsArr[MAX_SIZE];\n\n flat in int v_fontIndex;\n in vec2 v_uv;\n in vec4 v_rgba; \n\n flat in float v_outline;\n\n in vec3 v_pickingColor;\n\n layout(location = 0) out vec4 outScreen;\n\n float median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n }\n\n float getDistance() {\n vec3 msdf;\n if(v_fontIndex == 0) {\n msdf = texture(fontTextureArr[0], v_uv).rgb;\n } else if(v_fontIndex == 1){\n msdf = texture(fontTextureArr[1], v_uv).rgb;\n } else if(v_fontIndex == 2){\n msdf = texture(fontTextureArr[2], v_uv).rgb;\n } else if(v_fontIndex == 3){\n msdf = texture(fontTextureArr[3], v_uv).rgb;\n } else if(v_fontIndex == 4){\n msdf = texture(fontTextureArr[4], v_uv).rgb;\n } else if(v_fontIndex == 5){\n msdf = texture(fontTextureArr[5], v_uv).rgb;\n } else if(v_fontIndex == 6){\n msdf = texture(fontTextureArr[6], v_uv).rgb;\n } else if(v_fontIndex == 7){\n msdf = texture(fontTextureArr[7], v_uv).rgb;\n } else if(v_fontIndex == 8){\n msdf = texture(fontTextureArr[8], v_uv).rgb;\n } else if(v_fontIndex == 9){\n msdf = texture(fontTextureArr[9], v_uv).rgb;\n } else if(v_fontIndex == 10){\n msdf = texture(fontTextureArr[10], v_uv).rgb;\n }\n return median(msdf.r, msdf.g, msdf.b);\n }\n \n void main () {\n \n if(v_fontIndex == -1) {\n return;\n }\n \n vec4 sdfParams = sdfParamsArr[v_fontIndex];\n float sd = getDistance(); \n vec2 dxdy = fwidth(v_uv) * sdfParams.xy;\n\n if(isOutlinePass == 0){ \n float dist = sd + min(0.001, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);\n if(opacity <= 0.1){\n discard;\n }\n outScreen = vec4(v_rgba.rgb, opacity * v_rgba.a);\n } else { \n float dist = sd + min(v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0); \n if(opacity <= 0.1){\n discard;\n }\n outScreen = vec4(v_rgba.rgb, opacity * v_rgba.a);\n //outScreen = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;\n } \n }"})):this._renderer.handler.addProgram(new zi("label",{uniforms:{viewport:"vec2",fontTextureArr:"sampler2darray",sdfParamsArr:"vec4",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",isOutlinePass:"int",depthOffset:"float"},attributes:{a_outline:"float",a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4",a_offset:"vec3",a_fontIndex:"float"},vertexShader:` \n ${Gi}\n \n attribute float a_outline;\n attribute vec4 a_gliphParam;\n attribute vec2 a_vertices;\n attribute vec4 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute float a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n attribute float a_fontIndex;\n\n varying float v_outline;\n varying vec2 v_uv;\n varying vec4 v_rgba;\n varying float v_fontIndex; \n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Wi}\n\n ${ji}\n\n void main() {\n\n if(a_texCoord.w == EMPTY) {\n gl_Position = vec4(0.0);\n v_fontIndex = -1.0;\n return;\n }\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_outline = a_outline;\n v_uv = vec2(a_texCoord.xy);\n v_rgba = a_rgba;\n v_fontIndex = a_fontIndex;\n \n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n \n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n \n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"#extension GL_OES_standard_derivatives : enable\n\n precision highp float;\n precision highp int;\n\n const int MAX_SIZE = 11;\n\n // x - ATLAS_WIDTH = 512.0;\n // y - ATLAS_HEIGHT = 512.0;\n // z - ATLAS_GLYPH_SIZE = 32.0;\n // w - ATLAS_FIELD_RANGE = 8.0;\n\n uniform sampler2D fontTextureArr[MAX_SIZE];\n uniform vec4 sdfParamsArr[MAX_SIZE];\n uniform int isOutlinePass;\n \n varying float v_outline;\n varying vec2 v_uv;\n varying vec4 v_rgba; \n varying float v_fontIndex;\n \n float fontIndex;\n\n float median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n }\n\n float getDistance() {\n vec3 msdf;\n if(fontIndex >= 0.0 && fontIndex < 1.0) {\n msdf = texture2D(fontTextureArr[0], v_uv).rgb;\n } else if(fontIndex >= 1.0 && fontIndex < 2.0){\n msdf = texture2D(fontTextureArr[1], v_uv).rgb;\n } else if(fontIndex >= 2.0 && fontIndex < 3.0){\n msdf = texture2D(fontTextureArr[2], v_uv).rgb;\n } else if(fontIndex >= 3.0 && fontIndex < 4.0){\n msdf = texture2D(fontTextureArr[3], v_uv).rgb;\n } else if(fontIndex >= 4.0 && fontIndex < 5.0){\n msdf = texture2D(fontTextureArr[4], v_uv).rgb;\n } else if(fontIndex >= 5.0 && fontIndex < 6.0){\n msdf = texture2D(fontTextureArr[5], v_uv).rgb;\n } else if(fontIndex >= 6.0 && fontIndex < 7.0){\n msdf = texture2D(fontTextureArr[6], v_uv).rgb;\n } else if(fontIndex >= 7.0 && fontIndex < 8.0){\n msdf = texture2D(fontTextureArr[7], v_uv).rgb;\n } else if(fontIndex >= 8.0 && fontIndex < 9.0){\n msdf = texture2D(fontTextureArr[8], v_uv).rgb;\n } else if(fontIndex >= 9.0 && fontIndex < 10.0){\n msdf = texture2D(fontTextureArr[9], v_uv).rgb;\n } else if(fontIndex >= 10.0 && fontIndex < 11.0){\n msdf = texture2D(fontTextureArr[10], v_uv).rgb;\n }\n return median(msdf.r, msdf.g, msdf.b);\n }\n\n\n vec4 getSDFParams() {\n if(fontIndex >= 0.0 && fontIndex < 1.0) {\n return sdfParamsArr[0];\n } else if(fontIndex >= 1.0 && fontIndex < 2.0){\n return sdfParamsArr[1];\n } else if(fontIndex >= 2.0 && fontIndex < 3.0){\n return sdfParamsArr[2];\n } else if(fontIndex >= 3.0 && fontIndex < 4.0){\n return sdfParamsArr[3];\n } else if(fontIndex >= 4.0 && fontIndex < 5.0){\n return sdfParamsArr[4];\n } else if(fontIndex >= 5.0 && fontIndex < 6.0){\n return sdfParamsArr[5];\n } else if(fontIndex >= 6.0 && fontIndex < 7.0){\n return sdfParamsArr[6];\n } else if(fontIndex >= 7.0 && fontIndex < 8.0){\n return sdfParamsArr[7];\n } else if(fontIndex >= 8.0 && fontIndex < 9.0){\n return sdfParamsArr[8];\n } else if(fontIndex >= 9.0 && fontIndex < 10.0){\n return sdfParamsArr[9];\n } else if(fontIndex >= 10.0 && fontIndex < 11.0){\n return sdfParamsArr[10];\n }\n }\n \n void main () {\n\n fontIndex = v_fontIndex + 0.1;\n \n if(v_fontIndex < 0.0){\n return;\n }\n \n vec4 sdfParams = getSDFParams();\n float sd = getDistance(); \n vec2 dxdy = fwidth(v_uv) * sdfParams.xy;\n float dist = sd + min(0.001, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);\n\n if(isOutlinePass == 0){ \n //gl_FragColor = vec4(v_rgba.rgb, opacity * v_rgba.a);\n } else { \n float strokeDist = sd + min(v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float strokeAlpha = v_rgba.a * clamp(strokeDist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0); \n if(strokeAlpha < 0.1){\n discard;\n }\n //gl_FragColor = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;\n }\n }"}))),this._renderer.handler.programs.labelPicking||this._renderer.handler.addProgram(new zi("labelPicking",{uniforms:{viewport:"vec2",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4"},vertexShader:`\n \n ${Gi}\n \n attribute vec4 a_gliphParam;\n attribute vec2 a_vertices;\n attribute vec4 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute float a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec4 v_rgba;\n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Wi}\n\n ${ji}\n\n void main() {\n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n v_rgba = a_rgba;\n \n if(a_texCoord.w == EMPTY) {\n v_rgba.a = 0.0;\n gl_Position = vec4(0.0);\n return;\n }\n\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n \n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n\n varying vec4 v_rgba;\n\n varying vec3 v_pickingColor;\n\n void main () {\n\n vec4 color = v_rgba;\n if (color.a < 0.05) {\n return;\n }\n\n gl_FragColor = vec4(v_rgba.rgb, v_rgba.a);\n }"})))}get labels(){return this._billboards}add(e){e._handler||(e._handler=this,this.assignFontAtlas(e),this.refresh())}updateFonts(){let e=[...this._billboards];this._billboards=[];for(let t=0;t<e.length;t++)this.assignFontAtlas(e[t])}_addLabelToArrays(e){this._renderer&&this._renderer.labelWorker.make({handler:this,label:e})}assignFontAtlas(e){this._entityCollection&&this._renderer?(e.assignFontAtlas(this._renderer.fontAtlas),this._addLabelToArrays(e)):this._billboards.push(e)}workerCallback(e,t){t._lockId!==ti&&t._handler&&this.isEqual(t._handler)&&(t._isReady=!0,t._lockId=ti,t._handlerIndex=this._billboards.length,this._billboards.push(t),this._vertexArr=Ne(this._vertexArr,e.vertexArr),this._texCoordArr=Ne(this._texCoordArr,e.texCoordArr),this._gliphParamArr=Ne(this._gliphParamArr,e.gliphParamArr),this._positionHighArr=Ne(this._positionHighArr,e.positionHighArr),this._positionLowArr=Ne(this._positionLowArr,e.positionLowArr),this._sizeArr=Ne(this._sizeArr,e.sizeArr),this._offsetArr=Ne(this._offsetArr,e.offsetArr),this._rgbaArr=Ne(this._rgbaArr,e.rgbaArr),this._rotationArr=Ne(this._rotationArr,e.rotationArr),this._fontIndexArr=Ne(this._fontIndexArr,e.fontIndexArr),this._outlineArr=Ne(this._outlineArr,e.outlineArr),this._outlineColorArr=Ne(this._outlineColorArr,e.outlineColorArr),this._pickingColorArr=Ne(this._pickingColorArr,e.pickingColorArr),t.update(),this.refresh())}clear(){this._texCoordArr=null,this._gliphParamArr=null,this._vertexArr=null,this._positionHighArr=null,this._positionLowArr=null,this._sizeArr=null,this._offsetArr=null,this._rgbaArr=null,this._rotationArr=null,this._fontIndexArr=null,this._outlineArr=null,this._outlineColorArr=null,this._texCoordArr=new Float32Array([]),this._gliphParamArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._fontIndexArr=new Float32Array([]),this._outlineArr=new Float32Array([]),this._outlineColorArr=new Float32Array([]),this._removeBillboards(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e.deleteBuffer(this._gliphParamBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._fontIndexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._outlineBuffer),e.deleteBuffer(this._outlineColorBuffer),e.deleteBuffer(this._positionHighBuffer),e.deleteBuffer(this._positionLowBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._offsetBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._rotationBuffer),e.deleteBuffer(this._vertexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._pickingColorBuffer),this._gliphParamBuffer=null,this._sizeBuffer=null,this._fontIndexBuffer=null,this._texCoordBuffer=null,this._outlineBuffer=null,this._outlineColorBuffer=null,this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._vertexBuffer=null,this._texCoordBuffer=null,this._pickingColorBuffer=null}}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.label.activate();let i=t.programs.label._program,n=i.attributes,r=i.uniforms,s=t.gl,a=this._entityCollection;s.disable(s.CULL_FACE),s.uniform1iv(r.fontTextureArr,e.fontAtlas.samplerArr),s.uniform4fv(r.sdfParamsArr,e.fontAtlas.sdfParamsArr),s.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),s.uniform3fv(r.scaleByDistance,a.scaleByDistance),s.uniform1f(r.opacity,a._fadingOpacity),s.uniform1f(r.planetRadius,a.renderNode._planetRadius2||0),s.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),s.bindBuffer(s.ARRAY_BUFFER,this._texCoordBuffer),s.vertexAttribPointer(n.a_texCoord,this._texCoordBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._gliphParamBuffer),s.vertexAttribPointer(n.a_gliphParam,this._gliphParamBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._vertexBuffer),s.vertexAttribPointer(n.a_vertices,this._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionHighBuffer),s.vertexAttribPointer(n.a_positionsHigh,this._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionLowBuffer),s.vertexAttribPointer(n.a_positionsLow,this._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._sizeBuffer),s.vertexAttribPointer(n.a_size,this._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._rotationBuffer),s.vertexAttribPointer(n.a_rotation,this._rotationBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._offsetBuffer),s.vertexAttribPointer(n.a_offset,this._offsetBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._fontIndexBuffer),s.vertexAttribPointer(n.a_fontIndex,this._fontIndexBuffer.itemSize,s.FLOAT,!1,0,0),s.uniform1i(r.isOutlinePass,1),s.uniform1f(r.depthOffset,a.polygonOffsetUnits),s.bindBuffer(s.ARRAY_BUFFER,this._outlineColorBuffer),s.vertexAttribPointer(n.a_rgba,this._outlineColorBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._outlineBuffer),s.vertexAttribPointer(n.a_outline,this._outlineBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.depthFunc(s.EQUAL),s.uniform1i(r.isOutlinePass,0),s.uniform1f(r.depthOffset,a.polygonOffsetUnits),s.bindBuffer(s.ARRAY_BUFFER,this._rgbaBuffer),s.vertexAttribPointer(n.a_rgba,this._rgbaBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.depthFunc(s.LESS),s.enable(s.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.labelPicking.activate();let i=t.programs.labelPicking._program,n=i.attributes,r=i.uniforms,s=t.gl,a=this._entityCollection,o=a.renderNode;s.disable(s.CULL_FACE),s.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),s.uniform3fv(r.scaleByDistance,a.scaleByDistance),s.uniform1f(r.opacity,a._fadingOpacity),s.uniform1f(r.planetRadius,o._planetRadius2||0),s.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),s.bindBuffer(s.ARRAY_BUFFER,this._texCoordBuffer),s.vertexAttribPointer(n.a_texCoord,this._texCoordBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._gliphParamBuffer),s.vertexAttribPointer(n.a_gliphParam,this._gliphParamBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._vertexBuffer),s.vertexAttribPointer(n.a_vertices,this._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionHighBuffer),s.vertexAttribPointer(n.a_positionsHigh,this._positionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._positionLowBuffer),s.vertexAttribPointer(n.a_positionsLow,this._positionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._sizeBuffer),s.vertexAttribPointer(n.a_size,this._sizeBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._rotationBuffer),s.vertexAttribPointer(n.a_rotation,this._rotationBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._offsetBuffer),s.vertexAttribPointer(n.a_offset,this._offsetBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._pickingColorBuffer),s.vertexAttribPointer(n.a_rgba,this._pickingColorBuffer.itemSize,s.FLOAT,!1,0,0),s.uniform1f(r.depthOffset,a.polygonOffsetUnits),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.enable(s.CULL_FACE)}_removeBillboard(e){let t=e._handlerIndex;this._billboards.splice(t,1);let i=24*this._maxLetters,n=t*i;this._rgbaArr=Ge(this._rgbaArr,n,i),this._outlineColorArr=Ge(this._outlineColorArr,n,i),this._texCoordArr=Ge(this._texCoordArr,n,i),this._gliphParamArr=Ge(this._gliphParamArr,n,i),i=18*this._maxLetters,n=t*i,this._positionHighArr=Ge(this._positionHighArr,n,i),this._positionLowArr=Ge(this._positionLowArr,n,i),this._offsetArr=Ge(this._offsetArr,n,i),this._pickingColorArr=Ge(this._pickingColorArr,n,i),i=12*this._maxLetters,n=t*i,this._vertexArr=Ge(this._vertexArr,n,i),i=6*this._maxLetters,n=t*i,this._sizeArr=Ge(this._sizeArr,n,i),this._rotationArr=Ge(this._rotationArr,n,i),this._fontIndexArr=Ge(this._fontIndexArr,n,i),this._outlineArr=Ge(this._outlineArr,n,i),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1}setText(e,t,i,n,r=!1){t=t.normalize("NFKC");let s=this._renderer.fontAtlas.atlasesArr[i];if(!s)return;let a=24*e*this._maxLetters,o=this._texCoordArr,l=this._gliphParamArr,h=0,c=Math.min(this._maxLetters,t.length),d=0;r&&(d=1);let _=0,u=s.kernings;for(h=0;h<c;h++){let e=a+24*h,i=t[h],n=s.get(i.charCodeAt(0))||s.get(" ".charCodeAt(0));if(!n)continue;let r=n.texCoords,c=n.metrics;o[e]=r[0],o[e+1]=r[1],o[e+2]=_,o[e+3]=d,o[e+4]=r[2],o[e+5]=r[3],o[e+6]=_,o[e+7]=d,o[e+8]=r[4],o[e+9]=r[5],o[e+10]=_,o[e+11]=d,o[e+12]=r[6],o[e+13]=r[7],o[e+14]=_,o[e+15]=d,o[e+16]=r[8],o[e+17]=r[9],o[e+18]=_,o[e+19]=d,o[e+20]=r[10],o[e+21]=r[11],o[e+22]=_,o[e+23]=d,l[e]=c.nWidth,l[e+1]=c.nHeight,l[e+2]=c.nXOffset,l[e+3]=c.nYOffset,l[e+4]=c.nWidth,l[e+5]=c.nHeight,l[e+6]=c.nXOffset,l[e+7]=c.nYOffset,l[e+8]=c.nWidth,l[e+9]=c.nHeight,l[e+10]=c.nXOffset,l[e+11]=c.nYOffset,l[e+12]=c.nWidth,l[e+13]=c.nHeight,l[e+14]=c.nXOffset,l[e+15]=c.nYOffset,l[e+16]=c.nWidth,l[e+17]=c.nHeight,l[e+18]=c.nXOffset,l[e+19]=c.nYOffset,l[e+20]=c.nWidth,l[e+21]=c.nHeight,l[e+22]=c.nXOffset,l[e+23]=c.nYOffset;let f=u[i.charCodeAt(0)];if(f&&t[h+1]){let e=f[t[h+1].charCodeAt(0)];_+=e?c.nAdvance+e:c.nAdvance}else _+=c.nAdvance}if(n===mi.CENTER)for(_*=-.5,h=0;h<c;h++){let e=a+24*h;o[e+2]+=_,o[e+6]+=_,o[e+10]+=_,o[e+14]+=_,o[e+18]+=_,o[e+22]+=_}for(;h<this._maxLetters;h++){let e=a+24*h;o[e+3]=Yi,o[e+7]=Yi,o[e+11]=Yi,o[e+15]=Yi,o[e+19]=Yi,o[e+23]=Yi}this._changedBuffers[6]=!0}setPositionArr(e,t,i){let n=18*e*this._maxLetters,r=this._positionHighArr,s=t.x,a=t.y,o=t.z,l=this._positionLowArr,h=i.x,c=i.y,d=i.z;for(let e=0;e<this._maxLetters;e++){let t=n+18*e;r[t]=s,r[t+1]=a,r[t+2]=o,r[t+3]=s,r[t+4]=a,r[t+5]=o,r[t+6]=s,r[t+7]=a,r[t+8]=o,r[t+9]=s,r[t+10]=a,r[t+11]=o,r[t+12]=s,r[t+13]=a,r[t+14]=o,r[t+15]=s,r[t+16]=a,r[t+17]=o,l[t]=h,l[t+1]=c,l[t+2]=d,l[t+3]=h,l[t+4]=c,l[t+5]=d,l[t+6]=h,l[t+7]=c,l[t+8]=d,l[t+9]=h,l[t+10]=c,l[t+11]=d,l[t+12]=h,l[t+13]=c,l[t+14]=d,l[t+15]=h,l[t+16]=c,l[t+17]=d}this._changedBuffers[1]=!0}setPickingColorArr(e,t){let i=18*e*this._maxLetters,n=this._pickingColorArr,r=t.x/255,s=t.y/255,a=t.z/255;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;n[t]=r,n[t+1]=s,n[t+2]=a,n[t+3]=r,n[t+4]=s,n[t+5]=a,n[t+6]=r,n[t+7]=s,n[t+8]=a,n[t+9]=r,n[t+10]=s,n[t+11]=a,n[t+12]=r,n[t+13]=s,n[t+14]=a,n[t+15]=r,n[t+16]=s,n[t+17]=a}this._changedBuffers[0]=!0}setSizeArr(e,t){let i=6*e*this._maxLetters,n=this._sizeArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;n[r]=t,n[r+1]=t,n[r+2]=t,n[r+3]=t,n[r+4]=t,n[r+5]=t}this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e*this._maxLetters,n=this._offsetArr,r=t.x,s=t.y,a=t.z;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;n[t]=r,n[t+1]=s,n[t+2]=a,n[t+3]=r,n[t+4]=s,n[t+5]=a,n[t+6]=r,n[t+7]=s,n[t+8]=a,n[t+9]=r,n[t+10]=s,n[t+11]=a,n[t+12]=r,n[t+13]=s,n[t+14]=a,n[t+15]=r,n[t+16]=s,n[t+17]=a}this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e*this._maxLetters,n=this._rgbaArr,r=t.x,s=t.y,a=t.z,o=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;n[t]=r,n[t+1]=s,n[t+2]=a,n[t+3]=o,n[t+4]=r,n[t+5]=s,n[t+6]=a,n[t+7]=o,n[t+8]=r,n[t+9]=s,n[t+10]=a,n[t+11]=o,n[t+12]=r,n[t+13]=s,n[t+14]=a,n[t+15]=o,n[t+16]=r,n[t+17]=s,n[t+18]=a,n[t+19]=o,n[t+20]=r,n[t+21]=s,n[t+22]=a,n[t+23]=o}this._changedBuffers[4]=!0}setOutlineColorArr(e,t){let i=24*e*this._maxLetters,n=this._outlineColorArr,r=t.x,s=t.y,a=t.z,o=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;n[t]=r,n[t+1]=s,n[t+2]=a,n[t+3]=o,n[t+4]=r,n[t+5]=s,n[t+6]=a,n[t+7]=o,n[t+8]=r,n[t+9]=s,n[t+10]=a,n[t+11]=o,n[t+12]=r,n[t+13]=s,n[t+14]=a,n[t+15]=o,n[t+16]=r,n[t+17]=s,n[t+18]=a,n[t+19]=o,n[t+20]=r,n[t+21]=s,n[t+22]=a,n[t+23]=o}this._changedBuffers[10]=!0}setOutlineArr(e,t){let i=6*e*this._maxLetters,n=this._outlineArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;n[r]=t,n[r+1]=t,n[r+2]=t,n[r+3]=t,n[r+4]=t,n[r+5]=t}this._changedBuffers[9]=!0}setRotationArr(e,t){let i=6*e*this._maxLetters,n=this._rotationArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;n[r]=t,n[r+1]=t,n[r+2]=t,n[r+3]=t,n[r+4]=t,n[r+5]=t}this._changedBuffers[5]=!0}setVisibility(e,t){let i;i=t?[0,0,0,-1,1,-1,1,-1,1,0,0,0]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e*this._maxLetters,n=this._vertexArr;for(let e=0;e<this._maxLetters;e++){let r=i+12*e;n[r]=t[0],n[r+1]=t[1],n[r+2]=t[2],n[r+3]=t[3],n[r+4]=t[4],n[r+5]=t[5],n[r+6]=t[6],n[r+7]=t[7],n[r+8]=t[8],n[r+9]=t[9],n[r+10]=t[10],n[r+11]=t[11]}this._changedBuffers[7]=!0}setFontIndexArr(e,t){let i=6*e*this._maxLetters,n=this._fontIndexArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;n[r]=t,n[r+1]=t,n[r+2]=t,n[r+3]=t,n[r+4]=t,n[r+5]=t}this._changedBuffers[8]=!0}createSizeBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createArrayBuffer(this._sizeArr,1,this._sizeArr.length)}createFontIndexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._fontIndexBuffer),this._fontIndexBuffer=e.createArrayBuffer(this._fontIndexArr,1,this._fontIndexArr.length)}createTexCoordBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,4,this._texCoordArr.length/4),e.gl.deleteBuffer(this._gliphParamBuffer),this._gliphParamBuffer=e.createArrayBuffer(this._gliphParamArr,4,this._gliphParamArr.length/4)}createOutlineBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._outlineBuffer),this._outlineBuffer=e.createArrayBuffer(this._outlineArr,1,this._outlineArr.length)}createOutlineColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._outlineColorBuffer),this._outlineColorBuffer=e.createArrayBuffer(this._outlineColorArr,4,this._outlineColorArr.length/4)}setMaxLetters(e){this._maxLetters=e}}class Xi{constructor(e){this.pickingEnabled=!0,this.__id=Xi.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._pointClouds=[]}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.pointCloud||this._renderer.handler.addProgram(new zi("pointCloud",{uniforms:{projectionViewMatrix:"mat4",opacity:"float",pointSize:"float"},attributes:{coordinates:"vec3",colors:"vec3"},vertexShader:"attribute vec3 coordinates;\n attribute vec4 colors;\n uniform mat4 projectionViewMatrix;\n uniform float opacity;\n uniform float pointSize;\n varying vec4 color;\n void main() {\n color = colors;\n color.a *= opacity;\n gl_Position = projectionViewMatrix * vec4(coordinates, 1.0);\n gl_PointSize = pointSize;\n }",fragmentShader:"precision highp float;\n varying vec4 color;\n void main(void) {\n gl_FragColor = color;\n }"})))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._pointClouds.length;t++)this._pointClouds[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._pointClouds.length,this._pointClouds.push(e),this._entityCollection&&this._entityCollection.renderNode&&e.setRenderNode(this._entityCollection.renderNode))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._pointClouds.splice(t,1),this._reindexPointCloudArray(t))}_reindexPointCloudArray(e){let t=this._pointClouds;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e].drawPicking()}}clear(){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e]._deleteBuffers(),this._pointClouds[e]._handler=null,this._pointClouds[e]._handlerIndex=-1;this._pointClouds.length=0,this._pointClouds=[]}}Xi.__counter__=0;class $i{constructor(e){this.__id=$i.__counter__++,this._entityCollection=e,this._renderer=null,this._polylines=[],this.pickingEnabled=!0}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.polyline_screen||this._renderer.handler.addProgram(new zi("polyline_screen",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",uFloatParams:"vec2",thickness:"float",opacity:"float",depthOffset:"float"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float",color:"vec4"},vertexShader:"precision highp float;\n\n attribute vec3 prevHigh;\n attribute vec3 currentHigh;\n attribute vec3 nextHigh;\n\n attribute vec3 prevLow;\n attribute vec3 currentLow;\n attribute vec3 nextLow;\n\n attribute float order;\n\n attribute vec4 color;\n\n uniform float thickness;\n uniform mat4 proj;\n uniform mat4 view;\n uniform vec2 viewport;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float opacity;\n uniform float depthOffset;\n\n varying vec4 vColor;\n varying vec3 vPos;\n varying vec3 uCamPos;\n\n const float NEAR = -1.0;\n\n vec2 getIntersection(vec2 start1, vec2 end1, vec2 start2, vec2 end2){\n vec2 dir = end2 - start2;\n vec2 perp = vec2(-dir.y, dir.x);\n float d2 = dot(perp, start2);\n float seg = dot(perp, start1) - d2;\n float prl = seg - dot(perp, end1) + d2;\n if(prl > -1.0 && prl < 1.0){\n return start1;\n }\n float u = seg / prl;\n return start1 + u * (end1 - start1);\n }\n\n vec2 project(vec4 p){\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }\n\n void main(){\n\n uCamPos = eyePositionHigh + eyePositionLow;\n\n vColor = vec4(color.rgb, color.a * opacity);\n\n vec3 current = currentHigh + currentLow;\n\n vPos = current;\n\n mat4 viewMatrixRTE = view;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff, lowDiff;\n\n highDiff = currentHigh - eyePositionHigh;\n lowDiff = currentLow - eyePositionLow;\n vec4 vCurrent = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = prevHigh - eyePositionHigh;\n lowDiff = prevLow - eyePositionLow;\n vec4 vPrev = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = nextHigh - eyePositionHigh;\n lowDiff = nextLow - eyePositionLow;\n vec4 vNext = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n /*Clip near plane, the point behind view plane*/\n if(vCurrent.z > NEAR) {\n if(vPrev.z < NEAR && abs(order) == 1.0){\n vCurrent = vPrev + (vCurrent - vPrev) * (NEAR - vPrev.z) / (vCurrent.z - vPrev.z);\n } else if(vNext.z < NEAR && abs(order) == 2.0){\n vCurrent = vNext + (vCurrent - vNext) * (NEAR - vNext.z) / (vCurrent.z - vNext.z);\n }\n }\n\n vec4 dCurrent = proj * vCurrent;\n vec2 _next = project(proj * vNext);\n vec2 _prev = project(proj * vPrev);\n vec2 _current = project(dCurrent);\n\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n\n vec2 sNext = _next,\n sCurrent = _current,\n sPrev = _prev;\n\n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n\n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n\n float d = thickness * sign(order);\n\n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n m = getIntersection( sCurrent + normalPrev * d, sPrev + normalPrev * d,\n sCurrent + normalNext * d, sNext + normalNext * d );\n\n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n\n gl_Position = vec4((2.0 * m / viewport - 1.0) * dCurrent.w, dCurrent.z + depthOffset, dCurrent.w);\n }",fragmentShader:"precision highp float;\n uniform vec2 uFloatParams;\n varying vec3 uCamPos;\n varying vec4 vColor;\n varying vec3 vPos;\n void main() {\n vec3 look = vPos - uCamPos;\n float lookLength = length(look);\n float a = vColor.a * step(lookLength, sqrt(dot(uCamPos,uCamPos) - uFloatParams[0]) + sqrt(dot(vPos,vPos) - uFloatParams[0]));\n gl_FragColor = vec4(vColor.rgb, a);\n }"})),this._renderer.handler.programs.polyline_picking||this._renderer.handler.addProgram(new zi("polyline_picking",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",uFloatParams:"vec2",color:"vec4",thickness:"float",depthOffset:"float"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float"},vertexShader:"precision highp float;\n \n attribute vec3 prevHigh;\n attribute vec3 currentHigh;\n attribute vec3 nextHigh;\n \n attribute vec3 prevLow;\n attribute vec3 currentLow;\n attribute vec3 nextLow;\n\n attribute float order;\n\n uniform float thickness;\n uniform vec4 color;\n uniform mat4 proj;\n uniform mat4 view;\n uniform vec2 viewport;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float depthOffset;\n\n varying vec4 vColor;\n varying vec3 vPos;\n varying vec3 uCamPos;\n \n \n const float NEAR = -1.0;\n \n vec2 getIntersection(vec2 start1, vec2 end1, vec2 start2, vec2 end2){\n vec2 dir = end2 - start2;\n vec2 perp = vec2(-dir.y, dir.x);\n float d2 = dot(perp, start2);\n float seg = dot(perp, start1) - d2;\n float prl = seg - dot(perp, end1) + d2;\n if(prl > -1.0 && prl < 1.0){\n return start1;\n }\n float u = seg / prl;\n return start1 + u * (end1 - start1);\n }\n \n vec2 project(vec4 p){\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }\n \n void main(){\n\n uCamPos = eyePositionHigh + eyePositionLow;\n\n vColor = color;\n\n vec3 current = currentHigh + currentLow;\n\n vPos = current; \n\n vec3 highDiff, lowDiff;\n\n mat4 viewMatrixRTE = view;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n highDiff = currentHigh - eyePositionHigh;\n lowDiff = currentLow - eyePositionLow;\n vec4 vCurrent = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = prevHigh - eyePositionHigh;\n lowDiff = prevLow - eyePositionLow; \n vec4 vPrev = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = nextHigh - eyePositionHigh;\n lowDiff = nextLow - eyePositionLow; \n vec4 vNext = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n /*Clip near plane*/\n if(vCurrent.z > NEAR) {\n if(vPrev.z < NEAR && abs(order) == 1.0){\n vCurrent = vPrev + (vCurrent - vPrev) * (NEAR - vPrev.z) / (vCurrent.z - vPrev.z);\n } else if(vNext.z < NEAR && abs(order) == 2.0){\n vCurrent = vNext + (vCurrent - vNext) * (NEAR - vNext.z) / (vCurrent.z - vNext.z);\n }\n }\n \n vec4 dCurrent = proj * vCurrent;\n vec2 _next = project(proj * vNext);\n vec2 _prev = project(proj * vPrev);\n vec2 _current = project(dCurrent);\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n \n vec2 sNext = _next,\n sCurrent = _current,\n sPrev = _prev;\n\n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n \n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n \n float d = thickness * sign(order);\n \n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n m = getIntersection( sCurrent + normalPrev * d, sPrev + normalPrev * d,\n sCurrent + normalNext * d, sNext + normalNext * d );\n \n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }\n else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n gl_Position = vec4((2.0 * m / viewport - 1.0) * dCurrent.w, dCurrent.z + depthOffset, dCurrent.w);\n }",fragmentShader:"precision highp float;\n uniform vec2 uFloatParams;\n varying vec3 uCamPos;\n varying vec4 vColor;\n varying vec3 vPos;\n void main() {\n vec3 look = vPos - uCamPos;\n float lookLength = length(look);\n float a = vColor.a * step(lookLength, sqrt(dot(uCamPos,uCamPos) - uFloatParams[0]) + sqrt(dot(vPos,vPos) - uFloatParams[0])); \n gl_FragColor = vec4(vColor.rgb, a);\n }"})))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._polylines.length;t++)this._polylines[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._polylines.length,this._polylines.push(e),this._entityCollection&&this._entityCollection.renderNode&&e.setRenderNode(this._entityCollection.renderNode))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._polylines.splice(t,1),this.reindexPolylineArray(t))}reindexPolylineArray(e){let t=this._polylines;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){let e=this._polylines.length;for(;e--;)this._polylines[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._polylines.length;for(;e--;)this._polylines[e].drawPicking()}}clear(){let e=this._polylines.length;for(;e--;)this._polylines[e]._deleteBuffers(),this._polylines[e]._handler=null,this._polylines[e]._handlerIndex=-1;this._polylines.length=0,this._polylines=[]}}$i.__counter__=0;class Zi{constructor(e){this.__id=Zi.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._rays=[],this._vertexBuffer=null,this._startPositionHighBuffer=null,this._startPositionLowBuffer=null,this._endPositionHighBuffer=null,this._endPositionLowBuffer=null,this._thicknessBuffer=null,this._rgbaBuffer=null,this._pickingColorBuffer=null,this._vertexArr=[],this._startPositionHighArr=[],this._startPositionLowArr=[],this._endPositionHighArr=[],this._endPositionLowArr=[],this._thicknessArr=[],this._rgbaArr=[],this._pickingColorArr=[],this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[5]=this.createVertexBuffer,this._buffersUpdateCallbacks[1]=this.createStartPositionBuffer,this._buffersUpdateCallbacks[2]=this.createEndPositionBuffer,this._buffersUpdateCallbacks[4]=this.createThicknessBuffer,this._buffersUpdateCallbacks[3]=this.createRgbaBuffer,this._buffersUpdateCallbacks[0]=this.createPickingColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}static concArr(e,t){for(let i=0;i<t.length;i++)e.push(t[i])}initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.rayScreen||this._renderer.handler.addProgram(new zi("rayScreen",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",resolution:"float",uOpacity:"float"},attributes:{a_vertices:"vec2",a_startPosHigh:"vec3",a_startPosLow:"vec3",a_endPosHigh:"vec3",a_endPosLow:"vec3",a_thickness:"float",a_rgba:"vec4"},vertexShader:"precision highp float;\n\n attribute vec4 a_rgba;\n attribute vec3 a_startPosHigh;\n attribute vec3 a_startPosLow;\n attribute vec3 a_endPosHigh;\n attribute vec3 a_endPosLow;\n attribute vec2 a_vertices;\n attribute float a_thickness;\n\n varying vec4 v_rgba;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float resolution;\n uniform float uOpacity;\n\n void main() {\n\n v_rgba = vec4(a_rgba.rgb, a_rgba.a * uOpacity);\n\n vec3 v = (a_endPosHigh - a_startPosHigh) + (a_endPosLow - a_startPosLow);\n\n vec3 look = (a_startPosHigh - eyePositionHigh) + (a_startPosLow - eyePositionLow) + v * a_vertices.y;\n vec3 up = normalize(normalize(v));\n vec3 right = normalize(cross(look,up));\n \n float dist = dot(look, vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]));\n float focalSize = 2.0 * dist * resolution;\n vec3 vert = right * a_thickness * focalSize * a_vertices.x;\n\n vec3 highDiff;\n if(a_vertices.y == 0.0){\n highDiff = a_startPosHigh - eyePositionHigh;\n vert += a_startPosLow - eyePositionLow;\n }else{\n highDiff = a_endPosHigh - eyePositionHigh;\n vert += a_endPosLow - eyePositionLow;\n }\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n // Hack for iMac M1, looks like it doesnt \n // work correctly with zeroes in highDiff\n // if(length(highDiff) < 1.0){\n // highDiff = vec3(0.0);\n // }\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + vert, 1.0);\n }",fragmentShader:"precision highp float;\n varying vec4 v_rgba;\n void main () {\n gl_FragColor = v_rgba;\n }"})))}setRenderer(e){this._renderer=e,this.initProgram()}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_removeRays(){let e=this._rays.length;for(;e--;){let t=this._rays[e];t._handlerIndex=-1,t._handler=null}this._rays.length=0,this._rays=[]}clear(){this._vertexArr=null,this._startPositionHighArr=null,this._startPositionLowArr=null,this._endPositionHighArr=null,this._endPositionLowArr=null,this._thicknessArr=null,this._rgbaArr=null,this._vertexArr=new Float32Array([]),this._startPositionHighArr=new Float32Array([]),this._startPositionLowArr=new Float32Array([]),this._endPositionHighArr=new Float32Array([]),this._endPositionLowArr=new Float32Array([]),this._thicknessArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._removeRays(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e&&(e.deleteBuffer(this._startPositionHighBuffer),e.deleteBuffer(this._startPositionLowBuffer),e.deleteBuffer(this._endPositionHighBuffer),e.deleteBuffer(this._endPositionLowBuffer),e.deleteBuffer(this._thicknessBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._vertexBuffer)),this._startPositionHighBuffer=null,this._startPositionLowBuffer=null,this._endPositionHighBuffer=null,this._endPositionLowBuffer=null,this._thicknessBuffer=null,this._rgbaBuffer=null,this._vertexBuffer=null}}update(){if(this._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}add(e){-1==e._handlerIndex&&(e._handler=this,e._handlerIndex=this._rays.length,this._rays.push(e),this._addRayToArrays(e),this.refresh())}_addRayToArrays(e){e.getVisibility()?this._vertexArr=He(this._vertexArr,[-.5,1,-.5,0,.5,0,.5,0,.5,1,-.5,1]):this._vertexArr=He(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t=e._startPositionHigh.x,i=e._startPositionHigh.y,n=e._startPositionHigh.z;this._startPositionHighArr=He(this._startPositionHighArr,[t,i,n,t,i,n,t,i,n,t,i,n,t,i,n,t,i,n]),t=e._startPositionLow.x,i=e._startPositionLow.y,n=e._startPositionLow.z,this._startPositionLowArr=He(this._startPositionLowArr,[t,i,n,t,i,n,t,i,n,t,i,n,t,i,n,t,i,n]),t=e._endPositionHigh.x,i=e._endPositionHigh.y,n=e._endPositionHigh.z,this._endPositionHighArr=He(this._endPositionHighArr,[t,i,n,t,i,n,t,i,n,t,i,n,t,i,n,t,i,n]),t=e._endPositionLow.x,i=e._endPositionLow.y,n=e._endPositionLow.z,this._endPositionLowArr=He(this._endPositionLowArr,[t,i,n,t,i,n,t,i,n,t,i,n,t,i,n,t,i,n]),t=e._thickness,this._thicknessArr=He(this._thicknessArr,[t,t,t,t,t,t]);let r=e._startColor.x,s=e._startColor.y,a=e._startColor.z,o=e._startColor.w,l=e._endColor.x,h=e._endColor.y,c=e._endColor.z,d=e._endColor.w;this._rgbaArr=He(this._rgbaArr,[l,h,c,d,r,s,a,o,r,s,a,o,r,s,a,o,l,h,c,d,l,h,c,d]),t=e._entity._pickingColor.x/255,i=e._entity._pickingColor.y/255,n=e._entity._pickingColor.z/255,this._pickingColorArr=He(this._pickingColorArr,[t,i,n,t,i,n,t,i,n,t,i,n,t,i,n,t,i,n])}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.rayScreen.activate();let i=t.programs.rayScreen._program,n=i.attributes,r=i.uniforms,s=t.gl,a=this._entityCollection;s.disable(s.CULL_FACE),s.uniform1f(r.uOpacity,a._fadingOpacity),s.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),s.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),s.uniform1f(r.resolution,e.activeCamera._tanViewAngle_hradOneByHeight),s.bindBuffer(s.ARRAY_BUFFER,this._startPositionHighBuffer),s.vertexAttribPointer(n.a_startPosHigh,this._startPositionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._startPositionLowBuffer),s.vertexAttribPointer(n.a_startPosLow,this._startPositionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._endPositionHighBuffer),s.vertexAttribPointer(n.a_endPosHigh,this._endPositionHighBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._endPositionLowBuffer),s.vertexAttribPointer(n.a_endPosLow,this._endPositionLowBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._rgbaBuffer),s.vertexAttribPointer(n.a_rgba,this._rgbaBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._thicknessBuffer),s.vertexAttribPointer(n.a_thickness,this._thicknessBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._vertexBuffer),s.vertexAttribPointer(n.a_vertices,this._vertexBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLES,0,this._vertexBuffer.numItems),s.enable(s.CULL_FACE)}_pickingPASS(){}draw(){this._rays.length&&(this.update(),this._displayPASS())}drawPicking(){this._rays.length&&this.pickingEnabled&&this._pickingPASS()}reindexRaysArray(e){let t=this._rays;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}_removeRay(e){let t=e._handlerIndex;this._rays.splice(t,1);let i=24*t;this._rgbaArr=Ue(this._rgbaArr,i,24),i=18*t,this._startPositionHighArr=Ue(this._startPositionHighArr,i,18),this._startPositionLowArr=Ue(this._startPositionLowArr,i,18),this._endPositionHighArr=Ue(this._endPositionHighArr,i,18),this._endPositionLowArr=Ue(this._endPositionLowArr,i,18),this._pickingColorArr=Ue(this._pickingColorArr,i,18),i=12*t,this._vertexArr=Ue(this._vertexArr,i,12),i=6*t,this._thicknessArr=Ue(this._thicknessArr,i,6),this.reindexRaysArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null}remove(e){e._handler&&this.__id===e._handler.__id&&this._removeRay(e)}setStartPositionArr(e,t,i){let n=18*e,r=this._startPositionHighArr,s=t.x,a=t.y,o=t.z;r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,r=this._startPositionLowArr,s=i.x,a=i.y,o=i.z,r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,this._changedBuffers[1]=!0}setEndPositionArr(e,t,i){let n=18*e,r=this._endPositionHighArr,s=t.x,a=t.y,o=t.z;r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,r=this._endPositionLowArr,s=i.x,a=i.y,o=i.z,r[n]=s,r[n+1]=a,r[n+2]=o,r[n+3]=s,r[n+4]=a,r[n+5]=o,r[n+6]=s,r[n+7]=a,r[n+8]=o,r[n+9]=s,r[n+10]=a,r[n+11]=o,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=s,r[n+16]=a,r[n+17]=o,this._changedBuffers[2]=!0}setPickingColorArr(e,t){let i=18*e,n=this._pickingColorArr,r=t.x/255,s=t.y/255,a=t.z/255;n[i]=r,n[i+1]=s,n[i+2]=a,n[i+3]=r,n[i+4]=s,n[i+5]=a,n[i+6]=r,n[i+7]=s,n[i+8]=a,n[i+9]=r,n[i+10]=s,n[i+11]=a,n[i+12]=r,n[i+13]=s,n[i+14]=a,n[i+15]=r,n[i+16]=s,n[i+17]=a,this._changedBuffers[0]=!0}setRgbaArr(e,t,i){let n=24*e,r=this._rgbaArr,s=t.x,a=t.y,o=t.z,l=t.w,h=i.x,c=i.y,d=i.z,_=i.w;r[n]=h,r[n+1]=c,r[n+2]=d,r[n+3]=_,r[n+4]=s,r[n+5]=a,r[n+6]=o,r[n+7]=l,r[n+8]=s,r[n+9]=a,r[n+10]=o,r[n+11]=l,r[n+12]=s,r[n+13]=a,r[n+14]=o,r[n+15]=l,r[n+16]=h,r[n+17]=c,r[n+18]=d,r[n+19]=_,r[n+20]=h,r[n+21]=c,r[n+22]=d,r[n+23]=_,this._changedBuffers[3]=!0}setThicknessArr(e,t){let i=6*e,n=this._thicknessArr;n[i]=t,n[i+1]=t,n[i+2]=t,n[i+3]=t,n[i+4]=t,n[i+5]=t,this._changedBuffers[4]=!0}setVisibility(e,t){let i;i=t?[-.5,1,-.5,0,.5,0,.5,0,.5,1,-.5,1]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e,n=this._vertexArr;n[i]=t[0],n[i+1]=t[1],n[i+2]=t[2],n[i+3]=t[3],n[i+4]=t[4],n[i+5]=t[5],n[i+6]=t[6],n[i+7]=t[7],n[i+8]=t[8],n[i+9]=t[9],n[i+10]=t[10],n[i+11]=t[11],this._changedBuffers[5]=!0}createStartPositionBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._startPositionHighBuffer),this._startPositionHighArr=Oe(this._startPositionHighArr),this._startPositionHighBuffer=e.createArrayBuffer(this._startPositionHighArr,3,this._startPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._startPositionLowBuffer),this._startPositionLowArr=Oe(this._startPositionLowArr),this._startPositionLowBuffer=e.createArrayBuffer(this._startPositionLowArr,3,this._startPositionLowArr.length/3,e.gl.DYNAMIC_DRAW)}createEndPositionBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._endPositionHighBuffer),this._endPositionHighArr=Oe(this._endPositionHighArr),this._endPositionHighBuffer=e.createArrayBuffer(this._endPositionHighArr,3,this._endPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._endPositionLowBuffer),this._endPositionLowArr=Oe(this._endPositionLowArr),this._endPositionLowBuffer=e.createArrayBuffer(this._endPositionLowArr,3,this._endPositionLowArr.length/3,e.gl.DYNAMIC_DRAW)}createRgbaBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaArr=Oe(this._rgbaArr),this._rgbaBuffer=e.createArrayBuffer(this._rgbaArr,4,this._rgbaArr.length/4)}createThicknessBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._thicknessBuffer),this._thicknessArr=Oe(this._thicknessArr),this._thicknessBuffer=e.createArrayBuffer(this._thicknessArr,1,this._thicknessArr.length,e.gl.DYNAMIC_DRAW)}createVertexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexArr=Oe(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,2,this._vertexArr.length/2,e.gl.DYNAMIC_DRAW)}createPickingColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=Oe(this._pickingColorArr),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}}Zi.__counter__=0;class Ki{constructor(e){this.__id=Ki.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._strips=[]}_initProgram(){this._renderer&&this._renderer.handler&&!this._renderer.handler.programs.strip&&this._renderer.handler.addProgram(new zi("strip",{uniforms:{projectionMatrix:{type:"mat4"},viewMatrix:{type:"mat4"},eyePositionHigh:"vec3",eyePositionLow:"vec3",uColor:{type:"vec4"},uOpacity:{type:"float"}},attributes:{aVertexPositionHigh:{type:"vec3"},aVertexPositionLow:{type:"vec3"}},vertexShader:"attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n void main(void) {\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:"precision highp float;\n uniform vec4 uColor;\n uniform float uOpacity;\n void main(void) {\n gl_FragColor = vec4(uColor.rgb, uColor.a * uOpacity);\n }"}))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._strips.length;t++)this._strips[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._strips.length,this._strips.push(e),this._entityCollection&&this._entityCollection.renderNode&&e.setRenderNode(this._entityCollection.renderNode))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._strips.splice(t,1),this.reindexStripArray(t))}reindexStripArray(e){let t=this._strips;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){let e=this._strips.length;for(;e--;)this._strips[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._strips.length;for(;e--;)this._strips[e].drawPicking()}}clear(){let e=this._strips.length;for(;e--;)this._strips[e]._deleteBuffers(),this._strips[e]._handler=null,this._strips[e]._handlerIndex=-1;this._strips.length=0,this._strips=[]}}Ki.__counter__=0;class Qi{constructor(e={}){this.__id=Qi.__counter__++,this._renderNodeIndex=-1,this.renderNode=null,this._visibility=null==e.visibility||e.visibility,this.polygonOffsetUnits=null!=e.polygonOffsetUnits?e.polygonOffsetUnits:0,this.billboardHandler=new Hi(this),this.labelHandler=new qi(this,e.labelMaxLetters),this.polylineHandler=new $i(this),this.rayHandler=new Zi(this),this.pointCloudHandler=new Xi(this),this.stripHandler=new Ki(this),this.geoObjectHandler=new Ui(this),null!=e.pickingEnabled&&this.setPickingEnabled(e.pickingEnabled),this._entities=[],this.scaleByDistance=e.scaleByDistance||[r,r,r],this.pickingScale=e.pickingScale||1,this._opacity=null==e.opacity?1:e.opacity,this._fadingOpacity=this._opacity,this.events=this.rendererEvents=Pt(Ji,this),e.entities&&this.addEntities(e.entities)}get id(){return this.__id}isEqual(e){return this.__id===e.__id}setVisibility(e){this._visibility=e,this._fadingOpacity=this._opacity*(e?1:0),this.events.dispatch(this.events.visibilitychange,this)}getVisibility(){return this._visibility}setOpacity(e){this._opacity=e}setPickingEnabled(e){this.billboardHandler.pickingEnabled=e,this.labelHandler.pickingEnabled=e,this.polylineHandler.pickingEnabled=e,this.rayHandler.pickingEnabled=e,this.pointCloudHandler.pickingEnabled=e,this.stripHandler.pickingEnabled=e,this.geoObjectHandler.pickingEnabled=e}getOpacity(){return this._opacity}setScaleByDistance(e,t,i){this.scaleByDistance[0]=e,this.scaleByDistance[1]=t,this.scaleByDistance[2]=i||r}appendChildEntity(e){this._addRecursively(e)}_addRecursively(e){e.billboard&&this.billboardHandler.add(e.billboard),e.label&&this.labelHandler.add(e.label),e.polyline&&this.polylineHandler.add(e.polyline),e.ray&&this.rayHandler.add(e.ray),e.pointCloud&&this.pointCloudHandler.add(e.pointCloud),e.strip&&this.stripHandler.add(e.strip),e.geoObject&&this.geoObjectHandler.add(e.geoObject),this.events.dispatch(this.events.entityadd,e);for(let t=0;t<e.childrenNodes.length;t++)e.childrenNodes[t]._entityCollection=this,e.childrenNodes[t]._entityCollectionIndex=e._entityCollectionIndex,e.childrenNodes[t]._pickingColor=e._pickingColor,this._addRecursively(e.childrenNodes[t])}add(e){if(!e._entityCollection){e._entityCollection=this,e._entityCollectionIndex=this._entities.length,this._entities.push(e);let t=this.renderNode;t&&(t.renderer&&t.renderer.assignPickingColor(e),t.ellipsoid&&e._cartesian.isZero()&&e.setCartesian3v(t.ellipsoid.lonLatToCartesian(e._lonLat))),this._addRecursively(e),e.setPickingColor()}return this}addEntities(e){for(let t=0,i=e.length;t<i;t++)this.add(e[t]);return this}belongs(e){return e._entityCollection&&this._renderNodeIndex===e._entityCollection._renderNodeIndex}_removeRecursively(e){e._entityCollection=null,e._entityCollectionIndex=-1,e.billboard&&this.billboardHandler.remove(e.billboard),e.label&&this.labelHandler.remove(e.label),e.polyline&&this.polylineHandler.remove(e.polyline),e.ray&&this.rayHandler.remove(e.ray),e.pointCloud&&this.pointCloudHandler.remove(e.pointCloud),e.strip&&this.stripHandler.remove(e.strip),e.geoObject&&this.geoObjectHandler.remove(e.geoObject);for(let t=0;t<e.childrenNodes.length;t++)this._removeRecursively(e.childrenNodes[t])}removeEntity(e){this._entities.splice(e._entityCollectionIndex,1),this.reindexEntitiesArray(e._entityCollectionIndex),this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(e),e._pickingColor.clear()),this.belongs(e)&&this._removeRecursively(e),this.events.dispatch(this.events.entityremove,e)}_removeEntitySilent(e){this._entities.splice(e._entityCollectionIndex,1),this.reindexEntitiesArray(e._entityCollectionIndex),this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(e),e._pickingColor.clear()),this.belongs(e)&&this._removeRecursively(e)}createPickingColors(){if(!this.renderNode||!this.renderNode.renderer)return;let e=this._entities;for(let t=0;t<e.length;t++)e[t].parent||(this.renderNode.renderer.assignPickingColor(e[t]),e[t].setPickingColor())}reindexEntitiesArray(e){let t=this._entities;for(let i=e;i<t.length;i++)t[i]._entityCollectionIndex=i}addTo(e,t=!1){return this.renderNode||(this.renderNode=e,t||(this._renderNodeIndex=e.entityCollections.length,e.entityCollections.push(this)),e.ellipsoid&&this._updateGeodeticCoordinates(e.ellipsoid),this.bindRenderNode(e),this.events.dispatch(this.events.add,this)),this}bindRenderNode(e){e.renderer&&e.renderer.isInitialized()&&(this.billboardHandler.setRenderer(e.renderer),this.labelHandler.setRenderer(e.renderer),this.rayHandler.setRenderer(e.renderer),this.geoObjectHandler.setRenderNode(e),this.polylineHandler.setRenderNode(e),this.pointCloudHandler.setRenderNode(e),this.stripHandler.setRenderNode(e),this.updateBillboardsTextureAtlas(),this.updateLabelsFontAtlas(),this.createPickingColors())}_updateGeodeticCoordinates(e){let t=this._entities,i=t.length;for(;i--;){let n=t[i];n._lonLat&&n.setCartesian3v(e.lonLatToCartesian(n._lonLat))}}updateBillboardsTextureAtlas(){let e=this.billboardHandler.billboards;for(let t=0;t<e.length;t++)e[t].setSrc(e[t].getSrc())}updateLabelsFontAtlas(){this.renderNode&&this.labelHandler.updateFonts()}remove(){if(this.renderNode){if(-1!==this._renderNodeIndex){this.renderNode.entityCollections.splice(this._renderNodeIndex,1);for(let e=this._renderNodeIndex;e<this.renderNode.entityCollections.length;e++)this.renderNode.entityCollections[e]._renderNodeIndex=e}this.renderNode=null,this._renderNodeIndex=-1,this.events.dispatch(this.events.remove,this)}}getEntities(){return[].concat(this._entities)}each(e){let t=this._entities.length;for(;t--;){let i=this._entities[t];i&&e(i)}}clear(){this.billboardHandler.clear(),this.labelHandler.clear(),this.polylineHandler.clear(),this.rayHandler.clear(),this.pointCloudHandler.clear(),this.stripHandler.clear(),this.geoObjectHandler.clear();let e=this._entities.length;for(;e--;){let t=this._entities[e];this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(t),t._pickingColor.clear()),this._clearEntity(t)}this._entities.length=0,this._entities=[]}_clearEntity(e){e._entityCollection=null,e._entityCollectionIndex=-1;for(let t=0;t<e.childrenNodes.length;t++)this._clearEntity(e.childrenNodes[t])}}Qi.__counter__=0;const Ji=["draw","drawend","add","remove","entityadd","entityremove","visibilitychange","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];class en{constructor(e,t,i,n,r,s){this.layer=e,this.parentNode=i,this.childrenNodes=[],this.partId=t,this.nodeId=t+(i?4*i.nodeId+1:0),this.state=null,this.extent=n,this.count=0,this.deferredEntities=[],this.entityCollection=null,this.zoom=s,this._inTheQueue=!1,this.bsphere=new At,r&&this._setExtentBounds()}insertEntity(e,t=!1){this.buildTree([e],t)}_addEntitiesToCollection(e,t=!1){if(e.length){const i=this.layer,n=i._planet;let r=this.entityCollection;r||(r=new Qi({pickingEnabled:i._pickingEnabled,labelMaxLetters:i.labelMaxLetters}),r._layer=this.layer,r.addTo(n,!0),r._quadNode=this,i._bindEventsDefault(r),this.entityCollection=r),t||!i.async?this.entityCollection.addEntities(e):this.deferredEntities.push.apply(this.deferredEntities,e)}}_setExtentBounds(){this.nodeId?this.bsphere.setFromExtent(this.layer._planet.ellipsoid,this.extent.inverseMercator()):(this.bsphere.radius=this.layer._planet.ellipsoid.equatorialSize,this.bsphere.center=new oe)}__setLonLat__(e){return e._lonLat.isZero()&&!e._cartesian.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),Math.abs(e._lonLat.lat)<J?e._lonLatMerc=e._lonLat.forwardMercator():e._lonLatMerc=new z,e._lonLatMerc}buildTree(e,t=!1){if(this.count+=e.length,e.length>this.layer._nodeCapacity){const i=this.childrenNodes;i.length||this.createChildrenNodes();let n=[],r=[],s=[],a=[],o=e.length;for(;o--;){const t=e[o];i[0].isInside(t)?(t._nodePtr=i[0],n.push(t)):i[1].isInside(t)?(t._nodePtr=i[1],r.push(t)):i[2].isInside(t)?(t._nodePtr=i[2],s.push(t)):i[3].isInside(t)&&(t._nodePtr=i[3],a.push(t))}n.length&&i[0].buildTree(n,t),r.length&&i[1].buildTree(r,t),s.length&&i[2].buildTree(s,t),a.length&&i[3].buildTree(a,t)}else this._addEntitiesToCollection(e,t)}isInside(e){return!!e._lonLatMerc&&this.extent.isInside(e._lonLatMerc)}createChildrenNodes(){const e=this.layer,t=this.extent,i=.5*t.getWidth(),n=.5*t.getHeight(),r=t.northEast,s=t.southWest,a=new z(s.lon+i,s.lat+n),o=this.childrenNodes,l=this.layer._planet,h=this.zoom+1;o[0]=new en(e,0,this,new ie(new z(s.lon,s.lat+n),new z(s.lon+i,r.lat)),l,h),o[1]=new en(e,1,this,new ie(a,new z(r.lon,r.lat)),l,h),o[2]=new en(e,2,this,new ie(new z(s.lon,s.lat),a),l,h),o[3]=new en(e,3,this,new ie(new z(s.lon+i,s.lat),new z(r.lon,s.lat+n)),l,h)}collectRenderCollectionsPASS1(e,t){const i=e[this.nodeId];if(i){const n=this.childrenNodes;this.entityCollection?this.renderCollection(t,e):n.length&&(1===i.state?this.layer._secondPASS.push(this):(n[0].collectRenderCollectionsPASS1(e,t),n[1].collectRenderCollectionsPASS1(e,t),n[2].collectRenderCollectionsPASS1(e,t),n[3].collectRenderCollectionsPASS1(e,t)))}}collectRenderCollectionsPASS2(e,t,i){const n=this.layer._planet.camera,r=n.eye.distance(this.bsphere.center)-this.bsphere.radius<3570*Math.sqrt(n._lonLat.height)||n._lonLat.height>1e4;if(this.count>0&&r&&n.frustum.containsSphere(this.bsphere)){const n=this.childrenNodes;this.entityCollection?this.renderCollection(t,e,i):n.length&&(n[0].collectRenderCollectionsPASS2(e,t,i),n[1].collectRenderCollectionsPASS2(e,t,i),n[2].collectRenderCollectionsPASS2(e,t,i),n[3].collectRenderCollectionsPASS2(e,t,i))}}applyCollection(){this.entityCollection.addEntities(this.deferredEntities),this.deferredEntities.length=0,this.deferredEntities=[],this._inTheQueue=!1}traverseTree(e){const t=this.childrenNodes;this.entityCollection?e(this):t.length&&(t[0].traverseTree(e),t[1].traverseTree(e),t[2].traverseTree(e),t[3].traverseTree(e))}renderCollection(e,t,i){const n=this.layer;n._renderingNodes[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(n.async?n._queueDeferredNode(this):this.applyCollection());const r=this.entityCollection;if(r._fadingOpacity=n._fadingOpacity,r.scaleByDistance=n.scaleByDistance,r.pickingScale=n.pickingScale,r.polygonOffsetUnits=n.polygonOffsetUnits,e.push(r),n.clampToGround||n.relativeToGround){const e=r._entities;let s=e.length;if(t[this.nodeId]&&1===t[this.nodeId].state)for(;s--;){let i=e[s];this.alignEntityToTheGround(i,t[this.nodeId].segment)}else if(i)for(;s--;){let n=e[s];this.alignEntityToTheGround(n,t[i].segment)}else{const t=n._planet._renderedNodes;for(;s--;){let i=e[s],n=t.length;for(;n--;)if(t[n].segment.isEntityInside(i)){this.alignEntityToTheGround(i,t[n].segment);break}}}}}alignEntityToTheGround(e,t){let i=new oe;t.getEntityTerrainPoint(e,i);let n=Number(this.layer.relativeToGround)&&e._altitude||0;if(n){let t=this.layer._planet.ellipsoid.getSurfaceNormal3v(i);e._setCartesian3vSilent(i.addA(t.scale(n)))}else e._setCartesian3vSilent(i)}isVisible(){return!!this.layer._renderingNodes[this.nodeId]}}class tn extends en{constructor(e,t,i,n,r,s){super(e,t,i,n,r,s),this.isNorth=!1}createChildrenNodes(){const e=this.layer,t=this.extent,i=.5*t.getWidth(),n=.5*t.getHeight(),r=t.northEast,s=t.southWest,a=new z(s.lon+i,s.lat+n),o=this.childrenNodes,l=this.layer._planet,h=this.zoom+1;o[0]=new tn(e,0,this,new ie(new z(s.lon,s.lat+n),new z(s.lon+i,r.lat)),l,h),o[1]=new tn(e,1,this,new ie(a,new z(r.lon,r.lat)),l,h),o[2]=new tn(e,2,this,new ie(new z(s.lon,s.lat),a),l,h),o[3]=new tn(e,3,this,new ie(new z(s.lon+i,s.lat),new z(r.lon,s.lat+n)),l,h)}_setExtentBounds(){this.extent.northEast.lat>0&&(this.isNorth=!0),this.bsphere.setFromExtent(this.layer._planet.ellipsoid,this.extent)}__setLonLat__(e){return e._lonLat.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),e._lonLat}isVisible(){return!(!this.isNorth||!this.layer._renderingNodesNorth[this.nodeId])||!!this.layer._renderingNodesSouth[this.nodeId]}isInside(e){return this.extent.isInside(e._lonLat)}renderCollection(e,t,i){this.isNorth?this.layer._renderingNodesNorth[this.nodeId]=!0:this.layer._renderingNodesSouth[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?this.layer._queueDeferredNode(this):this.applyCollection());const n=this.entityCollection;n._fadingOpacity=this.layer._fadingOpacity,n.scaleByDistance=this.layer.scaleByDistance,n.pickingScale=this.layer.pickingScale,e.push(n)}}function nn(e,t){if(e>=0){let i=65536*Math.floor(e/65536);t[0]=Math.fround(i),t[1]=Math.fround(e-i)}else{let i=65536*Math.floor(-e/65536);t[0]=Math.fround(-i),t[1]=Math.fround(e+i)}return t}function rn(e,t){if(e>=0){let i=65536*Math.floor(e/65536);t.x=Math.fround(i),t.y=Math.fround(e-i)}else{let i=65536*Math.floor(-e/65536);t.x=Math.fround(-i),t.y=Math.fround(e+i)}return t}function sn(e,t,i){i=i||2;var n,r,s,a,o,l,h,c=t&&t.length,d=c?t[0]*i:e.length,_=an(e,0,d,i,!0),u=[];if(!_)return u;if(c&&(_=function(e,t,i,n){var r,s,a,o=[];for(r=0,s=t.length;r<s;r++)(a=an(e,t[r]*n,r<s-1?t[r+1]*n:e.length,n,!1))===a.next&&(a.steiner=!0),o.push(pn(a));for(o.sort(un),r=0;r<o.length;r++)fn(o[r],i),i=on(i,i.next);return i}(e,t,_,i)),e.length>80*i){n=s=e[0],r=a=e[1];for(let t=i;t<d;t+=i)(o=e[t])<n&&(n=o),(l=e[t+1])<r&&(r=l),o>s&&(s=o),l>a&&(a=l);h=Math.max(s-n,a-r)}return ln(_,u,i,n,r,h),u}function an(e,t,i,n,r){var s,a;if(r===function(e,t,i,n){var r=0;for(let s=t,a=i-n;s<i;s+=n)r+=(e[a]-e[s])*(e[s+1]+e[a+1]),a=s;return r}(e,t,i,n)>0)for(s=t;s<i;s+=n)a=Tn(s,e[s],e[s+1],a);else for(s=i-n;s>=t;s-=n)a=Tn(s,e[s],e[s+1],a);return a&&xn(a,a.next)&&(Ln(a),a=a.next),a}function on(e,t){if(!e)return e;t||(t=e);var i,n=e;do{if(i=!1,n.steiner||!xn(n,n.next)&&0!==yn(n.prev,n,n.next))n=n.next;else{if(Ln(n),(n=t=n.prev)===n.next)return null;i=!0}}while(i||n!==t);return t}function ln(e,t,i,n,r,s,a){if(e){!a&&s&&function(e,t,i,n){var r=e;do{null===r.z&&(r.z=gn(r.x,r.y,t,i,n)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==e);r.prevZ.nextZ=null,r.prevZ=null,function(e){var t,i,n,r,s,a,o,l,h=1;do{for(i=e,e=null,s=null,a=0;i;){for(a++,n=i,o=0,t=0;t<h&&(o++,n=n.nextZ);t++);for(l=h;o>0||l>0&&n;)0!==o&&(0===l||!n||i.z<=n.z)?(r=i,i=i.nextZ,o--):(r=n,n=n.nextZ,l--),s?s.nextZ=r:e=r,r.prevZ=s,s=r;i=n}s.nextZ=null,h*=2}while(a>1)}(r)}(e,n,r,s);for(var o,l,h=e;e.prev!==e.next;)if(o=e.prev,l=e.next,s?cn(e,n,r,s):hn(e))t.push(o.i/i),t.push(e.i/i),t.push(l.i/i),Ln(e),e=l.next,h=l.next;else if((e=l)===h){a?1===a?ln(e=dn(e,t,i),t,i,n,r,s,2):2===a&&_n(e,t,i,n,r,s):ln(on(e),t,i,n,r,s,1);break}}}function hn(e){var t=e.prev,i=e,n=e.next;if(yn(t,i,n)>=0)return!1;for(var r=e.next.next;r!==e.prev;){if(mn(t.x,t.y,i.x,i.y,n.x,n.y,r.x,r.y)&&yn(r.prev,r,r.next)>=0)return!1;r=r.next}return!0}function cn(e,t,i,n){var r=e.prev,s=e,a=e.next;if(yn(r,s,a)>=0)return!1;for(var o=r.x<s.x?r.x<a.x?r.x:a.x:s.x<a.x?s.x:a.x,l=r.y<s.y?r.y<a.y?r.y:a.y:s.y<a.y?s.y:a.y,h=r.x>s.x?r.x>a.x?r.x:a.x:s.x>a.x?s.x:a.x,c=r.y>s.y?r.y>a.y?r.y:a.y:s.y>a.y?s.y:a.y,d=gn(o,l,t,i,n),_=gn(h,c,t,i,n),u=e.nextZ;u&&u.z<=_;){if(u!==e.prev&&u!==e.next&&mn(r.x,r.y,s.x,s.y,a.x,a.y,u.x,u.y)&&yn(u.prev,u,u.next)>=0)return!1;u=u.nextZ}for(u=e.prevZ;u&&u.z>=d;){if(u!==e.prev&&u!==e.next&&mn(r.x,r.y,s.x,s.y,a.x,a.y,u.x,u.y)&&yn(u.prev,u,u.next)>=0)return!1;u=u.prevZ}return!0}function dn(e,t,i){var n=e;do{var r=n.prev,s=n.next.next;!xn(r,s)&&bn(r,n,n.next,s)&&wn(r,s)&&wn(s,r)&&(t.push(r.i/i),t.push(n.i/i),t.push(s.i/i),Ln(n),Ln(n.next),n=e=s),n=n.next}while(n!==e);return n}function _n(e,t,i,n,r,s){var a=e;do{for(var o=a.next.next;o!==a.prev;){if(a.i!==o.i&&vn(a,o)){var l=Cn(a,o);return a=on(a,a.next),l=on(l,l.next),ln(a,t,i,n,r,s),void ln(l,t,i,n,r,s)}o=o.next}a=a.next}while(a!==e)}function un(e,t){return e.x-t.x}function fn(e,t){if(t=function(e,t){var i,n=t,r=e.x,s=e.y,a=-1/0;do{if(s<=n.y&&s>=n.next.y&&n.next.y!==n.y){var o=n.x+(s-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(o<=r&&o>a){if(a=o,o===r){if(s===n.y)return n;if(s===n.next.y)return n.next}i=n.x<n.next.x?n:n.next}}n=n.next}while(n!==t);if(!i)return null;if(r===a)return i.prev;var l,h=i,c=i.x,d=i.y,_=1/0;n=i.next;for(;n!==h;)r>=n.x&&n.x>=c&&r!==n.x&&mn(s<d?r:a,s,c,d,s<d?a:r,s,n.x,n.y)&&((l=Math.abs(s-n.y)/(r-n.x))<_||l===_&&n.x>i.x)&&wn(n,e)&&(i=n,_=l),n=n.next;return i}(e,t),t){var i=Cn(t,e);on(i,i.next)}}function gn(e,t,i,n,r){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-i)/r)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-n)/r)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function pn(e){var t=e,i=e;do{t.x<i.x&&(i=t),t=t.next}while(t!==e);return i}function mn(e,t,i,n,r,s,a,o){return(r-a)*(t-o)-(e-a)*(s-o)>=0&&(e-a)*(n-o)-(i-a)*(t-o)>=0&&(i-a)*(s-o)-(r-a)*(n-o)>=0}function vn(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&bn(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&wn(e,t)&&wn(t,e)&&function(e,t){var i=e,n=!1,r=(e.x+t.x)/2,s=(e.y+t.y)/2;do{i.y>s!=i.next.y>s&&i.next.y!==i.y&&r<(i.next.x-i.x)*(s-i.y)/(i.next.y-i.y)+i.x&&(n=!n),i=i.next}while(i!==e);return n}(e,t)}function yn(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function xn(e,t){return e.x===t.x&&e.y===t.y}function bn(e,t,i,n){return!!(xn(e,t)&&xn(i,n)||xn(e,n)&&xn(i,t))||yn(e,t,i)>0!=yn(e,t,n)>0&&yn(i,n,e)>0!=yn(i,n,t)>0}function wn(e,t){return yn(e.prev,e,e.next)<0?yn(e,t,e.next)>=0&&yn(e,e.prev,t)>=0:yn(e,t,e.prev)<0||yn(e,e.next,t)<0}function Cn(e,t){var i=new An(e.i,e.x,e.y),n=new An(t.i,t.x,t.y),r=e.next,s=t.prev;return e.next=t,t.prev=e,i.next=r,r.prev=i,n.next=i,i.prev=n,s.next=n,n.prev=s,n}function Tn(e,t,i,n){var r=new An(e,t,i);return n?(r.next=n.next,r.prev=n,n.next.prev=r,n.next=r):(r.prev=r,r.next=r),r}function Ln(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function An(e,t,i){this.i=e,this.x=t,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function En(e){var t=e[0][0].length,i={vertices:[],holes:[],dimensions:t},n=0;for(let r=0;r<e.length;r++){for(let n=0;n<e[r].length;n++)for(let s=0;s<t;s++)i.vertices.push(e[r][n][s]);r>0&&(n+=e[r-1].length,i.holes.push(n))}return i}function Pn(e,t,i){let n=e[0],r=e[1];if(n>=0){let e=65536*Math.floor(n/65536);t.x=Math.fround(e),i.x=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t.x=Math.fround(-e),i.x=Math.fround(n+e)}if(r>=0){let e=65536*Math.floor(r/65536);t.y=Math.fround(e),i.y=Math.fround(r-e)}else{let e=65536*Math.floor(-r/65536);t.y=Math.fround(-e),i.y=Math.fround(r+e)}}let Sn=new le,Mn=new le,Bn=new le;class kn{constructor(e){this.__id=kn.__counter__++,this._layer=e,this._handler=null,this._geometries=[],this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr=[],this._removeGeometryExtents={},this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyColors=[],this._polyPickingColors=[],this._polyIndexes=[],this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineOrders=[],this._lineIndexes=[],this._lineColors=[],this._linePickingColors=[],this._lineThickness=[],this._lineStrokes=[],this._lineStrokeColors=[],this._polyVerticesHighBufferMerc=null,this._polyVerticesLowBufferMerc=null,this._polyColorsBuffer=null,this._polyPickingColorsBuffer=null,this._polyIndexesBuffer=null,this._lineVerticesHighBufferMerc=null,this._lineVerticesLowBufferMerc=null,this._lineColorsBuffer=null,this._linePickingColorsBuffer=null,this._lineThicknessBuffer=null,this._lineStrokesBuffer=null,this._lineStrokeColorsBuffer=null,this._lineOrdersBuffer=null,this._lineIndexesBuffer=null,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this.createPolyVerticesBuffer,this._buffersUpdateCallbacks[1]=this.createPolyIndexesBuffer,this._buffersUpdateCallbacks[2]=this.createPolyColorsBuffer,this._buffersUpdateCallbacks[3]=this.createLineVerticesBuffer,this._buffersUpdateCallbacks[4]=this.createLineIndexesBuffer,this._buffersUpdateCallbacks[5]=this.createLineOrdersBuffer,this._buffersUpdateCallbacks[6]=this.createLineColorsBuffer,this._buffersUpdateCallbacks[7]=this.createLineThicknessBuffer,this._buffersUpdateCallbacks[8]=this.createLineStrokesBuffer,this._buffersUpdateCallbacks[9]=this.createLineStrokeColorsBuffer,this._buffersUpdateCallbacks[10]=this.createPolyPickingColorsBuffer,this._buffersUpdateCallbacks[11]=this.createLinePickingColorsBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}static appendLineData(e,t,i,n,r,s,a,o,l,h,c,d,_,u,f,g,p,m){var v=0;c.length>0?(v=c[c.length-5]+9,c.push(v,v)):c.push(0,0);var y=r,x=[i.x,i.y,i.z,i.w],b=a,w=[s.x,s.y,s.z,s.w],C=[n.x,n.y,n.z,1];for(let i=0;i<e.length;i++){var T=e[i];if(0===T.length)continue;let n,r,s=v;if(t)n=T[T.length-1];else{let e=T[0],t=T[1];t||(t=e),n=[e[0]+e[0]-t[0],e[1]+e[1]-t[1]]}Pn(n,Sn,Mn),o.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),l.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),p.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),m.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),h.push(1,-1,2,-2),u.push(y,y,y,y),g.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),f.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3]);for(let e=0;e<T.length;e++){Pn(T[e],Sn,Mn),o.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),l.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),p.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),m.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),h.push(1,-1,2,-2),u.push(y,y,y,y),g.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),f.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3]),c.push(v++,v++,v++,v++)}if(t)r=T[0],c.push(s,s+1,s+1,s+1);else{let e=T[T.length-1],t=T[T.length-2];t||(t=e),r=[e[0]+e[0]-t[0],e[1]+e[1]-t[1]],c.push(v-1,v-1,v-1,v-1)}Pn(r,Sn,Mn),o.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),l.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),p.push(Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y,Sn.x,Sn.y),m.push(Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y,Mn.x,Mn.y),h.push(1,-1,2,-2),u.push(y,y,y,y),g.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),f.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3]),i<e.length-1&&(v+=8,c.push(v,v))}}assignHandler(e){this._handler=e,this.refresh(),e.isInitialized()&&this.update()}add(e){if(-1===e._handlerIndex){e._handler=this,e._handlerIndex=this._geometries.length,this._geometries.push(e);let t=e._entity._pickingColor.scaleTo(1/255);if(e._polyVerticesHighMerc=[],e._polyVerticesLowMerc=[],e._lineVerticesHighMerc=[],e._lineVerticesLowMerc=[],e._coordinates[0].length)if(e.type===ai.POLYGON){let i=e._coordinates,n=[];for(let e=0;e<i.length;e++){n[e]=[];for(let t=0;t<i[e].length;t++)n[e][t]=[$(i[e][t][0]),Z(i[e][t][1])]}let r=En(n),s=sn(r.vertices,r.holes,2);e._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,e._polyIndexesHandlerIndex=this._polyIndexes.length;for(let t=0;t<s.length;t++)this._polyIndexes.push(s[t]+.5*e._polyVerticesHandlerIndex);let a=e._style.fillColor,o=[],l=[];for(let e=0;e<.5*r.vertices.length;e++)this._polyColors.push(a.x,a.y,a.z,a.w),this._polyPickingColors.push(t.x,t.y,t.z,1);for(let e=0;e<r.vertices.length;e++)rn(r.vertices[e],Bn),o[e]=Bn.x,l[e]=Bn.y;e._polyVerticesHighMerc=o,e._polyVerticesLowMerc=l,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,o),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,l),e._polyVerticesLength=r.vertices.length,e._polyIndexesLength=s.length,e._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,e._lineOrdersHandlerIndex=this._lineOrders.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._lineColorsHandlerIndex=this._lineColors.length,e._lineThicknessHandlerIndex=this._lineThickness.length,kn.appendLineData(n,!0,e._style.lineColor,t,e._style.lineWidth,e._style.strokeColor,e._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,e._lineVerticesHighMerc,e._lineVerticesLowMerc),e._lineVerticesLength=this._lineVerticesHighMerc.length-e._lineVerticesHandlerIndex,e._lineOrdersLength=this._lineOrders.length-e._lineOrdersHandlerIndex,e._lineIndexesLength=this._lineIndexes.length-e._lineIndexesHandlerIndex,e._lineColorsLength=this._lineColors.length-e._lineColorsHandlerIndex,e._lineThicknessLength=this._lineThickness.length-e._lineThicknessHandlerIndex}else if(e.type===ai.MULTIPOLYGON){let i=e._coordinates,n=[],r=[];e._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,e._lineOrdersHandlerIndex=this._lineOrders.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._lineColorsHandlerIndex=this._lineColors.length,e._lineThicknessHandlerIndex=this._lineThickness.length;for(let s=0;s<i.length;s++){let a=i[s],o=[];for(let e=0;e<a.length;e++){o[e]=[];for(let t=0;t<i[s][e].length;t++)o[e][t]=[$(a[e][t][0]),Z(a[e][t][1])]}let l=En(o),h=sn(l.vertices,l.holes,2);for(let e=0;e<h.length;e++)r.push(h[e]+.5*n.length);n.push.apply(n,l.vertices),kn.appendLineData(o,!0,e._style.lineColor,t,e._style.lineWidth,e._style.strokeColor,e._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,e._lineVerticesHighMerc,e._lineVerticesLowMerc)}e._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,e._polyIndexesHandlerIndex=this._polyIndexes.length;for(let t=0;t<r.length;t++)this._polyIndexes.push(r[t]+.5*e._polyVerticesHandlerIndex);let s=e._style.fillColor,a=[],o=[];for(let e=0;e<.5*n.length;e++)this._polyColors.push(s.x,s.y,s.z,s.w),this._polyPickingColors.push(t.x,t.y,t.z,1);for(let e=0;e<n.length;e++)rn(n[e],Bn),a[e]=Bn.x,o[e]=Bn.y;e._polyVerticesHighMerc=a,e._polyVerticesLowMerc=o,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,a),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,o),e._polyVerticesLength=n.length,e._polyIndexesLength=r.length,e._lineVerticesLength=this._lineVerticesHighMerc.length-e._lineVerticesHandlerIndex,e._lineOrdersLength=this._lineOrders.length-e._lineOrdersHandlerIndex,e._lineIndexesLength=this._lineIndexes.length-e._lineIndexesHandlerIndex,e._lineColorsLength=this._lineColors.length-e._lineColorsHandlerIndex,e._lineThicknessLength=this._lineThickness.length-e._lineThicknessHandlerIndex}else if(e.type===ai.LINESTRING){let i=e._coordinates,n=new Array(i.length);for(let e=0;e<i.length;e++)n[e]=[$(i[e][0]),Z(i[e][1])];e._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,e._lineOrdersHandlerIndex=this._lineOrders.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._lineColorsHandlerIndex=this._lineColors.length,e._lineThicknessHandlerIndex=this._lineThickness.length,kn.appendLineData([n],!1,e._style.lineColor,t,e._style.lineWidth,e._style.strokeColor,e._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,e._lineVerticesHighMerc,e._lineVerticesLowMerc),e._lineVerticesLength=this._lineVerticesHighMerc.length-e._lineVerticesHandlerIndex,e._lineOrdersLength=this._lineOrders.length-e._lineOrdersHandlerIndex,e._lineIndexesLength=this._lineIndexes.length-e._lineIndexesHandlerIndex,e._lineColorsLength=this._lineColors.length-e._lineColorsHandlerIndex,e._lineThicknessLength=this._lineThickness.length-e._lineThicknessHandlerIndex}else if(e.type===ai.MULTILINESTRING){let i=e._coordinates,n=[];for(let e=0;e<i.length;e++){n[e]=[];for(let t=0;t<i[e].length;t++)n[e][t]=[$(i[e][t][0]),Z(i[e][t][1])]}e._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,e._lineOrdersHandlerIndex=this._lineOrders.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._lineColorsHandlerIndex=this._lineColors.length,e._lineThicknessHandlerIndex=this._lineThickness.length,kn.appendLineData(n,!1,e._style.lineColor,t,e._style.lineWidth,e._style.strokeColor,e._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,e._lineVerticesHighMerc,e._lineVerticesLowMerc),e._lineVerticesLength=this._lineVerticesHighMerc.length-e._lineVerticesHandlerIndex,e._lineOrdersLength=this._lineOrders.length-e._lineOrdersHandlerIndex,e._lineIndexesLength=this._lineIndexes.length-e._lineIndexesHandlerIndex,e._lineColorsLength=this._lineColors.length-e._lineColorsHandlerIndex,e._lineThicknessLength=this._lineThickness.length-e._lineThicknessHandlerIndex}this.setGeometryVisibility(e),!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0,this.refresh()}}remove(e){const t=e._handlerIndex;if(-1!==t){this._geometries.splice(t,1),this._polyVerticesHighMerc.splice(e._polyVerticesHandlerIndex,e._polyVerticesLength),this._polyVerticesLowMerc.splice(e._polyVerticesHandlerIndex,e._polyVerticesLength),this._polyColors.splice(2*e._polyVerticesHandlerIndex,2*e._polyVerticesLength),this._polyPickingColors.splice(2*e._polyVerticesHandlerIndex,2*e._polyVerticesLength),this._polyIndexes.splice(e._polyIndexesHandlerIndex,e._polyIndexesLength);let i=.5*e._polyVerticesLength;for(let t=e._polyIndexesHandlerIndex;t<this._polyIndexes.length;t++)this._polyIndexes[t]-=i;this._lineVerticesHighMerc.splice(e._lineVerticesHandlerIndex,e._lineVerticesLength),this._lineVerticesLowMerc.splice(e._lineVerticesHandlerIndex,e._lineVerticesLength),this._lineOrders.splice(e._lineOrdersHandlerIndex,e._lineOrdersLength),this._lineColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._linePickingColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._lineStrokeColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._lineThickness.splice(e._lineThicknessHandlerIndex,e._lineThicknessLength),this._lineStrokes.splice(e._lineThicknessHandlerIndex,e._lineThicknessLength),this._lineIndexes.splice(e._lineIndexesHandlerIndex,e._lineIndexesLength),i=.5*e._lineVerticesLength;for(let t=e._lineIndexesHandlerIndex;t<this._lineIndexes.length;t++)this._lineIndexes[t]-=i;let n=this._geometries;for(let i=t;i<n.length;i++){let t=n[i];t._handlerIndex=i,t._polyVerticesHandlerIndex-=e._polyVerticesLength,t._polyIndexesHandlerIndex-=e._polyIndexesLength,t._lineVerticesHandlerIndex-=e._lineVerticesLength,t._lineOrdersHandlerIndex-=e._lineOrdersLength,t._lineColorsHandlerIndex-=e._lineColorsLength,t._lineThicknessHandlerIndex-=e._lineThicknessLength,t._lineIndexesHandlerIndex-=e._lineIndexesLength}e._pickingReady=!1,e._handler=null,e._handlerIndex=-1,e._polyVerticesHighMerc=[],e._polyVerticesLowMerc=[],e._polyVerticesLength=-1,e._polyIndexesLength=-1,e._polyVerticesHandlerIndex=-1,e._polyIndexesHandlerIndex=-1,e._lineVerticesHighMerc=[],e._lineVerticesLowMerc=[],e._lineVerticesLength=-1,e._lineOrdersLength=-1,e._lineIndexesLength=-1,e._lineColorsLength=-1,e._lineThicknessLength=-1,e._lineVerticesHandlerIndex=-1,e._lineOrdersHandlerIndex=-1,e._lineIndexesHandlerIndex=-1,e._lineThicknessHandlerIndex=-1,e._lineColorsHandlerIndex=-1,!this._removeGeometryExtents[e.__id]&&this._removeGeometryExtentArr.push(e.getExtent()),this._removeGeometryExtents[e.__id]=!0,this.refresh()}}_refreshRecursevely(e,t){if(t.ready){let i=this._layer._id;for(let n=0;n<t.nodes.length;n++){let r=t.nodes[n];if(e.overlaps(r.segment.getExtentLonLat())){this._refreshRecursevely(e,r);let t=r.segment.materials[i];t&&t.isReady&&(1!==t.segment.node.getState()?t.layer.clearMaterial(t):(t.pickingReady=t.pickingReady&&e._pickingReady,t.isReady=!1,t._updateTexture=t.texture,t._updatePickingMask=t.pickingMask),e._pickingReady=!0)}}}}_refreshRecursevelyExt(e,t){if(t.ready){let i=this._layer.__id;for(let n=0;n<t.nodes.length;n++){let r=t.nodes[n];if(e.overlaps(r.segment.getExtentLonLat())){this._refreshRecursevelyExt(e,r);let t=r.segment.materials[i];t&&t.isReady&&t.layer.clearMaterial(t)}}}}_refreshPlanetNode(e){let t,i=this._removeGeometryExtentArr;for(t=0;t<i.length;t++)this._refreshRecursevelyExt(i[t],e);let n=this._updatedGeometryArr;for(t=0;t<n.length;t++)this._refreshRecursevely(n[t],e)}_updatePlanet(){let e=this._layer._planet;if(e){let t=e.quadTreeStrategy.quadTreeList;for(let e=0;e<t.length;e++)this._refreshPlanetNode(t[e])}this._updatedGeometryArr.length=0,this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr.length=0,this._removeGeometryExtentArr=[],this._removeGeometryExtents={}}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}update(){if(this._handler){let e=!1,t=this._changedBuffers.length;for(;t--;)this._changedBuffers[t]&&(e=!0,this._buffersUpdateCallbacks[t].call(this),this._changedBuffers[t]=!1);e&&this._updatePlanet()}}setGeometryVisibility(e){let t=e.getVisibility()?1:0,i=this._polyVerticesHighMerc,n=this._polyVerticesLowMerc,r=e._polyVerticesLength,s=e._polyVerticesHandlerIndex;for(let a=0;a<r;a++)i[s+a]=e._polyVerticesHighMerc[a]*t,n[s+a]=e._polyVerticesLowMerc[a]*t;i=this._lineVerticesHighMerc,n=this._lineVerticesLowMerc,r=e._lineVerticesLength,s=e._lineVerticesHandlerIndex;for(let a=0;a<r;a++)i[s+a]=e._lineVerticesHighMerc[a]*t,n[s+a]=e._lineVerticesLowMerc[a]*t;this._changedBuffers[0]=!0,this._changedBuffers[3]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setPolyColorArr(e,t){let i=2*e._polyVerticesHandlerIndex,n=i+2*e._polyVerticesLength,r=this._polyColors;for(let e=i;e<n;e+=4)r[e]=t.x,r[e+1]=t.y,r[e+2]=t.z,r[e+3]=t.w;this._changedBuffers[2]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineStrokeColorArr(e,t){let i=e._lineColorsHandlerIndex,n=i+e._lineColorsLength,r=this._lineStrokeColors;for(let e=i;e<n;e+=4)r[e]=t.x,r[e+1]=t.y,r[e+2]=t.z,r[e+3]=t.w;this._changedBuffers[9]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineColorArr(e,t){let i=e._lineColorsHandlerIndex,n=i+e._lineColorsLength,r=this._lineColors;for(let e=i;e<n;e+=4)r[e]=t.x,r[e+1]=t.y,r[e+2]=t.z,r[e+3]=t.w;this._changedBuffers[6]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineStrokeArr(e,t){}setLineThicknessArr(e,t){let i=e._lineThicknessHandlerIndex,n=i+e._lineThicknessLength,r=this._lineThickness;for(let e=i;e<n;e++)r[e]=t;this._changedBuffers[7]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}bringToFront(e){let t=this._polyIndexes.splice(e._polyIndexesHandlerIndex,e._polyIndexesLength),i=this._lineIndexes.splice(e._lineIndexesHandlerIndex,e._lineIndexesLength);this._geometries.splice(e._handlerIndex,1);let n=this._geometries;for(let t=e._handlerIndex;t<n.length;t++){let i=n[t];i._handlerIndex=t,i._polyIndexesHandlerIndex-=e._polyIndexesLength,i._lineIndexesHandlerIndex-=e._lineIndexesLength}e._polyIndexesHandlerIndex=this._polyIndexes.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._handlerIndex=this._geometries.length,this._geometries.push(e),this._polyIndexes.push.apply(this._polyIndexes,t),this._lineIndexes.push.apply(this._lineIndexes,i),this._changedBuffers[1]=!0,this._changedBuffers[4]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}createPolyVerticesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyVerticesHighBufferMerc),this._polyVerticesHighBufferMerc=e.createArrayBuffer(new Float32Array(this._polyVerticesHighMerc),2,this._polyVerticesHighMerc.length/2),e.gl.deleteBuffer(this._polyVerticesLowBufferMerc),this._polyVerticesLowBufferMerc=e.createArrayBuffer(new Float32Array(this._polyVerticesLowMerc),2,this._polyVerticesLowMerc.length/2)}createPolyIndexesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyIndexesBuffer),this._polyIndexesBuffer=e.createElementArrayBuffer(new Uint32Array(this._polyIndexes),1,this._polyIndexes.length)}createPolyColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyColorsBuffer),this._polyColorsBuffer=e.createArrayBuffer(new Float32Array(this._polyColors),4,this._polyColors.length/4)}createPolyPickingColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyPickingColorsBuffer),this._polyPickingColorsBuffer=e.createArrayBuffer(new Float32Array(this._polyPickingColors),4,this._polyPickingColors.length/4)}createLineVerticesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineVerticesHighBufferMerc),this._lineVerticesHighBufferMerc=e.createArrayBuffer(new Float32Array(this._lineVerticesHighMerc),2,this._lineVerticesHighMerc.length/2),e.gl.deleteBuffer(this._lineVerticesLowBufferMerc),this._lineVerticesLowBufferMerc=e.createArrayBuffer(new Float32Array(this._lineVerticesLowMerc),2,this._lineVerticesLowMerc.length/2)}createLineIndexesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineIndexesBuffer),this._lineIndexesBuffer=e.createElementArrayBuffer(new Uint32Array(this._lineIndexes),1,this._lineIndexes.length)}createLineOrdersBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineOrdersBuffer),this._lineOrdersBuffer=e.createArrayBuffer(new Float32Array(this._lineOrders),1,this._lineOrders.length/2)}createLineColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineColorsBuffer),this._lineColorsBuffer=e.createArrayBuffer(new Float32Array(this._lineColors),4,this._lineColors.length/4)}createLinePickingColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._linePickingColorsBuffer),this._linePickingColorsBuffer=e.createArrayBuffer(new Float32Array(this._linePickingColors),4,this._linePickingColors.length/4)}createLineThicknessBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineThicknessBuffer),this._lineThicknessBuffer=e.createArrayBuffer(new Float32Array(this._lineThickness),1,this._lineThickness.length)}createLineStrokesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineStrokesBuffer),this._lineStrokesBuffer=e.createArrayBuffer(new Float32Array(this._lineStrokes),1,this._lineStrokes.length)}createLineStrokeColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineStrokeColorsBuffer),this._lineStrokeColorsBuffer=e.createArrayBuffer(new Float32Array(this._lineStrokeColors),4,this._lineStrokeColors.length/4)}}kn.__counter__=0;class Rn{constructor(e=2048){this._size=e,this._array=new Array(this._size),this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}reset(){this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}clear(){this._array.length=0,this._array=new Array(this._size),this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}push(e){this.length++,this._array[this._popIndex++]=e}pop(){if(this.length){this.length--;let e=this._array[--this._popIndex];return this._array[this._popIndex]=null,this._array[this._popIndex-1]||(this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex),e}}unshift(e){this.length++,this._array[--this._shiftIndex]=e}shift(){if(this.length){this.length--;let e=this._array[this._shiftIndex];return this._array[this._shiftIndex++]=null,this._array[this._shiftIndex]||(this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex),e}}forEach(e){for(let t=this._shiftIndex;t<this._popIndex;t++)e(this._array[t])}}class In extends qt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(zn),this.isVector=!0,this._hasImageryTiles=!1,this.scaleByDistance=t.scaleByDistance||[r,r,r],this.pickingScale=t.pickingScale||1,this.async=void 0===t.async||t.async,this.clampToGround=t.clampToGround||!1,this.relativeToGround=t.relativeToGround||!1,this._nodeCapacity=t.nodeCapacity||30,this._entities=function(e){let t=[];for(let i=0;i<e.length;i++){let n=e[i];"Entity"===n.instanceName?t.push(n):t.push(new Ai(n))}return t}(t.entities||[]),this._labelMaxLetters=t.labelMaxLetters||24,this._stripEntityCollection=new Qi({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._stripEntityCollection),this._polylineEntityCollection=new Qi({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._polylineEntityCollection),this._geoObjectEntityCollection=new Qi({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._geoObjectEntityCollection),this._geometryHandler=new kn(this),this._entityCollectionsTree=null,this._entityCollectionsTreeNorth=null,this._entityCollectionsTreeSouth=null,this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={},this._counter=0,this._deferredEntitiesPendingQueue=new Rn,this._pendingsQueue=[],this.setEntities(this._entities),this.polygonOffsetUnits=null!=t.polygonOffsetUnits?t.polygonOffsetUnits:0,this.pickingEnabled=this._pickingEnabled,this._secondPASS=[]}get labelMaxLetters(){return this._labelMaxLetters}get instanceName(){return"Vector"}_bindPicking(){this._pickingColor.clear()}addTo(e){this._planet||(this._assignPlanet(e),this._geometryHandler.assignHandler(e.renderer.handler),this._polylineEntityCollection.addTo(e,!0),this._stripEntityCollection.addTo(e,!0),this._geoObjectEntityCollection.addTo(e,!0),this.setEntities(this._entities))}remove(){return super.remove(),this._polylineEntityCollection.remove(),this._stripEntityCollection.remove(),this._geoObjectEntityCollection.remove(),this}getEntities(){return[].concat(this._entities)}add(e,t=!1){return e._layer||e._entityCollection||(e._layer=this,e._layerIndex=this._entities.length,this._entities.push(e),this._proceedEntity(e,t)),this}insert(e,t,i=!1){if(!e._layer&&!e._entityCollection){e._layer=this,e._layerIndex=t,this._entities.splice(t,0,e);for(let e=t+1,i=this._entities.length;e<i;e++)this._entities[e]._layerIndex=e;this._proceedEntity(e,i)}return this}_proceedEntity(e,t=!1){let i=this._hasImageryTiles;e.strip&&this._stripEntityCollection.add(e),(e.polyline||e.ray)&&this._polylineEntityCollection.add(e),e.geoObject&&this._geoObjectEntityCollection.add(e),e.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(e),this._geometryHandler.add(e.geometry))),(e.billboard||e.label||e.geoObject)&&this._planet&&(e._cartesian.isZero()&&!e._lonLat.isZero()?e._setCartesian3vSilent(this._planet.ellipsoid.lonLatToCartesian(e._lonLat)):e._lonLat=this._planet.ellipsoid.cartesianToLonLat(e._cartesian),e._lonLat.lat>J?(this._entityCollectionsTreeNorth.__setLonLat__(e),this._entityCollectionsTreeNorth.insertEntity(e,t)):e._lonLat.lat<ee?(this._entityCollectionsTreeSouth.__setLonLat__(e),this._entityCollectionsTreeSouth.insertEntity(e,t)):(this._entityCollectionsTree.__setLonLat__(e),this._entityCollectionsTree.insertEntity(e,t))),this._planet&&this._hasImageryTiles!==i&&this._planet.updateVisibleLayers(),this.events.dispatch(this.events.entityadd,e)}addEntities(e,t=!1){let i=e.length;for(;i--;)this.add(e[i],t);return this}removeEntity(e){if(e._layer&&this.isEqual(e._layer)){if(this._entities.splice(e._layerIndex,1),this._reindexEntitiesArray(e._layerIndex),e._layer=null,e._layerIndex=-1,e._entityCollection){e._entityCollection._removeEntitySilent(e);let t=e._nodePtr;for(;t;)t.count--,t=t.parentNode;e._nodePtr&&0===e._nodePtr.count&&0===e._nodePtr.deferredEntities.length&&(e._nodePtr.entityCollection=null)}else if(e._nodePtr&&e._nodePtr.deferredEntities.length){let t=e._nodePtr.deferredEntities,i=t.length;for(;i--;)if(t[i].id===e.id){t.splice(i,1);let n=e._nodePtr;for(;n;)n.count--,n=n.parentNode;break}}e.geometry&&this._planet&&(this._geometryHandler.remove(e.geometry),this._planet.renderer.clearPickingColor(e)),e._nodePtr=void 0,this.events.dispatch(this.events.entityremove,e)}return this}set pickingEnabled(e){this._pickingEnabled=e,this._stripEntityCollection.setPickingEnabled(e),this._polylineEntityCollection.setPickingEnabled(e),this._geoObjectEntityCollection.setPickingEnabled(e),this._entityCollectionsTree&&this._entityCollectionsTree.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeNorth&&this._entityCollectionsTreeNorth.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeSouth&&this._entityCollectionsTreeSouth.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)}))}_reindexEntitiesArray(e){const t=this._entities;for(let i=e;i<t.length;i++)t[i]._layerIndex=i}removeEntities(e){let t=e.length;for(;t--;)this.removeEntity(e[t]);return this}clear(){let e=new Array(this._entities.length);for(let t=0;t<e.length;t++)e[t]=this._entities[t];let t=this._entities.length;for(;t--;)this._entities[t].remove();this._entities.length=0,this._entities=[];for(let t=0;t<e.length;t++)this._entities[t]=e[t];this._entityCollectionsTree=null,this._entityCollectionsTreeNorth=null,this._entityCollectionsTreeSouth=null}each(e){let t=this._entities,i=t.length;for(;i--;)e(t[i],i)}setEntities(e){let t=new Array(e.length);for(let i=0,n=e.length;i<n;i++)t[i]=e[i];this.clear(),this._entities=new Array(t.length);let i=[];for(let e=0;e<t.length;e++){let n=t[e];n._layer=this,n._layerIndex=e,n.strip?this._stripEntityCollection.add(n):n.polyline||n.ray?this._polylineEntityCollection.add(n):n.geoObject?this._geoObjectEntityCollection.add(n):(n.billboard||n.label)&&i.push(n),n.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(n),this._geometryHandler.add(n.geometry))),this._entities[e]=n}return this._createEntityCollectionsTree(i),this}_createEntityCollectionsTree(e){if(this._planet){this._entityCollectionsTree=new en(this,0,null,ie.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34]),this._planet,0),this._entityCollectionsTreeNorth=new tn(this,0,null,ie.createFromArray([-180,J,180,90]),this._planet,0),this._entityCollectionsTreeSouth=new tn(this,0,null,ie.createFromArray([-180,-90,180,ee]),this._planet,0);for(let t=0,i=e.length;t<i;t++){let i=e[t];i._lonLat.lat>J?this._entityCollectionsTreeNorth.__setLonLat__(i):i._lonLat.lat<ee?this._entityCollectionsTreeSouth.__setLonLat__(i):this._entityCollectionsTree.__setLonLat__(i)}this._entityCollectionsTree.buildTree(e),this._entityCollectionsTreeNorth.buildTree(e),this._entityCollectionsTreeSouth.buildTree(e)}}_bindEventsDefault(e){let t=this.events;e.events.on("mousemove",(e=>{t.dispatch(t.mousemove,e)})),e.events.on("mouseenter",(e=>{t.dispatch(t.mouseenter,e)})),e.events.on("mouseleave",(e=>{t.dispatch(t.mouseleave,e)})),e.events.on("lclick",(e=>{t.dispatch(t.lclick,e)})),e.events.on("rclick",(e=>{t.dispatch(t.rclick,e)})),e.events.on("mclick",(e=>{t.dispatch(t.mclick,e)})),e.events.on("ldblclick",(e=>{t.dispatch(t.ldblclick,e)})),e.events.on("rdblclick",(e=>{t.dispatch(t.rdblclick,e)})),e.events.on("mdblclick",(e=>{t.dispatch(t.mdblclick,e)})),e.events.on("lup",(e=>{t.dispatch(t.lup,e)})),e.events.on("rup",(e=>{t.dispatch(t.rup,e)})),e.events.on("mup",(e=>{t.dispatch(t.mup,e)})),e.events.on("ldown",(e=>{t.dispatch(t.ldown,e)})),e.events.on("rdown",(e=>{t.dispatch(t.rdown,e)})),e.events.on("mdown",(e=>{t.dispatch(t.mdown,e)})),e.events.on("lhold",(e=>{t.dispatch(t.lhold,e)})),e.events.on("rhold",(e=>{t.dispatch(t.rhold,e)})),e.events.on("mhold",(e=>{t.dispatch(t.mhold,e)})),e.events.on("mousewheel",(e=>{t.dispatch(t.mousewheel,e)})),e.events.on("touchmove",(e=>{t.dispatch(t.touchmove,e)})),e.events.on("touchstart",(e=>{t.dispatch(t.touchstart,e)})),e.events.on("touchend",(e=>{t.dispatch(t.touchend,e)})),e.events.on("doubletouch",(e=>{t.dispatch(t.doubletouch,e)})),e.events.on("touchleave",(e=>{t.dispatch(t.touchleave,e)})),e.events.on("touchenter",(e=>{t.dispatch(t.touchenter,e)}))}_collectStripCollectionPASS(e){let t=this._stripEntityCollection;t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t)}_collectPolylineCollectionPASS(e){let t=this._polylineEntityCollection;if(t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t),this.clampToGround||this.relativeToGround){let e=Number(this.relativeToGround);const i=this._planet._renderedNodes,n=this._planet.getViewExtent();let r=t._entities,s=r.length,a=new oe;for(;s--;){let t=r[s].polyline;if(t&&n.overlaps(t._extent)){let n=t._pathLonLatMerc,r=n.length;for(;r--;){let s=n[r].length;for(;s--;){let o=n[r][s],l=i.length;for(;l--;){let n=i[l].segment;if(n._extent.isInside(o)){let i=t._path3v[r][s];n.getTerrainPoint(i,o,a);let l=e&&t.altitude||0;if(l){let e=this._planet.ellipsoid.getSurfaceNormal3v(a);t.setPoint3v(a.addA(e.scale(l)),s,r,!0)}else t.setPoint3v(a,s,r,!0);break}}}}}}}}_collectGeoObjectCollectionPASS(e){let t=this._geoObjectEntityCollection;t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t)}collectVisibleCollections(e){let t=this._planet;if(this._fading&&this._fadingOpacity>0||this.minZoom<=t.maxCurrZoom&&this.maxZoom>=t.maxCurrZoom){this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={},this._collectStripCollectionPASS(e),this._collectPolylineCollectionPASS(e),this._collectGeoObjectCollectionPASS(e),this._secondPASS=[],this._entityCollectionsTree&&this._entityCollectionsTree.collectRenderCollectionsPASS1(t._visibleNodes,e);let i=this._secondPASS.length;for(;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodes,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeNorth&&this._entityCollectionsTreeNorth.collectRenderCollectionsPASS1(t._visibleNodesNorth,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesNorth,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeSouth&&this._entityCollectionsTreeSouth.collectRenderCollectionsPASS1(t._visibleNodesSouth,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesSouth,e,this._secondPASS[i].nodeId)}}_queueDeferredNode(e){this._visibility&&(e._inTheQueue=!0,this._counter>=1?this._deferredEntitiesPendingQueue.push(e):this._execDeferredNode(e))}_execDeferredNode(e){this._counter++,setTimeout((()=>{if(e.applyCollection(),this._counter--,this._deferredEntitiesPendingQueue.length&&this._counter<1)for(;this._deferredEntitiesPendingQueue.length;){let e=this._deferredEntitiesPendingQueue.pop();if(e._inTheQueue=!1,e.isVisible())return void this._execDeferredNode(e)}}),0)}loadMaterial(e){const t=e.segment;this._isBaseLayer?e.texture=t._isNorth?t.planet.solidTextureOne:t.planet.solidTextureTwo:e.texture=t.planet.transparentTexture,this._planet.layerLock.isFree()&&(e.isReady=!1,e.isLoading=!0,this._planet._vectorTileCreator.add(e))}abortMaterialLoading(e){e.isLoading=!1,e.isReady=!1}applyMaterial(e,t=!1){if(e.isReady)return[0,0,1,1];{!e.isLoading&&this.loadMaterial(e);const t=e.segment;let i=t.node,n=!1,r=this.__id,s=e;for(;i.parentNode;){if(s&&s.isReady){n=!0;break}i=i.parentNode,s=i.segment.materials[r]}if(n){e.appliedNodeId=i.nodeId,e.texture=s.texture,e.pickingMask=s.pickingMask;const n=1/(2<<t.tileZoom-i.segment.tileZoom-1);return[t.tileX*n-i.segment.tileX,t.tileY*n-i.segment.tileY,n,n]}return e.textureExists&&e._updateTexture?(e.texture=e._updateTexture,e.pickingMask=e._updatePickingMask):(e.texture=t.planet.transparentTexture,e.pickingMask=t.planet.transparentTexture),e.pickingReady=!0,[0,0,1,1]}}clearMaterial(e){if(e.isReady){const t=e.segment.handler.gl;e.isReady=!1,e.pickingReady=!1;let i=e.texture;e.texture=null,i&&!i.default&&t.deleteTexture(i),i=e.pickingMask,e.pickingMask=null,i&&!i.default&&t.deleteTexture(i),i=e._updateTexture,e._updateTexture=null,i&&!i.default&&t.deleteTexture(i),i=e._updatePickingMask,e._updatePickingMask=null,i&&!i.default&&t.deleteTexture(i)}this.abortMaterialLoading(e),e.isLoading=!1,e.textureExists=!1}update(){this._geometryHandler.update(),this.events.dispatch(this.events.draw,this)}}const zn=["draw","entityadd","entityremove"],Dn=["change","startpoint"],Fn=gi.createCylinder(1,1,2,20,1,!0,!1,0,-.5,0),Nn=200,Hn=.3,On={scale:.5,instanced:!0,tag:"corners",color:"rgb(350, 350, 0)",object3d:Fn},Vn={scale:.4,instanced:!0,tag:"centers",color:"rgb(0, 350, 50)",object3d:Fn},Un={thickness:3.5,color:"rgb(0, 350, 50)"};class Gn extends Pi{constructor(e){super(e.name),this._cornerDblClick=!1,this._onChange=e=>{if("POLYGON"===e.geometryType){let t=this.getCoordinates(),i=new Ai({geometry:{type:e.geometryType,coordinates:[t],style:{fillColor:"rgba(0,146,247,0.2)"}}});this._geometryLayer.clear(),this._geometryLayer.add(i)}},this._onCornerMouseEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer",this.hideGhostPointer()},this._onCornerMouseLeave=e=>{e.renderer.handler.canvas.style.cursor="default",this.showGhostPointer()},this._onCenterMouseEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer",this.hideGhostPointer()},this._onCenterMouseLeave=e=>{e.renderer.handler.canvas.style.cursor="default",this._pickedCenter||this._pickedCorner||this.showGhostPointer()},this._onLup=e=>{this._planet.renderer.controls.mouseNavigation.activate(),(this._pickedCorner||this._pickedCenter)&&(this.events.dispatch(this.events.change,this),this.setGhostPointerPosition(this._planet.getCartesianFromPixelTerrain(e)),this.showGhostPointer(),this._pickedCorner=null,this._pickedCenter=null)},this._onCornerLdown=e=>{this._pickedCorner=this._getLdown(e)},this._onCenterLdown=e=>{this._pickedCenter=this._getLdown(e)},this._onMouseMove=e=>{this._pickedCenter?this._moveCenterPoint():this._pickedCorner?this._moveCornerPoint(e.pos):this.setGhostPointerPosition(this._planet.getCartesianFromPixelTerrain(e.pos))},this._onCornerLdblclick=e=>{this._cornerDblClick=!0;let t=this.getCoordinates();t.splice(e.pickingObject.layerIndex,1),this.setCoordinates(t)},this._onMouseDblClick=e=>{if(this._cornerDblClick)return void(this._cornerDblClick=!1);if(!this._showGhostPointer)return;let t=this._planet.getCartesianFromPixelTerrain(e);t&&(this._addNew(t),!this._isStartPoint&&this._cornerLayer.getEntities().length>2&&(this._isStartPoint=!0,this.events.dispatch(this.events.startpoint,this)),this.events.dispatch(this.events.change,this))},this.events=Pt(Dn),this._planet=null,this._initCoordinates=e.coordinates||[],this._pickedCorner=null,this._pickedCenter=null,this._startPos=null,this._startClick=new le,this._geometryLayer=new In,this._cornerLayer=new In("corners",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._centerLayer=new In("centers",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._outlineLayer=new In("outline",{entities:[new Ai({polyline:{path3v:[],isClosed:!1,...Un}})],pickingEnabled:!1,polygonOffsetUnits:-5,relativeToGround:!0}),this._outlineLayer.getEntities()[0].polyline.altitude=Hn,this._ghostCorner=new Ai({geoObject:On}),this._ghostOutlineLayer=new In("ghost-pointer",{pickingEnabled:!1,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1],opacity:.5}),this._showGhostPointer=!1,this._isStartPoint=!1,this._insertCornerIndex=-1}get geometryType(){return"POLYGON"}getCoordinates(){let e=this._cornerLayer.getEntities();return e.length>0?e.map((e=>{let t=e.getLonLat();return[t.lon,t.lat,t.height]})):this._initCoordinates}bindPlanet(e){this._planet=e}init(){this._initEvents(),this._initGhostLayerPointer(),this._initCoordinates.length&&this.setCoordinates(this._initCoordinates),this._planet.addLayer(this._outlineLayer),this._planet.addLayer(this._cornerLayer),this._planet.addLayer(this._centerLayer),this.showGhostPointer(),this.startNewPoint(),this._planet.renderer.controls.mouseNavigation.deactivateDoubleClickZoom(),this._geometryLayer.addTo(this._planet),this.events.on("change",this._onChange,this)}onremove(){this._clearEvents(),this.hideGhostPointer(),this.stopNewPoint(),this.clear(),this._geometryLayer.remove()}clear(){this._geometryLayer.clear();let e=this._cornerLayer.getEntities(),t=e.length;for(;t--;)e[t].remove();let i=this._centerLayer.getEntities();for(t=i.length;t--;)i[t].remove();let n=this._outlineLayer.getEntities();for(t=n.length;t--;)n[t].polyline.clear(),t>0&&n[t].remove();this._clearGhostPointer()}setCoordinates(e){this.clear();for(let t=0;t<e.length;t++){let i=e[t],n=this._planet.ellipsoid.lonLatToCartesian(new z(i[0],i[1],i[2]));this._appendCart(n)}this.events.dispatch(this.events.change,this)}stopNewPoint(){this.renderer&&this.renderer.events.off("ldblclick",this._onMouseDblClick)}startNewPoint(){this.renderer.events.on("ldblclick",this._onMouseDblClick,this)}showGhostPointer(){this._showGhostPointer=!0,this._planet.addLayer(this._ghostOutlineLayer),this._insertCornerIndex=this._cornerLayer.getEntities().length}hideGhostPointer(){this._showGhostPointer=!1,this._ghostOutlineLayer.remove(),this._insertCornerIndex=-1}setGhostPointerPosition(e){e&&(this._ghostCorner.setCartesian3v(e),this._updateGhostOutlinePointer(e))}_getLdown(e){this._planet.renderer.controls.mouseNavigation.deactivate(),this._startClick.set(e.x,e.y);let t=e.pickingObject.getCartesian();return this._startPos=this._planet.getPixelFromCartesian(t),e.pickingObject}_initEvents(){this._cornerLayer.events.on("ldblclick",this._onCornerLdblclick,this),this._cornerLayer.events.on("ldown",this._onCornerLdown,this),this._centerLayer.events.on("ldown",this._onCenterLdown,this),this.renderer.events.on("lup",this._onLup,this),this.renderer.events.on("mousemove",this._onMouseMove,this),this._cornerLayer.events.on("mouseenter",this._onCornerMouseEnter,this),this._cornerLayer.events.on("mouseleave",this._onCornerMouseLeave,this),this._centerLayer.events.on("mouseenter",this._onCenterMouseEnter,this),this._centerLayer.events.on("mouseleave",this._onCenterMouseLeave,this)}_clearEvents(){this._cornerLayer.events.off("ldblclick",this._onCornerLdblclick),this._cornerLayer.events.off("ldown",this._onCornerLdown),this._centerLayer.events.off("ldown",this._onCenterLdown),this.renderer.events.off("lup",this._onLup),this.renderer.events.off("mousemove",this._onMouseMove),this._cornerLayer.events.off("mouseenter",this._onCornerMouseEnter),this._cornerLayer.events.off("mouseleave",this._onCornerMouseLeave),this._centerLayer.events.off("mouseenter",this._onCenterMouseEnter),this._centerLayer.events.off("mouseleave",this._onCenterMouseLeave)}_drawCorners(){let e=this._cornerLayer.getEntities();for(let t=0;t<e.length;t++){let i=e[t];this._checkTerrainCollision(i)}}_drawCenters(){let e=this._centerLayer.getEntities();for(let t=0;t<e.length;t++){let i=e[t];this._checkTerrainCollision(i)}}_drawGhostCorner(){this._showGhostPointer&&this._checkTerrainCollision(this._ghostCorner)}frame(){this._drawCorners(),this._drawCenters(),this._drawGhostCorner()}_checkTerrainCollision(e){let t=new oe,i=this._planet._renderedNodes;for(let n=0;n<i.length;n++){let r=i[n].segment;if(r&&r._extentLonLat.isInside(e.getLonLat())){r.getEntityTerrainPoint(e,t),e.setCartesian3v(t);break}}}_moveCenterPoint(){let e=this.getCoordinates(),t=this._pickedCenter.layerIndex+1,i=this._pickedCenter.getLonLat(),n=[i.lon,i.lat,i.height];e.splice(t,0,n),this.setCoordinates(e),this._pickedCenter=null,this._pickedCorner=this._cornerLayer.getEntities()[t]}_addNew(e){if(-1===this._insertCornerIndex||this._cornerLayer.getEntities().length<2)this._appendCart(e);else{let t=this.getCoordinates(),i=this._insertCornerIndex,n=this._planet.ellipsoid.cartesianToLonLat(e),r=[n.lon,n.lat,n.height];t.splice(i,0,r),this.clear(),this.setCoordinates(t)}}_appendCart(e){let t=this._cornerLayer.getEntities(),i=t[t.length-1],n=new Ai({geoObject:On});if(n.setCartesian3v(e),n.addTo(this._cornerLayer),this._checkTerrainCollision(n),i){let e=t[0].getCartesian(),r=i.getCartesian(),s=n.getCartesian().sub(r),a=n.getCartesian().sub(e),o=s.length(),l=a.length();s.normalize(),a.normalize();let h=[],c=[];for(let t=0;t<=Nn;t++){let i=s.scaleTo(t*o/Nn).addA(r);h.push(i);let n=a.scaleTo(t*l/Nn).addA(e);c.push(n)}this._outlineLayer.getEntities()[0].polyline.setPath3v([c]);let d=new Ai({polyline:{path3v:[h],isClosed:!1,...Un}});d.polyline.altitude=Hn,this._outlineLayer.add(d);let _=this._centerLayer.getEntities(),u=_[_.length-1],f=s.scaleTo(.5*o).addA(r),g=a.scaleTo(.5*l).addA(e),p=new Ai({geoObject:Vn});p.setCartesian3v(f),p.addTo(this._centerLayer),this._checkTerrainCollision(p),u.remove(),u.addTo(this._centerLayer),u.setCartesian3v(g)}else{new Ai({geoObject:Vn}).addTo(this._centerLayer)}}_clearGhostPointer(){const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.clear(),e.getEntities()[1].polyline.clear()}_moveCornerPoint(e){let t=new le(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),n=this._planet.getCartesianFromPixelTerrain(i);if(n){this._pickedCorner.setCartesian3v(n);let e=this._cornerLayer.getEntities();if(e.length){let t=this._pickedCorner.layerIndex,i=e.length,n=e[0===t?i-1:t-1].getCartesian(),r=e[(t+1)%i].getCartesian(),s=this._pickedCorner.getCartesian().sub(n),a=this._pickedCorner.getCartesian().sub(r),o=s.length(),l=a.length();s.normalize(),a.normalize();let h=[],c=[];for(let e=0;e<=Nn;e++){let t=s.scaleTo(e*o/Nn).addA(n);h.push(t);let i=a.scaleTo(e*l/Nn).addA(r);c.push(i)}let d=this._outlineLayer.getEntities(),_=d[t].polyline,u=d[(t+1)%i].polyline;_?.setPath3v([h]),u?.setPath3v([c]);let f=this._centerLayer.getEntities(),g=f[0===t?i-1:t-1],p=f[t],m=s.scaleTo(.5*o).addA(n),v=a.scaleTo(.5*l).addA(r);g.setCartesian3v(m),this._checkTerrainCollision(g),p.setCartesian3v(v),this._checkTerrainCollision(p)}}}_updateGhostOutlinePointer(e){let t=this._cornerLayer.getEntities(),i=t.length;if(i>0){let n=0,r=s;for(let s=0;s<i;s++){let i=t[s].getCartesian().distance(e);i<r&&(r=i,n=s)}let a=t[n].getCartesian(),o=t[(n+1)%i].getCartesian(),l=t[0===n?i-1:n-1].getCartesian().sub(a).normalize(),h=o.sub(a).normalize(),c=e.sub(a).normalize(),d=l.add(h).normalize(),_=c.cross(d),u=l.cross(h);_.dot(u)>0&&(n--,n<0&&(n=i-1));let f=new oe;for(let s=0;s<i;s++){if(new ci(t[s].getCartesian(),t[(s+1)%i].getCartesian()).getNearestDistancePoint(e,f)){let t=f.distance(e);t<r&&(r=t,n=s)}}this._insertCornerIndex=(n+1)%i;let g=t[n%i].getCartesian(),p=t[(n+1)%i].getCartesian(),m=this._ghostCorner.getCartesian().sub(g),v=this._ghostCorner.getCartesian().sub(p),y=m.length(),x=v.length();m.normalize(),v.normalize();let b=[],w=[];for(let e=0;e<=Nn;e++){let t=m.scaleTo(e*y/Nn).addA(g);b.push(t);let i=v.scaleTo(e*x/Nn).addA(p);w.push(i)}let C=this._ghostOutlineLayer.getEntities(),T=C[0].polyline,L=C[1].polyline;T?.setPath3v([b]),L?.setPath3v([w])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new Ai({polyline:{path3v:[],isClosed:!1,...Un}}),new Ai({polyline:{path3v:[],isClosed:!1,...Un}}),this._ghostCorner]);const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.altitude=e.getEntities()[1].polyline.altitude=Hn}}class Wn extends Gn{constructor(e){super(e)}get geometryType(){return"LineString"}_addNew(e){this._appendCart(e)}_appendCart(e){let t=this._cornerLayer.getEntities(),i=t[t.length-1],n=new Ai({geoObject:On});if(n.setCartesian3v(e),n.addTo(this._cornerLayer),this._checkTerrainCollision(n),i){let e=i.getCartesian(),t=n.getCartesian().sub(e),r=t.length();t.normalize();let s=[];for(let i=0;i<=Nn;i++){let n=t.scaleTo(i*r/Nn).addA(e);s.push(n)}let a=new Ai({polyline:{path3v:[s],isClosed:!1,...Un}});a.polyline.altitude=Hn,this._outlineLayer.add(a);let o=t.scaleTo(.5*r).addA(e),l=new Ai({geoObject:Vn});l.setCartesian3v(o),l.addTo(this._centerLayer),this._checkTerrainCollision(l)}}_clearGhostPointer(){this._ghostOutlineLayer.getEntities()[0].polyline.clear()}_moveCorner(e,t,i){let n=this._cornerLayer.getEntities();if(0==n.length)return;1==n.length&&(e=t=i=0);let r=n[e].getCartesian(),s=this._pickedCorner.getCartesian().sub(r),a=s.length();s.normalize();let o=[];for(let e=0;e<=Nn;e++){let t=s.scaleTo(e*a/Nn).addA(r);o.push(t)}let l=this._outlineLayer.getEntities()[t].polyline;l?.setPath3v([o]);let h=this._centerLayer.getEntities()[i];if(h){let e=s.scaleTo(.5*a).addA(r);h.setCartesian3v(e),this._checkTerrainCollision(h)}}_moveCornerPoint(e){let t=new le(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),n=this._planet.getCartesianFromPixelTerrain(i);if(n){this._pickedCorner.setCartesian3v(n);let e=this._cornerLayer.getEntities();if(e.length){let t=this._pickedCorner.layerIndex;0===t?this._moveCorner(t+1,t+1,t):(t===e.length-1||this._moveCorner(t+1,t+1,t),this._moveCorner(t-1,t,t-1))}}}_updateGhostOutlinePointer(e){let t=this._cornerLayer.getEntities(),i=t.length;if(i>0){let e=i-1;this._insertCornerIndex=e;let n=t[e].getCartesian(),r=this._ghostCorner.getCartesian().sub(n),s=r.length();r.normalize();let a=[];for(let e=0;e<=Nn;e++){let t=r.scaleTo(e*s/Nn).addA(n);a.push(t)}this._ghostOutlineLayer.getEntities()[0].polyline.setPath3v([a])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new Ai({polyline:{path3v:[],isClosed:!1,...Un}}),this._ghostCorner]),this._ghostOutlineLayer.getEntities()[0].polyline.altitude=Hn}}class jn extends It{constructor(e={}){super(e),this._drawingScene=new Wn({name:`drawingScene:${this.__id}`})}activatePolygonDrawing(){this.deactivate(),this._drawingScene=new Gn({name:`polygonDrawingScene:${this.__id}`}),this.activate()}activateLineStringDrawing(){this.deactivate(),this._drawingScene=new Wn({name:`linestringDrawingScene:${this.__id}`}),this.activate()}oninit(){}onactivate(){this.planet&&this._drawingScene.bindPlanet(this.planet),this.renderer&&this.renderer.addNode(this._drawingScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._drawingScene)}}const Yn={ell:0,msl:1,gnd:2},qn=.3048,Xn=1/qn,$n=1/3.6,Zn=.001*qn,Kn=1/Zn,Qn=["m","km","ft","s","h","m/s","km/h","ft/s"],Jn=[0,2,0,0,0,0,0,0];let er=[];function tr(e,t,i){return er[e][t](i)}function ir(e,t,i,n,r){return e?tr(t,i,n).toFixed(r||Jn[i]):"--"}function nr(e){return Qn[e]}er[0]=[],er[0][0]=e=>e,er[0][1]=e=>.001*e,er[0][2]=e=>e*Xn,er[2]=[],er[2][0]=e=>e*qn,er[2][1]=e=>e*Zn,er[2][2]=e=>e,er[1]=[],er[1][0]=e=>1e3*e,er[1][1]=e=>e,er[1][2]=e=>e*Kn,er[5]=[],er[5][5]=e=>e,er[5][6]=e=>3.6*e,er[5][7]=e=>3.28084*e,er[6]=[],er[6][5]=e=>e*$n,er[6][6]=e=>e;var rr=Object.freeze({__proto__:null,ELL:0,GND:2,MSL:1,_tenth:Jn,convert:tr,convertExt:ir,ft:2,fts:7,h:4,heightMode:Yn,km:1,kmh:6,m:0,ms:5,s:3,toString:nr});const sr=['<div class="og-lat-side"></div><div class="og-lat-val"></div>\n <div class="og-lon-side"></div><div class="og-lon-val"></div>\n <div class="og-height"></div>\n <div class="og-units-height"></div>','<div class="og-lat-side"></div><div class="og-lat-val"></div>\n <div class="og-lon-side"></div><div class="og-lon-val"></div>\n <div class="og-height"></div>\n <div class="og-units-height"></div>'];class ar extends It{constructor(e={}){super(e),this._type=e.type||0,this._TYPE_FUNC=[this._SHOW_DECIMAL,this._SHOW_DEGREE],this._showFn=null,this._el=null,this._latSideEl=null,this._lonSideEl=null,this._latValEl=null,this._lonValEl=null,this._heightEl=null,this._altUnitVal=e.altitudeUnit||"m",this._heightModeVal=e.heightMode||"ell",this._altUnit=rr[this._altUnitVal],this._heightMode=Yn[this._heightModeVal],this._lonLat=null,this._centerMode=null==e.centerMode||e.centerMode}_SHOW_DECIMAL(e){if(e){let t=e.lat,i=e.lon;this._latSideEl.innerHTML=t>=0?"N":"S",this._lonSideEl.innerHTML=i>=0?"E":"W",this._latValEl.innerHTML=Math.abs(t).toFixed(7)+"°",this._lonValEl.innerHTML=Math.abs(i).toFixed(7)+"°"}}_SHOW_DEGREE(e){if(e){let t=e.lat,i=e.lon;this._latSideEl.innerHTML=t>=0?"N":"S",this._lonSideEl.innerHTML=i>=0?"E":"W";let n=0,r=t<0?Math.ceil(t):Math.floor(t),s=Math.floor(n=60*Math.abs(t-r)),a=Math.floor(6e3*(n-s))/100;this._latValEl.innerHTML=Math.abs(r)+"°"+s+"'"+a.toFixed(0)+'"',r=i<0?Math.ceil(i):Math.floor(i),s=Math.floor(n=60*Math.abs(i-r)),a=Math.floor(6e3*(n-s))/100,this._lonValEl.innerHTML=Math.abs(r)+"°"+s+"'"+a.toFixed(0)+'"'}}_createCenterEl(){let e=document.createElement("div");return e.className="og-center-icon",e.innerHTML='<svg width="12" height="12"><g><path stroke-width="1" stroke-opacity="1" d="M6 0L6 12M0 6L12 6" stroke="#337ab7"></path></g></svg>',e}_updateUnits(){this._heightMode=Yn[this._heightModeVal],this._altUnit=rr[this._altUnitVal],this._el.querySelector(".og-units-height").innerHTML=nr(this._altUnit),this._showHeight()}_refreshCoordinates(){this._type>=this._TYPE_FUNC.length&&(this._type=0);let e=this._el;e.innerHTML=sr[this._type],this._latSideEl=e.querySelector(".og-lat-side"),this._lonSideEl=e.querySelector(".og-lon-side"),this._latValEl=e.querySelector(".og-lat-val"),this._lonValEl=e.querySelector(".og-lon-val"),this._heightEl=e.querySelector(".og-height"),this._showFn=this._TYPE_FUNC[this._type],this._showFn(this._lonLat)}oninit(){this._el=document.createElement("div"),this._el.classList.add("og-coordinates"),this.renderer.div.appendChild(this._el),this._el.addEventListener("click",(()=>{this._type++,this._refreshCoordinates(),this._updateUnits(),this._showHeight()})),this._centerMode?(this.renderer.div.appendChild(this._createCenterEl()),this.planet.camera.events.on("moveend",this._grabCoordinates,this),this.planet.camera.events.on("moveend",Fe((()=>this._showHeight()),400,!0),this)):(this.renderer.events.on("mousemove",this._grabCoordinates,this),this.renderer.events.on("mousestop",Fe((()=>this._showHeight()),400,!0),this)),this._refreshCoordinates(),this._updateUnits()}_grabCoordinates(e){let t,i=e.pos,n=this.renderer;t=this._centerMode?n.handler.getCenter():i,this._lonLat=this.planet.getLonLatFromPixelTerrain(t)||null,this._showFn(this._lonLat)}async _showHeight(){if(this._lonLat&&this.planet){let e=0;this._heightEl.style.opacity="0.7",this._heightMode===Yn.ell?(e=await this.planet.getHeightAboveELL(this._lonLat),e=Number(ir(!0,0,this._altUnit,e))):this._heightMode===Yn.msl&&(e=await this.planet.getHeightDefault(this._lonLat),e=Number(ir(!0,0,this._altUnit,e))),this._heightEl.style.opacity="1.0",this._heightEl.innerHTML=e.toString()}}}let or=class{constructor(){this.x=0,this.y=0,this.prev_x=0,this.prev_y=0,this.grabbedPoint=new oe,this.grabbedSpheroid=new At}dX(){return this.x-this.prev_x}dY(){return this.y-this.prev_y}};class lr extends It{constructor(e={}){super(e),this.grabbedPoint=new oe,this.grabbedDir=new oe,this.inertia=.007,this.grabbedSpheroid=new At,this.planet=null,this._vRot=new ae,this._hRot=new ae,this._a=0,this.scaleRot=0,this.currState=0,this.positionState=[{h:17119745.303455353,max:.98,min:-.98},{h:6866011,max:.98,min:-.98},{h:3e6,max:.98,min:-.98},{h:1e6,max:.98,min:-.98},{h:5e5,max:.98,min:-.98}],this.touches=[new or,new or]}switchZoomState(e){this.stopRotation(),e>0?this.currState++:this.currState--,this.currState<=0&&(this.currState=0),this.currState>=this.positionState.length&&(this.currState=this.positionState.length-1),this.planet.stopFlying();const t=this.planet.camera._lonLat;this.planet.flyLonLat(new z(t.lon,t.lat,this.positionState[this.currState].h))}onMouseWheel(e){this.switchZoomState(e.wheelDelta)}oninit(){this.activate()}onactivate(){let e=this.renderer;e.events.on("mousewheel",this.onMouseWheel,this),e.events.on("lhold",this.onMouseLeftButtonDown,this),e.events.on("ldown",this.onMouseLeftButtonClick,this),e.events.on("lup",this.onMouseLeftButtonUp,this),e.events.on("touchstart",this.onTouchStart,this),e.events.on("touchend",this.onTouchEnd,this),e.events.on("touchmove",this.onTouchMove,this),e.events.on("draw",this.onDraw,this)}onTouchStart(e){if(1==e.sys.touches.length){const t=this.touches[0];t.x=e.sys.touches.item(0).pageX-e.sys.offsetLeft,t.y=e.sys.touches.item(0).pageY-e.sys.offsetTop,t.prev_x=e.sys.touches.item(0).pageX-e.sys.offsetLeft,t.prev_y=e.sys.touches.item(0).pageY-e.sys.offsetTop,t.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new le(t.x,t.y))||null,t.grabbedPoint&&(t.grabbedSpheroid.radius=t.grabbedPoint.length(),this.stopRotation())}}onTouchEnd(e){0==e.sys.touches.length&&(this.scaleRot=1,Math.abs(this.touches[0].x-this.touches[0].prev_x)<3&&Math.abs(this.touches[0].y-this.touches[0].prev_y)<3&&this.stopRotation())}onTouchMove(e){if(1==e.sys.touches.length){let t=this.planet.camera,i=this.touches[0];if(i.prev_x=i.x,i.prev_y=i.y,i.x=e.sys.touches.item(0).pageX-e.sys.offsetLeft,i.y=e.sys.touches.item(0).pageY-e.sys.offsetTop,!i.grabbedPoint)return;let n=t.unproject(i.x,i.y),r=new _i(t.eye,n).hitSphere(i.grabbedSpheroid);if(r){this._a=Math.acos(i.grabbedPoint.y/i.grabbedSpheroid.radius)-Math.acos(r.y/i.grabbedSpheroid.radius),this._vRot=ae.axisAngleToQuat(t._u,this._a),this._hRot=ae.getRotationBetweenVectors(new oe(r.x,0,r.z).normal(),new oe(i.grabbedPoint.x,0,i.grabbedPoint.z).normal());let e=this._hRot.mul(this._vRot),n=this.positionState[this.currState],s=e.mulVec3(t.eye).normal().dot(oe.NORTH);(s>n.max||s<n.min)&&(e=ae.yRotation(e.getYaw())),t.set(e.mulVec3(t.eye),oe.ZERO,oe.NORTH),t.update()}}}onMouseLeftButtonClick(e){this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this.grabbedPoint=this.planet.getCartesianFromMouseTerrain()||null,this.grabbedDir.copy(e.direction),this.grabbedPoint&&(this.grabbedSpheroid.radius=this.grabbedPoint.length(),this.stopRotation())}stopRotation(){this.scaleRot=0,this._a=0,this._vRot.clear(),this._hRot.clear()}onMouseLeftButtonUp(e){this.scaleRot=1,this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),Math.abs(e.x-e.prev_x)<3&&Math.abs(e.y-e.prev_y)<3&&this.stopRotation()}onMouseLeftButtonDown(e){let t=this.planet.camera;if(this.grabbedPoint&&!t.isFlying())if(this.renderer.events.mouseState.moving){let i=new _i(t.eye,e.direction).hitSphere(this.grabbedSpheroid);if(i){this._a=Math.acos(this.grabbedPoint.y/this.grabbedSpheroid.radius)-Math.acos(i.y/this.grabbedSpheroid.radius);let e=this._vRot=ae.axisAngleToQuat(t._u,this._a);t.set(e.mulVec3(t.eye),oe.ZERO,e.mulVec3(t.getUp())),this._hRot=ae.getRotationBetweenVectors(new oe(i.x,0,i.z).normal(),new oe(this.grabbedPoint.x,0,this.grabbedPoint.z).normal()),e=this._hRot,t.set(e.mulVec3(t.eye),oe.ZERO,e.mulVec3(t.getUp())),t.update()}}else this.scaleRot=0}onDraw(){let e=this.renderer,t=this.planet.camera;if(!e.events.mouseState.leftButtonDown&&this.scaleRot&&!t.isFlying())if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{this._vRot=ae.axisAngleToQuat(t._u,this._a);let i=this._vRot.mul(this._hRot),n=i.mulVec3(t.eye).normal().dot(oe.NORTH),r=this.positionState[this.currState];(n>r.max||n<r.min)&&(i=ae.yRotation(i.getYaw())),e.controlsBag.scaleRot=this.scaleRot,i=i.slerp(ae.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize(),i.x||i.y||i.z||(this.scaleRot=0),t.set(i.mulVec3(t.eye),oe.ZERO,oe.NORTH),t.update()}}}const hr=["loadend"];class cr extends qt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(hr),this._projType=0,this._frameWidth=256,this._frameHeight=256,this._sourceReady=!1,this._sourceTexture=null,this._materialTexture=null,this._gridBufferLow=null,this._gridBufferHigh=null,this._extentWgs84ParamsHigh=new Float32Array(4),this._extentWgs84ParamsLow=new Float32Array(4),this._extentMercParamsHigh=new Float32Array(4),this._extentMercParamsLow=new Float32Array(4),this._refreshFrame=!0,this._frameCreated=!1,this._sourceCreated=!1,this._animate=!1,this._ready=!1,this._creationProceeding=!1,this._isRendering=!1,this._extentWgs84=new ie,this._cornersWgs84=[],this._cornersMerc=[],this._isFullExtent=t.fullExtent?1:0,this.rendering=this._renderingProjType0.bind(this),this._onLoadend_=null,t.corners&&this.setCorners(t.corners)}get isIdle(){return super.isIdle&&this._ready}addTo(e){return this._onLoadend_=this._onLoadend.bind(this),this.events.on("loadend",this._onLoadend_,this),super.addTo(e)}_onLoadend(){this._planet&&this._planet.events.dispatch(this._planet.events.layerloadend,this)}remove(){return this.events.off("loadend",this._onLoadend_),this._onLoadend_=null,super.remove()}get instanceName(){return"BaseGeoImage"}getCornersLonLat(){let e=this._cornersWgs84;return[new z(e[0].lon,e[0].lat),new z(e[1].lon,e[1].lat),new z(e[2].lon,e[2].lat),new z(e[3].lon,e[3].lat)]}getCorners(){let e=this._cornersWgs84;return[[e[0].lon,e[0].lat],[e[1].lon,e[1].lat],[e[2].lon,e[2].lat],[e[3].lon,e[3].lat]]}setCorners(e){this.setCornersLonLat(z.join(e))}setCornersLonLat(e){this._refreshFrame=!0,this._cornersWgs84=[e[0].clone(),e[1].clone(),e[2].clone(),e[3].clone()];for(let e=0;e<this._cornersWgs84.length;e++)this._cornersWgs84[e].lat>=89.9&&(this._cornersWgs84[e].lat=89.9),this._cornersWgs84[e].lat<=-89.9&&(this._cornersWgs84[e].lat=-89.9);this._extent.setByCoordinates(this._cornersWgs84);let t=this._extent;t.southWest.lat>J||t.northEast.lat<ee?(this._projType=0,this.rendering=this._renderingProjType0):(this._projType=1,this.rendering=this._renderingProjType1),this._ready&&!this._creationProceeding&&this._planet._geoImageCreator.add(this)}_createFrame(){this._extentWgs84=this._extent.clone(),this._cornersMerc=[this._cornersWgs84[0].forwardMercatorEPS01(),this._cornersWgs84[1].forwardMercatorEPS01(),this._cornersWgs84[2].forwardMercatorEPS01(),this._cornersWgs84[3].forwardMercatorEPS01()],this._extentMerc=new ie(this._extentWgs84.southWest.forwardMercatorEPS01(),this._extentWgs84.northEast.forwardMercatorEPS01());let e=new Float32Array(2);if(0===this._projType?(nn(this._extentWgs84.southWest.lon,e),this._extentWgs84ParamsHigh[0]=e[0],this._extentWgs84ParamsLow[0]=e[1],nn(this._extentWgs84.southWest.lat,e),this._extentWgs84ParamsHigh[1]=e[0],this._extentWgs84ParamsLow[1]=e[1],this._extentWgs84ParamsHigh[2]=2/this._extentWgs84.getWidth(),this._extentWgs84ParamsHigh[3]=2/this._extentWgs84.getHeight()):(nn(this._extentMerc.southWest.lon,e),this._extentMercParamsHigh[0]=e[0],this._extentMercParamsLow[0]=e[1],nn(this._extentMerc.southWest.lat,e),this._extentMercParamsHigh[1]=e[0],this._extentMercParamsLow[1]=e[1],this._extentMercParamsHigh[2]=2/this._extentMerc.getWidth(),this._extentMercParamsHigh[3]=2/this._extentMerc.getHeight()),this._planet){let e=this._planet.renderer.handler;e.gl.deleteTexture(this._materialTexture),this._materialTexture=e.createEmptyTexture_l(this._frameWidth,this._frameHeight);let t=this._planet._geoImageCreator.createGridBuffer(this._cornersWgs84,1===this._projType);this._gridBufferHigh=t[0],this._gridBufferLow=t[1],this._refreshFrame=!1}}abortMaterialLoading(e){this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}clear(){let e=this._planet;if(e){let t=e.renderer.handler.gl;this._creationProceeding&&e._geoImageCreator.remove(this),e._clearLayerMaterial(this),t&&(t.deleteBuffer(this._gridBufferHigh),t.deleteBuffer(this._gridBufferLow),t.deleteTexture(this._sourceTexture),this._materialTexture&&!this._materialTexture.default&&t.deleteTexture(this._materialTexture))}this._sourceTexture=null,this._materialTexture=null,this._gridBufferHigh=null,this._gridBufferLow=null,this._refreshFrame=!0,this._sourceCreated=!1,this._ready=!1,this._creationProceeding=!1}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),this._planet&&this._sourceReady&&(e?this._planet._geoImageCreator.add(this):this._planet._geoImageCreator.remove(this)))}clearMaterial(e){e.texture=null,e.isLoading=!1,e.isReady=!1}applyMaterial(e){let t,i,n=e.segment;this._ready?e.applyTexture(this._materialTexture):(e.texture=this._planet.transparentTexture,!this._creationProceeding&&this.loadMaterial(e)),0===this._projType?(t=this._extentWgs84,i=n._extent):(t=this._extentMerc,i=n.getExtentMerc());let r=t.northEast.lon-t.southWest.lon,s=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/r,(t.northEast.lat-i.northEast.lat)/s,(i.northEast.lon-i.southWest.lon)/r,(i.northEast.lat-i.southWest.lat)/s]}get getFrameWidth(){return this._frameWidth}get getFrameHeight(){return this._frameHeight}_createSourceTexture(){}_renderingProjType1(){let e=this._planet,t=e.renderer.handler,i=t.gl,n=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let r=n._framebuffer;r.setSize(this._frameWidth,this._frameHeight),r.activate(),t.programs.geoImageTransform.activate();let s=t.programs.geoImageTransform._program,a=s.attributes,o=s.uniforms;i.disable(i.CULL_FACE),r.bindOutputTexture(this._materialTexture),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.uniform1i(o.isFullExtent,this._isFullExtent),i.bindBuffer(i.ARRAY_BUFFER,n._texCoordsBuffer),i.vertexAttribPointer(a.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(a.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(a.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(o.extentParamsHigh,this._extentMercParamsHigh),i.uniform4fv(o.extentParamsLow,this._extentMercParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(o.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,n._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,n._indexBuffer.numItems,i.UNSIGNED_INT,0),r.deactivate(),i.enable(i.CULL_FACE),this._ready=!0,this._creationProceeding=!1}_renderingProjType0(){let e=this._planet,t=e.renderer.handler,i=t.gl,n=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let r=n._framebuffer;r.setSize(this._frameWidth,this._frameHeight),r.activate(),t.programs.geoImageTransform.activate();let s=t.programs.geoImageTransform._program,a=s.attributes,o=s.uniforms;i.disable(i.CULL_FACE),r.bindOutputTexture(this._materialTexture),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.bindBuffer(i.ARRAY_BUFFER,n._texCoordsBuffer),i.vertexAttribPointer(a.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(a.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(a.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(o.extentParamsHigh,this._extentWgs84ParamsHigh),i.uniform4fv(o.extentParamsLow,this._extentWgs84ParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(o.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,n._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,n._indexBuffer.numItems,i.UNSIGNED_INT,0),r.deactivate(),i.enable(i.CULL_FACE),this._ready=!0,this._creationProceeding=!1}}const dr={MB_LEFT:0,MB_RIGHT:2,MB_MIDDLE:1,KEY_CTRL:17,KEY_ALT:18,KEY_SHIFT:16,KEY_SPACE:32,KEY_PGUP:33,KEY_PGDN:34,KEY_LEFT:37,KEY_UP:38,KEY_RIGHT:39,KEY_DOWN:40,KEY_PRINTSCREEN:44,KEY_EQUALS:61,KEY_A:65,KEY_C:67,KEY_D:68,KEY_E:69,KEY_F:70,KEY_H:72,KEY_I:73,KEY_K:75,KEY_L:76,KEY_N:78,KEY_O:79,KEY_P:80,KEY_Q:81,KEY_R:82,KEY_S:83,KEY_V:86,KEY_W:87,KEY_X:88,KEY_Z:90,KEY_PLUS:107,KEY_F1:112,KEY_MINUS:173,KEY_APOSTROPHE:192,KEY_BACK_SLASH:220,KEY_MORE:190,KEY_SLASH:191,KEY_LESS:188,KEY_LEFT_SQUARE_BRACKET:219,KEY_RIGHT_SQUARE_BRACKET:221,KEY_SINGLE_QUOTE:222};const _r=["change","idle","play","pause","stop"];class ur extends Bt{constructor(e){super({template:be('<button title={title} class="og-layerSwitcher__layerButton">{icon}<div class="og-layerSwitcher__name">{name}</div></button>',{title:e.model.name,name:e.model.name,icon:e.model.iconSrc?`<img src="${e.model.iconSrc}" />`:""}),...e}),this._onVisibilityChange=e=>{this.el&&(this.model.getVisibility()?this.el.classList.add("og-layerSwitcher__visible"):this.el.classList.remove("og-layerSwitcher__visible"))},this._onClick=()=>{this.model.isBaseLayer()?this.model.setVisibility(!0):this.model.setVisibility(!this.model.getVisibility())},this._onDblClick=()=>{this.model.flyExtent()}}render(e){return super.render(e),this.model.events.on("visibilitychange",this._onVisibilityChange),this._onVisibilityChange(this.model),this.el.addEventListener("click",this._onClick),this.el.addEventListener("dblclick",this._onDblClick),this}remove(){super.remove(),this.model.events.off("visibilitychange",this._onVisibilityChange)}}const fr=["change"];class gr extends Bt{constructor(e={}){super({template:be('<div class="og-slider">\n <div class="og-slider-label">{label}</div>\n <div class="og-slider-panel">\n <div class="og-slider-progress"></div> \n <div class="og-slider-pointer"></div>\n </div>\n <input type="number"/>\n </div>',{label:e.label||""})}),this._onResize=()=>{this._setOffset((this._value-this._min)*this.$panel.clientWidth/(this._max-this._min))},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this.value=this._value+Math.sign(e.wheelDelta)*(this._max-this._min)/100},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onInput=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this.value=parseFloat(e.target.value)},this._onMouseDown=e=>{(e=e||window.event).preventDefault(),this._startPosX=e.clientX,this.value=this._min+(this._max-this._min)*(e.offsetX/this.$panel.clientWidth),document.addEventListener("mousemove",this._onMouseMove),document.addEventListener("mouseup",this._onMouseUp)},this._onMouseMove=e=>{(e=e||window.event).preventDefault(),e.stopPropagation();let t=this.$panel.getBoundingClientRect(),i=p(e.clientX,t.left,t.right),n=this._startPosX-i;this._startPosX=i,this.value=this._value-n*(this._max-this._min)/this.$panel.clientWidth},this._onMouseUp=()=>{document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove)},this.events=this.events.registerNames(fr),this._value=e.value||0,this._min=e.min||0,this._max=e.max||1,this._resizeObserver=new ResizeObserver(this._onResize),this._startPosX=0,this.$label=null,this.$pointer=null,this.$progress=null,this.$input=null,this.$panel=null}render(e){return super.render(e),this.$label=this.select(".og-slider-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$pointer=this.select(".og-slider-pointer"),this.$progress=this.select(".og-slider-progress"),this.$panel=this.select(".og-slider-panel"),this.$input=this.select("input"),this._resizeObserver.observe(this.el),this._initEvents(),this}set value(e){e!==this._value&&(this._value=p(e,this._min,this._max),this.$input.value=this._value.toString(),this._setOffset((this._value-this._min)*this.$panel.clientWidth/(this._max-this._min)),this.events.dispatch(this.events.change,this._value,this))}get value(){return this._value}_initEvents(){this.$panel.addEventListener("mousedown",this._onMouseDown),this.$panel.addEventListener("mousewheel",this._onMouseWheel),this.$panel.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.$panel.removeEventListener("mousedown",this._onMouseDown),this.$panel.removeEventListener("mousewheel",this._onMouseWheel),this.$panel.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("input",this._onInput)}_setOffset(e){e>=0&&e<=this.$panel.clientWidth&&(this.$pointer.style.left=this.$progress.style.width=100*e/this.$panel.clientWidth+"%")}remove(){this._clearEvents(),super.remove()}}const pr=["input"];let mr=0;class vr extends Bt{constructor(e={}){super({template:be('<div class="og-color">\n <label for="{id}" class="og-color-label">{label}</label>\n <input type="color" name="{id}" value="{value}"/>\n </div>',{id:"color-"+mr++,label:e.label||""})}),this._onInput=e=>{this.value=e.target.value},this.events=this.events.registerNames(pr),this._value=e.value||"blue",this.$label=null,this.$input=null}render(e){return super.render(e),this.$label=this.select(".og-color-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$input=this.select("input"),this._initEvents(),this}set value(e){e!==this._value&&(this._value=e,this.$input.value=this._value,this.events.dispatch(this.events.input,this._value,this))}get value(){return this._value}_initEvents(){this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.$input.removeEventListener("input",this._onInput)}remove(){this._clearEvents(),super.remove()}}class yr{constructor(){this._lock=0}lock(e){this._lock|=1<<e.id}free(e){this._lock&=~(1<<e.id)}isFree(){return 0===this._lock}isLocked(){return 0!==this._lock}}class xr{constructor(){this.__id=xr.__counter__++}get id(){return this.__id}}xr.__counter__=0;class br extends It{constructor(e={}){super(e),this._deactivate=!1,this._shiftBusy=!1,this._name="mouseNavigation",this.grabbedPoint=new oe,this._eye0=new oe,this.pointOnEarth=new oe,this.earthUp=new oe,this.inertia=.007,this.grabbedSpheroid=new At,this.qRot=new ae,this.scaleRot=0,this.distDiff=.3,this.stepsCount=8,this.stepsForward=null,this.stepIndex=0,this._lmbDoubleClickActive=!0,this.minSlope=e.minSlope||.1,this._wheelDirection=1,this._keyLock=new xr}static getMovePointsFromPixelTerrain(e,t,i,n,r,s,a){const o=[];let l=e.eye.clone(),h=e._b.clone(),c=e._r.clone(),d=e._u.clone(),_=t.getCartesianFromPixelTerrain(r);if(_||(_=t.getCartesianFromPixelTerrain(t.renderer.handler.getCenter())),_){a||(a=oe.sub(_,e.eye).normalize());let t=n*e.eye.distance(_)/i;t*=s?-1.25:2;const r=h.scaleTo(t);if(a.dot(e.eye.normal().negate())>=.1){const t=new At;t.radius=_.length();let n=[],s=[],u=!1;for(let e=0;e<i;e++){l.addA(r);const i=new _i(l,a).hitSphere(t);if(s[e]=l.clone(),!i){u=!0;break}n[e]=(new se).rotateBetweenVectors(_.normal(),i.normal())}if(u){l=e.eye.clone();for(let e=0;e<i;e++)o[e]={eye:l.addA(r).clone(),v:d,u:c,n:h}}else for(let e=0;e<i;e++){let t=n[e];o[e]={eye:t.mulVec3(s[e]),v:t.mulVec3(d),u:t.mulVec3(c),n:t.mulVec3(h)}}}else for(let e=0;e<i;e++)o[e]={eye:l.addA(a.scaleTo(-t)).clone(),v:d,u:c,n:h};return o}}onactivate(){this.renderer&&(this.renderer.events.on("mousewheel",this.onMouseWheel,this),this.renderer.events.on("lhold",this.onMouseLeftButtonDown,this),this.renderer.events.on("rhold",this.onMouseRightButtonDown,this),this.renderer.events.on("ldown",this.onMouseLeftButtonClick,this),this.renderer.events.on("lup",this.onMouseLeftButtonUp,this),this.renderer.events.on("rdown",this.onMouseRightButtonClick,this),this.renderer.events.on("draw",this.onDraw,this,-1e3),this.renderer.events.on("mousemove",this.onMouseMove,this),this.renderer.events.on("mouseleave",this.onMouseLeave,this),this.renderer.events.on("mouseenter",this.onMouseEnter,this),this._lmbDoubleClickActive&&this.renderer.events.on("ldblclick",this.onMouseLeftButtonDoubleClick,this))}ondeactivate(){this.renderer&&(this.renderer.events.off("mousewheel",this.onMouseWheel),this.renderer.events.off("lhold",this.onMouseLeftButtonDown),this.renderer.events.off("rhold",this.onMouseRightButtonDown),this.renderer.events.off("ldown",this.onMouseLeftButtonClick),this.renderer.events.off("lup",this.onMouseLeftButtonUp),this.renderer.events.off("rdown",this.onMouseRightButtonClick),this.renderer.events.off("draw",this.onDraw),this.renderer.events.off("ldblclick",this.onMouseLeftButtonDoubleClick),this.renderer.events.off("mouseleave",this.onMouseLeave),this.renderer.events.off("mouseenter",this.onMouseEnter))}activateDoubleClickZoom(){this._lmbDoubleClickActive||(this._lmbDoubleClickActive=!0,this.renderer&&this.renderer.events.on("ldblclick",this.onMouseLeftButtonDoubleClick,this))}deactivateDoubleClickZoom(){this._lmbDoubleClickActive&&(this._lmbDoubleClickActive=!1,this.renderer&&this.renderer.events.off("ldblclick",this.onMouseLeftButtonDoubleClick))}onMouseEnter(e){const t=this.renderer.events;t.isKeyPressed(dr.KEY_ALT)&&t.releaseKeys(),t.updateButtonsStates(e.sys.buttons),t.mouseState.leftButtonDown?this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"):this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")}onMouseLeave(){this.renderer.events.mouseState.leftButtonDown&&(this.scaleRot=0),this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")}onMouseWheel(e){this.stepIndex||(this.planet.stopFlying(),this.stopRotation(),this._deactivate=!0,this.lockPlanet(!0),this.stepsForward=br.getMovePointsFromPixelTerrain(this.planet.camera,this.planet,this.stepsCount,this.distDiff,e.pos,e.wheelDelta>0,e.direction)||null,this._wheelDirection=e.wheelDelta,this.stepsForward&&(this.stepIndex=this.stepsCount))}oninit(){this.activate(),this.renderer&&(this.renderer.events.on("keyfree",dr.KEY_ALT,this.onShiftFree,this),this.renderer.events.on("keyfree",dr.KEY_PRINTSCREEN,this.onShiftFree,this))}onMouseLeftButtonDoubleClick(e){this.planet.stopFlying(),this.stopRotation();const t=this.planet.getCartesianFromPixelTerrain(e.pos);if(t){const e=this.planet.camera;let i=e.maxAltitude+this.planet.ellipsoid.polarSize,n=e.minAltitude+this.planet.ellipsoid.polarSize;const r=e.eye.length(),s=this.planet.ellipsoid.cartesianToLonLat(t);if(r>i||r<n)return void this.planet.flyLonLat(new z(s.lon,s.lat));this.renderer.events.isKeyPressed(dr.KEY_ALT)?this.planet.flyLonLat(new z(s.lon,s.lat,2*e.eye.distance(t))):this.planet.flyLonLat(new z(s.lon,s.lat,.57*e.eye.distance(t)))}}onMouseLeftButtonClick(){this._active&&(this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this.grabbedPoint=this.planet.getCartesianFromMouseTerrain(),this.grabbedPoint&&(this._eye0.copy(this.planet.camera.eye),this.grabbedSpheroid.radius=this.grabbedPoint.length(),this.stopRotation()))}stopRotation(){this.qRot.clear(),this.freePlanet()}onMouseLeftButtonUp(e){this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.x===e.prev_x&&e.y===e.prev_y&&(this.scaleRot=0)}onMouseLeftButtonDown(e){if(this._active){if(!this.grabbedPoint)return;if(this.planet.stopFlying(),e.moving){let t=this.planet.camera;if(t.slope>.2){const i=new _i(t.eye,e.direction).hitSphere(this.grabbedSpheroid);if(i){this.scaleRot=1,this.qRot=ae.getRotationBetweenVectors(i.normal(),this.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t._u=e.mulVec3(t._u),t._r=e.mulVec3(t._r),t._b=e.mulVec3(t._b)}}else{let i=this.grabbedPoint,n=oe.add(i,t._r),r=oe.add(i,i.normal()),s=new oe;new _i(t.eye,e.direction).hitPlane(i,n,r,s)===_i.INSIDE&&(t.eye=this._eye0.addA(s.subA(i).negate()))}}}}onMouseRightButtonClick(e){this.stopRotation(),this.planet.stopFlying(),this.pointOnEarth=this.planet.getCartesianFromPixelTerrain(e.pos),this.pointOnEarth&&(this.earthUp=this.pointOnEarth.normal())}onMouseRightButtonDown(e){const t=this.planet.camera;if(this.pointOnEarth&&e.moving){this.renderer.controlsBag.scaleRot=1;let i=.5/t.eye.distance(this.pointOnEarth)*t._lonLat.height*o;i>.007?i=.007:i<.003&&(i=.003),t.rotateHorizontal(i*(e.x-e.prev_x),!1,this.pointOnEarth,this.earthUp),t.rotateVertical(i*(e.y-e.prev_y),this.pointOnEarth,this.minSlope)}}onShiftFree(){this._shiftBusy=!1}onMouseMove(e){this._active&&this.renderer.events.isKeyPressed(dr.KEY_ALT)&&(this._shiftBusy||(this._shiftBusy=!0,this.onMouseRightButtonClick(e)),this.onMouseRightButtonDown(e))}onDraw(){if(this._active){const e=this.renderer,t=this.planet.camera;let i=t.eye.clone();if(this.stepIndex){e.controlsBag.scaleRot=1;const i=this.stepsForward[this.stepsCount-this.stepIndex--];t.eye=i.eye,t._u=i.v,t._r=i.u,t._b=i.n}else this._deactivate&&(this._deactivate=!1,this.freePlanet());if(e.events.mouseState.leftButtonDown||!this.scaleRot)return;if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{e.controlsBag.scaleRot=this.scaleRot;let i=this.qRot.slerp(ae.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize();i.x||i.y||i.z||(this.scaleRot=0),t.eye=i.mulVec3(t.eye),t._u=i.mulVec3(t._u),t._r=i.mulVec3(t._r),t._b=i.mulVec3(t._b)}t.eye.distance(i)/t.getAltitude()>.01?this.lockPlanet():this.freePlanet()}}lockPlanet(e){this.planet.layerLock.lock(this._keyLock),!e&&this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock)}freePlanet(){this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}}const wr=e=>e>1e3?`${(e/1e3).toFixed(1)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`;let Cr=gi.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);const Tr={text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,20,0]},Lr={scale:1,instanced:!0,tag:"ruler",color:"rgb(0,305,0)",object3d:Cr};class Ar extends Pi{constructor(e={}){super(e.name),this._onCornerLdown=e=>{if(!this._startLonLat){this.renderer?.controls.mouseNavigation?.deactivate(),this._startClick.set(e.x,e.y);let t=e.pickingObject.getCartesian();this._startPos=this._planet.getPixelFromCartesian(t),this._pickedCorner=e.pickingObject,"start"==e.pickingObject.properties.name?this._anchorLonLat=this._cornerEntity[1].getLonLat().clone():this._anchorLonLat=this._cornerEntity[0].getLonLat().clone()}},this._onLUp=()=>{this._pickedCorner&&(this.renderer.controls.mouseNavigation?.activate(),this._pickedCorner=null,this._anchorLonLat=null)},this._onCornerLup=()=>{this._onLUp()},this._onCornerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onCornerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onLdblclick=()=>{this._preventClick=!0},this._onLclick=e=>{let t=this._planet.getLonLatFromPixelTerrain(e.pos);t&&(this._timeout=setTimeout((()=>{this._preventClick||(this._startLonLat?this._startLonLat=null:(this.setVisibility(!0),this._stopDrawing=!1,this._startLonLat=t)),this._preventClick=!1,this._stopDrawing=!1,clearTimeout(this._timeout)}),200),this._startLonLat&&(this._stopDrawing=!0))},this._onMouseMove=e=>{if(this._startLonLat&&!this._stopDrawing){this._propsLabel.label.setVisibility(!0);let t=this._planet.getLonLatFromPixelTerrain(e.pos);if(!t)return;this._drawLine(this._startLonLat,t)}else if(this._pickedCorner){let t=this._planet.getLonLatFromPixelTerrain(e.pos);t&&("start"===this._pickedCorner.properties.name?this._drawLine(t,this._anchorLonLat):this._drawLine(this._anchorLonLat,t))}},this.events=Pt(Er),this._ignoreTerrain=null==e.ignoreTerrain||e.ignoreTerrain,this._planet=e.planet||null,this._startLonLat=null,this._preventClick=!1,this._stopDrawing=!1,this._pickedCorner=null,this._startPos=null,this._startClick=new le,this._anchorLonLat=null,this._heading=0,this._trackLayer=new In("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._labelLayer=new In("ruler-label",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-100,relativeToGround:!0,hideInLayerSwitcher:!0}),this._cornersLayer=new In("corners",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[100,4e6,1],pickingScale:2}),this._propsLabel=new Ai({name:"propsLabel",label:Tr}),this._trackEntity=new Ai({polyline:{path3v:[],thickness:4.8,color:"rgb(255,131,0)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01,this._cornerEntity=[new Ai({geoObject:Lr,properties:{name:"start"}}),new Ai({geoObject:Lr,properties:{name:"end"}})]}set ignoreTerrain(e){this._ignoreTerrain=e}bindPlanet(e){this._planet=e}_createCorners(){this._cornersLayer.addEntities(this._cornerEntity)}init(){this._createCorners(),this._trackLayer.addEntities([this._trackEntity]),this._labelLayer.addEntities([this._propsLabel]),this._planet.addLayer(this._labelLayer),this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._cornersLayer),this._activate()}onremove(){this._deactivate()}_activate(){this._propsLabel.label.setVisibility(!1),this.setVisibility(!1),this.renderer.events.on("lclick",this._onLclick,this),this.renderer.events.on("mousemove",this._onMouseMove,this),this.renderer.events.on("ldblclick",this._onLdblclick,this),this.renderer.events.on("lup",this._onLUp,this),this._cornersLayer.events.on("mouseenter",this._onCornerEnter,this),this._cornersLayer.events.on("mouseleave",this._onCornerLeave,this),this._cornersLayer.events.on("ldown",this._onCornerLdown,this),this._cornersLayer.events.on("lup",this._onCornerLup,this)}_deactivate(){this._startLonLat=null,this._preventClick=!1,this._stopDrawing=!1,this._pickedCorner=null,this.renderer.events.off("lclick",this._onLclick),this.renderer.events.off("mousemove",this._onMouseMove),this.renderer.events.off("lup",this._onLUp),this._cornersLayer.events.off("mouseenter",this._onCornerEnter),this._cornersLayer.events.off("mouseleave",this._onCornerLeave),this._cornersLayer.events.off("ldown",this._onCornerLdown),this._cornersLayer.events.off("lup",this._onCornerLup),this.clear()}setVisibility(e){this._cornersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._labelLayer.setVisibility(e)}_drawLine(e,t,i){i||(i=this._planet.ellipsoid.lonLatToCartesian(e));let n=this._planet.ellipsoid.lonLatToCartesian(t),r=this._planet.ellipsoid.inverse(e,t),s=r.distance;this._heading=r.initialAzimuth;let a=[],o=n.sub(i),l=o.length();o.normalize();for(let e=0;e<120;e++){let t=o.scaleTo(e*l/120).addA(i);a.push(t)}a.push(n),this._trackEntity.polyline.setPath3v([a]),this._ignoreTerrain&&(this._propsLabel.setCartesian3v(a[Math.floor(a.length/2)]),this._propsLabel.label.setText(`${wr(s)}, ${Math.round(this._heading)} deg`))}clear(){this._trackEntity.remove(),this._cornerEntity[0].remove(),this._cornerEntity[1].remove(),this._propsLabel.remove(),this._planet.removeLayer(this._trackLayer),this._planet.removeLayer(this._cornersLayer)}isCornersPositionChanged(){let e=this._trackEntity.polyline.getPath3v()[0];if(e){const t=e[0].clone(),i=e[e.length-1].clone();return this._cornerEntity[0].getCartesian().equal(t)&&this._cornerEntity[1].getCartesian().equal(i)}return!1}frame(){let e=this._trackEntity.polyline.getPath3v()[0];if(e){const t=e[0].clone(),i=e[e.length-1].clone();if(!this.isCornersPositionChanged()&&(this._cornerEntity[0].setCartesian3v(t),this._cornerEntity[1].setCartesian3v(i),!this._ignoreTerrain)){let t=0;for(let i=0,n=e.length-1;i<n;i++)t+=e[i+1].distance(e[i]);this._propsLabel.setCartesian3v(e[Math.floor(e.length/2)]),this._propsLabel.label.setText(`${wr(t)}, ${Math.round(this._heading)} deg`)}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Er=["add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];class Pr extends It{constructor(e={}){super(e),this._rulerScene=new Ar({name:`rulerScene:${this.__id}`,ignoreTerrain:e.ignoreTerrain})}set ignoreTerrain(e){this._rulerScene.ignoreTerrain=e}oninit(){this._rulerScene.bindPlanet(this.planet)}onactivate(){this.renderer&&this.renderer.addNode(this._rulerScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._rulerScene)}}let Sr=gi.createCylinder(1.1,0,2,6,1,!0,!0,0,0,0);const Mr={startColor:"rgb(255,131,0)",endColor:"rgb(255,131,0)",thickness:5},Br={text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,18,0]},kr={scale:1,instanced:!0,tag:"height-ruler",color:"rgb(255,131,0)",object3d:Sr};class Rr extends Ar{constructor(e={}){super(e),this._geoRulerLayer=new In("rayHeightRuler",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-2,relativeToGround:!1,hideInLayerSwitcher:!0}),this._rayV=new Ai({name:"verticalRay",ray:Mr}),this._rayH=new Ai({name:"heightRay",ray:Mr}),this._heightLabels=[new Ai({name:"startCornerLabel",label:{...Br}}),new Ai({name:"endCornerLabel",label:{...Br}}),new Ai({name:"deltaLabel",label:{...Br}})]}setVisibility(e){super.setVisibility(e),this._geoRulerLayer.setVisibility(e)}get deltaLabel(){return this._heightLabels[2]}get startLabel(){return this._heightLabels[0]}get endLabel(){return this._heightLabels[1]}get corners(){return this._cornerEntity}get startCorner(){return this.corners[0]}get endCorner(){return this.corners[1]}get startCornerLonLat(){return this.startCorner.getLonLat()}get startCornerHeight(){return this.startCornerLonLat.height}get endCornerLonLat(){return this.endCorner.getLonLat()}get endCornerHeight(){return this.endCornerLonLat.height}get maxHeightCornerLonLat(){return this.startCornerHeight<=this.endCornerHeight?this.endCornerLonLat:this.startCornerLonLat}get minHeightCornerLonLat(){return this.startCornerHeight>this.endCornerHeight?this.endCornerLonLat:this.startCornerLonLat}get deltaHeight(){return Math.abs(this.startCornerHeight-this.endCornerHeight)}_drawLine(e,t,i){super._drawLine(e,t,i),this._updateHeightRaysAndLabels()}async _updateHeightRaysAndLabels(){const e=this.minHeightCornerLonLat.clone();e.height=this.maxHeightCornerLonLat.height,this._rayH.ray.setStartPosition3v(this._planet.ellipsoid.lonLatToCartesian(this.maxHeightCornerLonLat)),this._rayH.ray.setEndPosition3v(this._planet.ellipsoid.lonLatToCartesian(e)),this._rayV.ray.setStartPosition3v(this._planet.ellipsoid.lonLatToCartesian(this.minHeightCornerLonLat)),this._rayV.ray.setEndPosition3v(this._planet.ellipsoid.lonLatToCartesian(e)),e.height=this.minHeightCornerLonLat.height+this.deltaHeight/2,this.deltaLabel.setLonLat(e),this.startLabel.setLonLat(this.startCornerLonLat),this.endLabel.setLonLat(this.endCornerLonLat);const t=await this._planet.getHeightDefault(this.startCornerLonLat),i=await this._planet.getHeightDefault(this.endCornerLonLat);this.deltaLabel.label.setText(`Δ ${Math.abs(t-i).toFixed(1)} m`),this.startLabel.label.setText(`P1 ${t.toFixed(1)} m`),this.endLabel.label.setText(`P2 ${i.toFixed(1)} m`)}clear(){this._rayH.remove(),this._rayV.remove(),this.startCorner.remove(),this.endCorner.remove(),this.startLabel.remove(),this.endLabel.remove(),this.deltaLabel.remove(),super.clear(),this._planet.removeLayer(this._geoRulerLayer)}_createCorners(){this._cornerEntity=[new Ai({geoObject:kr,properties:{name:"start"}}),new Ai({geoObject:kr,properties:{name:"end"}})],this._cornersLayer.setEntities(this._cornerEntity)}init(){super.init(),this._createCorners(),this._labelLayer.addEntities(this._heightLabels),this._geoRulerLayer.addEntities([this._rayH,this._rayV]),this._planet.addLayer(this._geoRulerLayer)}frame(){super.frame(),this._updateHeightRaysAndLabels()}}class Ir extends Pr{constructor(e={}){super(e),this._rulerScene=new Rr({name:`heightRulerScene:${this.__id}`,ignoreTerrain:!1})}}const zr=[1,2,3,5,10,20,30,50,100,200,300,500,1e3,2e3,3e3,5e3,1e4,2e4,3e4,5e4,1e5,2e5,3e5,5e5,1e6,2e6,3e6,5e6,1e7];class Dr extends It{constructor(e={}){e.name&&""!==e.name||(e.name="scaleControl"),super(e),this._template='<div class="og-scale-container">\n <div class="og-scale-label"></div>\n <div class="og-scale-ruler"></div>\n </div>',this._minWidth=100,this._maxWidth=150,this._isCenter=null==e.isCenter||e.isCenter,this._mPx=0,this.currWidth=0,this._metersInMinSize=0,this.el=null,this._scaleLabelEl=null}_renderTemplate(){return we(this._template)[0]}oninit(){this.el=this._renderTemplate(),this._scaleLabelEl=this.el.querySelector(".og-scale-label"),this.renderer.div.appendChild(this.el),this._isCenter?(this.planet.camera.events.on("moveend",(()=>{this._drawScreen(this.planet.renderer.handler.getCenter())})),!this.planet.terrain.isEmpty&&this.planet.terrain.events.on("loadend",(()=>{this._drawScreen(this.planet.renderer.handler.getCenter())}))):(this.renderer.events.on("mousemove",(e=>{e.leftButtonHold||e.rightButtonHold||this._drawScreen(e.pos)})),this.planet.camera.events.on("moveend",(()=>{let e=this.renderer.events.mouseState;e.leftButtonHold||e.rightButtonHold||this._drawScreen(e.pos)})))}_drawScreen(e){let t=this.planet.camera,i=e,n=this.planet.getDistanceFromPixel(i)||0;0===n&&(i=t.project(oe.ZERO),n=this.planet.getDistanceFromPixel(i)||0);let r=t.getForward().scaleTo(n).addA(t.eye),s=n*Math.tan(t.viewAngle*o),a=r.add(t.getRight().scaleTo(s)),l=t.project(a);this._mPx=s/l.distance(i);let h=this._mPx*this._minWidth,c=ke(zr,h,((e,t)=>e-t));c<0&&(c=~c);let d=zr[c],_=(d-h)/(zr[c+1]-d);this.currWidth=this._minWidth+_*(this._maxWidth-this._minWidth),this._scaleLabelEl.innerText=d>1e3?d/1e3+" km":`${d} m`,this._metersInMinSize=h,this.el.style.width=this.currWidth+"px"}}class Fr extends It{constructor(e={}){super({name:"SimpleSkyBackground",...e}),this._colorOne=new Float32Array([128/255,223/255,1]),this._colorTwo=new Float32Array([10/255,15/255,56/255])}get colorOne(){let e=this._colorOne;return me([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}get colorTwo(){let e=this._colorTwo;return me([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}set colorOne(e){let t=xe(e);this._colorOne[0]=t.x,this._colorOne[1]=t.y,this._colorOne[2]=t.z}set colorTwo(e){let t=xe(e);this._colorTwo[0]=t.x,this._colorTwo[1]=t.y,this._colorTwo[2]=t.z}oninit(){this.renderer.handler.addProgram(new zi("simpleSkyBackground",{uniforms:{iResolution:"vec2",fov:"float",camPos:"vec3",earthRadius:"float",viewMatrix:"mat4",colorOne:"vec3",colorTwo:"vec3"},attributes:{corners:"vec3"},vertexShader:"attribute vec2 corners;\n \n varying vec2 tc;\n \n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n \n #define MAX 10e10\n #define PI 3.14159265359\n #define rad(x) x * PI / 180.\n #define ZERO vec3(0.0) \n \n #define RED vec4(1.0, 0.0, 0.0, 1.0)\n #define GREEN vec4(0.0, 1.0, 0.0, 1.0) \n \n uniform vec3 camPos; \n uniform vec2 iResolution;\n uniform float fov;\n uniform float earthRadius;\n uniform mat4 viewMatrix;\n \n uniform vec3 colorOne;\n uniform vec3 colorTwo;\n \n varying vec2 tc;\n \n // compute the view ray in the camera coordinate\n vec3 computeView(vec2 uv){\n float w_h_ratio = iResolution.x / iResolution.y; \n float h = tan(rad(fov/2.));\n return normalize(vec3(-w_h_ratio * h, -h, -1.) + vec3(uv.x * 2. * h * w_h_ratio, uv.y*2.*h, 0.));\n }\n\n // sphere of size ra centered at point ce\n vec2 sphIntersect( in vec3 ro, in vec3 rd, in vec3 ce, float ra )\n {\n vec3 oc = ro - ce;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - ra * ra;\n float h = b * b - c;\n if( h < 0.0 ) return vec2(MAX); // no intersection\n h = sqrt( h );\n return vec2( -b-h, -b+h );\n }\n \n mat3 transpose(mat3 matrix) {\n vec3 row0 = matrix[0];\n vec3 row1 = matrix[1];\n vec3 row2 = matrix[2];\n mat3 result = mat3(\n vec3(row0.x, row1.x, row2.x),\n vec3(row0.y, row1.y, row2.y),\n vec3(row0.z, row1.z, row2.z)\n );\n return result;\n }\n \n float det(mat2 matrix) {\n return matrix[0].x * matrix[1].y - matrix[0].y * matrix[1].x;\n }\n \n mat3 inverse(mat3 matrix) {\n vec3 row0 = matrix[0];\n vec3 row1 = matrix[1];\n vec3 row2 = matrix[2];\n \n vec3 minors0 = vec3(\n det(mat2(row1.y, row1.z, row2.y, row2.z)),\n det(mat2(row1.z, row1.x, row2.z, row2.x)),\n det(mat2(row1.x, row1.y, row2.x, row2.y))\n );\n vec3 minors1 = vec3(\n det(mat2(row2.y, row2.z, row0.y, row0.z)),\n det(mat2(row2.z, row2.x, row0.z, row0.x)),\n det(mat2(row2.x, row2.y, row0.x, row0.y))\n );\n vec3 minors2 = vec3(\n det(mat2(row0.y, row0.z, row1.y, row1.z)),\n det(mat2(row0.z, row0.x, row1.z, row1.x)),\n det(mat2(row0.x, row0.y, row1.x, row1.y))\n );\n \n mat3 adj = transpose(mat3(minors0, minors1, minors2));\n \n return (1.0 / dot(row0, minors0)) * adj;\n }\n \n void main(void) {\n \n vec3 dir = computeView(tc);\n dir = inverse(mat3(viewMatrix)) * dir;\n \n vec2 ER = sphIntersect(camPos, dir, vec3(0.0), earthRadius);\n \n float bigRadius = earthRadius * 2.5;\n vec3 bigCenter = normalize(camPos) * bigRadius * 1.3; \n \n vec2 BIG = sphIntersect(camPos, dir, bigCenter, bigRadius);\n \n float Ix = distance(camPos + dir * BIG.y, ZERO); \n \n float maxI = sqrt(bigRadius * bigRadius + bigRadius * bigRadius);\n \n gl_FragColor = vec4(mix(colorOne, colorTwo, Ix / maxI), 1.0);\n }"})),this.activate()}onactivate(){super.onactivate(),this.planet.events.on("draw",this._drawBackground,this)}ondeactivate(){super.ondeactivate(),this.planet.events.off("draw",this._drawBackground)}_drawBackground(){let e=this.renderer.handler,t=e.programs.simpleSkyBackground,i=t._program,n=i.uniforms,r=e.gl,s=this.planet.camera;r.disable(r.DEPTH_TEST),t.activate(),r.bindBuffer(r.ARRAY_BUFFER,this.renderer.screenFramePositionBuffer),r.vertexAttribPointer(i.attributes.corners,2,r.FLOAT,!1,0,0),r.uniform3fv(n.camPos,[s.eye.x,s.eye.y,s.eye.z]),r.uniform2fv(n.iResolution,[e.getWidth(),e.getHeight()]),r.uniform1f(n.fov,s.getViewAngle()),r.uniform1f(n.earthRadius,this.planet.ellipsoid.getPolarSize()+1),r.uniform3fv(n.colorOne,this._colorOne),r.uniform3fv(n.colorTwo,this._colorTwo),r.uniformMatrix4fv(n.viewMatrix,!1,s.getViewMatrix()),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST)}}const Nr=14959787e4;function Hr(t){var i=t-ut,n=282.9404+470935e-10*i,r=.016709-1.151e-9*i,s=P(356.047+.9856002585*i),a=23.4392911-3.563e-7*i,h=s+l*r*Math.sin(s*o)*(1+r*Math.cos(s*o)),c=Math.cos(h*o)-r,d=Math.sin(h*o)*Math.sqrt(1-r*r),_=Math.sqrt(c*c+d*d),u=P(Math.atan2(d,c)*l+n),f=c=_*Math.cos(u*o),g=(d=_*Math.sin(u*o))*Math.cos(a*o),p=d*Math.sin(a*o),m=e*(24*i/23.9344694-259.853/360);return ae.zRotation(-m).mulVec3(new oe(-f*Nr,-g*Nr,p*Nr))}class Or{constructor(e,t){this._name=e||"light_"+Or.__counter__++,this._renderNode=null,this._position=t.position||new oe,this.directional=null==t.directional||t.directional,this._ambient=t.ambient||new oe,this._diffuse=t.diffuse||new oe(.8,.8,.8),this._specular=t.specular||new oe(.18,.18,.18),this._shininess=null!=t.shininess?t.shininess:3.3,this._active=!0,this._tempAmbient=this._ambient.clone(),this._tempDiffuse=this._diffuse.clone(),this._tempSpecular=this._specular.clone(),this._tempShininess=this._shininess}clone(){}setActive(e){if(e&&!this._active){const e=this._renderNode;if(e){let t=e._lightsNames.indexOf(this._name);this._shininess=e._lightsParamsf[t]=this._tempShininess,-1!=t&&(t*=9,this._ambient.x=e._lightsParamsv[t]=this._tempAmbient.x,this._ambient.y=e._lightsParamsv[t+1]=this._tempAmbient.y,this._ambient.z=e._lightsParamsv[t+2]=this._tempAmbient.z,this._diffuse.x=e._lightsParamsv[t+3]=this._tempDiffuse.x,this._diffuse.y=e._lightsParamsv[t+4]=this._tempDiffuse.y,this._diffuse.z=e._lightsParamsv[t+5]=this._tempDiffuse.z,this._specular.x=e._lightsParamsv[t+6]=this._tempSpecular.x,this._specular.y=e._lightsParamsv[t+7]=this._tempSpecular.y,this._specular.z=e._lightsParamsv[t+8]=this._tempSpecular.z)}this._active=!0}else!e&&this._active&&(this._tempAmbient=this._ambient.clone(),this._tempDiffuse=this._diffuse.clone(),this._tempSpecular=this._specular.clone(),this._tempShininess=this._shininess,this.setBlack(),this._active=!1)}isActive(){return this._active}setPosition3v(e){this._position.x=e.x,this._position.y=e.y,this._position.z=e.z}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i}getPosition(){return this._position.clone()}setAmbient3v(e){this.setAmbient(e.x,e.y,e.z)}setDiffuse3v(e){this.setDiffuse(e.x,e.y,e.z)}setSpecular3v(e){this.setSpecular(e.x,e.y,e.z)}setAmbient(e,t,i){this._ambient.set(e,t,i);const n=this._renderNode;if(n){let r=9*n._lightsNames.indexOf(this._name);-1!=r&&(n._lightsParamsv[r]=e,n._lightsParamsv[r+1]=t,n._lightsParamsv[r+2]=i)}}setDiffuse(e,t,i){this._diffuse.set(e,t,i);const n=this._renderNode;if(n){let r=9*n._lightsNames.indexOf(this._name);-1!=r&&(n._lightsParamsv[r+3]=e,n._lightsParamsv[r+4]=t,n._lightsParamsv[r+5]=i)}}setSpecular(e,t,i){this._specular.set(e,t,i);const n=this._renderNode;if(n){let r=9*n._lightsNames.indexOf(this._name);-1!=r&&(n._lightsParamsv[r+6]=e,n._lightsParamsv[r+7]=t,n._lightsParamsv[r+8]=i)}}setShininess(e){this._shininess=e;const t=this._renderNode;if(t){let i=t._lightsNames.indexOf(this._name);-1!=i&&(t._lightsParamsf[i]=e)}}setBlack(){this._ambient.clear(),this._diffuse.clear(),this._specular.clear(),this._shininess=0;const e=this._renderNode;if(e){let t=9*e._lightsNames.indexOf(this._name);-1!==t&&(e._lightsParamsv[t]=e._lightsParamsv[t+1]=e._lightsParamsv[t+2]=e._lightsParamsv[t+3]=e._lightsParamsv[t+4]=e._lightsParamsv[t+5]=e._lightsParamsv[t+6]=e._lightsParamsv[t+7]=e._lightsParamsv[t+8]=0)}}addTo(e){this._renderNode=e,e._lights.push(this),e._lightsNames.push(this._name),e._lightsParamsf.push(this._shininess),e._lightsParamsv.push.apply(e._lightsParamsv,this._ambient.toArray()),e._lightsParamsv.push.apply(e._lightsParamsv,this._diffuse.toArray()),e._lightsParamsv.push.apply(e._lightsParamsv,this._specular.toArray()),e.transformLights()}remove(){this._renderNode,this._renderNode=null}}Or.__counter__=0;class Vr extends It{constructor(e={}){super({autoActivate:!0,...e}),this._name="sun",this.activationHeight=e.activationHeight||12079e3,this.offsetVertical=e.offsetVertical||-5e6,this.offsetHorizontal=e.offsetHorizontal||5e6,this.sunlight=new Or("Sun",{ambient:new oe(.15,.15,.25),diffuse:new oe(.9,.9,.8),specular:new oe(.1,.1,.06),shininess:110}),this._currDate=0,this._prevDate=0,this._clockPtr=null,this._lightOn=!1,this._f=0,this._k=0,this._stopped=e.stopped||!1}oninit(){this.planet.lightEnabled=!0,this.sunlight.addTo(this.planet),this.renderer.events.on("draw",this._draw,this),this._clockPtr||(this._clockPtr=this.renderer.handler.defaultClock)}stop(){this._stopped=!0,this.deactivate()}start(){this._stopped=!1,this.activate()}onactivate(){super.onactivate(),this._stopped=!1}bindClock(e){this._clockPtr=e}_draw(){if(this._clockPtr)if(this._currDate=this._clockPtr.currentDate,this._stopped)this.sunlight.setPosition3v(Hr(this._currDate));else{let e=this.planet.camera;if(e.getHeight()<this.activationHeight||!this._active){this._lightOn=!0,this._f=1;let t=e.eye.normal(),i=e.getForward();i.scale(Math.sign(e._u.dot(t))),e.slope>.99&&(i=e._u);let n=oe.proj_b_to_plane(i,t,i).normalize().scale(this.offsetVertical),r=oe.proj_b_to_plane(e._r,t,e._r).normalize().scale(this.offsetHorizontal),s=n.add(r),a=e.eye.add(s);if(this._k>0){this._k-=.01;let e=ae.getRotationBetweenVectors(this.sunlight._position.normal(),a.normal()).slerp(ae.IDENTITY,this._k).normalize();this.sunlight.setPosition3v(e.mulVec3(this.sunlight._position))}else this.sunlight.setPosition3v(a)}else if(this._k=1,this._f>0){this._f-=.01;let e=ae.getRotationBetweenVectors(this.sunlight._position.normal(),Hr(this._currDate).normal()).slerp(ae.IDENTITY,this._f).normalize();this.sunlight.setPosition3v(e.mulVec3(this.sunlight._position))}else(Math.abs(this._currDate-this._prevDate)>34e-5&&this._active||this._lightOn)&&(this._lightOn=!1,this._prevDate=this._currDate,this.sunlight.setPosition3v(Hr(this._currDate)),this._f=0)}}}class Ur{constructor(){this.x=0,this.y=0,this.prev_x=0,this.prev_y=0,this.grabbedPoint=null,this.grabbedSpheroid=new At,this._vec=new le,this._vecPrev=new le}get dY(){return this.y-this.prev_y}get dX(){return this.x-this.prev_x}get vec(){return this._vec.set(this.x,this.y)}get vecPrev(){return this._vecPrev.set(this.prev_x,this.prev_y)}}class Gr extends It{constructor(e={}){super(e),this._name="touchNavigation",this.grabbedPoint=new oe,this.inertia=.007,this.grabbedSpheroid=new At,this.planet=null,this.qRot=new ae,this.scaleRot=0,this.rot=1,this._eye0=new oe,this.pointOnEarth=null,this.earthUp=null,this.touches=[new Ur,new Ur],this._keyLock=new xr,this._touching=!1}oninit(){this.renderer&&(this.renderer.events.on("touchstart",this.onTouchStart,this),this.renderer.events.on("touchend",this.onTouchEnd,this),this.renderer.events.on("doubletouch",this.onDoubleTouch,this),this.renderer.events.on("touchcancel",this.onTouchCancel,this),this.renderer.events.on("touchmove",this.onTouchMove,this),this.renderer.events.on("draw",this.onDraw,this))}onTouchStart(e){const t=this.renderer.handler;if(this._touching=!0,2===e.sys.touches.length){const i=this.touches[0],n=this.touches[1];i.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*t.pixelRatio,i.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*t.pixelRatio,i.prev_x=i.x,i.prev_y=i.y,i.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new le(i.x,i.y))||null,n.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*t.pixelRatio,n.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*t.pixelRatio,n.prev_x=n.x,n.prev_y=n.y,n.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new le(n.x,n.y))||null,this.pointOnEarth=this.planet.getCartesianFromPixelTerrain(this.renderer.handler.getCenter())||null,this.pointOnEarth&&(this.earthUp=this.pointOnEarth.normal()),i.grabbedPoint&&n.grabbedPoint&&(i.grabbedSpheroid.radius=i.grabbedPoint.length(),n.grabbedSpheroid.radius=n.grabbedPoint.length(),this.stopRotation())}else 1===e.sys.touches.length&&this._startTouchOne(e)}_startTouchOne(e){const t=this.touches[0],i=this.renderer.handler;t.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,t.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,t.prev_x=t.x,t.prev_y=t.y,t.grabbedPoint=this.planet.getCartesianFromPixelTerrain(e)||null,this._eye0.copy(this.planet.camera.eye),t.grabbedPoint&&(t.grabbedSpheroid.radius=t.grabbedPoint.length(),this.stopRotation())}stopRotation(){this.qRot.clear(),this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}onDoubleTouch(e){this.planet.stopFlying(),this.stopRotation();const t=this.planet.getCartesianFromPixelTerrain(e);if(t){const e=this.planet.ellipsoid.cartesianToLonLat(t);this.planet.flyLonLat(new z(e.lon,e.lat,.57*this.planet.camera.eye.distance(t)))}}onTouchEnd(e){0===e.sys.touches.length&&(this._touching=!1),1===e.sys.touches.length&&this._startTouchOne(e),Math.abs(this.touches[0].x-this.touches[0].prev_x)<3&&Math.abs(this.touches[0].y-this.touches[0].prev_y)<3&&(this.scaleRot=0)}onTouchCancel(e){}onTouchMove(e){let t=this.planet.camera;const i=this.renderer.handler;if(2===e.sys.touches.length){this.renderer.controlsBag.scaleRot=1;let r=this.touches[0],s=this.touches[1];if(!r.grabbedPoint||!s.grabbedPoint)return;this.planet.stopFlying(),r.prev_x=r.x,r.prev_y=r.y,r.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,r.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,s.prev_x=s.x,s.prev_y=s.y,s.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*i.pixelRatio,s.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*i.pixelRatio;const a=r.vec.add(s.vec).scale(.5),l=this.planet.getCartesianFromPixelTerrain(a);if(l){this.pointOnEarth=l;const e=Math.atan2(r.prev_y-s.prev_y,r.prev_x-s.prev_x),i=Math.atan2(r.y-s.y,r.x-s.x)-e,a=t.eye.distance(this.pointOnEarth),h=r.vec.sub(s.vec),c=r.vecPrev.sub(s.vecPrev);let d=a*-(1-h.length()/c.length());t.eye.addA(t.getForward().scale(d)),t.rotateAround(-i,!1,this.pointOnEarth,this.earthUp);const _=r.vec.add(s.vec).scale(.5),u=r.vecPrev.add(s.vecPrev).scale(.5),f=_.sub(u).scale(-1);var n=.5/a*t._lonLat.height*o;n>.003&&(n=.003),t.rotateHorizontal(n*-f.x,!1,this.pointOnEarth,this.earthUp),t.rotateVertical(n*-f.y,this.pointOnEarth),t.checkTerrainCollision(),t.update()}this.scaleRot=0}else if(1===e.sys.touches.length){let n=this.touches[0];if(n.prev_x=n.x,n.prev_y=n.y,n.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,n.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,!n.grabbedPoint)return;this.planet.stopFlying();let r=e.direction,s=new _i(t.eye,r).hitSphere(n.grabbedSpheroid);if(s)if(t.slope>.2){this.qRot=ae.getRotationBetweenVectors(s.normal(),n.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t._r=e.mulVec3(t._r),t._u=e.mulVec3(t._u),t._b=e.mulVec3(t._b),t.checkTerrainCollision(),t.update(),this.scaleRot=1}else{let e=n.grabbedPoint,i=oe.add(e,t._u),r=oe.add(e,e.normal()),s=t.unproject(n.x,n.y),a=new oe;new _i(t.eye,s).hitPlane(e,i,r,a)===_i.INSIDE&&(t.eye=this._eye0.addA(a.subA(e).negate()),t.checkTerrainCollision(),t.update(),this.scaleRot=0)}}}onDraw(){const e=this.renderer;if(e.controlsBag.scaleRot=this.scaleRot,this._touching)return;let t=this.planet.camera,i=t.eye.clone();if(!e.events.mouseState.leftButtonDown&&this.scaleRot){if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{e.controlsBag.scaleRot=this.scaleRot;let i=this.qRot.slerp(ae.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize();i.x||i.y||i.z||(this.scaleRot=0),t.eye=i.mulVec3(t.eye),t._r=i.mulVec3(t._r),t._u=i.mulVec3(t._u),t._b=i.mulVec3(t._b),t.checkTerrainCollision(),t.update()}t.eye.distance(i)/t.getAltitude()>.01?(this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock)):(this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock))}}}class Wr extends It{constructor(e={}){super(e),this._keyLock=new xr,this._move=0,this._targetPoint=null}oninit(){let e=new Rt({classList:["og-map-button","og-zoomin-button"],icon:'<?xml version="1.0"?><svg width=24 height=24 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M 11 5 L 11 11 L 5 11 L 5 13 L 11 13 L 11 19 L 13 19 L 13 13 L 19 13 L 19 11 L 13 11 L 13 5 L 11 5 z"/></svg>'});e.appendTo(this.renderer.div);let t=new Rt({classList:["og-map-button","og-zoomout-button"],icon:'<?xml version="1.0"?><svg width=24 height=24 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M 5 11 L 5 13 L 19 13 L 19 11 L 5 11 z"/></svg>'});t.appendTo(this.renderer.div),e.events.on("mousedown",(()=>this.zoomIn())),e.events.on("mouseup",(()=>this.stopZoom())),t.events.on("mousedown",(()=>this.zoomOut())),t.events.on("mouseup",(()=>this.stopZoom())),e.events.on("touchstart",(()=>this.zoomIn())),e.events.on("touchend",(()=>this.stopZoom())),e.events.on("touchcancel",(()=>this.stopZoom())),t.events.on("touchstart",(()=>this.zoomOut())),t.events.on("touchend",(()=>this.stopZoom())),t.events.on("touchcancel",(()=>this.stopZoom())),this.renderer.events.on("draw",this._draw,this)}zoomIn(){this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this._targetPoint=this.renderer.getCenter(),this._move=1}zoomOut(){this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this._targetPoint=this.renderer.getCenter(),this._move=-1}stopZoom(){this._move=0,this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}_draw(e){const t=this.planet.camera;if(0!==this._move){const i=this.planet.getCartesianFromPixelTerrain(e.getCenter());if(i){let e=.035*t.eye.distance(i);t.eye.addA(t.getForward().scale(this._move*e)),t.checkTerrainCollision(),t.update()}}}}class jr extends Pi{constructor(e={}){super(e.name),this._ignoreTerrain=!1,this.events=new St(Yr),this._ignoreTerrain=null==e.ignoreTerrain||e.ignoreTerrain,this._onSelect=e.onSelect||null,this._autoSelectionHide=e.autoSelectionHide||!1,this._planet=e.planet||null,this._startLonLat=null,this._heading=0,this._propsLabel=new Ai({name:"propsLabel",label:{text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,18]}}),this._propsLabel?.label?.setVisibility(!1),this._trackEntity=new Ai({polyline:{path3v:[],thickness:3.8,color:"rgb(455,455,455)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01;let t=gi.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);this._cornerEntity=[new Ai({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(0,305,0)",object3d:t},properties:{name:"start"}}),new Ai({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(455,0,0)",object3d:t},properties:{name:"end"}})],this._trackLayer=new In("track",{entities:[this._trackEntity,this._propsLabel],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!1}),this._cornersLayer=new In("corners",{entities:[this._cornerEntity[0],this._cornerEntity[1]],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,4e6,.01],pickingScale:2})}set ignoreTerrain(e){this._ignoreTerrain=e}bindPlanet(e){this._planet=e}init(){this._activate()}onremove(){this._deactivate()}_activate(){this._propsLabel?.label?.setVisibility(!1),this._onMouseMove_=this._onMouseMove.bind(this),this.renderer?.events.on("mousemove",this._onMouseMove_,this),this._onMouseLdown_=this._onMouseLdown.bind(this),this.renderer?.events.on("ldown",this._onMouseLdown_,this),this._onMouseLup_=this._onMouseLup.bind(this),this.renderer?.events.on("lup",this._onMouseLup_,this),this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._cornersLayer)}_deactivate(){this._startLonLat=null,this._trackLayer.remove(),this._cornersLayer.remove(),this.renderer?.events.off("mousemove",this._onMouseMove_),this.renderer?.events.off("ldown",this._onMouseLdown_),this.renderer?.events.off("lup",this._onMouseLup_),this.clear(),this._onMouseMove_=null,this._onMouseLdown_=null,this._onMouseLup_=null}_onMouseLdown(e){if(e.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.renderer.handler.canvas.style.cursor="pointer",!this._startLonLat){this._propsLabel.label?.setVisibility(!1),this._trackEntity.polyline?.setPath3v([]),this._cornerEntity[0].geoObject?.setVisibility(!0),this._cornerEntity[1].geoObject?.setVisibility(!0),this.renderer?.controls.mouseNavigation?.deactivate(),this._startLonLat=this._planet.getLonLatFromPixelTerrain(e);let t=this._planet.ellipsoid.lonLatToCartesian(this._startLonLat);this._cornerEntity[0].setCartesian3v(t),this._cornerEntity[1].setCartesian3v(t)}}_onMouseLup(e){if(this._startLonLat){if(this._pickedCorner=null,this._anchorLonLat=null,this._propsLabel.label?.setVisibility(!0),this._onSelect&&"function"==typeof this._onSelect){let e=this._cornerEntity[0].getLonLat(),t=this._cornerEntity[1].getLonLat(),i=[Math.min(e.lon,t.lon),Math.min(e.lat,t.lat),Math.max(e.lon,t.lon),Math.max(e.lat,t.lat)];this._onSelect(i)}this._autoSelectionHide&&this.clear(),this._startLonLat=null}e.renderer.handler.canvas.style.cursor="default",this.renderer?.controls.mouseNavigation?.activate()}_drawLine(e,t,i){i||(i=this._planet.ellipsoid.lonLatToCartesian(e));let n=this._planet.ellipsoid.lonLatToCartesian(t),r=this._planet.ellipsoid.direct(e,t);this._heading=r.initialAzimuth;let s=[];this._cornerEntity[0].setCartesian3v(i),this._cornerEntity[1].setCartesian3v(n);let a=[i,this._planet.ellipsoid.lonLatToCartesian(new z(t.lon,e.lat,e.height)),n,this._planet.ellipsoid.lonLatToCartesian(new z(e.lon,t.lat,e.height)),i];s.push(i);let o=(e,t)=>{let i=t.sub(e),n=i.length();i.normalize();for(let t=0;t<120;t++){let r=i.scaleTo(t*n/120).addA(e);s.push(r)}};for(let e=0;e<a.length-1;e++)o(a[e],a[e+1]);this._trackEntity.polyline?.setPath3v([s]),this._ignoreTerrain}_onMouseMove(e){if(this._startLonLat){this._propsLabel.label?.setVisibility(!0);let t=this._planet.getLonLatFromPixelTerrain(e);if(!t)return;this._drawLine(this._startLonLat,t)}}clear(){this._trackEntity.polyline?.clear(),this._cornerEntity[0].geoObject?.setVisibility(!1),this._cornerEntity[1].geoObject?.setVisibility(!1)}frame(){let e=this._trackEntity.polyline?.getPath3v()[0];if(e&&!this._ignoreTerrain){let i=0;for(let t=0,n=e.length-1;t<n;t++)i+=e[t+1].distance(e[t]);this._propsLabel.setCartesian3v(e[Math.floor(e.length/2)]),this._propsLabel.label?.setText(`${t=i,t>1e3?`${(t/1e3).toFixed(1)} km`:t>9?`${Math.round(t)} m`:`${t.toFixed(1)} m`}, ${Math.round(this._heading)} deg`)}var t}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Yr=["add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];function qr(e,t){return new Date(+e+1e3*t)}function Xr(e,t=!0,i=!1){let n=Qr[e.getMonth()],r=e.getUTCDate(),s=e.getUTCFullYear();if(t){let t=e.getUTCHours().toString().padStart(2,"0"),a=e.getUTCMinutes().toString().padStart(2,"0"),o=e.getUTCSeconds().toString().padStart(2,"0");if(i){return`${n} ${r} ${s} ${t}:${a}:${o}.${e.getUTCMilliseconds().toString().padStart(3,"0")}`}return`${n} ${r} ${s} ${t}:${a}:${o}`}return`${n} ${r} ${s}`}function $r(e,t=0,i=10,n=2,r="white"){e.lineWidth=n,e.strokeStyle=r,e.beginPath(),e.moveTo(t,0),e.lineTo(t,i),e.stroke()}function Zr(e,t,i,n,r="12px Arial",s="black",a="left",l="bottom",h=0){e.save(),e.translate(i,n),e.rotate(h*o),e.fillStyle=s,e.textBaseline=l,e.font=r,e.textAlign=a,e.fillText(t,0,0),e.restore()}const Kr=[[.001,10],[.002,10],[.005,10],[.01,10],[.02,10],[.05,10],[.1,10],[.25,10],[.5,5],[1,10],[2,10],[5,5],[10,10],[15,15],[30,6],[60,12],[120,12],[300,5],[600,10],[900,15],[1800,6],[3600,12],[7200,10],[14400,4],[21600,6],[43200,12],[86400,24],[172800,2],[345600,4],[604800,7],[1296e3,15],[2592e3,5],[5184e3,6],[7776e3,9],[15552e3,18],[31536e3,12],[63072e3,2],[126144e3,4],[15768e4,5],[31536e4,10],[63072e4,2],[126144e4,4],[15768e5,5],[31536e5,10],[63072e5,2],[126144e5,4],[15768e6,5],[31536e6,10]];const Qr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Jr=["change","current"];class es{constructor(e={}){this.events=Pt(Jr),this._current=e.current||new Date,this._rangeStart=e.rangeStart||new Date,this._rangeEnd=e.rangeEnd||qr(this._rangeStart,3600),this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this._minDate=e.minDate||null,this._maxDate=e.maxDate||null,this.multiplier=null!=e.multiplier?e.multiplier:1,this._requestAnimationFrameId=0,this._prevNow=0,this.dt=0}play(){this._requestAnimationFrameId||(this._prevNow=window.performance.now(),this._animationFrameCallback())}stop(){this._requestAnimationFrameId&&(window.cancelAnimationFrame(this._requestAnimationFrameId),this._requestAnimationFrameId=0)}stopped(){return 0==this._requestAnimationFrameId}_animationFrameCallback(){this._requestAnimationFrameId=window.requestAnimationFrame((()=>{this._frame(),this._animationFrameCallback()}))}_frame(){let e=window.performance.now();this.dt=e-this._prevNow,this._prevNow=e,this.current=new Date(this.currentTime+this.dt*this.multiplier)}get range(){return this._range}set(e,t){e===this._rangeStart&&t===this._rangeEnd||(this._rangeStart=e,this._rangeEnd=t,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e,t))}get current(){return this._current}get rangeStart(){return this._rangeStart}get rangeEnd(){return this._rangeEnd}get rangeStartTime(){return this._rangeStart.getTime()}get rangeEndTime(){return this._rangeEnd.getTime()}get currentTime(){return this._current.getTime()}set current(e){e!==this._current&&(this._maxDate&&e>this._maxDate?this._current=this._maxDate:this._minDate&&e<this._minDate?this._current=this._minDate:this._current=e,this.events.dispatch(this.events.current,this._current))}set rangeStart(e){e!==this._rangeStart&&(this._rangeStart=e,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e))}set rangeEnd(e){e!==this._rangeEnd&&(this._rangeEnd=e,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e))}}const ts=.001,is=["startdrag","stopdrag","startdragcurrent","stopdragcurrent","setcurrent","reset","play","playback","pause","visibility"],ns="#bfbfbf";class rs extends Bt{constructor(e={}){super({template:'<div class="og-timeline">\n\n <div class="og-timeline-top">\n </div>\n\n <div class="og-timeline-frame">\n <div class="og-timeline-current">\n <div class="og-timeline-current-spin">\n <div class="og-timeline-current-arrow"></div>\n </div>\n </div>\n <div class="og-timeline-scale"></div>\n </div>\n\n <div class="og-timeline-bottom">\n <div class="og-timeline-controls">\n </div>\n </div>\n\n</div>',model:new es({rangeStart:e.rangeStart,rangeEnd:e.rangeEnd,current:e.currentDate,minDate:e.minDate,maxDate:e.maxDate})}),this._onMouseWheel=e=>{if(this._isMouseOver){let t=this._canvasEl.getBoundingClientRect(),i=e.clientX-t.left,n=-(i-.5*this.clientWidth),r=this.model.rangeStartTime+this._millisecondsInPixel*i;this._zoom(r,n,Math.sign(e.wheelDelta))}else if(this._isCurrentMouseOver){let t=-((this.model.currentTime-this.model.rangeStartTime)/this._millisecondsInPixel-.5*this.clientWidth);this._zoom(this.model.currentTime,t,Math.sign(e.wheelDelta))}},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onMouseDown=e=>{this._isMouseOver?(this._isDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._clickTime=Date.now(),this._clickRangeStart=this.model.rangeStart,this._clickRangeEnd=this.model.rangeEnd,this.events.dispatch(this.events.startdrag,e)):this._isCurrentMouseOver&&(this._isCurrentDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._clickCurrentDate=this.model.current,this.events.dispatch(this.events.startdragcurrent,e))},this._onMouseUp=e=>{if(this._isDragging)if(this._isDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this._clickPosX===e.clientX&&Date.now()-this._clickTime<this._clickDelay){let t=this._canvasEl.getBoundingClientRect(),i=new Date(this.model.rangeStartTime+(e.clientX-t.left)*this._millisecondsInPixel);this.model.current=i,this.events.dispatch(this.events.stopdrag,i),this.events.dispatch(this.events.setcurrent,i)}else this.events.dispatch(this.events.stopdrag,this.model.current);else this._isCurrentDragging&&(this._isCurrentDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this.events.dispatch(this.events.stopdragcurrent,this.model.current))},this._onMouseEnter=()=>{this._isMouseOver=!0},this._onMouseOut=()=>{this._isMouseOver=!1},this._onCurrentMouseEnter=()=>{this._isCurrentMouseOver=!0},this._onCurrentMouseOut=()=>{this._isCurrentMouseOver=!1},this._onMouseMove=e=>{if(this._isDragging){let t=(this._clickPosX-e.clientX)*this._millisecondsInPixel*ts;this.model.set(qr(this._clickRangeStart,t),qr(this._clickRangeEnd,t))}else if(this._isCurrentDragging){let t=(this._clickPosX-e.clientX)*this._millisecondsInPixel*ts,i=qr(this._clickCurrentDate,-t);i>=this.model.rangeStart&&i<=this.model.rangeEnd&&(this.model.current=qr(this._clickCurrentDate,-t))}},this.events=this.events.registerNames(is),this.fillStyle=e.fillStyle||"rgba(64, 59, 59, 1.0)",this.$controls=null,this._frameEl=null,this._currentEl=null,this._canvasEl=document.createElement("canvas"),this._ctx=this._canvasEl.getContext("2d"),this._isMouseOver=!1,this._isDragging=!1,this._isCurrentDragging=!1,this._isCurrentMouseOver=!1,this._minWidth=330,this._canvasScale=2,this._millisecondsInPixel=0,this._clickPosX=0,this._clickRangeStart=new Date,this._clickRangeEnd=new Date,this._clickCurrentDate=new Date,this._clickTime=0,this._clickDelay=450,this._onResizeObserver_=this._onResizeObserver.bind(this),this._resizeObserver=new ResizeObserver(this._onResizeObserver_),this._pauseBtn=new Ot({classList:["og-timeline-control_button"],icon:'<?xml version="1.0" ?><!DOCTYPE svg PUBLIC \'-//W3C//DTD SVG 1.1//EN\' \'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\'><svg enable-background="new 0 0 512 512" height="512px" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="Layer_6"><rect fill="#252525" height="320" width="60" x="153" y="96"/><rect fill="#252525" height="320" width="60" x="299" y="96"/></g></svg>',name:"pause"}),this._playBtn=new Ot({classList:["og-timeline-control_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M8 5v14l11-7z" style="fill: black;"/></svg>',name:"play"}),this._buttons=new Qt({buttons:[this._pauseBtn,this._playBtn]}),this._visibility=!1}_onResizeObserver(){this.resize()}get canvasScale(){return this._canvasScale}set canvasScale(e){e!==this._canvasScale&&(this._canvasScale=e,this.resize())}resize(){this._resize(),this.draw()}afterRender(e){this.resize()}render(){return super.render(),this.$controls=this.select(".og-timeline-controls"),this._frameEl=this.select(".og-timeline-frame"),this._currentEl=this.select(".og-timeline-current"),this.select(".og-timeline-frame .og-timeline-scale").appendChild(this._canvasEl),this._resizeObserver.observe(this.el),this.model.events.on("change",(()=>{this.draw()})),this.model.events.on("current",(e=>{this._drawCurrent(),this.events.dispatch(this.events.setcurrent,e)})),this._canvasEl.addEventListener("mouseenter",this._onMouseEnter),this._canvasEl.addEventListener("mouseout",this._onMouseOut),this._currentEl.addEventListener("mouseenter",this._onCurrentMouseEnter),this._currentEl.addEventListener("mouseout",this._onCurrentMouseOut),document.body.addEventListener("mousemove",this._onMouseMove),document.body.addEventListener("mousedown",this._onMouseDown),document.body.addEventListener("mouseup",this._onMouseUp),document.body.addEventListener("wheel",this._onMouseWheelFF),this._playBtn.appendTo(this.$controls),this._pauseBtn.appendTo(this.$controls),this.model.stopped()?(this._pauseBtn.setActive(!0,!0),this._pauseBtn.preventClick=!0):(this._playBtn.setActive(!0,!0),this._playBtn.preventClick=!0),this._buttons.events.on("change",(e=>{switch(e.name){case"play":this.play();break;case"pause":this.pause()}})),this.setVisibility(!0),this}setVisibility(e){e!==this._visibility&&(this._visibility=e,this.el&&(this.el.style.display=e?"block":"none"),this.events.dispatch(this.events.visibility,e))}reset(){this.model.stop(),this.events.dispatch(this.events.reset,this.model)}play(){this.model.multiplier=Math.abs(this.model.multiplier),this.model.play(),this.events.dispatch(this.events.play,this.model)}pause(){this.model.stop(),this.events.dispatch(this.events.pause,this.model)}playBack(){this.model.multiplier=-1*Math.abs(this.model.multiplier),this.model.play(),this.events.dispatch(this.events.playback,this.model)}_zoom(e,t,i){let n=(e-(this.model.rangeStartTime+.5*this.model.range))*ts,r=qr(this.model.rangeStart,n),s=qr(this.model.rangeEnd,n),a=(s.getTime()-r.getTime())/20*ts,o=qr(r,a*i),l=qr(s,-a*i),h=(l.getTime()-o.getTime())/this.clientWidth;if(h<31536e6&&h>.1){let e=h*t*ts;this.model.set(qr(o,e),qr(l,e))}}get clientWidth(){return this._canvasEl?this._canvasEl.width/this._canvasScale:0}get clientHeight(){return this._canvasEl?this._canvasEl.height/this._canvasScale:0}_resize(){this._frameEl&&(this._canvasEl.width=this._frameEl.clientWidth*this._canvasScale,this._canvasEl.height=this._frameEl.clientHeight*this._canvasScale,this._canvasEl.style.width=`${this._frameEl.clientWidth}px`,this._canvasEl.style.height=`${this._frameEl.clientHeight}px`)}getOffsetByTime(e){return(e-this.model.rangeStartTime)/this._millisecondsInPixel}remove(){super.remove(),this.model.stop()}_clearCanvas(){this._ctx.fillStyle=this.fillStyle,this._ctx.fillRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}_drawCurrent(){let e=(this.model.currentTime-this.model.rangeStartTime)/this._millisecondsInPixel;this.model.current<this.model.rangeStart||this.model.current>this.model.rangeEnd?this._currentEl.style.display="none":(this._currentEl.style.display="block",this._currentEl.style.transform=`translateX(${e}px)`)}draw(){this._millisecondsInPixel=this.model.range/this.clientWidth;let e=function(e){for(let t=0,i=Kr.length;t<i;t++)if(Kr[t][0]>e)return Kr[t-1]}(this._minWidth*this._millisecondsInPixel*ts);if(e){this._clearCanvas();let i=1e3*e[0],n=i/this._millisecondsInPixel,r=e[1],s=(t=this.model.rangeStartTime)-t%i,a=e[0]<1,o=e[0]<86400;for(let e=s,t=this.model.rangeEndTime+i;e<t;e+=i){let t=this.getOffsetByTime(e);t>=0&&t<=this.clientWidth*this._canvasScale&&$r(this._ctx,t*this._canvasScale,10*this._canvasScale,2*this._canvasScale,ns);for(let e=1;e<r;e++){let i=t+e*(n/r);i>=0&&i<=this.clientWidth*this._canvasScale&&$r(this._ctx,i*this._canvasScale,5*this._canvasScale,1*this._canvasScale,ns)}Zr(this._ctx,Xr(new Date(e),o,a),t*this._canvasScale,26*this._canvasScale,"24px monospace","#bfbfbf","center")}this._drawCurrent()}var t}}function ss(e,t){const i=new Date(e);return i.setHours(i.getHours()+t),i}class as{constructor(){this.resolve=()=>{},this.reject=()=>{},this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t})),Object.freeze(this)}}const os=["startcollecting","profilecollected","clear"];class ls{constructor(e={}){this.events=Pt(os),this.planet=e.planet||null,this._warningHeightLevel=5,this._pointsReady=!1,this._isWarning=!1,this._minX=0,this._planeDistance=this._maxX=1e3,this._minY=0,this._maxY=200,this._drawData=[[],[]],this._promiseArr=[],this._promiseCounter=0,this._pMaxY=0,this._pMinY=0,this._pDist=0,this._pTrackCoords=[],this._pGroundCoords=[],this._pIndex=0}bindPlanet(e){this.planet=e}setWarningHeightLevel(e=0){this._warningHeightLevel=e}setRange(e,t,i,n){this._minX=e,this._maxX=t,i&&(this._minY=i),n&&(this._maxY=n)}_getHeightAsync(e,t,i){let n=new as;if(this.planet){let r=this.planet.terrain.geoid.getHeightLonLat(e);this.planet.terrain.getHeightAsync(e,(s=>{this.planet&&i===this._promiseCounter?(s+=r,this._pGroundCoords[t][1]=s,this._pGroundCoords[t][2]=0,this._pGroundCoords[t][3]=e.height,s>this._pMaxY&&(this._pMaxY=s),s<this._pMinY&&(this._pMinY=s),this._updatePointType(t),n.resolve(s)):n.reject()}))}else n.reject();return n.promise}_collectCoordsBetweenTwoTrackPoints(e,t,i,n,r,s){if(this.planet)for(let a=1;a<=t;a++){this._pDist+=1,this._pIndex++;let t=a*i,o=n.add(r.scaleTo(t)),l=this.planet.ellipsoid.cartesianToLonLat(o);this._pGroundCoords[this._pIndex]=[this._pDist,0,0,0,e],((e,t)=>{this._promiseArr.push(this._getHeightAsync(e,t,s))})(l,this._pIndex)}}_collectAllPoints(e,t){if(!this.planet)return;if(t!==this._promiseCounter)return;let i=new oe,n=new oe;for(let r=1,s=e.length;r<s;r++){let s=e[r-1],a=e[r];this.planet.ellipsoid.lonLatToCartesianRes(s,i),this.planet.ellipsoid.lonLatToCartesianRes(a,n);let o=n.sub(i),l=o.length(),h=this.planet.ellipsoid.getSurfaceNormal3v(i),c=oe.proj_b_to_plane(o,h),d=c.length(),_=Math.floor(d/1),u=1*l/d;this._getGroundElevation(s,r-1,t),c.normalize(),o.normalize(),this._collectCoordsBetweenTwoTrackPoints(r-1,_,u,i,o,t),this._pDist+=d-1*_,this._pIndex++;let f=a.height;f>this._pMaxY&&(this._pMaxY=f),f<this._pMinY&&(this._pMinY=f),this._pTrackCoords[r]=[this._pDist,f,this._pIndex]}}_getGroundElevation(e,t,i){this._pGroundCoords[this._pIndex]=[this._pDist,0,0,0,t],this._promiseArr.push(this._getHeightAsync(e,this._pIndex,i))}_calcPointsAsync(e,t){return new Promise(((i,n)=>{this._pTrackCoords=[[0,e[0].height,0]],this._pMaxY=e[0].height,this._pMinY=this._pMaxY,this._pDist=0,this._pGroundCoords=[],this._pIndex=0,this._promiseArr=[],this._collectAllPoints(e,t),this._getGroundElevation(e[e.length-1],e.length-1,t),Promise.all(this._promiseArr).then((()=>{i({dist:this._pDist,minY:this._pMinY,maxY:this._pMaxY,trackCoords:this._pTrackCoords,groundCoords:this._pGroundCoords})}))}))}get minX(){return this._minX}get planeDistance(){return this._planeDistance}get maxX(){return this._maxX}get minY(){return this._minY}get maxY(){return this._maxY}get pointsReady(){return this._pointsReady}get isWarningOrCollision(){return this._isWarning}get drawData(){return this._drawData}collectProfile(e){let t=new as;return this.planet||t.reject(),this._pointsReady=!1,this._isWarning=!1,e&&e.length?(this.events.dispatch(this.events.startcollecting,this),this._promiseCounter++,(i=>{this._calcPointsAsync(e,i).then((e=>{i===this._promiseCounter&&(this._planeDistance=e.dist,this.setRange(0,e.dist,e.minY-.1*Math.abs(e.minY),e.maxY+.2*Math.abs(e.maxY)),this._pointsReady=!0,this._drawData=[e.trackCoords,e.groundCoords],this.events.dispatch(this.events.profilecollected,this._drawData,this),t.resolve(this._drawData))}))})(this._promiseCounter),t.promise):(t.reject(),t.promise)}_updatePointType(e){this._pGroundCoords[e][3]>=this._pGroundCoords[e][1]&&this._pGroundCoords[e][3]<this._pGroundCoords[e][1]+this._warningHeightLevel-.1&&(this._pGroundCoords[e][2]=1),this._pGroundCoords[e][3]<=this._pGroundCoords[e][1]+1&&(this._pGroundCoords[e][2]=2),1!==this._pGroundCoords[e][2]&&2!==this._pGroundCoords[e][2]||(this._isWarning=!0)}_setPointsType(){this._isWarning=!1,this._pTrackCoords=this._drawData[0],this._pGroundCoords=this._drawData[1];for(let e=0;e<this._pGroundCoords.length;e++)this._updatePointType(e);this._drawData[1]=this._pGroundCoords,this.events.dispatch(this.events.profilecollected,this._drawData,this)}clear(){this._promiseCounter=0,this._pointsReady=!1,this._isWarning=!1,this._drawData=[[],[]],this._pMaxY=0,this._pMinY=0,this._pDist=0,this._pTrackCoords=[],this._pGroundCoords=[],this._pIndex=0,this.events.dispatch(this.events.clear,this._drawData,this)}}const hs="rgb(198, 198, 198)",cs=[hs,"rgb(255, 255, 0)","rgb(255, 0, 0)"],ds=["startdrag","stopdrag","pointer","mouseenter","mouseleave","dblclick","tracklength","groundlength","warninglength","collisionlength"];class _s extends Bt{constructor(e={}){super({template:'<div class="og-elevationprofile">\n <div class="og-elevationprofile-loading" style="display: none;">\n <div class="loadingio-spinner-bars-r354qqyl5v">\n <div class="ldio-p0v5a1f6oz">\n <div></div>\n <div></div>\n <div></div>\n <div></div>\n </div>\n </div> \n </div> \n </div>',model:new ls}),this._onMouseDblClick=e=>{let t,i=this.$canvas.getBoundingClientRect(),n=e.clientX-i.left,r=this._leftDistance+(this._rightDistance-this._leftDistance)*n/this.clientWidth,s=this.model.drawData[1],a=this.model.drawData[0];r<0?(t=1,r=0,n=(0-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):r>this.model.planeDistance?(t=s.length-1,r=this.model.planeDistance,n=(r-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-ke(s,r,((e,t)=>e-t[0]));let o=s[t-1],l=s[t],h=(r-o[0])/(l[0]-o[0]),c=o[1]+h*(l[1]-o[1]),d=o[4],_=a[d],u=a[d+1];h=(r-_[0])/(u[0]-_[0]);let f=_[1]+h*(u[1]-_[1]);this.events.dispatch(this.events.dblclick,r,_,u,o,l,d,t-1,f-c)},this._onMouseEnter=e=>{this._isMouseOver=!0,this.events.dispatch(this.events.mouseenter,e)},this._onMouseOut=e=>{this._isMouseOver=!1,this.events.dispatch(this.events.mouseleave,e)},this._onMouseDown=e=>{this._isMouseOver&&(this._isDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX),this._clickLeftDistance=this._leftDistance,this._clickRightDistance=this._rightDistance,this.events.dispatch(this.events.startdrag,e))},this._onMouseUp=e=>{this._isDragging&&(this._isDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this.events.dispatch(this.events.stopdrag,e))},this._onCanvasMouseMove=e=>{if(this.model.pointsReady)if(this._isDragging)this.clearPointerCanvas();else{this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX);let t=this.$pointerCanvas.getBoundingClientRect(),i=e.clientX-t.left;this.redrawPointerCanvas(i)}},this._onMouseMove=e=>{if(this._isDragging&&this.model.pointsReady){let t=(this._clickPosX-e.clientX)*this._canvasScale/this._pixelsInMeter_x;this.setFrame(this._clickLeftDistance+t,this._clickRightDistance+t)}},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onMouseWheel=e=>{if(this._isMouseOver&&this.model.pointsReady){this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX),this._customFrame=!0;let t=Math.sign(e.wheelDelta)*(this._rightDistance-this._leftDistance)/20,i=this.$canvas.getBoundingClientRect(),n=e.clientX-i.left,r=n-.5*this.$canvas.clientWidth,s=r*this._canvasScale/this._pixelsInMeter_x,a=s+this._leftDistance+t,o=s+this._rightDistance-t;s=-r*(o-a)/this.clientWidth,this.setFrame(a+s,o+s),this.redrawPointerCanvas(n)}},this.events=this.events.registerNames(ds),this.fillStyle=e.fillStyle||"rgb(63, 63, 63)",this._customFrame=!1,this._leftDistance=0,this._rightDistance=0,this._pixelsInMeter_x=0,this._pixelsInMeter_y=0,this._canvasScale=2,this.$canvas=document.createElement("canvas"),this.$canvas.style.position="absolute",this._ctx=this.$canvas.getContext("2d"),this.$pointerCanvas=document.createElement("canvas"),this.$pointerCanvas.style.pointerEvents="none",this.$pointerCanvas.style.position="absolute",this._pointerCtx=this.$pointerCanvas.getContext("2d"),this.$loading=null,this._isMouseOver=!1,this._isDragging=!1,this._clickPosX=0,this._clickLeftDistance=0,this._clickRightDistance=0,this._timeStartHandler=0,this._onResizeObserver_=this._onResizeObserver.bind(this),this._resizeObserver=new ResizeObserver(this._onResizeObserver_)}_onResizeObserver(){this.resize()}get canvasScale(){return this._canvasScale}set canvasScale(e){e!==this._canvasScale&&(this._canvasScale=e,this.resize())}resize(){this._resize(),this.draw()}render(){return super.render(),this._resizeObserver.observe(this.el),this.el.appendChild(this.$canvas),this.el.appendChild(this.$pointerCanvas),this.model.events.on("profilecollected",(e=>{this._hideLoading(),this.clearPointerCanvas(),this.draw()})),this.model.events.on("startcollecting",(()=>{clearTimeout(this._timeStartHandler),this._timeStartHandler=setTimeout((()=>{this._showLoading()}),450)})),this.model.events.on("clear",(()=>{this._customFrame=!1,this._leftDistance=0,this.clearCanvas(),this.clearPointerCanvas()})),this.$loading=this.select(".og-elevationprofile-loading"),this.$canvas.addEventListener("mouseenter",this._onMouseEnter),this.$canvas.addEventListener("mouseout",this._onMouseOut),this.$canvas.addEventListener("dblclick",this._onMouseDblClick),this.$canvas.addEventListener("mousemove",this._onCanvasMouseMove),document.body.addEventListener("mousemove",this._onMouseMove),document.body.addEventListener("mousedown",this._onMouseDown),document.body.addEventListener("mouseup",this._onMouseUp),document.body.addEventListener("wheel",this._onMouseWheelFF),this}_hideLoading(){clearTimeout(this._timeStartHandler),this.$loading.style.display="none"}_showLoading(){this.$loading.style.display="flex"}redrawPointerCanvas(e){this.clearPointerCanvas();let t,i=this._leftDistance+(this._rightDistance-this._leftDistance)*e/this.clientWidth,n=this.model.drawData[1],r=this.model.drawData[0];i<0?(t=1,i=0,e=(0-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):i>this.model.planeDistance?(t=n.length-1,i=this.model.planeDistance,e=(i-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-ke(n,i,((e,t)=>e-t[0]));let s=n[t-1],a=n[t],o=(i-s[0])/(a[0]-s[0]),l=s[1]+o*(a[1]-s[1]),h=s[4],c=r[h],d=r[h+1];o=(i-c[0])/(d[0]-c[0]);let _=c[1]+o*(d[1]-c[1]),u=(this.model.maxY-_)*this._pixelsInMeter_y,f=(this.model.maxY-l)*this._pixelsInMeter_y;this.events.dispatch(this.events.pointer,i,c,d,s,a,h,t-1,_-l);let g=this._pointerCtx;g.lineWidth=3,g.strokeStyle="rgba(64,64,64,0.6)",g.beginPath(),g.moveTo(e*this._canvasScale,0),g.lineTo(e*this._canvasScale,this.clientHeight*this._canvasScale),g.stroke(),g.beginPath(),g.arc(e*this._canvasScale,f,4,0,2*Math.PI,!1),g.fillStyle="#FFB277",g.fill(),g.lineWidth=4,g.strokeStyle="#FFB277",g.stroke(),g.beginPath(),g.arc(e*this._canvasScale,u,4,0,2*Math.PI,!1),g.fillStyle="#FFB277",g.fill(),g.lineWidth=4,g.strokeStyle="#FFB277",g.stroke(),g.lineWidth=3,g.strokeStyle="#FFB277",g.beginPath(),g.moveTo(e*this._canvasScale,f),g.lineTo(e*this._canvasScale,u),g.stroke(),g.fillStyle="white",g.font=28/devicePixelRatio+"px Arial",g.textBaseline="middle",g.textAlign="left",g.fillText(`${Math.round(_-l).toString()} m`,(e+5)*this._canvasScale,f+.5*(u-f)),g.fillStyle="white",g.font=28/devicePixelRatio+"px Arial",g.textAlign="right";let p=Ze(i);g.fillText(`${p[0]} ${p[1]}`,(e-5)*this._canvasScale,(this.clientHeight-7)*this._canvasScale)}get clientWidth(){return this.$canvas?this.$canvas.width/this._canvasScale:0}get clientHeight(){return this.$canvas?this.$canvas.height/this._canvasScale:0}_resize(){this.el&&(this.$canvas.width=this.el.clientWidth*this._canvasScale,this.$canvas.height=this.el.clientHeight*this._canvasScale,this.$canvas.style.width=`${this.el.clientWidth}px`,this.$canvas.style.height=`${this.el.clientHeight}px`,this.$pointerCanvas.width=this.el.clientWidth*this._canvasScale,this.$pointerCanvas.height=this.el.clientHeight*this._canvasScale,this.$pointerCanvas.style.width=`${this.el.clientWidth}px`,this.$pointerCanvas.style.height=`${this.el.clientHeight}px`,this._customFrame&&(this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this._rightDistance-this._leftDistance)))}clearPointerCanvas(){this._pointerCtx.fillStyle="rgba(0,0,0,0)",this._pointerCtx.clearRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}clearCanvas(){const e=this._ctx.createLinearGradient(0,0,0,this.clientHeight*this._canvasScale);e.addColorStop(0,"black"),e.addColorStop(1,this.fillStyle),this._ctx.fillStyle=e,this._ctx.fillRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}setFrame(e,t){this._leftDistance=e,this._rightDistance=t,this._customFrame=!0,this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this._rightDistance-this._leftDistance),this.model.setRange(e,t),this.draw()}_updateUnits(){this._customFrame||(this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this.model.maxX-this.model.minX)),this._pixelsInMeter_y=this._canvasScale*this.clientHeight/(this.model.maxY-this.model.minY)}clear(){this.model.clear(),this.clearCanvas()}draw(){let e=this.model.drawData[0];if(e.length>1){this._updateUnits(),this.clearCanvas();let t=this.model.drawData[1];this._drawTrack(e,t),this._drawTerrain(t),this._drawWarningAndCollision(t),this._drawLabels(e,t)}else this.clearCanvas()}_drawLabels(e,t){let i=this._ctx;if(i){let n=e[0];const r=this.model.maxY;let s=(-this._leftDistance+n[0])*this._pixelsInMeter_x,a=(r-n[1])*this._pixelsInMeter_y;t[n[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(s-4,a-4,8,8),i.stroke(),i.fillStyle="white",i.font=26/devicePixelRatio+"px Arial",i.textBaseline="bottom",i.textAlign="left",i.fillText(`${Math.round(n[1]-t[n[2]][1]).toString()} m`,s+1,a-10),i.stroke();for(let n=1,o=e.length;n<o;n++){let o=e[n];s=(-this._leftDistance+o[0])*this._pixelsInMeter_x,a=(r-o[1])*this._pixelsInMeter_y,t[o[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(s-4,a-4,8,8),i.stroke(),i.fillStyle="white",i.fillText(`${Math.round(o[1]-t[o[2]][1]).toString()} m`,s+1,a-10),i.stroke()}}}_drawTrack(e,t){let i=e[0],n=this._ctx;if(n){const r=this.model.maxY;n.lineWidth=5,n.strokeStyle="rgb(0, 255, 50)",n.beginPath(),n.moveTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(r-i[1])*this._pixelsInMeter_y);let s=0;for(let t=1,i=e.length;t<i;t++){let i=e[t];n.lineTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(r-i[1])*this._pixelsInMeter_y);let a=e[t-1],o=i[0]-a[0],l=i[1]-a[1],h=o*o,c=l*l;s+=Math.sqrt(h+c)}n.stroke(),n.lineWidth=2,n.strokeStyle="rgba(255,255,255,0.7)",n.beginPath();let a=(-this._leftDistance+i[0])*this._pixelsInMeter_x,o=(r-i[1])*this._pixelsInMeter_y,l=(r-t[i[2]][1])*this._pixelsInMeter_y;n.moveTo(a,o),n.lineTo(a,l);for(let i=1,s=e.length;i<s;i++){let s=e[i];a=(-this._leftDistance+s[0])*this._pixelsInMeter_x,o=(r-s[1])*this._pixelsInMeter_y,l=(r-t[s[2]][1])*this._pixelsInMeter_y,n.strokeStyle="rgba(255,255,255,0.7)",n.moveTo(a,o),n.lineTo(a,l)}n.stroke(),this.events.dispatch(this.events.tracklength,s)}}_drawTerrain(e){let t=e[0],i=this._ctx;if(i){const n=this.model.maxY;i.lineWidth=5,i.strokeStyle=hs,i.beginPath(),i.moveTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,this.$canvas.height),i.lineTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,(n-t[1])*this._pixelsInMeter_y);let r=0;for(let t=1,s=e.length;t<s;t++){let s=e[t];i.lineTo((-this._leftDistance+s[0])*this._pixelsInMeter_x,(n-s[1])*this._pixelsInMeter_y);let a=e[t-1],o=s[0]-a[0],l=s[1]-a[1],h=o*o,c=l*l;r+=Math.sqrt(h+c)}i.lineTo((-this._leftDistance+e[e.length-1][0])*this._pixelsInMeter_x,this.$canvas.height),i.closePath(),i.stroke(),i.save(),i.fillStyle="rgb(64, 68, 82)",i.globalAlpha=.5,i.fill(),i.restore(),i.globalAlpha=1,this.events.dispatch(this.events.groundlength,r)}}_drawWarningAndCollision(e){let t=this._ctx;if(t&&e.length>1){let i=this.model.maxY;t.lineWidth=5,t.beginPath();let n=0,r=0;for(let s=0,a=e.length-1;s<a;s++){let a=e[s],o=e[s+1];if(0!==a[2]&&0!==o[2]){let e=o[0]-a[0],s=o[1]-a[1],l=e*e,h=s*s;2===a[2]?(t.stroke(),t.beginPath(),t.strokeStyle=cs[2],r+=Math.sqrt(l+h)):1===a[2]&&(t.stroke(),t.beginPath(),t.strokeStyle=cs[1],n+=Math.sqrt(l+h)),t.moveTo((-this._leftDistance+a[0])*this._pixelsInMeter_x,(i-a[1])*this._pixelsInMeter_y),t.lineTo((-this._leftDistance+o[0])*this._pixelsInMeter_x,(i-o[1])*this._pixelsInMeter_y)}}t.stroke(),this.events.dispatch(this.events.warninglength,n),this.events.dispatch(this.events.collisionlength,r)}}}let us=gi.createCylinder(.33,0,1,20,1,!0,!1,0,0,0),fs=gi.createCylinder(.33,.33,1.1,20,1,!0,!0,0,-.55,0);const gs={startPosition:new oe,endPosition:new oe,startColor:"rgba(255,131,0,0.2)",endColor:"rgba(255,131,0,1.0)",thickness:2.7},ps={src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjEuNBNAaMQAAAiLSURBVHhe7Z0r0BxFEMcjIhAIRERERAQCgUAgEBEIBAIRiUAgIiIQiAgEIlUREQgEIgIREYFAIBCIiAgEIiIiAoGIoHimqPAKz5CP/t23/8vcbe89d/dmZ/pf9avLdZK72e6+ee3M7Imjo6Opc8o4b7xn3DIeGEOJz+Y7+C6+k+/2yjQZXOMEOGdcNe4anv4wvjV+m73bT3wGn8VneqIMlIUyeWXNGteYKTj4feNrI9W/xi/HfxxVfCffnYqyUcbJJINrzIjTxjvGV0aqn43fj/+YhSgLZUpFmd81uAbv2rLANWbAC8ZHxp+GxC8ufZ+rKGNaI1FLcC1ck3etB8U1HhCqzk8N6T/jENV7X6LsXIN008iqeXCNB+B54zND+tt4ePzHIsS1cE0SicA1e74YFdc4IgyjrhvqTP3TvJas9Bq59oP2EVzjCJw03jI0TCMBcurUDS1qBCU9PnjbwCeerwbFNQ4MVd9tQ5pyG7+v0mvHJ6N3FF3jgFwy1JPvmlipUfIFvmHY6/luEFzjANDO0fGRfm1eQ0+UzlriqzOG58tecY0985LxnYH+al5D3ZKP8Bm+83zaG66xRy4a6uzU3NZvK/nqkUEH0fNtL7jGHqBH+4EhTWEGL2ddMwYZJbjGPaGgHxuIDA7tJ/mQGdLek8A17sHTxucGiva+P6kGxbf42PP9TrjGHUmDH1V+/xokCVzjDkTwx1HvSeAat4R2SWP8CP7wko9ZmrZ3n8A1bok6fBH88SRf4/u9ksA1bgFr4ZDG+qHxpLuKLFD1YrMRrnFDLhjocfMaGl8aIjLh5sVoLa5xA140+lhxG+pHNAk7TRu7xjXQ+9TK3Jru4ecqxYB7B88YXsw6cY1rUKcv7ujlI907YLbQi1knrnEFavej05ef1ClkpZUXOxfX2AH3p6Pdz1/E6FnDi2EL19iBVu3Gbd18pdgwU+jFsIVrdHjDQHGDJ39pkojm2ovlAq5xCXqWWtETmo7uG2t3L7vGJTTbF73+6UhNARtVvZjOcY0JZ42Y45+uGK2t7BC6xoQbBoqO3/SkGpt5Gy+2M1xjw3MGGZRubgxNS5qv6dxw4hob9OuPsf90pWnizlrANRpM+sSvvwypFqBGb8W6ZWjgHjOKtn/6Ug3OMv1WrFsG4ykjqv3yxGiudbdw4U2DbvjEuL8cqSZv7TJaeNOg1b2h8nTHWIj3whuDSQOUHmcSKkPagr5wNE0afLhioOj8lSc16QvTw2nwYfk8vlB5YjnfPOZp8FX9x8kd5Uqju3kzkCYAPUQU1X+5UjPACaatBEiPcAmVrfmKIQU/Jn/qEpNCs82lSgCOL0U/Na+hcvVD8/qKMU8AjiZDsdGjfCnGl415AnyCJVSVZptIlAD3sISqEgt9ZwnAHSIU07/1SMv7T5EA7CpFPzavofKljuA5EkCbPmICqB4p1m+SAPQGQ3XqMgnAQwtCdeo6CRBTwPXqJgnAKpFQnbpDAsQcQL26RwLEzt96dZ8ECFWsSIDKFQlQuSIBKlckQOUiAThLJlSnZqOAmAeoV7N5gJgJrFd3SQCePBGqU7dIgLgbWK9mdwO1ITRUn66QADoQIlYE1SPF+gIJEGsC69PCmkDOk0WxKrgeaQf4aRIA9AiYUD2a7wuA2BlUn1gKOE8A9ouj2BtYvh42r4z+5gnATlEUHcHy9X3z+poxT4A4H6Aecfxv63wAiOXh9ah1QgioHxAnhJYr1fKz9h/SBOA0aRSnhJUrJQCP/m0lAMQ5geWr85xA0I2haAbKk4b4K08KVTMQ08LlSU37vPqHNPgiVgiVK5r4hXgvvGm4aKC4PVyOFMuNnhfABEFMCpWnjZ8YAjxfBkUiTF/q/LH0rxXrlqFBJ4friVOh6Uod+oUHRYiWIYFnzaG4QzhdqefPo/+9GK9MAJ42SQ0QtcB0pV//wtAvxTUmqBaIiaHpSff9Z0fCduEaE+gLxBNEpyliRuzctl+4xiU0Ioh5gelIsfrQ8GI6xzUuwdjxgRGalojZacOL6RzX6KDNI0wmhPKWev6tWT8P19jBFwaKDmG+0pD9tnHS8OK4gGvsgDuFUQPkr7UdvxTXuAI9Wk7nzYfykX6clwwvdi6ucQ3MKqEYFeQjxYKFvRtV/cI1roG9hDpdNNYPHl6KAWc9re31L+MaN4DHzMUUcT4iFi8bXqxW4ho3RP2Bx81raHw9al557J8Xo7W4xi24ZqAYHYwv+XztbN8qXOMW0OFQpzBuG48n+XrrTt8yrnFLWELGViMUSTC85GN8Ptvftw+ucQcYGTD7hCIJhpN8y8rtrXv8Hq5xR7hpdNdAkQT9Sz7Fx70EH1zjHlAl6Z5BdAz7k3xJLdta2bsPrnFP0j5BzBXsL/mwlzZ/GdfYA/RMbxgo5gl2l3yHL/fq7XfhGnskfSpp3DvYXKmvZs/5HwrX2DOcP6QVRVqoGOqWfMSmnFcNz6e94RoH4IyhziGLFeMmUlv4RItv8RU+83zZK65xIGjDOH9AnZoYKj6RfIFvrhqDtPcernFg2KTwpSHVvMQsvXa2bnNus+ezwXCNI6DaQOPbGoeLumZ8gC9G+9WnuMYRYeOJdh+hGiaP0mvkiF584PlmFFzjAWAxgzqJqMRESK+Ja91pAUffuMYDwvGlaSJQTU65j0DZ0+aNaztveNd+EFxjBjB3QPWYOm9Kh1WkZeUa2KDJNXnXelBcY0bQPnKs2fIj7nOsFZbLRJkp+0Hb+HW4xgzhMGuqTubEl2sC9igcYpqZ71zeH0HZKCNlpczetWSFa8wcJQO7lrtONiUQ3xh9TDbxGXxWVxNEGSjLZIKe4honxlnjdYMFqnSyhhxB8Nl8B9/Fd/LdXpkmg2ssANpdfpEsXacdZq6BJ6Tya+VZyWnnUsLG3/Fv+Lf8H/4vn8FnZd2W78bRif8BxMOwtJg5Ph4AAAAASUVORK5CYII=",color:"rgb(255,131,0)",size:[8,8]},ms={text:"",size:10.5,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"left",offset:[5,15,-5]},vs={text:"",size:10.5,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"right",offset:[-47,25,0]},ys={instanced:!0,tag:"ground-pointer",color:"rgb(0,305,0)",object3d:us},xs={instanced:!0,tag:"head-pointer",color:"rgb(305,305,0)",object3d:fs};class bs extends Pi{constructor(e={}){super("ElevationProfileScene"),this._onLClick=e=>{let t=this._planet.getCartesianFromPixelTerrain(e.pos);t&&this.addGroundPoint3vAsync(t)},this._onMouseMove=e=>{if(this._planet.getCartesianFromMouseTerrain(),this._pickedGroundEntity){let t=new le(e.x,e.y).sub(this._startClickPos),i=this._startEntityPos.add(t),n=this._planet.getCartesianFromPixelTerrain(i);n&&this.setGroundPointCartesian3v(this._pickedGroundEntity.properties.index,n)}else if(this._pickedHeadEntity){let t=this._planet.camera,i=this._pickedHeadEntity.properties.groundEntity.getCartesian(),n=this._planet.ellipsoid.getSurfaceNormal3v(i),r=i.add(n),s=i.add(t.getRight()),a=new oe;if(new _i(t.eye,e.direction).hitPlane(i,r,s,a)===_i.INSIDE){let e=oe.proj_b_to_a(a,i),t=e.sub(i).dot(i),r=i.add(n.scale(Math.sign(t)*e.distance(i)));this.setHeadPointCartesian3v(this._pickedHeadEntity.properties.index,r)}}},this._onLUp=e=>{},this._onGroundPointerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onGroundPointerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onGroundPointerLDown=e=>{this._clampToGround=!1,this.renderer.controls.mouseNavigation.deactivate(),this._pickedGroundEntity=e.pickingObject;const t=this._pickedGroundEntity.getCartesian();this._startClickPos.set(e.x,e.y),this._startEntityPos=this._planet.getPixelFromCartesian(t)},this._onGroundPointerLUp=e=>{this._clampToGround=!0,this.renderer.controls.mouseNavigation.activate(),this._pickedGroundEntity=null},this._onHeadPointerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onHeadPointerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onHeadPointerLDown=e=>{this.renderer.controls.mouseNavigation.deactivate(),this._pickedHeadEntity=e.pickingObject},this._onHeadPointerLUp=e=>{this.renderer.controls.mouseNavigation.activate(),this._pickedHeadEntity=null},this.events=Pt(ws),this._planet=e.planet||null,this._pickedGroundEntity=null,this._pickedHeadEntity=null,this._startClickPos=new le,this._startEntityPos=new le,this._clampToGround=!0,this._trackLayer=new In("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._groundPointersLayer=new In("ground-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,5e3,.02],pickingScale:1.5}),this._headPointersLayer=new In("head-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,1e4,.02],pickingScale:1}),this._columnPointersLayer=new In("column-pointers",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._trackEntity=new Ai({polyline:{path3v:[],thickness:3.8,color:"rgba(0,305,0,0.8)",isClosed:!1}}),this._trackLayer=new In("column-pointers",{entities:[this._trackEntity],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._heightsLayer=new In("heights-labels",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._pointerHeadEntity=new Ai({cartesian:new oe,billboard:ps}),this._pointerLabelEntity=new Ai({cartesian:new oe,label:ms}),this._pointerRayEntity=new Ai({cartesian:new oe,ray:gs}),this._pointerLayer=new In("pointer",{entities:[this._pointerHeadEntity,this._pointerLabelEntity,this._pointerRayEntity],pickingEnabled:!1,hideInLayerSwitcher:!0})}flyExtent(){let e=this._headPointersLayer.getEntities(),t=180,i=180,n=-180,r=-180,s=-1e6;if(e.length>1){for(let a=0;a<e.length;a++){let o=e[a].getLonLat();o.lon<t&&(t=o.lon),o.lat<i&&(i=o.lat),o.lon>n&&(n=o.lon),o.lat>r&&(r=o.lat),o.height>s&&(s=o.height)}this._planet.camera.flyExtent(new ie(new z(t,i),new z(n,r)),s,null,0)}}get planet(){return this._planet}_createGroundPointer(e,t=10){let i=this.ellipsoid.getSurfaceNormal3v(e),n=e.add(i.scale(t)),r=new Ai({ray:{startPosition:e,endPosition:n,startColor:"rgba(255,255,255,0.2)",endColor:"rgba(355,355,355,1.0)",thickness:3.2}}),s=new Ai({cartesian:e,geoObject:ys}),a=new Ai({cartesian:n,geoObject:xs,properties:{}}),o=new Ai({cartesian:n,label:vs});o.appendChild(new Ai({cartesian:n,label:{...vs,offset:[-47,45,0]}}));const l=this._groundPointersLayer.getEntities().length;return r.properties=s.properties=a.properties={index:l,altitude:t,lonLatEll:new z,headEntity:a,groundEntity:s,columnEntity:r,heightLabelEntity:o},{headEntity:a,groundEntity:s,columnEntity:r,heightLabelEntity:o}}setPointerCartesian3v(e,t){this._pointerLabelEntity.setCartesian3v(e),this._pointerLabelEntity.label.setText(`${Math.round(t).toString()} m`),this._pointerRayEntity.ray.setEndPosition3v(e);let i=this._planet.ellipsoid.getSurfaceNormal3v(e);this._pointerRayEntity.ray.setStartPosition3v(e.add(i.scale(-t))),this._pointerHeadEntity.setCartesian3v(e)}bindPlanet(e){this._planet=e}init(){this._activate()}onremove(){this._deactivate()}_activate(){this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._groundPointersLayer),this._planet.addLayer(this._columnPointersLayer),this._planet.addLayer(this._headPointersLayer),this._planet.addLayer(this._heightsLayer),this._planet.addLayer(this._pointerLayer),this.renderer.events.on("ldblclick",this._onLClick),this.renderer.events.on("mousemove",this._onMouseMove),this.renderer.events.on("lup",this._onLUp),this._groundPointersLayer.events.on("mouseenter",this._onGroundPointerEnter),this._groundPointersLayer.events.on("mouseleave",this._onGroundPointerLeave),this._groundPointersLayer.events.on("ldown",this._onGroundPointerLDown),this._groundPointersLayer.events.on("lup",this._onGroundPointerLUp),this._headPointersLayer.events.on("mouseenter",this._onHeadPointerEnter),this._headPointersLayer.events.on("mouseleave",this._onHeadPointerLeave),this._headPointersLayer.events.on("ldown",this._onHeadPointerLDown),this._headPointersLayer.events.on("lup",this._onHeadPointerLUp),this.setPointerVisibility(!1)}getPointLonLat(e){let t=this._headPointersLayer.getEntities()[e];if(t)return t.getLonLat()}getPointsLonLat(){let e=this._headPointersLayer.getEntities(),t=new Array(e.length);for(let i=0,n=t.length;i<n;i++){let n=e[i];t[i]=n.getLonLat()}return t}getHeightMSL(e){return this._planet&&this._planet.terrain.geoid?this._planet.terrain.geoid.getHeightLonLat(e):0}getHeightELLAsync(e){return new Promise(((t,i)=>{this._planet.terrain.getHeightAsync(e,(n=>{if(this._planet){let i=this.getHeightMSL(e);t(n+i)}else i()}))}))}addPointLonLatArrayAsync(e,t=!1){if(!this._planet)throw new Error("Planet is not defined");let i=this._planet.ellipsoid;for(let t=0,n=e.length-1;t<n;t++){let n=i.lonLatToCartesian(e[t]),r=i.lonLatToCartesian(e[t+1]);if(n.distance(r)>1e5)throw new Error("Track is too long! 100 km is maximum.")}let n=new Array(e.length);for(let t=0,i=e.length;t<i;t++)n[t]=this.addPointLonLatAsync(e[t],!0);return Promise.all(n).then((()=>{t||this.events.dispatch(this.events.change,this)})),n}addPointLonLatAsync(e,t=!1){let i=this._planet.ellipsoid.lonLatToCartesian(e),n=this._planet.ellipsoid.getSurfaceNormal3v(i),r=new z(e.lon,e.lat),s=this._planet.ellipsoid.lonLatToCartesian(r),{headEntity:a,groundEntity:o,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(s);return this._groundPointersLayer.add(o),this._columnPointersLayer.add(l),this._headPointersLayer.add(a),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(a.getCartesian()),o.properties.lonLatEll.lon=r.lon,o.properties.lonLatEll.lat=r.lat,o.properties.lonLatEll.height=r.height,new Promise((r=>{this.getHeightELLAsync(e).then((s=>{o.properties.lonLatEll.height=s;let l,c=10;0===e.height?(l=i.add(n.scaleTo(s)),i=l.add(n.scaleTo(c))):(c=e.height-s,l=i.sub(n.scaleTo(c))),o.setCartesian3v(l),h.setCartesian3v(i),h.label.setText(`${s.toFixed(1)} m`),h.childrenNodes[0].label.setText(`${c.toFixed(1)} m`),a.properties.altitude=c,a.setCartesian3v(i),a.properties.columnEntity.ray.setStartPosition3v(l),a.properties.columnEntity.ray.setEndPosition3v(i),this._trackEntity.polyline?.setPoint3v(i,a.properties.index),t||(this.events.dispatch(this.events.addpoint,a,this),this.events.dispatch(this.events.change,this)),r(a)}))}))}addGroundPointLonLatAsync(e,t=10,i=!1){let n=this._planet.ellipsoid.lonLatToCartesian(e);return this._addPoint(n,e,t,i)}addGroundPoint3vAsync(e,t=10,i=!1){let n=this._planet.ellipsoid.cartesianToLonLat(e);return this._addPoint(e,n,t,i)}_addPoint(e,t,i,n=!1){return new Promise(((r,s)=>{let{headEntity:a,groundEntity:o,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(e,i);this._groundPointersLayer.add(o),this._columnPointersLayer.add(l),this._headPointersLayer.add(a),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(a.getCartesian()),o.properties.lonLatEll.lon=t.lon,o.properties.lonLatEll.lat=t.lat,o.properties.lonLatEll.height=t.height,this.getHeightELLAsync(t).then((e=>{o.properties.lonLatEll.height=t.height=e;let s=this._planet.ellipsoid.lonLatToCartesian(t),l=this._planet.ellipsoid.getSurfaceNormal3v(s),c=s.add(l.scale(i));h.setCartesian3v(c),h.label.setText(`${e.toFixed(1)} m`),h.childrenNodes[0].label.setText(`${i.toFixed(1)} m`),a.setCartesian3v(c),a.properties.columnEntity.ray.setEndPosition3v(c),this._trackEntity.polyline?.setPoint3v(c,a.properties.index),n||(this.events.dispatch(this.events.addpoint,a,this),this.events.dispatch(this.events.change,this)),r(a)}))}))}setHeadPointCartesian3v(e,t){const i=this._headPointersLayer.getEntities()[e];if(i){let n=this._planet.ellipsoid.lonLatToCartesian(i.properties.lonLatEll),r=t.length()-n.length();r<=0&&(t=n,r=0),i.properties.altitude=r,i.setCartesian3v(t),i.properties.columnEntity.ray.setEndPosition3v(t),i.properties.heightLabelEntity.setCartesian3v(t),i.properties.heightLabelEntity.childrenNodes[0].label.setText(`${r.toFixed(1)} m`),this._trackEntity.polyline.setPoint3v(t,e),this.events.dispatch(this.events.change,this._pickedHeadEntity)}}setGroundPointCartesian3v(e,t){let i=this._groundPointersLayer.getEntities()[e];if(i){let e=this._planet.ellipsoid.cartesianToLonLat(t);i.properties.lonLatEll.lon=e.lon,i.properties.lonLatEll.lat=e.lat,i.properties.lonLatEll.height=e.height;let n=this._planet.ellipsoid.getSurfaceNormal3v(t),r=i.properties.headEntity,s=i.properties.heightLabelEntity,a=i.properties.altitude;i.setCartesian3v(t);let o=t.add(n.scale(a));r.setCartesian3v(o),r.properties.columnEntity.ray.setStartPosition3v(t),r.properties.columnEntity.ray.setEndPosition3v(o),this._trackEntity.polyline?.setPoint3v(o,r.properties.index),s.setCartesian3v(o),s.label.setText(`${e.height.toFixed(1)} m`),s.childrenNodes[0].label.setText(`${a.toFixed(1)} m`),this.events.dispatch(this.events.change,i.properties.headEntity)}}_deactivate(){this.renderer.events.off("ldblclick",this._onLClick),this.renderer.events.off("mousemove",this._onMouseMove),this.renderer.events.off("lup",this._onLUp),this._groundPointersLayer.events.off("mouseenter",this._onGroundPointerEnter),this._groundPointersLayer.events.off("mouseleave",this._onGroundPointerLeave),this._groundPointersLayer.events.off("ldown",this._onGroundPointerLDown),this._groundPointersLayer.events.off("lup",this._onGroundPointerLUp),this._headPointersLayer.events.off("mouseenter",this._onHeadPointerEnter),this._headPointersLayer.events.off("mouseleave",this._onHeadPointerLeave),this._headPointersLayer.events.off("ldown",this._onHeadPointerLDown),this._headPointersLayer.events.off("lup",this._onHeadPointerLUp),this._trackLayer.remove(),this._groundPointersLayer.remove(),this._headPointersLayer.remove(),this._columnPointersLayer.remove(),this._trackLayer.remove(),this._heightsLayer.remove(),this._pointerLayer.remove(),this.clear()}setPointerVisibility(e){this._pointerLayer.setVisibility(e)}setVisibility(e){this._groundPointersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._columnPointersLayer.setVisibility(e),this._headPointersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._heightsLayer.setVisibility(e),this._pointerLayer.setVisibility(e)}clear(){this._headPointersLayer.setEntities([]),this._groundPointersLayer.setEntities([]),this._columnPointersLayer.setEntities([]),this._heightsLayer.setEntities([]),this._trackEntity.polyline.setPath3v([])}frame(){if(this._clampToGround){let e=new oe;const t=this._planet._renderedNodes,i=this._groundPointersLayer.getEntities();for(let n=0;n<i.length;n++){let r=i[n];for(let i=0;i<t.length;i++){let n=t[i];if(n.segment.isEntityInside(r)){n.segment.getEntityTerrainPoint(r,e),r.setCartesian3v(e),r.properties.columnEntity.ray.setStartPosition3v(e);break}}}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const ws=["change","addpoint"],Cs=["reset","list","location"];class Ts extends Bt{constructor(e={}){super({...e,template:'<div class="og-elevationprofile-buttons"></div>'}),this.events=this.events.registerNames(Cs),this.pointListBtn=new Ot({classList:["og-elevationprofile-button"],icon:'<?xml version="1.0" encoding="utf-8"?><svg width="800px" height="800px" viewBox="0 0 32 32" id="icon" xmlns="http://www.w3.org/2000/svg"><defs><style>.cls-1{fill:none;}</style></defs><title>list</title><rect x="10" y="6" width="18" height="2"/><rect x="10" y="24" width="18" height="2"/><rect x="10" y="15" width="18" height="2"/><rect x="4" y="15" width="2" height="2"/><rect x="4" y="6" width="2" height="2"/><rect x="4" y="24" width="2" height="2"/></svg>',title:"Point List"}),this.pointListBtn.events.on("change",(e=>{this.events.dispatch(this.events.list,e)}))}render(e){super.render(e);let t=new Rt({classList:["og-elevationprofile-button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg width="30" height="30" viewBox="0 0 30 30" version="1.1">\n <g transform="translate(0,-289.0625)">\n <path d="M 15 6 C 10.041282 6 6 10.04128 6 15 C 6 19.95872 10.041282 24 15 24 C 16.586491 24 18.07668 23.58246 19.373047 22.857422 L 17.888672 21.375 C 17.00816 21.772814 16.032235 22 15 22 C 11.122162 22 8 18.87784 8 15 C 8 11.12216 11.122162 8 15 8 C 18.877838 8 22 11.12216 22 15 L 19 15 L 23 20 L 27 15 L 24 15 C 24 10.04128 19.958718 6 15 6 z " transform="translate(0,289.0625)" />\n </g>\n</svg>',title:"Reset"});t.appendTo(this.el),t.events.on("click",(()=>{this.model.clear(),this.events.dispatch(this.events.reset,this)})),this.pointListBtn.appendTo(this.el);let i=new Rt({classList:["og-elevationprofile-button","og-elevationprofile-button__location"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 256 256" enable-background="new 0 0 256 256" xml:space="preserve">\n<metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n<g><g><path fill="#000000" d="M127,169.4c23.7,0,42.8-18.3,42.8-41s-19.2-41-42.8-41c-23.7,0-42.8,18.4-42.8,41S103.4,169.4,127,169.4z"/><path fill="#000000" d="M221.7,120.2c-3.8-44-40.9-78.9-87-82V15h-16.3v23.6c-44.8,4-80.3,38.5-84.1,81.7H10v15.6h24.3c3.8,43.1,39.3,77.4,84.1,81.7V241h16.3v-23.2c46-3.1,83.2-37.9,87-82H246v-15.6H221.7L221.7,120.2L221.7,120.2z M128,201.6c-42.5,0-76.7-33-76.7-73.4c0-40.4,34.5-73.4,76.7-73.4c42.5,0,76.7,33,76.7,73.4C204.7,168.5,170.5,201.6,128,201.6L128,201.6z"/></g></g>\n</svg>',title:"View bounds"});return i.appendTo(this.el),i.events.on("click",(()=>{this.events.dispatch(this.events.location,this)})),this}}class Ls extends Nt{constructor(e){super({title:"Points List",visible:!1,resizable:!0,useHide:!0,top:150,left:200,width:400,height:300,minHeight:100,minWidth:100,...e}),this._onApplyClick=()=>{try{this.model.clear();let e=JSON.parse(this.$textarea.value),t=new Array(e.length);for(let i=0;i<e.length;i++){let n=e[i];t[i]=new z(n[0],n[1],n[2])}this.model.addPointLonLatArrayAsync(t)}catch(e){console.error(e)}},this.$textarea=null}render(e){super.render(e);let t=new Bt({template:'<div class="og-elevationprofile-list">\n <textarea placeholder="[[lon, lat, height], [lon, lat, height], ..., [lon, lat, height]]"></textarea>\n <div class="og-elevationprofile-list-buttons"></div>\n </div>'});t.appendTo(this.container);let i=new Rt({classList:["og-elevationprofile-list-apply"],icon:"Apply"});return i.appendTo(t.select(".og-elevationprofile-list-buttons")),i.events.on("click",this._onApplyClick),this.$textarea=t.select("textarea"),this}}class As extends Bt{constructor(e={}){super({...e,template:'<div class="og-elevationprofile-legend">\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__track">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__ground">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__warning"> \n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__collision">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n </div>'}),this.$groundValue=null,this.$trackValue=null,this.$warningValue=null,this.$collisionValue=null,this.$trackUnits=null,this.$groundUnits=null,this.$warningUnits=null,this.$collisionUnits=null}render(e){return super.render(e),this.$trackValue=this.select(".og-elevationprofile-legend__track .og-elevationprofile-value"),this.$groundValue=this.select(".og-elevationprofile-legend__ground .og-elevationprofile-value"),this.$warningValue=this.select(".og-elevationprofile-legend__warning .og-elevationprofile-value"),this.$collisionValue=this.select(".og-elevationprofile-legend__collision .og-elevationprofile-value"),this.$trackUnits=this.select(".og-elevationprofile-legend__track .og-elevationprofile-units"),this.$groundUnits=this.select(".og-elevationprofile-legend__ground .og-elevationprofile-units"),this.$warningUnits=this.select(".og-elevationprofile-legend__warning .og-elevationprofile-units"),this.$collisionUnits=this.select(".og-elevationprofile-legend__collision .og-elevationprofile-units"),this}clear(){this.$trackValue&&(this.$trackValue.innerText="0"),this.$trackUnits&&(this.$trackUnits.innerText="m"),this.$groundValue&&(this.$groundValue.innerText="0"),this.$groundUnits&&(this.$groundUnits.innerText="m"),this.$warningValue&&(this.$warningValue.innerText="0"),this.$warningUnits&&(this.$warningUnits.innerText="m"),this.$collisionValue&&(this.$collisionValue.innerText="0"),this.$collisionUnits&&(this.$collisionUnits.innerText="m")}setTrackLength(e){let t=Ze(e);this.$trackValue.innerText=t[0],this.$trackUnits.innerText=t[1]}setGroundLength(e){let t=Ze(e);this.$groundValue.innerText=t[0],this.$groundUnits.innerText=t[1]}setWarningLength(e){let t=Ze(e);this.$warningValue.innerText=t[0],this.$warningUnits.innerText=t[1]}setCollisionLength(e){let t=Ze(e);this.$collisionValue.innerText=t[0],this.$collisionUnits.innerText=t[1]}}var Es=Object.freeze({__proto__:null,AtmosphereConfig:class extends It{constructor(e={}){super(e),this.$maxOpacity=null,this.$minOpacity=null,this.$rayleight=null,this.$mie=null,this.$height=null,this.$bottomRadius=null,this.$mieScatteringCoefficient=null,this.$mieExtinctionCoefficient=null,this.$rayleighScatteringCoefficientA=null,this.$rayleighScatteringCoefficientB=null,this.$rayleighScatteringCoefficientC=null,this.$ozoneAbsorptionCoefficientA=null,this.$ozoneAbsorptionCoefficientB=null,this.$ozoneAbsorptionCoefficientC=null,this.$sunAngularRadius=null,this.$sunIntensity=null,this.$groundAlbedo=null,this.$ozoneDensityHeight=null,this.$ozoneDensityWide=null,this._toggleBtn=new Ot({classList:["og-map-button","og-atmosphere_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg width="800px" height="800px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path fill="#000000" d="M135.688 18.5c-6.798 74.842-23.842 85.39-107.907 59.656 84.85 52.022 73.57 64.954-6.843 96.938 87.743-10.27 103.29 4.89 70.75 87.594 17.805-27.56 32.5-44.498 46.282-54.47-11.813 28.26-18.345 59.274-18.345 91.813 0 84.184 43.71 157.96 109.656 200.376-41.624-43.834-67.686-102.7-67.686-167.875 0-134.923 109.45-244.405 244.375-244.405 30.92 0 60.76 5.762 88 16.25-38.584-26.87-85.517-42.625-136.064-42.625-55.257 0-106.14 18.802-146.562 50.375 4.627-18.783 17.39-38.073 41.03-60.906C190.18 90.942 153.53 95.634 135.69 18.5zm10.03 77.188c5.67.002 11.428 1.247 16.876 3.874 14.506 6.998 22.72 21.81 22 36.938-10.26 10.87-19.507 22.696-27.594 35.344-9.035 2.753-19.075 2.27-28.25-2.156-19.37-9.343-27.5-32.6-18.156-51.97 6.715-13.92 20.638-22.036 35.125-22.03z"/></svg>'}),this._dialog=new Nt({title:"Atmosphere Parameters",visible:!1,useHide:!0,top:60,left:60,width:720}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._panel=new Bt({template:'<div class="og-atmosphere og-options-container">\n \n <div class="og-option og-atmosphere-maxOpacity"></div> \n <div class="og-option og-atmosphere-minOpacity"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-rayleight"></div>\n <div class="og-option og-atmosphere-mie"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-height"></div> \n <div class="og-option og-atmosphere-bottomRadius"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-mieScatteringCoefficient"></div> \n <div class="og-option og-atmosphere-mieExtinctionCoefficient"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-rayleighScatteringCoefficientA"></div> \n <div class="og-option og-atmosphere-rayleighScatteringCoefficientB"></div> \n <div class="og-option og-atmosphere-rayleighScatteringCoefficientC"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-ozoneAbsorptionCoefficientA"></div> \n <div class="og-option og-atmosphere-ozoneAbsorptionCoefficientB"></div> \n <div class="og-option og-atmosphere-ozoneAbsorptionCoefficientC"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-ozoneDensityHeight"></div> \n <div class="og-option og-atmosphere-ozoneDensityWide"></div> \n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-sunAngularRadius"></div> \n <div class="og-option og-atmosphere-sunIntensity"></div> \n <div class="og-option og-atmosphere-earthAlbedo"></div>\n \n </div>'}),this._maxOpacity=new gr({label:"Max.opacity",max:5}),this._minOpacity=new gr({label:"Min.opacity",max:5}),this._rayleight=new gr({label:"Rayleight Scale",min:-10,max:10}),this._mie=new gr({label:"Mie Scale",min:-10,max:10}),this._height=new gr({label:"Height",max:1e6}),this._bottomRadius=new gr({label:"Planet Radius",max:31783761.571225896}),this._mieScatteringCoefficient=new gr({label:"Mie Scattering Coefficient e-6",min:-39.96,max:39.96}),this._mieExtinctionCoefficient=new gr({label:"Mie Extinction Coef.e-6",min:4.44*-10,max:10*4.44}),this._rayleighScatteringCoefficientA=new gr({label:"Rayleight Scattering Coef A.e-6",min:5.802*-10,max:10*5.802}),this._rayleighScatteringCoefficientB=new gr({label:"Rayleight Scattering Coef B.e-6",min:13.558*-10,max:10*13.558}),this._rayleighScatteringCoefficientC=new gr({label:"Rayleight Scattering Coef C.e-6",min:-331,max:331}),this._ozoneAbsorptionCoefficientA=new gr({label:"Ozone absorbtion Coef A.e-6",min:-6.5,max:6.5}),this._ozoneAbsorptionCoefficientB=new gr({label:"Ozone absorbtion Coef B.e-6",min:-6.5,max:18.81}),this._ozoneAbsorptionCoefficientC=new gr({label:"Ozone absorbtion Coef C.e-6",min:.085*-10,max:10*.085}),this._ozoneDensityHeight=new gr({label:"Ozone Density Height",max:25e5}),this._ozoneDensityWide=new gr({label:"Ozone Density Wide",max:25e5}),this._sunAngularRadius=new gr({label:"Sun Angular Radius",max:4.685}),this._sunIntensity=new gr({label:"Sun Intensity",max:10}),this._groundAlbedo=new gr({label:"Earth Albedo",max:.5}),this._parameters={ATMOS_HEIGHT:0,RAYLEIGH_SCALE:0,MIE_SCALE:0,GROUND_ALBEDO:0,BOTTOM_RADIUS:0,rayleighScatteringCoefficient:[0,0,0],mieScatteringCoefficient:0,mieExtinctionCoefficient:0,ozoneAbsorptionCoefficient:[0,0,0],SUN_ANGULAR_RADIUS:0,SUN_INTENSITY:0,ozoneDensityHeight:0,ozoneDensityWide:0}}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.renderer.div),this._panel.appendTo(this._dialog.container),this._panel.el&&(this.$height=this._panel.el.querySelector(".og-option.og-atmosphere-height"),this.$maxOpacity=this._panel.el.querySelector(".og-option.og-atmosphere-maxOpacity"),this.$minOpacity=this._panel.el.querySelector(".og-option.og-atmosphere-minOpacity"),this.$rayleight=this._panel.el.querySelector(".og-option.og-atmosphere-rayleight"),this.$mie=this._panel.el.querySelector(".og-option.og-atmosphere-mie"),this.$bottomRadius=this._panel.el.querySelector(".og-option.og-atmosphere-bottomRadius"),this.$mieScatteringCoefficient=this._panel.el.querySelector(".og-option.og-atmosphere-mieScatteringCoefficient"),this.$mieExtinctionCoefficient=this._panel.el.querySelector(".og-option.og-atmosphere-mieExtinctionCoefficient"),this.$rayleighScatteringCoefficientA=this._panel.el.querySelector(".og-option.og-atmosphere-rayleighScatteringCoefficientA"),this.$rayleighScatteringCoefficientB=this._panel.el.querySelector(".og-option.og-atmosphere-rayleighScatteringCoefficientB"),this.$rayleighScatteringCoefficientC=this._panel.el.querySelector(".og-option.og-atmosphere-rayleighScatteringCoefficientC"),this.$ozoneAbsorptionCoefficientA=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneAbsorptionCoefficientA"),this.$ozoneAbsorptionCoefficientB=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneAbsorptionCoefficientB"),this.$ozoneAbsorptionCoefficientC=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneAbsorptionCoefficientC"),this.$sunAngularRadius=this._panel.el.querySelector(".og-option.og-atmosphere-sunAngularRadius"),this.$sunIntensity=this._panel.el.querySelector(".og-option.og-atmosphere-sunIntensity"),this.$groundAlbedo=this._panel.el.querySelector(".og-option.og-atmosphere-earthAlbedo"),this.$ozoneDensityHeight=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneDensityHeight"),this.$ozoneDensityWide=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneDensityWide")),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this._maxOpacity.appendTo(this.$maxOpacity),this._minOpacity.appendTo(this.$minOpacity),this._height.appendTo(this.$height),this._rayleight.appendTo(this.$rayleight),this._mie.appendTo(this.$mie),this._bottomRadius.appendTo(this.$bottomRadius),this._mieScatteringCoefficient.appendTo(this.$mieScatteringCoefficient),this._mieExtinctionCoefficient.appendTo(this.$mieExtinctionCoefficient),this._rayleighScatteringCoefficientA.appendTo(this.$rayleighScatteringCoefficientA),this._rayleighScatteringCoefficientB.appendTo(this.$rayleighScatteringCoefficientB),this._rayleighScatteringCoefficientC.appendTo(this.$rayleighScatteringCoefficientC),this._ozoneAbsorptionCoefficientA.appendTo(this.$ozoneAbsorptionCoefficientA),this._ozoneAbsorptionCoefficientB.appendTo(this.$ozoneAbsorptionCoefficientB),this._ozoneAbsorptionCoefficientC.appendTo(this.$ozoneAbsorptionCoefficientC),this._sunAngularRadius.appendTo(this.$sunAngularRadius),this._sunIntensity.appendTo(this.$sunIntensity),this._groundAlbedo.appendTo(this.$groundAlbedo),this._ozoneDensityHeight.appendTo(this.$ozoneDensityHeight),this._ozoneDensityWide.appendTo(this.$ozoneDensityWide),this.planet&&(this._parameters=this.planet.atmosphereControl.parameters,this._height.value=this._parameters.ATMOS_HEIGHT,this._rayleight.value=this._parameters.RAYLEIGH_SCALE,this._mie.value=this._parameters.MIE_SCALE,this._bottomRadius.value=this._parameters.BOTTOM_RADIUS,this._mieScatteringCoefficient.value=this._parameters.mieScatteringCoefficient,this._mieExtinctionCoefficient.value=this._parameters.mieExtinctionCoefficient,this._rayleighScatteringCoefficientA.value=this._parameters.rayleighScatteringCoefficient[0],this._rayleighScatteringCoefficientB.value=this._parameters.rayleighScatteringCoefficient[1],this._rayleighScatteringCoefficientC.value=this._parameters.rayleighScatteringCoefficient[2],this._ozoneAbsorptionCoefficientA.value=this._parameters.ozoneAbsorptionCoefficient[0],this._ozoneAbsorptionCoefficientB.value=this._parameters.ozoneAbsorptionCoefficient[1],this._ozoneAbsorptionCoefficientC.value=this._parameters.ozoneAbsorptionCoefficient[2],this._sunAngularRadius.value=this._parameters.SUN_ANGULAR_RADIUS,this._sunIntensity.value=this._parameters.SUN_INTENSITY,this._groundAlbedo.value=this._parameters.GROUND_ALBEDO,this._ozoneDensityHeight.value=this._parameters.ozoneDensityHeight,this._ozoneDensityWide.value=this._parameters.ozoneDensityWide),this._minOpacity.value=this.planet.atmosphereMinOpacity,this._minOpacity.events.on("change",(e=>{this.planet.atmosphereMinOpacity=e})),this._maxOpacity.value=this.planet.atmosphereMaxOpacity,this._maxOpacity.events.on("change",(e=>{this.planet.atmosphereMaxOpacity=e})),this._rayleight.events.on("change",(e=>{this._parameters.RAYLEIGH_SCALE=e,this._update()})),this._mie.events.on("change",(e=>{this._parameters.MIE_SCALE=e,this._update()})),this._height.events.on("change",(e=>{this._parameters.ATMOS_HEIGHT=e,this._update()})),this._bottomRadius.events.on("change",(e=>{this._parameters.BOTTOM_RADIUS=e,this._update()})),this._mieScatteringCoefficient.events.on("change",(e=>{this._parameters.mieScatteringCoefficient=e,this._update()})),this._mieExtinctionCoefficient.events.on("change",(e=>{this._parameters.mieExtinctionCoefficient=e,this._update()})),this._rayleighScatteringCoefficientA.events.on("change",(e=>{this._parameters.rayleighScatteringCoefficient[0]=e,this._update()})),this._rayleighScatteringCoefficientB.events.on("change",(e=>{this._parameters.rayleighScatteringCoefficient[1]=e,this._update()})),this._rayleighScatteringCoefficientC.events.on("change",(e=>{this._parameters.rayleighScatteringCoefficient[2]=e,this._update()})),this._ozoneAbsorptionCoefficientA.events.on("change",(e=>{this._parameters.ozoneAbsorptionCoefficient[0]=e,this._update()})),this._ozoneAbsorptionCoefficientB.events.on("change",(e=>{this._parameters.ozoneAbsorptionCoefficient[1]=e,this._update()})),this._ozoneAbsorptionCoefficientC.events.on("change",(e=>{this._parameters.ozoneAbsorptionCoefficient[2]=e,this._update()})),this._sunAngularRadius.events.on("change",(e=>{this._parameters.SUN_ANGULAR_RADIUS=e,this._update()})),this._sunIntensity.events.on("change",(e=>{this._parameters.SUN_INTENSITY=e,this._update()})),this._groundAlbedo.events.on("change",(e=>{this._parameters.GROUND_ALBEDO=e,this._update()})),this._ozoneDensityHeight.events.on("change",(e=>{this._parameters.ozoneDensityHeight=e,this._update()})),this._ozoneDensityWide.events.on("change",(e=>{this._parameters.ozoneDensityWide=e,this._update()}))}_update(){this.planet&&this.planet.atmosphereControl.setParameters(this._parameters)}},CompassButton:zt,Control:It,DebugInfo:class extends It{constructor(e={}){e.name&&""!==e.name||(e.name="DebugInfo"),super(e),this.el=null,this._watch=e.watch||[],this._toggleBtn=new Ot({classList:["og-map-button","og-debuginfo_button"],icon:'<?xml version="1.0" encoding="iso-8859-1"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg fill="#000000" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \n\t width="800px" height="800px" viewBox="0 0 932.179 932.179"\n\t xml:space="preserve">\n<g>\n\t<path d="M61.2,341.538c4.9,16.8,11.7,33,20.3,48.2l-24.5,30.9c-8,10.1-7.1,24.5,1.9,33.6l42.2,42.2c9.1,9.1,23.5,9.899,33.6,1.899\n\t\tl30.7-24.3c15.8,9.101,32.6,16.2,50.1,21.2l4.6,39.5c1.5,12.8,12.3,22.4,25.1,22.4h59.7c12.8,0,23.6-9.601,25.1-22.4l4.4-38.1\n\t\tc18.8-4.9,36.8-12.2,53.7-21.7l29.7,23.5c10.1,8,24.5,7.1,33.6-1.9l42.2-42.2c9.1-9.1,9.9-23.5,1.9-33.6l-23.1-29.3\n\t\tc9.6-16.601,17.1-34.3,22.1-52.8l35.6-4.1c12.801-1.5,22.4-12.3,22.4-25.1v-59.7c0-12.8-9.6-23.6-22.4-25.1l-35.1-4.1\n\t\tc-4.801-18.3-12-35.8-21.199-52.2l21.6-27.3c8-10.1,7.1-24.5-1.9-33.6l-42.1-42.1c-9.1-9.1-23.5-9.9-33.6-1.9l-26.5,21\n\t\tc-17.2-10.1-35.601-17.8-54.9-23l-4-34.3c-1.5-12.8-12.3-22.4-25.1-22.4h-59.7c-12.8,0-23.6,9.6-25.1,22.4l-4,34.3\n\t\tc-19.8,5.3-38.7,13.3-56.3,23.8l-27.5-21.8c-10.1-8-24.5-7.1-33.6,1.9l-42.2,42.2c-9.1,9.1-9.9,23.5-1.9,33.6l23,29.1\n\t\tc-9.2,16.6-16.2,34.3-20.8,52.7l-36.8,4.2c-12.8,1.5-22.4,12.3-22.4,25.1v59.7c0,12.8,9.6,23.6,22.4,25.1L61.2,341.538z\n\t\t M277.5,180.038c54.4,0,98.7,44.3,98.7,98.7s-44.3,98.7-98.7,98.7c-54.399,0-98.7-44.3-98.7-98.7S223.1,180.038,277.5,180.038z"/>\n\t<path d="M867.699,356.238l-31.5-26.6c-9.699-8.2-24-7.8-33.199,0.9l-17.4,16.3c-14.699-7.1-30.299-12.1-46.4-15l-4.898-24\n\t\tc-2.5-12.4-14-21-26.602-20l-41.1,3.5c-12.6,1.1-22.5,11.4-22.9,24.1l-0.799,24.4c-15.801,5.7-30.701,13.5-44.301,23.3\n\t\tl-20.799-13.8c-10.602-7-24.701-5-32.9,4.7l-26.6,31.7c-8.201,9.7-7.801,24,0.898,33.2l18.201,19.399\n\t\tc-6.301,14.2-10.801,29.101-13.4,44.4l-26,5.3c-12.4,2.5-21,14-20,26.601l3.5,41.1c1.1,12.6,11.4,22.5,24.1,22.9l28.1,0.899\n\t\tc5.102,13.4,11.801,26.101,19.9,38l-15.699,23.7c-7,10.6-5,24.7,4.699,32.9l31.5,26.6c9.701,8.2,24,7.8,33.201-0.9l20.6-19.3\n\t\tc13.5,6.3,27.699,11,42.299,13.8l5.701,28.2c2.5,12.4,14,21,26.6,20l41.1-3.5c12.6-1.1,22.5-11.399,22.9-24.1l0.9-27.601\n\t\tc15-5.3,29.199-12.5,42.299-21.399l22.701,15c10.6,7,24.699,5,32.9-4.7l26.6-31.5c8.199-9.7,7.799-24-0.9-33.2l-18.301-19.399\n\t\tc6.701-14.2,11.602-29.2,14.4-44.601l25-5.1c12.4-2.5,21-14,20-26.601l-3.5-41.1c-1.1-12.6-11.4-22.5-24.1-22.9l-25.1-0.8\n\t\tc-5.201-14.6-12.201-28.399-20.9-41.2l13.699-20.6C879.4,378.638,877.4,364.438,867.699,356.238z M712.801,593.837\n\t\tc-44.4,3.801-83.602-29.3-87.301-73.699c-3.801-44.4,29.301-83.601,73.699-87.301c44.4-3.8,83.602,29.301,87.301,73.7\n\t\tC790.301,550.938,757.199,590.138,712.801,593.837z"/>\n\t<path d="M205,704.438c-12.6,1.3-22.3,11.899-22.4,24.6l-0.3,25.3c-0.2,12.7,9.2,23.5,21.8,25.101l18.6,2.399\n\t\tc3.1,11.301,7.5,22.101,13.2,32.301l-12,14.8c-8,9.899-7.4,24.1,1.5,33.2l17.7,18.1c8.9,9.1,23.1,10.1,33.2,2.3l14.899-11.5\n\t\tc10.5,6.2,21.601,11.101,33.2,14.5l2,19.2c1.3,12.6,11.9,22.3,24.6,22.4l25.301,0.3c12.699,0.2,23.5-9.2,25.1-21.8l2.3-18.2\n\t\tc12.601-3.101,24.601-7.8,36-14l14,11.3c9.9,8,24.101,7.4,33.201-1.5l18.1-17.7c9.1-8.899,10.1-23.1,2.301-33.2L496.6,818.438\n\t\tc6.6-11,11.701-22.7,15.201-35l16.6-1.7c12.6-1.3,22.299-11.9,22.4-24.6l0.299-25.301c0.201-12.699-9.199-23.5-21.799-25.1\n\t\tl-16.201-2.1c-3.1-12.2-7.699-24-13.699-35l10.1-12.4c8-9.9,7.4-24.1-1.5-33.2l-17.699-18.1c-8.9-9.101-23.102-10.101-33.201-2.3\n\t\tl-12.101,9.3c-11.399-6.9-23.6-12.2-36.399-15.8l-1.601-15.7c-1.3-12.601-11.899-22.3-24.6-22.4l-25.3-0.3\n\t\tc-12.7-0.2-23.5,9.2-25.101,21.8l-2,15.601c-13.199,3.399-25.899,8.6-37.699,15.399l-12.5-10.2c-9.9-8-24.101-7.399-33.201,1.5\n\t\tl-18.2,17.801c-9.1,8.899-10.1,23.1-2.3,33.199l10.7,13.801c-6.2,11-11.1,22.699-14.3,35L205,704.438z M368.3,675.837\n\t\tc36.3,0.4,65.399,30.301,65,66.601c-0.4,36.3-30.301,65.399-66.601,65c-36.3-0.4-65.399-30.3-65-66.601\n\t\tC302.1,704.538,332,675.438,368.3,675.837z"/>\n</g>\n</svg>'}),this._dialog=new Nt({title:"Debug Info",visible:!1,useHide:!0,top:120,left:60,width:480}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._canvasTiles=new Zt("Tile grid",{visibility:!0,isBaseLayer:!1,hideInLayerSwitcher:!0,drawTile:function(e,t){let i,n=document.createElement("canvas"),r=n.getContext("2d");n.width=256,n.height=256,r.clearRect(0,0,n.width,n.height),r.beginPath(),r.rect(0,0,n.width,n.height),r.lineWidth=2,r.strokeStyle="black",r.stroke(),i=e.segment.tileZoom>14?"26":"32",r.fillStyle="black",r.font="normal "+i+"px Verdana",r.textAlign="center",r.fillText(e.segment.tileX+","+e.segment.tileY+","+e.segment.tileZoom,n.width/2,n.height/2),t(n)}})}addWatches(e){for(let t=0;t<e.length;t++)this.addWatch(e[t])}addWatch(e){this._watch.push(e);let t=document.createElement("div");t.classList.add("og-watch-line"),t.innerHTML=`<div class="og-watch-label">${e.label}</div><div class="og-watch-value"></div>`,e.valEl=t.querySelector(".og-watch-value"),this.el.appendChild(t)}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.renderer.div),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this.el=document.createElement("div"),this.el.className="og-debug-info";let e=document.createElement("div");e.classList.add("og-debuginfo_controls"),this.el.appendChild(e);let t=this._watch;this._watch=[];for(let e=0;e<t.length;e++)this.addWatch(t[e]);this._dialog.container?.appendChild(this.el),this.renderer.events.on("draw",this._frame,this);let i=this.planet;i&&this.addWatches([{label:"Nodes count",frame:()=>i._renderedNodes.length},{label:"Planet._fadingNodes",frame:()=>i._fadingNodes.size},{label:"createdNodes",frame:()=>i._createdNodesCount},{label:"indexesCache",frame:()=>i._indexesCacheToRemoveCounter},{label:"distBeforeMemClear",frame:()=>Math.round(i._distBeforeMemClear)},{label:"maxZoom/minZoom",frame:()=>i.maxCurrZoom+" / "+i?.minCurrZoom},{label:"viewExtent",frame:()=>i.getViewExtent().toString()},{label:"height/alt (km)",frame:()=>`<div style="width:190px">${(i.camera._lonLat.height/1e3).toFixed(2)+" / "+(i.camera.getAltitude()/1e3).toFixed(2)}</div>`},{label:"cam.slope",frame:()=>i.camera.slope.toFixed(3)},{label:"lodSize",frame:()=>Math.round(i.lodSize)},{label:"deltaTime/FPS",frame:()=>`<div style="width:70px"><div style="width:20px; float: left;">\n ${Math.round(i.renderer.handler.deltaTime)}\n </div> <div style="float: left">\n ${Math.round(1e3/i.renderer.handler.deltaTime)}\n </div></div>`},{label:"-------------------------"},{label:"_renderCompleted / renderCompletedActivated",frame:()=>`${i._renderCompleted} / ${i._renderCompletedActivated}`},{label:"_terrainCompleted / terrainCompletedActivated",frame:()=>`${i._terrainCompleted} / ${i._terrainCompletedActivated}`},{label:"PlainWorker",frame:()=>i._plainSegmentWorker.pendingQueue.length},{label:"TileLoader",frame:()=>`${i._tileLoader.loading} ${i._tileLoader.queue.length}`},{label:"TerrainLoader",frame:()=>i.terrain&&!i.terrain.isEmpty?`${i.terrain.loader.loading} ${i.terrain.loader.queue.length}`:""},{label:"TerrainWorker",frame:()=>i._terrainWorker.pendingQueue.length},{label:"NormalMapCreator",frame:()=>i._normalMapCreator.queueSize},{label:"VectorTileCreator",frame:()=>i._vectorTileCreator.queueSize}]);let n=new Ot({classList:["og-debuginfo_controls-button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg fill="#000000" width="800px" height="800px" viewBox="-7.5 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">\n<title>lock</title>\n<path d="M14.625 15.156h2.094c0.281 0 0.5 0.25 0.5 0.531v11c0 0.281-0.219 0.5-0.5 0.5h-16.219c-0.281 0-0.5-0.219-0.5-0.5v-11c0-0.281 0.219-0.531 0.5-0.531h2.031v-5.125c0-2.875 1.844-5.25 4.688-5.25h2.688c2.875 0 4.719 2.375 4.719 5.25v5.125zM5.188 15.156h6.813v-4.875c0-1.594-1.313-2.938-2.938-2.938h-0.969c-1.594 0-2.906 1.344-2.906 2.938v4.875zM7.156 24h2.906l-0.719-3.156c0.5-0.25 0.844-0.781 0.844-1.375 0-0.906-0.719-1.594-1.594-1.594s-1.563 0.688-1.563 1.594c0 0.594 0.344 1.125 0.844 1.375z"></path>\n</svg>',title:"Lock/Unlock quad tree"});n.appendTo(e),n.events.on("change",(e=>{e?i.lockQuadTree():i.unlockQuadTree()}));let r=new Ot({classList:["og-debuginfo_controls-button"],icon:'<?xml version="1.0"?>\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">\n <path d="M 4 4 L 4 8 L 8 8 L 8 4 L 4 4 z M 10 4 L 10 8 L 14 8 L 14 4 L 10 4 z M 16 4 L 16 8 L 20 8 L 20 4 L 16 4 z M 4 10 L 4 14 L 8 14 L 8 10 L 4 10 z M 10 10 L 10 14 L 14 14 L 14 10 L 10 10 z M 16 10 L 16 14 L 20 14 L 20 10 L 16 10 z M 4 16 L 4 20 L 8 20 L 8 16 L 4 16 z M 10 16 L 10 20 L 14 20 L 14 16 L 10 16 z M 16 16 L 16 20 L 20 20 L 20 16 L 16 16 z"/>\n</svg>',title:"Show/Hide grid"});r.appendTo(e),r.events.on("change",(e=>{e?this.planet.addLayer(this._canvasTiles):this._canvasTiles.remove()}))}_frame(){this._watch.forEach((e=>{e.valEl&&(e.valEl.innerHTML=e.frame?String(e.frame()):"")}))}},DrawingControl:jn,DrawingSwitcher:class extends It{constructor(e={}){super({name:"DrawingSwitcher",...e}),this.drawingControl=new jn}oninit(){this.planet.addControl(this.drawingControl),this._createMenu()}onactivate(){this.drawingControl.activate()}ondeactivate(){this.drawingControl.deactivate()}_createMenu(){let e=new Ot({classList:["og-map-button","og-drawing-default_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M4 0l16 12.279-6.951 1.17 4.325 8.817-3.596 1.734-4.35-8.879-5.428 4.702z"/></svg>',name:"default",isActive:!0}),t=new Ot({classList:["og-map-button","og-drawing-polygon_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Generator: Adobe Illustrator 24.1.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) --\x3e\n<svg version="1.1" id="Layer_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"\n\t viewBox="0 0 1024 1024" style="enable-background:new 0 0 1024 1024;" xml:space="preserve">\n<g>\n\t<path d="M926.03,321.16c-16.02,0-31.11,3.94-44.48,10.79l-263.43-191.4c2.69-8.94,4.18-18.4,4.18-28.2\n\t\tc0-54.02-43.95-97.97-97.97-97.97c-54.03,0-97.98,43.95-97.98,97.97c0,9.81,1.49,19.27,4.18,28.21L155.75,340.18\n\t\tc-16.22-11.91-36.16-19.03-57.78-19.03C43.95,321.16,0,365.11,0,419.13c0,52.58,41.67,95.5,93.71,97.75l102.63,315.86\n\t\tc-24.28,17.85-40.13,46.52-40.13,78.9c0,54.02,43.95,97.98,97.98,97.98c37.54,0,70.18-21.25,86.62-52.34h367.26\n\t\tc16.44,31.08,49.08,52.34,86.63,52.34c54.03,0,97.98-43.95,97.98-97.98c0-32.46-15.94-61.21-40.33-79.05l104.11-320.4\n\t\tc39.15-12.84,67.54-49.68,67.54-93.07C1024,365.11,980.05,321.16,926.03,321.16z M828.05,911.65c0,8.5-3.3,16.19-8.55,22.09\n\t\tc-6.11,6.85-14.9,11.26-24.79,11.26c-13.65,0-25.37-8.26-30.52-20.02c-1.79-4.09-2.82-8.58-2.82-13.33\n\t\tc0-18.39,14.95-33.35,33.34-33.35c2.93,0,5.72,0.5,8.43,1.21c13.27,3.49,23.21,14.91,24.59,28.9\n\t\tC827.83,909.5,828.05,910.54,828.05,911.65z M790.48,813.89c-45.63,1.96-83.27,35.16-91.87,78.77H350.28\n\t\tc-8.62-43.69-46.38-76.93-92.11-78.79L155.59,498.19c24.41-17.84,40.36-46.59,40.36-79.06c0-8.9-1.3-17.49-3.53-25.7L468.57,192.8\n\t\tc15.84,11.01,35.05,17.52,55.76,17.52c20.71,0,39.92-6.5,55.76-17.52l256.56,186.4c-5.48,12.21-8.59,25.7-8.59,39.93\n\t\tc0,41.02,25.36,76.17,61.21,90.75L790.48,813.89z M254.19,945c-10.11,0-19.07-4.62-25.19-11.75c-5.01-5.84-8.15-13.32-8.15-21.6\n\t\tc0-0.91,0.2-1.76,0.27-2.66c1.14-14.18,11.08-25.8,24.43-29.41c2.78-0.75,5.64-1.28,8.65-1.28c18.38,0,33.33,14.96,33.33,33.35\n\t\tc0,4.74-1.03,9.24-2.82,13.33C279.55,936.74,267.83,945,254.19,945z M64.88,421.49c-0.06-0.79-0.24-1.55-0.24-2.35\n\t\tc0-16.41,11.93-30.01,27.55-32.76c1.89-0.33,3.8-0.58,5.78-0.58c11.94,0,22.35,6.36,28.24,15.81c3.18,5.11,5.11,11.09,5.11,17.53\n\t\tc0,15.47-10.63,28.39-24.94,32.14c-2.7,0.71-5.48,1.2-8.4,1.2C80.4,452.47,66.11,438.76,64.88,421.49z M549.41,90.62\n\t\tc5.07,5.85,8.25,13.39,8.25,21.72c0,7.32-2.44,14.03-6.45,19.54c-6.07,8.33-15.82,13.81-26.88,13.81\n\t\tc-11.07,0-20.83-5.48-26.89-13.81c-4.01-5.51-6.45-12.22-6.45-19.54c0-8.33,3.17-15.86,8.24-21.71\n\t\tc6.12-7.07,15.04-11.64,25.1-11.64C534.38,79,543.29,83.57,549.41,90.62z M959.36,419.13c0,11.94-6.36,22.35-15.82,28.24\n\t\tc-5.1,3.18-11.07,5.1-17.52,5.1c-6.08,0-11.71-1.76-16.62-4.61c-9.71-5.64-16.33-15.94-16.64-27.89c-0.01-0.29-0.09-0.56-0.09-0.85\n\t\tc0-11.75,6.14-22.05,15.36-28c5.2-3.35,11.35-5.35,17.99-5.35C944.41,385.78,959.36,400.75,959.36,419.13z"/>\n</g>\n</svg>',name:"polygon"}),i=new Ot({classList:["og-map-button","og-drawing-linestring_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- License: MIT. Made by Esri: https://github.com/Esri/calcite-ui-icons --\x3e\n <svg width="800px" height="800px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M21 6h.046l-5.25 9h-.944L10 9.455V7H7v2.926L1.862 18H0v3h3v-2.926L8.138 10h1.01L14 15.545V18h3v-3h-.046l5.25-9H24V3h-3zM8 8h1v1H8zM2 20H1v-1h1zm14-3h-1v-1h1zm7-13v1h-1V4z"/></svg>',name:"linestring"});new Qt({buttons:[e,t,i]}).events.on("change",(e=>{switch(this.drawingControl.deactivate(),e.name){case"polygon":this.drawingControl.activatePolygonDrawing();break;case"linestring":this.drawingControl.activateLineStringDrawing()}})),e.appendTo(this.renderer.div),t.appendTo(this.renderer.div),i.appendTo(this.renderer.div)}},EarthCoordinates:ar,EarthNavigation:lr,ElevationProfileControl:class extends It{constructor(e={}){super({name:"ElevationProfileControl",...e}),this._onSceneChange=()=>{this._collectProfileThrottled()},this._onElevationProfilePointer=(e,t,i,n,r,s,a,o)=>{let l=this._elevationProfileScene.getPointLonLat(s),h=this._elevationProfileScene.getPointLonLat(s+1),c=this.planet.ellipsoid.lonLatToCartesian(l),d=this.planet.ellipsoid.lonLatToCartesian(h),_=(e-t[0])/(i[0]-t[0]),u=d.sub(c);this._elevationProfileScene.setPointerCartesian3v(c.add(u.scale(_)),o)},this._onElevationProfileDblClick=(e,t,i,n,r,s,a,o)=>{let l=this._elevationProfileScene.getPointLonLat(s),h=this._elevationProfileScene.getPointLonLat(s+1),c=this.planet.ellipsoid.lonLatToCartesian(l),d=this.planet.ellipsoid.lonLatToCartesian(h),_=(e-t[0])/(i[0]-t[0]),u=d.sub(c),f=c.add(u.scale(_));this.planet.camera.flyDistance(f,this.planet.camera.eye.distance(f))},this._onElevationProfileMouseEnter=()=>{this._elevationProfileView.model.pointsReady&&this._elevationProfileScene.setPointerVisibility(!0)},this._onElevationProfileMouseLeave=()=>{},this._elevationProfileScene=new bs,this._elevationProfileView=new _s,this._elevationProfileLegend=new As,this._elevationProfileButtonsView=new Ts({model:this._elevationProfileView.model}),this._elevationProfileView.events.on("pointer",this._onElevationProfilePointer),this._elevationProfileView.events.on("dblclick",this._onElevationProfileDblClick),this._elevationProfileView.events.on("mouseenter",this._onElevationProfileMouseEnter),this._elevationProfileView.events.on("mouseleave",this._onElevationProfileMouseLeave),this._dialog=new Nt({title:"Elevation Profile",visible:!1,resizable:!0,useHide:!0,top:175,left:65,width:400,height:200,minHeight:100,minWidth:100}),this._graphView=new Bt({template:'<div class="og-elevationprofile__container">\n <div class="og-elevationprofile__menu"></div>\n <div class="og-elevationprofile__graph"></div>\n </div>'}),this._poiListDialog=new Ls({model:this._elevationProfileScene}),this._toggleBtn=new Ot({classList:["og-map-button","og-elevationprofile_button"],icon:'<svg style="width: 2em; height: 2em;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M128 896v-158.293333l331.946667-191.573334 160.853333 93.866667L896 480V896H128M896 381.44l-275.2 159.146667-160.853333-92.586667L128 640v-94.293333l331.946667-191.573334 160.853333 93.866667L896 288v93.44z" fill="" /></svg>'}),this._collectProfileThrottled=Fe((()=>{let e=this._elevationProfileScene.getPointsLonLat();this._elevationProfileView.model.collectProfile(e)}),250)}oninit(){this._dialog.appendTo(this.planet.renderer.div),this._graphView.appendTo(this._dialog.container),this._toggleBtn.appendTo(this.renderer.div),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e),e?(this.activate(),this._elevationProfileView.resize()):this.deactivate()})),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this._elevationProfileView.appendTo(this._graphView.select(".og-elevationprofile__graph")),this._elevationProfileView.model.bindPlanet(this.planet),this._elevationProfileView.model.events.on("clear",(()=>{this._elevationProfileScene.clear(),this._elevationProfileLegend.clear()})),this._elevationProfileView.model.events.on("startcollecting",(()=>{this._elevationProfileScene.setPointerVisibility(!1)})),this._elevationProfileView.events.on("tracklength",(e=>{this._elevationProfileLegend.setTrackLength(e)})),this._elevationProfileView.events.on("groundlength",(e=>{this._elevationProfileLegend.setGroundLength(e)})),this._elevationProfileView.events.on("warninglength",(e=>{this._elevationProfileLegend.setWarningLength(e)})),this._elevationProfileView.events.on("collisionlength",(e=>{this._elevationProfileLegend.setCollisionLength(e)})),this._poiListDialog.appendTo(this.planet.renderer.div),this._poiListDialog.events.on("visibility",(e=>{this._elevationProfileButtonsView.pointListBtn.setActive(e,!0)})),this._elevationProfileLegend.appendTo(this._graphView.select(".og-elevationprofile__menu")),this._elevationProfileButtonsView.appendTo(this._graphView.select(".og-elevationprofile__menu")),this._elevationProfileButtonsView.events.on("list",(e=>{this._poiListDialog.setVisibility(e)})),this._elevationProfileButtonsView.events.on("location",(e=>{this._elevationProfileScene.flyExtent()})),this._elevationProfileButtonsView.events.on("reset",(e=>{this._elevationProfileScene.setPointerVisibility(!1)})),this._elevationProfileScene.events.on("change",this._onSceneChange)}onactivate(){this.renderer.controls.mouseNavigation.deactivateDoubleClickZoom(),this.planet&&this._elevationProfileScene.bindPlanet(this.planet),this.renderer&&this.renderer.addNode(this._elevationProfileScene)}ondeactivate(){this._poiListDialog.setVisibility(!1),this._elevationProfileView.model.clear(),this.renderer.controls.mouseNavigation.activateDoubleClickZoom(),this.renderer&&this.renderer.removeNode(this._elevationProfileScene),this._dialog.hide()}},GeoImageDragControl:class extends It{constructor(e={}){super(e),this._cornerIndex=-1,this._catchCorner=!1,this._toggleBtn=new Ot({classList:["og-map-button","og-geoimagegrag_button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M16 13l6.964 4.062-2.973.85 2.125 3.681-1.732 1-2.125-3.68-2.223 2.15L16 13zm-2-7h2v2h5a1 1 0 0 1 1 1v4h-2v-3H10v10h4v2H9a1 1 0 0 1-1-1v-5H6v-2h2V9a1 1 0 0 1 1-1h5V6zM4 14v2H2v-2h2zm0-4v2H2v-2h2zm0-4v2H2V6h2zm0-4v2H2V2h2zm4 0v2H6V2h2zm4 0v2h-2V2h2zm4 0v2h-2V2h2z" fill="#000"/></svg>'})}oninit(){this._toggleBtn.appendTo(this.renderer.div),this.planet.events.on("layeradd",(e=>{this.isActive()&&this._bindLayer(e)}),this),this._toggleBtn.events.on("change",(e=>{e?this.activate():this.deactivate()}))}onactivate(){super.onactivate();const e=this.planet;for(let t=0;t<e.layers.length;t++)this._bindLayer(e.layers[t])}ondeactivate(){super.ondeactivate();const e=this.planet;for(let t=0;t<e.layers.length;t++)this._unbindLayer(e.layers[t])}_bindLayer(e){e instanceof cr&&(e.events.on("mousemove",this._onMouseMove,this),e.events.on("mouseleave",this._onMouseLeave,this),e.events.on("ldown",this._onLDown,this),e.events.on("lup",this._onLUp,this))}_unbindLayer(e){e instanceof cr&&(e.events.off("mousemove",this._onMouseMove),e.events.off("mouseleave",this._onMouseLeave),e.events.off("ldown",this._onLDown),e.events.off("lup",this._onLUp))}_onLUp(e){this._catchCorner=!1,e.renderer.controls.mouseNavigation.activate()}_onLDown(e){-1!==this._cornerIndex&&(this._catchCorner=!0,e.renderer.controls.mouseNavigation.deactivate())}_onMouseLeave(){document.body.style.cursor="auto"}_onMouseMove(e){let t=e.pickingObject;const i=this.planet;if(this._catchCorner){let n=t.getCornersLonLat();n[this._cornerIndex]=i.getLonLatFromPixelTerrain(e),t.setCornersLonLat(n)}else{this._cornerIndex=-1;for(let n=0;n<t._cornersWgs84.length;n++){let r=i.getLonLatFromPixelTerrain(e);if(r&&i.ellipsoid.getGreatCircleDistance(t._cornersWgs84[n],r)/i.getDistanceFromPixel(e)<=.05){this._cornerIndex=n,document.body.style.cursor="move";break}document.body.style.cursor="auto"}}}},HeightRuler:Ir,KeyboardNavigation:class extends It{constructor(e={}){e=e||{},super({name:"KeyboardNavigation",...e}),this.step=e.step||250}onactivate(){let e=this.renderer;e.events.on("keypress",dr.KEY_PGUP,this.onCameraMoveForward,this),e.events.on("keypress",dr.KEY_PGDN,this.onCameraMoveBackward,this),e.events.on("keypress",dr.KEY_PLUS,this.onCameraMoveForward,this),e.events.on("keypress",dr.KEY_EQUALS,this.onCameraMoveForward,this),e.events.on("keypress",dr.KEY_MINUS,this.onCameraMoveBackward,this),e.events.on("keypress",dr.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",dr.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",dr.KEY_A,this.onCameraStrifeLeft,this),e.events.on("keypress",dr.KEY_D,this.onCameraStrifeRight,this),e.events.on("keypress",dr.KEY_UP,this.onCameraLookUp,this),e.events.on("keypress",dr.KEY_DOWN,this.onCameraLookDown,this),e.events.on("keypress",dr.KEY_LEFT,this.onCameraLookLeft,this),e.events.on("keypress",dr.KEY_RIGHT,this.onCameraLookRight,this),e.events.on("keypress",dr.KEY_Q,this.onCameraRollLeft,this),e.events.on("keypress",dr.KEY_E,this.onCameraRollRight,this),e.events.on("keypress",dr.KEY_N,this.onCameraRollNorth,this)}ondeactivate(){let e=this.renderer;e.events.off("keypress",dr.KEY_PGUP,this.onCameraMoveForward),e.events.off("keypress",dr.KEY_PGDN,this.onCameraMoveBackward),e.events.off("keypress",dr.KEY_PLUS,this.onCameraMoveForward),e.events.off("keypress",dr.KEY_EQUALS,this.onCameraMoveForward),e.events.off("keypress",dr.KEY_MINUS,this.onCameraMoveBackward),e.events.off("keypress",dr.KEY_W,this.onCameraMoveForward),e.events.off("keypress",dr.KEY_S,this.onCameraMoveBackward),e.events.off("keypress",dr.KEY_A,this.onCameraStrifeLeft),e.events.off("keypress",dr.KEY_D,this.onCameraStrifeRight),e.events.off("keypress",dr.KEY_UP,this.onCameraLookUp),e.events.off("keypress",dr.KEY_DOWN,this.onCameraLookDown),e.events.off("keypress",dr.KEY_LEFT,this.onCameraLookLeft),e.events.off("keypress",dr.KEY_RIGHT,this.onCameraLookRight),e.events.off("keypress",dr.KEY_Q,this.onCameraRollLeft),e.events.off("keypress",dr.KEY_E,this.onCameraRollRight),e.events.off("keypress",dr.KEY_N,this.onCameraRollNorth)}oninit(){this.activate()}onCameraMoveForward(){let e=this.planet.camera;e.slide(0,0,-e.getAltitude()/this.step)}onCameraMoveBackward(){let e=this.planet.camera;e.slide(0,0,e.getAltitude()/this.step)}onCameraStrifeLeft(){let e=this.planet.camera;e.slide(-e.getAltitude()/this.step,0,0)}onCameraStrifeRight(){let e=this.planet.camera;e.slide(e.getAltitude()/this.step,0,0)}onCameraLookUp(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.pitch(15/this.renderer.handler.deltaTime):e.rotateVertical(e.getAltitude()/3e6*o,oe.ZERO)}onCameraLookDown(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.pitch(-15/this.renderer.handler.deltaTime):e.rotateVertical(-e.getAltitude()/3e6*o,oe.ZERO)}onCameraLookLeft(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.roll(15/this.renderer.handler.deltaTime):e.rotateHorizontal(e.getAltitude()/3e6*o)}onCameraLookRight(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.roll(-15/this.renderer.handler.deltaTime):e.rotateHorizontal(-e.getAltitude()/3e6*o)}onCameraTurnLeft(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.yaw(15/this.renderer.handler.deltaTime):e.rotateHorizontal(e.getAltitude()/3e6*o)}onCameraTurnRight(){let e=this.planet.camera;this.renderer.events.isKeyPressed(dr.KEY_SHIFT)?e.yaw(-15/this.renderer.handler.deltaTime):e.rotateHorizontal(-e.getAltitude()/3e6*o,!1,oe.ZERO)}onCameraRollNorth(){let e=this.planet.getCartesianFromPixelTerrain(this.renderer.handler.getCenter());e?this.planet.flyCartesian(e.normal().scaleTo(e.length()+e.distance(this.planet.camera.eye)),null,null,0,null,null,(()=>{this.planet.camera.look})):this.planet.flyCartesian(this.planet.camera.eye)}onCameraRollLeft(){this.planet.camera.roll(-15/this.renderer.handler.deltaTime)}onCameraRollRight(){this.planet.camera.roll(15/this.renderer.handler.deltaTime)}},LayerAnimation:class extends It{constructor(e={}){super(e),this._currVisibleIndex=0,this._onViewchange=()=>{this._timeoutStart=performance.now()},this._onVisibilityChange=e=>{e||this.pause()},this._onLayerLoadend=e=>{let t=this._layersArr[this._currentIndex];if(t&&t.isEqual(e)){let e=this._getFrameIndex(this._currentIndex)*this._frameSize,i=this._currentIndex;for(let t=e;t<i;t++){let e=this._layersArr[t];e.opacity=0,e.setVisibility(!1)}t.opacity=1;let n=this._layersArr[this._currVisibleIndex];if(n){n.opacity=0,n.setVisibility(!1);let e=this._getFrameIndex(this._currVisibleIndex);this._getFrameIndex(this._currentIndex)!==e&&this._removeFrameFromPlanet(e)}this.events.dispatch(this.events.idle,t)}},this.events=Pt(_r),this._name=e.name||`layerAnimation-${this.__id}`,this._layersArr=e.layers?[].concat(e.layers):[],this._currentIndex=-1,this._playInterval=e.playInterval||120,this._playIntervalHandler=-1,this._playIndex=0,this._frameSize=e.frameSize||50,this.repeat=null==e.repeat||e.repeat,this.skipTimeout=e.skipTimeout||5e3,this._timeoutStart=0}_getFramesNum(){return Math.ceil(this._layersArr.length/this._frameSize)}_setFrame(e){for(let t=0,i=this._getFramesNum();t<i;t++)t!==e?this._removeFrameFromPlanet(t):this._appendFrameToPlanet(t)}_getFrameIndex(e){return Math.floor(e/this._frameSize)}_appendFrameToPlanet(e){if(this.planet){let t=e*this._frameSize,i=t+this._frameSize;for(let e=t,n=i>this._layersArr.length?this._layersArr.length:i;e<n;e++)this.planet.addLayer(this._layersArr[e])}}_removeFrameFromPlanet(e){if(this.planet){let t=e*this._frameSize,i=t+this._frameSize;for(let e=t,n=i>this._layersArr.length?this._layersArr.length:i;e<n;e++)this._layersArr[e].abortLoading(),this._layersArr[e].remove(),this._layersArr[e].setVisibility(!1)}}oninit(){super.oninit(),this.onactivate(),this._initLayers(),this.planet.events.on("layerloadend",this._onLayerLoadend),this._setCurrentIndexAsync(0,!1,!0)}onactivate(){super.onactivate(),this.planet.camera.events.on("viewchange",this._onViewchange),this.planet.renderer.handler.events.on("visibilitychange",this._onVisibilityChange)}ondeactivate(){super.ondeactivate(),this.planet.camera.events.off("viewchange",this._onViewchange);for(let e=0;e<this._layersArr.length;e++)this._layersArr[e].setVisibility(!1);this.planet.events.off("layerloadend",this._onLayerLoadend),this.planet.renderer.handler.events.off("visibilitychange",this._onVisibilityChange)}clear(){this.stop(),this._currentIndex=-1,this._currVisibleIndex=-1;let e=this._layersArr;this._layersArr=[];for(let t=0;t<e.length;t++)e[t].remove()}_initLayers(){if(this.planet){for(let e=0,t=this._layersArr.length;e<t;e++){let t=this._layersArr[e];t.setVisibility(!1),t.setBaseLayer(!1),t.opacity=0}this._appendFrameToPlanet(0)}}setLayers(e){this.clear(),this._layersArr=[].concat(e),this._initLayers()}appendLayer(e){this._layersArr.push(e),e.setVisibility(!1),e.setBaseLayer(!1),e.opacity=0,this.planet?.addLayer(e)}get isIdle(){let e=this._layersArr[this._currentIndex];return e&&e.isIdle||!e}get playInterval(){return this._playInterval}set playInterval(e){e!==this._playInterval&&(this._playInterval=e,this.isPlaying&&(this.pause(),this.play()))}get isPlaying(){return-1!==this._playIntervalHandler}get layers(){return this._layersArr}_checkEnd(){this._playIndex>this._layersArr.length&&(this.repeat?this._playIndex=0:this.pause())}play(){this.isPlaying||(this._currentIndex>=this._layersArr.length-1&&this.stop(),this._timeoutStart=performance.now(),this._playIntervalHandler=setInterval((()=>{this._checkEnd(),this._setCurrentIndexAsync(this._playIndex,!1,!1),requestAnimationFrame((()=>{(this.isIdle||performance.now()-this._timeoutStart>this.skipTimeout)&&(this._playIndex++,this._timeoutStart=performance.now())}))}),this._playInterval),this.events.dispatch(this.events.play))}stop(){this._playIndex>0&&(this._clearInterval(),this._playIndex=0,this.setCurrentIndex(0),this.events.dispatch(this.events.stop))}pause(){this.isPlaying&&(this._clearInterval(),this.events.dispatch(this.events.pause))}_clearInterval(){clearInterval(this._playIntervalHandler),this._playIntervalHandler=-1}setCurrentIndex(e,t=!1){this._setCurrentIndexAsync(e,!0,t)}_setCurrentIndexAsync(e,t=!1,i=!1){if(e!=this._currentIndex&&e>=0&&e<this._layersArr.length){let n=this._currentIndex;this._currentIndex=e,this._playIndex=e;let r=this._getFrameIndex(n),s=this._getFrameIndex(this._currentIndex),a=this._layersArr[n],o=this._layersArr[e],l=s!=r;l&&this._appendFrameToPlanet(s),a&&(a.isIdle?this._currVisibleIndex=n:(a.opacity=0,a.setVisibility(!1))),o&&(o.opacity=0,o.setVisibility(!0),requestAnimationFrame((()=>{if(o.isIdle||t){o.opacity=1,l&&this._removeFrameFromPlanet(r),a&&(a.opacity=0,a.setVisibility(!1));let e=this._layersArr[this._currVisibleIndex];e&&(e.opacity=0,e.setVisibility(!1))}})),i||this.events.dispatch(this.events.change,this._currentIndex,n))}}},LayerSwitcher:class extends It{constructor(e={}){super({name:"LayerSwitcher",...e}),this.addLayer=e=>{if(!e.hideInLayerSwitcher){let t=this._createLayerButton(e);this._layerViews.push(t),e.isBaseLayer()?t.appendTo(this.$baseLayers):t.appendTo(this.$overlays)}},this.removeLayer=e=>{for(let t=0;t<this._layerViews.length;t++){let i=this._layerViews[t];if(i.model.isEqual(e)){i.remove(),this._layerViews.splice(t,1);break}}},this._dialog=new Nt({title:"Layer Switcher",top:15,useHide:!0,visible:!1,width:300,maxHeight:500}),this._panel=new Bt({template:'<div class="og-layerSwitcher">\n <div class="og-layerSwitcher__title">Base Layers</div>\n <div class="og-layerSwitcher__list og-layerSwitcher__baseLayers"></div> \n \n <div class="og-layerSwitcher__title">Overlays</div>\n <div class="og-layerSwitcher__list og-layerSwitcher__overlays"></div>\n \n </div>'}),this._toggleBtn=new Ot({classList:["og-map-button","og-layerSwitcher_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">\n<metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n<g><path d="M500,573.5c-3.2,0-6.5-0.6-9.5-1.9L25,375.6c-9.1-3.8-15-12.7-15-22.6s5.9-18.8,15-22.6l465.5-196c6.1-2.5,12.9-2.5,19,0l465.5,196c9.1,3.8,15,12.7,15,22.6s-5.9,18.8-15,22.6l-465.5,196C506.5,572.9,503.2,573.5,500,573.5L500,573.5z M97.6,353L500,522.4L902.4,353L500,183.6L97.6,353L97.6,353z"/><path d="M500,720.5c-3.2,0-6.5-0.6-9.5-1.9L25,522.6c-12.4-5.2-18.3-19.6-13.1-32.1c5.2-12.5,19.6-18.3,32.1-13.1l456,192l456-192c12.4-5.2,26.9,0.6,32.1,13.1s-0.6,26.9-13.1,32.1l-465.5,196C506.5,719.9,503.2,720.5,500,720.5L500,720.5z"/><path d="M500,867.5c-3.2,0-6.5-0.6-9.5-1.9L25,669.6c-12.4-5.2-18.3-19.6-13.1-32.1c5.2-12.5,19.6-18.3,32.1-13.1l456,192l456-192c12.4-5.2,26.9,0.6,32.1,13.1c5.2,12.5-0.6,26.8-13.1,32.1l-465.5,196C506.5,866.9,503.2,867.5,500,867.5L500,867.5z"/></g>\n</svg>'}),this.$baseLayers=null,this.$overlays=null,this._layerViews=[]}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.planet.renderer.div),this._panel.appendTo(this._dialog.container),this.$baseLayers=this._panel.el.querySelector(".og-layerSwitcher__baseLayers"),this.$overlays=this._panel.el.querySelector(".og-layerSwitcher__overlays"),this._dialog.setPosition(this.planet.renderer.div.clientWidth-this._dialog.width-67),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this.planet.events.on("layeradd",this.addLayer,this),this.planet.events.on("layerremove",this.removeLayer,this),this._initLayers()}_initLayers(){let e=this.planet.layers;for(let t=0;t<e.length;t++)this.addLayer(e[t])}_createLayerButton(e){return new ur({model:e})}onactivate(){}ondeactivate(){this._dialog.hide()}},Lighting:class extends It{constructor(e={}){super(e),this._selectedLayer=null,this._toggleBtn=new Ot({classList:["og-map-button","og-lighting_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">\n\n<defs>\n</defs>\n<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; opacity: 1;" transform="translate(1.4065934065934016 1.4065934065934016) scale(2.81 2.81)" >\n\t<path d="M 45 68 c -12.682 0 -23 -10.317 -23 -23 c 0 -12.682 10.318 -23 23 -23 c 12.683 0 23 10.318 23 23 C 68 57.683 57.683 68 45 68 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 45 17.556 c -1.657 0 -3 -1.343 -3 -3 V 3 c 0 -1.657 1.343 -3 3 -3 c 1.657 0 3 1.343 3 3 v 11.556 C 48 16.212 46.657 17.556 45 17.556 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 45 90 c -1.657 0 -3 -1.343 -3 -3 V 75.444 c 0 -1.657 1.343 -3 3 -3 c 1.657 0 3 1.343 3 3 V 87 C 48 88.657 46.657 90 45 90 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 14.556 48 H 3 c -1.657 0 -3 -1.343 -3 -3 c 0 -1.657 1.343 -3 3 -3 h 11.556 c 1.657 0 3 1.343 3 3 C 17.556 46.657 16.212 48 14.556 48 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 87 48 H 75.444 c -1.657 0 -3 -1.343 -3 -3 c 0 -1.657 1.343 -3 3 -3 H 87 c 1.657 0 3 1.343 3 3 C 90 46.657 88.657 48 87 48 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 66.527 26.473 c -0.768 0 -1.535 -0.293 -2.121 -0.878 c -1.172 -1.172 -1.172 -3.071 0 -4.243 l 8.171 -8.171 c 1.172 -1.172 3.07 -1.171 4.242 0 c 1.172 1.172 1.172 3.071 0 4.243 l -8.171 8.171 C 68.063 26.18 67.295 26.473 66.527 26.473 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 15.302 77.698 c -0.768 0 -1.536 -0.293 -2.121 -0.879 c -1.172 -1.171 -1.172 -3.071 0 -4.242 l 8.171 -8.171 c 1.171 -1.172 3.071 -1.172 4.242 0 c 1.172 1.171 1.172 3.071 0 4.242 l -8.171 8.171 C 16.837 77.405 16.069 77.698 15.302 77.698 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 23.473 26.473 c -0.768 0 -1.536 -0.293 -2.121 -0.878 l -8.171 -8.171 c -1.172 -1.172 -1.172 -3.071 0 -4.243 c 1.172 -1.172 3.072 -1.171 4.243 0 l 8.171 8.171 c 1.172 1.172 1.172 3.071 0 4.243 C 25.008 26.18 24.24 26.473 23.473 26.473 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 74.698 77.698 c -0.768 0 -1.535 -0.293 -2.121 -0.879 l -8.171 -8.171 c -1.172 -1.171 -1.172 -3.071 0 -4.242 c 1.172 -1.172 3.07 -1.172 4.242 0 l 8.171 8.171 c 1.172 1.171 1.172 3.071 0 4.242 C 76.233 77.405 75.466 77.698 74.698 77.698 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n</g>\n</svg>'}),this._dialog=new Nt({title:"Lighting Parameters",visible:!1,useHide:!0,top:60,left:60,width:600}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._panel=new Bt({template:'<div class="og-lighing og-options-container">\n\n <div class="og-option">\n <div class="og-suncontrol"></div>\n </div> \n \n <div class="og-option og-atmosphere-opacity">\n </div>\n \n <div class="og-option og-simpleskybackground">\n </div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option og-gamma"></div> \n <div class="og-option og-exposure"></div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option">\n <div class="og-layers">\n <div class="og-caption">Select layer:</div>\n <select id="layers"></select>\n </div>\n </div>\n\n <div class="og-option og-opacity">\n </div>\n \n <div class="og-option og-night">\n </div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option og-diffuse">\n </div>\n \n <div class="og-option og-ambient">\n </div>\n\n <div class="og-option og-specular">\n </div> \n\n </div>'}),this.$gamma=null,this.$exposure=null,this.$night=null,this.$opacity=null,this.$diffuse=null,this.$ambient=null,this.$specular=null,this.$atmosphereOpacity=null,this.$simpleSkyBackground=null,this._atmosphereMaxOpacity=new gr({label:"Max.opacity",max:5}),this._atmosphereMinOpacity=new gr({label:"Min.opacity",max:5}),this._simpleSkyBackgroundColorOne=new vr({label:"Color One"}),this._simpleSkyBackgroundColorTwo=new vr({label:"Color Two"}),this._gamma=new gr({label:"Gamma",max:5}),this._exposure=new gr({label:"Exposure",max:5}),this._night=new gr({label:"Nightlight",max:5}),this._opacity=new gr({label:"Opacity",max:1}),this._diffuse_r=new gr({label:"Diffuse R",max:5}),this._diffuse_g=new gr({label:"Diffuse G",max:5}),this._diffuse_b=new gr({label:"Diffuse B",max:5}),this._ambient_r=new gr({label:"Ambient R",max:5}),this._ambient_g=new gr({label:"Ambient G",max:5}),this._ambient_b=new gr({label:"Ambient B",max:5}),this._specular_r=new gr({label:"Specular R",max:.2}),this._specular_g=new gr({label:"Specular G",max:.2}),this._specular_b=new gr({label:"Specular B",max:.2}),this._shininess=new gr({label:"Shininess",max:100})}bindLayer(e){this._selectedLayer=e,this._opacity.value=e.opacity,this._update()}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.renderer.div),this._panel.appendTo(this._dialog.container),this._panel.el&&(this.$atmosphereOpacity=this._panel.el.querySelector(".og-atmosphere-opacity"),this.$simpleSkyBackground=this._panel.el.querySelector(".og-simpleskybackground"),this.$gamma=this._panel.el.querySelector(".og-option.og-gamma"),this.$exposure=this._panel.el.querySelector(".og-option.og-exposure"),this.$opacity=this._panel.el.querySelector(".og-option.og-opacity"),this.$diffuse=this._panel.el.querySelector(".og-option.og-diffuse"),this.$ambient=this._panel.el.querySelector(".og-option.og-ambient"),this.$specular=this._panel.el.querySelector(".og-option.og-specular"),this.$night=this._panel.el.querySelector(".og-option.og-night")),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)}));let e=this._dialog.select(".og-suncontrol"),t=new Ot({classList:["og-suncontrol-button"],isActive:!0,icon:'<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 122.88 70.41" style="enable-background:new 0 0 122.88 70.41" xml:space="preserve"><g><path d="M60.91,19.12c6.95,0,13.24,2.95,17.8,7.72c4.55,4.77,7.37,11.37,7.37,18.64c0,1.94-0.2,3.83-0.58,5.65h31.61 c2.1,0,2.62,1.16,2.62,2.59c0,1.43-0.52,2.59-2.62,2.59H7.09c-2.1,0-2.62-1.16-2.62-2.59c0-1.43,0.52-2.59,2.62-2.59h29.23 c-0.38-1.82-0.58-3.71-0.58-5.65c0-7.28,2.82-13.87,7.37-18.64C47.67,22.08,53.96,19.12,60.91,19.12L60.91,19.12L60.91,19.12z M63.4,70.41c-2.1,0-2.62-1.16-2.62-2.59s0.52-2.59,2.62-2.59h56.86c2.1,0,2.62,1.16,2.62,2.59s-0.52,2.59-2.62,2.59H63.4 L63.4,70.41z M2.62,70.41c-2.1,0-2.62-1.16-2.62-2.59s0.52-2.59,2.62-2.59h29.51c2.1,0,2.62,1.16,2.62,2.59s-0.52,2.59-2.62,2.59 H2.62L2.62,70.41z M38.39,9.46c-0.78-1.35-0.32-3.07,1.03-3.85c1.35-0.78,3.07-0.32,3.85,1.03l3.62,6.27 c0.78,1.35,0.32,3.07-1.03,3.85c-1.35,0.78-3.07,0.32-3.85-1.03L38.39,9.46L38.39,9.46L38.39,9.46z M58.67,2.83 c0-1.56,1.27-2.83,2.83-2.83c1.56,0,2.83,1.27,2.83,2.83v7.24c0,1.56-1.27,2.83-2.83,2.83c-1.56,0-2.83-1.26-2.83-2.83V2.83 L58.67,2.83L58.67,2.83z M79.56,7.23c0.77-1.35,2.49-1.81,3.84-1.04c1.35,0.77,1.81,2.49,1.04,3.84l-3.62,6.27 c-0.77,1.35-2.49,1.81-3.84,1.04c-1.35-0.77-1.81-2.49-1.04-3.84L79.56,7.23L79.56,7.23L79.56,7.23z M95.45,21.48 c1.35-0.78,3.07-0.32,3.85,1.03c0.78,1.35,0.32,3.07-1.03,3.85L92,29.98c-1.35,0.78-3.07,0.32-3.85-1.03 c-0.78-1.35-0.32-3.07,1.03-3.85L95.45,21.48L95.45,21.48L95.45,21.48z M102.08,41.76c1.56,0,2.83,1.27,2.83,2.83 c0,1.56-1.27,2.83-2.83,2.83h-7.24c-1.56,0-2.83-1.26-2.83-2.83s1.26-2.83,2.83-2.83H102.08L102.08,41.76L102.08,41.76z M19.74,46.25c-1.56,0-2.83-1.27-2.83-2.83c0-1.56,1.27-2.83,2.83-2.83h7.24c1.56,0,2.83,1.26,2.83,2.83s-1.27,2.83-2.83,2.83 H19.74L19.74,46.25L19.74,46.25z M24.14,25.35c-1.35-0.77-1.81-2.49-1.04-3.84c0.77-1.35,2.49-1.81,3.84-1.04l6.27,3.62 c1.35,0.77,1.81,2.49,1.04,3.84c-0.77,1.35-2.49,1.81-3.84,1.04L24.14,25.35L24.14,25.35L24.14,25.35z"/></g></svg>',title:"Star/stop the Sun from following the camera"});t.appendTo(e);let i=new Ot({classList:["og-suncontrol-button"],isActive:!0,icon:'<?xml version="1.0"?>\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">\n <path style="text-indent:0;text-align:start;line-height:normal;text-transform:none;block-progression:tb;-inkscape-font-specification:Sans" d="M 16 4 C 9.3844277 4 4 9.3844277 4 16 C 4 22.615572 9.3844277 28 16 28 C 22.615572 28 28 22.615572 28 16 C 28 9.3844277 22.615572 4 16 4 z M 16 6 C 16.389823 6 16.778223 6.0506339 17.15625 6.09375 C 18.631659 7.6568432 21 10.9245 21 16 C 21 21.0755 18.631659 24.343157 17.15625 25.90625 C 16.778223 25.949366 16.389823 26 16 26 C 10.465308 26 6 21.534692 6 16 C 6 10.465308 10.465308 6 16 6 z" overflow="visible" font-family="Sans"/>\n</svg>\n',title:"Activate/deactivate the Sun current time positioning"});i.appendTo(e),t.events.on("change",(e=>{const t=this.planet.renderer.controls.sun;e?t.start():t.stop()})),i.events.on("change",(e=>{const t=this.planet.renderer.controls.sun;e?t.activate():t.deactivate()}));let n=new Ot({classList:["og-suncontrol-button"],isActive:this.planet.lightEnabled,icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Generated by IcoMoon.io --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="512" height="512" viewBox="0 0 512 512">\n<g>\n</g>\n\t<path d="M257.894 156.948c-53.258 0-96.42 43.561-96.42 97.26 0 53.719 43.161 97.249 96.42 97.249 53.197 0 96.379-43.53 96.379-97.25 0-53.698-43.182-97.26-96.379-97.26zM257.894 309.873c-30.464 0-55.163-24.945-55.163-55.665s24.699-55.624 55.163-55.624c30.423 0 55.101 24.904 55.101 55.624s-24.688 55.665-55.101 55.665z" fill="#000000" />\n\t<path d="M241.808 43.499h32.144v79.575h-32.144v-79.575z" fill="#000000" />\n\t<path d="M417.209 115.897l-22.723-22.917-55.757 56.279 22.723 22.907z" fill="#000000" />\n\t<path d="M389.468 238.407h78.899v32.389h-78.899v-32.389z" fill="#000000" />\n\t<path d="M396.012 416.86l22.723-22.917-55.767-56.259-22.712 22.897z" fill="#000000" />\n\t<path d="M242.473 388.915h32.144v79.575h-32.144v-79.575z" fill="#000000" />\n\t<path d="M96.266 396.073l22.722 22.938 55.778-56.289-22.692-22.928z" fill="#000000" />\n\t<path d="M43.633 240.537h78.879v32.43h-78.879v-32.43z" fill="#000000" />\n\t<path d="M115.394 93.051l-22.681 22.907 55.757 56.258 22.702-22.917z" fill="#000000" />\n</svg>',title:"Enable/disable planet lighting"});n.appendTo(e),n.events.on("change",(e=>{this.planet.lightEnabled=e}));let r=new Ot({classList:["og-suncontrol-button"],isActive:this.planet.atmosphereEnabled,icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg width="800px" height="800px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path fill="#000000" d="M135.688 18.5c-6.798 74.842-23.842 85.39-107.907 59.656 84.85 52.022 73.57 64.954-6.843 96.938 87.743-10.27 103.29 4.89 70.75 87.594 17.805-27.56 32.5-44.498 46.282-54.47-11.813 28.26-18.345 59.274-18.345 91.813 0 84.184 43.71 157.96 109.656 200.376-41.624-43.834-67.686-102.7-67.686-167.875 0-134.923 109.45-244.405 244.375-244.405 30.92 0 60.76 5.762 88 16.25-38.584-26.87-85.517-42.625-136.064-42.625-55.257 0-106.14 18.802-146.562 50.375 4.627-18.783 17.39-38.073 41.03-60.906C190.18 90.942 153.53 95.634 135.69 18.5zm10.03 77.188c5.67.002 11.428 1.247 16.876 3.874 14.506 6.998 22.72 21.81 22 36.938-10.26 10.87-19.507 22.696-27.594 35.344-9.035 2.753-19.075 2.27-28.25-2.156-19.37-9.343-27.5-32.6-18.156-51.97 6.715-13.92 20.638-22.036 35.125-22.03z"/></svg>',title:"Enable/disable atmosphere scattering"});r.appendTo(e),this.planet.atmosphereEnabled?(this.$atmosphereOpacity.style.display="block",this.$simpleSkyBackground.style.display="none"):(this.$atmosphereOpacity.style.display="none",this.$simpleSkyBackground.style.display="flex"),r.events.on("change",(e=>{this.planet.atmosphereEnabled=e,this.planet.atmosphereEnabled?(this.$atmosphereOpacity.style.display="block",this.$simpleSkyBackground.style.display="none"):(this.$atmosphereOpacity.style.display="none",this.$simpleSkyBackground.style.display="flex")})),this._atmosphereMaxOpacity.appendTo(this.$atmosphereOpacity),this._atmosphereMinOpacity.appendTo(this.$atmosphereOpacity),this._simpleSkyBackgroundColorOne.appendTo(this.$simpleSkyBackground),this._simpleSkyBackgroundColorTwo.appendTo(this.$simpleSkyBackground),this._gamma.appendTo(this.$gamma),this._exposure.appendTo(this.$exposure),this._night.appendTo(this.$night),this._opacity.appendTo(this.$opacity),this._diffuse_r.appendTo(this.$diffuse),this._diffuse_g.appendTo(this.$diffuse),this._diffuse_b.appendTo(this.$diffuse),this._ambient_r.appendTo(this.$ambient),this._ambient_g.appendTo(this.$ambient),this._ambient_b.appendTo(this.$ambient),this._specular_r.appendTo(this.$specular),this._specular_g.appendTo(this.$specular),this._specular_b.appendTo(this.$specular),this._shininess.appendTo(this.$specular),this._gamma.value=this.planet.renderer.gamma,this._gamma.events.on("change",(e=>{this.planet.renderer.gamma=e})),this._exposure.value=this.planet.renderer.exposure,this._exposure.events.on("change",(e=>{this.planet.renderer.exposure=e})),this._atmosphereMinOpacity.value=this.planet.atmosphereMinOpacity,this._atmosphereMinOpacity.events.on("change",(e=>{this.planet.atmosphereMinOpacity=e})),this._atmosphereMaxOpacity.value=this.planet.atmosphereMaxOpacity,this._atmosphereMaxOpacity.events.on("change",(e=>{this.planet.atmosphereMaxOpacity=e,this.planet.renderer.controls.Atmosphere.opacity=e}));let s=this.planet.renderer.controls.SimpleSkyBackground;s&&(this._simpleSkyBackgroundColorOne.value=s.colorOne,this._simpleSkyBackgroundColorTwo.value=s.colorTwo),this._simpleSkyBackgroundColorOne.events.on("input",(e=>{let t=this.planet.renderer.controls.SimpleSkyBackground;t&&(t.colorOne=e)})),this._simpleSkyBackgroundColorTwo.events.on("input",(e=>{let t=this.planet.renderer.controls.SimpleSkyBackground;t&&(t.colorTwo=e)})),this._panel.el.querySelector("#layers").addEventListener("change",(e=>{const t=this.planet.getLayerByName(e.target.value);t&&this.bindLayer(t)})),this._night.events.on("change",(e=>{this._selectedLayer&&(this._selectedLayer.nightTextureCoefficient=e)})),this._opacity.events.on("change",(e=>{this._selectedLayer&&(this._selectedLayer.opacity=e)})),this._ambient_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[0]=e)})),this._ambient_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[1]=e)})),this._ambient_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[2]=e)})),this._diffuse_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[0]=e)})),this._diffuse_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[1]=e)})),this._diffuse_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[2]=e)})),this._specular_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[0]=e)})),this._specular_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[1]=e)})),this._specular_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[2]=e)})),this._shininess.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[3]=e)})),this.planet&&(this.planet.events.on("layeradd",this._onLayerAdd,this),this.planet.events.on("layerremove",this._onLayerRemove,this)),this._fetchLayers()}_update(){let e=this._selectedLayer;this._opacity.value=e&&e.opacity?e.opacity:0,this._night.value=e&&e.nightTextureCoefficient?e.nightTextureCoefficient:this.planet.nightTextureCoefficient;let t=e&&e._ambient?e._ambient:this.planet._ambient;this._ambient_r.value=t[0],this._ambient_g.value=t[1],this._ambient_b.value=t[2];let i=e&&e._diffuse?e._diffuse:this.planet._diffuse;this._diffuse_r.value=i[0],this._diffuse_g.value=i[1],this._diffuse_b.value=i[2];let n=e&&e._specular?e._specular:this.planet._specular;this._specular_r.value=n[0],this._specular_g.value=n[1],this._specular_b.value=n[2],this._shininess.value=n[3]}_fetchLayers(){if(this.planet)for(let e=0;e<this.planet.layers.length;e++)this._onLayerAdd(this.planet.layers[e])}_onLayerAdd(e){this.bindLayer(e);let t=document.createElement("option");t.value=e.name,t.innerText=e.name,this._panel.el.querySelector("#layers").appendChild(t),this._panel.el.querySelector("#layers").value=e.name}_onLayerRemove(e){}},MouseNavigation:br,MouseWheelZoomControl:class extends It{constructor(e={}){super(e),this._name="MouseWheelZoomControl",this.grabbedPoint=new oe,this._eye0=new oe,this.pointOnEarth=new oe,this.earthUp=new oe,this.inertia=.007,this.grabbedSpheroid=new At,this.planet=null,this.qRot=new ae,this.scaleRot=0,this.distDiff=.3,this.stepsCount=8,this.stepsForward=null,this.stepIndex=0,this._lmbDoubleClickActive=!0,this.minSlope=e.minSlope||.1,this._keyLock=new xr,this._deactivate=!1,this._move=0}oninit(){let e=document.createElement("div"),t=document.createElement("button"),i=document.createElement("button");e.className="ogZoomControl",t.className="ogZoomButton ogZoomIn",i.className="ogZoomButton ogZoomOut",e.appendChild(t),e.appendChild(i),this.renderer.div.appendChild(e),t.addEventListener("mousedown",(()=>this.zoomIn())),t.addEventListener("mouseup",(()=>this.stopZoom())),i.addEventListener("mousedown",(()=>this.zoomOut())),i.addEventListener("mouseup",(()=>this.stopZoom())),t.addEventListener("touchstart",(e=>{e.preventDefault(),this.zoomIn()})),t.addEventListener("touchend",(e=>{e.preventDefault(),this.stopZoom()})),t.addEventListener("touchcancel",(e=>{e.preventDefault(),this.stopZoom()})),i.addEventListener("touchstart",(e=>{e.preventDefault(),this.zoomOut()})),i.addEventListener("touchend",(e=>{e.preventDefault(),this.stopZoom()})),i.addEventListener("touchcancel",(e=>{e.preventDefault(),this.stopZoom()})),this.renderer.events.on("draw",this._draw,this)}zoomIn(){this.stepIndex||(this.planet.stopFlying(),this.stopRotation(),this._deactivate=!0,this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this.stepsForward=br.getMovePointsFromPixelTerrain(this.planet.camera,this.planet,this.stepsCount,this.distDiff,this.renderer.handler.getCenter(),!0,null)||null,this.stepsForward&&(this.stepIndex=this.stepsCount))}zoomOut(){this.stepIndex||(this.planet.stopFlying(),this.stopRotation(),this._deactivate=!0,this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this.stepsForward=br.getMovePointsFromPixelTerrain(this.planet.camera,this.planet,this.stepsCount,this.distDiff,this.renderer.handler.getCenter(),!1,null)||null,this.stepsForward&&(this.stepIndex=this.stepsCount))}stopRotation(){this.qRot.clear(),this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}stopZoom(){this._move=0,this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}_draw(){if(this._active){let e=this.renderer,t=this.planet.camera,i=t.eye.clone();if(this.stepIndex){e.controlsBag.scaleRot=1;let i=this.stepsForward[this.stepsCount-this.stepIndex--],n=t.maxAltitude+this.planet.ellipsoid.equatorialSize,r=t.minAltitude+this.planet.ellipsoid.equatorialSize;const s=i.eye.length();if(s>n||s<r)return;t.eye=i.eye,t._u=i.v,t._r=i.u,t._b=i.n,t.checkTerrainCollision(),t.update()}else this._deactivate&&(this._deactivate=!1,this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock));if(e.events.mouseState.leftButtonDown||!this.scaleRot)return;if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{e.controlsBag.scaleRot=this.scaleRot;let i=this.qRot.slerp(ae.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize();i.x||i.y||i.z||(this.scaleRot=0),t.eye=i.mulVec3(t.eye),t._u=i.mulVec3(t._u),t._r=i.mulVec3(t._r),t._b=i.mulVec3(t._b),t.checkTerrainCollision(),t.update()}t.eye.distance(i)/t.getAltitude()>.01?(this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock)):(this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock))}}},Ruler:Pr,RulerSwitcher:class extends It{constructor(e={}){super({name:"RulerSwitcher",...e}),this.ruler=new Ir({ignoreTerrain:e.ignoreTerrain})}oninit(){this.planet.addControl(this.ruler),this._createMenuBtn()}onactivate(){this.ruler.activate()}ondeactivate(){this.ruler.deactivate()}_createMenuBtn(){let e=new Ot({classList:["og-map-button","og-ruler_button"],icon:'<?xml version="1.0" encoding="iso-8859-1"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg fill="#000000" height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \n\t viewBox="0 0 512 512" xml:space="preserve">\n<g>\n\t<g>\n\t\t<path d="M369.151,0L0.001,369.15L142.85,512l369.149-369.15L369.151,0z M47.286,369.15l10.908-10.908l47.782,47.782l23.642-23.642\n\t\t\tL81.837,334.6l10.909-10.909l23.711,23.711L140.1,323.76l-23.711-23.711l10.909-10.909l23.711,23.711l23.642-23.642\n\t\t\tl-23.711-23.711l10.909-10.909l47.782,47.782l23.642-23.642l-47.782-47.782l10.908-10.908l23.71,23.71l23.642-23.642l-23.71-23.71\n\t\t\tl10.908-10.908l23.711,23.711l23.642-23.642l-23.711-23.711l10.909-10.909l47.782,47.782l23.642-23.642l-47.782-47.782\n\t\t\tl10.908-10.908l23.71,23.711l23.642-23.642l-23.711-23.71L334.6,81.837l23.711,23.71l23.642-23.642l-23.711-23.712l10.908-10.908\n\t\t\tl95.564,95.564L142.85,464.714L47.286,369.15z"/>\n\t</g>\n</g>\n</svg>'});e.appendTo(this.renderer.div),e.events.on("change",(e=>{e?this.onactivate():this.ondeactivate()}))}},ScaleControl:Dr,Selection:class extends It{constructor(e={}){super(e),this._selectorScene=new jr({name:`selectionScene:${this.__id}`,ignoreTerrain:e.ignoreTerrain,onSelect:e.onSelect,autoSelectionHide:e.autoSelectionHide}),this._toggleBtn=new Ot({classList:["og-map-button","og-selection_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg width="800px" height="800px" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--gis" preserveAspectRatio="xMidYMid meet"><path d="M2.1 0v1.914H0v6h3V3h5.1V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h1.8v1.2h3V0h-4.8zm1.8 7.2v6h3v-6h-3zM0 10.913v6h3v-6H0zM66.9 16.2v6h3v-6h-3zM0 19.914v6h3v-6H0zM66.9 25.2v6h3v-6h-3zM0 28.914v6h3v-6H0zM66.9 34.2v6h3v-6h-3zM0 37.914v6h3v-6H0zM66.9 43.2v6h3v-6h-3zM0 46.914v6h3v-6H0zM66.9 52.2v6h3v-6h-3zM0 55.914v5.191h3.809v-3H3v-2.19H0zm6.809 2.191v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9.648 1.899a2.076 2.076 0 0 0-2.19 2.324l3.137 33.676c.2 1.635 2.135 2.399 3.397 1.34l6.623-5.371l2.969 5.142c1.707 2.958 4.417 3.684 7.375 1.977c2.957-1.708 3.684-4.417 1.976-7.375l-2.959-5.125l7.848-3.008c1.548-.564 1.855-2.62.539-3.611L71.576 60.416a2.073 2.073 0 0 0-1.119-.412z" fill="#000000"></path></svg>'})}set ignoreTerrain(e){this._selectorScene.ignoreTerrain=e}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._toggleBtn.events.on("change",(e=>{e?this.activate():this.deactivate()})),this._selectorScene.bindPlanet(this.planet)}onactivate(){this.renderer.addNode(this._selectorScene)}ondeactivate(){this.renderer.removeNode(this._selectorScene)}},ShowFps:class extends It{constructor(e){super(e)}oninit(){let e=document.createElement("div");e.className="defaultText ",e.id="ogShowFpsControl",document.body.appendChild(e),this.renderer.events.on("draw",this._draw,this)}_draw(){Ce("ogShowFpsControl",(1e3/this.renderer.handler.deltaTime).toFixed(1),this.renderer.handler.canvas.clientWidth-60,0)}},SimpleNavigation:class extends It{constructor(e={}){super({name:"SimpleNavigation",autoActivate:!0,...e}),this.speed=e.speed||1}oninit(){}onactivate(){super.onactivate();let e=this.renderer;e.events.on("keypress",dr.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",dr.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",dr.KEY_A,this.onCameraStrifeLeft,this),e.events.on("keypress",dr.KEY_D,this.onCameraStrifeRight,this),e.events.on("keypress",dr.KEY_UP,this.onCameraLookUp,this),e.events.on("keypress",dr.KEY_DOWN,this.onCameraLookDown,this),e.events.on("keypress",dr.KEY_LEFT,this.onCameraTurnLeft,this),e.events.on("keypress",dr.KEY_RIGHT,this.onCameraTurnRight,this),e.events.on("keypress",dr.KEY_Q,this.onCameraRollLeft,this),e.events.on("keypress",dr.KEY_E,this.onCameraRollRight,this)}ondeactivate(){super.ondeactivate();let e=this.renderer;e.events.off("keypress",dr.KEY_W,this.onCameraMoveForward),e.events.off("keypress",dr.KEY_S,this.onCameraMoveBackward),e.events.off("keypress",dr.KEY_A,this.onCameraStrifeLeft),e.events.off("keypress",dr.KEY_D,this.onCameraStrifeRight),e.events.off("keypress",dr.KEY_UP,this.onCameraLookUp),e.events.off("keypress",dr.KEY_DOWN,this.onCameraLookDown),e.events.off("keypress",dr.KEY_LEFT,this.onCameraTurnLeft),e.events.off("keypress",dr.KEY_RIGHT,this.onCameraTurnRight),e.events.off("keypress",dr.KEY_Q,this.onCameraRollLeft),e.events.off("keypress",dr.KEY_E,this.onCameraRollRight)}onCameraMoveForward(){if(this._active){let e=this.renderer.activeCamera;e.slide(0,0,-this.speed),e.update()}}onCameraMoveBackward(){let e=this.renderer.activeCamera;e.slide(0,0,this.speed),e.update()}onCameraStrifeLeft(){let e=this.renderer.activeCamera;e.slide(-this.speed,0,0),e.update()}onCameraStrifeRight(){let e=this.renderer.activeCamera;e.slide(this.speed,0,0),e.update()}onCameraLookUp(){let e=this.renderer.activeCamera;e.pitch(.5),e.update()}onCameraLookDown(){let e=this.renderer.activeCamera;e.pitch(-.5),e.update()}onCameraTurnLeft(){let e=this.renderer.activeCamera;e.yaw(.5),e.update()}onCameraTurnRight(){let e=this.renderer.activeCamera;e.yaw(-.5),e.update()}onCameraRollLeft(){let e=this.renderer.activeCamera;e.roll(-.5),e.update()}onCameraRollRight(){let e=this.renderer.activeCamera;e.roll(.5),e.update()}},SimpleSkyBackground:Fr,Sun:Vr,TimelineControl:class extends It{constructor(e={}){super({name:"timeline",...e});let t=e.current||new Date,i=e.rangeStart||ss(t,-12),n=e.rangeEnd||ss(t,12);this._timelineView=new rs({rangeStart:i,rangeEnd:n,currentDate:t}),this._toggleBtn=new Ot({classList:["og-map-button","og-timeline_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">\n <metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n <g><path d="M500,10C229.4,10,10,229.4,10,500s219.4,490,490,490s490-219.4,490-490S770.6,10,500,10z M800.3,800.3c-39,39-84.5,69.7-135,91C613,913.5,557.4,924.7,500,924.7s-112.9-11.2-165.3-33.3c-50.5-21.3-95.9-52-135-91c-39-39-69.7-84.5-91-135C86.5,612.9,75.3,557.4,75.3,500s11.2-112.9,33.3-165.3c21.3-50.5,52-95.9,91-135c39-39,84.5-69.7,135-91C387.1,86.5,442.6,75.3,500,75.3s112.9,11.2,165.3,33.3c50.5,21.3,95.9,52,135,91c39,39,69.7,84.5,91,135c22.1,52.3,33.3,107.9,33.3,165.3s-11.2,112.9-33.3,165.3C869.9,715.8,839.3,761.2,800.3,800.3z"/><path d="M761.3,532.7H532.7V304c0-18.1-14.6-32.7-32.7-32.7s-32.7,14.6-32.7,32.7v261.3l0,0c0,18.1,14.6,32.7,32.7,32.7h261.3c18.1,0,32.7-14.6,32.7-32.7l0,0C794,547.3,779.4,532.7,761.3,532.7z"/></g>\n</svg>'}),this._dialog=new Nt({title:"Timeline",visible:!1,resizable:!0,useHide:!0,top:10,left:60,width:600,height:115,minHeight:115,maxHeight:110}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)}))}oninit(){let e=this.renderer.div;this._toggleBtn.appendTo(e),this._dialog.appendTo(e),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e),e&&this._timelineView.resize()})),this._timelineView.appendTo(this._dialog.container),this._timelineView.events.on("setcurrent",(e=>{this.renderer&&this.renderer.handler.defaultClock.setDate(e)})),this._timelineView.events.on("startdrag",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.deactivate()})),this._timelineView.events.on("stopdrag",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.activate()})),this._timelineView.events.on("startdragcurrent",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.deactivate()})),this._timelineView.events.on("stopdragcurrent",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.activate()}))}},ToggleWireframe:class extends It{constructor(e={}){super(e),this._isActive=!1,this.toogleWireframe=()=>{this.renderer&&this.renderer.handler.gl&&(this.planet.drawMode===this.renderer.handler.gl.LINE_STRIP?this.planet.setDrawMode(this.renderer.handler.gl.TRIANGLE_STRIP):this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP))},this._isActive=e.isActive||!1}oninit(){this.renderer.events.on("charkeypress",dr.KEY_X,this.toogleWireframe,this),this._isActive&&this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP)}},TouchNavigation:Gr,ZoomControl:Wr});function Ps(e){return new Uint32Array(e)}function Ss(e){let t=[],i=0,n=0,r=0;for(let s=1;s<e-1-1;s++){for(let a=1;a<e-1;a++)i=s*e+a,r=(s+1)*e,n=r+a,t.push(i,n);t.push(n,r+1)}return t.push(t[t.length-1],e*e-e),Ps(t)}function Ms(e,t){let i=[];const n=(e-1)/t,r=e*e-e;let s=0;for(let t=0;t<e-2;t++){t%n==0&&(s=t);let a=r-e*t-e+1,o=r-e*s;i.push(o,a)}return t===e-1&&(i.push(e),i.push(0)),Ps(i)}function Bs(e,t){let i=[];const n=(e-1)/t;let r=0;for(let t=0;t<e-2;t++){t%n==0&&(r=t);let s=e+t+1,a=r;i.push(a,s)}return t===e-1&&(i.push(e-2),i.push(e-1)),Ps(i)}function ks(e,t){let i=[];const n=(e-1)/t;let r=0;for(let t=0;t<e-2;t++){t%n==0&&(r=t);let s=e*(t+1)+e-2,a=e+e*r-1;i.push(a,s)}return t===e-1&&(i.push(e*(e-1)-1),i.push(e*e-1)),Ps(i)}function Rs(e,t){let i=[];const n=(e-1)/t;let r=0;const s=e*(e-1)-2,a=e*e-1;for(let t=0;t<e-2;t++){t%n==0&&(r=t);let e=s-t,o=a-r;i.push(o,e)}return t===e-1&&i.push(e*e-e+1),i.push(e*e-e),Ps(i)}function Is(e){let t=[[],[],[],[]];for(let i=0;i<=e;i++){let n=Math.pow(2,i)+1;t[0][i]=[],t[3][i]=[],t[2][i]=[],t[1][i]=[];for(let r=0;r<=e;r++){let e=Math.pow(2,r);t[3][i][r]=Ms(n,e),t[0][i][r]=Bs(n,e),t[1][i][r]=ks(n,e),t[2][i][r]=Rs(n,e)}}return t}function zs(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=Ss(e+1)}return t}function Ds(e){let t=new Uint16Array((e+1)*(e+1)*2),i=0;for(let n=0;n<=e;n++)for(let r=0;r<=e;r++)t[i++]=r/e*65535,t[i++]=n/e*65535;return t}let Fs=new class{constructor(e=0){this._maxGridSize=e,this.centerIndexesTable=zs(this._maxGridSize),this.skirtsIndexesTable=Is(this._maxGridSize)}get maxGridSize(){return this._maxGridSize}init(){this.centerIndexesTable=zs(this._maxGridSize),this.skirtsIndexesTable=Is(this._maxGridSize)}setMaxGridSize(e){this._maxGridSize=e,this.init()}createSegmentIndexes(e,t){if(e){let i=this.centerIndexesTable[e],n=this.skirtsIndexesTable[3][e][t[3]],r=this.skirtsIndexesTable[0][e][t[0]],s=this.skirtsIndexesTable[1][e][t[1]],a=this.skirtsIndexesTable[2][e][t[2]],o=function(e){return new Uint32Array(e)}(i.length+n.length+r.length+s.length+a.length);return o.set(i,0),o.set(n,i.length),o.set(r,i.length+n.length),o.set(s,i.length+n.length+r.length),o.set(a,i.length+n.length+r.length+s.length),o}return Ps([0,2,1,3])}initTextureCoordsTable(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=Ds(e)}return t}};function Ns(){return Fs}const Hs="\n float getLerpValue(in float min, in float max, in float between)\n {\n return (clamp(between, min, max) - min) / (max - min);\n }\n \n vec3 aces(vec3 color) \n {\n float a = 2.51;\n float b = 0.03;\n float c = 2.43;\n float d = 0.59;\n float e = 0.14;\n return clamp((color * (a * color + b)) / (color * (c * color + d ) + e), 0.0, 1.0);\n }\n \n bool intersectSphere(vec3 rayOrigin, vec3 rayDirection, float radius, inout float t1, inout float t2) \n {\n float b = dot(rayDirection, rayOrigin);\n float c = dot(rayOrigin, rayOrigin) - radius * radius;\n float d = b * b - c;\n if (d < 0.0) {\n return false;\n }\n t1 = -b - sqrt(d);\n t2 = -b + sqrt(d);\n return true;\n }\n \n bool intersectSphere(vec3 rayOrigin, vec3 rayDirection, float radius, inout float t) \n {\n float b = dot(rayDirection, rayOrigin);\n float c = dot(rayOrigin, rayOrigin) - radius * radius;\n float d = b * b - c;\n if (d < 0.0) {\n return false;\n }\n t = -b - sqrt(d);\n return true;\n }\n \n bool intersectEllipsoid( in vec3 ro, in vec3 rd, in vec3 ra, inout float t )\n {\n vec3 ocn = ro/ra;\n vec3 rdn = rd/ra;\n float a = dot( rdn, rdn );\n float b = dot( ocn, rdn );\n float c = dot( ocn, ocn );\n float h = b*b - a*(c-1.0);\n \n if (h < 0.0) \n { \n return false; \n }\n \n t = (-b-sqrt(h))/a;\n \n return true;\n }\n \n bool intersectEllipsoid( in vec3 ro, in vec3 rd, in vec3 ra, inout float t1, inout float t2)\n {\n vec3 ocn = ro/ra;\n vec3 rdn = rd/ra;\n float a = dot( rdn, rdn );\n float b = dot( ocn, rdn );\n float c = dot( ocn, ocn );\n float h = b*b - a*(c-1.0);\n \n if (h < 0.0) \n { \n return false; \n }\n \n h = sqrt(h);\n t1 = (-b-h)/a;\n t2 = (-b+h)/a;\n \n return true;\n }\n \n vec3 normalEllipsoid( in vec3 pos, in vec3 ra )\n {\n return normalize( pos/(ra*ra) );\n }\n",Os={ATMOS_HEIGHT:1e5,RAYLEIGH_SCALE:.08,MIE_SCALE:.012,GROUND_ALBEDO:.05,BOTTOM_RADIUS:6356752.314245179,rayleighScatteringCoefficient:[5.802,13.558,33.1],mieScatteringCoefficient:3.996,mieExtinctionCoefficient:4.44,ozoneAbsorptionCoefficient:[.65,1.881,.085],SUN_ANGULAR_RADIUS:.004685,SUN_INTENSITY:1,ozoneDensityHeight:25e3,ozoneDensityWide:15e3},Vs=(e=Os)=>` \n ${Hs}\n \n #define PI 3.1415926538\n #define ATMOS_HEIGHT ${e.ATMOS_HEIGHT.toFixed(2)}\n #define RAYLEIGH_SCALE ${e.RAYLEIGH_SCALE.toFixed(5)}\n #define MIE_SCALE ${e.MIE_SCALE.toFixed(5)}\n \n #define SAMPLE_COUNT 16\n #define SQRT_SAMPLE_COUNT 4\n \n const float GROUND_ALBEDO = ${e.GROUND_ALBEDO.toFixed(2)} / PI;\n\n // Sphere\n const float BOTTOM_RADIUS = ${e.BOTTOM_RADIUS.toFixed(10)};\n const float TOP_RADIUS = BOTTOM_RADIUS + ATMOS_HEIGHT; \n const float EQUATORIAL_RADIUS = 6378137.0;\n \n // Ellipsoid\n const vec3 bottomRadii = vec3(EQUATORIAL_RADIUS, EQUATORIAL_RADIUS, BOTTOM_RADIUS); \n const vec3 topRadii = bottomRadii + ATMOS_HEIGHT;\n \n const vec3 SPHERE_TO_ELLIPSOID_SCALE = vec3(BOTTOM_RADIUS) / bottomRadii; \n \n const vec2 rayleighMieHeights = vec2(RAYLEIGH_SCALE, MIE_SCALE) * ATMOS_HEIGHT;\n \n const vec3 rayleighScatteringCoefficient = vec3(${e.rayleighScatteringCoefficient[0].toFixed(5)}, ${e.rayleighScatteringCoefficient[1].toFixed(5)}, ${e.rayleighScatteringCoefficient[2].toFixed(5)}) * 1e-6;\n \n const float mieScatteringCoefficient = ${e.mieScatteringCoefficient.toFixed(3)} * 1e-6;\n const float mieExtinctionCoefficient = ${e.mieExtinctionCoefficient.toFixed(3)} * 1e-6;\n const vec3 ozoneAbsorptionCoefficient = vec3(${e.ozoneAbsorptionCoefficient[0].toFixed(5)}, ${e.ozoneAbsorptionCoefficient[1].toFixed(5)}, ${e.ozoneAbsorptionCoefficient[2].toFixed(5)}) * 1e-6;\n \n const float SUN_ANGULAR_RADIUS = ${e.SUN_ANGULAR_RADIUS.toFixed(10)};\n const float SUN_INTENSITY = ${e.SUN_INTENSITY.toFixed(2)}; \n \n const float ozoneDensityHeight = ${e.ozoneDensityHeight.toFixed(1)};//25e3;\n const float ozoneDensityWide = ${e.ozoneDensityWide.toFixed(1)};//15e3;\n \n vec3 sunWithBloom(vec3 rayDir, vec3 sunDir) \n {\n float minSunCosTheta = cos(SUN_ANGULAR_RADIUS); \n float cosTheta = dot(rayDir, sunDir);\n if (cosTheta >= minSunCosTheta) return vec3(1.0); \n float offset = minSunCosTheta - cosTheta;\n float gaussianBloom = exp(-offset*15000.0)*0.7;\n float invBloom = 1.0/(0.09 + offset*200.0)*0.01;\n return vec3(gaussianBloom + invBloom);\n }\n \n float rayleighPhase(float angle) \n {\n return 3.0 / (16.0 * PI) * (1.0 + (angle * angle));\n }\n \n float miePhase(float angle) \n {\n float g = 0.8;\n return 3.0 / (8.0 * PI) * ((1.0 - g * g) * (1.0 + angle * angle)) / ((2.0 + g * g) * pow(1.0 + g * g - 2.0 * g * angle, 1.5));\n }\n \n vec3 opticalDepth(float height, float angle) \n {\n vec3 rayOrigin = vec3(0.0, BOTTOM_RADIUS + height, 0.0);\n vec3 rayDirection = vec3(sqrt(1.0 - angle * angle), angle, 0.0);\n float t1, t2;\n intersectSphere(rayOrigin, rayDirection, TOP_RADIUS, t1, t2);\n float segmentLength = t2 / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n vec3 opticalDepth = vec3(0.0);\n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n opticalDepth.xy += exp(-height / rayleighMieHeights) * segmentLength;\n opticalDepth.z += (1.0 - min(abs(height - ozoneDensityHeight) / ozoneDensityWide, 1.0)) * segmentLength; \n t += segmentLength;\n }\n \n return opticalDepth;\n }\n \n vec3 transmittance(float height, float angle) \n {\n vec3 opticalDepth = opticalDepth(height, angle);\n return exp(-(rayleighScatteringCoefficient * opticalDepth.x + mieExtinctionCoefficient * opticalDepth.y + ozoneAbsorptionCoefficient * opticalDepth.z));\n }`;const Us="const vec3 nightStep = 10.0 * vec3(0.58, 0.48, 0.25);",Gs="#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = texture( SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw ); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;",Ws="#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = texture2D( SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw ); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;";function js(){return new zi("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightsPositions:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"\n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec4 vTextureCoord;\n varying vec3 v_vertex;\n varying vec3 cameraPosition;\n varying vec2 vGlobalTextureCoord;\n varying float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n\n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`\n precision highp float;\n \n #define MAX_POINT_LIGHTS 1\n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient;\n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec3 lightsPositions[MAX_POINT_LIGHTS];\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient; \n uniform float camHeight;\n\n varying vec4 vTextureCoord;\n varying vec3 v_vertex;\n varying vec3 cameraPosition;\n varying vec2 vGlobalTextureCoord;\n varying float v_height;\n\n vec3 sunPos;\n\n ${Us}\n\n ${Ws}\n \n ${Hs}\n \n void main(void) {\n \n sunPos = lightsPositions[0];\n \n vec3 texNormal = texture2D(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture2D( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0); \n vec4 nightImageColor = texture2D( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + diffuse * diffuseLightWeighting + night, 1.0);\n \n gl_FragColor = texture2D( defaultTexture, vTextureCoord.xy );\n if( samplerCount == 0 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n vec4 src;\n\n blend(gl_FragColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n }`})}function Ys(e){return new zi("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightsPositions:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",transmittanceTexture:"sampler2D",scatteringTexture:"sampler2D",camHeight:"float",nightTextureCoefficient:"float",maxMinOpacity:"vec2",transitionOpacity:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"#version 300 es\n\n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in vec3 aVertexPositionLow;\n in vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n out vec4 vTextureCoord;\n out vec3 v_vertex;\n out vec3 cameraPosition;\n out vec2 vGlobalTextureCoord;\n out float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n\n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`#version 300 es\n\n precision highp float;\n \n #define MAX_POINT_LIGHTS 1\n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient;\n\n uniform vec3 lightsPositions[MAX_POINT_LIGHTS];\n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D transmittanceTexture;\n uniform sampler2D scatteringTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient;\n \n uniform vec2 maxMinOpacity; \n uniform float camHeight;\n \n uniform float transitionOpacity;\n\n in vec4 vTextureCoord;\n in vec3 v_vertex;\n in vec3 cameraPosition;\n in vec2 vGlobalTextureCoord;\n in float v_height;\n\n vec3 sunPos;\n\n layout(location = 0) out vec4 diffuseColor;\n\n ${Us}\n\n ${Gs}\n \n ${Vs(e)} \n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture(transmittanceTexture, vec2(u, v)).xyz;\n }\n\n vec3 multipleScatteringContributionFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture(scatteringTexture, vec2(u, v)).xyz;\n }\n \n void getSunIlluminance(in vec3 point, in vec3 lightDir, out vec3 sunIlluminance)\n {\n // float r = length(point);\n // float mu_s = dot(point, sun_direction) / r;\n // float height = r - BOTTOM_RADIUS;\n \n float mu_s = dot(normalize(point), lightDir);\n float height = length(point) - BOTTOM_RADIUS;\n sunIlluminance = SUN_INTENSITY * transmittanceFromTexture(height, mu_s);\n }\n \n void atmosGroundColor(out vec4 fragColor, in vec3 normal)\n { \n vec3 cameraPosition = cameraPosition; \n \n if(length(cameraPosition * SPHERE_TO_ELLIPSOID_SCALE) < BOTTOM_RADIUS + 1.0){\n cameraPosition = normalize(cameraPosition * SPHERE_TO_ELLIPSOID_SCALE) * (BOTTOM_RADIUS + 1.0) / SPHERE_TO_ELLIPSOID_SCALE;\n } \n \n vec3 rayDirection = normalize(v_vertex - cameraPosition);\n vec3 lightDir = normalize(sunPos);\n \n rayDirection = normalize(rayDirection * SPHERE_TO_ELLIPSOID_SCALE);\n vec3 camPos = cameraPosition * SPHERE_TO_ELLIPSOID_SCALE;\n lightDir = normalize(lightDir * SPHERE_TO_ELLIPSOID_SCALE);\n \n\n vec3 light = vec3(0.0);\n vec3 transmittanceFromCameraToSpace = vec3(1.0);\n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n intersectSphere(camPos, rayDirection, TOP_RADIUS, offset, distanceToSpace);\n \n vec3 rayOrigin = camPos;\n \n // above atmosphere\n if (offset > 0.0) \n {\n // intersection of camera ray with atmosphere\n rayOrigin += rayDirection * offset;\n }\n \n float height = length(rayOrigin) - BOTTOM_RADIUS;\n float rayAngle = dot(rayOrigin, rayDirection) / length(rayOrigin);\n bool cameraBelow = rayAngle < 0.0;\n \n transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float phaseAngle = dot(lightDir, rayDirection);\n float rayleighPhase = rayleighPhase(phaseAngle);\n float miePhase = miePhase(phaseAngle);\n \n float distanceToGround = 0.0;\n \n bool hitGround = intersectSphere(camPos, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0; \n //intersectSphere(camPos, rayDirection, BOTTOM_RADIUS, distanceToGround);\n \n\n if(length(v_vertex * SPHERE_TO_ELLIPSOID_SCALE) > BOTTOM_RADIUS){\n distanceToGround = distance(camPos, v_vertex * SPHERE_TO_ELLIPSOID_SCALE);\n }\n \n float segmentLength = (distanceToGround - max(offset, 0.0)) / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera; \n vec3 transmittanceLight; \n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDir); \n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n vec2 opticalDensity = exp(-height / rayleighMieHeights);\n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x * rayleighPhase + mieScatteringCoefficient * opticalDensity.y * miePhase);\n scatteredLight += multipleScatteringContributionFromTexture(height, lightAngle) * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y); \n light += transmittanceCamera * scatteredLight * segmentLength;\n t += segmentLength;\n }\n \n light *= SUN_INTENSITY;\n \n vec3 hitPoint = camPos + rayDirection * distanceToGround;\n vec3 up = normalize(hitPoint);\n float diffuseAngle = max(dot(up, lightDir), 0.0); \n \n float lightAngle = dot(normal, lightDir);\n vec3 tA = transmittanceCamera * GROUND_ALBEDO * SUN_INTENSITY; \n vec3 scatteringLight = multipleScatteringContributionFromTexture(height, lightAngle);\n vec3 diffuseTransmittanceLight = transmittanceLight * diffuseAngle; \n light += tA * (scatteringLight + diffuseTransmittanceLight);\n \n fragColor = vec4(pow(light * 8.0, vec3(1.0 / 2.2)), 1.0);\n }\n\n void getAtmosFadingOpacity(out float opacity)\n { \n float c = length(cameraPosition);\n float maxDist = sqrt(c * c - BOTTOM_RADIUS * BOTTOM_RADIUS);\n float minDist = c - BOTTOM_RADIUS;\n float vertDist = distance(cameraPosition, v_vertex); \n opacity = clamp(maxMinOpacity.y + ( maxMinOpacity.x - maxMinOpacity.y) * getLerpValue(minDist, maxDist, vertDist), 0.0, 1.0);\n }\n\n void main(void) {\n \n sunPos = lightsPositions[0];\n \n vec3 texNormal = texture(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n vec4 atmosColor;\n atmosGroundColor(atmosColor, normal);\n \n vec3 sunIlluminance; \n getSunIlluminance(v_vertex * SPHERE_TO_ELLIPSOID_SCALE, lightDir * SPHERE_TO_ELLIPSOID_SCALE, sunIlluminance);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = sunIlluminance * specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0);\n \n vec4 nightImageColor = texture( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + sunIlluminance * diffuse * diffuseLightWeighting + night, 1.0);\n \n float fadingOpacity;\n getAtmosFadingOpacity(fadingOpacity);\n \n getSunIlluminance(cameraPosition, viewDir * SPHERE_TO_ELLIPSOID_SCALE, sunIlluminance);\n \n spec *= sunIlluminance;\n\n diffuseColor = texture( defaultTexture, vTextureCoord.xy );\n if( samplerCount == 0 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n vec4 src;\n\n blend(diffuseColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n }`})}class qs{constructor(e,t={}){this.handler=e,this._fbo=null,this._width=t.width||e.canvas.width,this._height=t.height||e.canvas.height,this._depthComponent=null!=t.depthComponent?t.depthComponent:"DEPTH_COMPONENT16",this._useDepth=null==t.useDepth||t.useDepth,this._active=!1,this._size=t.size||1,this._depthRenderbuffer=null,this._filter=t.filter||"NEAREST"}get width(){return this._width}get height(){return this._height}setSize(e,t,i=!1){this._width=e,this._height=t,this._active&&this.handler.gl.viewport(0,0,this._width,this._height),(this._useDepth||i)&&(this.destroy(),this.init())}init(){}destroy(){}isComplete(){let e=this.handler.gl;return e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE}checkStatus(){let e=this.handler.gl;return e.checkFramebufferStatus(e.FRAMEBUFFER)}activate(){let e=this.handler.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo),e.viewport(0,0,this._width,this._height),this._active=!0;let t=this.handler.framebufferStack.current().data;return t&&(t._active=!1),this.handler.framebufferStack.push(this),this}deactivate(){let e=this.handler,t=e.gl;t.bindFramebuffer(t.FRAMEBUFFER,null),this._active=!1;let i=this.handler.framebufferStack.popPrev();i?(t.bindFramebuffer(t.FRAMEBUFFER,i._fbo),t.viewport(0,0,i._width,i._height)):t.viewport(0,0,e.canvas.width,e.canvas.height)}}class Xs{constructor(e=256,t=256){this._canvas=document.createElement("canvas"),this._canvas.width=e,this._canvas.height=t,this._context=this._canvas.getContext("2d",{willReadFrequently:!0})}getCanvas(){return this._canvas}getContext(){return this._context}fillEmpty(){let e=this._context.getImageData(0,0,this._canvas.width,this._canvas.height),t=e.data;for(let e=0,i=t.length;e<i;e+=4)t[e]=t[e+1]=t[e+2]=t[e+3]=0;this._context.putImageData(e,0,0)}fill(e){this._context.fillStyle=e,this._context.fill()}getData(){return this._context.getImageData(0,0,this._canvas.width,this._canvas.height).data}fillColor(e){this._context.fillStyle=e,this._context.fillRect(0,0,this._canvas.width,this._canvas.height)}setData(e){let t=this._context.createImageData(this._canvas.width,this._canvas.height);t.data.set(e),this._context.putImageData(t,0,0)}resize(e,t){this._canvas.width=e,this._canvas.height=t,this._context=this._canvas.getContext("2d")}drawImage(e,t,i,n,r){this._context.drawImage(e,t||0,i||0,n||e.width,r||e.height)}getImage(){let e=new Image;return e.width=this.getWidth(),e.height=this.getHeight(),e.src=this._canvas.toDataURL("image/png"),e}getTextWidth(e){let t=this._context.measureText(e);return Math.round(t.width)}drawText(e,t=0,i=14,n="normal 14px Verdana",r="black"){this._context.fillStyle=r,this._context.font=n,this._context.fillText(e,t,i)}getWidth(){return this._canvas.width}getHeight(){return this._canvas.height}load(e,t){let i=new Image,n=this;i.onload=function(){n.resize(i.width,i.height),n._context.drawImage(i,0,0,i.width,i.height),t&&t(i)},i.src=e}openImage(){let e=this.getImage(),t="<!DOCTYPE html>";t+="<html>",t+="<head><title>Print</title></head>",t+="<body>",t+='<img src="'+e.src+'">',t+="</body>",t+="</html>";let i=window.open("","","width="+e.width+"px ,height="+e.height+"px");i&&(i.document.open(),i.document.write(t),i.document.close(),i.focus())}destroy(){this._canvas.width=1,this._canvas.height=1,this._canvas=null,this._context=null}}class $s extends qs{constructor(e,t={}){super(e,t),this._isBare=t.isBare||!1,this._internalFormatArr=t.internalFormat instanceof Array?t.internalFormat:[t.internalFormat||"RGBA"],this._formatArr=t.format instanceof Array?t.format:[t.format||"RGBA"],this._typeArr=t.type instanceof Array?t.type:[t.type||"UNSIGNED_BYTE"],t.attachment instanceof Array?this._attachmentArr=t.attachment.map(((e,t)=>{let i=e.toUpperCase();return"COLOR_ATTACHMENT"===i?`${i}${t.toString()}`:i})):this._attachmentArr=[t.attachment||"COLOR_ATTACHMENT0"],this._renderbufferTarget=null!=t.renderbufferTarget?t.renderbufferTarget:"DEPTH_ATTACHMENT",this.textures=t.textures||new Array(this._size)}destroy(){let e=this.handler.gl;if(e){for(let t=0;t<this.textures.length;t++)e.deleteTexture(this.textures[t]);this.textures=new Array(this._size),e.deleteFramebuffer(this._fbo),e.deleteRenderbuffer(this._depthRenderbuffer),this._depthRenderbuffer=null,this._fbo=null,this._active=!1}}init(){let e=this.handler.gl;if(e){if(this._fbo=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo),!this._isBare){let t=[];for(let i=0;i<this.textures.length;i++){let n=this.textures[i]||this.handler.createEmptyTexture2DExt(this._width,this._height,this._filter,this._internalFormatArr[i],this._formatArr[i],this._typeArr[i]),r=e[this._attachmentArr[i]];n&&(this.bindOutputTexture(n,r),this.textures[i]=n),"DEPTH_ATTACHMENT"!=this._attachmentArr[i]&&t.push(r)}e.drawBuffers&&e.drawBuffers(t)}this._useDepth&&(this._depthRenderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this._depthRenderbuffer),e.renderbufferStorage(e.RENDERBUFFER,e[this._depthComponent],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e[this._renderbufferTarget],e.RENDERBUFFER,this._depthRenderbuffer),e.bindRenderbuffer(e.RENDERBUFFER,null)),e.bindFramebuffer(e.FRAMEBUFFER,null)}}bindOutputTexture(e,t){let i=this.handler.gl;i.bindTexture(i.TEXTURE_2D,e),i.framebufferTexture2D(i.FRAMEBUFFER,t||i.COLOR_ATTACHMENT0,i.TEXTURE_2D,e,0),i.bindTexture(i.TEXTURE_2D,null)}readPixels(e,t,i,n=0,r=1,s=1){let a=this.handler.gl;a.bindFramebuffer(a.FRAMEBUFFER,this._fbo),a.readBuffer&&a.readBuffer(a.COLOR_ATTACHMENT0+n||0),a.readPixels(t*this._width,i*this._height,r,s,a.RGBA,a[this._typeArr[n]],e),a.bindFramebuffer(a.FRAMEBUFFER,null)}readAllPixels(e,t=0){let i=this.handler.gl;i.bindFramebuffer(i.FRAMEBUFFER,this._fbo),i.readBuffer&&i.readBuffer(i.COLOR_ATTACHMENT0+t),i.readPixels(0,0,this._width,this._height,i.RGBA,i[this._typeArr[t]],e),i.bindFramebuffer(i.FRAMEBUFFER,null)}getImage(){let e=new Uint8Array(4*this._width*this._height);this.readAllPixels(e);let t=new Xs(this._width,this._height);return t.setData(e),t.getImage()}}class Zs extends It{constructor(e={}){super({name:"Atmosphere",...e}),this._transmittanceBuffer=null,this._scatteringBuffer=null,this.opacity=1,this._parameters={ATMOS_HEIGHT:e.height||1e5,RAYLEIGH_SCALE:e.rayleighScale||.08,MIE_SCALE:e.mieScale||.012,GROUND_ALBEDO:e.groundAlbedo||.05,BOTTOM_RADIUS:e.bottomRadius||6356752.314245179,rayleighScatteringCoefficient:e.rayleighScatteringCoefficient||[5.802,13.558,33.1],mieScatteringCoefficient:e.mieScatteringCoefficient||3.996,mieExtinctionCoefficient:e.mieExtinctionCoefficient||4.44,ozoneAbsorptionCoefficient:e.ozoneAbsorptionCoefficient||[.65,1.881,.085],SUN_ANGULAR_RADIUS:e.sunAngularRadius||.004685,SUN_INTENSITY:e.sunIntensity||1,ozoneDensityHeight:e.ozoneDensityHeight||25e3,ozoneDensityWide:e.ozoneDensityWide||15e3}}setParameters(e){this._parameters=JSON.parse(JSON.stringify(e)),this.initLookupTexturesShaders(),this.drawLookupTextures(),this.removeLookupTexturesShaders(),this.initPlanetAtmosphereShader()}get parameters(){return JSON.parse(JSON.stringify(this._parameters))}initPlanetAtmosphereShader(){this.planet?.initAtmosphereShader(this._parameters)}oninit(){this.renderer&&(this._initLookupTextures(),this.initLookupTexturesShaders(),this.drawLookupTextures(),this.removeLookupTexturesShaders(),this.initBackgroundShader(),this.activate())}initLookupTexturesShaders(){var e;this.renderer&&(this.renderer.handler.addProgram((e=this._parameters,new zi("transmittance",{uniforms:{iResolution:"vec2"},attributes:{a_position:"vec2"},vertexShader:"\n attribute vec2 a_position;\n \n void main(void) \n {\n gl_Position = vec4(a_position, 0.0, 1.0);\n }",fragmentShader:`\n precision highp float;\n \n ${Vs(e)}\n \n uniform vec2 iResolution;\n \n void main(void) \n {\n vec2 uv = gl_FragCoord.xy / iResolution.xy;\n float height = uv.y * ATMOS_HEIGHT;\n float angle = uv.x * 2.0 - 1.0;\n gl_FragColor = vec4(transmittance(height, angle), 1.0);\n }`})),!0),this.renderer.handler.addProgram(function(e){return new zi("scattering",{uniforms:{iResolution:"vec2",transmittanceTexture:"sampler2d"},attributes:{a_position:"vec2"},vertexShader:" \n attribute vec2 a_position; \n \n void main(void) \n {\n gl_Position = vec4(a_position, 0.0, 1.0);\n }",fragmentShader:` \n precision highp float;\n \n uniform sampler2D transmittanceTexture;\n uniform vec2 iResolution;\n \n ${Vs(e)}\n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(transmittanceTexture, vec2(u, v)).xyz;\n }\n \n void main(void) \n {\n vec2 uv = gl_FragCoord.xy / iResolution.xy;\n \n float height = uv.y * ATMOS_HEIGHT;\n float angle = uv.x * 2.0 - 1.0;\n \n vec3 rayOrigin = vec3(0.0, BOTTOM_RADIUS + height, 0.0);\n vec3 up = rayOrigin / length(rayOrigin);\n vec3 lightDirection = vec3(sqrt(1.0 - angle * angle), angle, 0.0);\n \n const float isotropicPhase = 1.0 / (4.0 * PI);\n \n vec3 light = vec3(0.0);\n vec3 lightTransferFactor = vec3(0.0);\n \n for (int i = 0; i < SQRT_SAMPLE_COUNT; i++)\n {\n for (int j = 0; j < SQRT_SAMPLE_COUNT; j++)\n {\n float u = ((0.5 + float(i)) / float(SQRT_SAMPLE_COUNT)) * 2.0 - 1.0;\n float v = (0.5 + float(j)) / float(SQRT_SAMPLE_COUNT);\n float r = sqrt(1.0 - u * u);\n float theta = 2.0 * PI * v;\n vec3 rayDirection = vec3(cos(theta) * r, sin(theta) * r, u);\n \n float rayAngle = dot(up, rayDirection);\n bool cameraBelow = rayAngle < 0.0;\n \n vec3 transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n intersectSphere(rayOrigin, rayDirection, TOP_RADIUS, offset, distanceToSpace);\n \n float distanceToGround = 0.0;\n bool hitGround = intersectSphere(rayOrigin, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0; \n float segmentLength = (hitGround ? distanceToGround : distanceToSpace) / float(SAMPLE_COUNT);\n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera;\n vec3 transmittanceLight;\n \n for (int k = 0; k < SAMPLE_COUNT; k++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDirection);\n \n float distanceToGround;\n float shadow = intersectSphere(position, lightDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround >= 0.0 ? 0.0 : 1.0;\n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n \n vec2 opticalDensity = exp(-height / rayleighMieHeights); \n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y) * isotropicPhase;\n \n light += shadow * transmittanceCamera * scatteredLight * segmentLength;\n lightTransferFactor += transmittanceCamera * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y) * segmentLength;\n \n t += segmentLength;\n }\n \n if (hitGround) \n {\n vec3 hitPoint = rayOrigin + rayDirection * distanceToGround;\n vec3 normal = normalize(hitPoint);\n float diffuseAngle = max(dot(normal, lightDirection), 0.0); \n light += transmittanceCamera * transmittanceLight * GROUND_ALBEDO * diffuseAngle;\n }\n }\n }\n \n light /= float(SAMPLE_COUNT);\n lightTransferFactor /= float(SAMPLE_COUNT);\n vec3 color = light / (1.0 - lightTransferFactor); \n gl_FragColor = vec4(color, 1.0);\n }`})}(this._parameters),!0))}initBackgroundShader(){var e;this.renderer&&this.renderer.handler.addProgram((e=this._parameters,new zi("atmosphereBackground",{uniforms:{iResolution:"vec2",fov:"float",camPos:"vec3",viewMatrix:"mat4",transmittanceTexture:"sampler2D",scatteringTexture:"sampler2D",sunPos:"vec3",opacity:"float"},attributes:{corners:"vec3"},vertexShader:" \n attribute vec2 corners;\n \n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n }",fragmentShader:` \n precision lowp float;\n \n ${Vs(e)}\n \n uniform mat4 viewMatrix;\n uniform vec3 sunPos;\n uniform vec3 camPos; \n uniform vec2 iResolution;\n uniform float fov;\n uniform float opacity;\n \n uniform sampler2D transmittanceTexture;\n uniform sampler2D scatteringTexture;\n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(transmittanceTexture, vec2(u, v)).xyz;\n }\n \n vec3 multipleScatteringContributionFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(scatteringTexture, vec2(u, v)).xyz; \n }\n\n bool intersectEllipsoidToSphere(in vec3 ro, in vec3 rd, in vec3 ellRadii, in float sphereRadius, out float t1, out float t2) \n {\n float offset = 0.0,\n distanceToSpace = 0.0;\n \n if(intersectEllipsoid(ro, rd, ellRadii, offset, distanceToSpace)){\n vec3 hitEll = ro + rd * offset;\n vec3 nEll = normalEllipsoid(hitEll, ellRadii);\n float t = 0.0;\n bool intersectsSphere = intersectSphere(hitEll, nEll, sphereRadius, t);\n vec3 hitSphere = hitEll + nEll * t;\n t1 = length(hitSphere - ro);\n \n hitEll = ro + rd * distanceToSpace;\n nEll = normalEllipsoid(hitEll, ellRadii);\n t = 0.0;\n intersectsSphere = intersectSphere(hitEll, nEll, sphereRadius, t);\n hitSphere = hitEll + nEll * t;\n t2 = length(hitSphere - ro);\n \n return true; \n }\n return false; \n }\n \n mat4 transpose(in mat4 m) \n {\n vec4 i0 = m[0];\n vec4 i1 = m[1];\n vec4 i2 = m[2];\n vec4 i3 = m[3];\n \n mat4 outMatrix = mat4(\n vec4(i0.x, i1.x, i2.x, i3.x),\n vec4(i0.y, i1.y, i2.y, i3.y),\n vec4(i0.z, i1.z, i2.z, i3.z),\n vec4(i0.w, i1.w, i2.w, i3.w)\n );\n \n return outMatrix;\n }\n \n void mainImage(out vec4 fragColor) \n { \n vec3 cameraPosition = camPos;\n \n vec3 lightDirection = normalize(sunPos); \n \n vec2 uv = (2.0 * gl_FragCoord.xy - iResolution.xy) / iResolution.y;\n float fieldOfView = fov;\n float z = 1.0 / tan(fieldOfView * 0.5 * PI / 180.0);\n vec3 rayDirection = normalize(vec3(uv, -z));\n vec4 rd = transpose(viewMatrix) * vec4(rayDirection, 1.0);\n rayDirection = rd.xyz; \n \n vec3 light = vec3(0.0);\n vec3 transmittanceFromCameraToSpace = vec3(1.0);\n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n rayDirection = normalize(rayDirection * SPHERE_TO_ELLIPSOID_SCALE);\n cameraPosition *= SPHERE_TO_ELLIPSOID_SCALE;\n lightDirection = normalize(lightDirection * SPHERE_TO_ELLIPSOID_SCALE);\n \n if(length(cameraPosition) < BOTTOM_RADIUS + 100.0){\n cameraPosition = normalize(cameraPosition) * (BOTTOM_RADIUS + 100.0); \n }\n \n if (intersectSphere(cameraPosition, rayDirection, TOP_RADIUS, offset, distanceToSpace)) \n { \n vec3 rayOrigin = cameraPosition;\n \n // above atmosphere \n if (offset > 0.0) {\n // intersection of camera ray with atmosphere\n rayOrigin = cameraPosition + rayDirection * offset;\n } \n \n float height = length(rayOrigin) - BOTTOM_RADIUS;\n float rayAngle = dot(rayOrigin, rayDirection) / length(rayOrigin);\n bool cameraBelow = rayAngle < 0.0;\n \n transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float phaseAngle = dot(lightDirection, rayDirection);\n float rayleighPhase = rayleighPhase(phaseAngle);\n float miePhase = miePhase(phaseAngle);\n \n float distanceToGround = 0.0;\n \n bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n \n if(intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS - 100000.0, distanceToGround) && hitGround)\n {\n discard;\n }\n \n float segmentLength = ((hitGround ? distanceToGround : distanceToSpace) - max(offset, 0.0)) / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera; \n vec3 transmittanceLight; \n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS; \n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDirection);\n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n vec2 opticalDensity = exp(-height / rayleighMieHeights);\n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x * rayleighPhase + mieScatteringCoefficient * opticalDensity.y * miePhase);\n scatteredLight += multipleScatteringContributionFromTexture(height, lightAngle) * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y); \n light += transmittanceCamera * scatteredLight * segmentLength;\n t += segmentLength;\n }\n \n light *= SUN_INTENSITY;\n \n if (hitGround) \n {\n vec3 hitPoint = cameraPosition + rayDirection * distanceToGround;\n vec3 up = hitPoint / length(hitPoint);\n float diffuseAngle = max(dot(up, lightDirection), 0.0);\n float lightAngle = dot(up, lightDirection);\n light += transmittanceCamera * GROUND_ALBEDO * multipleScatteringContributionFromTexture(height, lightAngle) * SUN_INTENSITY;\n light += transmittanceCamera * transmittanceLight * GROUND_ALBEDO * diffuseAngle * SUN_INTENSITY;\n }\n }\n \n // sun disk\n // float distanceToGround;\n // bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n // if (!hitGround) {\n // float angle = dot(rayDirection, lightDirection);\n // if (angle > cos(SUN_ANGULAR_RADIUS)) {\n // light = SUN_INTENSITY * transmittanceFromCameraToSpace;\n // }\n // }\n \n float distanceToGround = 0.0;\n bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n if(!hitGround)\n {\n vec3 sunLum = sunWithBloom(rayDirection, lightDirection) * vec3(1.0,1.0,0.8);\n // limit the bloom effect\n sunLum = smoothstep(0.002, 1.0, sunLum);\n light += sunLum * SUN_INTENSITY * transmittanceFromCameraToSpace;\n }\n \n fragColor = vec4(pow(light * 8.0, vec3(1.0 / 2.2)), clamp(opacity, 0.0, 1.0)); \n }\n \n void main(void) \n { \n mainImage(gl_FragColor); \n }`})),!0)}removeBackgroundShader(){this.renderer&&this.renderer.handler.removeProgram("atmosphereBackground")}removeLookupTexturesShaders(){if(this.renderer){let e=this.renderer.handler;this._scatteringBuffer?.isComplete()&&e.removeProgram("scattering"),this._transmittanceBuffer?.isComplete()&&e.removeProgram("transmittance")}}onactivate(){super.onactivate(),this.planet&&this.planet.events.on("draw",this._drawBackground,this)}ondeactivate(){super.ondeactivate(),this.planet&&this.planet.events.off("draw",this._drawBackground)}_initLookupTextures(){this._transmittanceBuffer=new $s(this.renderer.handler,{width:1024,height:1024,useDepth:!1,filter:"LINEAR",type:"FLOAT",internalFormat:"RGBA16F"}),this._transmittanceBuffer.init(),this._scatteringBuffer=new $s(this.renderer.handler,{width:1024,height:1024,useDepth:!1,filter:"LINEAR",type:"FLOAT",internalFormat:"RGBA16F"}),this._scatteringBuffer.init()}_renderLookupTextures(){if(!this.renderer)return;let e=this.renderer.screenFramePositionBuffer,t=this.renderer.handler,i=t.gl;if(this._transmittanceBuffer){this._transmittanceBuffer.activate();let n=t.programs.transmittance,r=n._program.attributes,s=n._program.uniforms;n.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(s.iResolution,[this._transmittanceBuffer.width,this._transmittanceBuffer.height]),i.bindBuffer(i.ARRAY_BUFFER,e),i.vertexAttribPointer(r.a_position,e.itemSize,i.FLOAT,!1,0,0),i.drawArrays(i.TRIANGLE_STRIP,0,e.numItems),this._transmittanceBuffer.deactivate()}if(this._scatteringBuffer&&this._transmittanceBuffer){this._scatteringBuffer.activate();let n=t.programs.scattering,r=n._program.attributes,s=n._program.uniforms;n.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(s.iResolution,[this._scatteringBuffer.width,this._scatteringBuffer.height]),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._transmittanceBuffer.textures[0]),i.uniform1i(s.transmittanceTexture,0),i.bindBuffer(i.ARRAY_BUFFER,e),i.vertexAttribPointer(r.a_position,e.itemSize,i.FLOAT,!1,0,0),i.drawArrays(i.TRIANGLE_STRIP,0,e.numItems),this._scatteringBuffer.deactivate()}}drawLookupTextures(){this._renderLookupTextures()}_drawBackground(){let e=this.renderer.handler,t=e.programs.atmosphereBackground,i=t._program,n=i.uniforms,r=e.gl,s=this.renderer,a=this.planet.camera;r.disable(r.DEPTH_TEST),t.activate(),r.bindBuffer(r.ARRAY_BUFFER,s.screenFramePositionBuffer),r.vertexAttribPointer(i.attributes.corners,2,r.FLOAT,!1,0,0),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this._transmittanceBuffer.textures[0]),r.uniform1i(n.transmittanceTexture,0),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,this._scatteringBuffer.textures[0]),r.uniform1i(n.scatteringTexture,1),r.uniformMatrix4fv(n.viewMatrix,!1,a.getViewMatrix());let o=this.planet.sunPos;r.uniform3fv(n.sunPos,[o.x,o.y,o.z]),r.uniform3fv(n.camPos,[a.eye.x,a.eye.y,a.eye.z]),r.uniform2fv(n.iResolution,[s.sceneFramebuffer.width,s.sceneFramebuffer.height]),r.uniform1f(n.fov,a.getViewAngle()),r.uniform1f(n.opacity,this.opacity),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST)}}const Ks="degrees",Qs="m";let Js=0;class ea{constructor(e){this.id=Js++,this.code=e.code,this.units=e.units}equal(e){return e.id===this.id}}const ta=new ea({code:"epsg:3857",units:Qs}),ia=new ea({code:"epsg:4326",units:Ks});class na{constructor(e){this.segment=e,this.layers=[],this.tileOffsetArr=new Float32Array(e.planet.SLICE_SIZE_4),this.layerOpacityArr=new Float32Array(e.planet.SLICE_SIZE)}clear(){this.layers=null,this.tileOffsetArr=null,this.layerOpacityArr=null}append(e,t){let i=this.layers.length;this.layers.push(e),this.layerOpacityArr[i]=e.screenOpacity;let n=4*i,r=e.applyMaterial(t);this.tileOffsetArr[n]=r[0],this.tileOffsetArr[n+1]=r[1],this.tileOffsetArr[n+2]=r[2],this.tileOffsetArr[n+3]=r[3]}}function ra(e,t,i){return Math.floor(Math.abs(i-e)/t)}function sa(e,t,i,n){let r=1/(1<<i),s=n.getWidth()*r,a=n.getHeight()*r,o=n.southWest.lon+e*s,l=n.northEast.lat-t*a;return new ie(new z(o,l-a),new z(o+s,l))}const aa=20,oa=300;let la=new oe,ha=new oe,ca=new oe,da=new oe,_a=new oe,ua=new oe,fa=new _i,ga=new _i;const pa=new Array(4);pa[0]=0,pa[1]=1,pa[2]=1,pa[3]=0;const ma=new Array(4);ma[0]=!1,ma[1]=!0,ma[2]=!1,ma[3]=!0;class va{constructor(e,t,i,n){this.isPole=!1,this._tileGroup=0,this._projection=ta,this.node=e,this.planet=t,this.handler=t.renderer.handler,this.bsphere=new At,this._plainRadius=0,this.bbox=new Lt,this._sw=new oe,this._nw=new oe,this._se=new oe,this._ne=new oe,this.centerNormal=new oe,this._extent=this._extentMerc=n,this._extentLonLat=new ie,this.gridSize=t.terrain.gridSizeByZoom[i],this.fileGridSize=0,this.tileZoom=i,this.powTileZoom=1<<i,this.tileX=0,this.tileXE=0,this.tileXW=0,this.tileYN=0,this.tileYS=0,this.tileY=0,this.tileIndex="",this.elevationData=null,this._assignTileIndexes(),this.materials=[],this.plainReady=!1,this.initialized=!1,this.normalMapReady=!1,this.terrainReady=!1,this.terrainIsLoading=!1,this.terrainExists=!1,this.passReady=!1,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapTexture=null,this.normalMapTextureBias=new Float32Array(3),this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null,this._globalTextureCoordinates=new Float32Array(4),this._inTheQueue=!1,this._appliedNeighborsZoom=[0,0,0,0],this._slices=[],this._indexBuffer=null,this.readyToEngage=!1,this.plainProcessing=!1,this.normalMapTexturePtr=null,this._transitionOpacity=1,this._transitionTimestamp=0}checkZoom(){return this.tileZoom<this.planet.terrain._maxNodeZoom}getEntityTerrainPoint(e,t){return this.getTerrainPoint(e._cartesian,this.getInsideLonLat(e),t)}getInsideLonLat(e){return e._lonLatMerc}isEntityInside(e){return this._extentLonLat.isInside(e._lonLat)}getTerrainPoint(e,t,i){let n=this.tempVertices;if(n&&n.length){let r=this.planet.ellipsoid.getSurfaceNormal3v(e);fa.set(e,r.negateTo());let s=this._extent.northEast,a=this._extent.southWest,o=Math.sqrt(n.length/3)-1,l=s.lon,h=s.lat,c=a.lon,d=a.lat,_=(l-c)/o,u=(h-d)/o,f=t.lon-c,g=t.lat-d,p=Math.floor(f/_),m=Math.floor(o-g/u),v=3*((o+1)*m+p),y=3*((o+1)*(m+1)+p);ca.set(n[v],n[v+1],n[v+2]),da.set(n[v+3],n[v+4],n[v+5]),_a.set(n[y],n[y+1],n[y+2]);let x=fa.hitTriangle(ca,da,_a,i);if(x===_i.INSIDE)return e.distance(i);if(x===_i.AWAY){if(ga.set(e,r),ga.hitTriangle(ca,da,_a,i)===_i.INSIDE)return-e.distance(i)}if(ua.set(n[y+3],n[y+4],n[y+5]),x=fa.hitTriangle(da,ua,_a,i),x===_i.INSIDE)return e.distance(i);if(x===_i.AWAY){if(ga.set(e,r),ga.hitTriangle(da,ua,_a,i)===_i.INSIDE)return-e.distance(i)}return x===_i.AWAY?-e.distance(i):e.distance(i)}return e.distance(this.planet.ellipsoid.hitRay(fa.origin,fa.direction))}projectNative(e){return e.forwardMercator()}loadTerrain(e=!1){this.tileZoom<this.planet.terrain.minZoom||this.planet.terrain.isEmpty?(this.terrainIsLoading=!0,this.elevationsNotExists(),this._inTheQueue||this.planet._normalMapCreator.queue(this)):this.tileZoom>this.planet.terrain.maxZoom?this.elevationsNotExists():this.terrainIsLoading||this.terrainReady||this.planet.terrain.loadTerrain(this,e)}elevationsExists(e){if(this.plainReady&&this.terrainIsLoading){let t=new Float32Array(e.length);t.set(e),this.elevationData=new Float32Array(e.length),this.elevationData.set(e),this.planet._terrainWorker.make({segment:this,elevations:t}),this.plainVerticesHigh=null,this.plainVerticesLow=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.planet.terrain.equalizeVertices||(this.tempVerticesHigh=null,this.tempVerticesLow=null)}}elevationsNotExists(){if(this.planet&&this.tileZoom<=this.planet.terrain.maxNativeZoom){if(this.plainReady&&this.terrainIsLoading){this.terrainIsLoading=!1;let e=this.node;e.appliedTerrainNodeId=this.node.nodeId,e.equalizedSideWithNodeId[0]=e.equalizedSideWithNodeId[1]=e.equalizedSideWithNodeId[2]=e.equalizedSideWithNodeId[3]=e.appliedTerrainNodeId,this.planet.lightEnabled&&!this._inTheQueue&&this.planet._normalMapCreator.queue(this),this.readyToEngage=!0}this.terrainVertices=this.plainVertices,this.terrainVerticesHigh=this.plainVerticesHigh,this.terrainVerticesLow=this.plainVerticesLow,this.tempVertices=this.terrainVertices,this.tempVerticesHigh=this.terrainVerticesHigh,this.tempVerticesLow=this.terrainVerticesLow,this.noDataVertices=null,this.fileGridSize=Math.sqrt(this.terrainVertices.length/3)-1,this.gridSize=this.fileGridSize,this.terrainReady=!0,this.terrainExists=!1}else if(this.plainReady&&this.terrainIsLoading){this.terrainIsLoading=!1;let e=this.node;e.appliedTerrainNodeId=this.node.nodeId,e.equalizedSideWithNodeId[0]=e.equalizedSideWithNodeId[1]=e.equalizedSideWithNodeId[2]=e.equalizedSideWithNodeId[3]=e.appliedTerrainNodeId,this.readyToEngage=!0,this.terrainReady=!0,this.passReady=!0,this.terrainExists=!1}}_checkEqualization(e,t){return t&&t.segment&&this.tileZoom>=t.segment.tileZoom&&this.node.equalizedSideWithNodeId[e]!==t.equalizedSideWithNodeId[Vt[e]]}equalize(){if(this.tileZoom<2||this.gridSize<2)return;this.readyToEngage=!0;let e=this.node.neighbors,t=this.tempVertices,i=this.tempVerticesHigh,n=this.tempVerticesLow,r=this.gridSize,s=r+1,a=e[0][0];if(this._checkEqualization(0,a)){this.node.equalizedSideWithNodeId[0]=a.equalizedSideWithNodeId[2],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(a,0),o=a.segment.tempVertices,l=a.segment.tempVerticesHigh,h=a.segment.tempVerticesLow,c=a.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-a.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let r=0,a=e*c;r<s;r+=u,a+=f){const e=3*r,s=3*(d*c+a);t[e]=o[s],t[e+1]=o[s+1],t[e+2]=o[s+2],i[e]=l[s],i[e+1]=l[s+1],i[e+2]=l[s+2],n[e]=h[s],n[e+1]=h[s+1],n[e+2]=h[s+2]}}if(a=e[1][0],this._checkEqualization(1,a)){this.node.equalizedSideWithNodeId[1]=a.equalizedSideWithNodeId[3],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(a,1),o=a.segment.tempVertices,l=a.segment.tempVerticesHigh,h=a.segment.tempVerticesLow,c=a.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-a.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let a=0,_=e*c;a<s;a+=u,_+=f){const e=3*(s*a+r),c=d*_*3;t[e]=o[c],t[e+1]=o[c+1],t[e+2]=o[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],n[e]=h[c],n[e+1]=h[c+1],n[e+2]=h[c+2]}}if(a=e[2][0],this._checkEqualization(2,a)){this.node.equalizedSideWithNodeId[2]=a.equalizedSideWithNodeId[0],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(a,2),o=a.segment.tempVertices,l=a.segment.tempVerticesHigh,h=a.segment.tempVerticesLow,c=a.segment.gridSize,d=1/(1<<this.tileZoom-a.segment.tileZoom),_=Math.max(r/(c*d),1),u=Math.max(c*d/r,1);for(let a=0,d=e*c;a<s;a+=_,d+=u){const e=3*(s*r+a),c=3*d;t[e]=o[c],t[e+1]=o[c+1],t[e+2]=o[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],n[e]=h[c],n[e+1]=h[c+1],n[e+2]=h[c+2]}}if(a=e[3][0],this._checkEqualization(3,a)){this.node.equalizedSideWithNodeId[3]=a.equalizedSideWithNodeId[1],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(a,3),o=a.segment.tempVertices,l=a.segment.tempVerticesHigh,h=a.segment.tempVerticesLow,c=a.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-a.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let r=0,a=e*c;r<s;r+=u,a+=f){const e=s*r*3,_=3*(d*a+c);t[e]=o[_],t[e+1]=o[_+1],t[e+2]=o[_+2],i[e]=l[_],i[e+1]=l[_+1],i[e+2]=l[_+2],n[e]=h[_],n[e+1]=h[_+1],n[e+2]=h[_+2]}}}engage(){this.readyToEngage=!1,this.createCoordsBuffers(this.tempVerticesHigh,this.tempVerticesLow,this.gridSize)}_terrainWorkerCallback(e){if(this.plainReady){this.readyToEngage=!0,this.normalMapNormals=null,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapNormals=e.normalMapNormals,this.normalMapVertices=e.normalMapVertices,this.normalMapVerticesHigh=e.normalMapVerticesHigh,this.normalMapVerticesLow=e.normalMapVerticesLow,this.terrainVertices=e.terrainVertices,this.terrainVerticesHigh=e.terrainVerticesHigh,this.terrainVerticesLow=e.terrainVerticesLow,this.noDataVertices=e.noDataVertices,this.tempVertices=this.terrainVertices,this.tempVerticesHigh=this.terrainVerticesHigh,this.tempVerticesLow=this.terrainVerticesLow,this.setBoundingVolumeArr(e.bounds),this.gridSize=Math.sqrt(this.terrainVertices.length/3)-1;let t=this.node;if(t.appliedTerrainNodeId=t.nodeId,t.equalizedSideWithNodeId[0]=t.equalizedSideWithNodeId[1]=t.equalizedSideWithNodeId[2]=t.equalizedSideWithNodeId[3]=t.appliedTerrainNodeId,this.terrainReady=!0,this.terrainIsLoading=!1,this.terrainExists=!0,!this.normalMapTexturePtr){const e=this.planet._normalMapCreator;this.normalMapTexturePtr=this.planet.renderer.handler.createEmptyTexture_l(e.width,e.height)}this.planet.lightEnabled&&this.planet._normalMapCreator.queue(this)}}_normalMapEdgeEqualize(e){let t=this.node.neighbors,i=t[e],n=i&&i[0],r=this.planet.terrain.maxZoom;this.tileZoom===r&&i&&!(t[0].length||t[1].length||t[2].length||t[3].length)&&(n=this.node.getEqualNeighbor(e));let s=n&&n.segment,a=this;if(n&&s&&s.terrainReady&&s.terrainExists&&s.tileZoom<=r&&a._appliedNeighborsZoom[e]!==s.tileZoom){a._appliedNeighborsZoom[e]=s.tileZoom;let t=a.normalMapNormals,i=s.normalMapNormals;if(!t||!i)return;let n=a.normalMapNormals,r=s.normalMapNormals,o=Math.sqrt(t.length/3),l=o-1;const h=l*pa[e];let c,d,_,u;if(a.tileZoom===s.tileZoom){const f=l-h;if(ma[e])for(let e=0;e<o;e++){let s=3*(e*o+h),a=3*(e*o+f);c=n[s]+r[a],d=n[s+1]+r[a+1],_=n[s+2]+r[a+2],u=1/Math.sqrt(c*c+d*d+_*_),i[a]=t[s]=c*u,i[a+1]=t[s+1]=d*u,i[a+2]=t[s+2]=_*u}else for(let e=0;e<o;e++){let s=3*(h*o+e),a=3*(f*o+e);c=n[s]+r[a],d=n[s+1]+r[a+1],_=n[s+2]+r[a+2],u=1/Math.sqrt(c*c+d*d+_*_),i[a]=t[s]=c*u,i[a+1]=t[s+1]=d*u,i[a+2]=t[s+2]=_*u}s._inTheQueue||s._appliedNeighborsZoom[Vt[e]]===a.tileZoom||(s._appliedNeighborsZoom[Vt[e]]=a.tileZoom,a.planet._normalMapCreator.queue(s))}}}applyTerrain(e){e?this.elevationsExists(e):this.elevationsNotExists()}deleteBuffers(){const e=this.handler.gl;e.deleteBuffer(this.vertexNormalBuffer),e.deleteBuffer(this.vertexPositionBuffer),e.deleteBuffer(this.vertexPositionBufferHigh),e.deleteBuffer(this.vertexPositionBufferLow),this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null}deleteMaterials(){let e=this.materials;for(let t=0;t<e.length;t++){let i=e[t];i&&i.clear()}this.materials.length=0}deleteElevations(){this.terrainExists=!1,this.terrainReady=!1,this.terrainIsLoading=!1,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.normalMapReady&&(this.handler.gl.deleteTexture(this.normalMapTexture),this.normalMapReady=!1),this._appliedNeighborsZoom=[0,0,0,0],this.normalMapTextureBias[0]=0,this.normalMapTextureBias[1]=0,this.normalMapTextureBias[2]=1,this._inTheQueue=!1}clearSegment(){this.plainReady=!1,this.initialized=!1,this.deleteBuffers(),this.deleteMaterials(),this.deleteElevations()}childrenInitialized(){let e=this.node.nodes;return 4===e.length&&e[0].segment.initialized&&e[1].segment.initialized&&e[2].segment.initialized&&e[3].segment.initialized}destroySegment(){this.clearSegment();let e=this._slices.length;for(;e--;)this._slices[e].clear();this._slices=null,this.node=null,this.planet=null,this.handler=null,this.bbox=null,this.bsphere=null,this._extent=null,this.materials=null,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapTextureBias=null,this.normalMapTexture=null,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null,this._projection=null,this._appliedNeighborsZoom=null,this._globalTextureCoordinates=null}_setExtentLonLat(){this._extentLonLat=this._extent.inverseMercator()}_createExtentNormals(){const e=this.planet.ellipsoid,t=this._extentLonLat,i=e.geodeticToCartesian(t.southWest.lon,t.southWest.lat),n=e.geodeticToCartesian(t.northEast.lon,t.northEast.lat),r=e.geodeticToCartesian(t.southWest.lon,t.northEast.lat),s=e.geodeticToCartesian(t.northEast.lon,t.southWest.lat);this._sw.copy(i),this._nw.copy(r),this._ne.copy(n),this._se.copy(s)}createBoundsByExtent(){this._createExtentNormals(),this.setBoundingVolume3v(this._sw,this._ne)}createBoundsByParent(){let e=this.node;for(;e.parentNode&&!e.segment.terrainReady;)e=e.parentNode;let t=1<<this.tileZoom-e.segment.tileZoom,i=this.tileX-e.segment.tileX*t,n=this.tileY-e.segment.tileY*t;if(e.segment.terrainReady&&e.segment.tileZoom>=this.planet.terrain.minZoom){let r=e.segment.gridSize/t;if(r>=1){this.bsphere.center.x=e.segment.bsphere.center.x,this.bsphere.center.y=e.segment.bsphere.center.y,this.bsphere.center.z=e.segment.bsphere.center.z,this.bsphere.radius=e.segment.bsphere.radius;let t=r*n,s=r*i,a=e.segment.gridSize+1,o=3*((t+r)*a+s),l=3*(t*a+s),h=3*(t*a+s+r),c=3*((t+r)*a+s+r),d=e.segment.tempVertices,_=new oe(d[o],d[o+1],d[o+2]),u=new oe(d[h],d[h+1],d[h+2]),f=new oe(d[l],d[l+1],d[l+2]),g=new oe(d[c],d[c+1],d[c+2]);this._sw.copy(_),this._nw.copy(f),this._ne.copy(u),this._se.copy(g)}else{let t,s=e.segment,a=Math.floor(r*n),o=Math.floor(r*i),l=1/r,h=n-l*a,c=i-l*o;t=1===s.gridSize?s.tempVertices:We(s.tempVertices,s.gridSize,a,o,1);let d,_,u=new oe(t[0],t[1],t[2]),f=new oe(t[9],t[10],t[11]),g=new oe(t[3]-t[0],t[4]-t[1],t[5]-t[2]),p=new oe(t[6]-t[0],t[7]-t[1],t[8]-t[2]),m=new oe(t[3]-t[9],t[4]-t[10],t[5]-t[11]),v=new oe(t[6]-t[9],t[7]-t[10],t[8]-t[11]),y=h,x=c;d=y+x<l?oe.add(g.scaleTo(x/l),p.scaleTo(y/l)).addA(u):oe.add(v.scaleTo(1-x/l),m.scaleTo(1-y/l)).addA(f),y=h+1,x=c+1,_=y+x<l?oe.add(g.scaleTo(x/l),p.scaleTo(y/l)).addA(u):oe.add(v.scaleTo(1-x/l),m.scaleTo(1-y/l)).addA(f),this._createExtentNormals(),this.setBoundingVolume3v(d,_)}}else this.createBoundsByExtent()}setBoundingSphere(e,t,i,n){this.bsphere.center.x=e,this.bsphere.center.y=t,this.bsphere.center.z=i,this.bsphere.radius=this.bsphere.center.distance(n)}setBoundingVolume(e,t,i,n,r,s){this.bbox.setFromBoundsArr([e,t,i,n,r,s]);let a=e+.5*(n-e),o=t+.5*(r-t),l=i+.5*(s-i);this.bsphere.center.set(a,o,l),this.bsphere.radius=this.bsphere.center.distance(new oe(e,t,i))}setBoundingVolume3v(e,t){this.bbox.setFromBoundsArr([e.x,e.y,e.z,t.x,t.y,t.z]);let i=e.x+.5*(t.x-e.x),n=e.y+.5*(t.y-e.y),r=e.z+.5*(t.z-e.z);this.bsphere.center.set(i,n,r),this.bsphere.radius=this.bsphere.center.distance(new oe(e.x,e.y,e.z))}setBoundingVolumeArr(e){this.bbox.setFromBoundsArr(e);let t=e[0]+.5*(e[3]-e[0]),i=e[1]+.5*(e[4]-e[1]),n=e[2]+.5*(e[5]-e[2]);this.bsphere.center.set(t,i,n),this.bsphere.radius=this.bsphere.center.distance(new oe(e[0],e[1],e[2]))}createCoordsBuffers(e,t,i){const n=(i+1)*(i+1),r=this.handler;this.vertexPositionBufferHigh&&this.vertexPositionBufferHigh.numItems===n?(r.setStreamArrayBuffer(this.vertexPositionBufferHigh,e),r.setStreamArrayBuffer(this.vertexPositionBufferLow,t)):(r.gl.deleteBuffer(this.vertexPositionBufferHigh),r.gl.deleteBuffer(this.vertexPositionBufferLow),this.vertexTextureCoordBuffer=this.planet._textureCoordsBufferCache[Math.log2(i)],this.vertexPositionBufferHigh=r.createArrayBuffer(e,3,n),this.vertexPositionBufferLow=r.createArrayBuffer(t,3,n))}_addViewExtent(){const e=this._extentLonLat;let t=this.planet._viewExtent;e.southWest.lon<t.southWest.lon&&(t.southWest.lon=e.southWest.lon),e.northEast.lon>t.northEast.lon&&(t.northEast.lon=e.northEast.lon),e.southWest.lat<t.southWest.lat&&(t.southWest.lat=e.southWest.lat),e.northEast.lat>t.northEast.lat&&(t.northEast.lat=e.northEast.lat)}_assignTileIndexes(){this._tileGroup=0;const e=this.tileZoom,t=this._extent,i=D;this.tileX=ra(t.getCenter().lon,t.getWidth(),-i),this.tileY=ra(t.getCenter().lat,t.getHeight(),i);const n=this.powTileZoom;this.tileXE=(this.tileX+1)%n,this.tileXW=(n+this.tileX-1)%n,this.tileYN=this.tileY-1,this.tileYS=this.tileY+1,this.tileIndex=qt.getTileIndex(this.tileX,this.tileY,e,this._tileGroup)}initialize(){const e=this.planet,t=this.node;if(this.gridSize=e.terrain.gridSizeByZoom[this.tileZoom]||e.terrain.plainGridSize,t.sideSizeLog2[0]=t.sideSizeLog2[1]=t.sideSizeLog2[2]=t.sideSizeLog2[3]=Math.log2(this.gridSize),this.tileZoom<=e.terrain.maxZoom){const t=this.planet._normalMapCreator;this.normalMapTexturePtr=e.renderer.handler.createEmptyTexture_l(t.width,t.height)}this.normalMapTexture=this.planet.transparentTexture,this._assignGlobalTextureCoordinates(),this.initialized=!0}_assignGlobalTextureCoordinates(){const e=this._extent;this._globalTextureCoordinates[0]=(e.southWest.lon+D)*q,this._globalTextureCoordinates[1]=(D-e.northEast.lat)*q,this._globalTextureCoordinates[2]=(e.northEast.lon+D)*q,this._globalTextureCoordinates[3]=(D-e.southWest.lat)*q}createPlainSegmentAsync(){let e=this.planet,t=e.terrain;t.isReady()&&!this.plainReady&&this.tileZoom<=t.maxZoom&&(this.plainProcessing=!0,e._plainSegmentWorker.make(this))}_plainSegmentWorkerCallback(e){this.plainProcessing=!1,this.initialized&&!this.terrainReady&&(this.plainReady=!0,this.plainVertices=e.plainVertices,this.plainVerticesHigh=e.plainVerticesHigh,this.plainVerticesLow=e.plainVerticesLow,this.plainNormals=e.plainNormals,this._plainRadius=e.plainRadius,this.normalMapNormals=e.normalMapNormals,this.normalMapVertices=e.normalMapVertices,this.normalMapVerticesHigh=e.normalMapVerticesHigh,this.normalMapVerticesLow=e.normalMapVerticesLow,this.fileGridSize=Math.sqrt(e.normalMapVertices.length/3)-1)}createPlainSegment(){this.initialize(),this._createPlainVertices(),this.readyToEngage=!0}_projToDeg(e,t){return z.inverseMercator(e,t)}_createPlainVertices(){const e=this.planet.terrain.gridSizeByZoom[this.tileZoom],t=this.planet.terrain.plainGridSize,i=Math.max(t,e),n=this._extent,r=n.getWidth()/i,s=n.getHeight()/i,a=n.southWest.lon,o=n.northEast.lat,l=Math.max(t/e,1),h=i+1,c=this.planet.ellipsoid._invRadii2,d=h*h,_=(e+1)*(e+1)*3;let u=0,f=0;this.plainNormals=new Float32Array(_),this.plainVertices=new Float64Array(_),this.plainVerticesHigh=new Float32Array(_),this.plainVerticesLow=new Float32Array(_),this.normalMapNormals=new Float32Array(3*d),this.normalMapVertices=new Float64Array(3*d),this.normalMapVerticesHigh=new Float32Array(3*d),this.normalMapVerticesLow=new Float32Array(3*d);let g=this.plainVertices,p=this.plainVerticesHigh,m=this.plainVerticesLow,v=this.plainNormals,y=this.normalMapVertices,x=this.normalMapVerticesHigh,b=this.normalMapVerticesLow,w=this.normalMapNormals;for(let e=0;e<d;e++){let t=e%h,i=~~(e/h),n=this.planet.ellipsoid.lonLatToCartesian(this._projToDeg(a+t*r,o-i*s)),d=n.x*c.x,_=n.y*c.y,C=n.z*c.z,T=1/Math.sqrt(d*d+_*_+C*C),L=d*T,A=_*T,E=C*T;oe.doubleToTwoFloats(n,la,ha),y[f]=n.x,x[f]=la.x,b[f]=ha.x,w[f++]=L,y[f]=n.y,x[f]=la.y,b[f]=ha.y,w[f++]=A,y[f]=n.z,x[f]=la.z,b[f]=ha.z,w[f++]=E,i%l==0&&t%l==0&&(g[u]=n.x,p[u]=la.x,m[u]=ha.x,v[u++]=L,g[u]=n.y,p[u]=la.y,m[u]=ha.y,v[u++]=A,g[u]=n.z,p[u]=la.z,m[u]=ha.z,v[u++]=E)}this.terrainVertices=g,this.terrainVerticesHigh=p,this.terrainVerticesLow=m,this.plainReady=!0}getMaterialByLayer(e){return this.materials[e.__id]}_getLayerExtentOffset(e){const t=e._extentMerc,i=this._extent,n=t.northEast.lon-t.southWest.lon,r=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/n,(t.northEast.lat-i.northEast.lat)/r,(i.northEast.lon-i.southWest.lon)/n,(i.northEast.lat-i.southWest.lat)/r]}initSlice(e){let t=this._slices[e];return t?t.layers=[]:t=this._slices[e]=new na(this),t}screenRendering(e,t,i,n,r=!1,s){const a=this.handler.gl,o=e.attributes,l=e.uniforms,h=this.materials,c=this.planet;let d,_;t&&t.length?(_=t[0],d=_._height):d=0,a.activeTexture(a.TEXTURE0+c.SLICE_SIZE+2),a.bindTexture(a.TEXTURE_2D,n||this.getDefaultTexture()),a.uniform1i(l.defaultTexture,c.SLICE_SIZE+2);let u=0,f=0,g=!1,p=this.initSlice(i);for(this._indexBuffer=this._getIndexBuffer();_;){if(this.layerOverlap(_)&&(_._fading&&_._fadingOpacity>0||(_.minZoom>=c.minCurrZoom||_.maxZoom>=c.minCurrZoom)&&(_.minZoom<=c.maxCurrZoom||_.maxZoom<=c.maxCurrZoom))){g=!0;let e=h[_.__id];e||(e=h[_.__id]=_.createMaterial(this)),e.isReady||(this.planet._renderCompleted=!1),p.append(_,e),c._samplerArr[u]=u,a.activeTexture(a.TEXTURE0+u),a.bindTexture(a.TEXTURE_2D,e.texture||c.transparentTexture),u++}f++,_=t[f]}!g&&r||(a.uniform1f(l.transitionOpacity,s||this._transitionOpacity>1?1:this._transitionOpacity),a.uniform1i(l.samplerCount,u),a.uniform1f(l.height,d),a.uniform1iv(l.samplerArr,c._samplerArr),a.uniform4fv(l.tileOffsetArr,p.tileOffsetArr),a.uniform1fv(l.layerOpacityArr,p.layerOpacityArr),c.lightEnabled&&(a.activeTexture(a.TEXTURE0+c.SLICE_SIZE+3),a.bindTexture(a.TEXTURE_2D,this.normalMapTexture||c.transparentTexture),a.uniform1i(l.uNormalMap,c.SLICE_SIZE+3),a.uniform3fv(l.uNormalMapBias,this.normalMapTextureBias),a.uniform4fv(l.uGlobalTextureCoord,this._globalTextureCoordinates)),a.bindBuffer(a.ARRAY_BUFFER,this.vertexPositionBufferHigh),a.vertexAttribPointer(o.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,this.vertexPositionBufferLow),a.vertexAttribPointer(o.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,this.vertexTextureCoordBuffer),a.vertexAttribPointer(o.aTextureCoord,2,a.UNSIGNED_SHORT,!0,0,0),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBuffer),a.drawElements(c.drawMode,this._indexBuffer.numItems,a.UNSIGNED_INT,0))}heightPickingRendering(e,t){const i=this.handler.gl,n=e.attributes,r=e.uniforms;let s;s=t&&t.length?t[0]._height:0,i.uniform1f(r.height,s),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferHigh),i.vertexAttribPointer(n.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferLow),i.vertexAttribPointer(n.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,this._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,this._indexBuffer.numItems,i.UNSIGNED_INT,0)}increaseTransitionOpacity(){this._transitionOpacity+=(window.performance.now()-this._transitionTimestamp)/this.planet.transitionTime,this._transitionTimestamp=window.performance.now(),this._transitionOpacity>2&&(this._transitionOpacity=2);let e=this.node._fadingNodes.length;for(;e--;){let t=this.node._fadingNodes[e];if(!t.segment){this._transitionOpacity=1;break}t.segment._transitionOpacity>0&&!this.planet._fadingNodes.has(t.__id)&&(this.planet._fadingNodes.set(t.__id,t),t.segment._transitionOpacity=2-this._transitionOpacity,0===t.segment._transitionOpacity&&this.node._fadingNodes.splice(e,1))}}fadingTransitionOpacity(){this._transitionOpacity-=.01,this._transitionTimestamp=window.performance.now(),this._transitionOpacity<0&&(this._transitionOpacity=0)}colorPickingRendering(e,t,i,n,r=!1){const s=this.handler.gl,a=e.attributes,o=e.uniforms;let l,h=this.materials,c=this.planet;l=t&&t.length?t[0]._height:0;let d=!1,_=this._slices[i],u=_.layers.length;for(let e=0;e<u;e++){d=!0;let t=_.layers[e],i=4*e;c._pickingColorArr[i]=t._pickingColor.x/255,c._pickingColorArr[i+1]=t._pickingColor.y/255,c._pickingColorArr[i+2]=t._pickingColor.z/255,c._pickingColorArr[i+3]=Number(t._pickingEnabled),c._samplerArr[e]=e,s.activeTexture(s.TEXTURE0+e),s.bindTexture(s.TEXTURE_2D,h[t.__id].texture||this.planet.transparentTexture),c._pickingMaskArr[e]=e+c.SLICE_SIZE,s.activeTexture(s.TEXTURE0+e+c.SLICE_SIZE),s.bindTexture(s.TEXTURE_2D,h[t.__id].pickingMask||this.planet.transparentTexture)}!d&&r||(s.uniform1i(o.samplerCount,u),s.uniform1f(o.height,l),s.uniform1iv(o.samplerArr,c._samplerArr),s.uniform1iv(o.pickingMaskArr,c._pickingMaskArr),s.uniform4fv(o.pickingColorArr,c._pickingColorArr),s.uniform4fv(o.tileOffsetArr,_.tileOffsetArr),s.uniform1fv(o.layerOpacityArr,_.layerOpacityArr),s.bindBuffer(s.ARRAY_BUFFER,this.vertexPositionBufferHigh),s.vertexAttribPointer(a.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this.vertexPositionBufferLow),s.vertexAttribPointer(a.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this.vertexTextureCoordBuffer),s.vertexAttribPointer(a.aTextureCoord,2,s.UNSIGNED_SHORT,!0,0,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,this._indexBuffer),s.drawElements(s.TRIANGLE_STRIP,this._indexBuffer.numItems,s.UNSIGNED_INT,0))}depthRendering(e,t){const i=this.handler.gl,n=e.attributes,r=e.uniforms;var s;s=t&&t.length?t[0]._height:0,i.uniform1f(r.height,s),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferHigh),i.vertexAttribPointer(n.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferLow),i.vertexAttribPointer(n.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,this._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,this._indexBuffer.numItems,i.UNSIGNED_INT,0)}_getIndexBuffer(){const e=this.node.sideSizeLog2;let t=this.planet._indexesCache[Math.log2(this.gridSize)][e[0]][e[1]][e[2]][e[3]];if(!t.buffer){let i=Ns().createSegmentIndexes(Math.log2(this.gridSize),[e[0],e[1],e[2],e[3]]);t.buffer=this.planet.renderer.handler.createElementArrayBuffer(i,1),this.planet._indexesCacheToRemoveCounter++}return t.buffer}_collectVisibleNodes(){this.planet._visibleNodes[this.node.nodeId]=this.node}layerOverlap(e){return this._extent.overlaps(e._extentMerc)}getDefaultTexture(){return this.planet.solidTextureOne}getExtentLonLat(){return this._extentLonLat}getExtentMerc(){return this._extentMerc}getExtent(){return this._extent}getNeighborSide(e){if(this.tileY===e.tileY){if(this.tileX===e.tileXE)return 3;if(this.tileX===e.tileXW)return 1}else if(this.tileX===e.tileX){if(this.tileY===e.tileYS)return 0;if(this.tileY===e.tileYN)return 2}return-1}}let ya=new oe,xa=new oe;const ba=[new le(0,0),new le(1,0),new le(0,1),new le(1,1)],wa=Math.sqrt(ba.length)-1;let Ca={xmin:0,ymin:0,zmin:0,xmax:0,ymax:0,zmax:0},Ta=0,La=class e{constructor(e,t,i,n,r,s){t._createdNodesCount++,this.__id=Ta++,this.SegmentPrototype=e,this.planet=t,this.parentNode=n,this.partId=i,this.nodeId=i+(n?4*n.nodeId+1:0),this.state=null,this.prevState=null,this.appliedTerrainNodeId=-1,this.sideSizeLog2=[0,0,0,0],this.ready=!1,this.neighbors=[[],[],[],[]],this.equalizedSideWithNodeId=[this.nodeId,this.nodeId,this.nodeId,this.nodeId],this.nodes=[],this.segment=new e(this,t,r,s),this._cameraInside=!1,this.inFrustum=0,this._fadingNodes=[],this.createBounds()}createChildrenNodes(){this.ready=!0;const t=this.planet,i=this.segment,n=i._extent,r=i.tileZoom+1,s=.5*n.getWidth(),a=.5*n.getHeight(),o=n.northEast,l=n.southWest,h=new z(l.lon+s,l.lat+a),c=this.nodes;c[0]=new e(this.SegmentPrototype,t,0,this,r,new ie(new z(l.lon,l.lat+a),new z(l.lon+s,o.lat))),c[1]=new e(this.SegmentPrototype,t,1,this,r,new ie(h,new z(o.lon,o.lat))),c[2]=new e(this.SegmentPrototype,t,2,this,r,new ie(new z(l.lon,l.lat),h)),c[3]=new e(this.SegmentPrototype,t,3,this,r,new ie(new z(l.lon+s,l.lat),new z(o.lon,l.lat+a)))}createBounds(){let e=this.segment;e._setExtentLonLat(),0===e.tileZoom?e.setBoundingSphere(0,0,0,new oe(0,0,e.planet.ellipsoid.equatorialSize)):e.tileZoom<e.planet.terrain.minZoom?e.createBoundsByExtent():e.createBoundsByParent();let t=e.bsphere.center.x,i=e.bsphere.center.y,n=e.bsphere.center.z,r=1/Math.sqrt(t*t+i*i+n*n);e.centerNormal.x=t*r,e.centerNormal.y=i*r,e.centerNormal.z=n*r}getState(){if(-1===this.state)return this.state;let e=this.parentNode;for(;e;){if(2!==e.state)return 0;e=e.parentNode}return this.state}getEqualNeighbor(e){let t=this,i=Ut[e][t.partId];if(-1!==i)return t.parentNode.nodes[i];{let n=[];for(;t.parentNode;)if(n.push(t.partId),i=Ut[e][t.partId],t=t.parentNode,-1!==i){let r=n.length;for(e=Vt[e];t&&r--;)i=Gt[e][n[r]],t=t.nodes[i];return t}}}traverseNodes(e,t,i,n,r){this.ready||this.createChildrenNodes();let s=this.nodes;s[0].renderTree(e,t,i,n,r),s[1].renderTree(e,t,i,n,r),s[2].renderTree(e,t,i,n,r),s[3].renderTree(e,t,i,n,r)}renderTree(e,t,i,n,r){if(this.planet._renderedNodes.length>=1e3)return;(!t||r&&this.segment.tileZoom>r.segment.tileZoom)&&(this.prevState=this.state),this.state=2,this.clearNeighbors();let s=this.segment,a=this.planet;if(this._cameraInside=!1,!this.parentNode||this.parentNode._cameraInside){let t;Math.abs(e._lonLat.lat)<=J&&s._projection.id===ta.id?t=s._extent.isInside(e._lonLatMerc):s._projection.id===ia.id&&(t=s._extent.isInside(e._lonLat)),t&&(e._insideSegment=s,this._cameraInside=!0)}this.inFrustum=0;let o=e.frustums,l=o.length;if(s.tileZoom<6)for(let e=0;e<l;e++)o[e].containsSphere(s.bsphere)&&(this.inFrustum|=1<<e);else{let e=1<<l-1-1;for(let t=0;e&&t<l;t++)s.terrainReady?o[t].containsBox(s.bbox)&&(e>>=1,this.inFrustum|=1<<t):o[t].containsSphere(s.bsphere)&&(e>>=1,this.inFrustum|=1<<t)}if(this.inFrustum||this._cameraInside||s.tileZoom<3){let o=Math.abs(e._lonLat.height),l=e.eye.length2()-this.planet.ellipsoid.polarSizeSqr;l=l<106876472875.63281*a._heightFactor?106876472875.63281*a._heightFactor:l;let h=s.tileZoom<2||s.tileZoom>19||s.tileZoom<6&&!s.terrainReady;h=h||e.eye.distance2(s._sw)<l||e.eye.distance2(s._nw)<l||e.eye.distance2(s._ne)<l||e.eye.distance2(s._se)<l,(this.inFrustum&&(h||o>1e4)||this._cameraInside)&&s._collectVisibleNodes(),s.tileZoom<2?this.traverseNodes(e,t,i,n,r):s.terrainReady&&(!t&&e.projectedSize(s.bsphere.center,s._plainRadius)<a.lodSize||t&&(s.tileZoom===t||!h))?h?(s.passReady=!0,this.renderNode(this.inFrustum,!this.inFrustum,i,n)):this.state=0:s.terrainReady&&s.checkZoom()&&(!t||e.projectedSize(s.bsphere.center,s.bsphere.radius)>this.planet._maxLodSize)?this.traverseNodes(e,t,s,n,r):h?(s.passReady=!!t&&s.terrainReady,this.renderNode(this.inFrustum,!this.inFrustum,i,n)):this.state=0}else this.state=0}renderNode(e,t,i,n){let r=this.segment;r.terrainReady||(r.initialized||r.initialize(),this.whileTerrainLoading(i),r.plainProcessing||r.createPlainSegmentAsync(),r.plainReady&&!n&&r.loadTerrain()),r.planet.lightEnabled&&!r.normalMapReady&&this.whileNormalMapCreating(),t?this.state=-1:(!this._cameraInside&&r.tileZoom>this.planet.maxCurrZoom&&(this.planet.maxCurrZoom=r.tileZoom),r.tileZoom<this.planet.minCurrZoom&&(this.planet.minCurrZoom=r.tileZoom),r._addViewExtent(),this.addToRender(e))}childrenPrevStateEquals(e){let t=this.nodes;return 4===t.length&&t[0].prevState===e&&t[1].prevState===e&&t[2].prevState===e&&t[3].prevState===e}isFading(){let e=this.nodes;return 2===this.state&&this.segment._transitionOpacity>0&&4===e.length&&1===e[0].state&&1===e[1].state&&1===e[2].state&&1===e[3].state}_collectFadingNodes(){if(this.segment.tileZoom<3)this.segment._transitionOpacity=1;else if(1!==this.prevState){this.segment._transitionOpacity=0,this._fadingNodes=[];let e=window.performance.now();if(this.segment._transitionTimestamp=e,this.parentNode)if(1===this.parentNode.prevState){let t=this.parentNode.parentNode;for(;t;){if(t.isFading()){for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment._transitionOpacity=1,t.nodes[e]._fadingNodes=[];t.segment._transitionOpacity=0;break}t=t.parentNode}this.parentNode.whileTerrainLoading(),this._fadingNodes.push(this.parentNode),this.parentNode.segment._transitionOpacity=2,this.parentNode.segment._transitionTimestamp=e}else if(this.segment.childrenInitialized()&&this.childrenPrevStateEquals(1))for(let t=0;t<this.nodes.length;t++){let i=this.nodes[t];i.whileTerrainLoading(),this._fadingNodes.push(i),i.segment._transitionOpacity=2,i.segment._transitionTimestamp=e,i.prevState=i.state,i.state=0}}}clearNeighbors(){this.neighbors&&(this.neighbors[0]=this.neighbors[1]=this.neighbors[2]=this.neighbors[3]=null,this.neighbors[0]=[],this.neighbors[1]=[],this.neighbors[2]=[],this.neighbors[3]=[])}_refreshTransitionOpacity(){if(0===this._fadingNodes.length)this.segment._transitionOpacity=1;else if(4!==this._fadingNodes.length||this.childrenPrevStateEquals(1)){for(let e=0;e<this._fadingNodes.length;e++)this.segment._transitionOpacity<1&&0===this._fadingNodes[e].segment._transitionOpacity&&(this._fadingNodes[e].segment._transitionOpacity=0,this.segment._transitionOpacity=1);this.segment.increaseTransitionOpacity()}else this.segment._transitionOpacity=1,this._fadingNodes=[]}addToRender(e){this.state=1;let t=this.planet._renderedNodes;this.planet._transitionOpacityEnabled?Re(t,this,((e,t)=>e.segment.tileZoom-t.segment.tileZoom)):(this.getRenderedNodesNeighbors(t),t.push(this)),this.segment.terrainReady||(this.planet._renderCompleted=!1,this.planet._terrainCompleted=!1);let i=0,n=this.planet._renderedNodesInFrustum;for(;e;)1&e&&n[i].push(this),i++,e>>=1}applyNeighbor(e,t){const i=Vt[t];if(0===this.neighbors[t].length||0===e.neighbors[i].length){const n=this.segment,r=e.segment,s=n.gridSize/(r.gridSize*Math.pow(2,r.tileZoom-n.tileZoom));let a=n.gridSize,o=r.gridSize;s>1?(a=Math.ceil(n.gridSize/s),o=r.gridSize):s<1&&(a=n.gridSize,o=Math.ceil(r.gridSize*s)),this.sideSizeLog2[t]=Math.log2(a),e.sideSizeLog2[i]=Math.log2(o)}this.neighbors[t].push(e),e.neighbors[i].push(this)}getRenderedNodesNeighbors(e){for(let t=e.length-1;t>=0;--t){let i=e[t],n=this.getCommonSide(i);-1!==n&&this.applyNeighbor(i,n)}}getCommonSide(e){const t=this.segment,i=e.segment;if(t.tileZoom===i.tileZoom&&t._tileGroup===i._tileGroup)return t.getNeighborSide(i);{const e=t._extentLonLat,n=i._extentLonLat;let r=e.northEast,s=e.southWest,a=n.northEast,o=n.southWest,l=r.lon,h=r.lat,c=s.lon,d=s.lat,_=a.lon,u=a.lat,f=o.lon,g=o.lat;if(t._tileGroup===i._tileGroup){if(l===f&&(h<=u&&d>=g||h>=u&&d<=g))return 1;if(c===_&&(h<=u&&d>=g||h>=u&&d<=g))return 3;if(h===g&&(c>=f&&l<=_||c<=f&&l>=_))return 0;if(d===u&&(c>=f&&l<=_||c<=f&&l>=_))return 2;if(0===i.tileX&&f===-l&&(h<=u&&d>=g||h>=u&&d<=g))return 1;if(0===t.tileX&&c===-_&&(h<=u&&d>=g||h>=u&&d<=g))return 3}if(0===t._tileGroup&&i._tileGroup===aa&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=f&&l<=_||c<=f&&l>=_))return 0;if(0===t._tileGroup&&i._tileGroup===oa&&t.tileY===t.powTileZoom-1&&0===i.tileY&&(c>=f&&l<=_||c<=f&&l>=_))return 2;if(t._tileGroup===oa&&0===i._tileGroup&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=f&&l<=_||c<=f&&l>=_))return 0;if(t._tileGroup===aa&&0===i._tileGroup&&t.tileY===t.powTileZoom-1&&0===i.tileY&&(c>=f&&l<=_||c<=f&&l>=_))return 2}return-1}whileNormalMapCreating(){const e=this.segment;e.terrainIsLoading||!e.terrainExists||e._inTheQueue||e.planet._normalMapCreator.queue(e);let t=this;for(;t.parentNode&&!t.segment.normalMapReady;)t=t.parentNode;const i=2<<e.tileZoom-t.segment.tileZoom-1;e.normalMapTexture=t.segment.normalMapTexture,e.normalMapTextureBias[0]=e.tileX-t.segment.tileX*i,e.normalMapTextureBias[1]=e.tileY-t.segment.tileY*i,e.normalMapTextureBias[2]=1/i}whileTerrainLoading(e){const t=this.segment;let i=this;if(e&&e.terrainReady)i=e.node;else for(;i.parentNode&&!i.segment.terrainReady;)i=i.parentNode;if(i.segment.terrainReady&&this.appliedTerrainNodeId!==i.nodeId){let e=2<<t.tileZoom-i.segment.tileZoom-1,n=t.tileX-i.segment.tileX*e,r=t.tileY-i.segment.tileY*e;const o=i.segment;let l,h,c,d;this.appliedTerrainNodeId=i.nodeId,this.equalizedSideWithNodeId[0]=this.equalizedSideWithNodeId[1]=this.equalizedSideWithNodeId[2]=this.equalizedSideWithNodeId[3]=this.appliedTerrainNodeId;let _=i.segment.gridSize/e,u=i.segment.fileGridSize/e;if(Ca.xmin=s,Ca.xmax=a,Ca.ymin=s,Ca.ymax=a,Ca.zmin=s,Ca.zmax=a,_>=1){t.gridSize=_;let e=(_+1)*(_+1)*3;l=new Float64Array(e),h=new Float32Array(e),c=new Float32Array(e),o.noDataVertices&&(d=new Uint8Array(e/3)),Ye(o.terrainVertices,o.terrainVerticesHigh,o.terrainVerticesLow,o.noDataVertices,o.gridSize,_*r,_*n,_,l,h,c,Ca,d)}else if(u>=1&&i.segment.terrainExists){t.gridSize=u;let e=(u+1)*(u+1)*3;l=new Float64Array(e),h=new Float32Array(e),c=new Float32Array(e),o.noDataVertices&&(d=new Uint8Array(e/3)),Ye(o.normalMapVertices,o.normalMapVerticesHigh,o.normalMapVerticesLow,o.noDataVertices,i.segment.fileGridSize,u*r,u*n,u,l,h,c,Ca,d)}else{t.gridSize=wa;let e,i=Math.floor(_*r),s=Math.floor(_*n);e=1===o.gridSize?o.terrainVertices:We(o.terrainVertices,o.gridSize,i,s,1);let a=1/_,d=r-a*i,u=n-a*s,f=new oe(e[0],e[1],e[2]),g=new oe(e[9],e[10],e[11]),p=new oe(e[3]-e[0],e[4]-e[1],e[5]-e[2]),m=new oe(e[6]-e[0],e[7]-e[1],e[8]-e[2]),v=new oe(e[3]-e[9],e[4]-e[10],e[5]-e[11]),y=new oe(e[6]-e[9],e[7]-e[10],e[8]-e[11]),x=new oe;l=new Float64Array(3*ba.length),h=new Float32Array(3*ba.length),c=new Float32Array(3*ba.length);for(let e=0;e<ba.length;e++){let t=ba[e].y+d,i=ba[e].x+u,n=i*_,r=t*_;x=t+i<a?p.scaleTo(n).addA(m.scaleTo(r)).addA(f):y.scaleTo(1-n).addA(v.scaleTo(1-r)).addA(g),oe.doubleToTwoFloats(x,ya,xa);let s=3*e;l[s]=x.x,l[s+1]=x.y,l[s+2]=x.z,h[s]=ya.x,h[s+1]=ya.y,h[s+2]=ya.z,c[s]=xa.x,c[s+1]=xa.y,c[s+2]=xa.z,x.x<Ca.xmin&&(Ca.xmin=x.x),x.x>Ca.xmax&&(Ca.xmax=x.x),x.y<Ca.ymin&&(Ca.ymin=x.y),x.y>Ca.ymax&&(Ca.ymax=x.y),x.z<Ca.zmin&&(Ca.zmin=x.z),x.z>Ca.zmax&&(Ca.zmax=x.z)}}if(t.readyToEngage=!0,t.terrainVertices=l,t.terrainVerticesHigh=h,t.terrainVerticesLow=c,t.tempVertices=l,t.tempVerticesHigh=h,t.tempVerticesLow=c,t.noDataVertices=d,t.setBoundingVolume(Ca.xmin,Ca.ymin,Ca.zmin,Ca.xmax,Ca.ymax,Ca.zmax),t.tileZoom>t.planet.terrain.maxZoom&&i.segment.tileZoom>=t.planet.terrain.maxZoom&&(t._plainRadius=i.segment._plainRadius/e,t.terrainReady=!0,t.terrainIsLoading=!1,t.terrainVertices=l,t.terrainVerticesHigh=h,t.terrainVerticesLow=c,t.passReady=!0,this.appliedTerrainNodeId=this.nodeId,this.equalizedSideWithNodeId[0]=this.equalizedSideWithNodeId[1]=this.equalizedSideWithNodeId[2]=this.equalizedSideWithNodeId[3]=this.appliedTerrainNodeId,i.segment.terrainExists)){t.normalMapVertices=l,t.fileGridSize=Math.sqrt(l.length/3)-1;let i=Math.sqrt(o.normalMapNormals.length/3)-1,s=i/e;t.normalMapNormals=i>1?je(o.normalMapNormals,i,s*r,s*n,s):o.normalMapNormals}}}destroy(){this.prevState=this.state=0,this.segment.destroySegment();let e=this.neighbors;for(let t=0,i=e.length;t<i;t++){let i=e[t];if(i)for(let e=0;e<i.length;e++){let t=i[e];t&&t.neighbors&&t.clearNeighbors()}}this.neighbors=null,this.parentNode=null,this.sideSizeLog2=null,this.segment=null}clearTree(){const e=this.getState();if(0===e||1===e)this.destroyBranches();else for(let e=0;e<this.nodes.length;e++)this.nodes[e]&&this.nodes[e].clearTree()}clearBranches(){for(let e=0;e<this.nodes.length;e++)this.nodes[e].clearBranches(),this.nodes[e].segment.deleteMaterials()}destroyBranches(){if(this.ready){let e,t=[];for(e=0;e<this.nodes.length;e++)t[e]=this.nodes[e];for(this.ready=!1,this.nodes=[],e=0;e<t.length;e++)t[e].destroyBranches(),t[e].destroy(),t[e]=null;t.length=0,t=null}}traverseTree(e){if(e(this),this.ready)for(let t=0;t<this.nodes.length;t++)this.nodes[t].traverseTree(e)}getOffsetOppositeNeighbourSide(e,t){let i=this,n=e.segment.tileZoom,r=0;for(;i.segment.tileZoom>n;)r+=Wt[i.partId][t]/(1<<i.segment.tileZoom-n),i=i.parentNode;return r}};class Aa{constructor(e,t="",i=ta){this.name=t,this.projection=i,this._planet=e,this._quadTreeList=[]}destroyBranches(){for(let e=0,t=this._quadTreeList.length;e<t;e++)this._quadTreeList[e].destroyBranches()}clearLayerMaterial(e){let t=e.__id;for(let e=0,i=this._quadTreeList.length;e<i;e++)this._quadTreeList[e].traverseTree((function(e){let i=e.segment.materials;i[t]&&(i[t].clear(),i[t]=null)}))}get planet(){return this._planet}init(){}preRender(){for(let e=0;e<this._quadTreeList.length;e++){let t=this._quadTreeList[e];t.createChildrenNodes(),t.segment.createPlainSegment();for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment.createPlainSegment()}}preLoad(){for(let e=0;e<this._quadTreeList.length;e++){let t=this._quadTreeList[e];t.segment.passReady=!0,t.renderNode(1),this._planet.normalMapCreator.drawSingle(t.segment);for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment.passReady=!0,t.nodes[e].renderNode(1),this._planet._normalMapCreator.drawSingle(t.nodes[e].segment)}}collectRenderNodes(){for(let e=0;e<this._quadTreeList.length;e++)this._quadTreeList[e].renderTree(this._planet.camera,0,null)}clear(){for(let e=0;e<this._quadTreeList.length;e++)this._quadTreeList[e].clearTree()}get quadTreeList(){return this._quadTreeList}getTileXY(e,t){let i=t,n=-1,r=-1,s=1<<i;return n=ra(e.lon,360/s,-180),r=ra(e.lat,180/s,90),[n,r,i,0]}getLonLatTileOffset(e,t,i,n,r){let s=e,a=new ie;a=sa(t,i,n,ie.createFromArray([-180,-90,180,90]));let o=a.getWidth()/(r-1),l=a.getHeight()/(r-1);return[r-Math.ceil((s.lat-a.southWest.lat)/l)-1,Math.floor((s.lon-a.southWest.lon)/o)]}}const Ea=(90-J)/Math.pow(2,7);class Pa extends va{constructor(e,t,i,n){super(e,t,i,n),this._projection=ia,this._extentLonLat=this._extent,this._extentMerc=new ie(n.southWest.forwardMercatorEPS01(),n.northEast.forwardMercatorEPS01()),this._isNorth=this._extent.northEast.lat>0,this.isPole=!0}_setExtentLonLat(){this._extentLonLat=this._extent}projectNative(e){return e}getInsideLonLat(e){return e._lonLat}_getMaxZoom(){let e=0;if(this._isNorth){let t=Math.floor((90-this._extent.northEast.lat)/Ea);e=Math.floor(t/16)+7}else{let t=Math.floor((ee-this._extent.northEast.lat)/Ea);e=12-Math.floor(t/16)}return e}checkZoom(){return super.checkZoom()&&this.tileZoom<=this._getMaxZoom()}_assignTileIndexes(){this._assignTileXIndexes(this._extent),this._assignTileYIndexes(this._extent),this.tileIndex=qt.getTileIndex(this.tileX,this.tileY,this.tileZoom,this._tileGroup)}_assignTileXIndexes(e){this.tileX=ra(e.getCenter().lon,e.getWidth(),-180);let t=1<<this.tileZoom;this.tileXE=(this.tileX+1)%t,this.tileXW=(t+this.tileX-1)%t}_assignTileYIndexes(e){const t=e.getCenter().lat;t>0?(this._tileGroup=aa,this.tileY=ra(t,e.getHeight(),90)):(this._tileGroup=oa,this.tileY=ra(t,e.getHeight(),ee)),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_projToDeg(e,t){return new z(e,t)}_assignGlobalTextureCoordinates(){const e=this._extent;this._globalTextureCoordinates[0]=(e.southWest.lon+180)/360,this._globalTextureCoordinates[1]=(90-e.northEast.lat)/180,this._globalTextureCoordinates[2]=(e.northEast.lon+180)/360,this._globalTextureCoordinates[3]=(90-e.southWest.lat)/180}_collectVisibleNodes(){this._isNorth?this.planet._visibleNodesNorth[this.node.nodeId]=this.node:this.planet._visibleNodesSouth[this.node.nodeId]=this.node}_getLayerExtentOffset(e){const t=e._extent,i=this._extent,n=t.northEast.lon-t.southWest.lon,r=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/n,(t.northEast.lat-i.northEast.lat)/r,(i.northEast.lon-i.southWest.lon)/n,(i.northEast.lat-i.southWest.lat)/r]}layerOverlap(e){return this._extent.overlaps(e._extent)}getDefaultTexture(){return this._isNorth?this.planet.solidTextureOne:this.planet.solidTextureTwo}getExtentLonLat(){return this._extent}}class Sa extends Aa{constructor(e){super(e,"Earth")}init(){this._quadTreeList=[new La(va,this.planet,0,null,0,ie.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34])),new La(Pa,this.planet,0,null,0,ie.createFromArray([-180,J,180,90])),new La(Pa,this.planet,0,null,0,ie.createFromArray([-180,-90,180,ee]))]}getTileXY(e,t){let i=function(e,t=J){return e>t?aa:e<-t?oa:0}(e.lat,J),n=t,r=-1,s=-1,a=1<<n;if(i===aa)r=ra(e.lon,360/a,-180),s=ra(e.lat,(90-J)/a,90);else if(i===oa)r=ra(e.lon,360/a,-180),s=ra(e.lat,(90-J)/a,ee);else{let t=X(e);r=ra(t.lon,F/a,-D),s=ra(t.lat,F/a,D)}return[r,s,n,i]}getLonLatTileOffset(e,t,i,n,r){let s=e,a=new ie;if(e.lat>J){a=sa(t,i,n,ie.createFromArray([-180,J,180,90]))}else if(e.lat<ee){a=sa(t,i,n,ie.createFromArray([-180,-90,180,ee]))}else s=X(e),a=Q(t,i,n);let o=a.getWidth()/(r-1),l=a.getHeight()/(r-1);return[r-Math.ceil((s.lat-a.southWest.lat)/l)-1,Math.floor((s.lon-a.southWest.lon)/o)]}}class Ma{constructor(e={}){this.model=e.model||null,this.src=e.src||null,this._cached_ix=0,this._cached_iy=0,this._v00=0,this._v01=0,this._v10=0,this._v11=0,this._t=0}static loadModel(e){return e?fetch(e,{}).then((e=>{if(!e.ok)throw Error("Geoid model file: HTTP error "+e.status);return e.arrayBuffer()})).then((t=>{if(t)return new Uint8Array(t);throw Error("Geoid model file: no data from "+e)})).then((function(e){if(80!==e[0]||53!==e[1]||(13!==e[2]||10!==e[3])&&10!==e[2])throw new Error("Geoid model file: no PGM header");var t,i,n=13===e[2]?4:3,r=null,s=null;function a(){let t=n;for(var i=n;;i++){if(i>=e.length)throw new Error("Geoid model file: missing newline in header");if(10===e[i]){n=i+1;break}}return i>t&&13===e[i-1]&&i--,String.fromCharCode.apply(null,e.slice(t,i))}for(;"#"===(i=a())[0];)if(t=i.match(/^# Offset (.*)$/)){if(r=parseInt(t[1],10),!isFinite(r))throw new Error("Geoid model file: bad offset "+t[1])}else if((t=i.match(/^# Scale (.*)$/))&&(s=parseFloat(t[1]),!isFinite(s)))throw new Error("Geoid model file: bad scale "+t[1]);let o=0,l=0;if((t=i.match(/^\s*(\d+)\s+(\d+)\s*$/))&&(o=parseInt(t[1],10),l=parseInt(t[2],10)),!(t&&o>=0&&l>=0))throw new Error("Geoid model file: bad PGM width&height line");if(65535!=parseInt(a()))throw new Error("Geoid model file: PGM file must have 65535 gray levels");if(null===r)throw new Error("Geoid model file: PGM file does not contain offset");if(null===s)throw new Error("Geoid model file: PGM file does not contain scale");if(o<2||l<2)throw new Error("Geoid model file: Raster size too small");if(e.length-n!==o*l*2)throw new Error("Geoid model file: File has the wrong length");return{scale:s,offset:r,width:o,height:l,rlonres:o/360,rlatres:(l-1)/180,i:n,rawfile:e}})):new Promise((e=>{e(null)}))}setModel(e){this.model=e}_rawval(e,t){let i=this.model;t<0?(t=-t,e+=i.width/2):t>=i.height&&(t=2*(i.height-1)-t,e+=i.width/2),e<0?e+=i.width:e>=i.width&&(e-=i.width);let n=2*(t*i.width+e)+i.i;return i.rawfile[n]<<8|i.rawfile[n+1]}getHeightLonLat(e){return this.getHeight(e.lon,e.lat)}getHeight(e,t){if(!this.model)return 0;let i=this.model;e<0&&(e+=360);let n=(90-t)*i.rlatres,r=e*i.rlonres,s=Math.floor(n),a=Math.floor(r);r-=a,n-=s,s===i.height-1&&s--,this._cached_ix===a&&this._cached_iy===s||(this._cached_ix=a,this._cached_iy=s,this._v00=this._rawval(a,s),this._v01=this._rawval(a+1,s),this._v10=this._rawval(a,s+1),this._v11=this._rawval(a+1,s+1));let o=(1-n)*((1-r)*this._v00+r*this._v01)+n*((1-r)*this._v10+r*this._v11);return i.offset+i.scale*o}}class Ba{constructor(e,t=5){this.MAX_FRAMES=t,this._gridSize=64,this._planet=e,this._framebuffer=null,this._framebufferMercProj=null,this._texCoordsBuffer=null,this._indexBuffer=null,this._currentFrame=0,this._queue=[],this._animate=[],this._quadTexCoordsBuffer=null,this._quadVertexBuffer=null}init(){this._initShaders(),this._initBuffers()}createGridBuffer(e,t=!1){let i=this._gridSize,n=new z((e[3].lon-e[0].lon)/i,(e[3].lat-e[0].lat)/i),r=new z((e[2].lon-e[1].lon)/i,(e[2].lat-e[1].lat)/i),s=new z((e[1].lon-e[0].lon)/i,(e[1].lat-e[0].lat)/i),a=new z((e[2].lon-e[3].lon)/i,(e[2].lat-e[3].lat)/i);const o=(i+1)*(i+1)*2,l=o/2;let h=new Float32Array(o),c=new Float32Array(o),d=new Array(l),_=0,u=0,f=0,g=new Float32Array(2);for(let t=0;t<=i;t++){let o=new z(e[0].lon+t*n.lon,e[0].lat+t*n.lat),l=new z(e[1].lon+t*r.lon,e[1].lat+t*r.lat);for(let t=0;t<=i;t++){let i=Ie(o,l,new z(e[0].lon+t*s.lon,e[0].lat+t*s.lat),new z(e[3].lon+t*a.lon,e[3].lat+t*a.lat));nn(i.lon,g),h[_++]=g[0],c[u++]=g[1],nn(i.lat,g),h[_++]=g[0],c[u++]=g[1],d[f++]=i}}if(t)for(let e=0;e<l;e++){let t=d[e].forwardMercator();nn(t.lon,g),h[2*e]=g[0],c[2*e]=g[1],nn(t.lat,g),h[2*e+1]=g[0],c[2*e+1]=g[1]}return[this._planet.renderer.handler.createArrayBuffer(h,2,l),this._planet.renderer.handler.createArrayBuffer(c,2,l)]}frame(){let e=this.MAX_FRAMES;for(;e--&&this._queue.length;){const e=this._queue.shift();e._isRendering=!1,e.rendering(),e.events.dispatch(e.events.loadend)}for(e=this._animate.length;e--;)this._animate[e].rendering()}add(e){e._isRendering||(e._isRendering=!0,e._animate?this._animate.push(e):this._queue.push(e))}remove(e){if(e._isRendering){let t;e._creationProceeding=!1,e._isRendering=!1,t=e._animate?this._animate:this._queue;for(let i=0;i<t.length;i++)if(t[i].isEqual(e))return void t.splice(i,1)}}_initBuffers(){let e=this._planet.renderer.handler;this._framebuffer=new $s(e,{width:2,height:2,useDepth:!1}),this._framebuffer.init(),this._framebufferMercProj=new $s(e,{width:2,height:2,useDepth:!1}),this._framebufferMercProj.init();let t=Math.log2(this._gridSize);this._texCoordsBuffer=this._planet._textureCoordsBufferCache[t],this._indexBuffer=this._planet._indexesCache[t][t][t][t][t].buffer,this._quadTexCoordsBuffer=e.createArrayBuffer(new Float32Array([0,1,1,1,0,0,1,0]),2,4),this._quadVertexBuffer=e.createArrayBuffer(new Float32Array([-1,1,1,1,-1,-1,1,-1]),2,4)}_initShaders(){this._planet.renderer.handler.addProgram(new zi("geoImageTransform",{uniforms:{sourceTexture:"sampler2d",extentParamsHigh:"vec4",extentParamsLow:"vec4",isFullExtent:"bool"},attributes:{cornersHigh:"vec2",cornersLow:"vec2",texCoords:"vec2"},vertexShader:"attribute vec2 cornersHigh; \n attribute vec2 cornersLow;\n attribute vec2 texCoords; \n uniform vec4 extentParamsHigh; \n uniform vec4 extentParamsLow; \n varying vec2 v_texCoords;\n void main() { \n v_texCoords = texCoords; \n vec2 highDiff = cornersHigh - extentParamsHigh.xy;\n vec2 lowDiff = cornersLow - extentParamsLow.xy; \n gl_Position = vec4((-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0), 0.0, 1.0); \n }",fragmentShader:"precision highp float;\n uniform sampler2D sourceTexture;\n uniform bool isFullExtent;\n varying vec2 v_texCoords;\n void main () {\n if(!isFullExtent && (v_texCoords.x <= 0.001 || v_texCoords.x >= 0.999 ||\n v_texCoords.y <= 0.001 || v_texCoords.y >= 0.999)) {\n discard;\n }\n gl_FragColor = texture2D(sourceTexture, v_texCoords);\n }"}))}}const ka=["loadend","layerloadend"];class Ra{constructor(e=24){this.MAX_REQUESTS=e,this.events=Pt(ka),this._loading=0,this._queue=[],this._senderRequestCounter=[],this._promises={json:e=>e.json(),blob:e=>e.blob(),arrayBuffer:e=>e.arrayBuffer(),imageBitmap:e=>e.blob().then((e=>createImageBitmap(e,{premultiplyAlpha:"premultiply"}))),text:e=>e.text()}}load(e,t){e.sender&&(this._senderRequestCounter[e.sender.__id]||(this._senderRequestCounter[e.sender.__id]={sender:e.sender,counter:0,__requestCounterFrame__:0}),this._senderRequestCounter[e.sender.__id].counter++),this._queue.push({params:e,callback:t}),this._exec()}fetch(e){return fetch(e.src,e.options||{}).then((t=>{if(!t.ok)throw Error(`Unable to load '${e.src}'`);return this._promises[e.type||"blob"](t)})).then((e=>({status:"ready",data:e}))).catch((e=>({status:"error",msg:e.toString()})))}getRequestCounter(e){if(e){let t=this._senderRequestCounter[e.__id];if(t)return t.counter}return 0}isIdle(e){return e.isIdle}_checkLoadend(e,t){0!==e.counter||t._planet&&!t._planet._terrainCompletedActivated?e.__requestCounterFrame__=requestAnimationFrame((()=>{this._checkLoadend(e,t)})):(t.events.dispatch(t.events.loadend,t),this.events.dispatch(this.events.layerloadend,t),e.__requestCounterFrame__=0)}_handleResponse(e,t){e.callback(t);let i=e.params.sender;if(i&&(i.events.loadend.handlers.length||this.events.layerloadend.handlers.length)){let e=this._senderRequestCounter[i.__id];e&&e.counter>0&&(e.counter--,cancelAnimationFrame(e.__requestCounterFrame__),e.__requestCounterFrame__=requestAnimationFrame((()=>{this._checkLoadend(e,i)})))}this._exec()}_exec(){if(this._queue.length>0&&this._loading<this.MAX_REQUESTS){let e=this._queue.pop();if(!e)return;let t=e.params;if(!t.filter||t.filter(t))return this._loading++,fetch(t.src,t.options||{}).then((e=>{if(!e.ok)throw Error(`Unable to load '${t.src}'`);return this._promises[t.type||"blob"](e)})).then((t=>{this._loading--,this._handleResponse(e,{status:"ready",data:t})})).catch((t=>{this._loading--,this._handleResponse(e,{status:"error",msg:t.toString()})}));this._handleResponse(e,{status:"abort"})}else 0===this._loading&&this.events.dispatch(this.events.loadend)}abort(e){this._senderRequestCounter[e.__id]&&(this._senderRequestCounter[e.__id].counter=0,cancelAnimationFrame(this._senderRequestCounter[e.__id].__requestCounterFrame__),this._senderRequestCounter[e.__id].__requestCounterFrame__=0);for(let t=0,i=this._queue.length;t<i;t++){let i=this._queue[t];i&&i.params.sender&&e.isEqual(i.params.sender)&&(i.callback({status:"abort"}),this._queue[t]=null)}}abortAll(){for(let e=0,t=this._queue.length;e<t;e++){let t=this._queue[e];if(t){let i=t.params.sender;i&&this._senderRequestCounter[i.__id]&&(this._senderRequestCounter[i.__id].counter=0,cancelAnimationFrame(this._senderRequestCounter[i.__id].__requestCounterFrame__),this._senderRequestCounter[i.__id].__requestCounterFrame__=0),t.callback({status:"abort"}),this._queue[e]=null}}this._queue=[]}get loading(){return this._loading}get queue(){return this._queue}}class Ia{constructor(e,t={}){this._minTabelSize=t.minTableSize||1,this._maxTableSize=t.maxTableSize||8,this._planet=e,this._handler=null,this._verticesBufferArray=[],this._indexBufferArray=[],this._positionBuffer=null,this._framebuffer=null,this._normalMapVerticesTexture=null,this._width=t.width||128,this._height=t.height||128,this._queue=new Rn(1024),this._lock=new yr}get width(){return this._width}get height(){return this._height}init(){this._maxTableSize=this._planet.maxGridSize||8,this._handler=this._planet.renderer.handler;const e=new zi("normalMapBlur",{attributes:{a_position:"vec2"},uniforms:{s_texture:"sampler2d"},vertexShader:`attribute vec2 a_position;\n attribute vec2 a_texCoord;\n\n varying vec2 blurCoordinates[5];\n\n void main() {\n vec2 vt = a_position * 0.5 + 0.5; \n \n gl_Position = vec4(a_position, 0.0, 1.0);\n blurCoordinates[0] = vt;\n blurCoordinates[1] = vt + ${1/this._width*1.407333};\n blurCoordinates[2] = vt - ${1/this._height*1.407333};\n blurCoordinates[3] = vt + ${1/this._width*3.294215};\n blurCoordinates[4] = vt - ${1/this._height*3.294215};\n }`,fragmentShader:"precision lowp float;\n uniform sampler2D s_texture; \n varying vec2 blurCoordinates[5]; \n\n void main() {\n lowp vec4 sum = vec4(0.0);\n //if(blurCoordinates[0].x <= 0.01 || blurCoordinates[0].x >= 0.99 ||\n // blurCoordinates[0].y <= 0.01 || blurCoordinates[0].y >= 0.99){\n // sum = texture2D(s_texture, blurCoordinates[0]);\n //} else {\n sum += texture2D(s_texture, blurCoordinates[0]) * 0.204164;\n sum += texture2D(s_texture, blurCoordinates[1]) * 0.304005;\n sum += texture2D(s_texture, blurCoordinates[2]) * 0.304005;\n sum += texture2D(s_texture, blurCoordinates[3]) * 0.093913;\n sum += texture2D(s_texture, blurCoordinates[4]) * 0.093913;\n //}\n gl_FragColor = sum;\n }"}),t=new zi("normalMap",{attributes:{a_position:"vec2",a_normal:"vec3"},uniforms:{},vertexShader:"attribute vec2 a_position;\n attribute vec3 a_normal;\n \n varying vec3 v_color;\n \n void main() {\n gl_Position = vec4(a_position, 0, 1);\n v_color = normalize(a_normal) * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n \n varying vec3 v_color;\n \n void main () {\n gl_FragColor = vec4(v_color, 1.0);\n }"});this._handler.addProgram(e),this._handler.addProgram(t),this._framebuffer=new $s(this._handler,{width:this._width,height:this._height,useDepth:!1}),this._framebuffer.init(),this._normalMapVerticesTexture=this._handler.createEmptyTexture_l(this._width,this._height);for(let e=this._minTabelSize;e<=this._maxTableSize;e++){const t=1<<e,i=t/2;let n=new Float32Array((t+1)*(t+1)*2);for(let e=0;e<=t;e++)for(let r=0;r<=t;r++){let s=2*(e*(t+1)+r);n[s]=r/i-1,n[s+1]=e/i-1}this._verticesBufferArray[t]=this._handler.createArrayBuffer(n,2,n.length/2),this._indexBufferArray[t]=this._planet._indexesCache[Math.log2(t)][Math.log2(t)][Math.log2(t)][Math.log2(t)][Math.log2(t)].buffer}const i=new Float32Array([-1,-1,1,-1,-1,1,1,1]);this._positionBuffer=this._handler.createArrayBuffer(i,2,i.length/2)}_drawNormalMapBlur(e){let t=e.normalMapNormals;if(e.node&&0!==e.node.getState()&&t&&t.length){const i=t.length/3,n=Math.sqrt(i)-1;let r=this._verticesBufferArray[n];if(r){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let s=e.normalMapTexturePtr;const a=this._handler,o=a.gl;let l=a.createArrayBuffer(t,3,i,o.DYNAMIC_DRAW);const h=this._framebuffer;let c=a.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(this._normalMapVerticesTexture),c.activate(),o.bindBuffer(o.ARRAY_BUFFER,r),o.vertexAttribPointer(d.a_position,r.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,l),o.vertexAttribPointer(d.a_normal,l.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[n]),o.drawElements(o.TRIANGLE_STRIP,this._indexBufferArray[n].numItems,o.UNSIGNED_INT,0),o.deleteBuffer(l),h.bindOutputTexture(s),c=a.programs.normalMapBlur,c.activate(),o.bindBuffer(o.ARRAY_BUFFER,this._positionBuffer),o.vertexAttribPointer(c._program.attributes.a_position,this._positionBuffer.itemSize,o.FLOAT,!1,0,0),o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,this._normalMapVerticesTexture),o.uniform1i(c._program.uniforms.s_texture,0),o.drawArrays(o.TRIANGLE_STRIP,0,this._positionBuffer.numItems),!0}return!0}return!1}_drawNormalMapNoBlur(e){let t=e.normalMapNormals;if(e.node&&0!==e.node.getState()&&t&&t.length){const i=t.length/3,n=Math.sqrt(i)-1;let r=this._verticesBufferArray[n];if(r){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let s=e.normalMapTexturePtr;const a=this._handler,o=a.gl;let l=a.createArrayBuffer(t,3,i,o.DYNAMIC_DRAW);const h=this._framebuffer,c=a.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(s),c.activate(),o.bindBuffer(o.ARRAY_BUFFER,r),o.vertexAttribPointer(d.a_position,r.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,l),o.vertexAttribPointer(d.a_normal,l.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[n]),o.drawElements(o.TRIANGLE_STRIP,this._indexBufferArray[n].numItems,o.UNSIGNED_INT,0),o.deleteBuffer(l),!0}return!0}return!1}_drawNormalMap(e){return e.planet.terrain.isBlur(e)?this._drawNormalMapBlur(e):this._drawNormalMapNoBlur(e)}drawSingle(e){const t=this._handler.gl;this._framebuffer.activate(),t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),e.terrainReady&&this._drawNormalMap(e)&&(e.normalMapReady=!0,e.normalMapTexture=e.normalMapTexturePtr,e.normalMapTextureBias[0]=0,e.normalMapTextureBias[1]=0,e.normalMapTextureBias[2]=1),e._inTheQueue=!1,t.enable(t.DEPTH_TEST),t.enable(t.CULL_FACE),t.enable(t.BLEND),this._framebuffer.deactivate()}frame(){if(this._queue.length){const e=this._handler.gl;this._framebuffer.activate(),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.BLEND);let t=0,i=window.performance.now();for(;this._lock.isFree()&&this._queue.length&&t<.25;){const e=this._queue.shift();e.terrainReady&&this._drawNormalMap(e)&&(e.normalMapReady=!0,e.normalMapTexture=e.normalMapTexturePtr,e.normalMapTextureBias[0]=0,e.normalMapTextureBias[1]=0,e.normalMapTextureBias[2]=1),e._inTheQueue=!1,t=window.performance.now()-i}e.enable(e.BLEND),e.enable(e.DEPTH_TEST),e.enable(e.CULL_FACE),this._framebuffer.deactivate()}}get queueSize(){return this._queue.length}queue(e){e._inTheQueue=!0,this._queue.push(e)}unshift(e){e._inTheQueue=!0,this._queue.unshift(e)}remove(e){}clear(){for(;this._queue.length;){this._queue.pop()._inTheQueue=!1}}lock(e){this._lock.lock(e)}free(e){this._lock.free(e)}}class za extends Jt{constructor(e=2){super(e,Da)}_onMessage(e){this._source.get(e.data.id)._plainSegmentWorkerCallback(e.data),e.data.plainVertices=null,e.data.plainVerticesHigh=null,e.data.plainVerticesLow=null,e.data.plainNormals=null,e.data.normalMapNormals=null,e.data.normalMapVertices=null,e.data.normalMapVerticesHigh=null,e.data.normalMapVerticesLow=null,this._source.delete(e.data.id)}setGeoid(e){if(e.model){let t=e.model,i={scale:t.scale,offset:t.offset,width:t.width,height:t.height,rlonres:t.rlonres,rlatres:t.rlatres,i:t.i};this._workerQueue.forEach((e=>{let n=new Uint8Array(t.rawfile.length);n.set(t.rawfile),e.postMessage({model:i,rawfile:n},[n.buffer])}))}else this._workerQueue.forEach((e=>{e.postMessage({model:null})}))}make(e){if(e.initialized)if(this._workerQueue.length){let t=this._workerQueue.pop();this._source.set(this._sourceId,e);let i=new Float64Array([this._sourceId,e._projection.id===ia.id?1:0,e.planet.terrain.gridSizeByZoom[e.tileZoom],e.planet.terrain.plainGridSize,e._extent.southWest.lon,e._extent.southWest.lat,e._extent.northEast.lon,e._extent.northEast.lat,e.planet.ellipsoid._e2,e.planet.ellipsoid.equatorialSize,e.planet.ellipsoid._invRadii2.x,e.planet.ellipsoid._invRadii2.y,e.planet.ellipsoid._invRadii2.z,e.planet._heightFactor]);this._sourceId++,t.postMessage({params:i},[i.buffer])}else this._pendingQueue.push(e);else this.check()}}const Da="\n 'use strict';\n \n let model = null;\n\n let cached_ix = null;\n let cached_iy = null;\n let v00 = null;\n let v01 = null;\n let v10 = null;\n let v11 = null;\n let t = null;\n\n function rawval(ix, iy) {\n\n if (iy < 0) {\n iy = -iy;\n ix += model.width / 2;\n } else if (iy >= model.height) {\n iy = 2 * (model.height - 1) - iy;\n ix += model.width / 2;\n }\n\n if (ix < 0) {\n ix += model.width;\n } else if (ix >= model.width) {\n ix -= model.width;\n }\n\n var k = (iy * model.width + ix) * 2 + model.i;\n\n return (model.rawfile[k] << 8) | model.rawfile[k + 1];\n };\n\n function getHeightMSL(lon, lat) {\n\n if (!model) return 0;\n\n if (lon < 0) lon += 360.0;\n\n var fy = (90 - lat) * model.rlatres;\n var fx = lon * model.rlonres;\n var iy = Math.floor(fy);\n var ix = Math.floor(fx);\n\n fx -= ix;\n fy -= iy;\n\n if (iy === (model.height - 1)) {\n iy--;\n }\n\n if ((cached_ix !== ix) || (cached_iy !== iy)) {\n\n cached_ix = ix;\n cached_iy = iy;\n\n v00 = rawval(ix, iy);\n v01 = rawval(ix + 1, iy);\n v10 = rawval(ix, iy + 1);\n v11 = rawval(ix + 1, iy + 1);\n }\n\n let h = null;\n\n var a = (1 - fx) * v00 + fx * v01;\n var b = (1 - fx) * v10 + fx * v11;\n\n h = (1 - fy) * a + fy * b;\n\n return model.offset + model.scale * h;\n };\n\n const HALF_PI = Math.PI * 0.5;\n const POLE = 20037508.34;\n const PI_BY_POLE = Math.PI / POLE;\n const INV_POLE_BY_180 = 180.0 / POLE;\n const INV_PI_BY_180 = 180.0 / Math.PI;\n const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;\n const RADIANS = Math.PI / 180.0;\n const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;\n\n let E2 = 0.0,\n A = 0.0;\n\n let _projFunc = null;\n\n const Vec3 = function (x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n };\n\n var geodeticToCartesian = function (lon, lat, heightFactor, res) {\n\n let h = getHeightMSL(lon, lat) * heightFactor;\n\n let latrad = RADIANS * lat,\n lonrad = RADIANS * lon;\n\n let slt = Math.sin(latrad);\n\n let N = A / Math.sqrt(1.0 - E2 * slt * slt);\n let nc = (N + h) * Math.cos(latrad); \n \n res.x = nc * Math.cos(lonrad);\n res.y = nc * Math.sin(lonrad);\n res.z = (N * (1 - E2) + h) * slt;\n };\n\n var geodeticToCartesianInverse = function (lon, lat, heightFactor, res){\n geodeticToCartesian(\n lon * INV_POLE_BY_180,\n INV_PI_BY_360 * Math.atan(Math.exp(lat * PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,\n heightFactor,\n res);\n };\n\n var v = new Vec3(0.0, 0.0, 0.0);\n var _tempHigh = new Vec3(0.0, 0.0, 0.0);\n var _tempLow = new Vec3(0.0, 0.0, 0.0);\n\n var doubleToTwoFloats = function(v, high, low) {\n\n let x = v.x, y = v.y, z = v.z;\n \n if (x >= 0.0) {\n var doubleHigh = Math.floor(x / 65536.0) * 65536.0;\n high.x = Math.fround(doubleHigh);\n low.x = Math.fround(x - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-x / 65536.0) * 65536.0;\n high.x = Math.fround(-doubleHigh);\n low.x = Math.fround(x + doubleHigh);\n }\n\n if (y >= 0.0) {\n var doubleHigh = Math.floor(y / 65536.0) * 65536.0;\n high.y = Math.fround(doubleHigh);\n low.y = Math.fround(y - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-y / 65536.0) * 65536.0;\n high.y = Math.fround(-doubleHigh);\n low.y = Math.fround(y + doubleHigh);\n }\n\n if (z >= 0.0) {\n var doubleHigh = Math.floor(z / 65536.0) * 65536.0;\n high.z = Math.fround(doubleHigh);\n low.z = Math.fround(z - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-z / 65536.0) * 65536.0;\n high.z = Math.fround(-doubleHigh);\n low.z = Math.fround(z + doubleHigh);\n }\n };\n\n self.onmessage = function (msg) {\n if(msg.data.model) {\n model = msg.data.model;\n model.rawfile = msg.data.rawfile;\n } else if(msg.data.params) {\n\n let xmin = 549755748352.0, xmax = -549755748352.0, \n ymin = 549755748352.0, ymax = -549755748352.0, \n zmin = 549755748352.0, zmax = -549755748352.0;\n\n E2 = msg.data.params[8];\n A = msg.data.params[9];\n\n let gridSize = msg.data.params[2],\n fgs = msg.data.params[3],\n r2_x = msg.data.params[10],\n r2_y = msg.data.params[11],\n r2_z = msg.data.params[12];\n\n let heightFactor = msg.data.params[13];\n \n if(msg.data.params[1] === 0.0){\n _projFunc = geodeticToCartesianInverse;\n }else{\n _projFunc = geodeticToCartesian;\n }\n\n let maxFgs = Math.max(fgs, gridSize);\n let llStep = (msg.data.params[6] - msg.data.params[4]) / maxFgs;\n let ltStep = (msg.data.params[7] - msg.data.params[5]) / maxFgs;\n\n let esw_lon = msg.data.params[4],\n ene_lat = msg.data.params[7];\n\n let dg = Math.max(fgs / gridSize, 1.0),\n gs = maxFgs + 1;\n \n const gsgs = gs * gs;\n\n const gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;\n\n let plainNormals = new Float32Array(gridSize3);\n\n let plainVertices = new Float64Array(gridSize3);\n let plainVerticesHigh = new Float32Array(gridSize3);\n let plainVerticesLow = new Float32Array(gridSize3);\n\n let normalMapNormals = new Float32Array(gsgs * 3);\n\n let normalMapVertices = new Float64Array(gsgs * 3);\n let normalMapVerticesHigh = new Float32Array(gsgs * 3);\n let normalMapVerticesLow = new Float32Array(gsgs * 3);\n\n let ind = 0,\n nmInd = 0;\n\n for (let k = 0; k < gsgs; k++) {\n\n let j = k % gs,\n i = ~~(k / gs);\n\n _projFunc(esw_lon + j * llStep, ene_lat - i * ltStep, heightFactor, v);\n\n let nx = v.x * r2_x, ny = v.y * r2_y, nz = v.z * r2_z;\n let l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz); \n let nxl = nx * l,\n nyl = ny * l,\n nzl = nz * l;\n\n doubleToTwoFloats(v, _tempHigh, _tempLow);\n\n normalMapVertices[nmInd] = v.x;\n normalMapVerticesHigh[nmInd] = _tempHigh.x;\n normalMapVerticesLow[nmInd] = _tempLow.x;\n normalMapNormals[nmInd++] = nxl;\n\n normalMapVertices[nmInd] = v.y;\n normalMapVerticesHigh[nmInd] = _tempHigh.y;\n normalMapVerticesLow[nmInd] = _tempLow.y;\n normalMapNormals[nmInd++] = nyl;\n\n normalMapVertices[nmInd] = v.z;\n normalMapVerticesHigh[nmInd] = _tempHigh.z;\n normalMapVerticesLow[nmInd] = _tempLow.z;\n normalMapNormals[nmInd++] = nzl;\n\n if (i % dg === 0 && j % dg === 0) {\n plainVertices[ind] = v.x;\n plainVerticesHigh[ind] = _tempHigh.x;\n plainVerticesLow[ind] = _tempLow.x;\n plainNormals[ind++] = nxl;\n\n plainVertices[ind] = v.y;\n plainVerticesHigh[ind] = _tempHigh.y;\n plainVerticesLow[ind] = _tempLow.y;\n plainNormals[ind++] = nyl;\n\n plainVertices[ind] = v.z;\n plainVerticesHigh[ind] = _tempHigh.z;\n plainVerticesLow[ind] = _tempLow.z;\n plainNormals[ind++] = nzl;\n\n if (v.x < xmin) xmin = v.x; if (v.x > xmax) xmax = v.x;\n if (v.y < ymin) ymin = v.y; if (v.y > ymax) ymax = v.y;\n if (v.z < zmin) zmin = v.z; if (v.z > zmax) zmax = v.z;\n }\n }\n\n let x = (xmax - xmin) * 0.5,\n y = (ymax - ymin) * 0.5,\n z = (zmax - zmin) * 0.5;\n\n let plainRadius = Math.sqrt(x * x + y * y + z * z);\n\n self.postMessage({\n id: msg.data.params[0],\n plainVertices: plainVertices,\n plainVerticesHigh: plainVerticesHigh,\n plainVerticesLow: plainVerticesLow,\n plainNormals: plainNormals,\n normalMapNormals: normalMapNormals,\n normalMapVertices: normalMapVertices,\n normalMapVerticesHigh: normalMapVerticesHigh,\n normalMapVerticesLow: normalMapVerticesLow,\n plainRadius: plainRadius\n }, [\n plainVertices.buffer,\n plainVerticesHigh.buffer,\n plainVerticesLow.buffer,\n plainNormals.buffer,\n normalMapNormals.buffer,\n normalMapVertices.buffer,\n normalMapVerticesHigh.buffer,\n normalMapVerticesLow.buffer\n ]);\n }\n }";function Fa(e){let t=1/Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]*=t,e[1]*=t,e[2]*=t,e[3]*=t}class Na{constructor(e={}){this._pickingColorU=new Float32Array([0,0,0]),this._f=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],this.projectionMatrix=new se,this.inverseProjectionMatrix=new se,this.projectionViewMatrix=new se,this.inverseProjectionViewMatrix=new se,this.left=0,this.right=0,this.bottom=0,this.top=0,this.near=0,this.far=0,this.cameraFrustumIndex=null!=e.cameraFrustumIndex?e.cameraFrustumIndex:-1,this.setProjectionMatrix(e.fov||30,e.aspect||1,e.near||1,e.far||1e3)}getRightPlane(){return this._f[0]}getLeftPlane(){return this._f[1]}getBottomPlane(){return this._f[2]}getTopPlane(){return this._f[3]}getBackwardPlane(){return this._f[4]}getForwardPlane(){return this._f[5]}getProjectionViewMatrix(){return this.projectionViewMatrix._m}getProjectionMatrix(){return this.projectionMatrix._m}getInverseProjectionMatrix(){return this.inverseProjectionMatrix._m}setProjectionMatrix(e,t,i,n){this.top=i*Math.tan(e*c),this.bottom=-this.top,this.right=this.top*t,this.left=-this.right,this.near=i,this.far=n,this.projectionMatrix.setPerspective(this.left,this.right,this.bottom,this.top,i,n),this.projectionMatrix.inverseTo(this.inverseProjectionMatrix)}setViewMatrix(e){this.projectionViewMatrix=this.projectionMatrix.mul(e),this.projectionViewMatrix.inverseTo(this.inverseProjectionViewMatrix);let t=this.projectionViewMatrix._m;this._f[0][0]=t[3]-t[0],this._f[0][1]=t[7]-t[4],this._f[0][2]=t[11]-t[8],this._f[0][3]=t[15]-t[12],Fa(this._f[0]),this._f[1][0]=t[3]+t[0],this._f[1][1]=t[7]+t[4],this._f[1][2]=t[11]+t[8],this._f[1][3]=t[15]+t[12],Fa(this._f[1]),this._f[2][0]=t[3]+t[1],this._f[2][1]=t[7]+t[5],this._f[2][2]=t[11]+t[9],this._f[2][3]=t[15]+t[13],Fa(this._f[2]),this._f[3][0]=t[3]-t[1],this._f[3][1]=t[7]-t[5],this._f[3][2]=t[11]-t[9],this._f[3][3]=t[15]-t[13],Fa(this._f[3]),this._f[4][0]=t[3]-t[2],this._f[4][1]=t[7]-t[6],this._f[4][2]=t[11]-t[10],this._f[4][3]=t[15]-t[14],Fa(this._f[4]),this._f[5][0]=t[3]+t[2],this._f[5][1]=t[7]+t[6],this._f[5][2]=t[11]+t[10],this._f[5][3]=t[15]+t[14],Fa(this._f[5])}containsPoint(e){for(let t=0;t<6;t++){if(e.dotArr(this._f[t])+this._f[t][3]<=0)return!1}return!0}containsSphereBottomExc(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[0])+i[0][3]<=t)&&(!(e.center.dotArr(i[1])+i[1][3]<=t)&&(!(e.center.dotArr(i[3])+i[3][3]<=t)&&(!(e.center.dotArr(i[4])+i[4][3]<=t)&&!(e.center.dotArr(i[5])+i[5][3]<=t))))}containsSphereButtom(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[2])+i[2][3]<=t)}containsSphere(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[0])+i[0][3]<=t)&&(!(e.center.dotArr(i[1])+i[1][3]<=t)&&(!(e.center.dotArr(i[2])+i[2][3]<=t)&&(!(e.center.dotArr(i[3])+i[3][3]<=t)&&(!(e.center.dotArr(i[4])+i[4][3]<=t)&&!(e.center.dotArr(i[5])+i[5][3]<=t)))))}containsSphere2(e,t){let i=-t;return!(e.dotArr(this._f[0])+this._f[0][3]<=i)&&(!(e.dotArr(this._f[1])+this._f[1][3]<=i)&&(!(e.dotArr(this._f[2])+this._f[2][3]<=i)&&(!(e.dotArr(this._f[3])+this._f[3][3]<=i)&&(!(e.dotArr(this._f[4])+this._f[4][3]<=i)&&!(e.dotArr(this._f[5])+this._f[5][3]<=i)))))}containsBox(e){let t,i,n=!0;for(let r=0;r<6;r++){t=0,i=0;for(let n=0;n<8&&(0===i||0===t);n++){e.vertices[n].dotArr(this._f[r])+this._f[r][3]<0?t++:i++}if(0===i)return!1;t>0&&(n=!0)}return n}}const Ha=["viewchange","moveend"];class Oa{constructor(e,t={}){if(this.renderer=e,this.events=Pt(Ha,this),this.eye=t.eye||new oe,this.eyeHigh=new Float32Array(3),this.eyeLow=new Float32Array(3),this._aspect=t.aspect||1,this._viewAngle=t.viewAngle||47,this._viewMatrix=new se,this._normalMatrix=new ne,this._r=new oe(1,0,0),this._u=new oe(0,1,0),this._b=new oe(0,0,1),this._pr=this._r.clone(),this._pu=this._u.clone(),this._pb=this._b.clone(),this._peye=this.eye.clone(),this.isMoving=!1,this._tanViewAngle_hrad=0,this._tanViewAngle_hradOneByHeight=0,this.frustums=[],this.frustumColors=[],t.frustums)for(let e=0,i=t.frustums.length;e<i;e++){let i=t.frustums[e],n=new Na({fov:this._viewAngle,aspect:this._aspect,near:i[0],far:i[1]});n.cameraFrustumIndex=this.frustums.length,this.frustums.push(n),this.frustumColors.push(n._pickingColorU[0],n._pickingColorU[1],n._pickingColorU[2])}else{let e=1,t=1e4,i=new Na({fov:this._viewAngle,aspect:this._aspect,near:e,far:t});i.cameraFrustumIndex=this.frustums.length,this.frustums.push(i),this.frustumColors.push(i._pickingColorU[0],i._pickingColorU[1],i._pickingColorU[2])}this.FARTHEST_FRUSTUM_INDEX=this.frustums.length-1,this.currentFrustumIndex=0,this.isFirstPass=!1,this._projSizeConst=0,this.set(t.eye||new oe(0,0,1),t.look||new oe,t.up||new oe(0,1,0))}checkMoveEnd(){let e=this._r,t=this._u,i=this._b,n=this.eye;this._peye.equal(n)&&this._pr.equal(e)&&this._pu.equal(t)&&this._pb.equal(i)?(this.isMoving&&this.events.dispatch(this.events.moveend,this),this.isMoving=!1):this.isMoving=!0,this._pr.copy(e),this._pu.copy(t),this._pb.copy(i),this._peye.copy(n)}bindRenderer(e){this.renderer=e;for(let e=0;e<this.frustums.length;e++)this.renderer.assignPickingColor(this.frustums[e]);this._aspect=this.renderer.handler.getClientAspect(),this._setProj(this._viewAngle,this._aspect)}_init(e){this._setProj(this._viewAngle,this._aspect),this.set(e.eye||new oe(0,0,1),e.look||new oe,e.up||new oe(0,1,0))}getUp(){return this._u.clone()}getDown(){return this._u.negateTo()}getRight(){return this._r.clone()}getLeft(){return this._r.negateTo()}getForward(){return this._b.negateTo()}getBackward(){return this._b.clone()}update(){let e=this._r,t=this._u,i=this._b,n=this.eye;oe.doubleToTwoFloat32Array(n,this.eyeHigh,this.eyeLow),this._viewMatrix.set([e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,-n.dot(e),-n.dot(t),-n.dot(i),1]);for(let e=0,t=this.frustums.length;e<t;e++)this.frustums[e].setViewMatrix(this._viewMatrix);this.events.dispatch(this.events.viewchange,this)}refresh(){this._setProj(this._viewAngle,this._aspect),this.update()}setAspectRatio(e){this._aspect=e,this.refresh()}getAspectRatio(){return this._aspect}_setProj(e,t){this._viewAngle=e,this._aspect=t,this._tanViewAngle_hrad=Math.tan(e*c),this._tanViewAngle_hradOneByHeight=this._tanViewAngle_hrad*this.renderer.handler._oneByHeight;let i=this.renderer.handler.canvas;this._projSizeConst=Math.min(i.clientWidth<512?512:i.clientWidth,i.clientHeight<512?512:i.clientHeight)/(e*o);for(let i=0,n=this.frustums.length;i<n;i++)this.frustums[i].setProjectionMatrix(e,t,this.frustums[i].near,this.frustums[i].far)}setViewAngle(e){this._viewAngle=e,this.refresh()}getViewAngle(){return this._viewAngle}get viewAngle(){return this._viewAngle}set(e,t,i){return this.eye.x=e.x,this.eye.y=e.y,this.eye.z=e.z,t=t||this._b,i=i||this._u,this._b.x=e.x-t.x,this._b.y=e.y-t.y,this._b.z=e.z-t.z,this._r.copy(i.cross(this._b)),this._b.normalize(),this._r.normalize(),this._u.copy(this._b.cross(this._r)),this}look(e,t){this._b.set(this.eye.x-e.x,this.eye.y-e.y,this.eye.z-e.z),this._r.copy((t||this._u).cross(this._b)),this._b.normalize(),this._r.normalize(),this._u.copy(this._b.cross(this._r))}slide(e,t,i){this.eye.x+=e*this._r.x+t*this._u.x+i*this._b.x,this.eye.y+=e*this._r.y+t*this._u.y+i*this._b.y,this.eye.z+=e*this._r.z+t*this._u.z+i*this._b.z}roll(e){let t=Math.cos(o*e),i=Math.sin(o*e),n=this._r.clone();this._r.set(t*n.x-i*this._u.x,t*n.y-i*this._u.y,t*n.z-i*this._u.z),this._u.set(i*n.x+t*this._u.x,i*n.y+t*this._u.y,i*n.z+t*this._u.z)}pitch(e){let t=Math.cos(o*e),i=Math.sin(o*e),n=this._b.clone();this._b.set(t*n.x-i*this._u.x,t*n.y-i*this._u.y,t*n.z-i*this._u.z),this._u.set(i*n.x+t*this._u.x,i*n.y+t*this._u.y,i*n.z+t*this._u.z)}yaw(e){let t=Math.cos(o*e),i=Math.sin(o*e),n=this._r.clone();this._r.set(t*n.x-i*this._b.x,t*n.y-i*this._b.y,t*n.z-i*this._b.z),this._b.set(i*n.x+t*this._b.x,i*n.y+t*this._b.y,i*n.z+t*this._b.z)}unproject(e,t){let i=this.renderer.handler.canvas,n=.5*i.width,r=.5*i.height,s=(e-n)/n,a=-(t-r)/r,o=this.frustums[0].inverseProjectionViewMatrix.mulVec4(new re(s,a,-1,1)).affinity();return this.frustums[0].inverseProjectionViewMatrix.mulVec4(new re(s,a,0,1)).affinity().subA(o).toVec3().normalize()}project(e){let t=this.frustums[0].projectionViewMatrix.mulVec4(e.toVec4()),i=this.renderer.handler.canvas;return new le((1+t.x/t.w)*i.width*.5,(1-t.y/t.w)*i.height*.5)}rotateAround(e,t,i,n){i=i||oe.ZERO,n=n||oe.UP;let r=(new se).setRotation(t?this._u:n,e),s=(new se).setIdentity().translate(i),a=(new se).setIdentity().translate(i.negateTo()),o=s.mul(r).mul(a);this.eye=o.mulVec3(this.eye),this._u=r.mulVec3(this._u).normalize(),this._r=r.mulVec3(this._r).normalize(),this._b=r.mulVec3(this._b).normalize()}rotateHorizontal(e,t,i,n){this.rotateAround(e,t,i,n)}rotateVertical(e,t){this.rotateAround(e,!1,t,this._r)}projectedSize(e,t){return Math.atan(t/this.eye.distance(e))*this._projSizeConst}getViewMatrix(){return this._viewMatrix._m}getNormalMatrix(){return this._normalMatrix._m}setCurrentFrustum(e){this.currentFrustumIndex=e,this.isFirstPass=e===this.FARTHEST_FRUSTUM_INDEX}getCurrentFrustum(){return this.currentFrustumIndex}get frustum(){return this.frustums[this.currentFrustumIndex]}getProjectionMatrix(){return this.frustum.projectionMatrix._m}getProjectionViewMatrix(){return this.frustum.projectionViewMatrix._m}getInverseProjectionViewMatrix(){return this.frustum.inverseProjectionViewMatrix._m}getInverseProjectionMatrix(){return this.frustum.inverseProjectionMatrix._m}}class Va extends Oa{constructor(e,t={}){super(e.renderer,{...t,frustums:t.frustums||[[1,100.075],[100,1000.075],[1e3,101e4],[1e6,1e9]]}),this.planet=e,this.minAltitude=t.minAltitude||1,this.maxAltitude=t.maxAltitude||2e7,this._lonLat=this.planet.ellipsoid.cartesianToLonLat(this.eye),this._lonLatMerc=this._lonLat.forwardMercator(),this._terrainAltitude=this._lonLat.height,this._terrainPoint=new oe,this._insideSegment=null,this.slope=0,this._keyLock=new xr,this._framesArr=[],this._framesCounter=0,this._numFrames=50,this._completeCallback=null,this._frameCallback=null,this._flying=!1,this._checkTerrainCollision=!0,this.eyeNorm=this.eye.getNormal()}setTerrainCollisionActivity(e){this._checkTerrainCollision=e}update(){this.events.stopPropagation();let e=this.maxAltitude+this.planet.ellipsoid.getEquatorialSize();this.eye.length()>e&&this.eye.copy(this.eye.getNormal().scale(e)),super.update(),this.updateGeodeticPosition(),this.eyeNorm=this.eye.getNormal(),this.slope=this._b.dot(this.eyeNorm),this.events.dispatch(this.events.viewchange,this)}updateGeodeticPosition(){this.planet.ellipsoid.cartesianToLonLatRes(this.eye,this._lonLat),Math.abs(this._lonLat.lat)<=J&&z.forwardMercatorRes(this._lonLat,this._lonLatMerc)}setAltitude(e){let t=this._terrainPoint,i=this.planet.ellipsoid.getSurfaceNormal3v(this.eye);this.eye.x=i.x*e+t.x,this.eye.y=i.y*e+t.y,this.eye.z=i.z*e+t.z,this._terrainAltitude=e}getAltitude(){return this._terrainAltitude}setLonLat(e,t,i){this.stopFlying(),this._lonLat.set(e.lon,e.lat,e.height||this._lonLat.height);let n=this.planet.ellipsoid,r=n.lonLatToCartesian(this._lonLat),s=t?n.lonLatToCartesian(t):oe.ZERO;this.set(r,s,i||oe.NORTH),this.update()}getLonLat(){return this._lonLat}getHeight(){return this._lonLat.height}getExtentPosition(e,t){t=t||0;let i=e.getNorth(),n=e.getSouth(),r=e.getEast(),s=e.getWest();s>r&&(r+=360);let a=this.planet.ellipsoid,l=new z(r,i),h=a.lonLatToCartesian(l);l.lat=n;let c=a.lonLatToCartesian(l);l.lon=s;let d=a.lonLatToCartesian(l);l.lat=i;let _=a.lonLatToCartesian(l),u=oe.sub(h,d).scale(.5).addA(d),f=u.length();f<1e-6&&(l.lon=.5*(r+s),l.lat=.5*(i+n),u=a.lonLatToCartesian(l)),_.subA(u),c.subA(u),h.subA(u),d.subA(u);let g=u.getNormal(),p=g.cross(oe.NORTH).normalize(),m=p.cross(g).normalize(),v=Math.max(Math.abs(m.dot(_)),Math.abs(m.dot(c)),Math.abs(m.dot(h)),Math.abs(m.dot(d))),y=Math.max(Math.abs(p.dot(_)),Math.abs(p.dot(c)),Math.abs(p.dot(h)),Math.abs(p.dot(d))),x=Math.tan(this._viewAngle*o*.5),b=this._aspect*x,w=Math.max(y/b,v/x);return u.normalize(),u.scale(f+w+t),u}viewExtent(e,t){this.stopFlying(),this.set(this.getExtentPosition(e,t),oe.ZERO,oe.NORTH),this.update()}flyExtent(e,t,i,n,r,s,a){this.flyCartesian(this.getExtentPosition(e,t),oe.ZERO,i,null==n?1:n,r,s,a)}viewDistance(e,t=1e4){let i=this.eye.add(this.getForward().scaleTo(t)),n=ae.getRotationBetweenVectors(i.getNormal(),e.getNormal());if(n.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let i=e.add(n.mulVec3(this.getBackward()).scale(t)),r=n.mulVec3(this.getUp());this.set(i,e,r)}this.update()}flyDistance(e,t=1e4,i=0,n,r,s){let a=this.eye.add(this.getForward().scaleTo(t)),o=ae.getRotationBetweenVectors(a.getNormal(),e.getNormal());if(o.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let a=e.add(o.mulVec3(this.getBackward()).scale(t)),l=o.mulVec3(this.getUp());this.flyCartesian(a,e,l,i,n,r,s)}}flyCartesian(e,t=oe.ZERO,i=oe.NORTH,n=1,r=(()=>{}),s=(()=>{}),a=(()=>{})){this.stopFlying(),t=t||oe.ZERO,i=i||oe.NORTH,this._completeCallback=r,this._frameCallback=a,s&&s.call(this),t instanceof z&&(t=this.planet.ellipsoid.lonLatToCartesian(t));let o=this.planet.ellipsoid.lonLatToCartesian(new z(this._lonLat.lon,this._lonLat.lat)),l=this._u,h=this._b,c=this.planet.ellipsoid.cartesianToLonLat(e),_=i,u=this.planet.ellipsoid.lonLatToCartesian(new z(c.lon,c.lat,0)),f=oe.sub(e,t),g=_.cross(f);f.normalize(),g.normalize();let p=f.cross(g),m=o.getNormal(),v=u.getNormal(),y=1-m.dot(v),x=n*d*Math.sqrt(y>0?y:0),b=6639613,w=Math.max(this._lonLat.height,c.height);w>b&&(b=w);let C=w+2.5*x*(b-w),T=oe.ZERO;for(let e=0;e<=this._numFrames;e++){let t=1-e/this._numFrames;t=t*t*(3-2*t),t*=t;let i=o.smerp(u,t).normalize(),n=this.planet.getRayIntersectionEllipsoid(new _i(T,i)),r=1-t,s=this._lonLat.height*t*t*t+3*C*t*t*r+3*C*t*r*r+c.height*r*r*r,a=n.addA(i.scale(s)),d=l.smerp(p,t),_=oe.add(a,h.smerp(f,t).negateTo()),g=new oe(a.x-_.x,a.y-_.y,a.z-_.z),m=d.cross(g);g.normalize(),m.normalize();let v=g.cross(m);this._framesArr[e]={eye:a,n:g,u:m,v:v}}this._framesCounter=this._numFrames,this._flying=!0}flyLonLat(e,t,i,n,r,s,a){let o=new z(e.lon,e.lat,e.height||this._lonLat.height);this.flyCartesian(this.planet.ellipsoid.lonLatToCartesian(o),t,i,n,r,s,a)}stopFlying(){this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet.normalMapCreator.free(this._keyLock),this._flying=!1,this._framesArr.length=0,this._framesArr=[],this._framesCounter=-1,this._frameCallback=null}isFlying(){return this._flying}rotateLeft(e,t){this.rotateHorizontal(e*o,!0!==t,oe.ZERO),this.update()}rotateRight(e,t){this.rotateHorizontal(-e*o,!0!==t,oe.ZERO),this.update()}rotateUp(e){this.rotateVertical(e*o,oe.ZERO),this.update()}rotateDown(e){this.rotateVertical(-e*o,oe.ZERO),this.update()}rotateVertical(e,t,i=0){let n=(new se).setRotation(this._r,e),r=(new se).setIdentity().translate(t),s=(new se).setIdentity().translate(t.negateTo()),a=r.mul(n).mul(s).mulVec3(this.eye),o=n.mulVec3(this._u).normalize(),l=n.mulVec3(this._r).normalize(),h=n.mulVec3(this._b).normalize(),c=a.getNormal(),d=h.dot(c);if(i){let e=d-this.slope;if(d<i&&e<0)return;(d>.1&&o.dot(c)>0||this.slope<=.1||this._u.dot(this.eye.getNormal())<=0)&&(this.eye=a,this._u=o,this._r=l,this._b=h)}else this.eye=a,this._u=o,this._r=l,this._b=h}checkFly(){if(this._flying){let e=this._numFrames-this._framesCounter;this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet.normalMapCreator.lock(this._keyLock),this.eye=this._framesArr[e].eye,this._r=this._framesArr[e].u,this._u=this._framesArr[e].v,this._b=this._framesArr[e].n,this._frameCallback&&this._frameCallback(),this.update(),this._framesCounter--,this._framesCounter<0&&(this.stopFlying(),this._completeCallback&&(this._completeCallback(),this._completeCallback=null))}}checkTerrainCollision(){if(this._terrainAltitude=this._lonLat.height,this._insideSegment&&this._insideSegment.planet)return this._terrainAltitude=this._insideSegment.getTerrainPoint(this.eye,this._insideSegment.getInsideLonLat(this),this._terrainPoint),this._terrainAltitude<this.minAltitude&&this._checkTerrainCollision&&this.setAltitude(this.minAltitude),this._terrainPoint}getSurfaceVisibleDistance(e){let t=this.planet.ellipsoid.equatorialSize;return t*Math.acos(t/(t+this._lonLat.height+e))}getHeading(){let e=this.eye.getNormal(),t=oe.proj_b_to_plane(this.slope>=.97?this.getUp():this.getForward(),e).normalize(),i=oe.proj_b_to_plane(oe.NORTH,e).normalize(),n=Math.sign(e.dot(t.cross(i)))*Math.acos(t.dot(i))*l;return n<0?360+n:n}isVisible(e){let t=this.eye.length();return this.eye.distance(e)<Math.sqrt(t*t-this.planet.ellipsoid.equatorialSizeSqr)}}class Ua extends Jt{constructor(e=2){super(e,Ga)}_onMessage(e){this._source.get(e.data.id).segment._terrainWorkerCallback(e.data),this._source.delete(e.data.id),e.data.normalMapNormals=null,e.data.normalMapVertices=null,e.data.normalMapVerticesHigh=null,e.data.normalMapVerticesLow=null,e.data.terrainVertices=null,e.data.terrainVerticesHigh=null,e.data.terrainVerticesLow=null}make(e){if(e.segment.plainReady&&e.segment.terrainIsLoading)if(this._workerQueue.length){const t=this._workerQueue.pop();this._source.set(this._sourceId,e);let i=e.segment;t.postMessage({elevations:e.elevations,this_plainVertices:i.plainVertices,this_plainNormals:i.plainNormals,this_normalMapVertices:i.normalMapVertices,this_normalMapNormals:i.normalMapNormals,heightFactor:i.planet._heightFactor,gridSize:i.planet.terrain.gridSizeByZoom[i.tileZoom],noDataValues:i.planet.terrain.noDataValues,id:this._sourceId},[e.elevations.buffer,i.plainVertices.buffer,i.plainNormals.buffer,i.normalMapVertices.buffer,i.normalMapNormals.buffer]),this._sourceId++}else this._pendingQueue.push(e);else this.check()}}const Ga="'use strict';\n //\n //Terrain worker\n //\n\n function binarySearchFast(arr, x) {\n let start = 0,\n end = arr.length - 1;\n while (start <= end) {\n let k = Math.floor((start + end) * 0.5); \n if (Math.abs(arr[k] - x) < 1e-3)\n return k;\n else if (arr[k] < x)\n start = k + 1;\n else\n end = k - 1;\n }\n return -1;\n };\n\n function checkNoDataValue(noDataValues, value) {\n return binarySearchFast(noDataValues, value) !== -1;\n };\n\n\n var Vec3 = function(x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n };\n\n var doubleToTwoFloats = function(v, high, low) {\n\n let x = v.x, y = v.y, z = v.z;\n \n if (x >= 0.0) {\n var doubleHigh = Math.floor(x / 65536.0) * 65536.0;\n high.x = Math.fround(doubleHigh);\n low.x = Math.fround(x - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-x / 65536.0) * 65536.0;\n high.x = Math.fround(-doubleHigh);\n low.x = Math.fround(x + doubleHigh);\n }\n\n if (y >= 0.0) {\n var doubleHigh = Math.floor(y / 65536.0) * 65536.0;\n high.y = Math.fround(doubleHigh);\n low.y = Math.fround(y - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-y / 65536.0) * 65536.0;\n high.y = Math.fround(-doubleHigh);\n low.y = Math.fround(y + doubleHigh);\n }\n\n if (z >= 0.0) {\n var doubleHigh = Math.floor(z / 65536.0) * 65536.0;\n high.z = Math.fround(doubleHigh);\n low.z = Math.fround(z - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-z / 65536.0) * 65536.0;\n high.z = Math.fround(-doubleHigh);\n low.z = Math.fround(z + doubleHigh);\n }\n };\n\n Vec3.prototype.sub = function(v) {\n return new Vec3(this.x - v.x, this.y - v.y, this.z - v.z);\n };\n\n Vec3.prototype.add = function(v) {\n return new Vec3(this.x + v.x, this.y + v.y, this.z + v.z);\n };\n\n Vec3.prototype.cross = function(v) {\n return new Vec3(\n this.y * v.z - this.z * v.y,\n this.z * v.x - this.x * v.z,\n this.x * v.y - this.y * v.x\n );\n };\n\n Vec3.prototype.normalize = function(v) {\n var x = this.x, y = this.y, z = this.z;\n var length = 1.0 / Math.sqrt(x * x + y * y + z * z);\n this.x = x * length;\n this.y = y * length;\n this.z = z * length;\n return this;\n };\n\n Vec3.prototype.distance = function(v) {\n return this.sub(v).length();\n };\n\n Vec3.prototype.length = function () {\n return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);\n };\n\n var blerp = function(x, y, fQ11, fQ21, fQ12, fQ22) {\n return (fQ11 * (1.0 - x) * (1.0 - y) + fQ21 * x * (1.0 - y) + fQ12 * (1.0 - x) * y + fQ22 * x * y);\n };\n \n var slice = function (t, h1, h0) {\n return t * (h1 - h0);\n };\n\n var _tempVec = new Vec3(0.0, 0.0, 0.0);\n\n var _tempHigh = new Vec3(0.0, 0.0, 0.0),\n _tempLow = new Vec3(0.0, 0.0, 0.0);\n\n self.onmessage = function (e) {\n var elevations = e.data.elevations,\n this_plainVertices = e.data.this_plainVertices,\n this_plainNormals = e.data.this_plainNormals,\n this_normalMapVertices = e.data.this_normalMapVertices,\n this_normalMapNormals = e.data.this_normalMapNormals,\n heightFactor = e.data.heightFactor,\n gridSize = e.data.gridSize,\n noDataValues = e.data.noDataValues,\n id = e.data.id;\n \n var xmin = 549755748352.0, xmax = -549755748352.0, \n ymin = 549755748352.0, ymax = -549755748352.0, \n zmin = 549755748352.0, zmax = -549755748352.0;\n\n const fileGridSize = Math.sqrt(elevations.length) - 1;\n\n const fileGridSize_one = fileGridSize + 1;\n const fileGridSize_one_x2 = fileGridSize_one * fileGridSize_one;\n const tgs = gridSize;\n const dg = fileGridSize / tgs;\n const gs = tgs + 1;\n const hf = heightFactor;\n\n var nmvInd = 0,\n vInd = 0,\n noDataInd = 0;\n\n var gsgs3 = gs * gs * 3;\n\n var terrainVertices = new Float64Array(gsgs3),\n terrainVerticesHigh = new Float32Array(gsgs3),\n terrainVerticesLow = new Float32Array(gsgs3),\n noDataVertices = new Uint8Array(gs * gs);\n\n var normalMapNormals,\n normalMapVertices,\n normalMapVerticesHigh,\n normalMapVerticesLow;\n\n var nv = this_normalMapVertices,\n nn = this_normalMapNormals;\n\n if (fileGridSize >= tgs) {\n\n normalMapNormals = new Float32Array(fileGridSize_one_x2 * 3);\n normalMapVertices = new Float64Array(fileGridSize_one_x2 * 3);\n normalMapVerticesHigh = new Float32Array(fileGridSize_one_x2 * 3);\n normalMapVerticesLow = new Float32Array(fileGridSize_one_x2 * 3);\n\n for (let k = 0; k < fileGridSize_one_x2; k++) {\n\n var j = k % fileGridSize_one,\n i = ~~(k / fileGridSize_one);\n\n //\n // V0\n //\n var hInd0 = k;\n var vInd0 = hInd0 * 3;\n var currElv = elevations[hInd0];\n if(checkNoDataValue(noDataValues, currElv)) {\n currElv = 0.0;\n }\n var h0 = hf * currElv;\n var v0 = new Vec3(nv[vInd0] + h0 * nn[vInd0], nv[vInd0 + 1] + h0 * nn[vInd0 + 1], nv[vInd0 + 2] + h0 * nn[vInd0 + 2]);\n \n doubleToTwoFloats(v0, _tempHigh, _tempLow);\n\n normalMapVertices[vInd0] = v0.x;\n normalMapVertices[vInd0 + 1] = v0.y;\n normalMapVertices[vInd0 + 2] = v0.z;\n\n normalMapVerticesHigh[vInd0] = _tempHigh.x;\n normalMapVerticesHigh[vInd0 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd0 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd0] = _tempLow.x;\n normalMapVerticesLow[vInd0 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd0 + 2] = _tempLow.z;\n\n //\n // The vertex goes into screen buffer\n if (i % dg === 0 && j % dg === 0) {\n\n let currVert = new Vec3(nv[vInd0], nv[vInd0 + 1], nv[vInd0 + 2]);\n let nextVert = new Vec3(nv[vInd0 + 3], nv[vInd0 + 4], nv[vInd0 + 5]);\n\n let nextElv = elevations[hInd0 + 1];\n if(checkNoDataValue(noDataValues, nextElv)) {\n nextElv = 0.0;\n }\n \n let eps = false;\n if(noDataValues.length === 0){\n let step = currVert.distance(nextVert);\n let deltaElv = Math.abs(currElv - nextElv);\n eps = ((deltaElv / step) > 10.0) || (currElv < -5000);\n }\n\n if(eps){\n noDataVertices[noDataInd] = 1;\n } else {\n noDataVertices[noDataInd] = 0;\n if (v0.x < xmin) xmin = v0.x; if (v0.x > xmax) xmax = v0.x;\n if (v0.y < ymin) ymin = v0.y; if (v0.y > ymax) ymax = v0.y;\n if (v0.z < zmin) zmin = v0.z; if (v0.z > zmax) zmax = v0.z;\n }\n\n terrainVerticesHigh[vInd] = _tempHigh.x;\n terrainVerticesLow[vInd] = _tempLow.x;\n terrainVertices[vInd++] = v0.x;\n\n terrainVerticesHigh[vInd] = _tempHigh.y;\n terrainVerticesLow[vInd] = _tempLow.y;\n terrainVertices[vInd++] = v0.y;\n\n terrainVerticesHigh[vInd] = _tempHigh.z;\n terrainVerticesLow[vInd] = _tempLow.z;\n terrainVertices[vInd++] = v0.z;\n\n noDataInd++;\n }\n\n if (i !== fileGridSize && j !== fileGridSize) {\n\n //\n // V1\n //\n var hInd1 = k + 1;\n var vInd1 = hInd1 * 3;\n var elv = elevations[hInd1];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h1 = hf * elv;\n var v1 = new Vec3(nv[vInd1] + h1 * nn[vInd1], nv[vInd1 + 1] + h1 * nn[vInd1 + 1], nv[vInd1 + 2] + h1 * nn[vInd1 + 2]);\n\n doubleToTwoFloats(v1, _tempHigh, _tempLow);\n\n normalMapVertices[vInd1] = v1.x;\n normalMapVertices[vInd1 + 1] = v1.y;\n normalMapVertices[vInd1 + 2] = v1.z;\n\n normalMapVerticesHigh[vInd1] = _tempHigh.x;\n normalMapVerticesHigh[vInd1 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd1 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd1] = _tempLow.x;\n normalMapVerticesLow[vInd1 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd1 + 2] = _tempLow.z;\n\n //\n // V2\n //\n var hInd2 = k + fileGridSize_one;\n var vInd2 = hInd2 * 3;\n var elv = elevations[hInd2];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h2 = hf * elv;\n var v2 = new Vec3(nv[vInd2] + h2 * nn[vInd2], nv[vInd2 + 1] + h2 * nn[vInd2 + 1], nv[vInd2 + 2] + h2 * nn[vInd2 + 2]);\n\n doubleToTwoFloats(v2, _tempHigh, _tempLow);\n\n normalMapVertices[vInd2] = v2.x;\n normalMapVertices[vInd2 + 1] = v2.y;\n normalMapVertices[vInd2 + 2] = v2.z;\n\n normalMapVerticesHigh[vInd2] = _tempHigh.x;\n normalMapVerticesHigh[vInd2 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd2 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd2] = _tempLow.x;\n normalMapVerticesLow[vInd2 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd2 + 2] = _tempLow.z;\n\n //\n // V3\n //\n var hInd3 = k + fileGridSize_one + 1;\n var vInd3 = hInd3 * 3;\n var elv = elevations[hInd3];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h3 = hf * elv;\n var v3 = new Vec3(nv[vInd3] + h3 * nn[vInd3], nv[vInd3 + 1] + h3 * nn[vInd3 + 1], nv[vInd3 + 2] + h3 * nn[vInd3 + 2]);\n\n doubleToTwoFloats(v3, _tempHigh, _tempLow);\n\n normalMapVertices[vInd3] = v3.x;\n normalMapVertices[vInd3 + 1] = v3.y;\n normalMapVertices[vInd3 + 2] = v3.z;\n\n normalMapVerticesHigh[vInd3] = _tempHigh.x;\n normalMapVerticesHigh[vInd3 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd3 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd3] = _tempLow.x;\n normalMapVerticesLow[vInd3 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd3 + 2] = _tempLow.z;\n\n //\n // Normal\n //\n var e10 = v1.sub(v0),\n e20 = v2.sub(v0),\n e30 = v3.sub(v0);\n var sw = e20.cross(e30).normalize();\n var ne = e30.cross(e10).normalize();\n var n0 = ne.add(sw).normalize();\n\n normalMapNormals[vInd0] += n0.x;\n normalMapNormals[vInd0 + 1] += n0.y;\n normalMapNormals[vInd0 + 2] += n0.z;\n\n normalMapNormals[vInd1] += ne.x;\n normalMapNormals[vInd1 + 1] += ne.y;\n normalMapNormals[vInd1 + 2] += ne.z;\n\n normalMapNormals[vInd2] += sw.x;\n normalMapNormals[vInd2 + 1] += sw.y;\n normalMapNormals[vInd2 + 2] += sw.z;\n\n normalMapNormals[vInd3] += n0.x;\n normalMapNormals[vInd3 + 1] += n0.y;\n normalMapNormals[vInd3 + 2] += n0.z;\n }\n }\n\n } else {\n\n normalMapNormals = new Float32Array(gsgs3);\n normalMapVertices = new Float64Array(gsgs3);\n normalMapVerticesHigh = new Float32Array(gsgs3);\n normalMapVerticesLow = new Float32Array(gsgs3);\n normalMapNormals = new Float32Array(gsgs3);\n\n var oneSize = tgs / fileGridSize;\n var h, inside_i, inside_j, v_i, v_j;\n var gsgs = gsgs3 / 3;\n var fgsOne = fileGridSize + 1;\n\n for(let i = 0; i < gsgs; i++) {\n let ii = Math.floor(i / gs),\n ij = i % gs;\n \n let qii = ii % oneSize,\n qij = ij % oneSize;\n\n let hlt_ind = Math.floor(ii / oneSize) * fgsOne + Math.floor(ij / oneSize);\n\n if (ij === tgs) {\n hlt_ind -= 1;\n qij = oneSize;\n }\n\n if (ii === tgs) {\n hlt_ind -= fgsOne;\n qii = oneSize;\n }\n\n let hrt_ind = hlt_ind + 1,\n hlb_ind = hlt_ind + fgsOne,\n hrb_ind = hlb_ind + 1;\n\n let h_lt = elevations[hlt_ind],\n h_rt = elevations[hrt_ind],\n h_lb = elevations[hlb_ind],\n h_rb = elevations[hrb_ind];\n\n if(checkNoDataValue(noDataValues, h_lt)) {\n h_lt = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_rt)) {\n h_rt = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_lb)) {\n h_lb = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_rb)) {\n h_rb = 0.0;\n }\n\n let hi = blerp(qij / oneSize, qii / oneSize, h_lt, h_rt, h_lb, h_rb);\n\n let i3 = i * 3;\n\n _tempVec.x = this_plainVertices[i3] + hi * this_plainNormals[i3],\n _tempVec.y = this_plainVertices[i3 + 1] + hi * this_plainNormals[i3 + 1],\n _tempVec.z = this_plainVertices[i3 + 2] + hi * this_plainNormals[i3 + 2];\n\n doubleToTwoFloats(_tempVec, _tempHigh, _tempLow);\n\n terrainVertices[i3] = _tempVec.x;\n terrainVertices[i3 + 1] = _tempVec.y;\n terrainVertices[i3 + 2] = _tempVec.z;\n\n terrainVerticesHigh[i3] = _tempHigh.x;\n terrainVerticesHigh[i3 + 1] = _tempHigh.y;\n terrainVerticesHigh[i3 + 2] = _tempHigh.z;\n\n terrainVerticesLow[i3] = _tempLow.x;\n terrainVerticesLow[i3 + 1] = _tempLow.y;\n terrainVerticesLow[i3 + 2] = _tempLow.z;\n\n if (_tempVec.x < xmin) xmin = _tempVec.x; if (_tempVec.x > xmax) xmax = _tempVec.x;\n if (_tempVec.y < ymin) ymin = _tempVec.y; if (_tempVec.y > ymax) ymax = _tempVec.y;\n if (_tempVec.z < zmin) zmin = _tempVec.z; if (_tempVec.z > zmax) zmax = _tempVec.z;\n }\n\n normalMapVertices.set(terrainVertices);\n normalMapVerticesHigh.set(terrainVerticesHigh);\n normalMapVerticesLow.set(terrainVerticesLow);\n\n for (let k = 0; k < gsgs; k++) {\n\n var j = k % gs,\n i = ~~(k / gs);\n\n if (i !== tgs && j !== tgs) {\n var v0ind = k * 3,\n v1ind = v0ind + 3,\n v2ind = v0ind + gs * 3,\n v3ind = v2ind + 3;\n\n\n var v0 = new Vec3(terrainVertices[v0ind], terrainVertices[v0ind + 1], terrainVertices[v0ind + 2]),\n v1 = new Vec3(terrainVertices[v1ind], terrainVertices[v1ind + 1], terrainVertices[v1ind + 2]),\n v2 = new Vec3(terrainVertices[v2ind], terrainVertices[v2ind + 1], terrainVertices[v2ind + 2]),\n v3 = new Vec3(terrainVertices[v3ind], terrainVertices[v3ind + 1], terrainVertices[v3ind + 2]);\n\n var e10 = v1.sub(v0).normalize(),\n e20 = v2.sub(v0).normalize(),\n e30 = v3.sub(v0).normalize();\n\n var sw = e20.cross(e30).normalize();\n var ne = e30.cross(e10).normalize();\n var n0 = ne.add(sw).normalize();\n\n normalMapNormals[v0ind] += n0.x;\n normalMapNormals[v0ind + 1] += n0.y;\n normalMapNormals[v0ind + 2] += n0.z;\n\n normalMapNormals[v1ind] += ne.x;\n normalMapNormals[v1ind + 1] += ne.y;\n normalMapNormals[v1ind + 2] += ne.z;\n\n normalMapNormals[v2ind] += sw.x;\n normalMapNormals[v2ind + 1] += sw.y;\n normalMapNormals[v2ind + 2] += sw.z;\n\n normalMapNormals[v3ind] += n0.x;\n normalMapNormals[v3ind + 1] += n0.y;\n normalMapNormals[v3ind + 2] += n0.z;\n }\n }\n }\n\n self.postMessage({\n id: id,\n normalMapNormals: normalMapNormals,\n normalMapVertices: normalMapVertices,\n normalMapVerticesHigh: normalMapVerticesHigh,\n normalMapVerticesLow: normalMapVerticesLow,\n terrainVertices: terrainVertices,\n terrainVerticesHigh: terrainVerticesHigh,\n terrainVerticesLow: terrainVerticesLow,\n noDataVertices: noDataVertices,\n //bounds: [xmin, xmax, ymin, ymax, zmin, zmax]\n bounds: [xmin, ymin, zmin, xmax, ymax, zmax]\n }, [\n normalMapNormals.buffer, \n normalMapVertices.buffer, \n normalMapVerticesHigh.buffer, \n normalMapVerticesLow.buffer, \n terrainVertices.buffer,\n terrainVerticesHigh.buffer,\n terrainVerticesLow.buffer,\n noDataVertices.buffer\n ]);\n }";let Wa=new Float32Array(2);class ja{constructor(e,t=512,i=512){this._width=t,this._height=i,this._planet=e,this._framebuffer=null,this._queue=[],this._handler=null}init(){this._handler=this._planet.renderer.handler,this._handler.programs.vectorTileLineRasterization||this._handler.addProgram(new zi("vectorTileLineRasterization",{uniforms:{viewport:"vec2",thicknessOutline:"float",alpha:"float",extentParamsHigh:"vec4",extentParamsLow:"vec4"},attributes:{prevHigh:"vec2",currentHigh:"vec2",nextHigh:"vec2",prevLow:"vec2",currentLow:"vec2",nextLow:"vec2",order:"float",color:"vec4",thickness:"float"},vertexShader:"attribute vec2 prevHigh;\n attribute vec2 currentHigh;\n attribute vec2 nextHigh;\n\n attribute vec2 prevLow;\n attribute vec2 currentLow;\n attribute vec2 nextLow;\n\n attribute float order;\n attribute float thickness;\n attribute vec4 color;\n uniform float thicknessOutline;\n uniform vec2 viewport;\n uniform vec4 extentParamsHigh;\n uniform vec4 extentParamsLow;\n varying vec4 vColor;\n \n vec2 proj(vec2 coordHigh, vec2 coordLow) {\n vec2 highDiff = coordHigh - extentParamsHigh.xy;\n vec2 lowDiff = coordLow - extentParamsLow.xy; \n return vec2(-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0);\n }\n \n void main(){\n vColor = color;\n\n vec2 vNext = proj(nextHigh, nextLow),\n vCurrent = proj(currentHigh, currentLow),\n vPrev = proj(prevHigh, prevLow);\n\n vec2 _next = vNext;\n vec2 _prev = vPrev;\n vec2 _current = vCurrent;\n\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n\n vec2 sNext = _next;\n vec2 sCurrent = _current;\n vec2 sPrev = _prev;\n \n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n \n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n vec2 d = (thickness + thicknessOutline) * 0.5 * sign(order) / viewport;\n \n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n vec2 dir = normalPrev + normalNext;\n m = sCurrent + dir * d / (dirNext.x * dir.y - dirNext.y * dir.x);\n \n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n gl_Position = vec4(m.x, m.y, 0.0, 1.0);\n }",fragmentShader:"precision highp float;\n uniform float alpha;\n varying vec4 vColor;\n void main() {\n gl_FragColor = vec4(vColor.rgb, alpha * vColor.a);\n }"})),this._handler.programs.vectorTilePolygonRasterization||this._handler.addProgram(new zi("vectorTilePolygonRasterization",{uniforms:{extentParamsHigh:"vec4",extentParamsLow:"vec4"},attributes:{coordinatesHigh:"vec2",coordinatesLow:"vec2",colors:"vec4"},vertexShader:"attribute vec2 coordinatesHigh;\n attribute vec2 coordinatesLow; \n attribute vec4 colors; \n uniform vec4 extentParamsHigh; \n uniform vec4 extentParamsLow; \n varying vec4 color;\n\n vec2 proj(vec2 coordHigh, vec2 coordLow) {\n vec2 highDiff = coordHigh - extentParamsHigh.xy;\n vec2 lowDiff = coordLow - extentParamsLow.xy;\n return vec2(-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0);\n }\n\n void main() { \n color = colors;\n gl_Position = vec4(proj(coordinatesHigh, coordinatesLow), 0.0, 1.0); \n }",fragmentShader:"precision highp float;\n varying vec4 color;\n void main () { \n gl_FragColor = color; \n }"})),this._framebuffer=new $s(this._handler,{width:this._width,height:this._height,useDepth:!1}),this._framebuffer.init()}frame(){if(this._planet.layerLock.isFree()&&this._queue.length){let e=this._handler,t=e.gl;t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST);let i=e.programs.vectorTileLineRasterization,n=e.programs.vectorTilePolygonRasterization,r=this._width,s=this._height,a=r,o=s,l=a<<1,h=o<<1,c=new Float32Array(4),d=new Float32Array(4),_=this._framebuffer.activate(),u=0,f=window.performance.now();for(;this._queue.length&&u<25;){let g=this._queue.shift();if(g.isLoading&&1===g.segment.node.getState()){let u=g.layer._pickingEnabled;g.segment.tileZoom<4?(a=l,o=h):(a=r,o=s);let f=g._updateTexture||e.createEmptyTexture_l(a,o),p=u?g._updatePickingMask||e.createEmptyTexture_n(a,o):null;g.applyTexture(f,p),_.setSize(a,o),_.bindOutputTexture(f),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);let m=g.segment.getExtentMerc();nn(m.southWest.lon,Wa),c[0]=Wa[0],d[0]=Wa[1],nn(m.southWest.lat,Wa),c[1]=Wa[0],d[1]=Wa[1],c[2]=2/m.getWidth(),c[3]=2/m.getHeight(),n.activate();let v=n._program,y=v.attributes,x=v.uniforms,b=g.layer._geometryHandler;t.uniform4fv(x.extentParamsHigh,c),t.uniform4fv(x.extentParamsLow,d),t.bindBuffer(t.ARRAY_BUFFER,b._polyVerticesHighBufferMerc),t.vertexAttribPointer(y.coordinatesHigh,b._polyVerticesHighBufferMerc.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._polyVerticesLowBufferMerc),t.vertexAttribPointer(y.coordinatesLow,b._polyVerticesLowBufferMerc.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._polyColorsBuffer),t.vertexAttribPointer(y.colors,b._polyColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,b._polyIndexesBuffer),t.drawElements(t.TRIANGLES,b._polyIndexesBuffer.numItems,t.UNSIGNED_INT,0),u&&(_.bindOutputTexture(p),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindBuffer(t.ARRAY_BUFFER,b._polyPickingColorsBuffer),t.vertexAttribPointer(y.colors,b._polyPickingColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.drawElements(t.TRIANGLES,b._polyIndexesBuffer.numItems,t.UNSIGNED_INT,0)),_.bindOutputTexture(f),i.activate(),v=i._program,y=v.attributes,x=v.uniforms,t.uniform2fv(x.viewport,[a,o]),t.uniform4fv(x.extentParamsHigh,c),t.uniform4fv(x.extentParamsLow,d);let w=b._lineVerticesHighBufferMerc;t.bindBuffer(t.ARRAY_BUFFER,w),t.vertexAttribPointer(y.prevHigh,w.itemSize,t.FLOAT,!1,8,0),t.vertexAttribPointer(y.currentHigh,w.itemSize,t.FLOAT,!1,8,32),t.vertexAttribPointer(y.nextHigh,w.itemSize,t.FLOAT,!1,8,64),w=b._lineVerticesLowBufferMerc,t.bindBuffer(t.ARRAY_BUFFER,w),t.vertexAttribPointer(y.prevLow,w.itemSize,t.FLOAT,!1,8,0),t.vertexAttribPointer(y.currentLow,w.itemSize,t.FLOAT,!1,8,32),t.vertexAttribPointer(y.nextLow,w.itemSize,t.FLOAT,!1,8,64),t.bindBuffer(t.ARRAY_BUFFER,b._lineOrdersBuffer),t.vertexAttribPointer(y.order,b._lineOrdersBuffer.itemSize,t.FLOAT,!1,4,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,b._lineIndexesBuffer),t.bindBuffer(t.ARRAY_BUFFER,b._lineStrokesBuffer),t.vertexAttribPointer(y.thickness,b._lineStrokesBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineStrokeColorsBuffer),t.vertexAttribPointer(y.color,b._lineStrokeColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(x.thicknessOutline,2),t.uniform1f(x.alpha,.54),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.uniform1f(x.thicknessOutline,1),t.uniform1f(x.alpha,1),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineThicknessBuffer),t.vertexAttribPointer(y.thickness,b._lineThicknessBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineColorsBuffer),t.vertexAttribPointer(y.color,b._lineColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(x.thicknessOutline,2),t.uniform1f(x.alpha,.54),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.uniform1f(x.thicknessOutline,1),t.uniform1f(x.alpha,1),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),u&&(_.bindOutputTexture(p),t.uniform1f(x.thicknessOutline,8),t.bindBuffer(t.ARRAY_BUFFER,b._linePickingColorsBuffer),t.vertexAttribPointer(y.color,b._linePickingColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0))}else g.isLoading=!1;u=window.performance.now()-f}t.enable(t.DEPTH_TEST),t.enable(t.CULL_FACE),_.deactivate()}}add(e){this._queue.push(e)}remove(e){}get queueSize(){return this._queue.length}}class Ya{constructor(e=1,t=1){this._a=e,this._b=t,this._flattening=(e-t)/e,this._f=1/this._flattening,this._a2=e*e,this._b2=t*t;const i=Math.sqrt(this._a2-this._b2);this._e=i/e,this._e2=this._e*this._e,this._e22=this._e2*this._e2,this._k=i/t,this._k2=this._k*this._k,this._radii=new oe(e,e,t),this._radii2=new oe(this._a2,this._a2,this._b2),this._invRadii=new oe(1/e,1/e,1/t),this._invRadii2=new oe(1/this._a2,1/this._a2,1/this._b2)}rhumbDistanceTo(e,t){const i=e.lat*o,n=t.lat*o,r=n-i;let s=Math.abs(t.lon-e.lon)*o;Math.abs(s)>Math.PI&&(s=s>0?-(2*Math.PI-s):2*Math.PI+s);const a=Math.log(Math.tan(n/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),l=Math.abs(a)>1e-11?r/a:Math.cos(i);return Math.sqrt(r*r+l*l*s*s)*this._a}getIntermediatePointOnGreatCircle(e,t,i){if(0==i)return e.clone();if(1==i)return t.clone();const n=this.inverse(e,t),r=n.distance,s=n.initialAzimuth;return isNaN(s)?e:this.getGreatCircleDestination(e,s,r*i)}static getBearing(e,t){let i=e.lat*o,n=e.lon*o,r=t.lat*o,s=t.lon*o,a=Math.sin(s-n)*Math.cos(r),h=Math.cos(i)*Math.sin(r)-Math.sin(i)*Math.cos(r)*Math.cos(s-n);return Math.atan2(a,h)*l}getFlattening(){return this._flattening}getEquatorialSize(){return this._a}get equatorialSize(){return this._a}get equatorialSizeSqr(){return this._a2}getPolarSize(){return this._b}get polarSize(){return this._b}get polarSizeSqr(){return this._b2}lonLatToCartesian(e){return this.geodeticToCartesian(e.lon,e.lat,e.height)}lonLatToCartesianRes(e,t){return this.geodeticToCartesian(e.lon,e.lat,e.height,t)}geodeticToCartesian(e,t,i=0,n=new oe){let r=o*t,s=o*e,a=Math.sin(r),l=this._a/Math.sqrt(1-this._e2*a*a),h=(l+i)*Math.cos(r);return n.x=h*Math.cos(s),n.y=h*Math.sin(s),n.z=(l*(1-this._e2)+i)*a,n}projToSurface(e){let t=e.x||0,i=e.y||0,n=e.z||0,r=Math.sqrt(t*t+i*i+n*n);if(0===r)return this.lonLatToCartesian(new z);let s=this._invRadii2.x,a=this._invRadii2.y,o=this._invRadii2.z,l=t*t*s,h=i*i*a,c=n*n*o,d=l+h+c,_=Math.sqrt(1/d),u=e.scaleTo(_);if(d<.1)return Number.isFinite(_)?u:new oe;let g=(1-_)*r/u.mulA(this._invRadii2).length(),p=0,m=0,v=0;for(;;){p=1/(1+g*s),m=1/(1+g*a),v=1/(1+g*o);let e=p*p,t=m*m,i=v*v,n=l*e+h*t+c*i-1;if(Math.abs(n)<f)break;g+=.5*n/(l*(e*p)*s+h*(t*m)*a+c*(i*v)*o)}return new oe(t*p,i*m,n*v)}cartesianToLonLat(e){return this.cartesianToLonLatRes(e)}cartesianToLonLatRes(e,t=new z){let i=this.projToSurface(e),n=this.getSurfaceNormal3v(i),r=e.sub(i);return t.lon=Math.atan2(n.y,n.x)*l,t.lat=Math.asin(n.z)*l,t.height=Math.sign(r.dot(e))*r.length(),t}getSurfaceNormal3v(e){let t=this._invRadii2,i=e.x*t.x,n=e.y*t.y,r=e.z*t.z,s=1/Math.sqrt(i*i+n*n+r*r);return new oe(i*s,n*s,r*s)}getGreatCircleDistance(e,t){return this.inverse(e,t).distance}getGreatCircleDestination(e,t,i){return this.direct(e,t,i).destination}inverse(e,t){let i=this._a,n=this._b,r=this._flattening;const s=e.lat*o,a=e.lon*o,h=t.lat*o,c=t.lon*o-a,d=(1-r)*Math.tan(s),_=1/Math.sqrt(1+d*d),u=d*_,g=(1-r)*Math.tan(h),p=1/Math.sqrt(1+g*g),m=g*p,v=Math.abs(c)>Math.PI/2||Math.abs(h-s)>Math.PI/2;let y=c,x=null,w=null,C=v?Math.PI:0,T=0,L=v?-1:1,A=null,E=1,P=1,S=null,M=0;do{if(x=Math.sin(y),w=Math.cos(y),A=(p*x)**2+(_*m-u*p*w)**2,Math.abs(A)<1e-24)break;T=Math.sqrt(A),L=u*m+_*p*w,C=Math.atan2(T,L);const e=_*p*x/T;P=1-e*e,E=0!=P?L-2*u*m/P:0;const t=r/16*P*(4+r*(4-3*P));S=y,y=c+(1-t)*r*e*(C+t*T*(E+t*L*(2*E*E-1)))}while(Math.abs(y-S)>f&&++M<1e3);const B=P*(i*i-n*n)/(n*n),k=B/1024*(256+B*(B*(74-47*B)-128)),R=n*(1+B/16384*(4096+B*(B*(320-175*B)-768)))*(C-k*T*(E+k/4*(L*(2*E*E-1)-k/6*E*(4*T*T-3)*(4*E*E-3)))),I=Math.abs(A)<Number.EPSILON?0:Math.atan2(p*x,_*m-u*p*w),z=Math.abs(A)<Number.EPSILON?Math.PI:Math.atan2(_*x,-u*p+_*m*w);return{distance:R,initialAzimuth:Math.abs(R)<Number.EPSILON?NaN:b(I)*l,finalAzimuth:Math.abs(R)<Number.EPSILON?NaN:b(z)*l}}direct(e,t,i){let n=e.lon,r=e.lat,s=this._a,a=this._b,h=this._flattening,c=i,d=t*o,_=Math.sin(d),u=Math.cos(d),f=(1-h)*Math.tan(r*o),g=1/Math.sqrt(1+f*f),p=f*g,m=Math.atan2(f,u),v=g*_,y=1-v*v,x=y*(s*s-a*a)/(a*a),b=1+x/16384*(4096+x*(x*(320-175*x)-768)),w=x/1024*(256+x*(x*(74-47*x)-128)),C=c/(a*b),T=2*Math.PI,L=0,A=0,E=0,P=0;for(;Math.abs(C-T)>1e-12;)L=Math.cos(2*m+C),A=Math.sin(C),E=Math.cos(C),P=w*A*(L+w/4*(E*(2*L*L-1)-w/6*L*(4*A*A-3)*(4*L*L-3))),T=C,C=c/(a*b)+P;let S=p*A-g*E*u,M=Math.atan2(p*E+g*A*u,(1-h)*Math.sqrt(v*v+S*S)),B=h/16*y*(4+h*(4-3*y)),k=Math.atan2(A*_,g*E-p*A*u)-(1-B)*h*v*(C+B*A*(L+B*E*(2*L*L-1))),R=Math.atan2(v,-S);return{destination:new z(n+k*l,M*l),finalAzimuth:R*l}}hitRay(e,t){let i,n,r,s,a,o=this._invRadii.mul(e),l=this._invRadii.mul(t),h=o.dot(o),c=o.dot(l);if(h>1){if(c>=0)return;var d=c*c;if(i=h-1,n=l.dot(l),r=n*i,Math.abs(d-r)>1e-15&&d<r)return;if(d>r){s=c*c-r,a=-c+Math.sqrt(s);var _=a/n,u=i/a;return _<u?e.add(t.scaleTo(_)):e.add(t.scaleTo(u))}var f=Math.sqrt(i/n);return e.add(t.scaleTo(f))}return h<1?(i=h-1,n=l.dot(l),r=n*i,s=c*c-r,a=-c+Math.sqrt(s),e.add(t.scaleTo(a/n))):c<0?(n=l.dot(l),e.add(t.scaleTo(-c/n))):void 0}getNorthFrameRotation(e){let t=this.getSurfaceNormal3v(e),i=oe.proj_b_to_plane(oe.NORTH,t);return ae.getLookRotation(i,t)}getBearingDestination(e,t=0,i=0){t*=o;var n=(e.lon+540)%360-180,r=e.lat*o,s=n*o,a=i/this._a,h=Math.asin(Math.sin(r)*Math.cos(a)+Math.cos(r)*Math.sin(a)*Math.cos(t));return new z((s+Math.atan2(Math.sin(t)*Math.sin(a)*Math.cos(r),Math.cos(a)-Math.sin(r)*Math.sin(h)))*l,h*l)}static getIntermediatePointOnGreatCircle(e,t,i){var n=e.lat*o,r=e.lon*o,s=t.lat*o,a=t.lon*o,h=Math.sin(n),c=Math.cos(n),d=Math.sin(r),_=Math.cos(r),u=Math.sin(s),f=Math.cos(s),g=Math.sin(a),p=Math.cos(a),m=s-n,v=a-r,y=Math.sin(m/2)*Math.sin(m/2)+Math.cos(n)*Math.cos(s)*Math.sin(v/2)*Math.sin(v/2),x=2*Math.atan2(Math.sqrt(y),Math.sqrt(1-y)),b=Math.sin((1-i)*x)/Math.sin(x),w=Math.sin(i*x)/Math.sin(x),C=b*c*_+w*f*p,T=b*c*d+w*f*g,L=b*h+w*u,A=Math.atan2(L,Math.sqrt(C*C+T*T)),E=Math.atan2(T,C);return new z((E*l+540)%360-180,A*l)}static getRhumbBearing(e,t){var i=(t.lon-e.lon)*o,n=Math.log(Math.tan(t.lat*o/2+Math.PI/4)/Math.tan(e.lat*o/2+Math.PI/4));return Math.abs(i)>Math.PI&&(i=i>0?-1*(2*Math.PI-i):2*Math.PI+i),(Math.atan2(i,n)*l+360)%360}}const qa=new Ya(6378137,6356752.314245179);let Xa=new Uint8Array(4),$a=new Uint8Array(4);class Za extends Pi{constructor(e={}){super(e.name),this._renderingFadingNodes=(e,t,i,n,r,s)=>{let a=0===r,o=this.terrain.equalizeVertices;for(let l=0,h=i._fadingNodes.length;l<h;l++){let h=i._fadingNodes[l].segment;this._fadingNodes.has(i._fadingNodes[0].__id)&&!e.has(h.node.__id)&&(e.set(h.node.__id,!0),h._transitionOpacity<1?s.push(h):a?(o&&h.equalize(),h.readyToEngage&&h.engage(),h.screenRendering(t,n,r)):h.screenRendering(t,n,r,this.transparentTexture,!0))}},this._renderingFadingNodesNoDepth=(e,t,i,n,r)=>{let s=0===r,a=this.terrain.equalizeVertices,o=t.gl;o.disable(o.DEPTH_TEST);for(let o=0,l=i._fadingNodes.length;o<l;o++){let l=i._fadingNodes[o].segment;this._fadingNodes.has(i._fadingNodes[0].__id)&&!e.has(l.node.__id)&&(e.set(l.node.__id,!0),s?(a&&l.equalize(),l.readyToEngage&&l.engage(),l.screenRendering(t,n,r)):l.screenRendering(t,n,r,this.transparentTexture,!0))}o.enable(o.DEPTH_TEST)},this._atmosphere=new Zs(e.atmosphereParameters),this._prevNodes=new Map,this._currNodes=new Map,this.transitionTime=580,this.ellipsoid=e.ellipsoid||qa,this.lightEnabled=!0,this._planetRadius2=this.ellipsoid.getPolarSize()*this.ellipsoid.getPolarSize(),this._layers=[],this._updateLayer=!1,this.visibleTileLayers=[],this.visibleVectorLayers=[],this._visibleTileLayerSlices=[],this._frustumEntityCollections=[],this.baseLayer=null,this.terrain=null,this.camera=new Va(this,{frustums:e.frustums,eye:new oe(25e6,0,0),look:oe.ZERO,up:oe.NORTH,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude}),this.maxEqualZoomAltitude=e.maxEqualZoomAltitude||15e6,this.minEqualZoomAltitude=e.minEqualZoomAltitude||1e4,this.minEqualZoomCameraSlope=e.minEqualZoomCameraSlope||.8,this.mousePositionOnEarth=new oe,this.emptyTexture=null,this.transparentTexture=null,this.defaultTexture=null,this.minCurrZoom=s,this.maxCurrZoom=a,this._viewExtent=new ie(new z(180,180),new z(-180,-180)),this._skipPreRender=!1,this._initialViewExtent=null,this._createdNodesCount=0,this._renderedNodes=[],this._renderedNodesInFrustum=[],this._fadingNodes=new Map,this._fadingNodesInFrustum=[],this._visibleNodes={},this._visibleNodesNorth={},this._visibleNodesSouth={},this.layerLock=new yr,this.terrainLock=new yr,this._heightFactor=1,this._indexesCache=[],this._indexesCacheToRemove=[],this._indexesCacheToRemoveCounter=0,this._textureCoordsBufferCache=[],this.quadTreeStrategy=e.quadTreeStrategyPrototype?new e.quadTreeStrategyPrototype(this):new Sa(this),this._nightTexture=null,this._specularTexture=null;let t=Pe(e.ambient,new oe(.2,.2,.3)),i=Pe(e.diffuse,new oe(1,1,1)),n=Pe(e.specular,new oe(63e-5,55e-5,32e-5)),r=e.shininess||18;this._ambient=new Float32Array([t.x,t.y,t.z]),this._diffuse=new Float32Array([i.x,i.y,i.z]),this._specular=new Float32Array([n.x,n.y,n.z,r]),this._maxGridSize=Math.log2(e.maxGridSize||256),this.SLICE_SIZE=4,this.SLICE_SIZE_4=4*this.SLICE_SIZE,this.SLICE_SIZE_3=3*this.SLICE_SIZE,this._lodSize=250,this._curLodSize=250,this._minLodSize=312,this._maxLodSize=190,this._pickingColorArr=new Float32Array(this.SLICE_SIZE_4),this._samplerArr=new Int32Array(this.SLICE_SIZE),this._pickingMaskArr=new Int32Array(this.SLICE_SIZE),this._geoImageCreator=new Ba(this),this._vectorTileCreator=new ja(this),this._normalMapCreator=new Ia(this),this._terrainWorker=new Ua(3),this._plainSegmentWorker=new za(3),this._tileLoader=new Ra(e.maxLoadingRequests||12),this._memKey=new xr,this.events=Pt(Ka),this._distBeforeMemClear=0,this._prevCamEye=new oe,this._initialized=!1,this.always=[],this._renderCompleted=!1,this._renderCompletedActivated=!1,this._terrainCompleted=!1,this._terrainCompletedActivated=!1,this._collectRenderNodesIsActive=!0,this.nightTextureCoefficient=2,this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this._atmosphereEnabled=e.atmosphereEnabled||!1,this._atmosphereMaxMinOpacity=new Float32Array([1,.41]),this.solidTextureOne=null,this.solidTextureTwo=null,this._nightTextureSrc=e.nightTextureSrc||null,this._specularTextureSrc=e.specularTextureSrc||null,this._transitionOpacityEnabled=null==e.transitionOpacityEnabled||e.transitionOpacityEnabled}get terrainReady(){return this._terrainCompleted&&this._terrainCompletedActivated}get maxGridSize(){return this._maxGridSize}getNorthFrameRotation(e){return this.ellipsoid.getNorthFrameRotation(e)}set atmosphereMaxOpacity(e){this._atmosphereMaxMinOpacity[0]=e}get atmosphereMaxOpacity(){return this._atmosphereMaxMinOpacity[0]}set atmosphereMinOpacity(e){this._atmosphereMaxMinOpacity[1]=e}get atmosphereMinOpacity(){return this._atmosphereMaxMinOpacity[1]}set atmosphereEnabled(e){e!=this._atmosphereEnabled&&(this._atmosphereEnabled=e,this._initializeAtmosphere())}get atmosphereEnabled(){return this._atmosphereEnabled}set diffuse(e){let t=Pe(e);this._diffuse=new Float32Array(t.toArray())}set ambient(e){let t=Pe(e);this._ambient=new Float32Array(t.toArray())}set specular(e){let t=Pe(e);this._specular=new Float32Array([t.x,t.y,t.y,this._specular[3]])}set shininess(e){this._specular[3]=e}get normalMapCreator(){return this._normalMapCreator}get layers(){return[...this._layers]}getLayers(){return this.layers}get sunPos(){return this.renderer.controls.sun.sunlight.getPosition()}addControl(e){e.planet=this,e.addTo(this.renderer)}get lodSize(){return this._lodSize}setLodSize(e,t,i){this._maxLodSize=i||this._maxLodSize,this._minLodSize=t||this._minLodSize,this._curLodSize=e,this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1}addControls(e){for(let t=0;t<e.length;t++)this.addControl(e[t])}getLayerByName(e){for(let t=0,i=this._layers.length;t<i;t++)if(e===this._layers[t].name)return this._layers[t]}addLayer(e){e.addTo(this)}_onLayerVisibilityChanged(e){this.events.dispatch(this.events.layervisibilitychange,e)}addLayers(e){for(let t=0,i=e.length;t<i;t++)this.addLayer(e[t])}removeLayer(e){e.remove()}_clearLayerMaterial(e){this.quadTreeStrategy.clearLayerMaterial(e)}setBaseLayer(e){this.baseLayer?this.baseLayer.isEqual(e)||(this.baseLayer.setVisibility(!1),this.baseLayer=e,e.setVisibility(!0),this.events.dispatch(this.events.baselayerchange,e)):(this.baseLayer=e,this.baseLayer.setVisibility(!0),this.events.dispatch(this.events.baselayerchange,e))}setHeightFactor(e){this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1,this._heightFactor!==e&&(this._heightFactor=e,this.quadTreeStrategy.destroyBranches(),this._clearRenderedNodeList(),this._clearRenderNodesInFrustum())}getHeightFactor(){return this._heightFactor}setTerrain(e){this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1,this._initialized&&this.memClear(),this.terrain&&(this.terrain.abortLoading(),this.terrain.clearCache(),this.terrain._planet=null),this.terrain=e,this.terrain._planet=this,this.quadTreeStrategy.destroyBranches(),e._geoid.model?(this._plainSegmentWorker.setGeoid(e.getGeoid()),e._isReady=!0):Ma.loadModel(e.geoid.src).then((t=>{e.geoid.setModel(t),this._plainSegmentWorker.setGeoid(e.getGeoid()),e._isReady=!0})).catch((e=>{console.warn(e)}))}initAtmosphereShader(e){if(this.renderer&&this.renderer.handler&&this._atmosphereEnabled){let t=this.renderer.handler;t.isWebGl2()?(t.removeProgram("drawnode_screen_wl"),t.addProgram(Ys(e),!0)):console.warn("Atmosphere WebGL2 only")}}get atmosphereControl(){return this._atmosphere}_initializeAtmosphere(){if(!this.renderer)return;let e=this.renderer.handler;e.removeProgram("drawnode_screen_wl"),this._atmosphereEnabled?(this._renderScreenNodesPASS=this._renderScreenNodesPASSAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSAtmos,this.renderer.controls.Atmosphere||this.addControl(this._atmosphere),this._atmosphere.activate(),e.isWebGl2()?e.addProgram(Ys(this._atmosphere.parameters),!0):e.addProgram(js(),!0),this.renderer.controls.SimpleSkyBackground&&this.renderer.controls.SimpleSkyBackground.deactivate()):(this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this._atmosphere.deactivate(),this.renderer.controls.SimpleSkyBackground?this.renderer.controls.SimpleSkyBackground.activate():this.addControl(new Fr),e.isWebGl2()?e.addProgram(new zi("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightsPositions:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float",transitionOpacity:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"#version 300 es\n\n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in vec3 aVertexPositionLow;\n in vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n out vec4 vTextureCoord;\n out vec3 v_vertex;\n out vec3 cameraPosition;\n out vec2 vGlobalTextureCoord;\n out float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n \n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`#version 300 es\n\n precision highp float;\n \n #define MAX_POINT_LIGHTS 1\n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient; \n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec3 lightsPositions[MAX_POINT_LIGHTS];\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient;\n \n uniform float transitionOpacity;\n \n uniform float camHeight;\n\n in vec4 vTextureCoord;\n in vec3 v_vertex;\n in vec3 cameraPosition;\n in vec2 vGlobalTextureCoord;\n in float v_height;\n\n vec3 sunPos;\n\n layout(location = 0) out vec4 diffuseColor;\n\n ${Us}\n\n ${Gs}\n \n ${Hs}\n \n void main(void) {\n \n sunPos = lightsPositions[0];\n \n vec3 texNormal = texture(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0); \n vec4 nightImageColor = texture( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + diffuse * diffuseLightWeighting + night, 1.0);\n \n diffuseColor = texture( defaultTexture, vTextureCoord.xy );\n \n if( samplerCount == 0 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n vec4 src;\n\n blend(diffuseColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n }`}),!0):e.addProgram(js(),!0))}_initializeShaders(){let e=this.renderer.handler;e.addProgram(new zi("drawnode_screen_nl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",height:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"precision highp float;\n \n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec2 vTextureCoord;\n\n void main(void) {\n\n vTextureCoord = aTextureCoord;\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n mat4 m = projectionMatrix * viewMatrixRTE;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n // This is works for Mac Chrome, prevent some weird optimization I suppose\n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`precision highp float;\n #define SLICE_SIZE 5\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform float layerOpacityArr[SLICE_SIZE];\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n uniform int samplerCount;\n varying vec2 vTextureCoord;\n\n ${Ws}\n\n void main(void) {\n gl_FragColor = texture2D( defaultTexture, vTextureCoord );\n if( samplerCount == 0 ) return;\n\n vec4 src;\n\n blend(gl_FragColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) return;\n\n blend(gl_FragColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) return;\n\n blend(gl_FragColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) return;\n\n blend(gl_FragColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) return;\n\n blend(gl_FragColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n }`}),!0),e.addProgram(new zi("drawnode_colorPicking",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",samplerCount:"int",tileOffsetArr:"vec4",samplerArr:"sampler2darray",pickingMaskArr:"sampler2darray",pickingColorArr:"vec4",height:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"precision highp float;\n \n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec2 vTextureCoord;\n\n void main(void) {\n\n vTextureCoord = aTextureCoord;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n mat4 m = projectionMatrix * viewMatrixRTE;\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:"precision highp float;\n #define SLICE_SIZE 5\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec4 pickingColorArr[SLICE_SIZE];\n uniform sampler2D samplerArr[SLICE_SIZE];\n uniform sampler2D pickingMaskArr[SLICE_SIZE];\n uniform int samplerCount;\n varying vec2 vTextureCoord;\n\n #define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = texture2D(SAMPLER, tc); p = texture2D(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0 : 1.0) * COLOR.a);\n\n void main(void) {\n gl_FragColor = vec4(0.0);\n if( samplerCount == 0 ) return;\n\n vec2 tc;\n vec4 t;\n vec4 p;\n\n blendPicking(gl_FragColor, tileOffsetArr[0], samplerArr[0], pickingMaskArr[0], pickingColorArr[0], 1.0);\n if( samplerCount == 1 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[1], samplerArr[1], pickingMaskArr[1], pickingColorArr[1], 1.0);\n if( samplerCount == 2 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[2], samplerArr[2], pickingMaskArr[2], pickingColorArr[2], 1.0);\n if( samplerCount == 3 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[3], samplerArr[3], pickingMaskArr[3], pickingColorArr[3], 1.0);\n if( samplerCount == 4 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[4], samplerArr[4], pickingMaskArr[4], pickingColorArr[4], 1.0);\n }"}),!0),e.addProgram(new zi("drawnode_depth",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3",frustumPickingColor:"vec3"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"precision highp float;\n\n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n void main(void) {\n\n // @hack\n // This code is works for Mac Chrome and Safari\n // any other code probably will produce jittering\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n mat4 m = projectionMatrix * viewMatrixRTE;\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n vec3 eyePosition = eyePositionHigh + eyePositionLow;\n vec3 vertexPosition = aVertexPositionHigh + aVertexPositionLow;\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0); \n }",fragmentShader:"precision highp float;\n uniform vec3 frustumPickingColor;\n\n void main(void) {\n gl_FragColor = vec4(frustumPickingColor, 1.0);\n } "}),!0),e.addProgram(new zi("drawnode_heightPicking",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"precision highp float;\n\n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec3 eyePosition;\n varying vec3 vertexPosition;\n\n void main(void) {\n\n // This code is works for Mac Chrome and Safari\n // any other code probably will produce jittering\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n mat4 m = projectionMatrix * viewMatrixRTE;\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n eyePosition = eyePositionHigh + eyePositionLow;\n vertexPosition = aVertexPositionHigh + aVertexPositionLow;\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0); \n }",fragmentShader:"precision highp float;\n\n varying vec3 eyePosition;\n varying vec3 vertexPosition;\n\n vec3 encode24(highp float f) {\n float F = abs(f);\n float s = step( 0.0, -f );\n float e = floor( log2(F) );\n float m = exp2(- e) * F;\n e = floor( log2(F) + 127.0 ) + floor( log2(m) );\n return vec3(\n ( 128.0 * s + floor( e * exp2(-1.0) ) ) / 255.0,\n ( 128.0 * mod( e, 2.0 ) + mod( floor( m * 128.0 ), 128.0 ) ) / 255.0,\n floor( mod( floor( m * exp2( 23.0 - 8.0) ), exp2(8.0) ) ) / 255.0);\n }\n\n void main(void) {\n float range = distance(eyePosition, vertexPosition);\n gl_FragColor = vec4(encode24(range), 1.0);\n }"}),!0),this.renderer.addPickingCallback(this,this._renderColorPickingFramebufferPASS),this.renderer.addDepthCallback(this,this._renderDepthFramebufferPASS),this.renderer.addDistanceCallback(this,this._renderDistanceFramebufferPASS)}_onLayerLoadend(e){this.events.dispatch(this.events.layerloadend,e)}init(){this._tileLoader.events.on("layerloadend",this._onLayerLoadend,this),Ns().setMaxGridSize(this._maxGridSize);const e=this._maxGridSize;let t=0;for(let i=0;i<=e;i++){!this._indexesCache[i]&&(this._indexesCache[i]=new Array(e));for(let n=0;n<=e;n++){!this._indexesCache[i][n]&&(this._indexesCache[i][n]=new Array(e));for(let r=0;r<=e;r++){!this._indexesCache[i][n][r]&&(this._indexesCache[i][n][r]=new Array(e));for(let s=0;s<=e;s++){!this._indexesCache[i][n][r][s]&&(this._indexesCache[i][n][r][s]=new Array(e));for(let a=0;a<=e;a++){let e={buffer:null};if(i>=1&&i===n&&i===r&&i===s&&i===a){let t=Ns().createSegmentIndexes(i,[n,r,s,a]);e.buffer=this.renderer.handler.createElementArrayBuffer(t,1)}else this._indexesCacheToRemove[t++]=e;this._indexesCache[i][n][r][s][a]=e}}}}}this.renderer.events.on("resize",(()=>{this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1})),this.renderer.events.on("drawtransparent",(()=>{this._renderScreenNodesWithHeightPASS()})),this._textureCoordsBufferCache=[];let i=Ns().initTextureCoordsTable(e+1);for(let t=0;t<=e;t++)this._textureCoordsBufferCache[t]=this.renderer.handler.createArrayBuffer(i[t],2,(1+(1<<t))*(1+(1<<t)));this.renderer.handler.createDefaultTexture(null,(e=>{this.solidTextureOne=e,this.solidTextureTwo=e})),this.transparentTexture=this.renderer.handler.transparentTexture,this._renderedNodesInFrustum=new Array(this.camera.frustums.length);for(let e=0,t=this._renderedNodesInFrustum.length;e<t;e++)this._renderedNodesInFrustum[e]=[];if(this.quadTreeStrategy.init(),this.drawMode=this.renderer.handler.gl.TRIANGLE_STRIP,this._initializeShaders(),this._initializeAtmosphere(),this._updateVisibleLayers(),this.renderer.addPickingCallback(this,this._frustumEntityCollectionPickingCallback),this._nightTextureSrc){let e=new Image;e.crossOrigin="Anonymous",e.onload=()=>{this._nightTexture=this.renderer.handler.createTextureDefault(e),this._nightTexture.default=!0},e.src=this._nightTextureSrc}if(this._specularTextureSrc){let e=new Image;e.crossOrigin="Anonymous",e.onload=()=>{this._specularTexture=this.renderer.handler.createTextureDefault(e),this._specularTexture.default=!0},e.src=this._specularTextureSrc}this._geoImageCreator.init(),this._vectorTileCreator.init(),this._normalMapCreator.init(),this.renderer.events.on("draw",this._globalPreDraw,this,-100),this._preRender(),this.renderer.events.on("postdraw",(()=>{this._checkRendercompleted()})),this.initLayers(),this._initialized=!0,this._initialViewExtent&&this.viewExtent(this._initialViewExtent),this.renderer.activeCamera=this.camera,this.camera.bindRenderer(this.renderer),this.camera.update()}initLayers(){let e=[...this._layers];for(let t=0;t<e.length;t++)this.removeLayer(e[t]),this.addLayer(e[t])}_clearIndexesCache(){this._indexesCacheToRemoveCounter=0;let e=this._indexesCacheToRemove,t=this.renderer.handler.gl;for(let i=0,n=e.length;i<n;i++){let n=e[i];t.deleteBuffer(n.buffer),n.buffer=null}}_preRender(){this.quadTreeStrategy.preRender(),this._preLoad()}_preLoad(){this._clearRenderedNodeList(),this._skipPreRender=!1,this.quadTreeStrategy.preLoad()}createDefaultTextures(e,t){this.renderer.handler.gl.deleteTexture(this.solidTextureOne),this.renderer.handler.gl.deleteTexture(this.solidTextureTwo),this.renderer.handler.createDefaultTexture(e,(e=>{this.solidTextureOne=e})),this.renderer.handler.createDefaultTexture(t,(e=>{this.solidTextureTwo=e}))}_getLayerAttributionHTML(e){return`<div class="og-attribution__layer">${e.getAttribution()}</div>`}updateAttributionsList(){let e="";for(let t=0,i=this._layers.length;t<i;t++){let i=this._layers[t];i.getVisibility()&&i.getAttribution().length&&(e+=this._getLayerAttributionHTML(i))}this._applyAttribution(e)}updateVisibleLayers(){this._updateLayer=!0}_updateVisibleLayers(){this.visibleTileLayers=[],this.visibleTileLayers.length=0,this.visibleVectorLayers=[],this.visibleVectorLayers.length=0;let e="";for(let t=0,i=this._layers.length;t<i;t++){let i=this._layers[t];i.getVisibility()?(i.isBaseLayer()&&(this.createDefaultTextures(i._defaultTextures[0],i._defaultTextures[1]),this.baseLayer=i),i.hasImageryTiles()&&this.visibleTileLayers.push(i),i.isVector&&this.visibleVectorLayers.push(i),i.getAttribution().length&&(e+=this._getLayerAttributionHTML(i))):i._fading&&i._fadingOpacity>0&&(i.hasImageryTiles()&&this.visibleTileLayers.push(i),i.isVector&&this.visibleVectorLayers.push(i))}this._applyAttribution(e),this._sortLayers()}_applyAttribution(e){this.renderer&&this.renderer.div&&(e.length?this.renderer.div.attributions.innerHTML!==e&&(this.renderer.div.attributions.innerHTML=e):this.renderer.div.attributions.innerHTML="")}_sortLayers(){if(this.visibleVectorLayers.sort(((e,t)=>e.getZIndex()-t.getZIndex()||e.getHeight()-t.getHeight())),this._visibleTileLayerSlices=[],this._visibleTileLayerSlices.length=0,this.visibleTileLayers.length){this.visibleTileLayers.sort(((e,t)=>e.getHeight()-t.getHeight()||e.getZIndex()-t.getZIndex()));let e=-1,t=this.visibleTileLayers[0].getHeight();for(let i=0,n=this.visibleTileLayers.length;i<n;i++)i%this.SLICE_SIZE!=0&&this.visibleTileLayers[i].getHeight()===t||(e++,this._visibleTileLayerSlices[e]=[],t=this.visibleTileLayers[i].getHeight()),this._visibleTileLayerSlices[e].push(this.visibleTileLayers[i])}}_clearRenderedNodeList(){this._renderedNodes.length=0,this._renderedNodes=[]}_clearRenderNodesInFrustum(){for(let e=0,t=this._renderedNodesInFrustum.length;e<t;e++)this._renderedNodesInFrustum[e].length=0,this._renderedNodesInFrustum[e]=[]}_collectRenderedNodesMaxZoom(e){if(e.slope>this.minEqualZoomCameraSlope&&e._lonLat.height<this.maxEqualZoomAltitude&&e._lonLat.height>this.minEqualZoomAltitude){this.minCurrZoom=this.maxCurrZoom;let t=this._renderedNodes,i=this._renderedNodesInFrustum,n=[];this._clearRenderNodesInFrustum(),this._renderedNodes=[];for(let r=0,s=t.length;r<s;r++){let s=t[r],a=s.segment.centerNormal.dot(e._b);if(s.segment.tileZoom===this.maxCurrZoom||a<.81){this._renderedNodes.push(s);let e=0,t=s.inFrustum;for(;t;)1&t&&i[e].push(s),e++,t>>=1}else n.push(s)}for(let t=0,i=n.length;t<i;t++)n[t].renderTree(e,this.maxCurrZoom,null,!1,n[t])}}set transitionOpacityEnabled(e){this._transitionOpacityEnabled=e}get transitionOpacityEnabled(){return this._transitionOpacityEnabled}_collectRenderNodes(e){if(this._lodSize=L(e.slope<0?0:e.slope,this._curLodSize,this._minLodSize),e._insideSegment=null,this._clearRenderedNodeList(),this._clearRenderNodesInFrustum(),this._viewExtent.southWest.set(180,180),this._viewExtent.northEast.set(-180,-180),this._visibleNodes={},this._visibleNodesNorth={},this._visibleNodesSouth={},this.minCurrZoom=s,this.maxCurrZoom=a,this.quadTreeStrategy.collectRenderNodes(),this._collectRenderedNodesMaxZoom(e),this._fadingNodes.clear(),this._transitionOpacityEnabled){let e=[];for(let t=0;t<this._renderedNodes.length;t++){let i=this._renderedNodes[t];if(i._collectFadingNodes(),i._refreshTransitionOpacity(),i.segment._transitionOpacity>=1)i.clearNeighbors(),i.getRenderedNodesNeighbors(e),e.push(i);else for(let t=0;t<i._fadingNodes.length;t++){let n=i._fadingNodes[t];n.segment&&n.segment._transitionOpacity>=1&&(n.clearNeighbors(),n.getRenderedNodesNeighbors(e),e.push(n))}}}}_renderScreenNodesPASSNoAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodes(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesPASSAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsAtmos(e);this._renderingScreenNodes(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSNoAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodesWithHeight(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsAtmos(e);this._renderingScreenNodesWithHeight(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_globalPreDraw(){let e=this.camera;this.renderer.__useDistanceFramebuffer__=!this.terrain.isEmpty,this._distBeforeMemClear+=this._prevCamEye.distance(e.eye),this._prevCamEye.copy(e.eye),e.checkFly(),this._createdNodesCount>200&&this._distBeforeMemClear>1e3&&(this.terrain.clearCache(),this.memClear()),this._indexesCacheToRemoveCounter>600&&this._clearIndexesCache()}preFrame(){this._updateLayer&&(this._updateLayer=!1,this._updateVisibleLayers()),this.camera.isFirstPass&&(this.camera.update(),this._skipPreRender&&this._collectRenderNodesIsActive&&this._collectRenderNodes(this.camera),this._skipPreRender=!0,this.transformLights(),this._normalMapCreator.frame(),this._geoImageCreator.frame(),this._vectorTileCreator.frame(),this.camera.checkTerrainCollision(),this.camera.update(),this.events.dispatch(this.events.draw,this),this._collectVectorLayerCollections()),this.drawEntityCollections(this._frustumEntityCollections)}frame(){this._renderScreenNodesPASS()}_checkRendercompleted(){this._renderCompleted?this._renderCompletedActivated||(this._renderCompletedActivated=!0,this.events.dispatch(this.events.rendercompleted,!0)):this._renderCompletedActivated=!1,this._renderCompleted=!0,this._terrainCompleted?this._terrainCompletedActivated||(this._terrainCompletedActivated=!0,this.events.dispatch(this.events.terraincompleted,!0)):this._terrainCompletedActivated=!1,this._terrainCompleted=!0}lockQuadTree(){this._collectRenderNodesIsActive=!1,this.camera.setTerrainCollisionActivity(!1)}unlockQuadTree(){this._collectRenderNodesIsActive=!0,this.camera.setTerrainCollisionActivity(!0)}_setUniformsNoAtmos(e){let t,i,n=this.renderer,r=n.handler,s=r.gl;return s.enable(s.CULL_FACE),n.enableBlendOneSrcAlpha(),this.lightEnabled?(r.programs.drawnode_screen_wl.activate(),t=r.programs.drawnode_screen_wl._program,i=t.uniforms,s.uniform3fv(i.lightsPositions,this._lightsPositions),s.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),s.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(s.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),s.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),s.uniform4fv(i.specular,this.baseLayer._specular||this._specular),s.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(s.uniform3fv(i.diffuse,this._diffuse),s.uniform3fv(i.ambient,this._ambient),s.uniform4fv(i.specular,this._specular),s.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE),s.bindTexture(s.TEXTURE_2D,this._nightTexture||this.transparentTexture),s.uniform1i(i.nightTexture,this.SLICE_SIZE),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE+1),s.bindTexture(s.TEXTURE_2D,this._specularTexture||this.transparentTexture),s.uniform1i(i.specularTexture,this.SLICE_SIZE+1),s.uniform1f(i.camHeight,e.getHeight())):(r.programs.drawnode_screen_nl.activate(),t=r.programs.drawnode_screen_nl._program,i=t.uniforms,s.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),s.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),s.uniform3fv(i.eyePositionHigh,e.eyeHigh),s.uniform3fv(i.eyePositionLow,e.eyeLow),t}_setUniformsAtmos(e){let t,i,n=this.renderer,r=n.handler,s=r.gl;return s.enable(s.CULL_FACE),n.enableBlendOneSrcAlpha(),this.lightEnabled?(r.programs.drawnode_screen_wl.activate(),t=r.programs.drawnode_screen_wl._program,i=t.uniforms,s.uniform3fv(i.lightsPositions,this._lightsPositions),s.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),s.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(s.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),s.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),s.uniform4fv(i.specular,this.baseLayer._specular||this._specular),s.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(s.uniform3fv(i.diffuse,this._diffuse),s.uniform3fv(i.ambient,this._ambient),s.uniform4fv(i.specular,this._specular),s.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),s.uniform2fv(i.maxMinOpacity,this._atmosphereMaxMinOpacity),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE),s.bindTexture(s.TEXTURE_2D,this._nightTexture||this.transparentTexture),s.uniform1i(i.nightTexture,this.SLICE_SIZE),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE+1),s.bindTexture(s.TEXTURE_2D,this._specularTexture||this.transparentTexture),s.uniform1i(i.specularTexture,this.SLICE_SIZE+1),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE+4),s.bindTexture(s.TEXTURE_2D,n.controls.Atmosphere._transmittanceBuffer.textures[0]),s.uniform1i(i.transmittanceTexture,this.SLICE_SIZE+4),s.activeTexture(s.TEXTURE0+this.SLICE_SIZE+5),s.bindTexture(s.TEXTURE_2D,n.controls.Atmosphere._scatteringBuffer.textures[0]),s.uniform1i(i.scatteringTexture,this.SLICE_SIZE+5),s.uniform1f(i.camHeight,e.getHeight())):(r.programs.drawnode_screen_nl.activate(),t=r.programs.drawnode_screen_nl._program,i=t.uniforms,s.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),s.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),s.uniform3fv(i.eyePositionHigh,e.eyeHigh),s.uniform3fv(i.eyePositionLow,e.eyeLow),t}_renderingScreenNodes(e,t,i){let n=t.isFirstPass,r=this._visibleTileLayerSlices;if(r.length){let e=r[0];for(let t=e.length-1;t>=0;--t){let i=e[t];i._fading&&n&&i._refreshFadingOpacity()&&e.splice(t,1)}}let s=new Map,a=[],o=this.terrain.equalizeVertices,l=i.length;if(t.slope>.8)for(;l--;){let t=i[l],n=t.segment;this._renderingFadingNodesNoDepth(s,e,t,r[0],0),o&&n.equalize(),n.readyToEngage&&n.engage(),n.screenRendering(e,r[0],0)}else{for(;l--;){let t=i[l],n=t.segment;this._renderingFadingNodes(s,e,t,r[0],0,a),n._transitionOpacity<1?a.push(n):(o&&n.equalize(),n.readyToEngage&&n.engage(),n.screenRendering(e,r[0],0))}for(let t=0;t<a.length;t++){let i=a[t];o&&i.equalize(),i.readyToEngage&&i.engage(),i.screenRendering(e,r[0],0)}}}_renderingScreenNodesWithHeight(e,t,i){let n=this.renderer.handler.gl,r=t.isFirstPass,s=this._visibleTileLayerSlices;n.enable(n.POLYGON_OFFSET_FILL),n.disable(n.CULL_FACE);let a=new Map,o=[];for(let t=1,l=s.length;t<l;t++){let l=s[t];for(let e=l.length-1;e>=0;--e){let t=l[e];t._fading&&r&&t._refreshFadingOpacity()&&l.splice(e,1)}n.polygonOffset(0,-t);let h=i.length;for(;h--;){let n=i[h];this._renderingFadingNodes(a,e,n,s[t],t,o),n.segment._transitionOpacity<1?n.segment.initSlice(t):n.segment.screenRendering(e,s[t],t,this.transparentTexture,!0)}}n.disable(n.POLYGON_OFFSET_FILL),n.enable(n.CULL_FACE)}_renderDistanceFramebufferPASS(){if(!this.terrain.isEmpty){let e,t=this.renderer,i=t.handler,n=i.gl,r=t.activeCamera;i.programs.drawnode_heightPicking.activate(),e=i.programs.drawnode_heightPicking._program;let s=e.uniforms;n.uniformMatrix4fv(s.viewMatrix,!1,r.getViewMatrix()),n.uniformMatrix4fv(s.projectionMatrix,!1,r.getProjectionMatrix()),n.uniform3fv(s.eyePositionHigh,r.eyeHigh),n.uniform3fv(s.eyePositionLow,r.eyeLow);let a=this._renderedNodesInFrustum[r.currentFrustumIndex],o=this._visibleTileLayerSlices,l=a.length;for(;l--;)a[l].segment.heightPickingRendering(e,o[0])}}_renderColorPickingFramebufferPASS(){let e,t=this.renderer,i=t.handler,n=i.gl;i.programs.drawnode_colorPicking.activate(),e=i.programs.drawnode_colorPicking._program;let r=e.uniforms,s=t.activeCamera;n.enable(n.CULL_FACE),n.uniformMatrix4fv(r.viewMatrix,!1,s.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,s.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,s.eyeHigh),n.uniform3fv(r.eyePositionLow,s.eyeLow);let a=this._renderedNodesInFrustum[s.getCurrentFrustum()],o=this._visibleTileLayerSlices,l=a.length;for(;l--;)a[l].segment.colorPickingRendering(e,o[0],0);t.enableBlendDefault(),n.enable(n.POLYGON_OFFSET_FILL);for(let t=1,i=o.length;t<i;t++)for(l=a.length,n.polygonOffset(0,-t);l--;)a[l].segment.colorPickingRendering(e,o[t],t,this.transparentTexture,!0);n.disable(n.POLYGON_OFFSET_FILL)}_renderDepthFramebufferPASS(){let e,t=this.renderer,i=t.handler,n=i.gl;i.programs.drawnode_depth.activate(),e=i.programs.drawnode_depth._program;let r=e.uniforms,s=t.activeCamera;n.disable(n.BLEND),n.disable(n.POLYGON_OFFSET_FILL),n.uniformMatrix4fv(r.viewMatrix,!1,s.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,s.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,s.eyeHigh),n.uniform3fv(r.eyePositionLow,s.eyeLow),n.uniform3fv(r.frustumPickingColor,s.frustum._pickingColorU);let a=this._renderedNodesInFrustum[s.getCurrentFrustum()],o=this._visibleTileLayerSlices,l=a.length;for(;l--;)a[l].segment.depthRendering(e,o[0]);n.enable(n.BLEND)}_collectVectorLayerCollections(){this._frustumEntityCollections.length=0,this._frustumEntityCollections=[];let e=this.visibleVectorLayers.length;for(;e--;){let t=this.visibleVectorLayers[e];t._fading&&t._refreshFadingOpacity()&&this.visibleVectorLayers.splice(e,1),t.collectVisibleCollections(this._frustumEntityCollections),t.update()}}_frustumEntityCollectionPickingCallback(){this.drawPickingEntityCollections(this._frustumEntityCollections)}memClear(){this._distBeforeMemClear=0,this.camera._insideSegment=null,this.layerLock.lock(this._memKey),this.terrainLock.lock(this._memKey),this._normalMapCreator.lock(this._memKey),this._normalMapCreator.clear(),this.terrain.abortLoading(),this._tileLoader.abortAll(),this.quadTreeStrategy.clear(),this.layerLock.free(this._memKey),this.terrainLock.free(this._memKey),this._normalMapCreator.free(this._memKey),this._createdNodesCount=0}getRayIntersectionEllipsoid(e){return this.ellipsoid.hitRay(e.origin,e.direction)}getCartesianFromPixelEllipsoid(e){let t=this.renderer.activeCamera;return this.ellipsoid.hitRay(t.eye,t.unproject(e.x,e.y))}getLonLatFromPixelEllipsoid(e){let t=this.getCartesianFromPixelEllipsoid(e);if(t)return this.ellipsoid.cartesianToLonLat(t)}getCartesianFromMouseTerrain(){let e=this.renderer.events.mouseState,t=this.getDistanceFromPixel(e);if(t)return e.direction.scaleTo(t).addA(this.renderer.activeCamera.eye)}getCartesianFromPixelTerrain(e){let t=this.getDistanceFromPixel(e);if(t){return(e.direction||this.renderer.activeCamera.unproject(e.x,e.y)).scaleTo(t).addA(this.renderer.activeCamera.eye)}}getLonLatFromPixelTerrain(e){let t=this.getCartesianFromPixelTerrain(e);if(t)return this.ellipsoid.cartesianToLonLat(t)}getPixelFromCartesian(e){return this.renderer.activeCamera.project(e)}getPixelFromLonLat(e){let t=this.ellipsoid.lonLatToCartesian(e);if(t)return this.renderer.activeCamera.project(t)}getDistanceFromPixelEllipsoid(e){let t=this.getCartesianFromPixelEllipsoid(e);if(t)return t.distance(this.renderer.activeCamera.eye)}getDistanceFromPixel(e){if(this.terrain.isEmpty)return this.getDistanceFromPixelEllipsoid(e)||0;{let t=this.renderer,i=t.handler.canvas,n=e.x/i.width,r=(i.height-e.y)/i.height;Xa[0]=Xa[1]=Xa[2]=0;let s=0;if(t.readDistanceColor(n,r,Xa),s=function(e,t=!1){let i=1-2*w(128,e[0]),n=2*x(e[0],128)+w(128,e[1])-127,r=65536*x(e[1],128)+256*e[2]+(t&&e[3]||0)+8388608;return i*T(n)*(1.1920928955078125e-7*r)}(Xa),Xa[0]||Xa[1]||Xa[2]){if(s<11){t.screenDepthFramebuffer.activate(),t.screenDepthFramebuffer.readPixels($a,n,r);let i=new re(2*n-1,2*r-1,$a[0]/255*2-1,1),a=this.camera.frustums[0].inverseProjectionMatrix.mulVec4(i),o=e.direction||t.activeCamera.unproject(e.x,e.y);s=-a.z/a.w/o.dot(t.activeCamera.getForward()),t.screenDepthFramebuffer.deactivate()}}else s=this.getDistanceFromPixelEllipsoid(e)||0;return s}}viewExtent(e){this.camera?this.camera.viewExtent(e):this._initialViewExtent=e}viewExtentArr(e){this.viewExtent(new ie(new z(e[0],e[1]),new z(e[2],e[3])))}getViewExtent(){return this._viewExtent}viewLonLat(e,t,i){this.camera.setLonLat(e,t,i)}flyExtent(e,t,i,n,r,s){this.camera.flyExtent(e,t,i,n,r,s)}flyCartesian(e,t,i,n,r,s,a){this.camera.flyCartesian(e,t,i,n,r,s,a)}flyLonLat(e,t,i,n,r,s,a){this.camera.flyLonLat(e,t,i,n,r,s,a)}stopFlying(){this.camera.stopFlying()}updateBillboardsTexCoords(){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].billboardHandler.refreshTexCoordsArr();let e={};for(let t=0;t<this._layers.length;t++){let i=this._layers[t];i instanceof In&&i.each((function(t){t._entityCollection&&!e[t._entityCollection.id]&&(t._entityCollection.billboardHandler.refreshTexCoordsArr(),e[t._entityCollection.id]=!0)}))}}getEntityTerrainPoint(e,t){let i=this._renderedNodes,n=i.length;for(;n--;)if(i[n].segment.isEntityInside(e))return i[n].segment.getEntityTerrainPoint(e,t)}async getHeightDefault(e){return new Promise((t=>{this.terrain?this.terrain.getHeightAsync(e.clone(),(e=>{t(e)})):t(0)}))}async getHeightAboveELL(e){return new Promise((t=>{this.terrain?this.terrain.getHeightAsync(e.clone(),(i=>{t(i+this.terrain.geoid.getHeightLonLat(e))})):t(0)}))}onremove(){this.memClear(),this.quadTreeStrategy.destroyBranches(),this._renderedNodes=[]}}const Ka=["draw","layeradd","baselayerchange","layerremove","layervisibilitychange","rendercompleted","terraincompleted","layerloadend"];class Qa extends Pi{constructor(e){super("skybox"),this.params=e,this.vertexPositionBuffer=null,this.texture=null}static createDefault(e){return new Qa({nx:e+"skybox/gal/_nx.jpg",px:e+"skybox/gal/_px.jpg",py:e+"skybox/gal/_py.jpg",ny:e+"skybox/gal/_ny.jpg",pz:e+"skybox/gal/_pz.jpg",nz:e+"skybox/gal/_nz.jpg"})}init(){this.renderer.handler.addProgram(new zi("skybox",{uniforms:{projectionViewMatrix:{type:Bi.MAT4},uSampler:{type:Bi.SAMPLERCUBE},pos:{type:Bi.VEC3}},attributes:{aVertexPosition:{type:Bi.VEC3,enableArray:!0}},vertexShader:"attribute vec3 aVertexPosition;\n uniform mat4 projectionViewMatrix;\n uniform vec3 pos;\n varying vec3 vTextureCoord;\n void main(void) {\n vTextureCoord = aVertexPosition;\n gl_Position = projectionViewMatrix * vec4(aVertexPosition + pos, 1.0);\n }",fragmentShader:"precision lowp float;\n varying vec3 vTextureCoord;\n uniform samplerCube uSampler;\n void main(void) {\n gl_FragColor = textureCube(uSampler, vTextureCoord);\n }"}),!0),this.texture=this.renderer.handler.loadCubeMapTexture(this.params),this._createBuffers(),this.drawMode=this.renderer.handler.gl.TRIANGLES}frame(){let e=this.renderer.handler,t=e.gl,i=this.renderer.activeCamera;t.disable(t.DEPTH_TEST),e.programs.skybox.activate();let n=e.programs.skybox._program,r=n.uniforms;t.uniformMatrix4fv(r.projectionViewMatrix,!1,i.getProjectionViewMatrix()),t.uniform3fv(r.pos,i.eye.toArray()),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_CUBE_MAP,this.texture),t.uniform1i(r.uSampler,0);let s=this.vertexPositionBuffer;t.bindBuffer(t.ARRAY_BUFFER,s),t.vertexAttribPointer(n.attributes.aVertexPosition,s.itemSize,t.FLOAT,!1,0,0),t.drawArrays(this.drawMode,0,s.numItems),t.enable(t.DEPTH_TEST)}_createBuffers(){const e=new Float32Array([-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,1e8,-1e8,1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,1e8,-1e8,1e8]);this.vertexPositionBuffer=this.renderer.handler.createArrayBuffer(e,3,e.length/3)}}var Ja=Object.freeze({__proto__:null,Axes:class extends Pi{constructor(e=100){super("Axes"),this.size=e,this.axesBuffer=null,this.axesColorBuffer=null}init(){this.createAxesBuffer(this.size),this.drawMode=this.renderer.handler.gl.LINES,this.renderer.handler.addProgram(new zi("axesShader",{uniforms:{projectionViewMatrix:"mat4"},attributes:{aVertexPosition:"vec3",aVertexColor:"vec4"},vertexShader:"attribute vec3 aVertexPosition;\n attribute vec4 aVertexColor;\n uniform mat4 projectionViewMatrix;\n varying vec4 vColor;\n void main(void) {\n gl_Position = projectionViewMatrix * vec4(aVertexPosition, 1.0);\n vColor = aVertexColor;\n }",fragmentShader:"precision highp float;\n varying vec4 vColor;\n void main(void) {\n gl_FragColor = vColor;\n }"}))}frame(){this.renderer.handler.programs.axesShader.activate().set({projectionViewMatrix:this.renderer.activeCamera.getProjectionViewMatrix(),aVertexPosition:this.axesBuffer,aVertexColor:this.axesColorBuffer}),this.renderer.handler.programs.axesShader.drawArrays(this.drawMode,this.axesBuffer.numItems)}createAxesBuffer(e){const t=[0,0,0,e-1,0,0,0,0,0,0,e-1,0,0,0,0,0,0,e-1];this.axesBuffer=this.renderer.handler.createArrayBuffer(new Float32Array(t),3,6),this.axesColorBuffer=this.renderer.handler.createArrayBuffer(new Float32Array([1,0,0,1,1,0,0,1,0,0,1,1,0,0,1,1,0,1,0,1,0,1,0,1]),4,6)}},Planet:Za,RenderNode:Pi,SkyBox:Qa});class eo{constructor(e={}){this.__id=eo.__counter__++,this.equalizeVertices=e.equalizeVertices||!1,this.equalizeNormals=!1,this.isEmpty=!0,this.name=e.name||"empty",this.minZoom=e.minZoom||2,this.maxZoom=e.maxZoom||19,this.maxNativeZoom=e.maxNativeZoom||this.maxZoom,this.gridSizeByZoom=e.gridSizeByZoom||[64,32,16,8,4,4,4,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],this._maxNodeZoom=this.gridSizeByZoom.length-1,this.plainGridSize=2,this.noDataValues=[],this._planet=null,this._geoid=e.geoid||new Ma({src:e.geoidSrc||null}),this._isReady=!1}setUrlRewriteCallback(e){}get isIdle(){return!0}isEqual(e){return e.__id===this.__id}static checkNoDataValue(e,t){return-1!==Be(e,t)}isBlur(e){return!1}set maxNodeZoom(e){e>this.gridSizeByZoom.length-1&&(e=this.gridSizeByZoom.length-1),this._maxNodeZoom=e}get maxNodeZoom(){return this._maxNodeZoom}set geoid(e){this._geoid=e}get geoid(){return this._geoid}getGeoid(){return this._geoid}handleSegmentTerrain(e){e.terrainIsLoading=!1,e.terrainReady=!0,e.terrainExists=!0}isReady(){return this._isReady}abortLoading(){}clearCache(){}getHeightAsync(e,t){return t(0),!0}loadTerrain(e,t=!1){}}eo.__counter__=0;class to extends eo{constructor(e="",t={}){super({geoidSrc:"https://openglobus.org/geoid/egm84-30.pgm",maxNativeZoom:t.maxNativeZoom||14,...t}),this._s=t.subdomains||["a","b","c"],this.events=Pt(io,this),this._requestCount=0,this._requestsPeerSubdomain=4,this.isEmpty=!1,this.equalizeNormals=!0,this.name=e||"openglobus",this.url=t.url||"https://{s}.srtm3.openglobus.org/{z}/{y}/{x}.ddm",this.gridSizeByZoom=t.gridSizeByZoom||[64,32,32,16,16,8,8,8,16,16,16,32,32,32,32,16,8,4,2,2,2,2,2,2],this._heightFactor=null!=t.heightFactor?t.heightFactor:1,this.noDataValues=t.noDataValues||[];for(let e=0;e<this.noDataValues.length;e++)this.noDataValues[e]*=this._heightFactor;this.plainGridSize=t.plainGridSize||32,this._extent=Se(t.extent,new ie(new z(-180,-90),new z(180,90))),this._dataType="arrayBuffer",this._maxNodeZoom=this.gridSizeByZoom.length-1,this._elevationCache={},this._fetchCache={},this._loader=new Ra,this._urlRewriteCallback=t.urlRewrite||null}get loader(){return this._loader}clearCache(){for(let e in this._elevationCache)this._elevationCache[e].heights=null,this._elevationCache[e].extent=null,delete this._elevationCache[e];this._elevationCache=null,this._elevationCache={};for(let e in this._fetchCache)this._fetchCache[e]=null,delete this._fetchCache[e];this._fetchCache=null,this._fetchCache={}}isBlur(e){return e.tileZoom>=6}setElevationCache(e,t){this._elevationCache[e]=t}getElevationCache(e){return this._elevationCache[e]}getHeightAsync(e,t,i,n){if(!e||e.lat>J||e.lat<ee)return t(0),!0;n=null==n||n;const[r,s,a,o]=this._planet.quadTreeStrategy.getTileXY(e,i||this.maxZoom);let l=qt.getTileIndex(r,s,a,o),h=this.getElevationCache(l),c=X(e);if(h)return h.heights?t(this._getGroundHeightMerc(c,h)):t(0),!0;{let i=this._fetchCache[l];i||(i=this._loader.fetch({src:this.buildURL(r,s,a,o),type:this._dataType}),this._fetchCache[l]=i),i.then((i=>{let h=Q(r,s,a);if("ready"===i.status){let e={heights:this._createHeights(i.data,null,o,r,s,a,h),extent:h};this.setElevationCache(l,e),t(this._getGroundHeightMerc(c,e))}else if("error"===i.status){if(n&&a>this.maxNativeZoom)return n=!1,void this.getHeightAsync(e,t,this.maxNativeZoom,!1);this.setElevationCache(l,{heights:null,extent:h}),t(0)}else this._fetchCache[l]=null,delete this._fetchCache[l]}))}return!1}_getGroundHeightMerc(e,t){if(!t.extent||!t.heights)return 0;let i=t.extent.getWidth(),n=Math.sqrt(t.heights.length),r=i/(n-1),s=n-Math.ceil((e.lat-t.extent.southWest.lat)/r)-1,a=Math.floor((e.lon-t.extent.southWest.lon)/r),o=(s+1)*n+a,l=o+1,h=s*n+a,c=h+1,d=t.heights[o],_=t.heights[l],u=t.heights[h],f=t.heights[c],g=new oe(t.extent.southWest.lon+r*a,d,t.extent.northEast.lat-r*s-r),p=new oe(g.x+r,_,g.z),m=new oe(g.x,u,g.z+r),v=new oe(g.x+r,f,g.z+r),y=new oe(e.lon,1e5,e.lat),x=new _i(y,new oe(0,-1,0)),b=new oe,w=x.hitTriangle(g,p,m,b);return w===_i.INSIDE?b.y:(w=x.hitTriangle(p,v,m,b),w===_i.INSIDE?b.y:0)}abortLoading(){this._loader.abortAll()}setUrl(e){this.url=e}setName(e){this.name=e}isReadyToLoad(e){return 0===e._tileGroup&&this._extent.overlaps(e.getExtentLonLat())}loadTerrain(e,t=!1){if(this._planet.terrainLock.isFree())if(e.terrainReady=!1,e.terrainIsLoading=!0,this.isReadyToLoad(e)){let i=this.getElevationCache(e.tileIndex);i?this._applyElevationsData(e,i.heights):this._loader.load({sender:this,src:this._getHTTPRequestString(e),segment:e,type:this._dataType,filter:()=>e.plainReady&&0!==e.node.getState()||t},(t=>{if("ready"===t.status){let i=this._createHeights(t.data,e,e._tileGroup,e.tileX,e.tileY,e.tileZoom,e.getExtent(),e.tileZoom===this.maxZoom);this.setElevationCache(e.tileIndex,{heights:i,extent:e.getExtent()}),this._applyElevationsData(e,i)}else"abort"===t.status?e.terrainIsLoading=!1:"error"===t.status?this._applyElevationsData(e,null):e.terrainIsLoading=!1}))}else e.elevationsNotExists();else e.terrainIsLoading=!1}_getSubdomain(){return this._requestCount++,this._s[Math.floor(this._requestCount%(this._requestsPeerSubdomain*this._s.length)/this._requestsPeerSubdomain)]}buildURL(e,t,i,n){return be(this.url,{s:this._getSubdomain(),x:e.toString(),y:t.toString(),z:i.toString()})}_createUrl(e){return this.buildURL(e.tileX,e.tileY,e.tileZoom,e._tileGroup)}_getHTTPRequestString(e){return this._urlRewriteCallback&&this._urlRewriteCallback(e.tileX,e.tileY,e.tileZoom,e._tileGroup)||this._createUrl(e)}setUrlRewriteCallback(e){this._urlRewriteCallback=e}_createHeights(e,t,i,n,r,s,a,o){if(1!==this._heightFactor){let t=new Float32Array(e);for(let e=0,i=t.length;e<i;e++)t[e]=t[e]*this._heightFactor;return t}return new Float32Array(e)}_applyElevationsData(e,t){if(e){let i=this.events.load;i.handlers.length&&this.events.dispatch(i,{elevations:t,segment:e}),e.applyTerrain(t)}}}const io=["load","loadend"];class no extends qt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(ro),this.url=t.url||"",this._s=t.subdomains||["a","b","c"],this.minNativeZoom=t.minNativeZoom||0,this.maxNativeZoom=t.maxNativeZoom||19,this._urlRewriteCallback=t.urlRewrite||null,this._requestsPeerSubdomains=4,this._requestCount=0}get isIdle(){return super.isIdle&&0===this._planet._tileLoader.getRequestCounter(this)}get instanceName(){return"XYZ"}abortLoading(){this._planet&&this._planet._tileLoader.abort(this)}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),e||this.abortLoading())}remove(){return this.abortLoading(),super.remove(),this}setUrl(e){this.url=e}_checkSegment(e){return e._projection.id===this._planet.quadTreeStrategy.projection.id}loadMaterial(e,t=!1){let i=e.segment;this._isBaseLayer?e.texture=i.getDefaultTexture():e.texture=i.planet.transparentTexture,(this._planet.layerLock.isFree()||e.segment.tileZoom<2)&&(e.isReady=!1,e.isLoading=!0,this._checkSegment(i)?(e.loadingAttempts++,this._planet._tileLoader.load({sender:this,src:this._getHTTPRequestString(e.segment),type:"imageBitmap",filter:()=>i.initialized&&1===i.node.getState()||t,options:{}},(t=>{if("ready"===t.status){if(e.isLoading){let i=this.events.load;i.handlers.length&&this.events.dispatch(i,e),e.applyImage(t.data),t.data=null}}else"abort"===t.status?e.isLoading=!1:"error"===t.status&&e.isLoading&&e.textureNotExists()}))):e.textureNotExists())}_createUrl(e){return be(this.url,{s:this._getSubdomain(),x:e.tileX.toString(),y:e.tileY.toString(),z:e.tileZoom.toString()})}_getSubdomain(){return this._requestCount++,this._s[Math.floor(this._requestCount%(this._requestsPeerSubdomains*this._s.length)/this._requestsPeerSubdomains)]}_getHTTPRequestString(e){return this._urlRewriteCallback?this._urlRewriteCallback(e,this.url):this._createUrl(e)}setUrlRewriteCallback(e){this._urlRewriteCallback=e}applyMaterial(e,t=!1){if(e.isReady)return e.texOffset;if(e.segment.tileZoom<this.minNativeZoom)e.textureNotExists();else{let i=e.segment,n=i.node,r=!1,s=this.__id,a=e;for(;n.parentNode;)if(n=n.parentNode,a=n.segment.materials[s],a&&a.textureExists){r=!0;break}if(i.passReady){let r=e.layer.maxNativeZoom;if(n.segment.tileZoom===r)e.textureNotExists();else if(e.segment.tileZoom<=r)!e.isLoading&&!e.isReady&&this.loadMaterial(e,t);else{let t=i.node;for(;t.segment.tileZoom>e.layer.maxNativeZoom;)t=t.parentNode;let n=t.segment.materials[e.layer.__id];n?!n.isLoading&&!n.isReady&&this.loadMaterial(n,!0):(n=t.segment.materials[e.layer.__id]=e.layer.createMaterial(t.segment),this.loadMaterial(n,!0))}}if(r){e.appliedNode=n,e.appliedNodeId=n.nodeId,e.texture=a.texture;let t=1/(2<<i.tileZoom-n.segment.tileZoom-1);e.texOffset[0]=i.tileX*t-n.segment.tileX,e.texOffset[1]=i.tileY*t-n.segment.tileY,e.texOffset[2]=t,e.texOffset[3]=t}else e.texture=i.planet.transparentTexture,e.texOffset[0]=0,e.texOffset[1]=0,e.texOffset[2]=1,e.texOffset[3]=1}return e.texOffset}clearMaterial(e){e.isReady&&e.textureExists&&(!e.texture.default&&e.segment.handler.gl.deleteTexture(e.texture),e.texture=null),e.isReady=!1,e.textureExists=!1,e.isLoading=!1}_correctFullExtent(){let e=this._extent,t=this._extentMerc,i=D+5e4,n=D+5e4;90===e.northEast.lat&&(t.northEast.lat=n),180===e.northEast.lon&&(t.northEast.lon=i),-90===e.southWest.lat&&(t.southWest.lat=-20087508.34),-180===e.southWest.lon&&(t.southWest.lon=-20087508.34),e.northEast.lat>=J&&(e.northEast.lat=J),e.northEast.lat<=ee&&(e.northEast.lat=ee)}}const ro=["load","loadend"];class so extends no{constructor(e,t){super(e,t),this._extra=new URLSearchParams(t.extra).toString(),t.extent||this.setExtent(new ie(new z(-180,-90),new z(180,90))),this.layers=t.layers,this.imageWidth=t.imageWidth||256,this.imageHeight=t.imageHeight||256,this._getBbox=so.get_bbox_v1_1_1,this._version="",this.setVersion(t.version)}static createRequestUrl(e,t,i="image/png",n="1.1.1",r="GetMap",s,a,o=256,l=256,h){return`${e}/?LAYERS=${t}&FORMAT=${i}&SERVICE=WMS&VERSION=${n}&REQUEST=${r}&SRS=${s}&BBOX=${a}&WIDTH=${o}&HEIGHT=${l}`+(h?`&${h}`:"")}static get_bbox_v1_1_1(e){return`${e.getWest()},${e.getSouth()},${e.getEast()},${e.getNorth()}`}static get_bbox_v1_3_0(e){return`${e.getSouth()},${e.getWest()},${e.getNorth()},${e.getEast()}`}_checkSegment(e){return!0}get instanceName(){return"WMS"}_createUrl(e){return so.createRequestUrl(this.url,this.layers,"image/png",this._version,"GetMap",e._projection.code,this._getBbox(e.getExtent()),this.imageWidth,this.imageHeight,this._extra)}setVersion(e){this._version=e||"1.1.1","1.1.1"===this._version?this._getBbox=so.get_bbox_v1_1_1:"1.3.0"===e&&(this._getBbox=so.get_bbox_v1_3_0)}_correctFullExtent(){const e=this._extent,t=this._extentMerc,i=D+5e4,n=D+5e4;90===e.northEast.lat&&(t.northEast.lat=n),180===e.northEast.lon&&(t.northEast.lon=i),-90===e.southWest.lat&&(t.southWest.lat=-20087508.34),-180===e.southWest.lon&&(t.southWest.lon=-20087508.34)}}class ao extends to{constructor(e={}){super("BilTerrain",e),this.equalizeVertices=!0,this.equalizeNormals=!0,this.minZoom=e.minZoom||2,this.maxZoom=e.maxZoom||14,this.noDataValues=e.noDataValues||[-9999,32767],this.url=e.url||"",this._format="application/bil16",this._layers=e.layers||"",this._imageSize=e.imageSize||256,this.plainGridSize=null!=e.plainGridSize?e.plainGridSize:m(this._imageSize)?this._imageSize/2:v(this._imageSize)/2,this._dataType="arrayBuffer"}isBlur(e){return e.tileZoom>=18}_createUrl(e){return so.createRequestUrl(this.url,this._layers,this._format,"1.1.1","GetMap",e._projection.code,so.get_bbox_v1_1_1(e.getExtent()),this._imageSize,this._imageSize)}_createHeights(e,t,i,n,r,s,a,o){let l=new Int16Array(e);if(!m(this._imageSize)){let e=new Float32Array(l.length);return function(e,t){for(let i=0,n=t.length;i<n;i++)t[i]=e[i]}(l,e),e}let h=(this.plainGridSize+1)*(this.plainGridSize+1),c=new Array(4);for(let e=0;e<4;e++){c[e]=[];for(let t=0;t<4;t++)c[e][t]=new Float32Array(h)}let d=new Float32Array(h);!function(e,t,i,n){let r=Math.sqrt(i.length)-1,s=r+1,a=Math.sqrt(e.length),o=a/r,l=0,h=0;for(let c=0,d=0,_=e.length;c<_;c++){let _=e[c],u=ao.checkNoDataValue(t,_),f=!1,g=!1,p=Math.floor(c/a),m=c%a,v=Math.floor(m/r),y=Math.floor(p/r),x=n[y][v],b=p%r,w=m%r,C=(b+y)*s+w+v;if(x[C]=_,(p+y)%o==0&&(m+v)%o==0&&(i[d++]=_),(m+1)%r==0&&m!==a-1){l=e[c],f=ao.checkNoDataValue(t,l);let a=_;u||f||(a=.5*(_+l)),C=(b+y)*s+w+1,x[C]=a,(p+y)%o==0&&(i[d++]=a);let h=(b+y)*s+(w+1)%r;n[y][v+1][h]=a}if((p+1)%r==0&&p!==a-1){h=e[c+a],g=ao.checkNoDataValue(t,h);let l=_;u||g||(l=.5*(_+h)),C=(b+1)*s+w+v,x[C]=l,(m+v)%o==0&&(i[d++]=l);let f=(b+1)%r*s+w+v;n[y+1][v][f]=l}if((m+1)%r==0&&m!==a-1&&(p+1)%r==0&&p!==a-1){let o=e[c+a+1],p=ao.checkNoDataValue(t,o),m=_;u||f||g||p||(m=.25*(_+l+h+o)),C=(b+1)*s+(w+1),x[C]=m,i[d++]=m;let T=(b+1)*s;n[y][v+1][T]=m;let L=r;n[y+1][v][L]=m;let A=0;n[y+1][v+1][A]=m}}}(l,this.noDataValues,d,c);let _=qt.getTileIndex(n,r,s,i);this.setElevationCache(_,{heights:d,extent:a});let u=this._imageSize/this.plainGridSize;for(let e=0;e<u;e++)for(let t=0;t<u;t++){let a=2*n+t,o=2*r+e,l=s+1,h=qt.getTileIndex(a,o,l,i);this.setElevationCache(h,{heights:c[e][t],extent:Q(a,o,l)})}return d}}const oo=(e,t,i)=>255===e?-1e4:.1*(256*e*256+256*t+i)-1e4;class lo extends to{constructor(e,t={}){super(e||"RgbTerrain",{equalizeVertices:null==t.equalizeVertices||t.equalizeVertices,maxZoom:t.maxZoom||17,noDataValues:t.noDataValues||[-65537,-1e4],plainGridSize:t.plainGridSize||128,url:null!=t.url?t.url:`//api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token=${t.key||"<key>"}`,gridSizeByZoom:t.gridSizeByZoom||[64,32,16,8,8,8,16,16,16,32,32,32,32,32,32,64,64,64,32,32,16,8],...t}),this.equalizeNormals=t.equalizeNormals||!1,this._dataType="imageBitmap",this._imageSize=t.imageSize||256,this._ctx=this._createTemporalCanvas(this._imageSize),this._imageDataCache={}}static checkNoDataValue(e,t){return t>5e4||-1!==Be(e,t)}isBlur(e){return e.tileZoom>=16}_createTemporalCanvas(e){let t=document.createElement("canvas");return t.width=e,t.height=e,t.getContext("2d",{willReadFrequently:!0})}_createHeights(e,t,i,n,r,s,a,o){this._ctx.clearRect(0,0,this._imageSize,this._imageSize),this._ctx.drawImage(e,0,0);let l=this._ctx.getImageData(0,0,this._imageSize,this._imageSize).data;const h=e.width;let c=0,d=0,_=0,u=null,f=!1;if(t&&t.tileZoom>this.maxNativeZoom){let e=t.node;for(;e&&!e.segment.terrainExists;)e=e.parentNode;e&&(c=e.segment.tileX,d=e.segment.tileY,_=e.segment.tileZoom,u=e.segment.elevationData,f=_<=8)}if(!m(this._imageSize)&&h===this._imageSize){let e=new Float32Array(h*h);return function(e,t,i=1){for(let n=0,r=t.length;n<r;n++){let r=4*n;t[n]=i*oo(e[r],e[r+1],e[r+2])}}(l,e,this._heightFactor),e}if(this._imageSize===this.plainGridSize){let e=(this.plainGridSize+1)*(this.plainGridSize+1),i=new Float32Array(e),[n,r,s]=t?ho(t.tileX,t.tileY,t.tileZoom,c,d,_):[0,0,0];return function(e,t,i=null,n,r,s,a,o,l=1,h){for(let c=0,d=h*h;c<d;c++){let d=c%h,_=Math.floor(c/h),u=4*c,f=l*oo(e[u],e[u+1],e[u+2]);(lo.checkNoDataValue(t,f)||0===f)&&i&&(f=co(s,n,r,i,_,d,a)),o[_*(h+1)+d]=f}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(c*h+d),u=l*oo(e[_],e[_+1],e[_+2]);(lo.checkNoDataValue(t,u)||0===u)&&i&&(u=co(s,n,r,i,c,d,a)),o[c*(h+1)+h]=u}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(d*h+c),u=l*oo(e[_],e[_+1],e[_+2]);(lo.checkNoDataValue(t,u)||0===u)&&i&&(u=co(s,n,r,i,d,c,a)),o[h*(h+1)+c]=u}let c=l*oo(e[e.length-4],e[e.length-3],e[e.length-2]);(lo.checkNoDataValue(t,c)||0===c)&&i&&(c=co(s,n,r,i,h-1,h-1,a));o[o.length-1]=c}(l,this.noDataValues,u,n,r,s,f,i,this._heightFactor,this._imageSize),i}let g=(this.plainGridSize+1)*(this.plainGridSize+1),p=h/this.plainGridSize,v=new Float32Array(g),y=new Array(p);for(let e=0;e<p;e++){y[e]=[];for(let t=0;t<p;t++)y[e][t]=new Float32Array(g)}if(o)!function(e,t,i,n=null,r,s,a,o,l,h,c,d){let _=Math.sqrt(d.length)-1,u=_+1,f=Math.sqrt(e.length/4),g=f/_,p=0,m=0,v=0,[y,x,b]=ho(o,l,h,r,s,a);for(let r=0,s=0,a=e.length/4;r<a;r++){let a=4*r,o=t*oo(e[a],e[a+1],e[a+2]),l=lo.checkNoDataValue(i,o),h=!1,w=!1,C=Math.floor(r/f),T=r%f;(l||0===o)&&n&&(o=co(b,y,x,n,Math.floor(s/u),s%u,c));let L=Math.floor(T/_),A=Math.floor(C/_);if((C+A)%g==0&&(T+L)%g==0&&(d[s++]=o),(T+1)%_==0&&T!==f-1){p=t*oo(e[a+4],e[a+5],e[a+6]),h=lo.checkNoDataValue(i,p),(h||0===p)&&n&&(p=co(b,y,x,n,Math.floor(s/u),s%u,c));let r=o;l||h||(r=.5*(o+p)),(C+A)%g==0&&(d[s++]=r)}if((C+1)%_==0&&C!==f-1){v=4*f,m=t*oo(e[a+v],e[a+v+1],e[a+v+2]),w=lo.checkNoDataValue(i,m),(w||0===m)&&n&&(m=co(b,y,x,n,Math.floor(s/u),s%u,c));let r=.5*(o+m);l||w||(r=.5*(o+m)),(T+L)%g==0&&(d[s++]=r)}if((T+1)%_==0&&T!==f-1&&(C+1)%_==0&&C!==f-1){let r=t*oo(e[a+v+4],e[a+v+5],e[a+v+6]),_=lo.checkNoDataValue(i,r);(_||0===r)&&n&&(r=co(b,y,x,n,Math.floor(s/u),s%u,c));let f=o;l||h||w||_||(f=.25*(o+p+m+r)),d[s++]=f}}}(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,f,v);else{!function(e,t,i,n=null,r,s,a,o,l,h,c,d,_){let u=Math.sqrt(d.length)-1,f=u+1,g=Math.sqrt(e.length/4),p=g/u,m=0,v=0,y=0,[x,b,w]=ho(o,l,h,r,s,a);for(let r=0,s=0,a=e.length/4;r<a;r++){let a=4*r,o=t*oo(e[a],e[a+1],e[a+2]),l=lo.checkNoDataValue(i,o),h=!1,C=!1,T=Math.floor(r/g),L=r%g;(l||0===o)&&n&&(o=co(w,x,b,n,Math.floor(T/p),Math.floor(L/p),c));let A=Math.floor(L/u),E=Math.floor(T/u),P=_[E][A],S=T%u,M=L%u,B=(S+E)*f+M+A;if(P[B]=o,(T+E)%p==0&&(L+A)%p==0&&(d[s++]=o),(L+1)%u==0&&L!==g-1){m=t*oo(e[a+4],e[a+5],e[a+6]),h=lo.checkNoDataValue(i,m),(h||0===m)&&n&&(m=co(w,x,b,n,Math.floor(T/p),Math.floor((L+1)/p),c));let r=o;l||h||(r=.5*(o+m)),B=(S+E)*f+M+1,P[B]=r,(T+E)%p==0&&(d[s++]=r);let g=(S+E)*f+(M+1)%u;_[E][A+1][g]=r}if((T+1)%u==0&&T!==g-1){y=4*g,v=t*oo(e[a+y],e[a+y+1],e[a+y+2]),C=lo.checkNoDataValue(i,v),(C||0===v)&&n&&(v=co(w,x,b,n,Math.floor((T+1)/p),Math.floor(L/p),c));let r=.5*(o+v);l||C||(r=.5*(o+v)),B=(S+1)*f+M+A,P[B]=r,(L+A)%p==0&&(d[s++]=r);let h=(S+1)%u*f+M+A;_[E+1][A][h]=r}if((L+1)%u==0&&L!==g-1&&(T+1)%u==0&&T!==g-1){let r=t*oo(e[a+y+4],e[a+y+5],e[a+y+6]),g=lo.checkNoDataValue(i,r);(g||0===r)&&n&&(r=co(w,x,b,n,Math.floor((T+1)/p),Math.floor((L+1)/p),c));let k=o;l||h||C||g||(k=.25*(o+m+v+r)),B=(S+1)*f+(M+1),P[B]=k,d[s++]=k;let R=(S+1)*f;_[E][A+1][R]=k;let I=u;_[E+1][A][I]=k;let z=0;_[E+1][A+1][z]=k}}}(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,f,v,y);for(let e=0;e<p;e++)for(let t=0;t<p;t++){let[a,o,l]=[2*n+t,2*r+e,s+1],h=qt.getTileIndex(a,o,l,i);this.setElevationCache(h,{heights:y[e][t],extent:Q(a,o,l)})}}let x=qt.getTileIndex(n,r,s,i);return this.setElevationCache(x,{heights:v,extent:a}),v}getHeightAsync(e,t,i){if(0===(i=null!=i?i:this.maxZoom))return t(0),!0;const n=this._planet.quadTreeStrategy,[r,s,a,o]=n.getTileXY(e,i),[l,h]=n.getLonLatTileOffset(e,r,s,a,this._imageSize),c=4*(l*this._imageSize+h),d=qt.getTileIndex(r,s,a,o);if(this._imageDataCache[d]){let n=this._imageDataCache[d],r=this._heightFactor*oo(n[c],n[c+1],n[c+2]);return lo.checkNoDataValue(this.noDataValues,r)?this.getHeightAsync(e,t,i-1):(t(this._heightFactor*oo(n[c],n[c+1],n[c+2])),!0)}let _=this._fetchCache[d];return _||(_=this._loader.fetch({src:this._urlRewriteCallback&&this._urlRewriteCallback(r,s,a,o)||this.buildURL(r,s,a,o),type:this._dataType}),this._fetchCache[d]=_),_.then((n=>{if("ready"===n.status){this._ctx.clearRect(0,0,this._imageSize,this._imageSize),this._ctx.drawImage(n.data,0,0);let r=this._ctx.getImageData(0,0,256,256).data;this._imageDataCache[d]=r;let s=this._heightFactor*oo(r[c],r[c+1],r[c+2]);if(lo.checkNoDataValue(this.noDataValues,s))return this.getHeightAsync(e,t,i-1);t(this._heightFactor*oo(r[c],r[c+1],r[c+2]))}else{if("error"===n.status)return this.getHeightAsync(e,t,i-1);this._fetchCache[d]=null,delete this._fetchCache[d]}})),!1}}function ho(e,t,i,n,r,s){let a=2<<i-s-1;return[e-a*n,t-a*r,1/a]}function co(e,t,i,n,r,s,a){let o=Math.sqrt(n.length),l=n[Math.floor(i*e*o+r*e)*o+Math.floor(t*e*o+s*e)];return a&&l>0?0:l}const _o={[aa]:"north",[oa]:"south"},uo=(e,t,i,n)=>{let r=_o[n];if(r)return`https://terrain.openglobus.org/public/poles/${r}/${i}/${e}/${t}.png`};class fo extends lo{constructor(e,t){super(e||"GlobusEarthRgb",{maxNativeZoom:6,maxZoom:17,url:"https://{s}.terrain.openglobus.org/public/all/{z}/{x}/{y}.png",urlRewrite:uo,...t})}isReadyToLoad(e){return this._extent.overlaps(e.getExtentLonLat())}}var go=Object.freeze({__proto__:null,BilTerrain:ao,EmptyTerrain:eo,GlobusRgbTerrain:fo,GlobusTerrain:to,RgbTerrain:lo});class po extends cr{constructor(e,t={}){super(e,t),this._image=t.image||null,this._src=t.src||null,this._onLoad_=null}get instanceName(){return"GeoImage"}abortLoading(){this._image instanceof HTMLImageElement&&(this._image.src="")}setSrc(e){this._planet&&this._planet._geoImageCreator.remove(this),this._src=e,this._sourceReady=!1,this._sourceCreated=!1,this._image=new Image,this._image.crossOrigin="Anonymous",this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_),this._image.src=e}setImage(e){this._planet&&this._planet._geoImageCreator.remove(this),this._sourceCreated=!1,this._sourceReady=!1,this._image=e,this._image.crossOrigin="Anonymous",this._src=e.src,$e(this._image)?this._applyImage(this._image):(this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_))}_createSourceTexture(){!this._sourceCreated&&this._image&&(this._sourceTexture=this._planet.renderer.handler.createTexture_l(this._image),this._sourceCreated=!0)}_onLoad(e){this._applyImage(this._image),this._image instanceof HTMLImageElement&&this._image.removeEventListener("load",this._onLoad_),this._onLoad_=null}_applyImage(e){e&&(this._frameWidth=v(2*e.width,4096),this._frameHeight=v(3*e.height,4096),this._sourceReady=!0,this._planet&&this._planet._geoImageCreator.add(this))}loadMaterial(e){e.isLoading=!0,this._creationProceeding=!0,!this._sourceReady&&this._src?this._image?this._image instanceof HTMLImageElement&&($e(this._image)?this._applyImage(this._image):(this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_))):(this._image=new Image,this._image.crossOrigin="Anonymous",this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_),this._image.src=this._src):this._planet&&this._planet._geoImageCreator.add(this)}abortMaterialLoading(e){this._image&&this._image instanceof HTMLImageElement&&(this._image.src=""),this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class mo extends cr{constructor(e,t={}){super(e,t),this._sourceTexture=t.texture||null,t.texture&&(this._sourceReady=!0,this._sourceCreated=!0),this._frameWidth=null!=t.frameWidth?v(t.frameWidth):256,this._frameHeight=null!=t.frameHeight?v(t.frameHeight):256,this._animate=!0}get instanceName(){return"GeoTexture2d"}loadMaterial(e){this._planet._geoImageCreator.add(this)}bindTexture(e){this._sourceReady=!0,this._sourceCreated=!0,this._sourceTexture=e}setSize(e,t){this._frameWidth=e,this._frameHeight=t,this._frameCreated=!1}abortMaterialLoading(e){this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class vo extends cr{constructor(e,t={}){super(e,t),this._animate=!0,this._video=t.videoElement||null,this._src=t.src||null}get instanceName(){return"GeoVideo"}setSrc(e){this._planet&&this._planet._geoImageCreator.remove(this),this._src=e,this._sourceReady=!1}setVideoElement(e){this._planet&&this._planet._geoImageCreator.remove(this),this._video=e,this._src=e.src,this._sourceReady=!1}setVisibility(e){e!=this._visibility&&(super.setVisibility(e),this._planet&&(e?(this._sourceReady&&this._planet._geoImageCreator.add(this),this._video&&this._video.play()):(this._sourceReady&&this._planet._geoImageCreator.remove(this),this._video&&this._video.pause())))}_createSourceTexture(){let e=this._planet.renderer.handler.gl;this._sourceCreated?(e.bindTexture(e.TEXTURE_2D,this._sourceTexture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this._video)):(this._sourceTexture=this._planet.renderer.handler.createTexture_n_webgl1(this._video),this._sourceCreated=!0)}_onCanPlay(e){this._frameWidth=e.videoWidth,this._frameHeight=e.videoHeight,e.width=e.videoWidth,e.height=e.videoHeight,e.play(),this._sourceReady=!0,this._planet._geoImageCreator.add(this)}_onError(e){let t="unknown error";switch(e.error.code){case 1:t="video loading aborted";break;case 2:t="network loading error";break;case 3:t="video decoding failed / corrupted data or unsupported codec";break;case 4:t="video not supported"}console.warn(`Error: ${t} error-code=${e.error.code})`)}loadMaterial(e){if(e.isLoading=!0,this._creationProceeding=!0,!this._sourceReady&&this._src){if(this._video){if(this._video.readyState===this._video.HAVE_ENOUGH_DATA)this._onCanPlay(this._video);else if(this._video.src){let e=this;this._video.addEventListener("canplay",(function(t){e._onCanPlay(this)}))}}else{this._video=document.createElement("video"),this._video.crossOrigin="Anonymous";let e=this;this._video.addEventListener("canplay",(function(){e._onCanPlay(this)})),this._video.addEventListener("error",(function(){e._onError(this)}))}this._video.autoplay=!0,this._video.loop=!0,this._video.src=this._src,this._video.muted=!0,this._video.setAttribute("playsinline","true"),this._video.setAttribute("webkit-playsinline","true")}else this._planet._geoImageCreator.add(this)}abortMaterialLoading(e){this._video&&(this._video.src=""),this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class yo extends In{constructor(e,t={}){super(e,t),this._billboard=t.billboard||{src:"https://openglobus.org/examples/billboards/carrot.png"},this._color=t.color||"#6689db"}get instanceName(){return"KML"}_extractCoordonatesFromKml(e){return Array.from(e.getElementsByTagName("coordinates")).map((e=>e.textContent.trim())).map((e=>e.replace(/\n/g," ").replace(/\t/g," ").replace(/ +/g," ").split(" ").map((e=>e.split(",").map(parseFloat)))))}_AGBRtoRGBA(e){if(!e||8!=e.length)return;const t=parseInt(e.slice(0,2),16)/255,i=parseInt(e.slice(2,4),16),n=parseInt(e.slice(4,6),16);return`rgba(${parseInt(e.slice(6,8),16)},${n},${i},${t})`}_parseKMLcoordinates(e){return e.innerHTML.trim().replace(/\n/g," ").replace(/\t/g," ").replace(/ +/g," ").split(" ").map((e=>e.split(",").map(parseFloat)))}_kmlPlacemarkToEntity(e,t){if(!e)return;const i=Array.from(e.getElementsByTagName("name")),n=i&&i.length>0?i[0].innerHTML.trim():"",{iconHeading:r,iconURL:s,iconColor:a,lineWidth:o,lineColor:l}=this._extractStyle(e),h=[];for(const i of e.getElementsByTagName("coordinates")){const e=this._parseKMLcoordinates(i)||[[0,0,0]];for(const i of e){const[e,n,r]=i;h.push(new z(e,n,r)),e<t.southWest.lon&&(t.southWest.lon=e),n<t.southWest.lat&&(t.southWest.lat=n),e>t.northEast.lon&&(t.northEast.lon=e),n>t.northEast.lat&&(t.northEast.lat=n)}}if(1===h.length){const e=.01745329*r;return new Ai({name:n,lonlat:h[0],billboard:{src:s,size:[24,24],color:a,rotation:e},properties:{color:a,heading:r}})}return new Ai({polyline:{pathLonLat:[h],thickness:o,color:l,isClosed:!1}})}_extractStyle(e){let t,i,n,r,s;const a=e.getElementsByTagName("Style")[0];if(a){let e=a.getElementsByTagName("IconStyle")[0];if(e){let r=e.getElementsByTagName("color")[0];r&&(t=this._AGBRtoRGBA(r.innerHTML.trim()));let s=e.getElementsByTagName("heading")[0];if(s){const e=parseFloat(s.innerHTML.trim());e>=0&&e<=360&&(i=e%360)}let a=e.getElementsByTagName("Icon")[0];if(a){let e=a.getElementsByTagName("href")[0];e&&(n=e.innerHTML.trim())}}let o=a.getElementsByTagName("LineStyle")[0];if(o){let e=o.getElementsByTagName("color")[0];e&&(r=this._AGBRtoRGBA(e.innerHTML.trim()));let t=o.getElementsByTagName("width")[0];void 0!==t&&(s=parseFloat(t.innerHTML.trim()))}}return t||(t="#FFFFFF"),i||(i=0),n||(n="https://openglobus.org/examples/billboards/carrot.png"),r||(r="#FFFFFF"),s||(s=1),{iconHeading:i,iconURL:n,iconColor:t,lineWidth:s,lineColor:r}}_parseKML(e,t,i){if(i||(i=[]),"kml"!==e.documentElement.nodeName)return i;for(const n of e.getElementsByTagName("Placemark")){const e=this._kmlPlacemarkToEntity(n,t);e&&i.push(e)}return i}_convertKMLintoEntities(e){const t=new ie(new z(180,90),new z(-180,-90));return{entities:this._parseKML(e,t),extent:t}}_convertCoordonatesIntoEntities(e,t,i){const n=new ie(new z(180,90),new z(-180,-90)),r=e=>{const t=e[0],i=e[1];t<n.southWest.lon&&(n.southWest.lon=t),i<n.southWest.lat&&(n.southWest.lat=i),t>n.northEast.lon&&(n.northEast.lon=t),i>n.northEast.lat&&(n.northEast.lat=i)},s=[];e.forEach((e=>e.forEach((e=>s.push(e)))));return{entities:s.map((e=>{if(1===e.length){const t=e[0],n=new Ai({lonlat:t,billboard:i});return r(t),n}if(e.length>1){const i=e.map((e=>(r(e),new z(e[0],e[1],e[2]))));return new Ai({polyline:{pathLonLat:[i],thickness:3,color:t,isClosed:!1}})}})),extent:n}}_getXmlContent(e){return new Promise((t=>{const i=new FileReader;i.onload=async e=>t((new DOMParser).parseFromString(e.target.result,"text/xml")),i.readAsText(e)}))}_expandExtents(e,t){return e?(t.southWest.lon<e.southWest.lon&&(e.southWest.lon=t.southWest.lon),t.southWest.lat<e.southWest.lat&&(e.southWest.lat=t.southWest.lat),t.northEast.lon>e.northEast.lon&&(e.northEast.lon=t.northEast.lon),t.northEast.lat>e.northEast.lat&&(e.northEast.lat=t.northEast.lat),e):t}async addKmlFromFiles(e,t,i){if(!Array.isArray(e))return null;const n=(await Promise.all(e.map(this._getXmlContent))).map(this._extractCoordonatesFromKml),{entities:r,extent:s}=this._convertCoordonatesIntoEntities(n,t||this._color,i||this._billboard);return this._extent=this._expandExtents(this._extent,s),r.forEach(this.add.bind(this)),{entities:r,extent:s}}setColor(e){this._color=e,this._billboard.color=e}_getKmlFromUrl(e){return new Promise(((t,i)=>{const n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="document",n.overrideMimeType("text/xml"),n.onload=()=>{n.readyState===n.DONE&&200===n.status?t(n.responseXML):i(new Error("no valid kml file"))},n.send()}))}async addKmlFromUrl(e,t,i){const n=await this._getKmlFromUrl(e),{entities:r,extent:s}=this._convertKMLintoEntities(n);return this._extent=this._expandExtents(this._extent,s),r.forEach(this.add.bind(this)),{entities:r,extent:s}}}class xo extends no{constructor(e,t={}){super(e||"OpenStreetMap",{iconSrc:"https://tile.openstreetmap.org/8/138/95.png",url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",attribution:"Data @ OpenStreetMap contributors, ODbL",isBaseLayer:!0,maxNativeZoom:19,defaultTextures:[{color:"#AAD3DF"},{color:"#F2EFE9"}],isSRGB:!1,shininess:18,specular:[63e-5,55e-5,32e-5],ambient:[.2,.2,.3],diffuse:[.9,.9,.7],...t})}}function bo(e,t,i){var n="";for(let a=i;a>0;a--){var r=0,s=1<<a-1;e&s&&r++,t&s&&(r+=2),n+=r.toString()}return n}class wo extends no{constructor(e,t={}){super(e||"Bing",{iconSrc:"https://ecn.t0.tiles.virtualearth.net/tiles/a120.jpeg?n=z&g=7146",subdomains:["t0","t1","t2","t3"],url:"https://ecn.{s}.tiles.virtualearth.net/tiles/a{quad}.jpeg?n=z&g=7146",isBaseLayer:!0,maxNativeZoom:17,defaultTextures:[{color:"#001522"},{color:"#E4E6F3"}],attribution:'<div style="transform: scale(0.8); margin-top:-2px;"><a href="https://www.bing.com" target="_blank"><img style="position: relative; top: 2px;" title="Bing Imagery" src="https://sandcastle.cesium.com/CesiumUnminified/Assets/Images/bing_maps_credit.png"></a> © 2021 Microsoft Corporation</div>',urlRewrite:(e,t)=>be(t,{s:this._getSubdomain(),quad:bo(e.tileX,e.tileY,e.tileZoom)}),specular:[63e-5,55e-5,32e-5],ambient:"rgb(90,90,90)",diffuse:"rgb(350,350,350)",shininess:20,nightTextureCoefficient:2.7,...t})}}var Co=Object.freeze({__proto__:null,Bing:wo,CanvasTiles:Zt,GeoImage:po,GeoTexture2d:mo,GeoVideo:vo,KML:yo,LAYER_EVENTS:Xt,Layer:qt,Material:jt,OpenStreetMap:xo,Vector:In,WMS:so,XYZ:no});const To=["tick","end","start","stop"];class Lo{constructor(e={}){this.__handler=null,this.active=!0,this.__id=Lo.__counter__++,this.events=Pt(To,this),this.name=e.name||"",this.startDate=e.startDate||0,this.endDate=e.endDate||0;let t=e.currentDate||gt(new Date);e.startDate&&t<e.startDate&&(t=e.startDate),e.endDate&&t>e.endDate&&(t=e.endDate),this.currentDate=t,this._multiplier=void 0!==e.multiplier?e.multiplier:1,this._running=1,this.deltaTicks=0,this.active=!0,this._intervalDelay=0,this._intervalStart=0,this._intervalCallback=null}clearInterval(){this._intervalDelay=0,this._intervalStart=0,this._intervalCallback=null}setInterval(e,t){this._intervalStart=this.currentDate,this._intervalDelay=e*dt,this._intervalCallback=t}setDate(e){let t=gt(e);this.startDate&&t<this.startDate&&(t=this.startDate),this.endDate&&t>this.endDate&&(t=this.endDate),this.currentDate=t}getDate(){return vt(this.currentDate)}reset(){this.startDate&&(this.currentDate=this.startDate)}tick(e){let t=this._multiplier*this._running;if(this.deltaTicks=e*t,this.active){let e=yt(this.currentDate,this.deltaTicks);t>0?this.endDate&&e>this.endDate?(this.currentDate=this.startDate,this.events.dispatch(this.events.end,this)):this.currentDate=e:this.startDate&&e<this.startDate?(this.currentDate=this.endDate,this.events.dispatch(this.events.end,this)):this.currentDate=e,this._intervalCallback&&this.currentDate-this._intervalStart>=this._intervalDelay&&(this._intervalStart=this.currentDate,this._intervalCallback(this)),this.events.dispatch(this.events.tick,this)}}isEqual(e){return this.__id===e.__id}start(){0===this._running&&(this._running=1,this.events.dispatch(this.events.start,this))}get multiplier(){return this._multiplier}set multiplier(e){this._multiplier=e}stop(){1===this._running&&(this._running=0,this.events.dispatch(this.events.stop,this))}}Lo.__counter__=0;class Ao{constructor(e,t){this._program=t,this._handler=e,this._activated=!1}initialize(){this._handler.gl&&this._program.createProgram(this._handler.gl)}getProgram(){return this._program}activate(){if(!this._activated){this._handler.activeProgram.deactivate(),this._handler.activeProgram=this;let e=this._program;this._activated=!0,e.enableAttribArrays(),e.use()}return this}remove(){let e=this._handler.programs;e[this._program.name]&&(this._activated&&this.deactivate(),this._program.delete(),delete e[this._program.name])}deactivate(){this._program.disableAttribArrays(),this._activated=!1}isActive(){return this._activated}set(e){return this.activate(),this._program.set(e),this}drawIndexBuffer(e,t){return this._program.drawIndexBuffer(e,t),this}drawArrays(e,t){return this._program.drawArrays(e,t),this}}class Eo{constructor(){this.next=null,this.prev=null,this.data=null}}class Po{constructor(e=256){this._current=new Eo,this._head=this._current;for(let t=0;t<e;t++){let e=new Eo;e.prev=this._current,this._current.next=e,this._current=e}this._current=this._head}current(){return this._current}push(e){this._current=this._current.next,this._current.data=e}pop(){let e=this._current.data;return this._current=this._current.prev,e}popPrev(){return this._current=this._current.prev,this._current.data}}const So=["","WEBKIT_","MOZ_"],Mo=["webgl2","webgl"];class Bo{constructor(e,t={}){this.framebufferStack=new Po,this._requestAnimationFrameId=0,this.drawFrame=()=>{let e=window.performance.now();this.deltaTime=e-this._lastAnimationFrameTime,this._lastAnimationFrameTime=e,this.defaultClock.tick(this.deltaTime);for(let e=0;e<this._clocks.length;e++)this._clocks[e].tick(this.deltaTime);let t=this.canvas;Math.floor(t.clientWidth*this._params.pixelRatio)===t.width&&Math.floor(t.clientHeight*this._params.pixelRatio)===t.height||(0===t.clientWidth||0===t.clientHeight?this.stop():document.hidden||(this.start(),this.setSize(t.clientWidth,t.clientHeight))),this._frameCallback()},this.events=Pt(["visibilitychange","resize"]),this._throttledDrawFrame=this.drawFrame,this.defaultClock=new Lo,this._clocks=[],this.deltaTime=0,this.canvas=null,this.gl=null,this.programs={},this.activeProgram=null,this._canvasSize=[0,0],this._params={anisotropy:t.anisotropy||4,width:t.width||256,height:t.height||256,pixelRatio:Ke("og_dpi")||t.pixelRatio||1,extensions:t.extensions||[],context:t.context||{}},this._oneByHeight=1/(this._params.height*this._params.pixelRatio),this.extensions={},this._canvasTarget=e,this._lastAnimationFrameTime=0,this._initialized=!1,this._frameCallback=function(){},this.transparentTexture=null,this.defaultTexture=null,this.framebufferStack=new Po,this.createTexture_n=this.createTexture_n_webgl2.bind(this),this.createTexture_l=this.createTexture_l_webgl2.bind(this),this.createTexture_mm=this.createTexture_mm_webgl2.bind(this),this.createTexture_a=this.createTexture_a_webgl2.bind(this),this.createTexture={NEAREST:this.createTexture_n,LINEAR:this.createTexture_l,MIPMAP:this.createTexture_mm,ANISOTROPIC:this.createTexture_a},this.createTextureDefault=this.createTexture_n,this.ONCANVASRESIZE=null,this._createCanvas(),(t.autoActivate||de(t.autoActivate))&&this.initialize()}set frameDelay(e){this._throttledDrawFrame=0===e?this.drawFrame:Fe(this.drawFrame,e)}isInitialized(){return this._initialized}_createCanvas(){this._canvasTarget?this._canvasTarget instanceof HTMLElement?this.canvas=this._canvasTarget:this.canvas=document.getElementById(this._canvasTarget)||document.querySelector(this._canvasTarget):(this.canvas=document.createElement("canvas"),this.canvas.width=this._params.width,this.canvas.height=this._params.height)}static getExtension(e,t){if(!e)return;let i,n;for(i in So)if(n=e.getExtension(So[i]+t),n)return n}static getContext(e,t){let i=null;try{let n=new URLSearchParams(location.search).get("og_ver");if(n)i=e.getContext(n,t),i&&(i.type=n);else for(let n=0;n<Mo.length;n++)if(i=e.getContext(Mo[n],t),i){i.type=Mo[n];break}}catch(e){Si.logErr("exception during the GL context initialization")}return i||Si.logErr("could not initialise WebGL"),i}setFrameCallback(e){e&&(this._frameCallback=e)}createEmptyTexture2DExt(e=1,t=1,i="NEAREST",n="RGBA",r="RGBA",s="UNSIGNED_BYTE",a=0){let o=this.gl,l=o.createTexture();return o.bindTexture(o.TEXTURE_2D,l),o.texImage2D(o.TEXTURE_2D,a,o[n.toUpperCase()],e,t,0,o[r.toUpperCase()],o[s.toUpperCase()],null),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o[i.toUpperCase()]),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o[i.toUpperCase()]),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.bindTexture(o.TEXTURE_2D,null),l}createEmptyTexture_n(e,t,i){let n=this.gl,r=n.createTexture();return n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,i||n.RGBA,e,t,0,n.RGBA,n.UNSIGNED_BYTE,null),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),r}createEmptyTexture_l(e,t,i){let n=this.gl,r=n.createTexture();return n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,i||n.RGBA,e,t,0,n.RGBA,n.UNSIGNED_BYTE,null),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),r}createTexture_n_webgl1(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_l_webgl1(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_mm_webgl1(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_a_webgl1(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameterf(n.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_n_webgl2(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texStorage2D(n.TEXTURE_2D,1,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_l_webgl2(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texStorage2D(n.TEXTURE_2D,1,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_mm_webgl2(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texStorage2D(n.TEXTURE_2D,2,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}createTexture_a_webgl2(e,t,i=null){let n=this.gl;return i=i||n.createTexture(),n.bindTexture(n.TEXTURE_2D,i),n.texStorage2D(n.TEXTURE_2D,2,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameterf(n.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),i}loadCubeMapTexture(e){let t=this.gl,i=t.createTexture();t.bindTexture(t.TEXTURE_CUBE_MAP,i),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,t.LINEAR);let n=[[e.px,t.TEXTURE_CUBE_MAP_POSITIVE_X],[e.nx,t.TEXTURE_CUBE_MAP_NEGATIVE_X],[e.py,t.TEXTURE_CUBE_MAP_POSITIVE_Y],[e.ny,t.TEXTURE_CUBE_MAP_NEGATIVE_Y],[e.pz,t.TEXTURE_CUBE_MAP_POSITIVE_Z],[e.nz,t.TEXTURE_CUBE_MAP_NEGATIVE_Z]],r=new Xs;r.fillEmpty();let s=r.getImage();for(let e=0;e<n.length;e++){let r=n[e][1];t.bindTexture(t.TEXTURE_CUBE_MAP,i),t.texImage2D(r,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,s)}for(let e=0;e<n.length;e++){let r=n[e][1],s=new Image;s.crossOrigin="",s.onload=function(e,i,n){return function(){t&&e&&(t.bindTexture(t.TEXTURE_CUBE_MAP,e),t.texImage2D(i,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,n))}}(i,r,s),s.src=n[e][0]}return i}addProgram(e,t=!1){if(this.programs[e.name])console.warn(`Shader program: "${e.name}" already exists.`);else{let i=new Ao(this,e);this.programs[e.name]=i,this._initProgramController(i),t&&(i._activated=!1)}return e}removeProgram(e){this.programs[e]&&this.programs[e].remove()}addPrograms(e){for(let t=0;t<e.length;t++)this.addProgram(e[t])}_initProgramController(e){this._initialized&&(e.initialize(),this.activeProgram?(e.deactivate(),this.activeProgram._program.enableAttribArrays(),this.activeProgram._program.use()):(this.activeProgram=e,e.activate()))}_initPrograms(){for(let e in this.programs)this._initProgramController(this.programs[e])}initializeExtension(e,t=!1){if(!this.extensions||!this.extensions[e]){let i=Bo.getExtension(this.gl,e);i?this.extensions[e]=i:t&&console.warn("og.webgl.Handler: extension '"+e+"' doesn't initialize.")}return this.extensions&&this.extensions[e]}initialize(){if(this._initialized)return;if(!this.canvas)return;if(this.gl=Bo.getContext(this.canvas,this._params.context),!this.gl)return;this._initialized=!0,this._params.extensions.push("EXT_texture_filter_anisotropic"),"webgl"===this.gl.type?(this._params.extensions.push("OES_standard_derivatives"),this._params.extensions.push("OES_element_index_uint"),this._params.extensions.push("WEBGL_depth_texture"),this._params.extensions.push("ANGLE_instanced_arrays")):(this._params.extensions.push("EXT_color_buffer_float"),this._params.extensions.push("OES_texture_float_linear"));let e=this._params.extensions.length;for(;e--;)this.initializeExtension(this._params.extensions[e],!0);"webgl"===this.gl.type?(this.createTexture_n=this.createTexture_n_webgl1.bind(this),this.createTexture_l=this.createTexture_l_webgl1.bind(this),this.createTexture_mm=this.createTexture_mm_webgl1.bind(this),this.createTexture_a=this.createTexture_a_webgl1.bind(this)):(this.createTexture_n=this.createTexture_n_webgl2.bind(this),this.createTexture_l=this.createTexture_l_webgl2.bind(this),this.createTexture_mm=this.createTexture_mm_webgl2.bind(this),this.createTexture_a=this.createTexture_a_webgl2.bind(this)),this.createTexture.NEAREST=this.createTexture_n,this.createTexture.LINEAR=this.createTexture_l,this.createTexture.MIPMAP=this.createTexture_mm,this.createTexture.ANISOTROPIC=this.createTexture_a,this.extensions.EXT_texture_filter_anisotropic?this.createTextureDefault=this.createTexture_a:this.createTextureDefault=this.createTexture_mm,this._initPrograms(),this._setDefaults(),this.intersectionObserver=new IntersectionObserver((e=>{this._toggleVisibilityChange(e[0].isIntersecting)}),{threshold:0}),this.intersectionObserver.observe(this.canvas),this.resizeObserver=new ResizeObserver((e=>{this._toggleVisibilityChange(0!==e[0].contentRect.width&&0!==e[0].contentRect.height)})),this.resizeObserver.observe(this.canvas),document.addEventListener("visibilitychange",(()=>{this._toggleVisibilityChange("visible"===document.visibilityState)}))}_toggleVisibilityChange(e){e?(this.start(),this.ONCANVASRESIZE&&this.ONCANVASRESIZE(),this.events.dispatch(this.events.visibilitychange,!0)):(this.events.dispatch(this.events.visibilitychange,!1),this.stop())}_setDefaults(){let e=this.gl;e&&this.canvas&&(e.depthFunc(e.LESS),e.enable(e.DEPTH_TEST),this.setSize(this.canvas.clientWidth||this._params.width,this.canvas.clientHeight||this._params.height),e.frontFace(e.CCW),e.cullFace(e.BACK),e.enable(e.CULL_FACE),e.disable(e.BLEND),this.createDefaultTexture({color:"rgba(0,0,0,0.0)"},(e=>{this.transparentTexture=e})),this.createDefaultTexture({color:"rgba(255, 255, 255, 1.0)"},(e=>{this.defaultTexture=e})))}getCanvasSize(){return this._canvasSize}createStreamArrayBuffer(e,t,i,n=4){let r=this.gl,s=r.createBuffer();return r.bindBuffer(r.ARRAY_BUFFER,s),r.bufferData(r.ARRAY_BUFFER,t*e*n,i||r.STREAM_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),s.itemSize=e,s.numItems=t,s}setStreamArrayBuffer(e,t,i=0){let n=this.gl;return n.bindBuffer(n.ARRAY_BUFFER,e),n.bufferSubData(n.ARRAY_BUFFER,i,t),n.bindBuffer(n.ARRAY_BUFFER,null),e}createArrayBuffer(e,t,i,n){let r=this.gl,s=r.createBuffer();return r.bindBuffer(r.ARRAY_BUFFER,s),r.bufferData(r.ARRAY_BUFFER,e,n||r.STATIC_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),s.itemSize=t,s.numItems=i,s}createArrayBufferLength(e,t){let i=this.gl,n=i.createBuffer();return i.bindBuffer(i.ARRAY_BUFFER,n),i.bufferData(i.ARRAY_BUFFER,e,t||i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),n.itemSize=1,n.numItems=e,n}createElementArrayBuffer(e,t,i,n){let r=this.gl,s=r.createBuffer();return r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,s),r.bufferData(r.ELEMENT_ARRAY_BUFFER,e,n||r.STATIC_DRAW),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,null),s.itemSize=t,s.numItems=i||e.length,s}setSize(e,t){this._params.width=e,this._params.height=t,this.canvas&&(this.canvas.width=e*this._params.pixelRatio,this.canvas.height=t*this._params.pixelRatio,this._canvasSize[0]=this.canvas.width,this._canvasSize[1]=this.canvas.height,this._oneByHeight=1/this.canvas.height,this.gl&&this.gl.viewport(0,0,e,t),this.ONCANVASRESIZE&&this.ONCANVASRESIZE(this.canvas),this.events.dispatch(this.events.resize,this))}get pixelRatio(){return this._params.pixelRatio}set pixelRatio(e){this._params.pixelRatio=e,this.setSize(this._params.width,this._params.height)}getWidth(){return this.canvas?this.canvas.width:0}getHeight(){return this.canvas?this.canvas.height:0}getClientAspect(){return this.canvas?this.canvas.clientWidth/this.canvas.clientHeight:0}getCenter(){let e=this.canvas;return e?new le(Math.round(.5*e.width),Math.round(.5*e.height)):new le}clearFrame(){let e=this.gl;e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}start(){!this._requestAnimationFrameId&&this._initialized&&this._animationFrameCallback()}stop(){this._requestAnimationFrameId&&(window.cancelAnimationFrame(this._requestAnimationFrameId),this._requestAnimationFrameId=0)}isStopped(){return!this._requestAnimationFrameId}isWebGl2(){return!!this.gl&&"webgl2"===this.gl.type}_animationFrameCallback(){this._requestAnimationFrameId=window.requestAnimationFrame((()=>{this._throttledDrawFrame(),this._requestAnimationFrameId&&this._animationFrameCallback()}))}createDefaultTexture(e,t){let i,n;if(e&&e.color)i=new Xs(2,2),i.fillColor(e.color),n=this.createTexture_n(i.getCanvas()),n.default=!0,t(n);else if(e&&e.url){let i=new Image,r=this;i.onload=function(){n=r.createTextureDefault(i),n.default=!0,t(n)},i.src=e.url}else i=new Xs(2,2),i.fillColor("#C5C5C5"),n=this.createTexture_n(i.getCanvas()),n.default=!0,t(n)}deleteTexture(e){e&&!e.default&&this.gl.deleteTexture(e)}destroy(){this.resizeObserver?.disconnect(),this.intersectionObserver?.disconnect(),this.stop();for(let e in this.programs)this.removeProgram(e);let e=this.gl;if(e){e.deleteTexture(this.transparentTexture),this.transparentTexture=null,e.deleteTexture(this.defaultTexture),this.defaultTexture=null,this.framebufferStack=new Po;let t=e.getParameter(e.MAX_VERTEX_ATTRIBS),i=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,i);for(let i=0;i<t;++i)e.disableVertexAttribArray(i),e.vertexAttribPointer(i,4,e.FLOAT,!1,0,0),e.vertexAttrib1f(i,0);e.deleteBuffer(i);let n=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS);for(let t=0;t<n;++t)e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_CUBE_MAP,null),e.bindTexture(e.TEXTURE_2D,null);e.activeTexture(e.TEXTURE0),e.useProgram(null),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindRenderbuffer(e.RENDERBUFFER,null),e.disable(e.BLEND),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.DITHER),e.disable(e.SCISSOR_TEST),e.blendColor(0,0,0,0),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ZERO),e.clearColor(0,0,0,0),e.clearDepth(1),e.clearStencil(-1)}this.canvas&&(this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.canvas.width=1,this.canvas.height=1,this.canvas=null),this.gl=null,this._initialized=!1}addClock(e){e.__handler||(e.__handler=this,this._clocks.push(e))}addClocks(e){for(let t=0;t<e.length;t++)this.addClock(e[t])}removeClock(e){if(e.__handler){let t=this._clocks,i=t.length;for(;i--;)if(t[i].isEqual(e)){e.__handler=null,t.splice(i,1);break}}}}class ko extends qs{constructor(e,t={}){super(e,t),this._internalFormat=t.internalFormat?t.internalFormat.toUpperCase():"RGBA8",this._msaa=null!=t.msaa?t.msaa:4,this._glFilter=0,this.renderbuffers=new Array(this._size)}destroy(){let e=this.handler.gl;if(e){for(let t=0;t<this.renderbuffers.length;t++)e.deleteRenderbuffer(this.renderbuffers[t]);this.renderbuffers=new Array(this._size),e.deleteFramebuffer(this._fbo),e.deleteRenderbuffer(this._depthRenderbuffer),this._depthRenderbuffer=null,this._fbo=null,this._active=!1}}init(){let e=this.handler.gl;if(!e)return;this._glFilter=e[this._filter],this._fbo=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo);let t=[];for(let i=0;i<this.renderbuffers.length;i++){let n=e.createRenderbuffer();e.bindRenderbuffer(e.RENDERBUFFER,n),this._msaa>0?e.renderbufferStorageMultisample(e.RENDERBUFFER,this._msaa,e[this._internalFormat],this._width,this._height):e.renderbufferStorage(e.RENDERBUFFER,e[this._internalFormat],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+i,e.RENDERBUFFER,n),t.push(e.COLOR_ATTACHMENT0+i),this.renderbuffers[i]=n,e.bindRenderbuffer(e.RENDERBUFFER,null)}e.drawBuffers(t),this._useDepth&&(this._depthRenderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this._depthRenderbuffer),e.renderbufferStorageMultisample(e.RENDERBUFFER,this._msaa,e[this._depthComponent],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,this._depthRenderbuffer),e.bindRenderbuffer(e.RENDERBUFFER,null)),e.bindFramebuffer(e.FRAMEBUFFER,null)}blitTo(e,t=0){let i=this.handler.gl;i.bindFramebuffer(i.READ_FRAMEBUFFER,this._fbo),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,e._fbo),i.readBuffer(i.COLOR_ATTACHMENT0+t),i.clearBufferfv(i.COLOR,0,[0,0,0,1]),i.blitFramebuffer(0,0,this._width,this._height,0,0,e._width,e._height,i.COLOR_BUFFER_BIT,this._glFilter),i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindFramebuffer(i.READ_FRAMEBUFFER,null),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,null)}}var Ro=Object.freeze({__proto__:null,Framebuffer:$s,Handler:Bo,Multisample:ko,Program:zi,types:Bi});const Io=function(e,t){return Number(e.priority<t.priority)};class zo{constructor(){this._currentlyPressedKeys={},this._pressedKeysCallbacks={},this._unpressedKeysCallbacks={},this._charkeysCallbacks={},this._anykeyCallback=null,this._event=null,this._active=!0,this._stampCache={},document.onkeydown=e=>{this._event=e,this._active&&this.handleKeyDown()},document.onkeyup=e=>{this._event=e,this._active&&this.handleKeyUp()}}getcurrentlyPressedKeys(){return this._currentlyPressedKeys}getPressedKeysCallbacks(){return this._pressedKeysCallbacks}getUnpressedKeysCallbacks(){return this._unpressedKeysCallbacks}getCharkeysCallbacks(){return this._charkeysCallbacks}removeEvent(e,t,i){let n=this._getStamp(e,t,i._openglobus_id);i._openglobus_id&&this._stampCache[n]&&(delete this._stampCache[n],"keypress"===e?this._removeCallback(this._pressedKeysCallbacks[t],i):"keyfree"===e?this._removeCallback(this._unpressedKeysCallbacks[t],i):"charkeypress"===e&&this._removeCallback(this._charkeysCallbacks[t],i))}_removeCallback(e,t){for(let i=0;i<e.length;i++)e[i].callback._openglobus_id===t._openglobus_id&&e.splice(i,1)}_getStamp(e,t,i){return`${e}_${t}_${i}`}_stamp(e,t,i){const n=fe(i),r=this._getStamp(e,t,n);return!this._stampCache[r]&&(this._stampCache[r]=n,!0)}setActivity(e){this._active=e}releaseKeys(){this._currentlyPressedKeys={}}addEvent(e,t,i,n,r){if(this._stamp(e,t,i))switch(void 0===r&&(r=1600),e){case"keyfree":this._unpressedKeysCallbacks[t]||(this._unpressedKeysCallbacks[t]=[]),this._unpressedKeysCallbacks[t].push({callback:i,sender:n,priority:r}),this._unpressedKeysCallbacks[t].sort(Io);break;case"keypress":null==t?this._anykeyCallback={callback:i,sender:n||this}:(this._pressedKeysCallbacks[t]||(this._pressedKeysCallbacks[t]=[]),this._pressedKeysCallbacks[t].push({callback:i,sender:n,priority:r}),this._pressedKeysCallbacks[t].sort(Io));break;case"charkeypress":this._charkeysCallbacks[t]||(this._charkeysCallbacks[t]=[]),this._charkeysCallbacks[t].push({callback:i,sender:n,priority:r}),this._charkeysCallbacks[t].sort(Io)}}isKeyPressed(e){return this._currentlyPressedKeys[e]}handleKeyDown(){this._anykeyCallback&&this._anykeyCallback.callback.call(this._anykeyCallback.sender,this._event),this._currentlyPressedKeys[this._event.keyCode]=!0;for(let e in this._charkeysCallbacks)if(String.fromCharCode(this._event.keyCode)===String.fromCharCode(Number(e))){let t=this._charkeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}this._event.keyCode!=dr.KEY_ALT&&this._event.keyCode!=dr.KEY_SHIFT||this._event.preventDefault()}handleKeyUp(){if(this._currentlyPressedKeys[this._event.keyCode]||this._event.keyCode===dr.KEY_PRINTSCREEN)for(let e in this._unpressedKeysCallbacks)if(this._currentlyPressedKeys[e]||this._event.keyCode===dr.KEY_PRINTSCREEN&&Number(e)===dr.KEY_PRINTSCREEN){let t=this._unpressedKeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}this._currentlyPressedKeys[this._event.keyCode]=!1}handleEvents(){for(let e in this._pressedKeysCallbacks)if(this._currentlyPressedKeys[e]){let t=this._pressedKeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}}}class Do{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"mousewheel":this._htmlObject.addEventListener("wheel",(function(e){let n=e.deltaY||e.detail||e.wheelDelta||0;null==e.wheelDelta&&(e.wheelDelta=-120*n),i.call(t,e),e.preventDefault()}),!1);break;case"mousedown":this._htmlObject.addEventListener("mousedown",(function(e){let n=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-n.left,clientY:e.clientY-n.top})})),this._htmlObject.addEventListener("contextmenu",(function(e){return e.preventDefault(),!1}));break;case"mouseup":this._htmlObject.addEventListener("mouseup",(function(e){let n=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-n.left,clientY:e.clientY-n.top})}));break;case"mousemove":this._htmlObject.addEventListener("mousemove",(function(e){let n=this.getBoundingClientRect();i.call(t,e,{clientX:e.clientX-n.left,clientY:e.clientY-n.top})}));break;case"mouseleave":this._htmlObject.addEventListener("mouseleave",(function(e){i.call(t,e)}));break;case"mouseout":this._htmlObject.addEventListener("mouseout",(function(e){i.call(t,e)}));break;case"mouseover":this._htmlObject.addEventListener("mouseover",(function(e){i.call(t,e)}));break;case"mouseenter":this._htmlObject.addEventListener("mouseenter",(function(e){i.call(t,e)}))}}}class Fo{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"touchcancel":this._htmlObject.addEventListener("touchcancel",(function(e){e.preventDefault();const n=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:n.left,offsetTop:n.top});i.call(t,r)}));break;case"touchstart":this._htmlObject.addEventListener("touchstart",(function(e){e.preventDefault();const n=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:n.left,offsetTop:n.top});i.call(t,r)}));break;case"touchend":this._htmlObject.addEventListener("touchend",(function(e){e.preventDefault();const n=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:n.left,offsetTop:n.top});i.call(t,r)}));break;case"touchmove":this._htmlObject.addEventListener("touchmove",(function(e){e.preventDefault();const n=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:n.left,offsetTop:n.top});i.call(t,r)}))}}}let No=new Uint8Array(4),Ho=new Uint8Array(4),Oo=new Uint8Array(4);class Vo extends St{constructor(e){super(Uo),this.renderer=e,this._touchHandler=new Fo(e.handler.canvas),this._mouseHandler=new Do(e.handler.canvas),this._keyboardHandler=new zo,this._active=!0,this.clickRadius=15,this.mouseState={clientX:0,clientY:0,pos:new le,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new oe,leftButtonUp:!1,rightButtonUp:!1,middleButtonUp:!1,leftButtonDown:!1,rightButtonDown:!1,middleButtonDown:!1,leftButtonHold:!1,rightButtonHold:!1,middleButtonHold:!1,leftButtonDoubleClick:!1,rightButtonDoubleClick:!1,middleButtonDoubleClick:!1,leftButtonClick:!1,rightButtonClick:!1,middleButtonClick:!1,moving:!1,justStopped:!1,doubleClickDelay:500,clickDelay:200,wheelDelta:0,sys:null,pickingObject:null,renderer:e},this.touchState={moving:!1,touchEnd:!1,touchStart:!1,touchCancel:!1,doubleTouch:!1,doubleTouchDelay:550,doubleTouchRadius:10,clientX:0,clientY:0,pos:new le,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new oe,sys:null,pickingObject:null,renderer:e},this._isMouseInside=!1,this._entityPickingEventsActive=!0,this._dblTchCoords=new le,this._oneTouchStart=!1,this._dblTchBegins=0,this._mousestopThread=null,this._ldblClkBegins=0,this._rdblClkBegins=0,this._mdblClkBegins=0,this._lClkBegins=0,this._rClkBegins=0,this._mClkBegins=0,this._lclickX=0,this._lclickY=0,this._rclickX=0,this._rclickY=0,this._mclickX=0,this._mclickY=0}pointerEvent(){let e=this.mouseState,t=this.touchState;return e.moving||e.justStopped||t.moving||t.touchStart||t.touchEnd||0!==e.wheelDelta}get active(){return this._active}set active(e){this._active=e,this._keyboardHandler.setActivity(e)}handleEvents(){this._active&&(this.mouseState.direction=this.renderer.activeCamera.unproject(this.mouseState.x,this.mouseState.y),this.touchState.direction=this.renderer.activeCamera.unproject(this.touchState.x,this.touchState.y),this._keyboardHandler.handleEvents(),this.handleMouseEvents(),this.handleTouchEvents(),this.entityPickingEvents())}on(e,t,i,n,r){"keypress"===e||"charkeypress"===e||"keyfree"===e?this._keyboardHandler.addEvent(e,t,i,n,r):super.on(e,t,i,n)}off(e,t,i){"keypress"===e||"charkeypress"===e||"keyfree"===e?this._keyboardHandler.removeEvent(e,t,i):super.off(e,t)}isKeyPressed(e){return this._keyboardHandler.isKeyPressed(e)}releaseKeys(){this._keyboardHandler.releaseKeys()}initialize(){this._mouseHandler.setEvent("mouseup",this,this.onMouseUp),this._mouseHandler.setEvent("mousemove",this,this.onMouseMove),this._mouseHandler.setEvent("mousedown",this,this.onMouseDown),this._mouseHandler.setEvent("mousewheel",this,this.onMouseWheel),this._mouseHandler.setEvent("mouseleave",this,this.onMouseLeave),this._mouseHandler.setEvent("mouseenter",this,this.onMouseEnter),this._touchHandler.setEvent("touchstart",this,this.onTouchStart),this._touchHandler.setEvent("touchend",this,this.onTouchEnd),this._touchHandler.setEvent("touchcancel",this,this.onTouchCancel),this._touchHandler.setEvent("touchmove",this,this.onTouchMove)}onMouseWheel(e){this.mouseState.sys=e,this.mouseState.wheelDelta=e.wheelDelta||0}updateButtonsStates(e){let t=this.mouseState;1&e&&t.leftButtonDown?t.leftButtonDown=!0:(t.leftButtonHold=!1,t.leftButtonDown=!1),2&e&&t.rightButtonDown?t.rightButtonDown=!0:(t.rightButtonHold=!1,t.rightButtonDown=!1),4&e&&t.middleButtonDown?t.middleButtonDown=!0:(t.middleButtonHold=!1,t.middleButtonDown=!1)}onMouseMove(e,t){let i=this.mouseState;this.updateButtonsStates(e.buttons),i.sys=e;let n=t.clientX,r=t.clientY,s=this.clickRadius;if(Math.abs(this._lclickX-n)>=s&&Math.abs(this._lclickY-r)>=s&&(this._ldblClkBegins=0,this._lClkBegins=0),Math.abs(this._rclickX-n)>=s&&Math.abs(this._rclickY-r)>=s&&(this._rdblClkBegins=0,this._rClkBegins=0),Math.abs(this._mclickX-n)>=s&&Math.abs(this._mclickY-r)>=s&&(this._mdblClkBegins=0,this._mClkBegins=0),i.clientX===t.clientX&&i.clientY===t.clientY)return;i.clientX=t.clientX,i.clientY=t.clientY;let a=this.renderer.handler;i.pos.x=i.x=t.clientX*a.pixelRatio,i.pos.y=i.y=t.clientY*a.pixelRatio,i.nx=i.x/a.canvas.width,i.ny=i.y/a.canvas.height,i.moving=!0,clearTimeout(this._mousestopThread),this._mousestopThread=setTimeout((function(){i.justStopped=!0}),100)}onMouseLeave(e){this._isMouseInside=!1,this.mouseState.sys=e,this.dispatch(this.mouseleave,this.mouseState)}onMouseEnter(e){this._isMouseInside=!0,this.mouseState.sys=e,this.dispatch(this.mouseenter,this.mouseState)}onMouseDown(e,t){t.button===dr.MB_LEFT?(this._lClkBegins=window.performance.now(),this._lclickX=t.clientX,this._lclickY=t.clientY,this.mouseState.sys=e,this.mouseState.leftButtonDown=!0):t.button===dr.MB_RIGHT?(this._rClkBegins=window.performance.now(),this._rclickX=t.clientX,this._rclickY=t.clientY,this.mouseState.sys=e,this.mouseState.rightButtonDown=!0):t.button===dr.MB_MIDDLE&&(this._mClkBegins=window.performance.now(),this._mclickX=t.clientX,this._mclickY=t.clientY,this.mouseState.sys=e,this.mouseState.middleButtonDown=!0)}onMouseUp(e,t){let i=this.mouseState;i.sys=e;let n=window.performance.now();if(t.button===dr.MB_LEFT){if(i.leftButtonDown=!1,i.leftButtonUp=!0,Math.abs(this._lclickX-t.clientX)<this.clickRadius&&Math.abs(this._lclickY-t.clientY)<this.clickRadius&&n-this._lClkBegins<=i.clickDelay){if(this._ldblClkBegins){window.performance.now()-this._ldblClkBegins<=i.doubleClickDelay&&(i.leftButtonDoubleClick=!0),this._ldblClkBegins=0}else this._ldblClkBegins=window.performance.now();i.leftButtonClick=!0,this._lClkBegins=0}}else if(t.button===dr.MB_RIGHT){if(i.rightButtonDown=!1,i.rightButtonUp=!0,Math.abs(this._rclickX-t.clientX)<this.clickRadius&&Math.abs(this._rclickY-t.clientY)<this.clickRadius&&n-this._rClkBegins<=i.clickDelay){if(this._rdblClkBegins){window.performance.now()-this._rdblClkBegins<=i.doubleClickDelay&&(i.rightButtonDoubleClick=!0),this._rdblClkBegins=0}else this._rdblClkBegins=window.performance.now();i.rightButtonClick=!0,this._rClkBegins=0}}else if(t.button===dr.MB_MIDDLE&&(i.middleButtonDown=!1,i.middleButtonUp=!0,Math.abs(this._mclickX-t.clientX)<this.clickRadius&&Math.abs(this._mclickY-t.clientY)<this.clickRadius&&n-this._mClkBegins<=i.clickDelay)){if(this._mdblClkBegins){window.performance.now()-this._mdblClkBegins<=i.doubleClickDelay&&(i.middleButtonDoubleClick=!0),this._mdblClkBegins=0}else this._mdblClkBegins=window.performance.now();i.middleButtonClick=!0,this._mClkBegins=0}}onTouchStart(e){let t=this.touchState;t.sys=e,t.clientX=e.touches.item(0).clientX-e.offsetLeft,t.clientY=e.touches.item(0).clientY-e.offsetTop;let i=this.renderer.handler;t.pos.x=t.x=t.clientX*i.pixelRatio,t.pos.y=t.y=t.clientY*i.pixelRatio,t.nx=t.x/i.canvas.width,t.ny=t.y/i.canvas.height,t.prev_x=t.x,t.prev_y=t.y,t.touchStart=!0,1===e.touches.length?(this._dblTchCoords.x=t.x,this._dblTchCoords.y=t.y,this._oneTouchStart=!0):this._oneTouchStart=!1}onTouchEnd(e){let t=this.touchState;if(t.sys=e,t.touchEnd=!0,0===e.touches.length&&(t.prev_x=t.x,t.prev_y=t.y,this._oneTouchStart)){if(this._dblTchBegins){window.performance.now()-this._dblTchBegins<=t.doubleTouchDelay&&(t.doubleTouch=!0),this._dblTchBegins=0}this._dblTchBegins=window.performance.now(),this._oneTouchStart=!1}}onTouchCancel(e){let t=this.touchState;t.sys=e,t.touchCancel=!0}onTouchMove(e){let t=this.touchState;t.clientX=e.touches.item(0).clientX-e.offsetLeft,t.clientY=e.touches.item(0).clientY-e.offsetTop;let i=this.renderer.handler;t.x=t.clientX*i.pixelRatio,t.y=t.clientY*i.pixelRatio,t.nx=t.x/i.canvas.width,t.ny=t.y/i.canvas.height,t.sys=e,t.moving=!0;let n=t.x-t.prev_x,r=t.y-t.prev_y;(Math.abs(n)>9||Math.abs(r)>9)&&(this._dblTchBegins=0,this._oneTouchStart=!1)}entityPickingEvents(){let e=this.touchState,t=this.mouseState;if(this._isMouseInside!==this._entityPickingEventsActive&&(this._entityPickingEventsActive=this._isMouseInside,!this._entityPickingEventsActive)){let i=this.renderer,n=No,r=i.getPickingObjectArr(n);if(r){let i=r.rendererEvents;t.pickingObject=r,i&&i.dispatch(i.mouseleave,t),e.pickingObject=r,i&&i.dispatch(i.touchleave,e)}No[0]=No[1]=No[2]=No[3]=Oo[0]=Oo[1]=Oo[2]=Oo[3]=Ho[0]=Ho[1]=Ho[2]=Ho[3]=0}if(this._isMouseInside&&!(t.leftButtonHold||t.rightButtonHold||t.middleButtonHold)){let i=this.renderer,n=No,r=Oo,s=Ho;e.x||e.y?i.readPickingColor(e.nx,1-e.ny,s):i.readPickingColor(t.nx,1-t.ny,s),r[0]=n[0],r[1]=n[1],r[2]=n[2],n[0]=s[0],n[1]=s[1],n[2]=s[2],t.pickingObject=null,e.pickingObject=null;let a=i.getPickingObjectArr(n);if(t.pickingObject=a,e.pickingObject=a,n[0]!==r[0]||n[1]!==r[1]||n[2]!==r[2])if((e=>!(e[0]||e[1]||e[2]))(n)){let n=i.getPickingObjectArr(r);if(n){let i=n.rendererEvents;t.pickingObject=n,i&&i.dispatch(i.mouseleave,t),e.pickingObject=n,i&&i.dispatch(i.touchleave,e)}}else{if((e=>!!(e[0]||e[1]||e[2]))(r)){let n=i.getPickingObjectArr(r);if(n){let i=n.rendererEvents;t.pickingObject=n,i&&i.dispatch(i.mouseleave,t),e.pickingObject=n,i&&i.dispatch(i.touchleave,e)}}if(a){let i=a.rendererEvents;t.pickingObject=a,i&&i.dispatch(i.mouseenter,t),e.pickingObject=a,i&&i.dispatch(i.touchenter,e)}}}}handleMouseEvents(){let e=this,t=this.mouseState,i=t.pickingObject,n=null;t.leftButtonClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.lclick,t)),this.dispatch(e.lclick,t),t.leftButtonClick=!1),t.rightButtonClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.rclick,t)),this.dispatch(e.rclick,t),t.rightButtonClick=!1),t.middleButtonClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.mclick,t)),this.dispatch(e.mclick,t),t.middleButtonClick=!1),t.leftButtonDown&&(t.leftButtonHold?(i&&(n=i.rendererEvents,n&&n.dispatch(n.lhold,t)),this.dispatch(e.lhold,t)):(t.leftButtonHold=!0,i&&(n=i.rendererEvents,n&&n.dispatch(n.ldown,t)),this.dispatch(e.ldown,t))),t.rightButtonDown&&(t.rightButtonHold?(i&&(n=i.rendererEvents,n&&n.dispatch(n.rhold,t)),this.dispatch(e.rhold,t)):(t.rightButtonHold=!0,i&&(n=i.rendererEvents,n&&n.dispatch(n.rdown,t)),this.dispatch(e.rdown,t))),t.middleButtonDown&&(t.middleButtonHold?(i&&(n=i.rendererEvents,n&&n.dispatch(n.mhold,t)),this.dispatch(e.mhold,t)):(t.middleButtonHold=!0,i&&(n=i.rendererEvents,n&&n.dispatch(n.mdown,t)),this.dispatch(e.mdown,t))),t.leftButtonUp&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.lup,t)),this.dispatch(e.lup,t),t.leftButtonUp=!1,t.leftButtonHold=!1),t.rightButtonUp&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.rup,t)),this.dispatch(e.rup,t),t.rightButtonUp=!1,t.rightButtonHold=!1),t.middleButtonUp&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.mup,t)),this.dispatch(e.mup,t),t.middleButtonUp=!1,t.middleButtonHold=!1),t.leftButtonDoubleClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.ldblclick,t)),this.dispatch(e.ldblclick,t),t.leftButtonDoubleClick=!1),t.rightButtonDoubleClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.rdblclick,t)),this.dispatch(e.rdblclick,t),t.rightButtonDoubleClick=!1),t.middleButtonDoubleClick&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.mdblclick,t)),this.dispatch(e.mdblclick,t),t.middleButtonDoubleClick=!1),t.wheelDelta&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.mousewheel,t)),this.dispatch(e.mousewheel,t)),t.moving&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.mousemove,t)),this.dispatch(e.mousemove,t),t.prev_x=t.x,t.prev_y=t.y),t.justStopped&&this.dispatch(e.mousestop,t)}handleTouchEvents(){let e=this,t=this.touchState,i=t.pickingObject,n=null;if(t.touchCancel&&(this.dispatch(e.touchcancel,t),t.touchCancel=!1),t.touchStart){let r=this.renderer;r.pickingFramebuffer.activate(),r.pickingFramebuffer.readPixels(No,t.nx,1-t.ny,1),r.pickingFramebuffer.deactivate();let s=r.getPickingObjectArr(No);i=t.pickingObject=s,i&&(n=i.rendererEvents,n&&n.dispatch(n.touchstart,t)),this.dispatch(e.touchstart,t),t.touchStart=!1}t.doubleTouch&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.doubletouch,t)),this.dispatch(e.doubletouch,t),t.doubleTouch=!1),t.touchEnd&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.touchend,t)),this.dispatch(e.touchend,t),t.x=0,t.y=0,t.touchEnd=!1),t.moving&&(i&&(n=i.rendererEvents,n&&n.dispatch(n.touchmove,t)),this.dispatch(e.touchmove,t),t.prev_x=t.x,t.prev_y=t.y)}}const Uo=["draw","drawtransparent","postdraw","resize","resizeend","mouseenter","mouseleave","mousemove","mousestop","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchstart","touchend","touchcancel","touchmove","doubletouch","touchleave","touchenter"];class Go{constructor(e=0,t=0,i=0,n=0){this.left=e,this.right=i,this.top=t,this.bottom=n}set(e=0,t=0,i=0,n=0){this.left=e,this.right=i,this.top=t,this.bottom=n}clone(){return new Go(this.left,this.top,this.right,this.bottom)}getWidth(){return Math.abs(this.right-this.left)}getHeight(){return Math.abs(this.bottom-this.top)}getSquare(){return this.getHeight()*this.getWidth()}getDiagonal(){let e=this.getWidth(),t=this.getHeight();return Math.sqrt(t*t+e*e)}fit(e,t){return this.getWidth()===e&&this.getHeight()===t}isInside(e,t){return e>=this.left&&e<=this.right&&t>=this.top&&t<=this.bottom}}class Wo{constructor(){this.imagesCache={},this._counter=0,this._pendingsQueue=new Rn,this._imageIndexCounter=0}load(e,t){if(this.imagesCache[e])t(this.imagesCache[e]);else{let i={src:e,success:t};this._counter>=1?this._pendingsQueue.unshift(i):this._exec(i)}}_exec(e){this._counter++;const t=this;let i=new Image;i.crossOrigin="",i.onload=function(){t.imagesCache[e.src]=i,i.__nodeIndex=t._imageIndexCounter++,e.success(i),t._dequeueRequest()},i.onerror=function(){t._dequeueRequest()},i.src=e.src}_dequeueRequest(){if(this._counter--,this._pendingsQueue.length&&this._counter<1)for(;this._pendingsQueue.length;){let e=this._pendingsQueue.pop();if(e){if(!this.imagesCache[e.src]){this._exec(e);break}this._counter<=0?this._counter=0:this._counter--,e.success(this.imagesCache[e.src])}}}}class jo{constructor(e=1024,t=1024){this.nodes=new Map,this.texture=null,this.canvas=new Xs(e,t),this.clearCanvas(),this._handler=null,this._images=[],this._btree=null,this._imagesCacheManager=new Wo,this.borderSize=4}getImage(){return this.canvas.getImage()}getCanvas(){return this.canvas.getCanvas()}clearCanvas(){this.canvas.fillEmpty()}assignHandler(e){this._handler=e,this.createTexture()}getDiagonal(e){let t=e.atlasWidth||e.width,i=e.atlasHeight||e.height;return Math.sqrt(t*t+i*i)}addImage(e,t=!1){if(e.width&&e.height)return this._images.push(e),this._makeAtlas(t),null!=e.__nodeIndex?this.get(e.__nodeIndex):void 0}_completeNode(e,t){if(t){let i=this.canvas.getWidth(),n=this.canvas.getHeight(),r=t.image,s=t.rect,a=Math.round(.5*this.borderSize);this.canvas.drawImage(r,s.left+a,s.top+a,r.atlasWidth||0,r.atlasHeight||0);let o=t.texCoords;o[0]=(s.left+a)/i,o[1]=(s.top+a)/n,o[2]=(s.left+a)/i,o[3]=(s.bottom-a)/n,o[4]=(s.right-a)/i,o[5]=(s.bottom-a)/n,o[6]=(s.right-a)/i,o[7]=(s.bottom-a)/n,o[8]=(s.right-a)/i,o[9]=(s.top+a)/n,o[10]=(s.left+a)/i,o[11]=(s.top+a)/n,e.set(r.__nodeIndex,t)}}_makeAtlas(e=!1){if(e&&this._btree){let e=this._images[this._images.length-1];this._completeNode(this.nodes,this._btree.insert(e))}else{let e=this._images.slice(0);e.sort((function(e,t){return(t.atlasWidth||t.width)-(e.atlasWidth||e.width)||(t.atlasHeight||t.height)-(e.atlasHeight||e.height)})),this._btree=new Yo(new Go(0,0,this.canvas.getWidth(),this.canvas.getHeight())),this._btree.atlas=this,this.clearCanvas();let t=new Map;for(let i=0;i<e.length;i++)this._completeNode(t,this._btree.insert(e[i]));this.nodes=null,this.nodes=t}}get(e){return this.nodes.get(e)}set(e,t){this.nodes.set(e,t)}createTexture(e,t){this._handler&&(this._handler.gl.deleteTexture(this.texture),e&&(this.canvas.resize(e.width,e.height),this.canvas.drawImage(e,0,0,e.width,e.height)),this.texture=this._handler.createTexture_l(this.canvas.getCanvas(),t))}loadImage(e,t){this._imagesCacheManager.load(e,t)}getImageTexCoordinates(e){if(null!=e.__nodeIndex){let t=this.get(e.__nodeIndex);if(t)return t.texCoords}}}class Yo{constructor(e,t){this.childNodes=null,this.image=null,this.rect=e||new Go,this.texCoords=t||[],this.atlas=null}insert(e){if(this.childNodes){let t=this.childNodes[0].insert(e);return t||this.childNodes[1].insert(e)}{if(null!=this.image)return;let t=this.rect;const i=(e.atlasWidth||e.width)+this.atlas.borderSize,n=(e.atlasHeight||e.height)+this.atlas.borderSize;if(i>t.getWidth()||n>t.getHeight())return;if(t.fit(i,n))return this.image=e,this;this.childNodes=new Array(2),this.childNodes[0]=new Yo,this.childNodes[0].atlas=this.atlas,this.childNodes[1]=new Yo,this.childNodes[1].atlas=this.atlas;return t.getWidth()-i>t.getHeight()-n?(this.childNodes[0].rect.set(t.left,t.top,t.left+i,t.bottom),this.childNodes[1].rect.set(t.left+i,t.top,t.right,t.bottom)):(this.childNodes[0].rect.set(t.left,t.top,t.right,t.top+n),this.childNodes[1].rect.set(t.left,t.top+n,t.right,t.bottom)),this.childNodes[0].insert(e)}}}class qo extends jo{constructor(e,t){super(e,t),this.width=0,this.height=0,this.gliphSize=0,this.distanceRange=0,this.nodes=new Map,this.kernings={}}get(e){return this.nodes.get(e)}}class Xo extends Yo{constructor(e,t){super(e,t),this.emptySize=1,this.metrics={id:0,char:"",width:0,height:0,x:0,y:0,chnl:0,index:0,page:0,xadvance:0,xoffset:0,yoffset:0,nChar:"",nCode:0,nWidth:0,nHeight:0,nAdvance:0,nXOffset:0,nYOffset:0}}}class $o{constructor(e){this.atlasesArr=[],this.atlasIndexes={},this.atlasIndexesDeferred={},this.tokenImageSize=64,this.samplerArr=new Uint32Array(11),this.sdfParamsArr=new Float32Array(44),this._handler=null,this.catalogSrc=e||"./"}assignHandler(e){this._handler=e}getFontIndex(e){let t=this.getFullIndex(e);return this.atlasIndexes[t]||this.loadFont(e,this.catalogSrc,`${e}.json`),this.atlasIndexesDeferred[t]||(this.atlasIndexesDeferred[t]=new as),this.atlasIndexesDeferred[t].promise}getFullIndex(e){return e.trim().toLowerCase()}_applyFontDataToAtlas(e,t,i=0){let n=t.chars;e.height=t.common.scaleH,e.width=t.common.scaleW,e.gliphSize=t.info.size,e.distanceRange=t.distanceField.distanceRange;let r=e.width,s=e.height,a=e.gliphSize;this.sdfParamsArr[4*i]=r,this.sdfParamsArr[4*i+1]=s,this.sdfParamsArr[4*i+2]=a,this.sdfParamsArr[4*i+3]=e.distanceRange;let o={};for(let t=0;t<n.length;t++){let i=n[t],l=i.char;o[i.id]=l;let h=new Go(i.x,i.y,i.x+i.width,i.y+i.height),c=new Array(12);c[0]=h.left/r,c[1]=h.top/s,c[2]=h.left/r,c[3]=h.bottom/s,c[4]=h.right/r,c[5]=h.bottom/s,c[6]=h.right/r,c[7]=h.bottom/s,c[8]=h.right/r,c[9]=h.top/s,c[10]=h.left/r,c[11]=h.top/s;let d=new Xo(h,c),_=i.char.normalize("NFKC"),u=_.charCodeAt(0),f=d.metrics;f.id=i.id,f.char=i.char,f.width=i.width,f.height=i.height,f.x=i.x,f.y=i.y,f.chnl=i.chnl,f.index=i.index,f.page=i.page,f.xadvance=i.xadvance,f.xoffset=i.xoffset,f.yoffset=i.yoffset,f.nChar=_,f.nCode=u,f.nWidth=d.metrics.width/a,f.nHeight=d.metrics.height/a,f.nAdvance=d.metrics.xadvance/a,f.nXOffset=d.metrics.xoffset/a,f.nYOffset=1-d.metrics.yoffset/a,d.emptySize=1,e.nodes.set(_.charCodeAt(0),d)}e.kernings={};for(let i=0;i<t.kernings.length;i++){let n=t.kernings[i],r=n.first,s=n.second;e.kernings[r]||(e.kernings[r]={}),e.kernings[r][s]=n.amount/a}}initFont(e,t,i){let n=this.atlasesArr.length,r=this.getFullIndex(e);this.atlasIndexes[r]=n;let s=this.atlasIndexesDeferred[r];s||(s=this.atlasIndexesDeferred[r]=new as),this.samplerArr[this.atlasesArr.length]=n;let a=new qo;a.height=0,a.width=0,a.gliphSize=0,a.distanceRange=0,a.kernings={},a.assignHandler(this._handler),this.atlasesArr[n]=a,this._applyFontDataToAtlas(a,t,n);let o=new Image;o.onload=()=>{this._createTexture(a,o),s.resolve(n)},o.src=i}_createTexture(e,t){e.createTexture(t)}loadFont(e,t,i){let n=this.atlasesArr.length,r=this.getFullIndex(e);this.atlasIndexes[r]=n;let s=this.atlasIndexesDeferred[r];s||(s=this.atlasIndexesDeferred[r]=new as),this.samplerArr[this.atlasesArr.length]=n;let a=new qo;a.height=0,a.width=0,a.gliphSize=0,a.distanceRange=0,a.kernings={},a.assignHandler(this._handler),this.atlasesArr[n]=a,fetch(`${t}/${i}`).then((e=>{if(!e.ok)throw Error(`Unable to load "${t}/${i}"`);return e.json()})).then((e=>{this._applyFontDataToAtlas(a,e,n);let i=new Image;i.onload=()=>{this._createTexture(a,i),s.resolve(n)},i.src=`${t}/${e.pages[0]}`,i.crossOrigin="Anonymous"})).catch((e=>(s.reject(),{status:"error",msg:e.toString()})))}}let Zo=0,Ko=0,Qo=0;function Jo(e,t,i){return new Promise(((n,r)=>{!function s(){const a=e.clientWaitSync(t,i,0);a==e.WAIT_FAILED?r():a==e.TIMEOUT_EXPIRED?requestAnimationFrame(s):n()}()}))}class el{constructor(e,t={}){if(this._readPickingBuffer_webgl1=()=>{this.pickingFramebuffer.activate(),this.pickingFramebuffer.readAllPixels(this._tempPickingPix_),this.pickingFramebuffer.deactivate()},this._readPickingBuffer_webgl2=()=>{const e=this.handler.gl,t=this._pickingPixelBuffer;if(!this._skipPickingFrame){this._skipPickingFrame=!0;let i=this._tempPickingPix_,n=this.pickingFramebuffer.width,r=this.pickingFramebuffer.height;this.pickingFramebuffer.activate(),e.bindBuffer(e.PIXEL_PACK_BUFFER,t),e.bufferData(e.PIXEL_PACK_BUFFER,i.byteLength,e.STREAM_READ),e.readPixels(0,0,n,r,e.RGBA,e.UNSIGNED_BYTE,0),e.bindBuffer(e.PIXEL_PACK_BUFFER,null),this.pickingFramebuffer.deactivate();const s=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);e.flush(),Jo(e,s,0).then((()=>{this._skipPickingFrame=!1,e.deleteSync(s),e.bindBuffer(e.PIXEL_PACK_BUFFER,t),e.getBufferSubData(e.PIXEL_PACK_BUFFER,0,i),e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}))}},this._readDistanceBuffer_webgl1=()=>{this.distanceFramebuffer.activate(),this.distanceFramebuffer.readAllPixels(this._tempDistancePix_),this.distanceFramebuffer.deactivate()},this._readDistanceBuffer_webgl2=()=>{const e=this.handler.gl,t=this._distancePixelBuffer;if(!this._skipDistanceFrame){this._skipDistanceFrame=!0;let i=this._tempDistancePix_,n=this.distanceFramebuffer.width,r=this.distanceFramebuffer.height;this.distanceFramebuffer.activate(),e.bindBuffer(e.PIXEL_PACK_BUFFER,t),e.bufferData(e.PIXEL_PACK_BUFFER,i.byteLength,e.STREAM_READ),e.readPixels(0,0,n,r,e.RGBA,e.UNSIGNED_BYTE,0),e.bindBuffer(e.PIXEL_PACK_BUFFER,null),this.distanceFramebuffer.deactivate();const s=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);e.flush(),Jo(e,s,0).then((()=>{this._skipDistanceFrame=!1,e.deleteSync(s),e.bindBuffer(e.PIXEL_PACK_BUFFER,t),e.getBufferSubData(e.PIXEL_PACK_BUFFER,0,i),e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}))}},this.div=null,this.handler=e,this.exposure=3.01,this.gamma=.47,this.whitepoint=1,this.brightThreshold=.9,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=null,this.events=new Vo(this),this.controls={},t.controls)for(let e in t.controls)this.controls[t.controls[e].name]=t.controls[e];this.controlsBag={},this.colorObjects=new Map,this._pickingCallbacks=[],this.pickingFramebuffer=null,this._tempPickingPix_=new Uint8Array([]),this.distanceFramebuffer=null,this._distanceCallbacks=[],this._tempDistancePix_=new Uint8Array([]),this._depthCallbacks=[],this.depthFramebuffer=null;let i=new URLSearchParams(location.search),n=i.get("og_msaa");this._msaa=n?Number(i.get("og_msaa")):null!=t.msaa?t.msaa:0,this._internalFormat="RGBA16F",this._format="RGBA",this._type="FLOAT",this.sceneFramebuffer=null,this.blitFramebuffer=null,this.toneMappingFramebuffer=null,this._initialized=!1,this.billboardsTextureAtlas=new jo,this.geoObjectsTextureAtlas=new jo,this.fontAtlas=new $o(t.fontsSrc),this._entityCollections=[],this._currentOutput="screen",this._fnScreenFrame=null,this.labelWorker=new ii(4),this.__useDistanceFramebuffer__=!0,this.screenDepthFramebuffer=null,this.screenFramePositionBuffer=null,this.screenTexture={},this.outputTexture=null,this._skipDistanceFrame=!1,this._distancePixelBuffer=null,this._skipPickingFrame=!1,this._pickingPixelBuffer=null,this._readDistanceBuffer=this._readDistanceBuffer_webgl2,this._readPickingBuffer=this._readPickingBuffer_webgl2,(t.autoActivate||de(t.autoActivate))&&this.start()}enableBlendOneSrcAlpha(){let e=this.handler.gl;e.enable(e.BLEND),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA)}enableBlendDefault(){let e=this.handler.gl;e.enable(e.BLEND),e.blendEquation(e.FUNC_ADD),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE)}setEventsActivity(e){this.events.active=e}addDepthCallback(e,t){let i=Ko++;return this._depthCallbacks.push({id:i,callback:t,sender:e}),i}removeDepthCallback(e){for(let t=0;t<this._depthCallbacks.length;t++)if(e===this._depthCallbacks[t].id){this._depthCallbacks.splice(t,1);break}}addDistanceCallback(e,t){let i=Qo++;return this._distanceCallbacks.push({id:i,callback:t,sender:e}),i}removeDistanceCallback(e){for(let t=0;t<this._distanceCallbacks.length;t++)if(e===this._distanceCallbacks[t].id){this._distanceCallbacks.splice(t,1);break}}addPickingCallback(e,t){let i=Zo++;return this._pickingCallbacks.push({id:i,callback:t,sender:e}),i}removePickingCallback(e){for(let t=0;t<this._pickingCallbacks.length;t++)if(e===this._pickingCallbacks[t].id){this._pickingCallbacks.splice(t,1);break}}getPickingObject(e,t,i){return this.colorObjects.get(`${e}_${t}_${i}`)}getPickingObjectArr(e){return this.colorObjects.get(`${e[0]}_${e[1]}_${e[2]}`)}getPickingObject3v(e){return this.colorObjects.get(`${e.x}_${e.y}_${e.z}`)}assignPickingColor(e){if(!e._pickingColor||e._pickingColor.isZero()){let t=0,i=0,n=0,r="0_0_0";for(;!(t||i||n)||this.colorObjects.has(r);)t=y(1,255),i=y(1,255),n=y(1,255),r=`${t}_${i}_${n}`;e._pickingColor?e._pickingColor.set(t,i,n):e._pickingColor=new oe(t,i,n),e._pickingColorU=new Float32Array([t/255,i/255,n/255]),this.colorObjects.set(r,e)}}clearPickingColor(e){if(e._pickingColor&&!e._pickingColor.isZero()){let t=e._pickingColor;t.isZero()||(this.colorObjects.delete(`${t.x}_${t.y}_${t.z}`),t.x=t.y=t.z=0)}}getWidth(){return this.handler.canvas.clientWidth}getHeight(){return this.handler.canvas.clientHeight}getCenter(){let e=this.handler.canvas;return new le(Math.round(.5*e.width),Math.round(.5*e.height))}getClientCenter(){let e=this.handler.canvas;return new le(Math.round(.5*e.clientWidth),Math.round(.5*e.clientHeight))}addControl(e){e.addTo(this)}addControls(e){for(let t=0;t<e.length;t++)e[t].addTo(this)}removeControl(e){e.remove()}isInitialized(){return this._initialized}initialize(){if(!this._initialized){if(this._initialized=!0,this.handler.initialize(),this.billboardsTextureAtlas.assignHandler(this.handler),this.geoObjectsTextureAtlas.assignHandler(this.handler),this.fontAtlas.assignHandler(this.handler),this.handler.setFrameCallback((()=>{this.draw()})),this.activeCamera=new Oa(this,{eye:new oe(0,0,0),look:new oe(0,0,-1),up:new oe(0,1,0)}),this.events.initialize(),this.events.on("charkeypress",dr.KEY_APOSTROPHE,(function(){Si.setVisibility(!Si.getVisibility())})),this.handler.addProgram(new zi("screenFrame",{uniforms:{texture:"sampler2d"},attributes:{corners:"vec3"},vertexShader:"attribute vec2 corners;\n \n varying vec2 tc;\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n uniform sampler2D texture;\n \n varying vec2 tc;\n \n void main(void) {\n gl_FragColor = texture2D( texture, tc );\n }"})),this.pickingFramebuffer=new $s(this.handler,{width:640,height:480}),this.pickingFramebuffer.init(),this._tempPickingPix_=new Uint8Array(this.pickingFramebuffer.width*this.pickingFramebuffer.height*4),this.distanceFramebuffer=new $s(this.handler,{width:320,height:240}),this.distanceFramebuffer.init(),this._tempDistancePix_=new Uint8Array(this.distanceFramebuffer.width*this.distanceFramebuffer.height*4),this.depthFramebuffer=new $s(this.handler,{size:2,internalFormat:["RGBA","DEPTH_COMPONENT24"],format:["RGBA","DEPTH_COMPONENT"],type:["UNSIGNED_BYTE","UNSIGNED_INT"],attachment:["COLOR_ATTACHMENT","DEPTH_ATTACHMENT"],useDepth:!1}),this.depthFramebuffer.init(),this.screenDepthFramebuffer=new $s(this.handler,{useDepth:!1}),this.screenDepthFramebuffer.init(),"webgl"===this.handler.gl.type)this._readDistanceBuffer=this._readDistanceBuffer_webgl1,this._readPickingBuffer=this._readPickingBuffer_webgl1,this.sceneFramebuffer=new $s(this.handler),this.sceneFramebuffer.init(),this._fnScreenFrame=this._screenFrameNoMSAA,this.screenTexture={screen:this.sceneFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],distance:this.distanceFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0]};else{let e=this.getMaxMSAA(this._internalFormat);this._msaa>e&&(this._msaa=e),this.handler.addPrograms([new zi("toneMapping",{uniforms:{hdrBuffer:"sampler2d",exposure:"float",gamma:"float",whitepoint:"float"},attributes:{corners:"vec3"},vertexShader:"#version 300 es\n \n in vec2 corners;\n \n out vec2 tc;\n\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"#version 300 es\n\n precision highp float;\n\n #ifndef saturate\n #define saturate(a) clamp(a, 0.0, 1.0)\n #endif\n\n uniform sampler2D hdrBuffer;\n\n uniform float whitepoint;\n uniform float exposure;\n uniform float gamma;\n\n vec3 LinearToneMapping(vec3 color) {\n return exposure * color;\n }\n\n vec3 ReinhardToneMapping2(vec3 color) {\n return vec3(1.0) - exp(-color * exposure);\n }\n\n vec3 ReinhardToneMapping(vec3 color) {\n color *= exposure;\n return saturate(color / (vec3(1.0) + color));\n }\n\n #define Uncharted2Helper(x) max(((x * (0.15 * x + 0.10 * 0.50) + 0.20 * 0.02) / (x * (0.15 * x + 0.50) + 0.20 * 0.30)) - 0.02 / 0.30, vec3(0.0))\n\n vec3 Uncharted2ToneMapping(vec3 color) {\n color *= exposure;\n return saturate(Uncharted2Helper(color) / Uncharted2Helper(vec3(whitepoint)));\n }\n\n vec3 OptimizedCineonToneMapping(vec3 color) {\n color *= exposure;\n color = max(vec3(0.0), color - 0.004);\n return pow((color * (6.2 * color + 0.5)) / (color * (6.2 * color + 1.7) + 0.06), vec3(2.2));\n }\n\n vec3 ACESFilmicToneMapping(vec3 color) {\n color *= exposure;\n return saturate((color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14));\n }\n\n in vec2 tc;\n\n layout(location = 0) out vec4 fragColor;\n \n void main(void) {\n vec4 hdrColor = texture(hdrBuffer, tc).rgba;\n \n float oneByGamma = gamma / gamma;\n float oneByWhitePoint = whitepoint / whitepoint;\n vec3 mapped = ReinhardToneMapping2(hdrColor.rgb) * oneByGamma * oneByWhitePoint;\n //vec3 mapped = ACESFilmicToneMapping(hdrColor.rgb) * oneByGamma * oneByWhitePoint;\n\n mapped = pow(mapped, vec3(1.0 / gamma));\n \n fragColor = vec4(mapped, hdrColor.a);\n }"})]),this.handler.addPrograms([new zi("depth",{uniforms:{depthTexture:"sampler2d"},attributes:{corners:"vec2"},vertexShader:"#version 300 es\n \n in vec2 corners;\n \n out vec2 tc;\n\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"#version 300 es\n\n precision highp float;\n\n #define MAX_FRUSTUMS 4\n\n uniform sampler2D depthTexture;\n \n in vec2 tc;\n\n layout(location = 0) out vec4 fragColor;\n\n float LinearizeDepth(in vec2 uv)\n {\n float depth = texture(depthTexture, tc).x;\n return depth;//(2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear));\n }\n \n void main(void) {\n float c = LinearizeDepth(tc);\n fragColor = vec4(c, c, c, 1.0);\n }"})]),this.sceneFramebuffer=new ko(this.handler,{size:1,msaa:this._msaa,internalFormat:this._internalFormat,filter:"LINEAR"}),this.sceneFramebuffer.init(),this.blitFramebuffer=new $s(this.handler,{size:1,useDepth:!1,internalFormat:this._internalFormat,format:this._format,type:this._type,filter:"NEAREST"}),this.blitFramebuffer.init(),this.toneMappingFramebuffer=new $s(this.handler,{useDepth:!1}),this.toneMappingFramebuffer.init(),this._fnScreenFrame=this._screenFrameMSAA,this.screenTexture={screen:this.toneMappingFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],distance:this.distanceFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0],frustum:this.depthFramebuffer.textures[0]},this._initReadPixelsBuffers()}this.handler.ONCANVASRESIZE=()=>{this._resizeStart(),this.events.dispatch(this.events.resize,this.handler.canvas),this._resizeEnd(),this.events.dispatch(this.events.resizeend,this.handler.canvas)},this.screenFramePositionBuffer=this.handler.createArrayBuffer(new Float32Array([1,1,-1,1,1,-1,-1,-1]),2,4),this.outputTexture=this.screenTexture.screen,this._initializeRenderNodes(),this._initializeControls()}}_initReadPixelsBuffers(){let e=this.handler.gl;this._distancePixelBuffer=e.createBuffer(),e.bindBuffer(e.PIXEL_PACK_BUFFER,this._distancePixelBuffer),e.bufferData(e.PIXEL_PACK_BUFFER,this.distanceFramebuffer.width*this.distanceFramebuffer.height*4,e.STREAM_READ),e.bindBuffer(e.PIXEL_PACK_BUFFER,null),this._pickingPixelBuffer=e.createBuffer(),e.bindBuffer(e.PIXEL_PACK_BUFFER,this._pickingPixelBuffer),e.bufferData(e.PIXEL_PACK_BUFFER,this.pickingFramebuffer.width*this.pickingFramebuffer.height*4,e.STREAM_READ),e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}_initializeControls(){let e=this.controls;this.controls={};for(let t in e)this.addControl(e[t])}resize(){this._resizeEnd()}setCurrentScreen(e){this._currentOutput=e,this.screenTexture[e]&&(this.outputTexture=this.screenTexture[e])}_resizeStart(){let e=this.handler.canvas;this.activeCamera.setAspectRatio(e.width/e.height),this.sceneFramebuffer.setSize(.5*e.width,.5*e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(.5*e.width,.5*e.height,!0)}_resizeEnd(){let e=this.handler.canvas;this.activeCamera.setAspectRatio(e.width/e.height),this.sceneFramebuffer.setSize(e.width,e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(e.width,e.height,!0),this.toneMappingFramebuffer&&this.toneMappingFramebuffer.setSize(e.width,e.height,!0),this.depthFramebuffer&&this.depthFramebuffer.setSize(e.clientWidth,e.clientHeight,!0),this.screenDepthFramebuffer&&this.screenDepthFramebuffer.setSize(e.clientWidth,e.clientHeight,!0),"webgl"===this.handler.gl.type?(this.screenTexture.screen=this.sceneFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.distance=this.distanceFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]):(this.screenTexture.screen=this.toneMappingFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.distance=this.distanceFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]),this.setCurrentScreen(this._currentOutput)}removeNode(e){e.remove()}addNode(e){this.renderNodes[e.name]?Si.logWrn(`Node name ${e.name} already exists.`):(e.assign(this),this._renderNodesArr.unshift(e),this.renderNodes[e.name]=e)}_initializeRenderNodes(){for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].initialize()}addNodeBefore(e,t){if(this.renderNodes[e.name])Si.logWrn(`Node name ${e.name} already exists.`);else{e.assign(this),this.renderNodes[e.name]=e;for(let i=0;i<this._renderNodesArr.length;i++)if(this._renderNodesArr[i].isEqual(t)){this._renderNodesArr.splice(i,0,e);break}this._renderNodesArr.unshift(e)}}addNodes(e){for(let t=0;t<e.length;t++)this.addNode(e[t])}getMaxMSAA(e){let t=this.handler.gl;return t.getInternalformatParameter(t.RENDERBUFFER,t[e],t.SAMPLES)[0]}getMSAA(){return this._msaa}enqueueEntityCollectionsToDraw(e){this._entityCollections.push.apply(this._entityCollections,e)}_drawOpaqueEntityCollections(){let e=this._entityCollections;if(e.length){this.enableBlendDefault();let t=e.length;for(;t--;)e[t]._fadingOpacity&&e[t].pointCloudHandler.draw()}}_drawTransparentEntityCollections(){let e=this._entityCollections;if(e.length){let t=this.handler.gl;this.enableBlendDefault();let i=e.length;for(;i--;){let t=e[i];e[i]._fadingOpacity&&(t.events.dispatch(t.events.draw,t),e[i].geoObjectHandler.draw())}for(t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.billboardsTextureAtlas.texture),i=e.length;i--;){let t=e[i];t._fadingOpacity&&t.billboardHandler.draw()}let n=this.fontAtlas.atlasesArr;for(i=0;i<n.length;i++)t.activeTexture(t.TEXTURE0+i),t.bindTexture(t.TEXTURE_2D,n[i].texture);for(i=e.length;i--;)e[i]._fadingOpacity&&e[i].labelHandler.draw();for(i=e.length;i--;)e[i]._fadingOpacity&&e[i].rayHandler.draw();for(i=e.length;i--;)e[i]._fadingOpacity&&e[i].polylineHandler.draw();for(i=e.length;i--;)e[i]._fadingOpacity&&e[i].stripHandler.draw()}}_clearEntityCollectionQueue(){this._entityCollections.length=0,this._entityCollections=[]}draw(){this.activeCamera.checkMoveEnd();let e=this.events;e.handleEvents();let t=this.sceneFramebuffer;t.activate();let i=this.handler,n=i.gl;n.clearColor(0,0,0,1),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),this.enableBlendDefault(),e.dispatch(e.draw,this);let r=this.activeCamera.frustums,s=e.pointerEvent(),a=e.mouseState.leftButtonDown||e.mouseState.rightButtonDown,o=this._renderNodesArr,l=r.length;for(;l--;){this.activeCamera.setCurrentFrustum(l),n.clear(n.DEPTH_BUFFER_BIT);let t=o.length;for(;t--;)o[t].preDrawNode();for(this._drawOpaqueEntityCollections(),t=o.length;t--;)this.enableBlendDefault(),o[t].drawNode();this._drawTransparentEntityCollections(),this._clearEntityCollectionQueue(),e.dispatch(e.drawtransparent,this),s&&!a&&this._drawPickingBuffer(),this.__useDistanceFramebuffer__&&this._drawDistanceBuffer()}t.deactivate(),this.blitFramebuffer&&t.blitTo(this.blitFramebuffer,0),s&&(i.isWebGl2()&&this._drawDepthBuffer(),this._readPickingBuffer()),this.__useDistanceFramebuffer__&&this._readDistanceBuffer(),this._fnScreenFrame(),e.dispatch(e.postdraw,this),e.mouseState.wheelDelta=0,e.mouseState.justStopped=!1,e.mouseState.moving=!1,e.touchState.moving=!1}_screenFrameMSAA(){let e=this.handler,t=e.programs.toneMapping,i=t._program,n=e.gl;n.disable(n.DEPTH_TEST),n.bindBuffer(n.ARRAY_BUFFER,this.screenFramePositionBuffer),n.vertexAttribPointer(i.attributes.corners,2,n.FLOAT,!1,0,0),this.toneMappingFramebuffer.activate(),t.activate(),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this.blitFramebuffer.textures[0]),n.uniform1i(i.uniforms.hdrBuffer,0),n.uniform1f(i.uniforms.gamma,this.gamma),n.uniform1f(i.uniforms.exposure,this.exposure),n.uniform1f(i.uniforms.whitepoint,this.whitepoint),n.drawArrays(n.TRIANGLE_STRIP,0,4),this.toneMappingFramebuffer.deactivate(),t=e.programs.screenFrame,i=t._program,t.activate(),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this.outputTexture),n.uniform1i(i.uniforms.texture,0),n.drawArrays(n.TRIANGLE_STRIP,0,4),n.enable(n.DEPTH_TEST)}_screenFrameNoMSAA(){let e=this.handler,t=e.programs.screenFrame,i=t._program,n=e.gl;n.disable(n.DEPTH_TEST),t.activate(),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this.outputTexture),n.uniform1i(i.uniforms.texture,0),n.bindBuffer(n.ARRAY_BUFFER,this.screenFramePositionBuffer),n.vertexAttribPointer(i.attributes.corners,2,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLE_STRIP,0,4),n.enable(n.DEPTH_TEST)}_drawPickingBuffer(){this.pickingFramebuffer.activate();let e=this.handler.gl;this.activeCamera.isFirstPass?(e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)):e.clear(e.DEPTH_BUFFER_BIT);let t=this._pickingCallbacks;for(let i=0,n=t.length;i<n;i++)e.disable(e.BLEND),t[i].callback.call(t[i].sender),e.enable(e.BLEND);this.pickingFramebuffer.deactivate()}_drawDistanceBuffer(){this.distanceFramebuffer.activate();let e=this.handler.gl;this.activeCamera.isFirstPass?(e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)):e.clear(e.DEPTH_BUFFER_BIT),e.disable(e.BLEND);let t=this._distanceCallbacks,i=t.length;for(;i--;)t[i].callback.call(t[i].sender);e.enable(e.BLEND),this.distanceFramebuffer.deactivate()}_drawDepthBuffer(){this.depthFramebuffer.activate();let e=this.handler,t=e.gl;t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),t.enable(t.DEPTH_TEST);let i=this._depthCallbacks,n=i.length;for(;n--;)i[n].callback.call(i[n].sender);this.depthFramebuffer.deactivate(),this.screenDepthFramebuffer.activate();let r=e.programs.depth,s=r._program;t.bindBuffer(t.ARRAY_BUFFER,this.screenFramePositionBuffer),t.vertexAttribPointer(s.attributes.corners,2,t.FLOAT,!1,0,0),r.activate(),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.depthFramebuffer.textures[1]),t.uniform1i(s.uniforms.depthTexture,0),t.drawArrays(t.TRIANGLE_STRIP,0,4),this.screenDepthFramebuffer.deactivate()}readPickingColor(e,t,i){let n=this.pickingFramebuffer.width,r=this.pickingFramebuffer.height;e=Math.round(e*n);let s=4*((t=Math.round(t*r))*n+e);i[0]=this._tempPickingPix_[s],i[1]=this._tempPickingPix_[s+1],i[2]=this._tempPickingPix_[s+2]}readDistanceColor(e,t,i){let n=this.distanceFramebuffer.width,r=this.distanceFramebuffer.height;e=Math.round(e*n);let s=4*((t=Math.round(t*r))*n+e);i[0]=this._tempDistancePix_[s],i[1]=this._tempDistancePix_[s+1],i[2]=this._tempDistancePix_[s+2]}start(){this._initialized||this.initialize(),this.handler.start()}destroy(){for(let e in this.controls)this.controls[e].remove();for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].remove();this.div=null,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=null,this.controls={},this.controlsBag={},this.colorObjects.clear(),this.colorObjects=null,this._pickingCallbacks=[],this.pickingFramebuffer=null,this._tempPickingPix_=null,this.distanceFramebuffer=null,this._distanceCallbacks=[],this._tempDistancePix_=null,this._depthCallbacks=[],this.depthFramebuffer=null,this.sceneFramebuffer=null,this.blitFramebuffer=null,this.toneMappingFramebuffer=null,this._entityCollections=[],this.handler.ONCANVASRESIZE=null,this.handler.destroy(),this.handler=null,this._initialized=!1}}const tl="/res";class il{constructor(e){this.$target=null,this._instanceID=`__globus${il.__counter__++?il.__counter__:""}__`,window[this._instanceID]=this,this._canvas=document.createElement("canvas"),this._canvas.id=`canvas${this._instanceID}`,this._canvas.style.width="100%",this._canvas.style.height="100%",this._canvas.style.display="block",this._canvas.style.opacity="0.0",this._canvas.style.transition="opacity 150ms",this.$inner=document.createElement("div"),this.$inner.classList.add("og-inner"),this.$inner.appendChild(this._canvas),this.$inner.attributions=document.createElement("div"),e.attributionContainer?e.attributionContainer.appendChild(this.$inner.attributions):(this.$inner.attributions.classList.add("og-attribution"),this.$inner.appendChild(this.$inner.attributions)),e.target&&this.attachTo(e.target);const t=e=>{e.preventDefault()};this._canvas.onmouseenter=function(){document.addEventListener("mousewheel",t,{capture:!1,passive:!1})},this._canvas.onmouseleave=function(){document.removeEventListener("mousewheel",t)},this.renderer=new el(new Bo(this._canvas,{autoActivate:!1,pixelRatio:e.dpi||window.devicePixelRatio+.15,context:{antialias:!1,premultipliedAlpha:!1}}),{autoActivate:!1,msaa:e.msaa,fontsSrc:e.fontsSrc}),this.renderer.div=this.$inner,e.skybox&&this.renderer.addNode(e.skybox),this._planetName=e.name?e.name:"globus_planet_"+il.__counter__,this.planet=new Za({name:this._planetName,frustums:e.frustums,ellipsoid:e.ellipsoid,maxGridSize:e.maxGridSize,nightTextureSrc:null===e.nightTextureSrc?null:`${e.resourcesSrc||tl}/night.png`,specularTextureSrc:null===e.specularTextureSrc?null:`${e.resourcesSrc||tl}/spec.png`,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude||15e6,maxEqualZoomAltitude:e.maxEqualZoomAltitude,minEqualZoomAltitude:e.minEqualZoomAltitude,minEqualZoomCameraSlope:e.minEqualZoomCameraSlope,quadTreeStrategyPrototype:e.quadTreeStrategyPrototype,maxLoadingRequests:e.maxLoadingRequests,atmosphereEnabled:e.atmosphereEnabled,transitionOpacityEnabled:e.transitionOpacityEnabled,atmosphereParameters:e.atmosphereParameters}),e.terrain?Array.isArray(e.terrain)?this.planet.setTerrain(e.terrain[0]):this.planet.setTerrain(e.terrain):this.planet.setTerrain(new eo),this.renderer.addNode(this.planet),e.controls?this.planet.addControls(e.controls):this.planet.addControls([new Wr,e.useEarthNavigation?new lr:new br({minSlope:e.minSlope}),new Gr,new ar,new Dr,new zt]);const i=this.renderer.controls;let n;for(let e in i)if(i[e]instanceof Vr){n=i[e];break}n?this.sun=n:(this.sun=new Vr,this.planet.addControl(this.sun)),e.sun&&(void 0===e.sun.active||e.sun.active||this.sun.deactivate(),!0===e.sun.stopped&&this.sun.stop()),e.layers&&this.planet.addLayers(e.layers);let r=e.viewExtent;r&&(r instanceof Array?this.planet.viewExtentArr(r):this.planet.viewExtent(r)),(e.autoActivate||de(e.autoActivate))&&this.start()}start(){this.renderer.start(),this.fadeIn()}fadeIn(){this._canvas.style.opacity="1.0"}fadeOut(){this._canvas.style.opacity="0"}attachTo(e){let t;this.detach(),t=e instanceof HTMLElement?e:document.getElementById(e)||document.querySelector(e),t&&(this.$target=t,t.appendChild(this.$inner))}detach(){this.$target&&this.$target.removeChild(this.$inner)}destroy(){this.detach(),this.planet.layers.forEach((e=>e.remove())),this.planet.destroy(),this.renderer.destroy(),window[this._instanceID]=null}}il.__counter__=0;const nl=`<div class="og-popup {className}">\n <div class="og-popup-content-wrapper">\n <div class="og-popup-content"></div>\n </div>\n <div class="og-popup-tip-container">\n <div class="og-popup-tip"></div>\n </div>\n <div class="og-popup-toolbar">\n <div class="og-popup-btn og-popup-close">${Dt}</div>\n </div>\n <div class="og-popup-title">{title}</div>\n </div>`,rl=["open","close"];class sl extends Bt{constructor(e){super({template:be(nl,{title:e.title||""}),classList:e.className?[e.className]:[],...e}),this.events=this.events.registerNames(rl),this._content=e.content||"",this.$content=null,this.$tip=null,this.$title=null,this._planet=e.planet,this._offset=e.offset||[0,0],this._lonLat=Me(e.lonLat),this._cartPos=new oe,this._visibility=e.visibility||!1,this.render()}_updatePosition(){this.setCartesian3v(this._cartPos)}setScreen(e){if(this._planet){let t=this._planet.renderer.handler.pixelRatio;this.el.style.transform=`translate(${e.x/t-.5*this.clientWidth}px, ${e.y/t-this._planet.renderer.handler.canvas.clientHeight-this.$tip.clientHeight}px)`}}get clientWidth(){return this.el?this.el.clientWidth:0}get clientHeight(){return this.el?this.el.clientHeight:0}setOffset(e=0,t=0){return this._offset[0]=e,this._offset[1]=t,this.el&&(this.el.style.left=`${e}px`,this.el.style.bottom=`${t}px`),this}render(e){return super.render(e),this.$content=this.select(".og-popup-content"),this.$title=this.select(".og-popup-title"),this.$tip=this.select(".og-popup-tip-container"),this.setOffset(this._offset[0],this._offset[1]),this.setContent(this._content),this.setLonLat(this._lonLat),this.setVisibility(this._visibility),this.select(".og-popup-close").addEventListener("click",(()=>{this.hide()})),this}setVisibility(e){return e?this.show():this.hide(),this}getContainer(){return this.$content}getToolbarContainer(){return this.select(".og-popup-toolbar")}show(){return this._visibility=!0,this._planet&&(this._planet.events.on("draw",this._updatePosition,this),this.appendTo(this._planet.renderer.div),this.events.dispatch(this.events.open,this)),this}hide(){return this._visibility=!1,this.el&&this.el.parentNode&&(this._planet.events.off("draw",this._updatePosition),this.el.parentNode.removeChild(this.el),this.events.dispatch(this.events.close,this)),this}setCartesian3v(e,t=0){if(this._cartPos=e,this._planet){let i=this._planet.camera,n=this._planet.ellipsoid.equatorialSize+t,r=i._lonLat.height,s=e.sub(i.eye);Math.sqrt((n+r)*(n+r)-n*n)>s.length()&&i.getForward().dot(s.normalize())>0?(this.el.style.display="block",this.setScreen(i.project(e))):this.el.style.display="none"}return this}setTitle(e){this.$title&&(this.$title.innerHTML=e)}setLonLat(e){this._lonLat=e,this._planet&&this.setCartesian3v(this._planet.ellipsoid.lonLatToCartesian(e),e.height)}setContent(e){e&&(this.clear(),this._content=e,this.$content&&("string"==typeof e?this.$content.innerHTML=e:this.$content.appendChild(e)))}clear(){this._content=null,this.$content&&(this.$content.innerHTML="")}}class al extends Pa{constructor(e,t,i,n){super(e,t,i,n),this.isPole=!1,this._tileGroup=0}_getMaxZoom(){return 150}_assignTileYIndexes(e){const t=e.getCenter().lat;this.tileY=ra(t,e.getHeight(),90),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_assignTileXIndexes(e){let t=e.getCenter().lon;this.tileX=ra(t,e.getWidth(),-180);let i=2*(1<<this.tileZoom);this.tileXE=(this.tileX+1)%i,this.tileXW=(i+this.tileX-1)%i}}class ol extends Aa{constructor(e){super(e,"Mars",ia),this._westExtent=ie.createFromArray([-180,-90,0,90]),this._eastExtent=ie.createFromArray([0,-90,180,90])}init(){this._quadTreeList=[new La(al,this.planet,0,null,0,this._westExtent),new La(al,this.planet,0,null,0,this._eastExtent)]}getTileXY(e,t){let i=t,n=-1,r=-1,s=1<<i;return n=e.lon>0?ra(e.lon,180/s,0)+s:ra(e.lon,180/s,-180),r=ra(e.lat,180/s,90),[n,r,i,0]}getLonLatTileOffset(e,t,i,n,r){let s=e,a=new ie;a=e.lon>0?sa(t-(1<<n),i,n,this._westExtent):sa(t,i,n,this._eastExtent);let o=a.getWidth()/(r-1),l=a.getHeight()/(r-1);return[r-Math.ceil((s.lat-a.southWest.lat)/l)-1,Math.floor((s.lon-a.southWest.lon)/o)]}}class ll extends Aa{constructor(e){super(e,"wgs84",ia)}init(){this._quadTreeList=[new La(al,this.planet,0,null,0,ie.createFromArray([-180,-90,180,90]))]}}const hl={epsg4326:class extends Aa{constructor(e){super(e,"EPSG4326",ia)}init(){this._quadTreeList=[new La(al,this.planet,0,null,0,ie.createFromArray([-180,-90,0,90])),new La(al,this.planet,0,null,0,ie.createFromArray([0,-90,180,90]))]}},earth:Sa,mars:ol,wgs84:ll};export{mi as ALIGN,ao as BilTerrain,si as Billboard,wo as Bing,Oa as Camera,Zt as CanvasTiles,Lo as Clock,It as Control,Sa as EarthQuadTreeStrategy,Ya as Ellipsoid,eo as EmptyTerrain,Ai as Entity,Qi as EntityCollection,St as Events,ie as Extent,$s as Framebuffer,po as GeoImage,pi as GeoObject,mo as GeoTexture2d,vo as GeoVideo,Ma as Geoid,li as Geometry,ai as GeometryTypeEnum,il as Globe,fo as GlobusRgbTerrain,to as GlobusTerrain,Bo as Handler,yo as KML,Xt as LAYER_EVENTS,yi as Label,qt as Layer,Or as LightSource,hi as Line2,ci as Line3,z as LonLat,ol as MarsQuadTreeStrategy,ne as Mat3,se as Mat4,jt as Material,ko as Multisample,gi as Object3d,xo as OpenStreetMap,di as Plane,Za as Planet,Va as PlanetCamera,xi as PointCloud,bi as Polyline,sl as Popup,zi as Program,Aa as QuadTreeStrategy,ae as Quat,_i as Ray,Pi as RenderNode,el as Renderer,lo as RgbTerrain,Li as Strip,le as Vec2,oe as Vec3,re as Vec4,In as Vector,so as WMS,ll as Wgs84QuadTreeStrategy,no as XYZ,Et as bv,Es as control,dr as input,Tt as jd,Co as layer,S as math,te as mercator,hl as quadTreeStrategyType,Ja as scene,go as terrain,Qe as utils,Ro as webgl,qa as wgs84};
|
|
2
2
|
//# sourceMappingURL=og.esm.js.map
|